OpenGl读取和写入相同的纹理 [英] OpenGl read and write to the same texture

查看:155
本文介绍了OpenGl读取和写入相同的纹理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个RGBA16F纹理,其深度为normal.x,normal.y.我想读取r,g,b并在纹理上写入a.我将完全击中每个像素一次.

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.

您无法从正在通过FBO写入的图像中读取图像,并且期望获得合理的结果.这会产生不确定的行为.

You cannot read from an image that you are writing to via FBO and expect to get reasonable results. That's yields undefined behavior.

如果您使用shader_image_load_store进行读取/写入,则可能可以摆脱它.但是即使那样,它还是一个读/修改/写操作.您必须写回所阅读的字母.

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.

话虽如此,如果您确定自己会完全精确地击中每个像素 "(添加了重点),那么您确实有追索权.即, NV_texture_barrier .不要让该扩展名上的"NV"欺骗了您;它也广泛应用于AMD硬件(所有HD系列卡).此扩展允许您使用屏障"功能(有效地告诉GPU清除帧缓冲区和纹理缓存的功能),该功能在调用后将允许您精确地 one 一次读取/在片段着色器中修改/写入.经过一遍之后,您需要在第二遍和第二遍之间设置另一个障碍.

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.

这篇关于OpenGl读取和写入相同的纹理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆