PDA

View Full Version : Computer shader write to image3D not work



destiny
01-03-2013, 02:57 AM
I tried to modify a 3D texture in a compute shader with a fixed value, but it seems the texture has never changed.



#version 430 compatibility


layout(r8) uniform image3D destTex;
layout (local_size_x = 36, local_size_y = 36,local_size_z = 1) in;


void main()
{
ivec3 storePos = ivec3(gl_GlobalInvocationID.xyz);
imageStore(destTex, storePos, vec4(3.0/255.0));
}





glActiveTexture(GL_TEXTURE3);
glBindTexture(GL_TEXTURE_3D,m_uiMaskPoolTexID);
glTexImage3D(GL_TEXTURE_3D,
0,
GL_R8,
m_aBrickPoolDim[0],
m_aBrickPoolDim[1],
m_aBrickPoolDim[2],
0,
GL_RED,
GL_UNSIGNED_BYTE,
nullptr);
glBindImageTexture(3,
m_uiMaskPoolTexID,
0,
GL_FALSE,
0,
GL_WRITE_ONLY,
GL_R8);
glBindTexture(GL_TEXTURE_3D,0);




glEnable(GL_TEXTURE_3D);

glActiveTexture(GL_TEXTURE3);
glUseProgram(imaskProgram);
glBindTexture(GL_TEXTURE_3D,iMask);
glBindImageTexture(3,
iMask,
0,
GL_FALSE,
0,
GL_WRITE_ONLY,
GL_R8);

int texp = glGetUniformLocation(imaskProgram, "destTex");

glUniform1i(texp, 3);
glDispatchCompute(aBrickPoolDim[0]/36,aBrickPoolDim[1]/36,aBrickPoolDim[2]);
glMemoryBarrier(GL_ALL_BARRIER_BITS);
glBindTexture(GL_TEXTURE_3D,0);

AHeumann
01-09-2013, 05:01 AM
The code looks fine.
I assume you are using NVIDIA hardware. There had been a bug with compute shaders and textures which is now fixed. Have you tried the latest drivers? Release 310.90 has the fix.

destiny
01-16-2013, 12:31 AM
I'am using 310.70, and 2d texture works fine.I'll get a newest driver and try again