Sign in to follow this  

Dynamic Buffers and Compute Shaders

Recommended Posts

_the_phantom_    11250
I'm currently working on a compute shader which is effectively a rehash of my final year degree project and I've hit a bit of a snag. I need to have a structured buffer which I can write to every frame (or maybe every couple of frames, but certainly often) and read from via the shader. So, from the GPU's point of view it is read only and the cpu write only. Looking through the docs I came to the following conclusion with regards to the buffer description;
	ZeroMemory( &desc, sizeof(desc) );
	desc.Usage = D3D11_USAGE_DYNAMIC;
	desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
	desc.ByteWidth = uElementSize * uCount;
	desc.StructureByteStride = uElementSize;

Which seems logical to me; - dynamic flag allows me to read on gpu, write on cpu - cpu access write says I'll be wanting to write to the buffer However, on calling CreateBuffer on my device I get;
D3D11: ERROR: ID3D11Device::CreateBuffer: A D3D11_USAGE_DYNAMIC Resource cannot be bound to certain parts of the graphics pipeline, but must have at least one BindFlags bit set. 
The BindFlags bits (0x88) have the following settings: D3D11_BIND_STREAM_OUTPUT (0), D3D11_BIND_RENDER_TARGET (0), D3D11_BIND_DEPTH_STENCIL (0), D3D11_BIND_UNORDERED_ACCESS (1). 
First-chance exception at 0x7560b727 in D3D11VisualiserTest.exe: Microsoft C++ exception: _com_error at memory location 0x0018f4c4..
D3D11: ERROR: ID3D11Device::CreateBuffer: CreateBuffer returning E_INVALIDARG, meaning invalid parameters were passed. [ STATE_CREATION ERROR #69: CREATEBUFFER_INVALIDARG_RETURN ]

thrown back at me. I'm a bit confused as to what it wants me to do, as from what I can see I HAVE a bind buffer bit set (UNORDERED_ACCESS) which should let me do what I need. So, any clues from anyone out there? Or even a better way to do it? (I'll be uploading somewhere in the region of 5120 floats per frame, in a linear manner but not contiguous in destination memory).

Share this post

Link to post
Share on other sites
DieterVW    724
By definition, an unordered_access object is writable from the GPU, which is what's causing the problem. Since you only want GPU read, you can just bind your structured buffer as a shader_resource and the problem will be fixed. In HLSL that will be StructuredBuffer instead of RWStructuredBuffer.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this