从也是渲染目标的纹理采样 [英] Sampling from a texture which is also a render target
问题描述
我知道这在技术上不受支持(据我所知,这是未定义的行为),但是从也要写入的纹理中采样确实是一件非常可怕的事情吗?
I know this technically isn't supported (and as far as I can tell it's undefined behavior) but is it really a fatally horrible thing to sample from a texture which is also being written to?
我问是因为我需要读取我也需要写的深度纹理,如果不能这样做,这意味着我将不得不复制深度纹理,如果这没什么大不了的我看不到仅仅复制它的危害吗?
I ask because I need to read from a depth texture which I also need to write to, if I can't do this it means I will have to copy the depth texture and if it isn't that big of a deal I don't see the harm in simply copying it?
感谢您的帮助!
推荐答案
是的,它是致命的,会触发未定义的行为.只需进行复制并从副本中读取即可.
Yes, it's fatal and triggers undefined behaviour. Just make a copy and read from the copy.
解释很简单.由于片段以未指定的顺序并行处理,因此您可能正在读取已写入的纹理像素或原始值纹理像素,并且无法知道正在读取的内容.进行复制并从中读取可以确保您读取正确的值.
The explanation is simple. Since fragments are processed in parallel in a unspecified order, you might be reading from already written texels or original value texels, and there is no way of knowing what you are reading. Making a copy and reading from it ensures that you will read the correct values.
这篇关于从也是渲染目标的纹理采样的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!