I am trying to figure out how to use some additional data per instance. The current implementation uses only world matrix as instance data which is accessed in VS using drawId to reference it within the buffer. Let consider that i would like to store additional data for each mesh, but the size of the data is not constant - e.g. it contains a float4 for each triangle. In the GS I can use PrimitiveID to access the data for a particular triangle.
I am considering following management in HLMS:
- buffer for storing all custom instance data - like 10MB (read-only buffer) - BufferX (just working name to be able to refer to it later within the text)
- per instance, there is world matrix + offset into BufferX where the data for the instance begins
In fillBuffersForV2:
- fill world matrix + currently stored size of BufferX in the instance data buffer
- add data to BufferX from the renderable
In GS or PS, I can use:
Code: Select all
// 1. using drawId to access the offset in the buffer
// 2. using primitiveId (generated automaticall by IA) to access myValue within the buffer after applying bufferXOffset
const float4 primitiveData = bufferX[instanceData[drawId].bufferXOffset + primitiveId].myValue;
I see however that it is probably not optimal approach. On one side there will be huge fill every frame to prepare BufferX and actually the data stored in BufferX are same for all same meshes so instancing seems like a good idea. I will have VB+IB+BufferX for a single mesh, but how should I pack it together for multiple visible instances? The BufferX has nothing to do with number of stored vertices in VB, it is just a buffer which is accessed and somehow processed by GS or PS (according to PrimitiveID).