Source browser
examples/shaders/fft_bit_reverse.cpp
Read the complete file below or download its original bytes. Line numbers provide stable links to a declaration or processing step.
File fingerprint
1// Arrange complex values in the order needed by radix-two butterflies.
2#ifdef __cplusplus // Include the runtime only in the generated C++ build.
3#include "shdr.h" // Use the same resource types as the other examples.
4#endif // Finish header inclusion for the generated C++ build.
5layout(local_size_x = 64) in; // Each invocation arranges one complex value.
6layout(std430, binding = 0) readonly buffer Input { // Read channel-major input.
7 vec2 input_values[]; // Read channel-major input.
8}; // Read channel-major input.
9layout(std430, binding = 1) writeonly buffer Output { // Write to separate working storage.
10 vec2 output_values[]; // Write to separate working storage.
11}; // Write to separate working storage.
12uniform uint block_length; // Number of complex values in one channel.
13uniform uint channels; // Number of independent transforms.
14uniform uint bits; // Number of binary digits in a channel index.
15void main() { // Run the same index permutation on the CPU or GPU.
16 uint index = gl_GlobalInvocationID.x; // Identify one output value across all channels.
17 if (index >= block_length * channels) // Ignore extra invocations in the last group.
18 return; // Ignore extra invocations in the last group.
19 uint position = index % block_length; // Find the position within this channel.
20 uint reversed = 0u; // A single-sample transform has only position zero.
21 if (bits != 0u) // Keep only the reversed index bits.
22 reversed = bitfieldReverse(position) >> (32u - bits); // Keep only the reversed index bits.
23 output_values[index - position + reversed] = // Permute the positions within this signal channel.
24 input_values[index]; // Permute the positions within this signal channel.
25} // All later stages read this completed permutation.