9
9
10
10
// Shared Memory
11
11
#include < nbl/ builtin/ glsl/ workgroup/ shared_arithmetic.glsl>
12
+ #include < nbl/ builtin/ glsl/ math/ functions.glsl>
12
13
13
14
14
15
#ifndef _NBL_GLSL_EXT_FFT_MAX_DIM_SIZE_
@@ -81,33 +82,22 @@ vec2 nbl_glsl_ext_FFT_getPaddedData(in uvec3 coordinate, in uint channel);
81
82
#error "You need to define `nbl_glsl_ext_FFT_getPaddedData` and mark `_NBL_GLSL_EXT_FFT_GET_PADDED_DATA_DEFINED_`! "
82
83
#endif
83
84
84
- // Count Leading Zeroes (naive?)
85
- uint nbl_glsl_ext_FFT_clz(in uint x)
86
- {
87
- return 31u - findMSB(x);
88
- }
89
-
90
- uint nbl_glsl_ext_FFT_reverseBits(in uint x)
91
- {
92
- return bitfieldReverse(x);
93
- }
94
-
95
85
uint nbl_glsl_ext_FFT_calculateTwiddlePower(in uint threadId, in uint iteration, in uint logTwoN)
96
86
{
97
87
const uint shiftSuffix = logTwoN - 1u - iteration; // can we assert that iteration<logTwoN always?? yes
98
88
const uint suffixMask = (2u << iteration) - 1u;
99
89
return (threadId & suffixMask) << shiftSuffix;
100
90
}
101
91
102
- nbl_glsl_complex nbl_glsl_ext_FFT_twiddle(in uint threadId, in uint iteration, in uint logTwoN, in uint N )
92
+ nbl_glsl_complex nbl_glsl_ext_FFT_twiddle(in uint threadId, in uint iteration, in uint logTwoN)
103
93
{
104
94
uint k = nbl_glsl_ext_FFT_calculateTwiddlePower(threadId, iteration, logTwoN);
105
- return nbl_glsl_expImaginary(- 1 * 2 * nbl_glsl_PI * k / N );
95
+ return nbl_glsl_expImaginary(- 1 .0f * 2 .0f * nbl_glsl_PI * float (k) / ( 1 << logTwoN) );
106
96
}
107
97
108
- nbl_glsl_complex nbl_glsl_ext_FFT_twiddleInverse(in uint threadId, in uint iteration, in uint logTwoN, in uint N )
98
+ nbl_glsl_complex nbl_glsl_ext_FFT_twiddleInverse(in uint threadId, in uint iteration, in uint logTwoN)
109
99
{
110
- return nbl_glsl_complex_conjugate(nbl_glsl_ext_FFT_twiddle(threadId, iteration, logTwoN, N ));
100
+ return nbl_glsl_complex_conjugate(nbl_glsl_ext_FFT_twiddle(threadId, iteration, logTwoN));
111
101
}
112
102
113
103
uint nbl_glsl_ext_FFT_getChannel()
@@ -124,7 +114,7 @@ uvec3 nbl_glsl_ext_FFT_getCoordinates(in uint tidx)
124
114
125
115
uvec3 nbl_glsl_ext_FFT_getBitReversedCoordinates(in uvec3 coords, in uint leadingZeroes)
126
116
{
127
- uint bitReversedIndex = nbl_glsl_ext_FFT_reverseBits (coords[pc.direction]) >> leadingZeroes;
117
+ uint bitReversedIndex = bitfieldReverse (coords[pc.direction]) >> leadingZeroes;
128
118
uvec3 tmp = coords;
129
119
tmp[pc.direction] = bitReversedIndex;
130
120
return tmp;
@@ -145,7 +135,7 @@ void nbl_glsl_ext_FFT()
145
135
uint channel = nbl_glsl_ext_FFT_getChannel();
146
136
147
137
// Pass 0: Bit Reversal
148
- uint leadingZeroes = nbl_glsl_ext_FFT_clz (dataLength) + 1u;
138
+ uint leadingZeroes = nbl_glsl_clz (dataLength) + 1u;
149
139
uint logTwo = 32u - leadingZeroes;
150
140
151
141
nbl_glsl_complex current_values[_NBL_GLSL_EXT_FFT_MAX_ITEMS_PER_THREAD];
@@ -203,8 +193,8 @@ void nbl_glsl_ext_FFT()
203
193
nbl_glsl_complex shuffled_value = shuffled_values[t];
204
194
205
195
nbl_glsl_complex twiddle = (0u == pc.is_inverse)
206
- ? nbl_glsl_ext_FFT_twiddle(tid, i, logTwo, dataLength )
207
- : nbl_glsl_ext_FFT_twiddleInverse(tid, i, logTwo, dataLength );
196
+ ? nbl_glsl_ext_FFT_twiddle(tid, i, logTwo)
197
+ : nbl_glsl_ext_FFT_twiddleInverse(tid, i, logTwo);
208
198
209
199
nbl_glsl_complex this_value = current_values[t];
210
200
0 commit comments