Advertisement

DrawIndexed / IASetVertexBuffers

Started by November 28, 2019 11:30 AM
3 comments, last by pcmaster 4 years, 9 months ago

Just a quick one, can't find any answers online but how does the drawIndexed work with an array of buffers set through IASetVertexBuffers?

Let's say, if I have 2 vertex buffers in the array both the same size with the same number of indexes to draw. How would this be drawn?

I have not used arrays of vertex buffers yet, but I believe the drawing procedure does not change, you just need to specify the input slots correctly during creation of the Input Layout Object.

Advertisement

There is always only one index buffer, but can be multiple vertex buffers. The vertex buffers should match your input layout declaration. It's useful to have multiple vertex buffers as opposed to one. For example, with one vertex buffer, your vertex struct would be something like:

struct Vertex
{
  float3 position;
  float3 normal;
  float2 uv;
};

But with multiple vertex buffers you can instead have one vertex buffer for all the positions, an other for all the normals and the third one for just all the uvs. Imagine you only want to read from positions in the shadow render pass, then you only bind the position vertex buffer. But in the main render pass, you will bind all three vertex buffers. This can help achieve better cache usage and also produces easier to maintain code in my opinion.

For completeness, let's also mention that any vertex buffer can have one of the two 'frequencies'

  1. One item per vertex
  2. One item per instance

Discussed above has been the first option. The per-instance frequency will cause the input assembler (fetch shader) to fetch the same item (typically a transform matrix) for all vertices composing one instance.

So you might have 4 vertex buffers set using

  1. Positions (per-vertex, N elements)
  2. Normals (per-vertex, N elements)
  3. UVs (per-vertex, N elements)
  4. Transforms (per-instance, I elements)

This topic is closed to new replies.

Advertisement