Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
298 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...