Compute Shader Pass RWStructuredBuffer by Reference
I was curious if there is a way to pass a structured buffer around by reference. With both structured buffers and arrays I don't want them to be copied entirely when passed to a function, because this would be ridiculously inefficient. Is there a way to do this properly in HLSL for compute shaders?
I saw the in, out, and inout keywords, but the documentation makes it seem like this just performs a copy anyway. Is a copy for structured buffers and arrays just a pointer copy? Or is it by values?
Answer by ModLunar · Jun 14, 2018 at 03:31 PM
Yeah good question, I'm wondering the same thing now..
It seems like from Microsoft's HLSL documentation that all function arguments are copied every time, and passed by value only.
But in this forum post (elsewhere), they say it's fine and that it does use references.. so I'm like which is it? xD
For now, I'm going to be on the safe side and just keep all the methods I would have wanted to give in StructuredBuffers as arguments in the same compute shader instead, so I can just access the buffer globally. At least until I find someone who has a definitive answer, or find concrete documentation/evidence saying it is okay to do.
Your answer
Follow this Question
Related Questions
How can I read in the actual elements from an Append Compute Buffer? 2 Answers
AsyncGPUReadback.GetData with computeBufferType.Append 0 Answers
ScriptableObject Instances Referencing One Set of Prefabs - Changing One SO Changes The same prefab 1 Answer
ComputeShader: StructuredBuffer sometimes empty in Metal 1 Answer