i965/fs: Rework uniform handling
authorJason Ekstrand <jason.ekstrand@intel.com>
Tue, 18 Aug 2015 19:00:15 +0000 (12:00 -0700)
committerJason Ekstrand <jason.ekstrand@intel.com>
Tue, 25 Aug 2015 17:18:27 +0000 (10:18 -0700)
Previously, we treated the entire UNIFORM file as if it had two elements:
One for direct things and one for indirect.  This is substantially
different from how the old visitor code handled it where each element was
effectively its own uniform.  This commit makes the NIR path more like the
old ir_visitor path where each uniform is separate.  This should allow us
to more easily make decisions about what to push.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/mesa/drivers/dri/i965/brw_fs.h
src/mesa/drivers/dri/i965/brw_fs_nir.cpp
src/mesa/drivers/dri/i965/brw_nir.c

index 6d18929c3b1bada0e42e88ac1b1131a20eb07565..6bca762951ffb92e55bc0617cd80056c31a944ad 100644 (file)
@@ -318,9 +318,6 @@ public:
    /** Number of uniform variable components visited. */
    unsigned uniforms;
 
-   /** Total number of direct uniforms we can get from NIR */
-   unsigned num_direct_uniforms;
-
    /** Byte-offset for the next available spot in the scratch space buffer. */
    unsigned last_scratch;
 
index ad51d80fd096e931c997f04f28e56d6c4c0ab18f..a62dbb8b0ad27128e4c06d0131f535fb5ea2dbc3 100644 (file)
@@ -175,19 +175,9 @@ fs_visitor::nir_setup_outputs(nir_shader *shader)
 void
 fs_visitor::nir_setup_uniforms(nir_shader *shader)
 {
-   num_direct_uniforms = shader->num_direct_uniforms;
-
    if (dispatch_width != 8)
       return;
 
-   /* We split the uniform register file in half.  The first half is
-    * entirely direct uniforms.  The second half is indirect.
-    */
-   if (num_direct_uniforms > 0)
-      param_size[0] = num_direct_uniforms;
-   if (shader->num_uniforms > num_direct_uniforms)
-      param_size[num_direct_uniforms] = shader->num_uniforms - num_direct_uniforms;
-
    uniforms = shader->num_uniforms;
 
    if (shader_prog) {
@@ -200,15 +190,19 @@ fs_visitor::nir_setup_uniforms(nir_shader *shader)
             nir_setup_builtin_uniform(var);
          else
             nir_setup_uniform(var);
+
+         param_size[var->data.driver_location] = type_size_scalar(var->type);
       }
    } else {
-      /* prog_to_nir doesn't create uniform variables; set param up directly. */
+      /* prog_to_nir only creates a single giant uniform variable so we can
+       * just set param up directly. */
       for (unsigned p = 0; p < prog->Parameters->NumParameters; p++) {
          for (unsigned int i = 0; i < 4; i++) {
             stage_prog_data->param[4 * p + i] =
                &prog->Parameters->ParameterValues[p][i];
          }
       }
+      param_size[0] = prog->Parameters->NumParameters * 4;
    }
 }
 
@@ -1504,21 +1498,13 @@ fs_visitor::nir_emit_intrinsic(const fs_builder &bld, nir_intrinsic_instr *instr
       has_indirect = true;
       /* fallthrough */
    case nir_intrinsic_load_uniform: {
-      unsigned index = instr->const_index[0] + instr->const_index[1];
-
-      fs_reg uniform_reg;
-      if (index < num_direct_uniforms) {
-         uniform_reg = fs_reg(UNIFORM, 0);
-      } else {
-         uniform_reg = fs_reg(UNIFORM, num_direct_uniforms);
-         index -= num_direct_uniforms;
-      }
+      fs_reg uniform_reg(UNIFORM, instr->const_index[0]);
+      uniform_reg.reg_offset = instr->const_index[1];
 
       for (unsigned j = 0; j < instr->num_components; j++) {
-         fs_reg src = offset(retype(uniform_reg, dest.type), bld, index);
+         fs_reg src = offset(retype(uniform_reg, dest.type), bld, j);
          if (has_indirect)
             src.reladdr = new(mem_ctx) fs_reg(get_nir_src(instr->src[0]));
-         index++;
 
          bld.MOV(dest, src);
          dest = offset(dest, bld, 1);
index 3d04363ee1e22e8a8954410a279aa4caf3f8a4ff..dfac44fd406c55393bf52b512899870381a9e47f 100644 (file)
@@ -111,10 +111,9 @@ brw_create_nir(struct brw_context *brw,
    nir_optimize(nir, is_scalar);
 
    if (is_scalar) {
-      nir_assign_var_locations_direct_first(nir, &nir->uniforms,
-                                            &nir->num_direct_uniforms,
-                                            &nir->num_uniforms,
-                                            type_size_scalar);
+      nir_assign_var_locations(&nir->uniforms,
+                               &nir->num_uniforms,
+                               type_size_scalar);
       nir_assign_var_locations(&nir->inputs, &nir->num_inputs, type_size_scalar);
       nir_assign_var_locations(&nir->outputs, &nir->num_outputs, type_size_scalar);
       nir_lower_io(nir, type_size_scalar);