Inconsistent behavior with array samplers between GeForce and GTX TITAN

We are using a wide range of different Nvidia video cards, including GTX 980, 1080, and GTX TITAN 6 GB. I just found out that some of our shaders break on the GTX TITAN.

The shaders that break use array samplers or images (sampler2DArray, image2DArray, …), but the textures we bind to these uniforms are not always array textures, but plain GL_TEXTURE_2D. This works perfectly fine on all other cards, i.e. as long as you don’t access another (non-existent) layer of the texture, you can read from and write to it. On the GTX TITAN, sampling from layer 0 will always return vec4(0), writing to layer 0 with imageStore has no influence on the texture’s contents. It is simply as if no texture was bound.

I am not sure whether the whole “binding a 2D texture to an 2D texture array sampler” trick is actually supposed to work reliably or if it’s undefined behavior and we were at the mercy of the video drivers all this time. But now that we encountered the crashes on the GTX TITAN, I wonder why it does not work or fail reliably on all cards. We have tested this with the current and the previous drivers.

So, this is not really a bug report I guess, but a comment on inconsistent behavior. Failing/crashing on undefined behavior is not bad, at least then you know that you made a mistake. It’s succeeding in most of the cases and crashing on exotic setups that really freaks out the programmer.

This is definitely not supported by the GL spec (or any spec), and I guess just happens to work because Nvidia Hardware seems to alias texture types… but there are no guarantees that it will stay that way for future architectures or that it will work with other vendors.