Skip to content

Commit 2e902d0

Browse files
committed
more small issues resolved
1 parent b54defc commit 2e902d0

File tree

4 files changed

+22
-31
lines changed

4 files changed

+22
-31
lines changed

examples_tests/49.ComputeFFT/convolve.comp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,19 @@
88

99
layout(local_size_x=256, local_size_y=1, local_size_z=1) in;
1010

11-
#define complex_value vec2
12-
1311
layout(set=0, binding=0) restrict readonly buffer SrcBuffer
1412
{
15-
complex_value src_data[];
13+
nbl_glsl_complex src_data[];
1614
};
1715

1816
layout(set=0, binding=1) restrict readonly buffer KernelBuffer
1917
{
20-
complex_value ker_data[];
18+
nbl_glsl_complex ker_data[];
2119
};
2220

2321
layout(set=0, binding=2) restrict buffer OutputBuffer
2422
{
25-
complex_value out_data[];
23+
nbl_glsl_complex out_data[];
2624
};
2725

2826
layout(push_constant) uniform PushConstants

examples_tests/49.ComputeFFT/remove_padding.comp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,13 @@
44

55
#version 430 core
66

7+
#include <nbl/builtin/glsl/math/complex.glsl>
8+
79
layout(local_size_x=16, local_size_y=16, local_size_z=1) in;
810

9-
struct nbl_glsl_ext_FFT_output_t
10-
{
11-
vec2 complex_value;
12-
};
13-
1411
layout(set=0, binding=0) restrict readonly buffer Buffer
1512
{
16-
nbl_glsl_ext_FFT_output_t data[];
13+
nbl_glsl_complex data[];
1714
};
1815

1916
layout(set=0, binding=1, rgba16f) uniform image2D outImage;
@@ -38,7 +35,7 @@ void main()
3835
vec4 color_value = vec4(0, 0, 0, 0);
3936
for(uint c = 0; c < pc.numChannels; ++c) {
4037
uint index = c * (padded_dimension.x * padded_dimension.y) + padded_coords.y * (padded_dimension.x) + padded_coords.x;
41-
color_value[c] = data[index].complex_value.x;
38+
color_value[c] = data[index].x;
4239
}
4340
imageStore(outImage, coords, color_value);
4441
}

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

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
// Shared Memory
1111
#include <nbl/builtin/glsl/workgroup/shared_arithmetic.glsl>
12+
#include <nbl/builtin/glsl/math/functions.glsl>
1213

1314

1415
#ifndef _NBL_GLSL_EXT_FFT_MAX_DIM_SIZE_
@@ -81,33 +82,22 @@ vec2 nbl_glsl_ext_FFT_getPaddedData(in uvec3 coordinate, in uint channel);
8182
#error "You need to define `nbl_glsl_ext_FFT_getPaddedData` and mark `_NBL_GLSL_EXT_FFT_GET_PADDED_DATA_DEFINED_`!"
8283
#endif
8384

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-
9585
uint nbl_glsl_ext_FFT_calculateTwiddlePower(in uint threadId, in uint iteration, in uint logTwoN)
9686
{
9787
const uint shiftSuffix = logTwoN - 1u - iteration; // can we assert that iteration<logTwoN always?? yes
9888
const uint suffixMask = (2u << iteration) - 1u;
9989
return (threadId & suffixMask) << shiftSuffix;
10090
}
10191

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)
10393
{
10494
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));
10696
}
10797

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)
10999
{
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));
111101
}
112102

113103
uint nbl_glsl_ext_FFT_getChannel()
@@ -124,7 +114,7 @@ uvec3 nbl_glsl_ext_FFT_getCoordinates(in uint tidx)
124114

125115
uvec3 nbl_glsl_ext_FFT_getBitReversedCoordinates(in uvec3 coords, in uint leadingZeroes)
126116
{
127-
uint bitReversedIndex = nbl_glsl_ext_FFT_reverseBits(coords[pc.direction]) >> leadingZeroes;
117+
uint bitReversedIndex = bitfieldReverse(coords[pc.direction]) >> leadingZeroes;
128118
uvec3 tmp = coords;
129119
tmp[pc.direction] = bitReversedIndex;
130120
return tmp;
@@ -145,7 +135,7 @@ void nbl_glsl_ext_FFT()
145135
uint channel = nbl_glsl_ext_FFT_getChannel();
146136

147137
// Pass 0: Bit Reversal
148-
uint leadingZeroes = nbl_glsl_ext_FFT_clz(dataLength) + 1u;
138+
uint leadingZeroes = nbl_glsl_clz(dataLength) + 1u;
149139
uint logTwo = 32u - leadingZeroes;
150140

151141
nbl_glsl_complex current_values[_NBL_GLSL_EXT_FFT_MAX_ITEMS_PER_THREAD];
@@ -203,8 +193,8 @@ void nbl_glsl_ext_FFT()
203193
nbl_glsl_complex shuffled_value = shuffled_values[t];
204194

205195
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);
208198

209199
nbl_glsl_complex this_value = current_values[t];
210200

include/nbl/builtin/glsl/math/functions.glsl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,12 @@ uint nbl_glsl_rotl(in uint x, in uint k)
244244
return (x<<k) | (x>>(32u-k));
245245
}
246246

247+
// Count Leading Zeroes (naive?)
248+
uint nbl_glsl_clz(in uint x)
249+
{
250+
return 31u - findMSB(x);
251+
}
252+
247253

248254
// trig
249255

0 commit comments

Comments
 (0)