Same texture from multiple samplers?

What would be the impact of using one texture and setting the same texture unit to multiple sampler uniforms? The idea is to support either packed or planar YUV video with the same sampler, but no texture reads in conditionals.

So, in one version, a Y pixel would be read from texture 0, u from texture 1 etc., but in a packed version, texture 0 would have the y, u and v. I would then just calculate the different offsets to sample the pixels.

Would that break the shader or GPU in any way? I don’t really care if the texture is ‘copied’ into caches multiple times - the idea is just for the same shader to decode different pixel formats of video.

Bruce

What would be the impact of using one texture and setting the same texture unit to multiple sampler uniforms?

You can bind the same texture to two different texture units. And now with ARB_sampler_objects, you can even give the two different textures different texture parameters (well, mostly different texture parameters).

So, in one version, a Y pixel would be read from texture 0, u from texture 1 etc., but in a packed version, texture 0 would have the y, u and v. I would then just calculate the different offsets to sample the pixels.

Wouldn’t that require having different shaders, since you’re computing texture coordinates differently, getting different data from the textures, and so forth?

Thanks. But what can’t I do without ARB sampler objects?

I can calculate the texture fetch position from uniforms, then use conditionals to decide how to calculate, I believe.

The idea is that since I can’t put texture fetches inside conditionals, I’ll sample three textures using uniforms like bool uvSubSampled to calc position of the texture fetch, and other uniforms to decide what color matrix, transfer functions etc. to use.

Bruce

But what can’t I do without ARB sampler objects?

ARB_sampler_objects just gives you the ability to have different filtering settings on the different texture units you bind textures to. That probably doesn’t matter for you in this case.

The idea is that since I can’t put texture fetches inside conditionals

Of course you can. You just have to do it correctly.

If this is YUV data, there’s a good chance you’re not using mipmapping. So you can just use the textureLOD functions to directly access the top mipmap.

If you do need proper mipmapping, you have to compute the gradient using the two gradient functions and use textureGrad to access the texture.

Oh, sorry Alfonse, you threw me for a loop there. Yes, no mipmapping applies here, and I’m not sure why you mention textureLOD? Is there a trick that makes it applicable?

There was another recent thread where it was mentioned that you can’t alter what textures you sample based on conditionals, since it breaks caching. I’m also trying to use conditionals as little as possible - I only want them so I’m not changing shader programs around too much while running.

I had distilled things down to 2-3 shaders - planar and packed primarily, then was going to use:
uniforms and math to select sub-sampled or not,
uniforms and conditionals to select swizzling,
uniforms to set color matrix etc.

Then I realized that if my y, u and v samplers all pointed at the same texture, I could set those uniforms and do all the sampling from that one texture. In the planar case, I’d expect texture size to change, but internal format, mipmapping (none), lerp (none) etc. to be the same.

In the packed case, I make an effort to treat the data as BGRA to avoid CPU swizzling of the texture.

Sorry, I’m giving too much info here, but since I don’t understand some of your replies, I’m hoping you can be specific with this extra info.

Bruce

I’m not sure why you mention textureLOD? Is there a trick that makes it applicable?

textureLOD is a function that samples the texture at a specific mipmap level. The issue with conditional sampling is determining the gradients for mipmapping. By using textureLOD to sample from a specific mipmap (namely, mipmap 0), you don’t need to worry about it.

There was another recent thread where it was mentioned that you can’t alter what textures you sample based on conditionals, since it breaks caching.

Then they were wrong. You can conditional texture all you want. You just have to do it correctly, as I outlined.