Download

Unreal RDG, HLSL and a structured buffers with custom data

I’m trying to learn more about RDG in Unreal and HLSL, so far so good, with one exception: I’m trying to pass an array of a custom struct from C++ to HLSL via a structured buffer, and I currently don’t know how to tell the C++ buffer: hey, this is your data so you can pass it to the GPU.

it is possible that I don’t fully comprehend the role and scope of a structured buffer…

In C++ my shader has


SHADER_PARAMETER_RDG_BUFFER_UAV(RWStructuredBuffer<FMyStuff>, MyStuffBuffer)

Then at some point I create it


FRDGBufferRef MyStuffBuffer = GraphBuilder.CreateBuffer(MyStuffBufferDesc, TEXT("MyStuffBuffer"));

here I was expecting to be able to do something like


MyStuffBuffer.SetData(some TArray<FMyStuff>)

then I assign it to the parameters


PassParameters.MyStuffBuffer = GraphBuilder.CreateUAV(MyStuffBuffer);

And then I pass everything to the GPU via


FComputeShaderUtils::AddPass

I was hoping there is a way, after I create the RDG buffer in C++, to set its data/payload as some TArray<FMyStuff> I previously created and populated in C++

I poked around the source code, but to no avail, this specific aspect of RDG still eludes me :slight_smile: do you happen to have any idea, by any chance? Thanks!

Apparently, this should be enough in 4.26.1 :slight_smile:

PassParameters.MyBuffer = GraphBuilder.CreateUAV(CreateStructuredBuffer(GraphBuilder, TEXT("MyBuffer"), sizeof(FMyStruct), MyStructArrayData.Num(), &MyStructArrayData, sizeof(MyStructArrayData)));