Files
UnrealEngineUWP/Engine/Source/Runtime/RenderCore/Private/PixelShaderUtils.cpp
Krzysztof Narkowicz f94472aea1 Lumen surface cache compression
* First all cards are allocated to a temporary atlas of fixed size set by r.LumenScene.CardCaptureAtlasFactor
* After cards are captured into temporary atlas, they are compressed into final BC compressed atlas. Compression can be disabled with r.LumenScene.SurfaceCache.Compress
* Atlas clears were also converted to support clearing compressed surfaces
* Atlas capture operations work on uploaded rect list, instead of a GPU generated card list
* Renamed r.LumenSurfaceCache.* to r.LumenScene.SurfaceCache.*
* Renamed LumenSceneLighting.usf to LumenSurfaceCache.usf
* Renamed LumenScenePrefilter.cpp to LumenSurfaceCache.cpp

Cuts down VRAM memory usage by 160mb
Compression performance on console: ~0.18ms for 1M texels (~0.9ms with UAV aliasing path, which is currently disabled due to missing pieces in RHI)

[CL 16160800 by Krzysztof Narkowicz in ue5-main branch]
2021-04-29 15:30:04 -04:00

92 lines
3.4 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
/*=============================================================================
PixelShaderUtils.cpp: Implementations of utilities for pixel shaders.
=============================================================================*/
#include "PixelShaderUtils.h"
#include "CommonRenderResources.h"
#include "RenderGraph.h"
IMPLEMENT_SHADER_TYPE(, FPixelShaderUtils::FRasterizeToRectsVS, TEXT("/Engine/Private/RenderGraphUtilities.usf"), TEXT("RasterizeToRectsVS"), SF_Vertex);
bool FPixelShaderUtils::FRasterizeToRectsVS::ShouldCompilePermutation(const FGlobalShaderPermutationParameters& Parameters)
{
return IsFeatureLevelSupported(Parameters.Platform, ERHIFeatureLevel::SM5);
}
BEGIN_SHADER_PARAMETER_STRUCT(FUploadRectBuffer, )
RDG_BUFFER_ACCESS(RectBuffer, ERHIAccess::CopyDest)
END_SHADER_PARAMETER_STRUCT()
// static
void FPixelShaderUtils::DrawFullscreenTriangle(FRHICommandList& RHICmdList, uint32 InstanceCount)
{
RHICmdList.SetStreamSource(0, GScreenRectangleVertexBuffer.VertexBufferRHI, 0);
RHICmdList.DrawIndexedPrimitive(
GScreenRectangleIndexBuffer.IndexBufferRHI,
/*BaseVertexIndex=*/ 0,
/*MinIndex=*/ 0,
/*NumVertices=*/ 3,
/*StartIndex=*/ 6,
/*NumPrimitives=*/ 1,
/*NumInstances=*/ InstanceCount);
}
// static
void FPixelShaderUtils::DrawFullscreenQuad(FRHICommandList& RHICmdList, uint32 InstanceCount)
{
RHICmdList.SetStreamSource(0, GScreenRectangleVertexBuffer.VertexBufferRHI, 0);
RHICmdList.DrawIndexedPrimitive(
GScreenRectangleIndexBuffer.IndexBufferRHI,
/*BaseVertexIndex=*/ 0,
/*MinIndex=*/ 0,
/*NumVertices=*/ 4,
/*StartIndex=*/ 0,
/*NumPrimitives=*/ 2,
/*NumInstances=*/ InstanceCount);
}
// static
void FPixelShaderUtils::InitFullscreenPipelineState(
FRHICommandList& RHICmdList,
const FGlobalShaderMap* GlobalShaderMap,
const TShaderRef<FShader>& PixelShader,
FGraphicsPipelineStateInitializer& GraphicsPSOInit)
{
TShaderMapRef<FScreenVertexShaderVS> VertexShader(GlobalShaderMap);
RHICmdList.ApplyCachedRenderTargets(GraphicsPSOInit);
GraphicsPSOInit.BlendState = TStaticBlendState<>::GetRHI();
GraphicsPSOInit.RasterizerState = TStaticRasterizerState<>::GetRHI();
GraphicsPSOInit.DepthStencilState = TStaticDepthStencilState<false, CF_Always>::GetRHI();
GraphicsPSOInit.BoundShaderState.VertexDeclarationRHI = GFilterVertexDeclaration.VertexDeclarationRHI;
GraphicsPSOInit.BoundShaderState.VertexShaderRHI = VertexShader.GetVertexShader();
GraphicsPSOInit.BoundShaderState.PixelShaderRHI = PixelShader.GetPixelShader();
GraphicsPSOInit.PrimitiveType = PT_TriangleList;
}
void FPixelShaderUtils::UploadRectBuffer(FRDGBuilder& GraphBuilder,
const TArray<FUintVector4, SceneRenderingAllocator>& RectArray,
FRDGBufferRef RectBuffer)
{
FUploadRectBuffer* PassParameters = GraphBuilder.AllocParameters<FUploadRectBuffer>();
PassParameters->RectBuffer = RectBuffer;
const uint32 RectArraySizeInBytes = RectArray.GetTypeSize() * RectArray.Num();
const void* RectArrayDataPtr = RectArray.GetData();
GraphBuilder.AddPass(
RDG_EVENT_NAME("UploadRectBuffer"),
PassParameters,
ERDGPassFlags::Copy,
[PassParameters, RectArraySizeInBytes, RectArrayDataPtr](FRHICommandListImmediate& RHICmdList)
{
void* WritePointer = RHILockBuffer(PassParameters->RectBuffer->GetRHI(), 0, RectArraySizeInBytes, RLM_WriteOnly);
FPlatformMemory::Memcpy(WritePointer, RectArrayDataPtr, RectArraySizeInBytes);
RHIUnlockBuffer(PassParameters->RectBuffer->GetRHI());
});
}