2019-12-26 14:45:42 -05:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
2018-10-22 23:01:29 -04:00
|
|
|
|
|
|
|
|
/*=============================================================================
|
|
|
|
|
RenderTargetPool.h: Scene render target pool manager.
|
|
|
|
|
=============================================================================*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "CoreMinimal.h"
|
|
|
|
|
#include "RHI.h"
|
|
|
|
|
#include "RenderResource.h"
|
|
|
|
|
#include "RendererInterface.h"
|
|
|
|
|
#include "RenderGraphResources.h"
|
|
|
|
|
|
2022-01-03 18:28:16 -05:00
|
|
|
class RENDERCORE_API FRDGBufferPool : public FRenderResource
|
2018-10-22 23:01:29 -04:00
|
|
|
{
|
|
|
|
|
public:
|
2022-01-03 18:28:16 -05:00
|
|
|
FRDGBufferPool() = default;
|
2018-10-22 23:01:29 -04:00
|
|
|
|
2019-07-09 17:22:17 -04:00
|
|
|
/** Call once per frame to trim elements from the pool. */
|
|
|
|
|
void TickPoolElements();
|
2018-10-22 23:01:29 -04:00
|
|
|
|
2020-09-24 00:43:27 -04:00
|
|
|
/** Allocate a buffer from a given descriptor. */
|
2022-04-22 17:11:57 -04:00
|
|
|
UE_DEPRECATED(5.1, "Use FindFreeBuffer without a command list instead.")
|
|
|
|
|
TRefCountPtr<FRDGPooledBuffer> FindFreeBuffer(FRHICommandList& RHICmdList, const FRDGBufferDesc& Desc, const TCHAR* InDebugName)
|
|
|
|
|
{
|
|
|
|
|
return FindFreeBuffer(Desc, InDebugName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TRefCountPtr<FRDGPooledBuffer> FindFreeBuffer(const FRDGBufferDesc& Desc, const TCHAR* InDebugName, ERDGPooledBufferAlignment Alignment = ERDGPooledBufferAlignment::Page);
|
2020-09-24 00:43:27 -04:00
|
|
|
|
2022-04-25 11:38:06 -04:00
|
|
|
void DumpMemoryUsage(FOutputDevice& OutputDevice);
|
|
|
|
|
|
2018-10-22 23:01:29 -04:00
|
|
|
private:
|
2022-01-03 18:28:16 -05:00
|
|
|
void ReleaseDynamicRHI() override;
|
|
|
|
|
|
2018-10-22 23:01:29 -04:00
|
|
|
/** Elements can be 0, we compact the buffer later. */
|
2020-09-24 00:43:27 -04:00
|
|
|
TArray<TRefCountPtr<FRDGPooledBuffer>> AllocatedBuffers;
|
2022-04-22 17:11:57 -04:00
|
|
|
TArray<uint32> AllocatedBufferHashes;
|
2019-07-09 17:22:17 -04:00
|
|
|
|
|
|
|
|
uint32 FrameCounter = 0;
|
2020-09-24 00:43:27 -04:00
|
|
|
|
|
|
|
|
friend class FRDGBuilder;
|
2018-10-22 23:01:29 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/** The global render targets for easy shading. */
|
2022-01-03 18:28:16 -05:00
|
|
|
extern RENDERCORE_API TGlobalResource<FRDGBufferPool> GRenderGraphResourcePool;
|
|
|
|
|
|
|
|
|
|
enum class ERDGTransientResourceLifetimeState
|
|
|
|
|
{
|
|
|
|
|
Deallocated,
|
|
|
|
|
Allocated,
|
|
|
|
|
PendingDeallocation
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class FRDGTransientRenderTarget final : public IPooledRenderTarget
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
uint32 AddRef() const override;
|
|
|
|
|
uint32 Release() override;
|
|
|
|
|
uint32 GetRefCount() const override { return RefCount; }
|
|
|
|
|
|
|
|
|
|
bool IsFree() const override { return false; }
|
|
|
|
|
bool IsTracked() const override { return true; }
|
|
|
|
|
uint32 ComputeMemorySize() const override { return 0; }
|
|
|
|
|
|
|
|
|
|
const FPooledRenderTargetDesc& GetDesc() const override { return Desc; }
|
|
|
|
|
|
|
|
|
|
FRHITransientTexture* GetTransientTexture() const override
|
|
|
|
|
{
|
|
|
|
|
check(LifetimeState == ERDGTransientResourceLifetimeState::Allocated);
|
|
|
|
|
return Texture;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Reset()
|
|
|
|
|
{
|
|
|
|
|
Texture = nullptr;
|
|
|
|
|
RenderTargetItem.ShaderResourceTexture = nullptr;
|
|
|
|
|
RenderTargetItem.TargetableTexture = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
FRDGTransientRenderTarget() = default;
|
|
|
|
|
|
|
|
|
|
FRHITransientTexture* Texture;
|
|
|
|
|
FPooledRenderTargetDesc Desc;
|
|
|
|
|
ERDGTransientResourceLifetimeState LifetimeState;
|
|
|
|
|
mutable uint32 RefCount = 0;
|
|
|
|
|
|
|
|
|
|
friend class FRDGTransientResourceAllocator;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class FRDGTransientResourceAllocator : public FRenderResource
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
IRHITransientResourceAllocator* Get() { return Allocator; }
|
|
|
|
|
|
|
|
|
|
TRefCountPtr<FRDGTransientRenderTarget> AllocateRenderTarget(FRHITransientTexture* Texture);
|
|
|
|
|
|
|
|
|
|
void Release(TRefCountPtr<FRDGTransientRenderTarget>&& RenderTarget, FRDGPassHandle PassHandle);
|
|
|
|
|
|
|
|
|
|
void ReleasePendingDeallocations();
|
|
|
|
|
|
2022-01-14 16:28:58 -05:00
|
|
|
bool IsValid() const { return Allocator != nullptr; }
|
|
|
|
|
|
2022-01-03 18:28:16 -05:00
|
|
|
private:
|
|
|
|
|
void InitDynamicRHI() override;
|
|
|
|
|
void ReleaseDynamicRHI() override;
|
|
|
|
|
|
|
|
|
|
void AddPendingDeallocation(FRDGTransientRenderTarget* RenderTarget);
|
|
|
|
|
|
|
|
|
|
IRHITransientResourceAllocator* Allocator = nullptr;
|
|
|
|
|
|
|
|
|
|
TArray<FRDGTransientRenderTarget*> FreeList;
|
|
|
|
|
TArray<FRDGTransientRenderTarget*> PendingDeallocationList;
|
|
|
|
|
TArray<FRDGTransientRenderTarget*> DeallocatedList;
|
|
|
|
|
|
|
|
|
|
friend class FRDGTransientRenderTarget;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
extern RENDERCORE_API TGlobalResource<FRDGTransientResourceAllocator> GRDGTransientResourceAllocator;
|