Hello. I am implementing a compute shader. I need to guarantee the computation in GPU has finished before I copy data back to CPU.
Intuitively, I would like to use “fence”, but I found that in UE 5.2 “fence” has been depricated and should be replaced with “transition”. But I do not know how should I use “transition” in UE.
For example, I have a variable and its buffer in my class like this.
TArray<float> Data_Float;
FBufferRHIRef Data_CsBuffer;
FUnorderedAccessViewRHIRef Data_CsBufferUAV;
And I initialize them like this.
ENQUEUE_RENDER_COMMAND(FComputeShaderRunner)(
[this](FRHICommandListImmediate& RHICommands)
{
TResourceArray<float> TmpResourceArray;
TmpResourceArray.Init(0, Data_Float.Num());
FRHIResourceCreateInfo CreateInfo(TEXT("Data_Float"));
CreateInfo.ResourceArray = &TmpResourceArray;
constexpr EBufferUsageFlags Usage = BUF_UnorderedAccess | BUF_ShaderResource | BUF_StructuredBuffer;
Data_CsBuffer = RHICommands.CreateBuffer(
sizeof(float) * Data_Float.Num(),
Usage,
sizeof(float),
RHIGetDefaultResourceState(Usage, false),
CreateInfo);
});
After I have triggered some GPU computation, I think I should use a “transition” before I copy back data from Data_CsBufferUAV to Data_Float. I guess it should be something like this.
RHICommands.Transition(FRHITransitionInfo(Data_CsBufferUAV, ERHIAccess::Unknown, ERHIAccess::UAVMask));
But is this correct? What is the meaning of each ERHIAccess? How and by whom the Data_CsBufferUAV’s state is (shoud should be) changed? Are there any tutorial or documents about these?
Thanks in advance.