   global variable changes in hlsl
  is there any way to update a global variable in a pixel shader?i am trying to keep a running average of a derivative, but i cant seem to update any sort of global variable. i could do the derivative in the cpu and pass it along with each new texture update but it is soo expensive with the amount of data i am crunching, so i wanted to keep it all in the gpu. the ideal setup would be a sort of FIR filter which updates the average derivative but is spread across several frames of data. basically i want the running average of the derivative over the last 2 to 10 frames of data, at up to a million points per frame. this will easily overload the cpu when i ramp up the framerate to 60+ fps seeing as it is partially occupied already. i have several variables that i am passing into the shaders, but there is no writeback to update the values in the pc? i wouldnt mind storing the value in the pc side seeing as each pixel will only very slightly alter the running average so it doesnt matter whether or not the updates are synchronous. i just need some means of getting the values out of the pixel shader. the only option i can think of is to render to a texture an a first pass and then render to the screen. just to get some output from the shaders into the pc then pass them back into the gpu. how do i get a value out of the shaders?   
  The only thing a pixel shader can write to is the output render target.  It can't directly writeback values to the CPU, and it can't read and write global variables that are shared by all running pixel shaders.  Remember that there will be many shaders running in parallel, they don't all run one at a time.If you really want to do this sort of thing on a GPU then your best bet is to look into using CUDA or D3D11 compute shaders.   ;  then is there any way to sample more than 7 texels away from the current texel?or is that error due to hitting the edge of the texture and going into null space?   ;  You can sample wherever you want on the texture, you have full control over texture coordinates.  If you go past the edges, then what you get depends on your sampler states.  If you use WRAP, then the coordinate will "loop around" back to the beginning.  If you use CLAMP, then the coordinate will be clamped to the edge of the texture.   