このコードを Nvidia ハードウェアで問題なく試してみましたが、AMD では imageStore() 関数は何もしないようです (GL エラーはスローされませんが、確認しました)。
シェーダー:
#extension GL_EXT_shader_image_load_store : require
layout(size4x32) uniform image2D A;
void main(void){
vec4 output = vec4(0.111, 0.222 , 0.333, 0.444);
imageStore(A, ivec2(gl_FragCoord.xy-vec2(0.5,0.5)), output);
}
コーリング プログラム:
glUseProgram(program);
glUniform1i(glGetUniformLocation (program , "A" ), id);
glBindImageTexture(id, texture, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RGBA32F);
//Bind the fbo associated with the texture to run a shader per pixel
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
glViewport(0, 0, width, height);
glDrawBuffer(GL_NONE); //Forbid gl_FragColor to be modified
//Render a quad
draw();
//Then read the texture...
Nicol Bolas ( imageStore() のトラブル (OpenGL 4.3) )による別のスレッドで提案されているように、テクスチャを読み返したときにメモリが書き込まれることを保証するためにいくつかのバリアを追加しようとしましたが、変更はありません。 write to は変更されません。
void main(void){
vec4 output = vec4(0.111, 0.222 , 0.333, 0.444);
memoryBarrier();
imageStore(A, ivec2(gl_FragCoord.xy), output);
memoryBarrier();
}
メインプログラムでは:
...
draw();
glMemoryBarrierEXT(GL_ALL_BARRIER_BITS);
...
一方、glDrawBuffer(GL_NONE) を削除して、gl_FragColor を使用して値を単純に出力すると、通常どおり動作します。
void main(void){
gl_FragColor = vec4(0.111, 0.222 , 0.333, 0.444);
}
しかし、分散書き込みを使用したいので、実際には imageStore で行う必要があります。imageLoad も使用しようとしましたが、問題はありませんでした。この imageStore 関数で何が起こっていますか?
何か案は?