Niagara allocating virtual texture between Begin/End Render

5.7 introduced a new UNiagaraDataInterfaceVirtualTextureSample which is calling AquireAllocatedVT(). This is happening during BeginInitViews which is in between FVirtualTextureSystem::Get().BeginUpdate and FVirtualTextureSystem::Get().EndUpdate in DeferredShadingRenderer.cpp. This will lead to hitting the check(!bUpdating); inside FVirtualTextureSystem::LockTile.

[Attachment Removed]

Some more info:

This texture is “BakedWaterSurfaceNormalTexture”, which looks to be from \Engine\Plugins\Experimental\WaterAdvanced\Source\WaterAdvanced\Private\ShallowWaterRiverActor.cpp

Here is the full callstack:

UnrealEditor-Renderer.dll!FVirtualTextureSystem::LockTile(const FVirtualTextureLocalTile & Tile) Line 1212 C++

UnrealEditor-Renderer.dll!FAllocatedVirtualTexture::LockOrUnlockTiles(FVirtualTextureSystem * InSystem, bool bLock) Line 219 C++

UnrealEditor-Renderer.dll!FAllocatedVirtualTexture::FAllocatedVirtualTexture(FRHICommandListBase & RHICmdList, FVirtualTextureSystem * InSystem, unsigned int InFrame, const FAllocatedVTDescription & InDesc, FVirtualTextureProducer * const * InProducers, unsigned int InBlockWidthInTiles, unsigned int InBlockHeightInTiles, unsigned int InWidthInBlocks, unsigned int InHeightInBlocks, unsigned int InDepthInTiles) Line 83 C++

UnrealEditor-Renderer.dll!FVirtualTextureSystem::AllocateVirtualTexture(FRHICommandListBase & RHICmdList, const FAllocatedVTDescription & Desc) Line 721 C++

UnrealEditor-Engine.dll!FVirtualTexture2DResource::AcquireAllocatedVT() Line 1881 C++

> UnrealEditor-Niagara.dll!UNiagaraDataInterfaceVirtualTextureSample::SetShaderParameters(const FNiagaraDataInterfaceSetShaderParametersContext & Context) Line 352 C++

UnrealEditor-Niagara.dll!FNiagaraGpuComputeDispatch::SetDataInterfaceParameters(FRDGBuilder & GraphBuilder, const FNiagaraGPUSystemTick & Tick, const FNiagaraComputeInstanceData & InstanceData, const TShaderRefBase<FNiagaraShader,FNiagaraShaderMapPointerTable> & ComputeShader, const FNiagaraSimStageData & SimStageData, const FNiagaraShaderScriptParametersMetadata & NiagaraShaderParametersMetadata, unsigned char * ParametersStructure) Line 2505 C++

UnrealEditor-Niagara.dll!FNiagaraGpuComputeDispatch::DispatchStage(FRDGBuilder & GraphBuilder, const FNiagaraGPUSystemTick & Tick, const FNiagaraComputeInstanceData & InstanceData, const FNiagaraSimStageData & SimStageData) Line 1708 C++

UnrealEditor-Niagara.dll!FNiagaraGpuComputeDispatch::ExecuteTicks(FRDGBuilder & GraphBuilder, TStridedView<FSceneView const ,int> Views, ENiagaraGpuComputeTickStage::Type TickStage) Line 1295 C++

UnrealEditor-Niagara.dll!FNiagaraGpuComputeDispatch::PostInitViews(FRDGBuilder & GraphBuilder, TStridedView<FSceneView const ,int> Views, bool bAllowGPUParticleUpdate) Line 2096 C++

UnrealEditor-Engine.dll!FFXSystemSet::PostInitViews(FRDGBuilder & GraphBuilder, TStridedView<FSceneView const ,int> Views, bool bAllowGPUParticleUpdate) Line 127 C++

UnrealEditor-Renderer.dll!FDeferredShadingSceneRenderer::BeginInitViews(FRDGBuilder & GraphBuilder, const FSceneTexturesConfig & SceneTexturesConfig, FInstanceCullingManager & InstanceCullingManager, FRDGExternalAccessQueue & ExternalAccessQueue, FDeferredShadingSceneRenderer::FInitViewTaskDatas & TaskDatas) Line 7694 C++

UnrealEditor-Renderer.dll!FDeferredShadingSceneRenderer::Render(FRDGBuilder & GraphBuilder, const FSceneRenderUpdateInputs * SceneUpdateInputs) Line 2120 C++

UnrealEditor-Renderer.dll!RenderViewFamily_RenderThread(FRDGBuilder & GraphBuilder, FSceneRenderer * Renderer, const FSceneRenderUpdateInputs * SceneUpdateInputs) Line 5275 C++

[Inline Frame] UnrealEditor-Renderer.dll!FRendererModule::BeginRenderingViewFamilies::__l116::<lambda_4>::operator()(FRDGBuilder &) Line 5574 C++

UnrealEditor-Renderer.dll!`FRendererModule::BeginRenderingViewFamilies’::`116’::<lambda_4>::<lambda_invoker_cdecl>(FRDGBuilder & GraphBuilder, const FSceneRenderFunctionInputs & Inputs) Line 5576 C++

[Inline Frame] UnrealEditor-Renderer.dll!UE::Core::Private::Function::TFunctionRefBase<UE::Core::Private::Function::TFunctionStorage<1>,bool __cdecl(FRDGBuilder &,FSceneRenderFunctionInputs const &)>::operator()(FRDGBuilder &) Line 414 C++

UnrealEditor-Renderer.dll!FSceneRenderProcessor::Execute::__l30::<lambda_4>::operator()(FRHICommandListImmediate & RHICmdList) Line 898 C++

UnrealEditor-RenderCore.dll!ExecuteCommand(FRHICommandList * RHICmdList, const TVariant<TUniqueFunction<void __cdecl(void)>,TUniqueFunction<void __cdecl(FRHICommandList &)>,TUniqueFunction<void __cdecl(FRHICommandListImmediate &)>> & Function, const FRenderCommandTag & Tag) Line 1564 C++

[Inline Frame] UnrealEditor-RenderCore.dll!FRenderThreadCommandPipe::ExecuteCommands::__l2::<lambda_1>::operator()(TVariant<TUniqueFunction<void __cdecl(void)>,TUniqueFunction<void __cdecl(FRHICommandList &)>,TUniqueFunction<void __cdecl(FRHICommandListImmediate &)>> &&) Line 1961 C++

UnrealEditor-RenderCore.dll!UE::RenderCommandPipe::FCommandList::ConsumeCommands<`FRenderThreadCommandPipe::ExecuteCommands’::`2’::<lambda_1>>(const FRenderThreadCommandPipe::ExecuteCommands::__l2::<lambda_1> & Lambda) Line 431 C++

[Inline Frame] UnrealEditor-RenderCore.dll!FRenderThreadCommandPipe::ExecuteCommands(UE::RenderCommandPipe::FCommandList &) Line 1959 C++

UnrealEditor-RenderCore.dll!FRenderThreadCommandPipe::EnqueueAndLaunch::__l5::<lambda_1>::operator()() Line 1948 C++

[Inline Frame] UnrealEditor-RenderCore.dll!UE::Core::Private::Function::TFunctionRefBase<UE::Core::Private::Function::TFunctionStorage<1>,void __cdecl(void)>::operator()() Line 414 C++

[Inline Frame] UnrealEditor-RenderCore.dll!TFunctionGraphTaskImpl<void __cdecl(void),1>::DoTaskImpl(TUniqueFunction<void __cdecl(void)> &) Line 1116 C++

[Inline Frame] UnrealEditor-RenderCore.dll!TFunctionGraphTaskImpl<void __cdecl(void),1>::DoTask(ENamedThreads::Type) Line 1109 C++

UnrealEditor-RenderCore.dll!TGraphTask<TFunctionGraphTaskImpl<void __cdecl(void),1>>::ExecuteTask() Line 711 C++

UnrealEditor-Core.dll!UE::Tasks::Private::FTaskBase::TryExecuteTask() Line 518 C++

[Inline Frame] UnrealEditor-Core.dll!FBaseGraphTask::Execute(TArray<FBaseGraphTask *,TSizedDefaultAllocator<32>> &) Line 495 C++

UnrealEditor-Core.dll!FNamedTaskThread::ProcessTasksNamedThread(int QueueIndex, bool bAllowStall) Line 791 C++

UnrealEditor-Core.dll!FNamedTaskThread::ProcessTasksUntilQuit(int QueueIndex) Line 680 C++

UnrealEditor-RenderCore.dll!RenderingThreadMain(FEvent * TaskGraphBoundSyncEvent) Line 267 C++

UnrealEditor-RenderCore.dll!FRenderingThread::Run() Line 427 C++

UnrealEditor-Core.dll!FRunnableThreadWin::Run() Line 159 C++

UnrealEditor-Core.dll!FRunnableThreadWin::GuardedRun() Line 71 C++

[External Code]

[Attachment Removed]

Hello,

I just submitted a fix for this today in CL 49224959.

It’s a small isolated change inside the DI to acquire the VT when we are push to the RT, and use it when setting shader parameters.

Thanks,

Stu

[Attachment Removed]

I’ve not been able to repro this locally, can you give me more information about when you see this? I.e. cooked / uncooked.

I’m guessing so other process hasn’t transitioned it, as we don’t do any inside Niagara for these.

Thanks,

Stu

[Attachment Removed]

Do you have a way to setup a repro for this?

The native VT sample does not repro, so I expect it’s something outside of Niagara leaving it in CopyDest state.

Thanks,

Stu

[Attachment Removed]

Thanks for the fix, we have integrated that into our engine. We are also seeing this RHI Validation error with -rhivalidation:

--------------------------------------------------------------------

RHI Resource Transition Validation Error

--------------------------------------------------------------------

Attempted to access resource “VirtualTexture_Physical” (0x00000154BAC02A40) (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: SRVCompute

--- Allowed pipelines for this resource are: Graphics

--- Required pipelines are: Graphics

--------------------------------------------------------------------

Breadcrumbs: Frame 2098/WorldTick/RenderGraphExecute - /NiagaraGpuComputeDispatch/NiagaraGpuSim(Grid2D_SW_River:SW_River_Secondary_Emitter) DispatchCount(50000x1x1) Stage(ParticleSpawnUpdate 0) Iteration(0) Nu

--------------------------------------------------------------------

[Attachment Removed]

Hi, I see this in editor using the cmdline -rhivalidation, after loading the level. I haven’t tried in a cooked build, but I expect it would behave the same.

--------------------------------------------------------------------

RHI Resource Transition Validation Error

--------------------------------------------------------------------

Attempted to access resource “VirtualTexture_Physical” (0x00000270717EDCC0) (Whole Resource) from a hardware unit it is not currently accessible from. A resource transition is required.

--- Allowed access states for this resource are: CopyDest

--- Required access states are: SRVCompute

--- Allowed pipelines for this resource are: Graphics

--- Required pipelines are: Graphics

--------------------------------------------------------------------

Breadcrumbs: Frame 4602/SceneRender - ViewFamilies/RenderGraphExecute - /ViewFamilies/Scene/VisibilityCommands/NiagaraGpuComputeDispatch/NiagaraGpuSim(Grid2D_SW_River:SW_River_Secondary_Emitter) DispatchCount(50000x1x1) Stage(ParticleSpawnUpdate 0) Iteration(0) Nu

--------------------------------------------------------------------

[Attachment Removed]