diff --git a/src/gallium/drivers/v3d/v3d_program.c b/src/gallium/drivers/v3d/v3d_program.c index 45cc1c5bb6c..5436411e65e 100644 --- a/src/gallium/drivers/v3d/v3d_program.c +++ b/src/gallium/drivers/v3d/v3d_program.c @@ -602,12 +602,25 @@ v3d_setup_shared_precompile_key(struct v3d_uncompiled_shader *uncompiled, { nir_shader *s = uncompiled->base.ir.nir; + /* The shader may have gaps in the texture bindings, so figure out + * the largest binding in use and setup the number of textures and + * samplers from there instead of just the texture count from shader + * info. + */ + key->num_tex_used = 0; + key->num_samplers_used = 0; + for (int i = V3D_MAX_TEXTURE_SAMPLERS - 1; i >= 0; i--) { + if (s->info.textures_used[0] & (1 << i)) { + key->num_tex_used = i + 1; + key->num_samplers_used = i + 1; + break; + } + } + /* Note that below we access they key's texture and sampler fields * using the same index. On OpenGL they are the same (they are * combined) */ - key->num_tex_used = s->info.num_textures; - key->num_samplers_used = s->info.num_textures; for (int i = 0; i < s->info.num_textures; i++) { key->sampler[i].return_size = 16; key->sampler[i].return_channels = 2;