Texture sampling, which is also a rendering target

I know that this is not technically supported (and as far as I can tell this behavior is undefined), but is it really a terribly awful thing to select from a texture that also writes to?

I ask, because I need to read the depth texture, which I also need to write, if I can’t do this, does it mean that I will have to copy the depth texture and if it is not a big deal I don’t see the harm of just copying?

Thanks for any help!

+3
source share
2 answers

Yes, this is fatal and causes undefined behavior. Just make a copy and read from the copy.

The explanation is simple. Since the fragments are processed in parallel in an unspecified order, you can read from the texels already written or the original texels, and there is no way to know what you are reading. Creating a copy and reading from it ensures that you read the correct values.

+3
source

Matthias and Goz examined the most important bits. Let me add a couple of interesting facts:

  • The Direct3D runtime actively unleashes textures when you anchor your base resource as a rendering target (so you cannot create a loop there).
  • Direct3D 11 -- (, ). , . , , , ( ).
+2

Source: https://habr.com/ru/post/1772421/


All Articles