[Mesa-dev] [PATCH 2/3] nir/builder: Add a load_system_value helper

Jason Ekstrand jason at jlekstrand.net
Mon Dec 14 19:51:50 PST 2015


While we're at it, go ahead and make nir_lower_clip use it.

Cc: Rob Clark <robclark at gmail.com>
---
 src/glsl/nir/nir_builder.h    | 12 ++++++++++++
 src/glsl/nir/nir_lower_clip.c | 13 +++----------
 2 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/src/glsl/nir/nir_builder.h b/src/glsl/nir/nir_builder.h
index b909f483..332bb02 100644
--- a/src/glsl/nir/nir_builder.h
+++ b/src/glsl/nir/nir_builder.h
@@ -322,4 +322,16 @@ nir_store_var(nir_builder *build, nir_variable *var, nir_ssa_def *value)
    nir_builder_instr_insert(build, &store->instr);
 }
 
+static inline nir_ssa_def *
+nir_load_system_value(nir_builder *build, nir_intrinsic_op op, int index)
+{
+   nir_intrinsic_instr *load = nir_intrinsic_instr_create(build->shader, op);
+   load->num_components = nir_intrinsic_infos[op].dest_components;
+   load->const_index[0] = index;
+   nir_ssa_dest_init(&load->instr, &load->dest,
+                     nir_intrinsic_infos[op].dest_components, NULL);
+   nir_builder_instr_insert(build, &load->instr);
+   return &load->dest.ssa;
+}
+
 #endif /* NIR_BUILDER_H */
diff --git a/src/glsl/nir/nir_lower_clip.c b/src/glsl/nir/nir_lower_clip.c
index 36cc578..4630135 100644
--- a/src/glsl/nir/nir_lower_clip.c
+++ b/src/glsl/nir/nir_lower_clip.c
@@ -180,18 +180,11 @@ lower_clip_vs(nir_function_impl *impl, unsigned ucp_enables,
 
    for (int plane = 0; plane < MAX_CLIP_PLANES; plane++) {
       if (ucp_enables & (1 << plane)) {
-         nir_intrinsic_instr *ucp;
-
-         /* insert intrinsic to fetch ucp[plane]: */
-         ucp = nir_intrinsic_instr_create(b.shader,
-                                          nir_intrinsic_load_user_clip_plane);
-         ucp->num_components = 4;
-         ucp->const_index[0] = plane;
-         nir_ssa_dest_init(&ucp->instr, &ucp->dest, 4, NULL);
-         nir_builder_instr_insert(&b, &ucp->instr);
+         nir_ssa_def *ucp =
+            nir_load_system_value(&b, nir_intrinsic_load_user_clip_plane, plane);
 
          /* calculate clipdist[plane] - dot(ucp, cv): */
-         clipdist[plane] = nir_fdot4(&b, &ucp->dest.ssa, cv);
+         clipdist[plane] = nir_fdot4(&b, ucp, cv);
       }
       else {
          /* 0.0 == don't-clip == disabled: */
-- 
2.5.0.400.gff86faf



More information about the mesa-dev mailing list