iris: Don't make duplicate system values
authorKenneth Graunke <kenneth@whitecape.org>
Thu, 27 Dec 2018 09:27:44 +0000 (01:27 -0800)
committerKenneth Graunke <kenneth@whitecape.org>
Thu, 21 Feb 2019 18:26:11 +0000 (10:26 -0800)
We were relying on CSE/GVN/etc to coalesce all intrinsics that load the
same value, but that's a bad idea.  We might have a couple intrinsics
that reload the same value.  If so, we only want to set up the uniform
on the first one we see.

src/gallium/drivers/iris/iris_context.h
src/gallium/drivers/iris/iris_program.c

index 7c5faee668fad36655fd3cb1dcbbf13b1e1b9429..ad7cfdb7b909e7920afa93a6eba173ae874bc836 100644 (file)
@@ -46,6 +46,7 @@ struct blorp_params;
 #define IRIS_MAX_ABOS 16
 #define IRIS_MAX_SSBOS 16
 #define IRIS_MAX_VIEWPORTS 16
+#define IRIS_MAX_CLIP_PLANES 8
 
 /**
  * Dirty flags.  When state changes, we flag some combination of these
index 95c56a11748c85dfcbaed6c3b9979924620fb3d0..b8929be9b72ba3b3b0d52ad3a06622b9dcd866f4 100644 (file)
@@ -601,6 +601,10 @@ iris_setup_uniforms(const struct brw_compiler *compiler,
       rzalloc_array(mem_ctx, enum brw_param_builtin, IRIS_MAX_SYSTEM_VALUES);
    unsigned num_system_values = 0;
 
+   unsigned patch_vert_idx = -1;
+   unsigned ucp_idx[IRIS_MAX_CLIP_PLANES];
+   memset(ucp_idx, -1, sizeof(ucp_idx));
+
    nir_function_impl *impl = nir_shader_get_entrypoint(nir);
 
    nir_builder b;
@@ -616,30 +620,41 @@ iris_setup_uniforms(const struct brw_compiler *compiler,
             continue;
 
          nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
-
-         unsigned idx = num_system_values;
+         nir_ssa_def *offset;
 
          switch (intrin->intrinsic) {
          case nir_intrinsic_load_user_clip_plane: {
             unsigned ucp = nir_intrinsic_ucp_id(intrin);
+
+            if (ucp_idx[ucp] == -1) {
+               ucp_idx[ucp] = num_system_values;
+               num_system_values += 4;
+            }
+
             for (int i = 0; i < 4; i++) {
-               system_values[num_system_values++] =
+               system_values[ucp_idx[ucp] + i] =
                   BRW_PARAM_BUILTIN_CLIP_PLANE(ucp, i);
             }
+
+            b.cursor = nir_before_instr(instr);
+            offset = nir_imm_int(&b, ucp_idx[ucp] * sizeof(uint32_t));
             break;
          }
          case nir_intrinsic_load_patch_vertices_in:
-            system_values[num_system_values++] =
+            if (patch_vert_idx == -1)
+               patch_vert_idx = num_system_values++;
+
+            system_values[patch_vert_idx] =
                BRW_PARAM_BUILTIN_PATCH_VERTICES_IN;
+
+            b.cursor = nir_before_instr(instr);
+            offset = nir_imm_int(&b, patch_vert_idx * sizeof(uint32_t));
             break;
          default:
             continue;
          }
 
-         b.cursor = nir_before_instr(instr);
-
          unsigned comps = nir_intrinsic_dest_components(intrin);
-         nir_ssa_def *offset = nir_imm_int(&b, idx * sizeof(uint32_t));
 
          nir_intrinsic_instr *load =
             nir_intrinsic_instr_create(nir, nir_intrinsic_load_ubo);