Files
UnrealEngineUWP/Engine/Source/Runtime/RenderCore/Public/CommonRenderResources.h
jason hoerner 311f875d30 [Re-submit Backout attempt take 2 -- original horde failure didn't repro on preflight, so maybe it was a spurious issue?]
Post Process Material:  Support for "UserSceneTextures" -- transient intermediate render targets that can be written and read by name in post process materials.  The post process section of materials has a UserSceneTexture output name, and a new UserSceneTexture node type has been added to read back those outputs as inputs.

Shader features:
* A resolution divisor can be specified on the output to allow things like half resolution targets.  If the same name is used with multiple resolutions, the most recently written resolution is used as an input.
* A UV clamping option was added to solve out of bounds interpolation issues when bilinear sampling lower resolution targets from a higher resolution pass.
* A human readable define based on the user specified name is added to HLSL (with prefix "PPIUser_"), allowing Custom HLSL nodes to refer to UserSceneTexture inputs by name.  Necessary because input slots are dynamically allocated.  Useful for things like blur kernels that use Custom HLSL to sample a range of inputs.
* All 5 Post Process Input slots are potentially available to UserSceneTextures -- built-in SceneTexture slots for a given location (like SceneColor, SeparateTranslucency, or SceneVelocity) are used for UserSceneTextures if not referenced in the shader.
* Supports translucent blending.  If the first write to a UserSceneTexture includes blending, it will be primed with the current input for the given location.
* Missing inputs are replaced with black.
* Simplified syntax for accessing SceneTextures / UserSceneTextures in Custom HLSL (see "SceneTextureFetch" macro).

Editing / debug features:
* Material editor preview window automatically includes other edited materials that feed inputs into the current material, allowing multi-pass effects to be interactively edited.
* Debug display of post process passes with UserSceneTexture inputs or output via r.PostProcessing.UserSceneTextureDebug.  Allows seeing order, location, and priority of passes, plus names of material, inputs, and output, and whether an output is written with blending.
* Debug display pops up automatically on error conditions (missing input, unused output), improving discoverability.  Suppressed by DisableAllScreenMessages (or setting CVar itself to zero).
* FRDGViewableResource can now be given dynamically generated heap allocated debug names (indicated by setting a flag immediately after construction), instead of only supporting static const strings.  Allows UserSceneTexture names to be displayed in debug displays, VisualizeTexture, GPU captures, and GPU dumps, instead of every resource getting the same name.

Mobile doesn't support post process domain materials at all, so the feature is not relevant there.  Tested on scene captures, split screen, and both legacy and new material translate code paths.  An existing bug was fixed where rendering post process materials with blending before bloom would crash, due to the output not being allocated with the render target flag set.

#rb eric.renaudhoude, Ruslan.Idrisov

[CL 34055494 by jason hoerner in ue5-main branch]
2024-06-01 13:02:37 -04:00

198 lines
6.9 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
/*=============================================================================
DummyRenderResource.h: Frequently used rendering resources
=============================================================================*/
#pragma once
#include "GlobalShader.h"
#include "HAL/Platform.h"
#include "Math/Vector2D.h"
#include "Math/Vector4.h"
#include "PipelineStateCache.h"
#include "RHI.h"
#include "RHIDefinitions.h"
#include "RenderResource.h"
#include "Serialization/MemoryLayout.h"
#include "Shader.h"
#include "ShaderParameterMacros.h"
#include "ShaderParameterStruct.h"
#include "Templates/UnrealTemplate.h"
#include "DataDrivenShaderPlatformInfo.h"
class FPointerTableBase;
class FRDGTexture;
/** The vertex data used to filter a texture. */
struct FFilterVertex
{
public:
FVector4f Position;
FVector2f UV;
};
/** The filter vertex declaration resource type. */
class FFilterVertexDeclaration : public FRenderResource
{
public:
FVertexDeclarationRHIRef VertexDeclarationRHI;
/** Destructor. */
virtual ~FFilterVertexDeclaration() {}
virtual void InitRHI(FRHICommandListBase& RHICmdList)
{
FVertexDeclarationElementList Elements;
uint16 Stride = sizeof(FFilterVertex);
Elements.Add(FVertexElement(0, STRUCT_OFFSET(FFilterVertex, Position), VET_Float4, 0, Stride));
Elements.Add(FVertexElement(0, STRUCT_OFFSET(FFilterVertex, UV), VET_Float2, 1, Stride));
VertexDeclarationRHI = PipelineStateCache::GetOrCreateVertexDeclaration(Elements);
}
virtual void ReleaseRHI()
{
VertexDeclarationRHI.SafeRelease();
}
};
extern RENDERCORE_API TGlobalResource<FFilterVertexDeclaration, FRenderResource::EInitPhase::Pre> GFilterVertexDeclaration;
/** The empty vertex declaration resource type. */
class FEmptyVertexDeclaration : public FRenderResource
{
public:
FVertexDeclarationRHIRef VertexDeclarationRHI;
/** Destructor. */
virtual ~FEmptyVertexDeclaration() {}
virtual void InitRHI(FRHICommandListBase& RHICmdList)
{
FVertexDeclarationElementList Elements;
VertexDeclarationRHI = PipelineStateCache::GetOrCreateVertexDeclaration(Elements);
}
virtual void ReleaseRHI()
{
VertexDeclarationRHI.SafeRelease();
}
};
extern RENDERCORE_API TGlobalResource<FEmptyVertexDeclaration, FRenderResource::EInitPhase::Pre> GEmptyVertexDeclaration;
/**
* Static vertex and index buffer used for 2D screen rectangles.
*/
class FScreenRectangleVertexBuffer : public FVertexBuffer
{
public:
/** Initialize the RHI for this rendering resource */
void InitRHI(FRHICommandListBase& RHICmdList) override;
};
extern RENDERCORE_API TGlobalResource<FScreenRectangleVertexBuffer, FRenderResource::EInitPhase::Pre> GScreenRectangleVertexBuffer;
class FScreenRectangleIndexBuffer : public FIndexBuffer
{
public:
/** Initialize the RHI for this rendering resource */
void InitRHI(FRHICommandListBase& RHICmdList) override;
};
extern RENDERCORE_API TGlobalResource<FScreenRectangleIndexBuffer, FRenderResource::EInitPhase::Pre> GScreenRectangleIndexBuffer;
/** Vertex shader to draw a screen quad that works on all platforms. Does not have any shader parameters.
* The pixel shader should just use SV_Position. */
class FScreenVertexShaderVS : public FGlobalShader
{
DECLARE_EXPORTED_GLOBAL_SHADER(FScreenVertexShaderVS, RENDERCORE_API);
SHADER_USE_PARAMETER_STRUCT(FScreenVertexShaderVS, FGlobalShader);
BEGIN_SHADER_PARAMETER_STRUCT(FParameters, )
END_SHADER_PARAMETER_STRUCT()
};
/** Vertex shader to draw an instanced quad covering all the viewports (SV_ViewportArrayIndex is output for each SV_InstanceID). Does not have any shader parameters.
* The pixel shader should just use SV_Position. */
class FInstancedScreenVertexShaderVS : public FScreenVertexShaderVS
{
DECLARE_GLOBAL_SHADER(FInstancedScreenVertexShaderVS);
SHADER_USE_PARAMETER_STRUCT(FInstancedScreenVertexShaderVS, FScreenVertexShaderVS);
static bool ShouldCompilePermutation(const FGlobalShaderPermutationParameters& Parameters);
static void ModifyCompilationEnvironment(const FGlobalShaderPermutationParameters& Parameters, FShaderCompilerEnvironment& OutEnvironment)
{
FScreenVertexShaderVS::ModifyCompilationEnvironment(Parameters, OutEnvironment);
OutEnvironment.SetDefine(TEXT("SCREEN_VS_FOR_INSTANCED_VIEWS"), 1);
}
BEGIN_SHADER_PARAMETER_STRUCT(FParameters, )
END_SHADER_PARAMETER_STRUCT()
};
/** Vertex shader to draw a quad covering all the viewports with mobile multi view (SV_RenderTargetArrayIndex is output for each SV_InstanceID if using the multi view fallback path). Does not have any shader parameters.
* The pixel shader should expect UV in TEXCOORD0 (and EyeIndex in TEXCOORD1 if using the mobile multi view fallback path). */
class FMobileMultiViewVertexShaderVS : public FScreenVertexShaderVS
{
DECLARE_EXPORTED_GLOBAL_SHADER(FMobileMultiViewVertexShaderVS, RENDERCORE_API);
SHADER_USE_PARAMETER_STRUCT(FMobileMultiViewVertexShaderVS, FScreenVertexShaderVS);
static bool ShouldCompilePermutation(const FGlobalShaderPermutationParameters& Parameters);
static void ModifyCompilationEnvironment(const FGlobalShaderPermutationParameters& Parameters, FShaderCompilerEnvironment& OutEnvironment)
{
FScreenVertexShaderVS::ModifyCompilationEnvironment(Parameters, OutEnvironment);
OutEnvironment.SetDefine(TEXT("SCREEN_VS_FOR_MOBILE_MULTI_VIEW"), 1);
}
BEGIN_SHADER_PARAMETER_STRUCT(FParameters, )
END_SHADER_PARAMETER_STRUCT()
};
/** Pixel shader to copy pixels from src to dst performing a format change that works on all platforms. */
class FCopyRectPS : public FGlobalShader
{
DECLARE_EXPORTED_GLOBAL_SHADER(FCopyRectPS, RENDERCORE_API);
SHADER_USE_PARAMETER_STRUCT(FCopyRectPS, FGlobalShader);
BEGIN_SHADER_PARAMETER_STRUCT(FParameters, )
SHADER_PARAMETER_RDG_TEXTURE(Texture2D, InputTexture)
SHADER_PARAMETER_SAMPLER(SamplerState, InputSampler)
RENDER_TARGET_BINDING_SLOTS()
END_SHADER_PARAMETER_STRUCT()
};
/** Pixel shader to copy pixels from src to dst performing a format change that works on all platforms -- variation that accepts SRV */
class FCopyRectSrvPS : public FGlobalShader
{
DECLARE_EXPORTED_GLOBAL_SHADER(FCopyRectSrvPS, RENDERCORE_API);
SHADER_USE_PARAMETER_STRUCT(FCopyRectSrvPS, FGlobalShader);
BEGIN_SHADER_PARAMETER_STRUCT(FParameters, )
SHADER_PARAMETER_RDG_TEXTURE_SRV(Texture2D, InputTexture)
SHADER_PARAMETER_SAMPLER(SamplerState, InputSampler)
RENDER_TARGET_BINDING_SLOTS()
END_SHADER_PARAMETER_STRUCT()
};
/** Vertex shader to perform a screen rotation for Vulkan pre-rotation on mobile. */
class FImagePreTransformVS : public FGlobalShader
{
DECLARE_EXPORTED_GLOBAL_SHADER(FImagePreTransformVS, RENDERCORE_API);
SHADER_USE_PARAMETER_STRUCT(FImagePreTransformVS, FGlobalShader);
static bool ShouldCompilePermutation(const FGlobalShaderPermutationParameters& Parameters)
{
return IsVulkanMobilePlatform(Parameters.Platform) || IsVulkanMobileSM5Platform(Parameters.Platform);
}
BEGIN_SHADER_PARAMETER_STRUCT(FParameters, )
SHADER_PARAMETER(FVector4f, PreTransform)
END_SHADER_PARAMETER_STRUCT()
};