DX10 Constant Buffers Question

Started by
9 comments, last by MJP 13 years, 3 months ago
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
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.
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
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.
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.
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.
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.
Unfortunately I can't see that picture you posted.
Strange, try going to this url please :

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

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

This topic is closed to new replies.

Advertisement