What is a dependent texture read?

匿名 (未验证) 提交于 2019-12-03 10:24:21

问题:

I've been reading papers on computer graphics, and every so often I come across the term "dependent texture read" or "dependent texture fetch" used in the context of querying textures in shader code. What is a dependent texture read, and what is the difference between this and a "normal" texture read?

回答1:

A "dependent texture read" is when return values from one texture lookup (or other in-shader computations) are used to determine WHERE to look up from a second texture. An important implication is that the texture coordinates (where you look up from) is not determined until the middle of execution of the shader... there's no kind of static analysis you can do on the shader (even knowing the values of all parameters) that will tell you what the coordinates will be ahead of time. It also strictly orders the two texture reads and limits how much the execution order could be changed by optimizations in the driver, etc.

On older graphics cards, there used to be quite a few limitations on this kind of thing. For example, at one point (IIRC) you could look up from multiple textures but only with a small number of distinct texture coordinates. The hardware was actually implemented in a way that certain types of dependent texture reads were either impossible or very inefficient.

In the latest generation or two of cards, you shouldn't have to worry about this. But you may be reading books or articles from a couple years ago when you really did have to pay close attention to such things.



回答2:

The accepted answer (and the one below it) incorrectly restricts dependent texture reads to using the output of another texture read. That is incorrect.

A dependent texture read is any texture read with coordinates that are not the exact coordinates passed into the shader program. Even a swizzle will cause a dependent texture read.

This is taken directly from Apple's OpenGL ES programming guide.



回答3:

A normal texture read just uses the texture coordinates passed into the shader. A dependent texture read is with texture coordinates that were calculated in part using values fetched from another texture previously accessed in the shader. Thus the second texture access is "dependent" on the value fetched from the first.



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