Jump to content

  • Log In with Google      Sign In   
  • Create Account


DirectX10 + HLSL Constantbuffer problem


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 Farci   Members   -  Reputation: 126

Like
0Likes
Like

Posted 02 August 2012 - 04:00 PM

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.

Sponsor:

#2 Radikalizm   Crossbones+   -  Reputation: 2772

Like
4Likes
Like

Posted 02 August 2012 - 04:04 PM

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

#3 MJP   Moderators   -  Reputation: 10231

Like
4Likes
Like

Posted 02 August 2012 - 04:08 PM

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.

#4 Farci   Members   -  Reputation: 126

Like
0Likes
Like

Posted 02 August 2012 - 04:14 PM

Radikalizm, could you maybe tell me how?^^

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

#5 Radikalizm   Crossbones+   -  Reputation: 2772

Like
1Likes
Like

Posted 02 August 2012 - 04:35 PM

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.

#6 Farci   Members   -  Reputation: 126

Like
0Likes
Like

Posted 02 August 2012 - 05:29 PM

Thank you, btw i used the wrong descriptorname too and now it works

#7 french_hustler   Members   -  Reputation: 341

Like
1Likes
Like

Posted 02 August 2012 - 05:49 PM

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.

#8 mhagain   Crossbones+   -  Reputation: 7436

Like
0Likes
Like

Posted 02 August 2012 - 06:16 PM

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.

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS