freedreno/ir3: split ubo analysis/lowering passes
authorRob Clark <robdclark@chromium.org>
Wed, 17 Jun 2020 17:07:09 +0000 (10:07 -0700)
committerMarge Bot <eric+marge@anholt.net>
Sun, 21 Jun 2020 00:52:02 +0000 (00:52 +0000)
Since binning pass variants share the same const_state with their
draw-pass counterpart, we should re-use the draw-pass variant's ubo
range analysis.  So split the two functions of the existing pass
into two parts.

Signed-off-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5526>

src/freedreno/ir3/ir3_nir.c
src/freedreno/ir3/ir3_nir.h
src/freedreno/ir3/ir3_nir_analyze_ubo_ranges.c
src/freedreno/ir3/ir3_shader.h

index 93b8012e1d5830051fcc56b581b4ad0b633f57b6..b1f5fb9669c7ffc8fb1312c9272d728d9587c3f3 100644 (file)
@@ -344,7 +344,10 @@ ir3_nir_lower_variant(struct ir3_shader_variant *so, nir_shader *s)
                progress |= OPT(s, nir_lower_tex, &tex_options);
        }
 
-       progress |= OPT(s, ir3_nir_analyze_ubo_ranges, so);
+       if (!so->binning_pass)
+               OPT_V(s, ir3_nir_analyze_ubo_ranges, so);
+
+       progress |= OPT(s, ir3_nir_lower_ubo_loads, so);
 
        /* UBO offset lowering has to come after we've decided what will
         * be left as load_ubo
index 915f1638419bf8a43ebac69de0847fe71118909b..b84525bd69f267972beaae0c0326c714549c0664 100644 (file)
@@ -57,7 +57,8 @@ void ir3_nir_lower_variant(struct ir3_shader_variant *so, nir_shader *s);
 
 void ir3_setup_const_state(nir_shader *nir, struct ir3_shader_variant *v,
                struct ir3_const_state *const_state);
-bool ir3_nir_analyze_ubo_ranges(nir_shader *nir, struct ir3_shader_variant *v);
+void ir3_nir_analyze_ubo_ranges(nir_shader *nir, struct ir3_shader_variant *v);
+bool ir3_nir_lower_ubo_loads(nir_shader *nir, struct ir3_shader_variant *v);
 
 nir_ssa_def *
 ir3_nir_try_propagate_bit_shift(nir_builder *b, nir_ssa_def *offset, int32_t shift);
index 3feb60ed7114fb58ce70d894bc603e3a5fabc642..2cccee24dc874b984b848a34c08bcbe4b855ccfe 100644 (file)
@@ -229,9 +229,10 @@ track_ubo_use(nir_intrinsic_instr *instr, nir_builder *b, int *num_ubos)
        }
 }
 
-static void
+static bool
 lower_ubo_load_to_uniform(nir_intrinsic_instr *instr, nir_builder *b,
-               struct ir3_ubo_analysis_state *state, int *num_ubos, uint32_t alignment)
+               const struct ir3_ubo_analysis_state *state,
+               int *num_ubos, uint32_t alignment)
 {
        b->cursor = nir_before_instr(&instr->instr);
 
@@ -242,14 +243,14 @@ lower_ubo_load_to_uniform(nir_intrinsic_instr *instr, nir_builder *b,
        const struct ir3_ubo_range *range = get_existing_range(instr, state);
        if (!range) {
                track_ubo_use(instr, b, num_ubos);
-               return;
+               return false;
        }
 
        /* We don't have a good way of determining the range of the dynamic
         * access in general, so for now just fall back to pulling.
         */
        if (!nir_src_is_const(instr->src[1]) && !ubo_is_gl_uniforms(&range->ubo))
-               return;
+               return false;
 
        /* After gathering the UBO access ranges, we limit the total
         * upload. Don't lower if this load is outside the range.
@@ -258,7 +259,7 @@ lower_ubo_load_to_uniform(nir_intrinsic_instr *instr, nir_builder *b,
                        instr, alignment);
        if (!(range->start <= r.start && r.end <= range->end)) {
                track_ubo_use(instr, b, num_ubos);
-               return;
+               return false;
        }
 
        nir_ssa_def *ubo_offset = nir_ssa_for_src(b, instr->src[1], 1);
@@ -313,7 +314,7 @@ lower_ubo_load_to_uniform(nir_intrinsic_instr *instr, nir_builder *b,
 
        nir_instr_remove(&instr->instr);
 
-       state->lower_count++;
+       return true;
 }
 
 static bool
@@ -330,7 +331,7 @@ instr_is_load_ubo(nir_instr *instr)
        return op == nir_intrinsic_load_ubo;
 }
 
-bool
+void
 ir3_nir_analyze_ubo_ranges(nir_shader *nir, struct ir3_shader_variant *v)
 {
        struct ir3_const_state *const_state = ir3_const_state(v);
@@ -394,15 +395,30 @@ ir3_nir_analyze_ubo_ranges(nir_shader *nir, struct ir3_shader_variant *v)
 
        }
        state->size = offset;
+}
+
+bool
+ir3_nir_lower_ubo_loads(nir_shader *nir, struct ir3_shader_variant *v)
+{
+       struct ir3_compiler *compiler = v->shader->compiler;
+       /* For the binning pass variant, we re-use the corresponding draw-pass
+        * variants const_state and ubo state.  To make these clear, in this
+        * pass it is const (read-only)
+        */
+       const struct ir3_const_state *const_state = ir3_const_state(v);
+       const struct ir3_ubo_analysis_state *state = &const_state->ubo_state;
 
        int num_ubos = 0;
+       bool progress = false;
        nir_foreach_function (function, nir) {
                if (function->impl) {
                        nir_builder builder;
                        nir_builder_init(&builder, function->impl);
                        nir_foreach_block (block, function->impl) {
                                nir_foreach_instr_safe (instr, block) {
-                                       if (instr_is_load_ubo(instr))
+                                       if (!instr_is_load_ubo(instr))
+                                               continue;
+                                       progress |=
                                                lower_ubo_load_to_uniform(nir_instr_as_intrinsic(instr),
                                                                &builder, state, &num_ubos,
                                                                compiler->const_upload_unit);
@@ -420,5 +436,5 @@ ir3_nir_analyze_ubo_ranges(nir_shader *nir, struct ir3_shader_variant *v)
        if (nir->info.first_ubo_is_default_ubo)
            nir->info.num_ubos = num_ubos;
 
-       return state->lower_count > 0;
+       return progress;
 }
index e7e6f3812930df10eebfe728c5a42c3660b6c55c..5ccbd8cb65848ed986c41037ca3e18a56c23a850 100644 (file)
@@ -97,7 +97,6 @@ struct ir3_ubo_analysis_state {
        struct ir3_ubo_range range[IR3_MAX_UBO_PUSH_RANGES];
        uint32_t num_enabled;
        uint32_t size;
-       uint32_t lower_count;
        uint32_t cmdstream_size; /* for per-gen backend to stash required cmdstream size */
 };