Accessing textures with non-uniform control flow in glsl execution of mdl materials

I’m working on getting the mdl GLSL execution example to work on OSX, but my intel graphics chip doesn’t support bindless textures.

I can code around this I think, but it occurs to me that there’s no way to enforce uniform control flow accessing of textures. My understanding is that that would invalidate implicit derivatives in those textures which could lead to undefined behavior (and possibly crashing).

Am I misunderstanding? How is this to be handled?

Thanks for reporting this, there is actually a bug in Material_opengl_context::set_material_data() for Mac OS X.
Please wrap the lines 613 (“if (glfwExtensionSupported(“GL_ARB_bindless_texture”))”) to 660 in a “#ifdef USE_SSBO”/“#endif”. Then it will use bound textures on Mac.
We will fix that for the next release.

As for the implicit derivatives, the GLSL backend does not move code around. So you can use the same techniques as described in [url]Sampler (GLSL) - OpenGL Wiki to avoid texture lookups being control-flow dependent on non-uniform expressions by always making the texture lookup and only making the use of the result dependent on the non-uniform expressions.

Ya… we can get the GLSL implementation of the texture function to be dynamically uniform. But… we can’t control how the mdl material calls those functions. It seems to me that supporting arbitrary mdl shaders with arbitrary control flow means that we don’t have any control over how the texturing calls are made, and they might be called in a non-uniformly. Isn’t that an issue?

Indeed. Currently, the OpenGL back-end does not support derivatives. You would need to use texture lookup functions that are not dependent on (dynamic) uniform control flow to be on the safe side in general, sorry.

We are currently working on general derivative support in the MDL SDK and we will revisit the GLSL back-end in the course of this feature work.