Skip to content

Commit 32eddff

Browse files
committed
better twiddle computation
1 parent c73d576 commit 32eddff

File tree

1 file changed

+5
-3
lines changed
  • include/nbl/builtin/glsl/ext/FFT

1 file changed

+5
-3
lines changed

include/nbl/builtin/glsl/ext/FFT/fft.glsl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,16 @@ uint nbl_glsl_ext_FFT_reverseBits(in uint x)
8484
return bitfieldReverse(x);
8585
}
8686

87-
uint nbl_glsl_ext_FFT_calculateTwiddlePower(in uint threadId, in uint iteration, in uint logTwoN, in uint N)
87+
uint nbl_glsl_ext_FFT_calculateTwiddlePower(in uint threadId, in uint iteration, in uint logTwoN)
8888
{
89-
return (threadId & ((N / (1u << (logTwoN - iteration))) * 2 - 1)) * ((1u << (logTwoN - iteration)) / 2);;
89+
const uint shiftSuffix = logTwoN - 1u - iteration; // can we assert that iteration<logTwoN always?? yes
90+
const uint suffixMask = (2u << iteration) - 1u;
91+
return (threadId & suffixMask) << shiftSuffix;
9092
}
9193

9294
vec2 nbl_glsl_ext_FFT_twiddle(in uint threadId, in uint iteration, in uint logTwoN, in uint N)
9395
{
94-
uint k = nbl_glsl_ext_FFT_calculateTwiddlePower(threadId, iteration, logTwoN, N);
96+
uint k = nbl_glsl_ext_FFT_calculateTwiddlePower(threadId, iteration, logTwoN);
9597
return nbl_glsl_expImaginary(-1 * 2 * nbl_glsl_PI * k / N);
9698
}
9799

0 commit comments

Comments
 (0)