Hello, I need to perform some calculations with compute shader. Input data will be sent to it in image2D, so I’ve written this line in my compute shader:
layout(rg32f, binding = 0) readonly uniform image2D imageIn;
As you can see, each element of image consists of two floating-point numbers. Namely, they are real and imaginary parts of complex number. In C++ code I have structure for it and array with proper complex numbers:
struct complex_number {
float re, im;
}
...
complex_number *h_fft = new complex_number[N * N];
// filling h_fft
Now I need to send that array to imageIn in compute shader. What I do is generating texture first:
glGenTextures(1, &texture_H_t);
glBindTexture(GL_TEXTURE_2D, texture_H_t);
glTexStorage2D(GL_TEXTURE_2D, 1, GL_RG32F, N, N);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
Then in place of calculation I update texture with array of complex numbers by glTexSubImage2D():
glBindTexture(GL_TEXTURE_2D, texture_H_t);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, N, N, GL_RG, GL_FLOAT, h_fft);
And finally run compute shader:
glBindImageTexture(0, texture_H_t, 0, GL_FALSE, 0, GL_READ_ONLY, GL_RG32F);
glDispatchCompute(...);
glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);
However, it seems that imageIn variable in compute shader is filled by zeros. Also I tried using glTexImage2D() instead of glTexSubImage2D() - same result. I think that my problem is writing C++ structure to texture without some extra actions, but I have a little experience with OpenGL.
Could you please help me?