Files
UnrealEngineUWP/Engine/Source/Runtime/RenderCore/Private/CommonRenderResources.cpp
christopher waters 576fa781e0 More upload helpers
- Adding FRHIResourceCreateInfoUploadArray to the new RHIResourceUtils.h
- FRHIResourceCreateInfoUploadArray is a FRHIResourceCreateInfo type that manages its own FResourceArrayUploadArrayView, meaning it can be used to replace the multi-line code it previously took to upload data from a container type.
- Adding UE::RHIResourceUtils::CreateBufferWithData to further reduce the code it takes to create a buffer with initial data.

#rb jeannoe.morissette, Yuriy.ODonnell

[CL 34084534 by christopher waters in ue5-main branch]
2024-06-03 22:54:22 -04:00

70 lines
3.5 KiB
C++

// 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);
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
FRHIResourceCreateInfoUploadArray CreateInfo(TEXT("FScreenRectangleVertexBuffer"), MakeArrayView(GScreenRectangleVertexBufferData));
VertexBufferRHI = RHICmdList.CreateVertexBuffer(CreateInfo.GetResourceDataSize(), BUF_Static, CreateInfo);
}
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
FRHIResourceCreateInfoUploadArray CreateInfo(TEXT("FScreenRectangleIndexBuffer"), MakeArrayView(GScreenRectangleIndexBufferData));
IndexBufferRHI = RHICmdList.CreateIndexBuffer(sizeof(uint16), CreateInfo.GetResourceDataSize(), BUF_Static, CreateInfo);
}