Jump to content
  • Advertisement
Sign in to follow this  
eltharynd

Constant buffer

This topic is 2119 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'm attempting to create a Constant buffer in which to store the view, world and projection matrices..

i get E_INVALIDARG

ZeroMemory(&mBufferDesc, sizeof(mBufferDesc));
mBufferDesc.Usage = D3D11_USAGE_DEFAULT;
mBufferDesc.ByteWidth = sizeof(ConstantBuffer);
mBufferDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
mBufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
HRESULT hr =eng->mDevice->CreateBuffer( &mBufferDesc, NULL, &mConstantBuffer );
	return 0;

any ideas? =/

 

mBufferDesc is declared as a member of the class where my code is:

D3D11_BUFFER_DESC mBufferDesc;

and ConstantBuffer struct is a member of the class as well
struct ConstantBuffer
{
XMMATRIX mWorld;
XMMATRIX mView;
XMMATRIX mProjection;
};
Edited by eltharynd

Share this post


Link to post
Share on other sites
Advertisement

ok so i figured out i had to use D3D11_USAGE_DYNAMIC.... i don't know how my eyes missed it and i don't know how i wrote that since i was following directx official tutorials :/ but still it displays nothing...

Share this post


Link to post
Share on other sites

but still it displays nothing...

 

That could be caused by a large number of reasons... What are you trying to render? Are you correctly filing the constant buffers and binding it to the right shader stage?

Have you tried to run your program in PIX (or NSight or GPU PerfStudio or Intel GPA) to check if the shader is running as expected (with the right values).?

Share this post


Link to post
Share on other sites

Create your device with the D3D11_CREATE_DEVICE_DEBUG flag. When you do that, D3D will output messages to the debugger output window whenever a  function fails, and it will give you detailed information about what you messed up. It would have saved you a lot of time figuring out why CreateBuffer failed.

As for nothing displaying, are you transposing your matrices when setting them into the constant buffer? By default shaders except column-major matrices in constant buffers, so you either need to transpose your matrices or you need to specify in your shader that it should expect row-major matrices (you can do this by adding row_major to the matrix declaration in the constant buffer).

Share this post


Link to post
Share on other sites

Well you may have to post your shader code. Also, don't forget about row major vs column major when writing your WVP matrices to the CB, you may have forgotten to transpose depending on how you have things setup...

 

Edit: Well shoot, beat me to the punch... :)

Edited by Starnick

Share this post


Link to post
Share on other sites

I just started with DirectX recently (SharpDX) and I had problems getting the constant buffer working too.

Here is a snippet of my C# code which works. (remember tp update your buffer using UpdateSubResource - that is where I had the problem)

 

 

 

[StructLayout(LayoutKind.Sequential, Pack=4)]
struct cbTransform
{
 public Matrix worldProj;
}

...
cbTransform m_cbTransform = new cbTransform();
Buffer m_transformBuf;
m_transformBuf = new Buffer(rc.Device, Utilities.SizeOf<cbTransform>(), ResourceUsage.Default, BindFlags.ConstantBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);
rc.Context.VertexShader.SetConstantBuffer(0, m_transformBuf);
...

 

m_cbTransform.worldProj = m_viewProj;

m_cbTransform.worldProj =

/*Matrix.RotationX(time) **/ Matrix.RotationY(time * 2)/* * Matrix.RotationZ(time * .7f)*/ * m_viewProj;

m_cbTransform.worldProj.Transpose();

rc.Context.UpdateSubresource<cbTransform>(ref m_cbTransform, m_transformBuf);

Edited by jkristia

Share this post


Link to post
Share on other sites

nevermind solved.... apparently i had a return 0; at some point in my code... that i really have no clues  why it was there... so no error returns but the code won't work..... i must be tired.. thanks anyway

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!