Sampling from a texture which is also a render target

回眸只為那壹抹淺笑 提交于 2019-12-12 11:41:02

问题


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?

Thanks for any help!


回答1:


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.




回答2:


Matias and Goz covered the most important bits. Let me add a couple interesting facts:

  • The Direct3D runtime actively unbinds textures when you bind their underlying resource as a render-target (so you can't create the cycle there).
  • UAVs in Direct3D 11 actually allow read-modify-write operations on a subset of the formats (the ones that do not require a type conversion). They do not guarantee any order of operation, though. This is what is being used by a number of algorithms that do Order-independent transparency, notably (where the re-ordering is done manually).


来源:https://stackoverflow.com/questions/4066454/sampling-from-a-texture-which-is-also-a-render-target

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!