OpenGL - Accessing bindless textures inside glMultiDrawElementsIndirect without NV_gpu_shader5

Viewed 354

I am using glMultiDrawElementsIndirect with a combination of ARB_bindless_texture to draw things. I fetch texture handles with the built in vertex shader variable gl_DrawID. This variable is said to to be a dynamically uniform expression which means I dont have to depend on NV_gpu_shader5 when accessing bindless textures inside the shader. It looks something like this.

#version 460 core

out flat int MaterialIndex;

void main()
{
    ...
    MaterialIndex = gl_DrawID;
}
#version 460 core
#extension GL_ARB_bindless_texture : require

struct Material
{
    sampler2D Albedo;
    ivec2 pad0;
};

layout(std140, binding = 1) uniform BindlessUBO
{
    Material Materials[256];
} bindlessUBO;

in flat int MaterialIndex;

void main()
{
    Material material = bindlessUBO.Materials[MaterialIndex];
    vec3 albedo = texture(material.Albedo, coords).rgb;
}

This works on a NVIDIA RTX 3050 Ti, supporting NV_gpu_shader5. The model with all of its meshes and textures gets drawn correctly in one draw call. However on a AMD RX 5700XT, not supporting the extension, the driver crashes after a few seconds. Both GPUs can render the model without any textures. So now my guess would be that MaterialIndex is not a dynamically uniform expression even though it gets its value from one. Does passing MaterialIndex from a vertex to a fragment shader make it a non d.u.e? How could I obtain the index of the drawing command within glMultiDrawElementsIndirect in the fragment shader as a d.u.e? Is there a way to accomplish what I am trying to do without NV_gpu_shader5?

1 Answers

After upgrading from AMD driver 19.12.2 to 21.12.1 the bug disappeared. So passing gl_DrawID from vertex to fragment shader using the flat qualifier does in fact preserve it as a dynamically uniform expression and I dont need to depend on NV_gpu_shader5 :).

Related