Sign in to follow this  

DirectX11 Multiple Constant Buffer Issue

Recommended Posts

I am trying to draw a Sphere. The Vertex Shader simply transforms the Vertice from Object Space to Clip Space. The Pixel Shader just returns a single color. I am using Visual Studio 2015, Shader Model 5.0, and DirectX11.


This is the result I am looking for:


Here is the Vertex Shader Code:


Now my issue is that the WorldViewProj variable in constant buffer cb1 is acting like it is referring to Proj in cb0 when the code runs. This means that when I set Proj to what the WorldViewProj's value is for that frame, the code works. But if Proj is what it is supposed to be, just the projection matrix, the code does not work. In fact, if the Proj matrix is actually set to the projection matrix values like it is supposed to, the screen looks like this:


If I set the Proj Matrix to WorldViewProj Values and don't set WorldViewProj at all, the code runs correctly, even though in the HLSL code I am clearly asking for values stored in WorldViewProj even though they are 0's(If you don't set a constant buffer's values, they are set to 0, see my links to GPU Debug output below) but yet it still works. If I don't set the Proj to anything, I get a black screen.


Now I want to prove this is not an issue on the CPU side...


The following picture is CPU side code for setting everything for that frame, I fill the Proj Matrix with 999.0f's and the WorldViewProj Matrix with 111.0f's.


I ran the GPU Debugger and saved the results.

Here is the Camera Constant Buffer:

Here is the World Constant Buffer:


So I am setting the data correctly. I don't understand why this is happening. Thank you for your help.



I had quite a bit of discussion with some people over on Reddit with this issue here.

Please don't suggest a solution that has already been talked about and looked at there.


Here is my Constant Buffer Binding Code:


For those with Visual 2015, here is a link to the Debugger Capture File with the correct values set for all the matrices in the constant buffers (But when you look at the results of the frame, it is clearly showing it use the projection matrix even though the HLSL code calls the WorldViewProj Matrix in cb1, hence the issue):


For those who are reluctant to download the file here is a screenshot of the Constant Buffer Bind info from it:


Thank you all.

Edited by phatgreen

Share this post

Link to post
Share on other sites

That was the problem..... Thank you so much. In all the documentation I've read, and in previous projects I've done, they all use 'cb'. Why is 'b' making it work?

Share this post

Link to post
Share on other sites

Just out of curiosity, what happens if you remove the packoffsets, but use cb0 and cb1 as the register names as you originally did? (I don't exactly know what happens here, but I have an idea.)

It didn't work like before. It reads from the Proj matrix even though I'm using the WorldViewProj, weird stuff, what were suspecting?

Share this post

Link to post
Share on other sites
You don't need the pack offsets if you so the manual padding in your application struct. Which in this case isn't necessary because your only passing around float4's (indirectly)

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