Hello, I’ve got a possible GLSL compiler bug when writing to a shader storage buffer from a compute shader. System info is: Windows 8.1 64, driver 361.91, GTX 770.
I am filling a buffer in a loop, but writing a separate value at index 0 as follows:
#version 450
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
layout(std430) buffer _bfWrite { int bfWrite[]; };
void main() {
for (int i = 1, n = int(bfWrite.length()); i < n; ++i) {
bfWrite[ i ] = i;
}
bfWrite[0] = 999;
}
If I subsequently read the buffer I see that ‘999’ is written to index 0, but the other indices are not written. However if I move line 10 above the loop, or if I write ‘999’ to any index other than 0 the shader works as expected.
The compiler outputs the following assembly for the ‘broken’ shader (bfWrite[0] = 999 below the loop):
!!NVcp5.0
OPTION NV_shader_storage_buffer;
OPTION NV_bindless_texture;
GROUP_SIZE 1;
STORAGE sbo_buf0[] = { program.storage[0] };
PARAM sbo_storage_len0[] = { program.storagelen[0] };
TEMP R0;
TEMP RC, HC;
MOV.S R0.x, {1, 0, 0, 0};
REP.S ;
SGE.S.CC HC.x, R0, sbo_storage_len0[0];
BRK (NE.x);
ADD.S R0.x, R0, {1, 0, 0, 0};
ENDREP;
STB.S32 {999, 0, 0, 0}, sbo_buf0[0];
END
And the following assembly when bfWrite[0] = 999 is above the loop:
!!NVcp5.0
OPTION NV_shader_storage_buffer;
OPTION NV_bindless_texture;
GROUP_SIZE 1;
STORAGE sbo_buf0[] = { program.storage[0] };
PARAM sbo_storage_len0[] = { program.storagelen[0] };
TEMP R0;
TEMP RC, HC;
STB.S32 {999, 0, 0, 0}, sbo_buf0[0];
MOV.S R0.x, {1, 0, 0, 0};
REP.S ;
SGE.S.CC HC.x, R0, sbo_storage_len0[0];
BRK (NE.x);
MUL.S R0.y, R0.x, {4, 0, 0, 0}.x;
MOV.U R0.y, R0;
STB.S32 R0, sbo_buf0[R0.y];
ADD.S R0.x, R0, {1, 0, 0, 0};
ENDREP;
END
As you can see, the compiler emits the loop in the broken version, but there’s no STB instruction writing to the buffer :/
It’s not clear to me that I’m doing anything wrong in the source code, any advice appreciated.