Fast Fourier transform in OpenGL Compute Shader
<p>I'm trying to implement FFT in OpenGL Compute Shaders in educational purposes (that's why I do not want to use CUDA and OpenCL), but I think that some approaches for parallel programming used in OpenCL, for example, are similar to OpenGL Compute Shaders. I've found several code examples of FFT in OpenCL: one of them is <a href="http://www.bealto.com/gpu-fft_opencl-1.html" rel="nofollow">Eric Bainville's article</a>. Sample source code from it is following:</p>

<pre><code>__kernel void fft_radix2(__global const float2 * x,__global float2 * y,int p)

{

  int i = get_global_id(0); // number of threads

  int t = get_global_size(0); // current thread

  int k = i &amp; (p-1); // index in input sequence, in 0..P-1

  x += i; // input offset

  y += (i&lt;&lt;1) - k; // output offset

  float4 u = dft2( (float4)(x[0], mul_1(exp_alpha_1(-M_PI*(float)k/(float)p),x[t]) ));

  y[0] = u.lo;

  y[p] = u.hi;

}
</code></pre>

<p>Here <code>x</code> is input and <code>y</code> is output for each step in FFT.<br>After that, he says that "This kernel must be called for <code>p = 1</code>, then <code>p = 2</code>, etc. until <code>p = N/2</code>. The number of threads at each call is <code>N/2</code>, and the work group size WG doesn't matter since all threads are independent." Here <code>N</code> is size of input (should be power of 2).<br><br>
So, my question is about parameter <code>p</code>. How can I push that parameter in compute shader, so the latter will be invoked for <code>p = 1</code>, then <code>p = 2</code>, etc. until <code>p = N/2</code>?</p>