nir: add nir_intrinsic_interp_deref_at_vertex
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Fri, 24 Jan 2020 15:01:04 +0000 (16:01 +0100)
committerMarge Bot <eric+marge@anholt.net>
Wed, 29 Jan 2020 09:49:50 +0000 (09:49 +0000)
From the SPV_AMD_shader_explicit_vertex_parameter extension:
   "Returns the value of the input <interpolant> without any
    interpolation, i.e. the raw output value of previous shader
    stage."

Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3578>

12 files changed:
src/compiler/nir/nir_divergence_analysis.c
src/compiler/nir/nir_gather_info.c
src/compiler/nir/nir_intrinsics.py
src/compiler/nir/nir_linking_helpers.c
src/compiler/nir/nir_lower_array_deref_of_vec.c
src/compiler/nir/nir_lower_indirect_derefs.c
src/compiler/nir/nir_lower_io.c
src/compiler/nir/nir_lower_io_arrays_to_elements.c
src/compiler/nir/nir_lower_io_to_scalar.c
src/compiler/nir/nir_lower_io_to_temporaries.c
src/compiler/nir/nir_lower_io_to_vector.c
src/compiler/nir/nir_lower_phis_to_scalar.c

index 397015263e1f348bd54c04f3eb7c429aded4c737..f0c8bfad7b2632bbd9d67233a17a007b737ac648 100644 (file)
@@ -269,6 +269,7 @@ visit_intrinsic(bool *divergent, nir_intrinsic_instr *instr,
    case nir_intrinsic_interp_deref_at_offset:
    case nir_intrinsic_interp_deref_at_sample:
    case nir_intrinsic_interp_deref_at_centroid:
+   case nir_intrinsic_interp_deref_at_vertex:
    case nir_intrinsic_load_tess_coord:
    case nir_intrinsic_load_point_coord:
    case nir_intrinsic_load_frag_coord:
index 9267db95b7735054567030ebbe3a04e1793ac119..0a89c4b9b4463dd22603386ffb5e185e2ab1415a 100644 (file)
@@ -209,6 +209,7 @@ gather_intrinsic_info(nir_intrinsic_instr *instr, nir_shader *shader,
    case nir_intrinsic_interp_deref_at_centroid:
    case nir_intrinsic_interp_deref_at_sample:
    case nir_intrinsic_interp_deref_at_offset:
+   case nir_intrinsic_interp_deref_at_vertex:
    case nir_intrinsic_load_deref:
    case nir_intrinsic_store_deref:{
       nir_deref_instr *deref = nir_src_as_deref(instr->src[0]);
index 9269ac99a2d7ba0d3e97e3853aafbf8f0e76762d..6ebc76eb88bac283686633388b5ed3f86ef16f93 100644 (file)
@@ -170,9 +170,9 @@ intrinsic("copy_deref", src_comp=[-1, -1], indices=[DST_ACCESS, SRC_ACCESS])
 
 # Interpolation of input.  The interp_deref_at* intrinsics are similar to the
 # load_var intrinsic acting on a shader input except that they interpolate the
-# input differently.  The at_sample and at_offset intrinsics take an
-# additional source that is an integer sample id or a vec2 position offset
-# respectively.
+# input differently.  The at_sample, at_offset and at_vertex intrinsics take an
+# additional source that is an integer sample id, a vec2 position offset, or a
+# vertex ID respectively.
 
 intrinsic("interp_deref_at_centroid", dest_comp=0, src_comp=[1],
           flags=[ CAN_ELIMINATE, CAN_REORDER])
@@ -180,6 +180,8 @@ intrinsic("interp_deref_at_sample", src_comp=[1, 1], dest_comp=0,
           flags=[CAN_ELIMINATE, CAN_REORDER])
 intrinsic("interp_deref_at_offset", src_comp=[1, 2], dest_comp=0,
           flags=[CAN_ELIMINATE, CAN_REORDER])
+intrinsic("interp_deref_at_vertex", src_comp=[1, 1], dest_comp=0,
+          flags=[CAN_ELIMINATE, CAN_REORDER])
 
 # Gets the length of an unsized array at the end of a buffer
 intrinsic("deref_buffer_array_length", src_comp=[-1], dest_comp=1,
index e1cf58f35147af685e8a9097f3cd679e81abf68a..6e49c8737c5f3c30347860b0dd61b92da92121c1 100644 (file)
@@ -523,7 +523,8 @@ gather_varying_component_info(nir_shader *consumer,
          if (intr->intrinsic != nir_intrinsic_load_deref &&
              intr->intrinsic != nir_intrinsic_interp_deref_at_centroid &&
              intr->intrinsic != nir_intrinsic_interp_deref_at_sample &&
-             intr->intrinsic != nir_intrinsic_interp_deref_at_offset)
+             intr->intrinsic != nir_intrinsic_interp_deref_at_offset &&
+             intr->intrinsic != nir_intrinsic_interp_deref_at_vertex)
             continue;
 
          nir_deref_instr *deref = nir_src_as_deref(intr->src[0]);
index 2a70dd1ddbc853f3d1aef8b25dd550f9806f3500..0766a1beb715101ba0848a9d4356c8dff63b83ca 100644 (file)
@@ -80,6 +80,7 @@ nir_lower_array_deref_of_vec_impl(nir_function_impl *impl,
              intrin->intrinsic != nir_intrinsic_interp_deref_at_centroid &&
              intrin->intrinsic != nir_intrinsic_interp_deref_at_sample &&
              intrin->intrinsic != nir_intrinsic_interp_deref_at_offset &&
+             intrin->intrinsic != nir_intrinsic_interp_deref_at_vertex &&
              intrin->intrinsic != nir_intrinsic_store_deref)
             continue;
 
index 58365628885ffb0a63ba27a37d3254e8d0e52c6d..9e8a844b534120b8c1b166fc115ab10c84bb8cab 100644 (file)
@@ -126,6 +126,7 @@ lower_indirect_derefs_block(nir_block *block, nir_builder *b,
           intrin->intrinsic != nir_intrinsic_interp_deref_at_centroid &&
           intrin->intrinsic != nir_intrinsic_interp_deref_at_sample &&
           intrin->intrinsic != nir_intrinsic_interp_deref_at_offset &&
+          intrin->intrinsic != nir_intrinsic_interp_deref_at_vertex &&
           intrin->intrinsic != nir_intrinsic_store_deref)
          continue;
 
index 1483ef208c3a6143318975e3b437aacd9d194f9e..f10022936d0b65d7fd2fc6d007c955d6c68115f3 100644 (file)
@@ -520,7 +520,8 @@ lower_interpolate_at(nir_intrinsic_instr *intrin, struct lower_io_state *state,
    nir_intrinsic_set_interp_mode(bary_setup, var->data.interpolation);
 
    if (intrin->intrinsic == nir_intrinsic_interp_deref_at_sample ||
-       intrin->intrinsic == nir_intrinsic_interp_deref_at_offset)
+       intrin->intrinsic == nir_intrinsic_interp_deref_at_offset ||
+       intrin->intrinsic == nir_intrinsic_interp_deref_at_vertex)
       nir_src_copy(&bary_setup->src[0], &intrin->src[1], bary_setup);
 
    nir_builder_instr_insert(b, &bary_setup->instr);
@@ -581,6 +582,7 @@ nir_lower_io_block(nir_block *block,
       case nir_intrinsic_interp_deref_at_centroid:
       case nir_intrinsic_interp_deref_at_sample:
       case nir_intrinsic_interp_deref_at_offset:
+      case nir_intrinsic_interp_deref_at_vertex:
          /* We can optionally lower these to load_interpolated_input */
          if (options->use_interpolated_input_intrinsics)
             break;
@@ -653,6 +655,7 @@ nir_lower_io_block(nir_block *block,
       case nir_intrinsic_interp_deref_at_centroid:
       case nir_intrinsic_interp_deref_at_sample:
       case nir_intrinsic_interp_deref_at_offset:
+      case nir_intrinsic_interp_deref_at_vertex:
          assert(vertex_index == NULL);
          replacement = lower_interpolate_at(intrin, state, var, offset,
                                             component_offset, deref->type);
index 428860fef4589e7a31846cf7f2b753e098c280b1..c4c7c5cc9c7cbf432acf85f364b209a2a7040455 100644 (file)
@@ -167,7 +167,8 @@ lower_array(nir_builder *b, nir_intrinsic_instr *intr, nir_variable *var,
                         intr->num_components, intr->dest.ssa.bit_size, NULL);
 
       if (intr->intrinsic == nir_intrinsic_interp_deref_at_offset ||
-          intr->intrinsic == nir_intrinsic_interp_deref_at_sample) {
+          intr->intrinsic == nir_intrinsic_interp_deref_at_sample ||
+          intr->intrinsic == nir_intrinsic_interp_deref_at_vertex) {
          nir_src_copy(&element_intr->src[1], &intr->src[1],
                       &element_intr->instr);
       }
@@ -232,7 +233,8 @@ create_indirects_mask(nir_shader *shader,
                    intr->intrinsic != nir_intrinsic_store_deref &&
                    intr->intrinsic != nir_intrinsic_interp_deref_at_centroid &&
                    intr->intrinsic != nir_intrinsic_interp_deref_at_sample &&
-                   intr->intrinsic != nir_intrinsic_interp_deref_at_offset)
+                   intr->intrinsic != nir_intrinsic_interp_deref_at_offset &&
+                   intr->intrinsic != nir_intrinsic_interp_deref_at_vertex)
                   continue;
 
                nir_deref_instr *deref = nir_src_as_deref(intr->src[0]);
@@ -277,7 +279,8 @@ lower_io_arrays_to_elements(nir_shader *shader, nir_variable_mode mask,
                    intr->intrinsic != nir_intrinsic_store_deref &&
                    intr->intrinsic != nir_intrinsic_interp_deref_at_centroid &&
                    intr->intrinsic != nir_intrinsic_interp_deref_at_sample &&
-                   intr->intrinsic != nir_intrinsic_interp_deref_at_offset)
+                   intr->intrinsic != nir_intrinsic_interp_deref_at_offset &&
+                   intr->intrinsic != nir_intrinsic_interp_deref_at_vertex)
                   continue;
 
                nir_deref_instr *deref = nir_src_as_deref(intr->src[0]);
@@ -327,6 +330,7 @@ lower_io_arrays_to_elements(nir_shader *shader, nir_variable_mode mask,
                case nir_intrinsic_interp_deref_at_centroid:
                case nir_intrinsic_interp_deref_at_sample:
                case nir_intrinsic_interp_deref_at_offset:
+               case nir_intrinsic_interp_deref_at_vertex:
                case nir_intrinsic_load_deref:
                case nir_intrinsic_store_deref:
                   if ((mask & nir_var_shader_in && mode == nir_var_shader_in) ||
index 1277a8a7373403ae7b885670ea0205a79f2c3bd9..adbcf0ef9756b1e9db85afef64753a3bd5e600a5 100644 (file)
@@ -217,7 +217,8 @@ lower_load_to_scalar_early(nir_builder *b, nir_intrinsic_instr *intr,
       chan_intr->src[0] = nir_src_for_ssa(&deref->dest.ssa);
 
       if (intr->intrinsic == nir_intrinsic_interp_deref_at_offset ||
-          intr->intrinsic == nir_intrinsic_interp_deref_at_sample)
+          intr->intrinsic == nir_intrinsic_interp_deref_at_sample ||
+          intr->intrinsic == nir_intrinsic_interp_deref_at_vertex)
          nir_src_copy(&chan_intr->src[1], &intr->src[1], &chan_intr->instr);
 
       nir_builder_instr_insert(b, &chan_intr->instr);
@@ -311,7 +312,8 @@ nir_lower_io_to_scalar_early(nir_shader *shader, nir_variable_mode mask)
                    intr->intrinsic != nir_intrinsic_store_deref &&
                    intr->intrinsic != nir_intrinsic_interp_deref_at_centroid &&
                    intr->intrinsic != nir_intrinsic_interp_deref_at_sample &&
-                   intr->intrinsic != nir_intrinsic_interp_deref_at_offset)
+                   intr->intrinsic != nir_intrinsic_interp_deref_at_offset &&
+                   intr->intrinsic != nir_intrinsic_interp_deref_at_vertex)
                   continue;
 
                nir_deref_instr *deref = nir_src_as_deref(intr->src[0]);
@@ -350,6 +352,7 @@ nir_lower_io_to_scalar_early(nir_shader *shader, nir_variable_mode mask)
                case nir_intrinsic_interp_deref_at_centroid:
                case nir_intrinsic_interp_deref_at_sample:
                case nir_intrinsic_interp_deref_at_offset:
+               case nir_intrinsic_interp_deref_at_vertex:
                case nir_intrinsic_load_deref:
                   if ((mask & nir_var_shader_in && mode == nir_var_shader_in) ||
                       (mask & nir_var_shader_out && mode == nir_var_shader_out))
index f92489b9d51cc2eaf502dde8fd12687a421de9ef..1ede0238e4f63122553a6e6b22028661a0dbe179 100644 (file)
@@ -199,7 +199,8 @@ emit_interp(nir_builder *b, nir_deref_instr **old_interp_deref,
 
    new_interp->src[0] = nir_src_for_ssa(&new_interp_deref->dest.ssa);
    if (interp->intrinsic == nir_intrinsic_interp_deref_at_sample ||
-       interp->intrinsic == nir_intrinsic_interp_deref_at_offset) {
+       interp->intrinsic == nir_intrinsic_interp_deref_at_offset ||
+       interp->intrinsic == nir_intrinsic_interp_deref_at_vertex) {
       new_interp->src[1] = interp->src[1];
    }
 
@@ -262,7 +263,8 @@ fixup_interpolation(struct lower_io_state *state, nir_function_impl *impl,
          
          if (interp->intrinsic == nir_intrinsic_interp_deref_at_centroid ||
              interp->intrinsic == nir_intrinsic_interp_deref_at_sample ||
-             interp->intrinsic == nir_intrinsic_interp_deref_at_offset) {
+             interp->intrinsic == nir_intrinsic_interp_deref_at_offset ||
+             interp->intrinsic == nir_intrinsic_interp_deref_at_vertex) {
             fixup_interpolation_instr(state, interp, b);
          }
       }
index 82c4bdf87496ae9ba6c25d0cda314dd8aedb6899..05412e2375de01fdff6d5d708463d7b5e7843a77 100644 (file)
@@ -411,7 +411,8 @@ nir_lower_io_to_vector_impl(nir_function_impl *impl, nir_variable_mode modes)
          case nir_intrinsic_load_deref:
          case nir_intrinsic_interp_deref_at_centroid:
          case nir_intrinsic_interp_deref_at_sample:
-         case nir_intrinsic_interp_deref_at_offset: {
+         case nir_intrinsic_interp_deref_at_offset:
+         case nir_intrinsic_interp_deref_at_vertex: {
             nir_deref_instr *old_deref = nir_src_as_deref(intrin->src[0]);
             if (!(old_deref->mode & modes))
                break;
index bea9dc407534b5d4ff1783a07232c521c77a3070..45894dee352f4c28e0176cd4dc2735d8707a83c8 100644 (file)
@@ -100,6 +100,7 @@ is_phi_src_scalarizable(nir_phi_src *src,
       case nir_intrinsic_interp_deref_at_centroid:
       case nir_intrinsic_interp_deref_at_sample:
       case nir_intrinsic_interp_deref_at_offset:
+      case nir_intrinsic_interp_deref_at_vertex:
       case nir_intrinsic_load_uniform:
       case nir_intrinsic_load_ubo:
       case nir_intrinsic_load_ssbo: