You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
Serialize the payload size as part of the raytracing shader so it can be examined in the RHI layer. Validate that the RTPSO is configured with the appropriate payload size. Add macros to ensure the payloads have the expected size Ensure that all raytracing pipelines explicitly bind a miss shader Add a shared shader header to implement static asserts for those shader compilers that support them (like dxc). Fix payload type on main deferred reflection raygen shader Fix incorrect raygen shader included in the deferred RTPSO list for RTGI Don't add builtin shaders to the RTPSO from the RHI layer as these are unlikely to ever match the required payload type Add new method to register payload types so that plugins can more easily describe custom payloads they may be using (up to a maximum of 32 unique payload types since we use a bitmask to represent payload sets). #rb Yuriy.ODonnell #jira UE-157946 #preflight 636aff4363037c102679f13a #preflight 63869dde170bc34a93e8c90e [CL 23337139 by chris kulla in ue5-main branch]
68 lines
3.2 KiB
C++
68 lines
3.2 KiB
C++
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
#include "BuiltInRayTracingShaders.h"
|
|
#include "ShaderParameterUtils.h"
|
|
#include "PipelineStateCache.h"
|
|
|
|
#if RHI_RAYTRACING
|
|
|
|
#include "RayTracingPayloadType.h"
|
|
|
|
IMPLEMENT_RT_PAYLOAD_TYPE(ERayTracingPayloadType::Default, 24);
|
|
IMPLEMENT_RT_PAYLOAD_TYPE(ERayTracingPayloadType::RayTracingMaterial, 64);
|
|
|
|
IMPLEMENT_GLOBAL_SHADER( FDefaultPayloadMS, "/Engine/Private/RayTracing/RayTracingBuiltInShaders.usf", "DefaultPayloadMS", SF_RayMiss);
|
|
IMPLEMENT_GLOBAL_SHADER( FPackedMaterialClosestHitPayloadMS, "/Engine/Private/RayTracing/RayTracingBuiltInShaders.usf", "PackedMaterialClosestHitPayloadMS", SF_RayMiss);
|
|
IMPLEMENT_GLOBAL_SHADER(FRayTracingDispatchDescCS, "/Engine/Private/RayTracing/RayTracingDispatchDesc.usf", "RayTracingDispatchDescCS", SF_Compute);
|
|
|
|
|
|
ERayTracingPayloadType FDefaultPayloadMS::GetRayTracingPayloadType(const int32 PermutationId)
|
|
{
|
|
return ERayTracingPayloadType::Default;
|
|
}
|
|
|
|
ERayTracingPayloadType FPackedMaterialClosestHitPayloadMS::GetRayTracingPayloadType(const int32 PermutationId)
|
|
{
|
|
return ERayTracingPayloadType::RayTracingMaterial;
|
|
}
|
|
|
|
|
|
void FRayTracingDispatchDescCS::Dispatch(FRHICommandList& RHICmdList,
|
|
const void* DispatchDescInput, uint32 DispatchDescSize, uint32 DispatchDescDimensionsOffset,
|
|
FRHIShaderResourceView* DispatchDimensionsSRV, uint32 DimensionsBufferOffset,
|
|
FRHIUnorderedAccessView* DispatchDescOutputUAV)
|
|
{
|
|
const uint32 DispatchDescSizeDwords = DispatchDescSize / 4;
|
|
const uint32 DispatchDescDimensionsOffsetDwords = DispatchDescDimensionsOffset / 4;
|
|
|
|
checkf(DimensionsBufferOffset % 4 == 0, TEXT("Dispatch dimensions buffer offset must be DWORD-aligned"));
|
|
const uint32 DimensionsBufferOffsetDwords = DimensionsBufferOffset / 4;
|
|
|
|
check(DispatchDescSizeDwords <= DispatchDescMaxSizeDwords);
|
|
|
|
TShaderMapRef<FRayTracingDispatchDescCS> ComputeShader(GetGlobalShaderMap(GMaxRHIFeatureLevel));
|
|
FRHIComputeShader* ShaderRHI = ComputeShader.GetComputeShader();
|
|
SetComputePipelineState(RHICmdList, ShaderRHI);
|
|
|
|
static_assert(DispatchDescMaxSizeDwords % 4 == 0, "DispatchDescMaxSizeDwords must be a multiple of 4");
|
|
static constexpr uint32 DispatchDescMaxSizeUint4s = DispatchDescMaxSizeDwords / 4;
|
|
|
|
FUintVector4 DispatchDescData[DispatchDescMaxSizeUint4s] = {};
|
|
FMemory::Memcpy(DispatchDescData, DispatchDescInput, DispatchDescSize);
|
|
|
|
SetShaderValueArray(RHICmdList, ShaderRHI, ComputeShader->DispatchDescInputParam, DispatchDescData, DispatchDescMaxSizeUint4s);
|
|
SetShaderValue(RHICmdList, ShaderRHI, ComputeShader->DispatchDescSizeDwordsParam, DispatchDescSizeDwords);
|
|
SetShaderValue(RHICmdList, ShaderRHI, ComputeShader->DispatchDescDimensionsOffsetDwordsParam, DispatchDescDimensionsOffsetDwords);
|
|
SetShaderValue(RHICmdList, ShaderRHI, ComputeShader->DimensionsBufferOffsetDwordsParam, DimensionsBufferOffsetDwords);
|
|
|
|
SetSRVParameter(RHICmdList, ShaderRHI, ComputeShader->DispatchDimensionsParam, DispatchDimensionsSRV);
|
|
SetUAVParameter(RHICmdList, ShaderRHI, ComputeShader->DispatchDescOutputParam, DispatchDescOutputUAV);
|
|
|
|
RHICmdList.DispatchComputeShader(1, 1, 1);
|
|
|
|
SetSRVParameter(RHICmdList, ShaderRHI, ComputeShader->DispatchDimensionsParam, nullptr);
|
|
SetUAVParameter(RHICmdList, ShaderRHI, ComputeShader->DispatchDescOutputParam, nullptr);
|
|
}
|
|
|
|
#endif // RHI_RAYTRACING
|