DrawIndexed : StartIndexLocation / IASetVertexBuffers : Offset

Started by
3 comments, last by eppo 11 years, 3 months ago

Hi,

My renderer has this issue where I get an DEVICE_DRAW_INDEX_BUFFER_TOO_SMALL warning when using DrawIndexed(Instanced)().

I use 16 bit index buffers that refer to max 2^16 vertices chunks in a vertex buffer. Whenever I pass a BaseVertexLocation > 0 to DrawIndexed(), this warning is output. However, if I set StartIndexLocation to zero and instead pass an index buffer offset to IASetIndexBuffer(), the warning disappears. For both cases the rendered scene looks fine.

Any ideas what could be causing this?

Advertisement
As far as I know, StartIndexLocation and Index Buffer Offset is almost the same thing. The difference is that the offset is in bytes so you have to take the index size (16 bit vs 32 bit) into account. They both accomplish the same thing, ie. defining where to start reading the indices. Both can be used in the same time or just one of them. Typically I define the location of the indices only with the byte offset.

The BaseVertexLocation however is another kind of offset. The MSDN says that "BaseVertexLocation is a value added to each index before reading a vertex from the vertex buffer." So this offset is changing the index which is used to access the vertex buffer.

The error message you get is related to the situation where your drawing call is "out of bounds" ie. trying to read indices outside of the index buffer.

Changing just BaseVertexLocation shouldn't give this error since it doesn't affect the starting point of reading or the amount of reading from the index buffer. However, messing with all the three values (BaseVertexLocation, StartIndexLocation, Index Buffer Offset) are a good source of errors and incorrect output.

You should look into the the program logic again and verify that you are reading the index buffer from desired location with the amount of indices that resides inside the buffer.

Enable Direct3d debugging and enable the break points so that you can halt the program at the point which creates the error.

Cheers!

You're right. I was led off course by the fact that using an offset in IASetIndexBuffer() doesn't generate an error, making me think it was something API related. It turns out there was a bug in my offset calculations.

I prefer to pass the offsets to DrawIndexed() as it involves less state changes when using the same index buffer.

[quote name='eppo' timestamp='1357130387' post='5016666']
I prefer to pass the offsets to DrawIndexed() as it involves less state changes when using the same index buffer.
[/quote]

Putting it that way, I guess you are right.

Cheers!

Update: my offsets were correct after all.

There is a known bug in the D3D11 debug layer that generates the "Index buffer has not enough space!" warning when both the StartIndexLocation and BaseVertexLocation arguments to DrawIndexed() are non-zero.

This topic is closed to new replies.

Advertisement