0

I am about to add compute shader support to my codebase and having problems finding answers to some pretty basic questions:

  1. All documentation out there says that Compute Shader pipeline runs independently from the GPU, however all dx11 sample code uses the device context interface to set the shader itself, resource views and calling the dispatch() method, so do these get queued up in the command buffer with the rest of the rendering commands or do they get executed independently?

  2. Following up on question 1, can I invoke compute shaders from multiple threads or do I need to buffer all compute shader commands and issue them on the thread that the immediate device context was created on?

  3. Synchronization. Most articles use the CopyResource command which will automatically synchronize compute shader completion and give CPU access to the results, but seems like that would block the GPU as well. Is there a more efficient way to synchronize?

I know I could find answers to this by experimenting, but any help that saves me time would be appreciated.

Rincer
  • 31
  • 4

1 Answers1

2
  1. The Compute Shader pipeline runs independently from the Rendering pipeline, i.e. vertex shaders, pixel shaders, blend states, etc. have no effect on what happens when you call Dispatch(). However, they do go into the same queue, so ordering between calls to Draw and Dispatch are preserved.

  2. All calls to the immediate context must be done from a single thread.

  3. One common approach is to use two buffers. While one is being operated on with the compute shader, the other is being copied back and read by the CPU. Most GPUs will be able to parallelize this.

MooseBoys
  • 6,641
  • 1
  • 19
  • 43
  • I see, so what happens when I call Present()? Does the Compute Shader pipeline behave the same as the rendering pipeline? Meaning – Rincer Jan 23 '14 at 23:22
  • I see, so what happens if I have a compute shader queued up and I call Present()? Will it stall until the compute shader finishes executing? Basically is it possible to run a compute shader that spans multilpe render frames? – Rincer Jan 23 '14 at 23:28