So I wrote this really simple compute shader. I'm processing a buffer of ints and outputing the result in a RWStructuredBuffer.
I had trouble with converting the 3D coordinates of a GPU thread to a 1D coordinate of my buffer.
The way I got around this was by passing in (by means of a cbuffer) to the compute shader, the dispatch dimensions.
cbuffer dispatchParams : register(b0)
Then, the 1D coordinate was calculated in the shader as
[numthreads(size_x, size_y, 1)]
int index = DispatchThreadID.x + DispatchThreadID.y *( DispatchSize.x * size_x) + DispatchThreadID.z * (DispatchSize.x * size_x ) * (DispatchSize.y * size_y);
Is this how it's done? It just seems counterintuitive, since the compute shader gets all this data automaticaly (SV_DispatchThreadID, SV_GroupID etc...) I kinda expected that there would be a better way of doing this.... Any opinions?
Edited by gfxCahd, 26 February 2014 - 07:26 AM.