Files
UnrealEngineUWP/Engine/Source/Runtime/RenderCore/Private/CommonRenderResources.cpp

78 lines
3.4 KiB
C++
Raw Normal View History

// Copyright Epic Games, Inc. All Rights Reserved.
/*=============================================================================
DummyRenderResources.cpp: Implementations of frequently used render resources.
=============================================================================*/
#include "CommonRenderResources.h"
#include "Containers/DynamicRHIResourceArray.h"
#include "RHIResourceUtils.h"
#include "StereoRenderUtils.h"
TGlobalResource<FFilterVertexDeclaration, FRenderResource::EInitPhase::Pre> GFilterVertexDeclaration;
TGlobalResource<FEmptyVertexDeclaration, FRenderResource::EInitPhase::Pre> GEmptyVertexDeclaration;
TGlobalResource<FScreenRectangleVertexBuffer, FRenderResource::EInitPhase::Pre> GScreenRectangleVertexBuffer;
TGlobalResource<FScreenRectangleIndexBuffer, FRenderResource::EInitPhase::Pre> GScreenRectangleIndexBuffer;
IMPLEMENT_GLOBAL_SHADER(FScreenVertexShaderVS, "/Engine/Private/Tools/FullscreenVertexShader.usf", "MainVS", SF_Vertex);
IMPLEMENT_GLOBAL_SHADER(FInstancedScreenVertexShaderVS, "/Engine/Private/Tools/FullscreenVertexShader.usf", "MainVS", SF_Vertex);
IMPLEMENT_GLOBAL_SHADER(FMobileMultiViewVertexShaderVS, "/Engine/Private/Tools/FullscreenVertexShader.usf", "MainVS", SF_Vertex);
IMPLEMENT_GLOBAL_SHADER(FCopyRectPS, "/Engine/Private/ScreenPass.usf", "CopyRectPS", SF_Pixel);
[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
IMPLEMENT_GLOBAL_SHADER(FCopyRectSrvPS, "/Engine/Private/ScreenPass.usf", "CopyRectPS", SF_Pixel);
IMPLEMENT_GLOBAL_SHADER(FImagePreTransformVS, "/Engine/Private/Tools/FullscreenVertexShader.usf", "MainForPreTransform", SF_Vertex);
bool FInstancedScreenVertexShaderVS::ShouldCompilePermutation(const FGlobalShaderPermutationParameters& Parameters)
{
UE::StereoRenderUtils::FStereoShaderAspects Aspects(Parameters.Platform);
return Aspects.IsInstancedMultiViewportEnabled();
}
bool FMobileMultiViewVertexShaderVS::ShouldCompilePermutation(const FGlobalShaderPermutationParameters& Parameters)
{
UE::StereoRenderUtils::FStereoShaderAspects Aspects(Parameters.Platform);
return Aspects.IsMobileMultiViewEnabled();
}
static const FFilterVertex GScreenRectangleVertexBufferData[] =
{
{ FVector4f(1, 1, 0, 1), FVector2f(1, 1) },
{ FVector4f(0, 1, 0, 1), FVector2f(0, 1) },
{ FVector4f(1, 0, 0, 1), FVector2f(1, 0) },
{ FVector4f(0, 0, 0, 1), FVector2f(0, 0) },
//The final two vertices are used for the triangle optimization (a single triangle spans the entire viewport )
{ FVector4f(-1, 1, 0, 1), FVector2f(-1, 1) },
{ FVector4f(1, -1, 0, 1), FVector2f(1, -1) },
};
void FScreenRectangleVertexBuffer::InitRHI(FRHICommandListBase& RHICmdList)
{
// Create vertex buffer. Fill buffer with initial data upon creation
VertexBufferRHI = UE::RHIResourceUtils::CreateVertexBufferFromArray(
RHICmdList,
TEXT("FScreenRectangleVertexBuffer"),
EBufferUsageFlags::Static,
MakeConstArrayView(GScreenRectangleVertexBufferData)
);
}
static const uint16 GScreenRectangleIndexBufferData[] =
{
0, 1, 2, 2, 1, 3, // [0 .. 5] Full screen quad with 2 triangles
0, 4, 5, // [6 .. 8] Full screen triangle
3, 2, 1 // [9 .. 11] Full screen rect defined with TL, TR, BL corners
};
void FScreenRectangleIndexBuffer::InitRHI(FRHICommandListBase& RHICmdList)
{
// Create index buffer. Fill buffer with initial data upon creation
IndexBufferRHI = UE::RHIResourceUtils::CreateIndexBufferFromArray(
RHICmdList,
TEXT("FScreenRectangleIndexBuffer"),
EBufferUsageFlags::Static,
MakeConstArrayView(GScreenRectangleIndexBufferData)
);
}