Hi,
I have trouble setting the uniforms nx, ny, nz, bx, by, bz in the following Compute Shader. I wrote their values in a buffer to check and they always have the value 0…
#version 450 core
#extension GL_NV_shader_thread_shuffle : require
#extension GL_NV_shader_thread_group : require
layout (local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
layout (std430, binding = 0) buffer Dataset
{
float values[];
} dataset;
struct MinMaxPair
{
float min;
float max;
} minMaxPair;
layout (std430, binding = 1) buffer MinMaxArray
{
MinMaxPair pairs[];
} minMaxArray;
uniform uint nx;
uniform uint ny;
uniform uint bx;
uniform uint by;
uniform uint bz;
void main()
{
uint shader_x = gl_GlobalInvocationID.x;
uint shader_y = gl_GlobalInvocationID.y;
uint shader_z = gl_GlobalInvocationID.z;
uint blockFlatIndex = shader_x + shader_y*gl_NumWorkGroups.x + shader_z*gl_NumWorkGroups.x*gl_NumWorkGroups.y;
uint blockFirstPointIndex = shader_x*(bx-1) + shader_y*(by-1)*nx + shader_z*(bz-1)*nx*ny;
MinMaxPair minMaxPair2;
minMaxPair2.min = dataset.values[blockFirstPointIndex];
minMaxPair2.max = dataset.values[blockFirstPointIndex];
uint x, y, z;
uint index;
for (z = 0; z < bz; z++)
{
for (y = 0; y < by; y++);
{
for (x = blockFirstPointIndex; x < (blockFirstPointIndex + bx); x++)
{
index = x + y*nx + z*nx*ny;
if (dataset.values[index] < minMaxPair2.min)
{
minMaxPair2.min = dataset.values[index];
}
if (dataset.values[index] > minMaxPair2.max)
{
minMaxPair2.max = dataset.values[index];
}
}
}
}
minMaxPair2.min = bx;
minMaxPair2.max = by;
minMaxArray.pairs[blockFlatIndex] = minMaxPair2;
}
I am using Qt-Wrapper classes to interface with the shader program. The following code shows all that should be necessary to set uniforms…
Create the QOpenGLShaderProgram object
m_computeShaderProgram = new QOpenGLShaderProgram();
Add shader source code, link and bind the program.
if (!m_computeShaderProgram->addShaderFromSourceFile(QOpenGLShader::Compute, "./shaders/parallelMarchingBlocks/minMaxPairs.comp"))
{
std::cout << "minMaxPairs.comp compilation error: " << m_computeShaderProgram->log().toStdString() << std::endl;
}
if (!m_computeShaderProgram->link())
{
std::cout << "m_computeShaderProgram linking error: " << m_computeShaderProgram->log().toStdString() << std::endl;
}
if (!m_computeShaderProgram->bind())
{
std::cout << "m_computeShaderProgram bind error: " << m_computeShaderProgram->log().toStdString() << std::endl;
}
m_computeShaderProgram->release();
Bind shader program, set the uniform values and start the compute shader…
if (!m_computeShaderProgram->bind())
{
qDebug() << "ERROR WHEN TRYING TO BIND COMPUTE SHADER PROGRAM";
}
m_computeShaderProgram->setUniformValue(m_computeShaderProgram->uniformLocation("nx"), nx);
m_computeShaderProgram->setUniformValue(m_computeShaderProgram->uniformLocation("ny"), ny);
m_computeShaderProgram->setUniformValue(m_computeShaderProgram->uniformLocation("bx"), bx);
m_computeShaderProgram->setUniformValue(m_computeShaderProgram->uniformLocation("by"), by);
m_computeShaderProgram->setUniformValue(m_computeShaderProgram->uniformLocation("bz"), bz);
context->glDispatchCompute(numBlocksXDirection, numBlocksYDirection, numBlocksZDirection);
I have checked with the debugger that the values that I am passing to setUniformValue are actually the values that I want to pass. I have also checked that uniformLocation() does not return -1 for the uniforms.