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:
- hlsli include files to prevent duplication.
- casting groupshared memory. At first I gave up because I couldn't properly cast c arrays.
groupshared uint4 UInt4Array[4];
void main(...)
{
float Float1Array[16] = (float[16])UInt4Array;
}
- writing to groupshared memory through an output parameter.
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.