After a little more experimenting I noticed that if you remove the swap command Swap(SourceIndex, DestIndex); the project works.
Upon re-enabling it I think that the problem is that the pressure textures assigned in
Params->pressureIn = GraphBuilder.CreateSRV(PressureTemp[SourceIndex]);
Params->outputFloat = GraphBuilder.CreateUAV(PressureTemp[DestIndex]);
are marked as used and become unusable inside of the loop as their resources are probably released after assignment or locked as they have been sent in dispatch.
Changed code
for(int32 I=1; I < Config.NumPressureIterations; ++I)
{
FFireShaderPressureCS::FParameters* Params = GraphBuilder.AllocParameters<FFireShaderPressureCS::FParameters>();
const FRDGTextureRef PressureTemp[2] =
{
GraphBuilder.CreateTexture(CreateTextureDesc(Velocity.Resolution, false), TEXT("Pressure0")),
GraphBuilder.CreateTexture(CreateTextureDesc(Velocity.Resolution, false), TEXT("Pressure1"))
};
Params->VelocityBounds = Velocity.Bounds;
Params->pressureIn = GraphBuilder.CreateSRV(PressureTemp[SourceIndex]);
Params->divergenceIn = GraphBuilder.CreateSRV(Divergence);
Params->obstaclesIn = GraphBuilder.CreateSRV(ObstaclesTexture);
Params->outputFloat = GraphBuilder.CreateUAV(PressureTemp[DestIndex]);
GraphBuilder.AddPass(
RDG_EVENT_NAME("Pressure"),
Params,
ERDGPassFlags::AsyncCompute,
[&Params, Shader, GroupCount, I](FRHIComputeCommandList& RHICmdList)
{
FComputeShaderUtils::Dispatch(RHICmdList, Shader, *Params, GroupCount);
}
);
Swap(SourceIndex, DestIndex);
}
It stops the RHI error, but it does trigger a single MarkAsConsumed error.
If could be due to persure0 being empty during the first pass
Edit:
As a further optimization the descriptions themselves can be pulled out of the loop, they don’t seem to loose the RHI as I think it might be generated and assigned from within GraphBuilder.CreateTexture()
FRDGTextureDesc p0 = CreateTextureDesc(Velocity.Resolution, false);
FRDGTextureDesc p1 = CreateTextureDesc(Velocity.Resolution, false);
for(int32 I=0; I < Config.NumPressureIterations; I++)
{
FFireShaderPressureCS::FParameters* Params = GraphBuilder.AllocParameters<FFireShaderPressureCS::FParameters>();
const FRDGTextureRef PressureTemp[2] =
{
GraphBuilder.CreateTexture(p0, TEXT("Pressure0")),
GraphBuilder.CreateTexture(p1, TEXT("Pressure1"))
};
/// rest of code
}