1

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.

Tom Huntington
  • 2,260
  • 10
  • 20

1 Answers1

0

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.

Tom Huntington
  • 2,260
  • 10
  • 20
  • I just spent hours debugging a missed placed `GroupMemoryBarrierWithGroupSync();`. Very glad I am using DirectML whenever I can now – Tom Huntington Aug 29 '22 at 04:23