Jump to content
  • Advertisement
Sign in to follow this  
Funkymunky

DX12 [D3D12] Array of cbuffers?

This topic is 1209 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to use an array of cbuffers for instanced rendering.  In the shader I set up an array of two structs, like so:

 

struct MVPBuffer
{
   float4x4 MVP;
};
ConstantBuffer<MVPBuffer> Matrices[2] : register(b0);

 

For creating the root signature, I do the following:

 

cbufferRange = CD3DX12_DESCRIPTOR_RANGE(D3D12_DESCRIPTOR_RANGE_TYPE_CBV, 2, 0, 0);
rootParams[0].InitAsDescriptorTable(1, &cbufferRange, D3D12_SHADER_VISIBILITY_ALL);

 

And when I create the constant buffer view, I tell it to use (sizeof(MVPBuffer) * 2).  But when I render my mesh with two instances, and try to index the Matrices array with a variable assigned to SV_InstanceID, I only see the first mesh.

Edited by Funkymunky

Share this post


Link to post
Share on other sites
Advertisement

Are you sure you want an array of two constant buffers and not just a single constant buffer with an array of two matrices?

Share this post


Link to post
Share on other sites

You can't, but you should really stick to a StructuredBuffer for what you're trying to do.

 

A wave/warp of threads is almost certainly going to access your array in a divergent manner and that's not a good thing to do with a constant buffer on some GPUs. Trying to access an array of constant buffers using a feature of Shader Model 5.1 is taking divergence to a whole new level and will not run well at all.

Share this post


Link to post
Share on other sites

And when I create the constant buffer view, I tell it to use (sizeof(MVPBuffer) * 2).

That's what you would do if you had a cbuffer that contained an array.

If you want an array of cbuffer like in your shader code, you'll need an array of constant buffer views with size=sizeof(MVPBuffer)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!