ac/llvm: fix mixing non-uniform/uniform sampler/texture descriptors
authorRhys Perry <pendingchaos02@gmail.com>
Wed, 19 Oct 2022 17:17:29 +0000 (18:17 +0100)
committerMarge Bot <emma+marge@anholt.net>
Fri, 21 Oct 2022 19:09:49 +0000 (19:09 +0000)
Non-uniform descriptors are not loaded in NIR and instead the pointer is
passed to abi->load_sampler_desc. It can be the case that only the texture
or sampler uses this path.

For the descriptor which doesn't use the path, we would previously pass
NULL to abi->load_sampler_desc.

Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Georg Lehmann <dadschoorse@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19198>

src/amd/llvm/ac_nir_to_llvm.c

index d8efa41..17cbeea 100644 (file)
@@ -4619,11 +4619,6 @@ static void tex_fetch_ptrs(struct ac_nir_context *ctx, nir_tex_instr *instr,
       }
    }
 
-   if (*res_ptr) {
-      /* descriptors given through nir_tex_src_{texture,sampler}_handle */
-      return;
-   }
-
    enum ac_descriptor_type main_descriptor =
       instr->sampler_dim == GLSL_SAMPLER_DIM_BUF ? AC_DESC_BUFFER : AC_DESC_IMAGE;
 
@@ -4642,7 +4637,7 @@ static void tex_fetch_ptrs(struct ac_nir_context *ctx, nir_tex_instr *instr,
       main_descriptor = AC_DESC_FMASK;
    }
 
-   if (texture_dynamic_handle) {
+   if (texture_dynamic_handle || sampler_dynamic_handle) {
       /* descriptor handles given through nir_tex_src_{texture,sampler}_handle */
       if (instr->texture_non_uniform)
          texture_dynamic_handle = enter_waterfall(ctx, &wctx[0], texture_dynamic_handle, divergent);
@@ -4650,15 +4645,21 @@ static void tex_fetch_ptrs(struct ac_nir_context *ctx, nir_tex_instr *instr,
       if (instr->sampler_non_uniform)
          sampler_dynamic_handle = enter_waterfall(ctx, &wctx[1], sampler_dynamic_handle, divergent);
 
-      *res_ptr = ctx->abi->load_sampler_desc(ctx->abi, 0, 0, 0, texture_dynamic_handle,
-                                             main_descriptor, false, false, true);
+      if (texture_dynamic_handle)
+         *res_ptr = ctx->abi->load_sampler_desc(ctx->abi, 0, 0, 0, texture_dynamic_handle,
+                                                main_descriptor, false, false, true);
 
-      if (samp_ptr)
+      if (samp_ptr && sampler_dynamic_handle)
          *samp_ptr = ctx->abi->load_sampler_desc(ctx->abi, 0, 0, 0, sampler_dynamic_handle,
                                                  AC_DESC_SAMPLER, false, false, true);
       return;
    }
 
+   if (*res_ptr) {
+      /* descriptors given through nir_tex_src_{texture,sampler}_handle */
+      return;
+   }
+
    LLVMValueRef texture_dynamic_index =
       get_sampler_desc_index(ctx, texture_deref_instr, &instr->instr, false);
    if (!sampler_deref_instr)