Sign in to follow this  
alexandrov

D3D10 Constant buffers underrun

Recommended Posts

Greetings! I've run into some peculiar problem while binding constant buffers to an effect via ID3D10EffectConstantBuffer::SetConstantBuffer. The constant buffer declared in the effect contains a float4 array of, say, 512 elements: cbuffer entryBuf { float4 entries[512]; } However, the buffers that are actually bound would typically contain data for less number of elements. When this situation occurs (data underrun), I get a long debug layer warning on each successive draw call. It states however, that 'This is OK, as out-of-bounds reads are defined to return 0'. No reads beyond the bounds would be done, as this buffer is _indexed_ by appropriate vertex attributes. Everything works ok, xcept the perfomance drain I have to tolerate with the swarm of these warnings being issued. First thing I try to do is to reduce the size in array declaration inside the effect: float4 entries[1]; as the least size of a potentially bound buffer is exactly 1 float4. Unfortunatelly, this changes the way the buffer is viewed by shader compiler, and it compiles to being 'immediateIndexed' instead of 'dynamicIndexed', which corrupts all the drawing. Doing float4 entries[2]; leaves it dynamic indexed, everything draws fine, but I start getting a swarm of warnings if the scene contains at least one entity with 1-element-sized entry buffer. So mates, 2 questions: 1. Is it safe to declare less-than-bound sized array in the effect file in the first place? (declare entries[2], bind say, 16 element buffer and read from all those 16 - draws fine at my place, but who knows how would it behave elsewhere) 2. Perhaps someone knows a solution to leave my cbuffer being dynamicIndexed, while providing only 1 element in array declaration, so that I get no warnings? ;] Thanks in advance!

Share this post


Link to post
Share on other sites
Declaring a smaller array than you are going to use is generally a bad idea. The compiler makes assumptions and optimizations based on the array size. For example, in the case where you had just one element, it assumed that all accesses were to that one element. There are other side effects as well, such as stopping loop simulations, which could cause several problems with your code.

There are options for muting certain messages that you can look at here:
http://msdn2.microsoft.com/en-us/library/Bb232911.aspx

Without seeing why you're doing this I can't really give many different options on how to do this without generating these warnings. If the code itself knows that it's not using the entire array (it's indexed by a value with a range known at compile-time), there is a fix in the August release to declare the size of the cbuffer (the size compared when generating this warning) as the size that was used rather than the total size of the cbuffer.

Share this post


Link to post
Share on other sites
Quote:
Original post by Jalibr
There are options for muting certain messages that you can look at here:
http://msdn2.microsoft.com/en-us/library/Bb232911.aspx


My array was indexed by vertex attributes, thus it's not the august fix case ;]. The conclusion I've made is to leave the array large enough, and use ID3D10InfoQueue to mute. Thank you for the tip!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this