Hi!
I'm wondering if it is possible to structure a Vertex Buffer in a SoA approach like this
{ x1, x2, x3 . . . xn, y1, y2, y3 . . . yn, z1, z2, z3 . . . zn }
instead of the traditional AoS approach
{ x1, y1, z1, x2, y2, z2, x3, y3, z3 . . . xn, yn, zn }
If that beeing the case.. Is it possible to design the ID3D11InputLayout
like this?
D3D11_INPUT_ELEMENT_DESC inputDesc[] = {
{ "POSITION", 0, DXGI_FORMAT_R32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
{ "POSITION", 1, DXGI_FORMAT_R32_FLOAT, 0, offsetToY, D3D11_INPUT_PER_VERTEX_DATA, 0 },
{ "POSITION", 2, DXGI_FORMAT_R32_FLOAT, 0, offsetToZ, D3D11_INPUT_PER_VERTEX_DATA, 0 }
};
And how does one call the deviceContext->IASetVertexBuffers
correctly with this type of layout?
Any suggestions? Thank you!
If all the attributes of your vertices are stored contiguously then you can probably get it to work.
Have each element of your vertex be in a separate vertex stream (0-15) and bind as many vertex buffers as you have vertex components. See the "InputSlot" member of D3D11_INPUT_ELEMENT_DESC.
When you bind your N vertex buffers using IASetVertexBuffers then you can provide the offset for each vertex buffer to be the offset to the start of that vertex element. The stride for each vertex stream will be 4 bytes.
The offset to PositionX will be 0 bytes.
The offset to PositionY will be sizeof(float) * vertex count.
The offset to PositionZ will be 2 * sizeof(float) * vertex count.
etc
Alternatively you could not use vertex buffers at all and simply bind your buffer of floats using a Shader Resource View (Buffer< float >. You could then use SV_VertexID to locate each element of your vertex.
X0 could be found at index 0.
X1 could be found at index 1.
Y0 could be found at index (vertexCount).
Y1 could be found at index (vertexCount + 1).
Z0 could be found at index (2 * vertexCount + 1).
Z1 could be found at index (2 * vertexCount + 2).
etc