Jump to content
  • Advertisement
Sign in to follow this  
Corefanatic

DX10 Constant Buffers Question

This topic is 2823 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 have a quick question about DX10 co nstant buffers. Is it possible to set the whole constant buffer instead of the individual values?

Ie create a struct identical to the data layout of the constant buffer and then send it over as whole instead of piece by piece?

Thx for help

Share this post


Link to post
Share on other sites
Advertisement
That would be the entire point of a constant buffer yes :)

How you update the buffer CPU side doesn't really matter. What makes constant buffers smart is that you update the GPU memory data using an entire chunk of data.

Share this post


Link to post
Share on other sites
Thank you!

I have this code I coded since I first posted, but atm have no means to verify it works:


the struct:

struct cbConstants
{
D3DXMATRIX view;
D3DXMATRIX proj;
};

in my effect:

cbuffer cbConstant
{
float4x4 matView;
float4x4 matProj;
}

cbConstants cbC;

D3DXMatrixPerspectiveFovLH(&cbC.proj,( float )D3DX_PI * 0.25f,1200/800,1,100);

D3DXVECTOR3 Eye( 0.0f, 3.0f, -6.0f );
D3DXVECTOR3 At( 0.0f, 1.0f, 0.0f );
D3DXVECTOR3 Up( 0.0f, 1.0f, 0.0f );
D3DXMatrixLookAtLH( &cbC.view, &Eye, &At, &Up );

ID3D10EffectConstantBuffer* constants = m_currentEffect->GetConstantBufferByIndex(1);

HRESULT tryout = constants->SetRawValue(&cbC,0,1);




the setrawvalue function returns S_OK

Share this post


Link to post
Share on other sites
I think that should work. If not, you can always just call GetConstantBuffer to get the actual ID3D10Buffer interface, then call Map on it and memcpy in your constant data.

Also the one thing you want to be careful with using structs for constant buffers is alignment. This has all of the rules used by the HLSL compiler.

Share this post


Link to post
Share on other sites
Thanks MJP,

I just checked the data in PIX and it works ok, but I will keep your advice on alignment in mind.

I'm still not seeing anything I'm drawing (just a triangle), but now that I know my matrices are passed in fine I know I can look somewhere else for a problem.

Share this post


Link to post
Share on other sites
Try transposing your matrices before setting them into the constant buffer, or passing the D3D10_SHADER_PACK_MATRIX_ROW_MAJOR flag when compiling your effect. By default HLSL shaders expect column-major matrices in constant buffers, and the Effect framework will automatically transpose when setting one matrix at a time.

Share this post


Link to post
Share on other sites
Once again, Thanks MJP :)

The flag during compilation of the effect helped, but I still don't see anything on the screen except my clear color. The reason I know the flag helped is that now in PIX I see this:


PIX

So I know the geometry is rendered with right coordinates in screen space, but nothing still shows up. Do you have any suggestions where the problem might lie?

If you need more source to help me let me know and I will post it here right away.

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!