nir: support feeding state to nir_lower_clip_[vg]s
authorErik Faye-Lund <erik.faye-lund@collabora.com>
Wed, 2 Oct 2019 20:30:45 +0000 (16:30 -0400)
committerErik Faye-Lund <erik.faye-lund@collabora.com>
Thu, 17 Oct 2019 08:41:36 +0000 (10:41 +0200)
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
src/broadcom/compiler/vir.c
src/compiler/nir/nir.h
src/compiler/nir/nir_lower_clip.c
src/freedreno/ir3/ir3_nir.c
src/gallium/drivers/iris/iris_program.c
src/gallium/drivers/vc4/vc4_program.c
src/mesa/drivers/dri/i965/brw_nir_uniforms.cpp

index afba863b0ec1496f22d5962244b53c532e18b8fa..8cbcc001d18b0550806785693d7791f61bc25484 100644 (file)
@@ -825,7 +825,7 @@ v3d_nir_lower_vs_late(struct v3d_compile *c)
 
         if (c->key->ucp_enables) {
                 NIR_PASS_V(c->s, nir_lower_clip_vs, c->key->ucp_enables,
-                           false, false);
+                           false, false, NULL);
                 NIR_PASS_V(c->s, nir_lower_io_to_scalar,
                            nir_var_shader_out);
         }
index a1f233917bdb074a999dbdc6209764fe847dfeb5..9b94c9edf2363e662a01ddbb82dc5355cd8d80d1 100644 (file)
@@ -3908,9 +3908,11 @@ bool nir_lower_input_attachments(nir_shader *shader, bool use_fragcoord_sysval);
 
 bool nir_lower_clip_vs(nir_shader *shader, unsigned ucp_enables,
                        bool use_vars,
-                       bool use_clipdist_array);
+                       bool use_clipdist_array,
+                       const gl_state_index16 clipplane_state_tokens[][STATE_LENGTH]);
 bool nir_lower_clip_gs(nir_shader *shader, unsigned ucp_enables,
-                       bool use_clipdist_array);
+                       bool use_clipdist_array,
+                       const gl_state_index16 clipplane_state_tokens[][STATE_LENGTH]);
 bool nir_lower_clip_fs(nir_shader *shader, unsigned ucp_enables,
                        bool use_clipdist_array);
 bool nir_lower_clip_cull_distance_arrays(nir_shader *nir);
index 0da36d79ba0daeda660aed862dbdf93a8d32c364..81c714971b2cf6e4a91c7d77a86228f06949e5f5 100644 (file)
@@ -203,11 +203,35 @@ find_clipvertex_and_position_outputs(nir_shader *shader,
    return *clipvertex || *position;
 }
 
+static nir_ssa_def *
+get_ucp(nir_builder *b, int plane,
+        const gl_state_index16 clipplane_state_tokens[][STATE_LENGTH])
+{
+   if (clipplane_state_tokens) {
+      char tmp[100];
+      snprintf(tmp, ARRAY_SIZE(tmp), "gl_ClipPlane%dMESA", plane);
+      nir_variable *var = nir_variable_create(b->shader,
+                                              nir_var_uniform,
+                                              glsl_vec4_type(),
+                                              tmp);
+
+      var->num_state_slots = 1;
+      var->state_slots = ralloc_array(var, nir_state_slot, 1);
+      memcpy(var->state_slots[0].tokens,
+             clipplane_state_tokens[plane],
+             sizeof(var->state_slots[0].tokens));
+      return nir_load_var(b, var);
+   } else
+      return nir_load_user_clip_plane(b, plane);
+}
+
+
 static void
 lower_clip_outputs(nir_builder *b, nir_variable *position,
                    nir_variable *clipvertex, nir_variable **out,
                    unsigned ucp_enables, bool use_vars,
-                   bool use_clipdist_array)
+                   bool use_clipdist_array,
+                   const gl_state_index16 clipplane_state_tokens[][STATE_LENGTH])
 {
    nir_ssa_def *clipdist[MAX_CLIP_PLANES];
    nir_ssa_def *cv;
@@ -231,7 +255,7 @@ lower_clip_outputs(nir_builder *b, nir_variable *position,
 
    for (int plane = 0; plane < MAX_CLIP_PLANES; plane++) {
       if (ucp_enables & (1 << plane)) {
-         nir_ssa_def *ucp = nir_load_user_clip_plane(b, plane);
+         nir_ssa_def *ucp = get_ucp(b, plane, clipplane_state_tokens);
 
          /* calculate clipdist[plane] - dot(ucp, cv): */
          clipdist[plane] = nir_fdot4(b, ucp, cv);
@@ -279,7 +303,8 @@ lower_clip_outputs(nir_builder *b, nir_variable *position,
  */
 bool
 nir_lower_clip_vs(nir_shader *shader, unsigned ucp_enables, bool use_vars,
-                  bool use_clipdist_array)
+                  bool use_clipdist_array,
+                  const gl_state_index16 clipplane_state_tokens[][STATE_LENGTH])
 {
    nir_function_impl *impl = nir_shader_get_entrypoint(shader);
    nir_builder b;
@@ -314,7 +339,7 @@ nir_lower_clip_vs(nir_shader *shader, unsigned ucp_enables, bool use_vars,
                         use_clipdist_array);
 
    lower_clip_outputs(&b, position, clipvertex, out, ucp_enables, use_vars,
-                      use_clipdist_array);
+                      use_clipdist_array, clipplane_state_tokens);
 
    nir_metadata_preserve(impl, nir_metadata_dominance);
 
@@ -324,7 +349,8 @@ nir_lower_clip_vs(nir_shader *shader, unsigned ucp_enables, bool use_vars,
 static void
 lower_clip_in_gs_block(nir_builder *b, nir_block *block, nir_variable *position,
                        nir_variable *clipvertex, nir_variable **out,
-                       unsigned ucp_enables, bool use_clipdist_array)
+                       unsigned ucp_enables, bool use_clipdist_array,
+                       const gl_state_index16 clipplane_state_tokens[][STATE_LENGTH])
 {
    nir_foreach_instr_safe(instr, block) {
       if (instr->type != nir_instr_type_intrinsic)
@@ -336,7 +362,7 @@ lower_clip_in_gs_block(nir_builder *b, nir_block *block, nir_variable *position,
       case nir_intrinsic_emit_vertex:
          b->cursor = nir_before_instr(instr);
          lower_clip_outputs(b, position, clipvertex, out, ucp_enables, true,
-                            use_clipdist_array);
+                            use_clipdist_array, clipplane_state_tokens);
          break;
       default:
          /* not interesting; skip this */
@@ -351,7 +377,8 @@ lower_clip_in_gs_block(nir_builder *b, nir_block *block, nir_variable *position,
 
 bool
 nir_lower_clip_gs(nir_shader *shader, unsigned ucp_enables,
-                  bool use_clipdist_array)
+                  bool use_clipdist_array,
+                  const gl_state_index16 clipplane_state_tokens[][STATE_LENGTH])
 {
    nir_function_impl *impl = nir_shader_get_entrypoint(shader);
    nir_builder b;
@@ -375,7 +402,8 @@ nir_lower_clip_gs(nir_shader *shader, unsigned ucp_enables,
 
    nir_foreach_block(block, impl)
       lower_clip_in_gs_block(&b, block, position, clipvertex, out,
-                             ucp_enables, use_clipdist_array);
+                             ucp_enables, use_clipdist_array,
+                             clipplane_state_tokens);
 
    nir_metadata_preserve(impl, nir_metadata_dominance);
 
index dbf25926ac5a7d73819ce58770d2ec427f63f2c3..2f95b249c263ff85e3d1cb9be1069d7ad9698c52 100644 (file)
@@ -223,7 +223,7 @@ ir3_optimize_nir(struct ir3_shader *shader, nir_shader *s,
 
        if (key) {
                if (s->info.stage == MESA_SHADER_VERTEX) {
-                       OPT_V(s, nir_lower_clip_vs, key->ucp_enables, false, false);
+                       OPT_V(s, nir_lower_clip_vs, key->ucp_enables, false, false, NULL);
                        if (key->vclamp_color)
                                OPT_V(s, nir_lower_clamp_color_outputs);
                } else if (s->info.stage == MESA_SHADER_FRAGMENT) {
index fc4f2d2949df709b228e917a302c6b0837933af9..6f2b320bb44c3f7da0156e626f072670a237a83f 100644 (file)
@@ -939,7 +939,7 @@ iris_compile_vs(struct iris_context *ice,
    if (key->nr_userclip_plane_consts) {
       nir_function_impl *impl = nir_shader_get_entrypoint(nir);
       nir_lower_clip_vs(nir, (1 << key->nr_userclip_plane_consts) - 1, true,
-                        false);
+                        false, NULL);
       nir_lower_io_to_temporaries(nir, impl, true, false);
       nir_lower_global_vars_to_local(nir);
       nir_lower_vars_to_ssa(nir);
@@ -1283,7 +1283,7 @@ iris_compile_tes(struct iris_context *ice,
    if (key->nr_userclip_plane_consts) {
       nir_function_impl *impl = nir_shader_get_entrypoint(nir);
       nir_lower_clip_vs(nir, (1 << key->nr_userclip_plane_consts) - 1, true,
-                        false);
+                        false, NULL);
       nir_lower_io_to_temporaries(nir, impl, true, false);
       nir_lower_global_vars_to_local(nir);
       nir_lower_vars_to_ssa(nir);
@@ -1403,7 +1403,8 @@ iris_compile_gs(struct iris_context *ice,
 
    if (key->nr_userclip_plane_consts) {
       nir_function_impl *impl = nir_shader_get_entrypoint(nir);
-      nir_lower_clip_gs(nir, (1 << key->nr_userclip_plane_consts) - 1, false);
+      nir_lower_clip_gs(nir, (1 << key->nr_userclip_plane_consts) - 1, false,
+                        NULL);
       nir_lower_io_to_temporaries(nir, impl, true, false);
       nir_lower_global_vars_to_local(nir);
       nir_lower_vars_to_ssa(nir);
index 4568100c10499d4e340d38a58ac99178ace7ff98..11133ce2bf8d0eada0e7c92389318c42fcaad48a 100644 (file)
@@ -2317,7 +2317,7 @@ vc4_shader_ntq(struct vc4_context *vc4, enum qstage stage,
                                    c->key->ucp_enables, false);
                 } else {
                         NIR_PASS_V(c->s, nir_lower_clip_vs,
-                                   c->key->ucp_enables, false, false);
+                                   c->key->ucp_enables, false, false, NULL);
                         NIR_PASS_V(c->s, nir_lower_io_to_scalar,
                                    nir_var_shader_out);
                 }
index 995b229e101829cc5a59a16308cc4fd7a14f509e..639bdfc0f2cbe1750dc78200367e2d51d87e3b77 100644 (file)
@@ -407,7 +407,8 @@ brw_nir_lower_legacy_clipping(nir_shader *nir, int nr_userclip_plane_consts,
 
    nir_function_impl *impl = nir_shader_get_entrypoint(nir);
 
-   nir_lower_clip_vs(nir, (1 << nr_userclip_plane_consts) - 1, true, false);
+   nir_lower_clip_vs(nir, (1 << nr_userclip_plane_consts) - 1, true, false,
+                     NULL);
    nir_lower_io_to_temporaries(nir, impl, true, false);
    nir_lower_global_vars_to_local(nir);
    nir_lower_vars_to_ssa(nir);