# DX11 [SlimDX] DX11 Structured buffer creation error

This topic is 3174 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, First of all I'd like to say thanks for all the hard work and support you guys are giving here. Really appreciated all the work you put in SlimDX, keep it up. Also I've learned so much from this site simply by searching and reading the forums and articles. Cheers! Now..I'm a beginner in 3D programming (started learning not that long ago), but I'm not new to the whole programming thing. I put up a basic DX10 rendering engine in C# to get familiar with these things, it will be used for my project later. This evening I've decided to play around with compute shaders (was always excited about this DX11 feature) and try to add some basic GPU compute support to my engine. My starting point was the BasicCompute11 sample from the latest DX SDK (I'm trying to port in to SlimDX with C#) which hasn't worked out as I've expected.. I'm getting a E_INVALIDARG error when I try to create a structured buffer. After some more testing and debugging I'm really out of ideas, but I hope that you guys will be able to say what I'm missing here. Here's the code which is relevant to my problem: Struct element which will gonna fill the buffer:
          struct test_buff
{
public int ii;
public float ff;
}


And the part where I create the buffer:
            BufferDescription b_desc = new BufferDescription();
b_desc.BindFlags = (BindFlags)0x80L | BindFlags.ShaderResource; // 0x80L - UnorderedAccessView
b_desc.SizeInBytes = Marshal.SizeOf(typeof(test_buff)) * 1024;
b_desc.OptionFlags = ResourceOptionFlags.StructuredBuffer;
b_desc.StructureByteStride = Marshal.SizeOf(typeof(test_buff));
b_desc.Usage = ResourceUsage.Default;
b_desc.CpuAccessFlags = CpuAccessFlags.None;

Buffer buf1 = new Buffer(device, b_desc);


After enabling debugging I'm getting this error information:
D3D11: ERROR: ID3D11Device::CreateBuffer: When creating a buffer with the MiscFlag D3D11_RESOURCE_MISC_BUFFER_STRUCTURED specified, the StructureByteStride must be greater than zero, no greater than 2048, and a multiple of 4. [ STATE_CREATION ERROR #2097340: CREATEBUFFER_INVALIDSTRUCTURESTRIDE ]
First-chance exception at 0x74e8b727 in Demo.exe: Microsoft C++ exception: _com_error at memory location 0x0032ed3c..
D3D11: ERROR: ID3D11Device::CreateBuffer: CreateBuffer returning E_INVALIDARG, meaning invalid parameters were passed. [ STATE_CREATION ERROR #69: CREATEBUFFER_INVALIDARG_RETURN ]


It seems like my b_desc.StructureByteStride is invalid or something... although I've checked - Marshal.SizeOf(typeof(test_buff)) returns 8 as it supposed to be in this case (which is indeed a multiple of 4). I've even tried setting the StructureByteStride with other values which hasn't changed anything. Any help or tips would be great :) If you need any more info - just ask. Thanks for your time. [Edited by - Sieras on November 6, 2009 4:53:03 PM]

##### Share on other sites
You've said it yourself:
Quote:
 Marshal.SizeOf(typeof(test_buff)) returns 8 as it supposed to be in this case
So, 8 * 1024 = 8192 which is certainly above the upper allowed limit of 2048, which is stated in the error message. Looks like your buffer is simply too large.

##### Share on other sites
Quote:
Original post by sirob
You've said it yourself:
Quote:
 Marshal.SizeOf(typeof(test_buff)) returns 8 as it supposed to be in this case
So, 8 * 1024 = 8192 which is certainly above the upper allowed limit of 2048, which is stated in the error message. Looks like your buffer is simply too large.

Well I thought so too in the first place, tried changing that value any other value so that the whole buffer size would be smaller than 2048 and it still gives me the same error. It facts it works fine in the BasicCompute11 SDK sample with 1024 multiplied by 8 (struct size) so it shouldn't be a problem here.

It seems like compiler complains about StructureByteStride value and not the whole buffer size.

Any more ideas? :)

##### Share on other sites
Hi Sieras

I've also translated the BasicCompute11 from the DirectX SDK to C# / SlimDX to get familar with GPU computing.

There were a few errors in SlimDX which were closed in revision r1237 (StructureByteStride not used) and r1242 (BufferEx properties missing).

So make sure you got the latest svn trunk of SlimDX, especially when you are using DirectX 11 features.

##### Share on other sites
Quote:
 Original post by Dysprosium88Hi SierasI've also translated the BasicCompute11 from the DirectX SDK to C# / SlimDX to get familar with GPU computing.There were a few errors in SlimDX which were closed in revision r1237 (StructureByteStride not used) and r1242 (BufferEx properties missing).So make sure you got the latest svn trunk of SlimDX, especially when you are using DirectX 11 features.

Thanks for your reply. I've downloaded and compiled the latest HEAD version from SVN and now it's working as it supposed to. Now I can get back to work :)

Thanks again. I'll try to keep SlimDX up-to-date next time.

1. 1
Rutin
24
2. 2
3. 3
JoeJ
18
4. 4
5. 5

• 38
• 23
• 13
• 13
• 17
• ### Forum Statistics

• Total Topics
631706
• Total Posts
3001835
×