Create Structured Buffer Questions

Hello,

I was playing with shader on unreal engine and stumble upon some problem when creating buffer.

How do I Set the FRHIResourceCreateInfo with an array resource that I made into FRWBufferStructured::Initialize() ?

I was planning to call FRWStructuredBuffer::Initialize but inside that function it seems RHICreateStructuredBuffer call don’t use any FRHICreateInfo with any array resource. Am I missing something when creating it?

How do I normally Initialize a FRWBufferStructured with a ResourceArray?

::Edit for further explanation

It could be achieved by adding this into FRWBufferStructured::Initialize()

	void Initialize(uint32 BytesPerElement, uint32 NumElements, uint32 AdditionalUsage = 0, bool bUseUavCounter = false, bool bAppendBuffer = false, FResourceArrayInterface* Data /*this var added*/)
{
		check(GMaxRHIFeatureLevel == ERHIFeatureLevel::SM5);
		NumBytes = BytesPerElement * NumElements;
		FRHIResourceCreateInfo CreateInfo;
		CreateInfo.ResourceArray = Data; // this line added
		Buffer = RHICreateStructuredBuffer(BytesPerElement, NumBytes, BUF_UnorderedAccess | BUF_ShaderResource | AdditionalUsage, CreateInfo);
		UAV = RHICreateUnorderedAccessView(Buffer, bUseUavCounter, bAppendBuffer);
		SRV = RHICreateShaderResourceView(Buffer);
}

But I could be wrong

Thanks!

Looking at the code, FD3D11DynamicRHI::RHICreateStructuredBuffer does pass CreateInfo.ResourceArray to D3D to initialize the structured buffer. I don’t do this personally when creating structured buffers, because I only write to them on the GPU using a Unordered Access View from a compute shader.

If you don’t want to modify FRWBufferStructured you can make your own version of it which passes the FResourceArrayInterface to RHICreateStructuredBuffer. It’s just a helper class that does things people commonly need.

Yes, basically creating my version of helper class would solve the issue, but then again, I was wondering why is that line isn’t added in the engine. Thanks for the answer though!