I have a RGBA16F texture with depth, normal.x, normal.y on it. I want to read r, g, b and write to a on the texture. I will hit every pixel exactly once.
Would there be a performance problem if I read and write to the same texture in this case?
There won't be a performance problem. There will be a functionality problem. As in, it won't work.
You cannot read from an image that you are writing to via FBO and expect to get reasonable results. That's yields undefined behavior.
If you were using shader_image_load_store to do your reading/writing, you might be able to get away with it. But even then, it's a read/modify/write operation; you have to write back the alpha that you read.
That being said, if you are certain that you will "hit every pixel exactly once" (emphasis added), you do have a recourse. Namely, NV_texture_barrier. Don't let the "NV" on this extension fool you; it's widely implemented on AMD hardware as well (all HD-series cards). This extension allows you to use a "barrier" function (effectively a function that tells the GPU to clear the framebuffer and texture caches) which, after calling, will allow you to do exactly one pass of read/modify/write in your fragment shader. After that one pass, you need another barrier between that and your second pass.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With