5
votes

I have been at this all day and am starting to give up on it. I can't find a lot of information on compute shaders. Best source was "Practical Rendering and Computation with Direct3D 11" and unfortunately it was not too much help. It helped me understand some theories but I still don't know how to implement anything.

I am working on something similar to the particle system that is created in that book. Except my particle system will basically just have particles that display in a 3d grid (nothing like gravity/forces/etc). This is for educational purposes, if I get this working I would be able to work out the rest I assume.

What I don't understand is how the compute shader fits into the pipeline. I think I understand what I need to do, but I dont know how I am supposed to get it working.

I need to somehow seed the compute shader with a buffer filled with all of the particle positions. (Say, a 1024x1024x1 buffer). I then need this compute shader to output every position as a vertex to my vertex shader, and the rest of the pipeline is standard after that (vertex shader does all the transformations, my geometry shader expands the vertex out to a quad, and my pixel shader renders it).

I don't even know if this is right, but it sounds right. And even if it is, I have no idea as to how I would go about doing this. How would I feed the output of the compute shader to the vertex shader? How would I initially seed the compute shader to begin with? How would I ensure the compute shader does not discard the buffer of particles? (otherwise, i'd have to supply the particles every time, which would defeat the purpose of (eventually) doing a particle system with particles that move around, etc, as i would have to do all that on the CPU)

There are so many unknowns, and it feels like I am expected to know it all to even begin writing these shaders. I can't find any stepping stones.

1
It doesn't fit in with the rest of the pipeline directly, it's an independent thing. The interface uses a lot of the same things though for obvious reasons. And the results and inputs are the same kind of graphics card objects that the pipeline uses, making it very good to use in combination with the pipleline.jcoder
I got started with computer shaders by making a simple one, independent from any graphics stuff, that just populates two buffers with arrays of numbers and making a compute shader to generate a third that contains their sum and reading it back to the CPU to print... You can see how you could extend that to update the positions of a load of particles - and then there would be no need to read those positions back to the CPU, a graphics pipleline program could use the data directly as input..jcoder
I would recommend something like this book amazon.co.uk/Introduction-Game-Programming-DirectX-ebook/dp/… as it contains exactly the kind of examples you need. (Although it does seem to leave out some of the steps sometimes, I found it a good book)jcoder

1 Answers

3
votes

The compute shader isn't a part of the graphicspipeline. It's a tool for easy GPGPU, so you can use the computationpower of the graphic device for non-rendering purpose, like particlemovement, in an easier way. If you want to use it for your particle system, you should compute the particle positions first with a compute shader. Then you fill the output in you normal code into a vertexbuffer for rendering. AFAIK there is no direct way to pipe the output to the renderpipeline, but im not so familiar with compute shaders. Interesting links for you are maybe the documentation and the example there. The graphicspipeline is shown at this page.