Skip to main content
GameDev.net gamedev.net
🔒 Locked

DirectX10 + HLSL Constantbuffer problem

Started by Farci Aug 2, 2012 at 10:00 PM 6 replies 2.1k views
Original Post
Farci
Farci
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.
Radikalizm
Radikalizm
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
I gets all your texture budgets!
MJP
MJP
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.
Farci
Farci
Radikalizm, could you maybe tell me how?^^

ahh I knew that was the problem... but I wasnt sure, I'll try that, thx guys
Radikalizm
Radikalizm
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.
I gets all your texture budgets!
Farci
Farci
Thank you, btw i used the wrong descriptorname too and now it works
french_hustler
french_hustler
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.
21st Century Moose
21st Century Moose
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.
Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls. 

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.