DX10 Constant Buffers Question

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

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 on other sites
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 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 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 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 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 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:

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 on other sites
Unfortunately I can't see that picture you posted.

Share on other sites
Strange, try going to this url please :

http://gallery.me.com/petr.tomicek#100021/PIX

Share on other sites
Update:

All fixed, at first I was not clearing the depth buffer and then I was not clearing it properly :)

1. 1
2. 2
Rutin
21
3. 3
A4L
15
4. 4
5. 5

• 13
• 26
• 10
• 11
• 44
• Forum Statistics

• Total Topics
633740
• Total Posts
3013621
×