nir/opt_preamble: Treat *size as an input
authorAlyssa Rosenzweig <alyssa@collabora.com>
Thu, 29 Dec 2022 02:56:00 +0000 (21:56 -0500)
committerMarge Bot <emma+marge@anholt.net>
Tue, 31 Jan 2023 17:02:34 +0000 (17:02 +0000)
Some backends may wish to reserve early uniforms for internal system values, and
use the remaining space for preamble storage. In this case, it's convenient to
teach nir_opt_preamble about a reserved offset. It's logical to treat the output
*size instead of an in/out variable that nir_opt_preamble adds to. This requires
a slight change to the consumers to zero the input.

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Acked-by-(with-sparkles): Asahi Lina <lina@asahilina.net>

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20562>

src/compiler/nir/nir_opt_preamble.c
src/freedreno/ir3/ir3_nir_opt_preamble.c

index ee3ffac..e5e2696 100644 (file)
@@ -421,7 +421,6 @@ nir_opt_preamble(nir_shader *shader, const nir_opt_preamble_options *options,
    }
 
    if (num_candidates == 0) {
-      *size = 0;
       free(ctx.states);
       return false;
    }
@@ -485,7 +484,6 @@ nir_opt_preamble(nir_shader *shader, const nir_opt_preamble_options *options,
    num_candidates = candidate_idx;
 
    if (num_candidates == 0) {
-      *size = 0;
       free(ctx.states);
       free(candidates);
       return false;
@@ -498,11 +496,11 @@ nir_opt_preamble(nir_shader *shader, const nir_opt_preamble_options *options,
     * divided by size.
     */
 
-   if (total_size > options->preamble_storage_size) {
-      qsort(candidates, num_candidates, sizeof(*candidates), candidate_sort);
+   if (((*size) + total_size) > options->preamble_storage_size) {
+     qsort(candidates, num_candidates, sizeof(*candidates), candidate_sort);
    }
 
-   unsigned offset = 0;
+   unsigned offset = *size;
    for (unsigned i = 0; i < num_candidates; i++) {
       def_state *state = candidates[i];
       offset = ALIGN_POT(offset, state->align);
index 43f757f..2dfacd1 100644 (file)
@@ -284,7 +284,7 @@ ir3_nir_opt_preamble(nir_shader *nir, struct ir3_shader_variant *v)
       .rewrite_cost_cb = rewrite_cost,
    };
 
-   unsigned size;
+   unsigned size = 0;
    bool progress = nir_opt_preamble(nir, &options, &size);
 
    if (!v->binning_pass)