Passing dynamic information to a compute shader

Nov 1, 2011 at 4:57 PM

I need to pass dynamic information from system memory to a compute shader, such as mouse position, zoom factor, grey window center and width and many others.

Is there somthing I could use in the demos ?

Once the dynamic informations changes, how to I instruct the compute shader to restart computation ?

-- Francois Piette

Nov 1, 2011 at 6:46 PM

The typical way to get information like this into a shader program (including compute shaders) is to use a constant buffer.  This is used in all of the demos, and in particular has a strong support in the form of the parameter system for getting data to be compiled into a constant buffer.

The general idea is that you will define a structure in your shader program that specifies the data you want to have available.  Then you will specify the data that goes into that structure one member at a time with a RenderParameterDX11 subclass.  As long as the data is passed into the parameters, then it will be automatically loaded into a constant buffer for you, and made available to your shader.  Every sample that performs rendering with a RenderEffectDX11 (which nearly all of them do) provide demonstrations of how to do this.

The compute shader only executes when you call Dispatch(x,y,z) (take a look at the ImageProcessing sample for an example).  So if you want to update the data, you would write it into the appropriate parameters, and then execute your compute shader.