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 Answers1

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.

mrvux
  • 8,523
  • 1
  • 27
  • 61
  • 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? – Siegfried Stephan Nov 25 '13 at 16:56
  • 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... – Siegfried Stephan Nov 25 '13 at 17:23
  • 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. – mrvux Nov 25 '13 at 20:55