Jump to content
  • Advertisement
Sign in to follow this  
VanillaSnake21

[DX10] Can't get the constant buffer to update

This topic is 2320 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

Hey all, to be brief, I can't get the constant buffer in the shader to update.
Heres the code:


//decl
ID3D10Buffer* g_pConstantBuffer;

//definition
struct _SHADER_CONST_BUFFER
{
float fDelta;
};

//creation
D3D10_BUFFER_DESC cbDesc;
cbDesc.ByteWidth = sizeof( _SHADER_CONST_BUFFER );
cbDesc.Usage = D3D10_USAGE_DYNAMIC;
cbDesc.BindFlags = D3D10_BIND_CONSTANT_BUFFER;
cbDesc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
cbDesc.MiscFlags = 0;
HRESULT hr = pD3DDevice->CreateBuffer( &cbDesc, &InitData, &g_pConstantBuffer );
pD3DDevice->VSSetConstantBuffers( 0, 1, &g_pConstantBuffer );

//updating
_SHADER_CONST_BUFFER* pConstData;
g_pConstantBuffer->Map( D3D10_MAP_WRITE_DISCARD, NULL, ( void** )&pConstData );
pConstData->fDelta = gTimeDelta;
g_pConstantBuffer->Unmap();
pD3DDevice->VSSetConstantBuffers( 0, 1, &g_pConstantBuffer );


This is the way it looks in the .fx file


cbuffer cb0
{
float fDelta;
};


I am given no errors during compilation or runtime. I don't show it here, but I tested all the functions' HRESULTs - no failures.I have the D3D error reporting enabled, but I'm not getting messages from there either.
It appears to have written the values, but when I read them from the shader they all show 0.0000, also a little animation in the texture is not playing (because this is the time delta I'm trying to set)

I have gone trough the directx samples and copied the code verbatim, so I don't know what the problem could be.

Share this post


Link to post
Share on other sites
Advertisement
Just to be clear on intent, as someone made this mistake on here recently, you are aware that you are only binding the vertex shader CB, yes? That is where you expect to access the value and not any other shader stage, correct?

Share this post


Link to post
Share on other sites

Just to be clear on intent, as someone made this mistake on here recently, you are aware that you are only binding the vertex shader CB, yes? That is where you expect to access the value and not any other shader stage, correct?


I think this might be the cause. I'm referencing the timeDelta only in my pixel shader. What is strange is that not one of the sources told me anything about the buffer being limited to vs. Thanks, phantom. Does that mean I have to specify a second buffer to be used in the ps, or is just a limitation?

Share this post


Link to post
Share on other sites
Hi!


Does that mean I have to specify a second buffer to be used in the ps, or is just a limitation?

You can bind the constant buffer to every shader stage you want, even at the same time. So there is no need to create a second buffer storing the same values.

This will bind the constant buffer to the VS and PS:
pD3DDevice->VSSetConstantBuffers( 0, 1, &g_pConstantBuffer );
pD3DDevice->PSSetConstantBuffers( 0, 1, &g_pConstantBuffer );


Cheers!

Share this post


Link to post
Share on other sites
Also, stated by the MSDN

[color=#2A2A2A]"If the bind flag is D3D11_BIND_CONSTANT_BUFFER then the ByteWidth[color=#2A2A2A] value must be in multiples of 16, and less than or equal to D3D11_REQ_CONSTANT_BUFFER_ELEMENT_COUNT."

[color=#2A2A2A]one float is only 4 bytes

[color=#2A2A2A]Cheers!

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!