开发者

Sampling from a texture which is also a render target

开发者 https://www.devze.com 2023-01-22 15:52 出处:网络
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 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 copyin开发者_StackOverflowg it?

Thanks for any help!


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.


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).
0

精彩评论

暂无评论...
验证码 换一张
取 消