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/componentwiseBinaryOp.hlsli | |
| parent | 990a8d0dbaefc996244097397259e92758b15cce (diff) | |
Source codes
Diffstat (limited to 'ComputeShaders/componentwiseBinaryOp.hlsli')
| -rw-r--r-- | ComputeShaders/componentwiseBinaryOp.hlsli | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/ComputeShaders/componentwiseBinaryOp.hlsli b/ComputeShaders/componentwiseBinaryOp.hlsli new file mode 100644 index 0000000..0a523ca --- /dev/null +++ b/ComputeShaders/componentwiseBinaryOp.hlsli @@ -0,0 +1,43 @@ +Buffer<float> arg0: register( t0 ); +Buffer<float> arg1: register( t1 ); +RWBuffer<float> result: register( u0 ); + +cbuffer Constants: register( b0 ) +{ + uint4 src0_elements: packoffset( c0 ); + uint4 src0_strides: packoffset( c1 ); + uint4 src1_elements: packoffset( c2 ); + uint4 src1_strides: packoffset( c3 ); + uint4 result_elements: packoffset( c4 ); + uint4 result_strides: packoffset( c5 ); +} + +[ numthreads( 32, 1, 1 ) ] +void main( uint3 group: SV_GroupID, uint thread : SV_GroupIndex ) +{ + const uint j = group.x; + const uint nb1 = result_strides[ 1 ]; + const uint nb01 = src0_strides[ 1 ]; + + const uint nb10 = src1_strides[ 0 ]; + const uint nb11 = src1_strides[ 1 ]; + const uint nc = src0_elements[ 0 ]; + + uint rsi0 = j * nb01; + uint rsi1 = j * nb11; + uint rdi = j * nb1; + const uint rsi0End = rsi0 + nc; + + rsi0 += thread; + rsi1 += thread * nb10; + rdi += thread; + + const uint rsi1Inc = 32 * nb10; + for( ; rsi0 < rsi0End; rsi0 += 32, rsi1 += rsi1Inc, rdi += 32 ) + { + const float a = arg0[ rsi0 ]; + const float b = arg1[ rsi1 ]; + const float res = compute( a, b ); + result[ rdi ] = res; + } +}
\ No newline at end of file |
