0

I use compute shaders to compute a triangle list and to store it in a RWStructuredBuffer. For testing I read this buffer and pass it to the IA via context.InputAssembler.SetVertexBuffers (…). This approach works, but is valid only for testing the data for correctness.

Now I want to bind the (already existing) buffer to the IA stage using a resource view (aka without passing a pointer to the vertex buffer).

I am reading some good books (Frank D. Luna, Jason Zink), but they never mention this case.

=============== EDIT:

  1. The syntax I am using here in imposed by the SharpDX wrapper.

  2. I can bind the buffer to the vertex shader via context.VertexShader.SetShaderResource(...), bindig a ResoureceView. In the VS I use SV_VertexID to access the buffer. So I HAVE a working solution for moment, but there might be cases in the future where I must bind the buffer to the input assembler.

1 Answer 1

1

Simply put, you can't bind a structured buffer to the IA stage, at least directly, runtime will not allow this.

If you put ResourceOptionFlags.BufferStructured as OptionFlags, you are not allowed to use : VertexBuffer/IndexBuffer/StreamOutput/ConstantBuffer/RenderTarget/Depth as bind flags, Resource creation will fail.

One option, which costs you a GPU copy, is to create a second buffer with VertexBuffer BindFlags, and Default usage (same size as your structured buffer).

Once you are done processing your structuredbuffer, call: DeviceContext.CopyResource

And you'll have a standard vertex buffer ready to use.

Sign up to request clarification or add additional context in comments.

3 Comments

I am a bit confused: With context.InputAssembler.SetVertexBuffers I have actually bound a structured buffer to the IA stage, and I have set the input layout to exactly that structure. Many samples use this setup. In case I would make the copy you suggest, how would I bind this (new) buffer to the IA stage? Using one of the DrawIndirect calls?
See the miniTri SharpDX sample HLSL: struct VS_IN { float4 pos : POSITION; float4 col : COLOR; }; C#: var layout = new InputLayout(device, signature, new[] { new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0), new InputElement("COLOR", 0, Format.R32G32B32A32_Float, 16, 0) }); looks like a structured buffer to me...
Many samples will bind a buffer but creation doesn't have BufferStructured flag, so in that case it works. if you copy the buffer to a vertex one you just bind it like you would do as usual, since you should know vertices count. And I'm not sure why dx runtime doesn't allow this, that would be really handy.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.