Offsetting DrawIndexedInstanced() using StartIndexLocation, BaseVertexLocation, StartInstanceLocation

Started by
1 comment, last by collie 4 years, 6 months ago

Hi, I use the following layout within my code and use DrawIndexedInstanced() to render multiple objects. Everything works fine !

CONST D3D11_INPUT_ELEMENT_DESC vertexLayoutDesc[] =
{
  // Vertex buffer slot 0.
  { "POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0,                            D3D11_INPUT_PER_VERTEX_DATA,   INSTANCE_DATA_STEP_RATE_0 }, // vertexPosition
  { "TEXCOORD", 0, DXGI_FORMAT_R32_FLOAT,          0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA,   INSTANCE_DATA_STEP_RATE_0 }, // vertexNumber
  // slot 1, 2 and 3.
  { "COLOR",    0, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_INSTANCE_DATA, INSTANCE_DATA_STEP_RATE_1 }, // bitColor Color
  { "TEXCOORD", 1, DXGI_FORMAT_R32G32B32A32_FLOAT, 2, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_INSTANCE_DATA, INSTANCE_DATA_STEP_RATE_1 }, // bitSize Widths
  { "TEXCOORD", 2, DXGI_FORMAT_R32G32B32_FLOAT,    3, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_INSTANCE_DATA, INSTANCE_DATA_STEP_RATE_1 }, // bitOffset Offsets
  // slot 4.
  { "TEXCOORD",  3, DXGI_FORMAT_R32G32B32_FLOAT,    4, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_INSTANCE_DATA, (UINT)instanceCount },      // XMFLOAT3 VoxelPositions::_position.  An XMFLOAT4 W could have been used as a *single* orientation {angle}
  { "WORLDVIEW", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 4, D3D10_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_INSTANCE_DATA, (UINT)instanceCount },      // XMFLOAT4X4 VoxelPositions::_orientation
  { "WORLDVIEW", 1, DXGI_FORMAT_R32G32B32A32_FLOAT, 4, D3D10_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_INSTANCE_DATA, (UINT)instanceCount },
  { "WORLDVIEW", 2, DXGI_FORMAT_R32G32B32A32_FLOAT, 4, D3D10_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_INSTANCE_DATA, (UINT)instanceCount },
  { "WORLDVIEW", 3, DXGI_FORMAT_R32G32B32A32_FLOAT, 4, D3D10_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_INSTANCE_DATA, (UINT)instanceCount },
  { "TEXCOORD",  4, DXGI_FORMAT_R32_FLOAT,          4, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_INSTANCE_DATA, (UINT)instanceCount },       // FLOAT VoxelPositions::_dimColor
   };

As an experiment I have been trying variations of what is passed to IASetVertexBuffers() and DrawIndexedInstanced().

I have tried using IASetVertexBuffers() with changed pOffsets and a different InstanceCount for DrawIndexedInstanced().

Doing this I can render a single object by offsetting slot 4 (rather than multiple objects which are available).

What I would like to do next is to leave the IASetVertexBuffers() pOffsets unchanged and to solely modify DrawIndexedInstanced(). Ideally I would like to offset the slot group 1, 2 and 3 indexes; along with slot 4 index.

I have read:

https://stackoverflow.com/questions/20794017/how-to-use-instancing-offsets

https://stackoverflow.com/questions/51274628/how-do-vertex-and-index-buffers-work-in-directx11-with-vertices-normals-and-te/51278334#51278334

but I just can't seem to figure out the relationship of StartIndexLocation, BaseVertexLocation, StartInstanceLocation to the above layout. I haven't found the official DrawIndexedInstanced() documentation or the above links particularly helpful.

I have tried things like:

StartInstanceLocation = IndexCountPerInstance + InstanceCount + InstanceCount + InstanceCount; 

(also trying against BaseVertexLocation and StartIndexLocation) but just get multiple errors each time:

D3D11 WARNING: ID3D11DeviceContext::DrawIndexedInstanced: Vertex Buffer at the input vertex slot 1 is not big enough for what the Draw*()
D3D11 WARNING: ID3D11DeviceContext::DrawIndexedInstanced: Vertex Buffer at the input vertex slot 2 is not big enough for what the Draw*()
D3D11 WARNING: ID3D11DeviceContext::DrawIndexedInstanced: Vertex Buffer at the input vertex slot 3 is not big enough for what the Draw*()

If anyone has any experience of using DrawIndexedInstanced() and could offer insights into how StartIndexLocation, BaseVertexLocation, StartInstanceLocation are used to access the above layout I would be very thankful.

Advertisement

I found this documentation which showed it it a manner I could understand.

https://microsoft.github.io/DirectX-Specs/d3d/archive/D3D11_3_FunctionalSpec.htm#IAExample

This topic is closed to new replies.

Advertisement