zink: set textures_used in analyze_io
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Thu, 12 Jan 2023 15:15:59 +0000 (10:15 -0500)
committerMarge Bot <emma+marge@anholt.net>
Wed, 18 Jan 2023 07:20:58 +0000 (07:20 +0000)
this is otherwise not usable

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20674>

src/gallium/drivers/zink/zink_compiler.c

index 30a8247..1fe6947 100644 (file)
@@ -3113,6 +3113,21 @@ analyze_io(struct zink_shader *zs, nir_shader *shader)
    nir_function_impl *impl = nir_shader_get_entrypoint(shader);
    nir_foreach_block(block, impl) {
       nir_foreach_instr(instr, block) {
+         if (shader->info.stage != MESA_SHADER_KERNEL && instr->type == nir_instr_type_tex) {
+            /* gl_nir_lower_samplers_as_deref is where this would normally be set, but zink doesn't use it */
+            nir_tex_instr *tex = nir_instr_as_tex(instr);
+            nir_foreach_variable_with_modes(img, shader, nir_var_uniform) {
+               if (glsl_type_is_sampler(glsl_without_array(img->type))) {
+                  unsigned size = glsl_type_is_array(img->type) ? glsl_get_aoa_size(img->type) : 1;
+                  if (tex->texture_index >= img->data.driver_location &&
+                     tex->texture_index < img->data.driver_location + size) {
+                     BITSET_SET_RANGE(shader->info.textures_used, img->data.driver_location, img->data.driver_location + (size - 1));
+                     break;
+                  }
+               }
+            }
+            continue;
+         }
          if (instr->type != nir_instr_type_intrinsic)
             continue;