• Advertisement
Sign in to follow this  

DirectX10 + HLSL Constantbuffer problem

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

Hi,

I don't know why but dx10 always give me back a false result when I try to create buffer, in this case a constantbuffer.

[source lang="cpp"]struct SPSSSAOPerFrameBuffer
{
float m_sample_rad;
float m_scale;
float m_intensity;
float m_bias;
float m_screen_size_x;
float m_screen_size_y;
float m_random_size;
};

ID3D10Buffer* g_pPSSSAOPerFrameBuffer = 0;

D3D10_BUFFER_DESC PSSSAOPerFrameBufferDesciptor;

PSPerFrameBufferDesciptor.ByteWidth = sizeof(SPSSSAOPerFrameBuffer);
PSPerFrameBufferDesciptor.Usage = D3D10_USAGE_DYNAMIC;
PSPerFrameBufferDesciptor.BindFlags = D3D10_BIND_CONSTANT_BUFFER;
PSPerFrameBufferDesciptor.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE; PSPerFrameBufferDesciptor.MiscFlags = 0;

Result = g_pDevice->CreateBuffer(&PSSSAOPerFrameBufferDesciptor, 0, &g_pPSSSAOPerFrameBuffer);

if (Result != S_OK)
{
return false;
}[/source]

I'm getting back, in Result, the value E_INVALIDARG.
And thats the constantbuffer in hlsl.
[source lang="cpp"]cbuffer CBPSSSAOPerFrameBuffer
{
float1 m_sample_rad;
float1 m_scale;
float1 m_intensity;
float1 m_bias;
float1 m_screen_size_x;
float1 m_screen_size_y;
float1 m_random_size;
};
[/source]

Before you think I'm just too lazy to find a solution, I've already read the part for constantbuffers in the msdn (http://msdn.microsoft.com/en-us/library/windows/desktop/bb205130(v=vs.85).aspx#Create_a_Constant_Buffer) :).
And they are doing exactly the same. I really don't know what I'm doing wrong :(

I hope somebody can help me, thx so far.

Share this post


Link to post
Share on other sites
Advertisement
Enable the debug layer when creating your d3d device, this will give you more info on what went wrong exactly and which parameter was invalid

Share this post


Link to post
Share on other sites
Your problem is that constant buffer sizes need to be multiples of 16 bytes, which in your case means that you need to round up the size from 28 to 32 bytes. You can round it up by doing (size + 15) / 16.

Either way if you enable the debug layer like Radikalizm suggests (which you do by passing D3D10_CREATE_DEVICE_DEBUG when creating your device), the runtime will tell you what the problem is.

Share this post


Link to post
Share on other sites
Radikalizm, could you maybe tell me how?^^

ahh I knew that was the problem... but I wasnt sure, I'll try that, thx guys :)

Share this post


Link to post
Share on other sites
The functions D3D10CreateDevice and D3D10CreateDeviceAndSwapChain take a parameter called flags which takes a D3D10_CREATE_DEVICE_FLAG enum value which can enable certain API layers for your device.
Passing in the value D3D10_CREATE_DEVICE_DEBUG (as MJP said) will enable the debug layer for your device which will give you loads of information in your debug output when you encounter an issue.

Share this post


Link to post
Share on other sites
Thank you, btw i used the wrong descriptorname too and now it works

Share this post


Link to post
Share on other sites
You could also force the debug layer on from the SDK's DirectX control panel if you do not want to change your device creation code.

Share this post


Link to post
Share on other sites
I'd suggest adding an 8th float to your HLSL cbuffer declaration too, just as padding to make it match the size of your C++ struct, otherwise your GPU and/or driver may get unhappy with you. Also consider adding packoffset and register declarations (see last example at http://msdn.microsoft.com/en-us/library/windows/desktop/bb509581%28v=vs.85%29.aspx). All of these will make things much more robust for you.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement