从也是渲染目标的纹理中采样

发布于 2024-09-30 09:45:44 字数 180 浏览 12 评论 0原文

我知道这在技术上不受支持(据我所知,这是未定义的行为),但是从也被写入的纹理中采样真的是一件非常可怕的事情吗?

我问这个问题是因为我需要从深度纹理中读取数据,我也需要写入该深度纹理,如果我不能这样做,这意味着我将不得不复制深度纹理,如果这没什么大不了的,我就不会这样做。没有看到简单复制它的危害吗?

感谢您的帮助!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

猫卆 2024-10-07 09:45:44

是的,它是致命的并会引发未定义的行为。只需制作一份副本并从副本中读取即可。

解释很简单。由于片段以未指定的顺序并行处理,因此您可能正在从已写入的纹素或原始值纹素中读取,并且无法知道您正在读取的内容。制作副本并从中读取可确保您读取到正确的值。

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.

抱着落日 2024-10-07 09:45:44

马蒂亚斯和戈兹涵盖了最重要的部分。让我添加几个有趣的事实:

  • 当您将底层资源绑定为渲染目标时,Direct3D 运行时会主动解除纹理绑定(因此您无法在那里创建循环)。
  • Direct3D 11 中的 UAV 实际上允许对格式的子集(不需要类型转换的格式)进行读取-修改-写入操作。但他们不保证任何操作顺序。这是许多实现与顺序无关的透明度的算法所使用的,特别是(手动完成重新排序)。

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).
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文