I've been writing gpgpu compute shaders in the most awful style (i.e. just one monolithic procedure). I think the problem is I've read virtual no code that's not like this, so I was hoping someone can point me to some code to learn style from.
I'm hoping to program in a more functional style (for my parallel-reductions, butterflies etc.) and was wondering if something could be achieved using macros. (scans are suppose to be primitives for gpgpu)
The things I'm looking for include:
groupshared uint4 UInt4Array[4];
void main(...)
{
float Float1Array[16] = (float[16])UInt4Array;
}
void square(float input, out float ans)
{
ans = input*input
}
groupshared float shared[THREAD_GROUP_LENGTH];
numthreads(THREAD_GROUP_LENGTH, 1, 1)]
void main(uint3 position : SV_DispatchThreadID)
{
square(position.x, shared[position.x])
}
Also if anyone has any style tips like these please post them.
I do a lot of my gpgpu work with DirectML now, so I'm never going to get around to writing macros for parallel reductions/expansions.
I only use compute shaders for the more exotic work, which is quite manageable as all the tedium of doing the math for parallel reductions/expansions can be passed on to DirectML operators (i.e. DML_OPERATOR_REDUCE
and DML_OPERATOR_TILE
, although I'm now doing matrix multiplications as well now).
Unfortunately, you can only use DirectML with DirectX12.