2019-01-17 18:54:05 -05:00
|
|
|
// Copyright 1998-2019 Epic Games, Inc. All Rights Reserved.
|
2018-12-04 09:59:43 -05:00
|
|
|
|
|
|
|
|
#include "RenderGraphUtils.h"
|
2019-01-30 21:24:04 -05:00
|
|
|
#include <initializer_list>
|
2018-12-04 09:59:43 -05:00
|
|
|
|
2019-01-30 21:24:04 -05:00
|
|
|
void ClearUnusedGraphResourcesImpl(
|
|
|
|
|
const FShaderParameterBindings& ShaderBindings,
|
|
|
|
|
const FShaderParametersMetadata* ParametersMetadata,
|
|
|
|
|
void* InoutParameters,
|
|
|
|
|
std::initializer_list< FRDGResourceRef > ExcludeList)
|
2018-12-04 09:59:43 -05:00
|
|
|
{
|
|
|
|
|
int32 GraphTextureId = 0;
|
|
|
|
|
int32 GraphSRVId = 0;
|
|
|
|
|
int32 GraphUAVId = 0;
|
|
|
|
|
|
|
|
|
|
uint8* Base = reinterpret_cast<uint8*>(InoutParameters);
|
|
|
|
|
|
|
|
|
|
for (int32 ResourceIndex = 0, Num = ParametersMetadata->GetLayout().Resources.Num(); ResourceIndex < Num; ResourceIndex++)
|
|
|
|
|
{
|
2019-01-30 21:24:04 -05:00
|
|
|
EUniformBufferBaseType Type = ParametersMetadata->GetLayout().Resources[ResourceIndex].MemberType;
|
|
|
|
|
uint16 ByteOffset = ParametersMetadata->GetLayout().Resources[ResourceIndex].MemberOffset;
|
2018-12-04 09:59:43 -05:00
|
|
|
|
2019-01-30 21:24:04 -05:00
|
|
|
if (Type == UBMT_RDG_TEXTURE)
|
2018-12-04 09:59:43 -05:00
|
|
|
{
|
|
|
|
|
if (GraphTextureId < ShaderBindings.GraphTextures.Num() && ByteOffset == ShaderBindings.GraphTextures[GraphTextureId].ByteOffset)
|
|
|
|
|
{
|
|
|
|
|
GraphTextureId++;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-01-30 21:24:04 -05:00
|
|
|
else if (Type == UBMT_RDG_TEXTURE_SRV || Type == UBMT_RDG_BUFFER_SRV)
|
2018-12-04 09:59:43 -05:00
|
|
|
{
|
|
|
|
|
if (GraphSRVId < ShaderBindings.GraphSRVs.Num() && ByteOffset == ShaderBindings.GraphSRVs[GraphSRVId].ByteOffset)
|
|
|
|
|
{
|
|
|
|
|
GraphSRVId++;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-01-30 21:24:04 -05:00
|
|
|
else if (Type == UBMT_RDG_TEXTURE_UAV || Type == UBMT_RDG_BUFFER_UAV)
|
2018-12-04 09:59:43 -05:00
|
|
|
{
|
|
|
|
|
if (GraphUAVId < ShaderBindings.GraphUAVs.Num() && ByteOffset == ShaderBindings.GraphUAVs[GraphUAVId].ByteOffset)
|
|
|
|
|
{
|
|
|
|
|
GraphUAVId++;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-30 21:24:04 -05:00
|
|
|
for( FRDGResourceRef ExcludeResource : ExcludeList )
|
|
|
|
|
{
|
|
|
|
|
auto Resource = *reinterpret_cast<const FRDGResource* const*>(Base + ByteOffset);
|
|
|
|
|
if( Resource == ExcludeResource )
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-04 09:59:43 -05:00
|
|
|
void** ResourcePointerAddress = reinterpret_cast<void**>(Base + ByteOffset);
|
|
|
|
|
*ResourcePointerAddress = nullptr;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-01-30 21:24:04 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
FRDGTextureRef RegisterExternalTextureWithFallback(
|
|
|
|
|
FRDGBuilder& GraphBuilder,
|
|
|
|
|
const TRefCountPtr<IPooledRenderTarget>& ExternalPooledTexture,
|
|
|
|
|
const TRefCountPtr<IPooledRenderTarget>& FallbackPooledTexture,
|
|
|
|
|
const TCHAR* ExternalPooledTextureName)
|
|
|
|
|
{
|
|
|
|
|
ensureMsgf(FallbackPooledTexture.IsValid(), TEXT("RegisterExternalTextureWithDummyFallback() requires a valid fallback pooled texture."));
|
|
|
|
|
if (ExternalPooledTexture.IsValid())
|
|
|
|
|
{
|
|
|
|
|
return GraphBuilder.RegisterExternalTexture(ExternalPooledTexture, ExternalPooledTextureName);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return GraphBuilder.RegisterExternalTexture(FallbackPooledTexture);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|