diff options
| author | Konstantin <const@const.me> | 2023-01-16 14:52:43 +0100 |
|---|---|---|
| committer | Konstantin <const@const.me> | 2023-01-16 14:52:43 +0100 |
| commit | 8c4603c73675958efc960fbd4bb599a2909d106a (patch) | |
| tree | 714dc6fc9a1672d5fd7f89676b97e10959662abc /ComputeShaders/addInPlace.hlsl | |
| parent | 990a8d0dbaefc996244097397259e92758b15cce (diff) | |
Source codes
Diffstat (limited to 'ComputeShaders/addInPlace.hlsl')
| -rw-r--r-- | ComputeShaders/addInPlace.hlsl | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/ComputeShaders/addInPlace.hlsl b/ComputeShaders/addInPlace.hlsl new file mode 100644 index 0000000..a83c221 --- /dev/null +++ b/ComputeShaders/addInPlace.hlsl @@ -0,0 +1,39 @@ +#ifndef THREADS +#define THREADS 512 +#endif + +Buffer<float> arg0: register( t0 ); +RWBuffer<float> result: register( u0 ); + +cbuffer Constants: register( b0 ) +{ + uint4 size: packoffset( c0 ); + uint4 strides: packoffset( c1 ); + uint4 argStrides: packoffset( c3 ); +} + +inline uint rowOffset( uint3 idx, uint4 strides ) +{ + return idx[ 0 ] * strides[ 1 ] + idx[ 1 ] * strides[ 2 ] + idx[ 2 ] * strides[ 3 ]; +} + +[ numthreads( THREADS, 1, 1 ) ] +void main( uint3 group: SV_GroupID, uint thread : SV_GroupIndex ) +{ + uint rdi = rowOffset( group, strides ); + uint rsi = rowOffset( group, argStrides ); + + const uint rdiEnd = rdi + size[ 0 ] * strides[ 0 ]; + rdi += thread * strides[ 0 ]; + rsi += thread * argStrides[ 0 ]; + + const uint rdiInc = THREADS * strides[ 0 ]; + const uint rsiInc = THREADS * argStrides[ 0 ]; + + for( ; rdi < rdiEnd; rdi += rdiInc, rsi += rsiInc ) + { + float f = result[ rdi ]; + f += arg0[ rsi ]; + result[ rdi ] = f; + } +}
\ No newline at end of file |
