nir: Allow a non-existent sampler deref in nir_lower_samplers_as_deref
authorKenneth Graunke <kenneth@whitecape.org>
Thu, 10 Jan 2019 19:10:13 +0000 (11:10 -0800)
committerKenneth Graunke <kenneth@whitecape.org>
Fri, 11 Jan 2019 15:54:32 +0000 (07:54 -0800)
GL_ARB_gl_spirv does not provide a sampler deref for e.g. texelFetch(),
so we can't assume that both are present and identical.  Simply lower
each if it is present.

Fixes regressions in GL_ARB_gl_spirv tests since I switched everyone to
using this pass.  Thanks to Alejandro Piñeiro for catching these.

Fixes: f003859f97c nir: Make gl_nir_lower_samplers use gl_nir_lower_samplers_as_deref
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Tested-by: Alejandro Piñeiro <apinheiro@igalia.com>
src/compiler/glsl/gl_nir_lower_samplers_as_deref.c

index 96c751a1284e1a9a26d92d1b4ab1e45d59a689be..719968a667130859e7d789dcb6854c7914640ef1 100644 (file)
@@ -196,28 +196,30 @@ lower_sampler(nir_tex_instr *instr, struct lower_samplers_as_deref_state *state,
    int sampler_idx =
       nir_tex_instr_src_index(instr, nir_tex_src_sampler_deref);
 
-   if (texture_idx < 0)
-      return false;
+   b->cursor = nir_before_instr(&instr->instr);
 
-   assert(texture_idx >= 0 && sampler_idx >= 0);
-   assert(instr->src[texture_idx].src.is_ssa);
-   assert(instr->src[sampler_idx].src.is_ssa);
-   assert(instr->src[texture_idx].src.ssa == instr->src[sampler_idx].src.ssa);
+   if (texture_idx >= 0) {
+      assert(instr->src[texture_idx].src.is_ssa);
 
-   b->cursor = nir_before_instr(&instr->instr);
+      nir_deref_instr *texture_deref =
+         lower_deref(b, state, nir_src_as_deref(instr->src[texture_idx].src));
+      /* only lower non-bindless: */
+      if (texture_deref) {
+         nir_instr_rewrite_src(&instr->instr, &instr->src[texture_idx].src,
+                               nir_src_for_ssa(&texture_deref->dest.ssa));
+      }
+   }
 
-   nir_deref_instr *texture_deref =
-      lower_deref(b, state, nir_src_as_deref(instr->src[texture_idx].src));
-   /* don't lower bindless: */
-   if (!texture_deref)
-      return false;
-   nir_instr_rewrite_src(&instr->instr, &instr->src[texture_idx].src,
-                         nir_src_for_ssa(&texture_deref->dest.ssa));
-
-   nir_deref_instr *sampler_deref =
-      lower_deref(b, state, nir_src_as_deref(instr->src[sampler_idx].src));
-   nir_instr_rewrite_src(&instr->instr, &instr->src[sampler_idx].src,
-                         nir_src_for_ssa(&sampler_deref->dest.ssa));
+   if (sampler_idx >= 0) {
+      assert(instr->src[sampler_idx].src.is_ssa);
+      nir_deref_instr *sampler_deref =
+         lower_deref(b, state, nir_src_as_deref(instr->src[sampler_idx].src));
+      /* only lower non-bindless: */
+      if (sampler_deref) {
+         nir_instr_rewrite_src(&instr->instr, &instr->src[sampler_idx].src,
+                               nir_src_for_ssa(&sampler_deref->dest.ssa));
+      }
+   }
 
    return true;
 }