Read the framebuffer during writing?

NV’s G80 card could read/write the buffers by single thread in CUDA, so is it possible to read the framebuffer in fragment shader? I’d like to read/write in a single rendering pass to realize a kind of fragments blending.

Not AFAIK. But I am on slightly older ATI HW until Apple starts shipping toys to me!!

Perhaps render to a texture in an FBO and read-back from there after?

no the behaviour is undefined if you do this. you will get away with it on some devices but it’s a bad idea. as scratt suggested render to texture via fbo and read back in a seperate pass.

I really need to do this in a single pass, for example, to emulate depth testing or blending. You mentioned the behaviour is undefined, could you hint me what is the behavor in GLSL (how to represent the framebuffer data)?, like:
if( value > gl_FBDepth ) gl_FragDepth = value;

sorry i had my gpgpu hat on when i replied.
The behaviour is undefined when reading from a texture also bound for write via an fbo. there is no way to directly read a standard framebuffer in the fragment shader.

You don’t need to read the depth value. Just copy that depth data into the framebuffer and it will automatically be used for early discard.

I don’t know much about CUDA, but reading the reference a bit maybe that R/W memory you meant is the global “device” uncached memory. Which is noted to be horribly slow. Uncached access isn’t exposed in opengl.

I have tried binding the texture which is used as the destination of a FBO, like:

glBindTexture(GL_TEXTURE_2D, Texture[0]);
bindShader();//fragment shader performs texture read and FragData write
glDrawArrays( ... )

//Fragment Shader
uniform sampler2D framebuffer;
void main () {
  vec4 fbcolor = vec4(texture2D(framebuffer, position));
  gl_FragData[0] = func( fbcolor );

It works, but there randomly occurs mozaic artifacts.
this is rendered by conventional texture reading and write to another buffer:

this is rendered by single texture R/W by FBO

BTW,I’m using Geforce8800GTS

maybe the picture proves that “the result is undefined!”, I ever did some test when I was using pingpong algorithm. reading and writing to the same attachment gave me the similar result as I did it correctly. But randomly there are some pixels are flicking( I was keeping updating the texture ). And the benefit I got is: great performance improvement (but I can not use it )

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.