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/repeatUtils.hlsli | |
| parent | 990a8d0dbaefc996244097397259e92758b15cce (diff) | |
Source codes
Diffstat (limited to 'ComputeShaders/repeatUtils.hlsli')
| -rw-r--r-- | ComputeShaders/repeatUtils.hlsli | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/ComputeShaders/repeatUtils.hlsli b/ComputeShaders/repeatUtils.hlsli new file mode 100644 index 0000000..1181501 --- /dev/null +++ b/ComputeShaders/repeatUtils.hlsli @@ -0,0 +1,21 @@ +inline uint rowOffset( uint3 idx, uint4 strides ) +{ + return idx[ 0 ] * strides[ 1 ] + idx[ 1 ] * strides[ 2 ] + idx[ 2 ] * strides[ 3 ]; +} + +// Initial iterator state for a row of the output tensor +// x = current index, y = index increment, z = end of the index +inline uint3 tensorIteratorState( uint3 group, uint thread, uint4 size, uint4 stride ) +{ + uint3 res; + res.x = rowOffset( group, stride ); + res.y = THREADS * stride[ 0 ]; + res.z = res.x + size[ 0 ] * stride[ 0 ]; + res.x += thread * stride[ 0 ]; + return res; +} + +// Handle a complete row of output tensor, using the iterator made by tensorIteratorState() function +#define ROW_LOOP( ts ) for( ; ts.x < ts.z; ts.x += ts.y ) +// Same as above, using different row length +#define ROW_LOOP_EX( ts, len, stride ) for( ; ts.x < ts.z; ts.x += len * stride[ 0 ] )
\ No newline at end of file |
