Ensures during enabled rhi validation

We are looking into various GPU and rendering-related crashes in our codebase, which are mostly random crashes. To investigate them, we run a game with `-rhivalidation -rdgimmediate -forcerhibypass -onethread`. In the beginning of the game engine issues following warning:

`--------------------------------------------------------------------
RHI Resource Transition Validation Error

Attempted to access resource “Nanite.MaterialDepthDataBuffer” (0x0000021629E61EA8) (Whole Resource) from a hardware unit it is not currently accessible from. A resource transition is required.
— Allowed access states for this resource are: UAVCompute|UAVGraphics
— Required access states are: SRVGraphics
— Allowed pipelines for this resource are: Graphics
— Required pipelines are: Graphics

Breadcrumbs: Frame 711/Scene/Nanite::EmitDepthTargets/Emit Material Depth
--------------------------------------------------------------------`Does it something we need to investigate further for that?

Steps to Reproduce

Callstack:

FValidationRHI::ReportValidationFailure(const wchar_t * InMessage) Line 739 C++ RHIValidation::FSubresourceState::Assert(RHIValidation::FResource * Resource, const RHIValidation::FSubresourceIndex & SubresourceIndex, const RHIValidation::FState & RequiredState, bool bAllowAllUAVsOverlap) Line 1592 C++ RHIValidation::FOperation::Replay::__l9::<lambda>(RHIValidation::FSubresourceState &) Line 1776 C++ Invoke(RHIValidation::FOperation::Replay::__l9::void <lambda>(void) &) Line 47 C++ UE::Core::Private::Function::TFunctionRefCaller<RHIValidation::FOperation::Replay’::9'::void <lambda>(void),void __cdecl(RHIValidation::FSubresourceState &,RHIValidation::FSubresourceIndex const &)>::Call(void * Obj, RHIValidation::FSubresourceState & <Params_0>, const RHIValidation::FSubresourceIndex & <Params_1>) Line 475 C++ RHIValidation::FResource::EnumerateSubresources(const RHIValidation::FSubresourceRange & SubresourceRange, TFunctionRef<void __cdecl(RHIValidation::FSubresourceState &,RHIValidation::FSubresourceIndex const &)> Callback, bool bBeginTransition) Line 1648 C++ RHIValidation::FOperation::Replay(ERHIPipeline Pipeline, bool & bAllowAllUAVsOverlap, TArray<wchar_t const *,TConcurrentLinearArrayAllocator<FDefaultBlockAllocationTag>> & Breadcrumbs) Line 1830 C++ RHIValidation::FTracker::AddOp(const RHIValidation::FOperation & Op) Line 1838 C++ ValidateShaderParameters(RHIValidation::FTracker * Tracker, RHIValidation::FStaticUniformBuffers & StaticUniformBuffers, TArrayView<FRHIShaderParameterResource const ,int> InParameters, ERHIAccess InRequiredAccess, RHIValidation::EUAVMode InRequiredUAVMode) Line 21 C++ FValidationContext::RHISetShaderParameters(FRHIGraphicsShader * Shader, TArrayView<unsigned char const ,int> InParametersData, TArrayView<FRHIShaderParameter const ,int> InParameters, TArrayView<FRHIShaderParameterResource const ,int> InResourceParameters, TArrayView<FRHIShaderParameterResource const ,int> InBindlessParameters) Line 804 C++ FRHICommandList::SetShaderParameters(FRHIGraphicsShader *) Line 3478 C++ SetShaderParametersInternal<FRHICommandList,FRHIGraphicsShader>(FRHICommandList & RHICmdList, FRHIGraphicsShader * ShaderRHI, const FShaderParameterBindings & Bindings, const FShaderParametersMetadata * ParametersMetadata, const void * InParametersData) Line 771 C++ SetShaderParameters(FRHICommandList &) Line 250 C++ SetShaderParameters<FRHICommandList,FEmitMaterialDepthPS,FRHIPixelShader>(FRHICommandList & RHICmdList, const TShaderRefBase<FEmitMaterialDepthPS,FShaderMapPointerTable> & Shader, FRHIPixelShader * ShaderRHI, const FEmitMaterialDepthPS::FParameters & Parameters) Line 258 C++ FPixelShaderUtils::DrawFullscreenPixelShader<FEmitMaterialDepthPS>(FRHICommandList & RHICmdList, const FGlobalShaderMap * GlobalShaderMap, const TShaderRefBase<FEmitMaterialDepthPS,FShaderMapPointerTable> & PixelShader, const FEmitMaterialDepthPS::FParameters & Parameters, const UE::Math::TIntRect<int> & Viewport, FRHIBlendState * BlendState, FRHIRasterizerState * RasterizerState, FRHIDepthStencilState * DepthStencilState, unsigned int StencilRef) Line 112 C++ FPixelShaderUtils::AddFullscreenPass::__l2::<lambda>(FRHICommandList &) Line 138 C++ TRDGLambdaPass<FEmitMaterialDepthPS::FParameters,FPixelShaderUtils::AddFullscreenPass‘::2'::void <lambda>(const TArray<FString,TSizedDefaultAllocator<32>> &)>::ExecuteLambdaFunc(FRHIComputeCommandList &) Line 602 C++ TRDGLambdaPass<FEmitMaterialDepthPS::FParameters,FPixelShaderUtils::AddFullscreenPass’::2'::void <lambda>(const TArray<FString,TSizedDefaultAllocator<32>> &)>::Execute(FRHIComputeCommandList & RHICmdList) Line 616 C++ FRDGBuilder::ExecutePass(FRDGPass * Pass, FRHIComputeCommandList & RHICmdListPass) Line 2938 C++ FRDGBuilder::SetupAuxiliaryPasses(FRDGPass * Pass) Line 2431 C++ FRDGBuilder::AddPassInternal<FEmitMaterialDepthPS::FParameters,FPixelShaderUtils::AddFullscreenPass'::2'::void <lambda>(const TArray<FString,TSizedDefaultAllocator<32>> &)>(FRDGEventName && Name, const FShaderParametersMetadata * ParametersMetadata, const FEmitMaterialDepthPS::FParameters * ParameterStruct, ERDGPassFlags Flags, FPixelShaderUtils::AddFullscreenPass::__l2::void <lambda>(const TArray<FString,TSizedDefaultAllocator<32>> &) && ExecuteLambda) Line 270 C++ FRDGBuilder::AddPass(FRDGEventName &&) Line 290 C++ FPixelShaderUtils::AddFullscreenPass(FRDGBuilder & GlobalShaderMap, const FGlobalShaderMap * BlendState, FRDGEventName && RasterizerState, const TShaderRefBase<FEmitMaterialDepthPS,FShaderMapPointerTable> & StencilRef, FEmitMaterialDepthPS::FParameters *) Line 132 C++ Nanite::EmitDepthTargets(FRDGBuilder & GraphBuilder, const FScene & Scene, const FViewInfo & View, const UE::Math::TIntVector4<int> & PageConstants, FRDGBuffer * VisibleClustersSWHW, FRDGBuffer * ViewsBuffer, FRDGTexture * SceneDepth, FRDGTexture * VisBuffer64, FRDGTexture * VelocityBuffer, FRDGTexture * & OutMaterialDepth, FRDGTexture * & OutMaterialResolve, bool bStencilMask) Line 1678 C++ FDeferredShadingSceneRenderer::Render(FRDGBuilder & GraphBuilder) Line 4323 C++

Hi,

this RHI validation error seems similar to the one reported in [this [Content removed] which is also related to version 5.2. From that thread, it appears that adding -norhithread would avoid a crash.

The issue has probably been resolved in later engine versions (5.3+) with this commit which made some changes in Nanite’s EmitDepthTargets. Is it possible to upgrade the project to a newer version of the engine and test again?

Best,

Sam

Sorry for raising it again, but we still would like to know more about this warning

> From that thread, it appears that adding***-norhithread***would avoid a crash.

Having that switch doesn’t prevent validation errors to be issued in our case.

> The issue has probably been resolved in later engine versions (5.3+) withthis commitwhich made some changes in Nanite’s EmitDepthTargets

It the thread you mentioned they found they use `vr.InstancedStereo` switched on, and after they switched it off - it prevented engine from issuing a warning. In our case we have it switched off already. A description on mentioned commit also says about ISR specifically.

> Is it possible to upgrade the project to a newer version of the engine and test again?

Unfortunately no, currently we can afford only cherry-picks.

Hi,

It looks as though this commit was intended to fix this issue. It may be worth investigating what cherry picking this change would involve for your code base.

Thanks,

Hayden