简体   繁体   English

OpenGL 4.2使用与图像和采样器相同的纹理

[英]OpenGL 4.2 use same texture as image and as sampler

Is it legal (and well defined) to use the same texture as an image2D as well as a sampler2D? 使用与image2D和sampler2D相同的纹理是否合法(并且定义明确)?

currently I use imageLoad() and imageStore() within the GLSL shader to write and load from a image2D. 当前,我在GLSL着色器中使用imageLoad()和imageStore()从image2D写入和加载。 However, I would like to read (not write) also from some mipmap levels of the texture, but this is not supported by imageLoad (I think I would have to bind each mipMap level as a separate image2D but the ammount of available image units is quite limited). 但是,我也想从某些纹理的mipmap级别读取(而不是写入),但是imageLoad不支持此功能(我想我必须将每个mipMap级别绑定为一个单独的image2D,但是可用图像单元的数量却是相当有限)。 So my question is, whether it's ok to use the same texture which i use as a image2D for imageStore() also as a sampler2D to use with textureLod()? 所以我的问题是,是否可以将与image2D相同的纹理用作imageStore()以及与textureLod()一起使用的sampler2D?

Legal? 法律? Yes. 是。 Well-defined? 定义明确? It depends on what you're doing with them. 这取决于您对他们的处理方式。

You say that you want to write to images and then sample mipmaps from textures. 您说要写入图像,然后从纹理中采样mipmap。 Are you sampling from the same mipmap that you wrote from? 您是否从编写的相同Mipmap中采样? If so... that's going to be a problem. 如果是这样,那将是一个问题。 Texture accesses are not required to be coherant , so there's no guarantee that this will work. 纹理访问不需要是coherant ,因此不能保证这会起作用。 Not without an explicit CPU glMemoryBarrier call between the time it is written and the time it is sampled. 在写入时间和采样时间之间没有明确的CPU glMemoryBarrier调用。 And since it requires CPU intervention, it can't be done within the same shader. 而且由于它需要CPU干预,因此无法在同一着色器中完成。

If you provide protection to prevent sampling from mipmaps that you aren't writing to (and by "you", I mean "every shader invocation you're using"), then everything should be fine. 如果您提供保护以防止从您写入的mipmap中采样(“您”,我的意思是“您正在使用的每个着色器调用”),那么一切都应该很好。 Using textureLod or setting the BASE_LEVEL of the texture or something similar should be fine. 使用textureLod或设置纹理的BASE_LEVEL或类似的东西都可以。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM