Simple example, I have 2 models I want to draw:
- tree
- rock
In order to use GPUIndexedIndirectDrawCommand
, I put their MVP matrices into a storage buffer.
I’d like to put all of them in one buffer, like:
[treeMat1, treeMat2, treeMat3, bushMat1, bushMat2]
Then, render it with 2 separate SDL_DrawGPUIndexedPrimitivesIndirect
draw commands.
In order to do that, you’d have to say:
“draw 3 trees, starting at instance 0” and “draw 2 bushes, starting at instance 3”
That’s why I’d like to set first_instance
in SDL_GPUIndexedIndirectDrawCommand
.
However, the docs say that the first_instance
parameter is not compatible with the InstanceID in the shader, so in the shader I would not be able to get the correct MVP.
struct Input {
uint instanceID : SV_InstanceID;
};
struct DefaultInstanceData {
float4x4 mvp;
};
StructuredBuffer<DefaultInstanceData> instanceData : register(t0, space0);
float4x4 mvp = instanceData[input.instanceID].mvp;
I just wanted to ask if this kind of usage is really impossible and if I have to create separate buffers for the instance data for each type of object I need to draw?
It seems having one buffer and indexing into it is the proper way from what I’ve read so please let me know if I’m missing something or if you have any ideas on how it can be done / would be done by an expert.
Thanks!