Mesa (main): radeonsi: deserialize nir binary in si_check_blend_dst_sampler_noop
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Mon Jun 27 03:16:28 UTC 2022
Module: Mesa
Branch: main
Commit: 05b829cd0c2ac644e8b68941a3194030ab13e917
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=05b829cd0c2ac644e8b68941a3194030ab13e917
Author: Qiang Yu <yuq825 at gmail.com>
Date: Fri May 27 17:24:41 2022 +0800
radeonsi: deserialize nir binary in si_check_blend_dst_sampler_noop
We can do this parse with original nir instead of shader key pass
applied nir in si_get_nir_shader.
This can free si_get_nir_shader to just use si_shader as parameter.
Reviewed-by: Marek Olšák <marek.olsak at amd.com>
Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer at amd.com>
Signed-off-by: Qiang Yu <yuq825 at gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16705>
---
src/gallium/drivers/radeonsi/si_nir_optim.c | 25 ++++++++++---------------
src/gallium/drivers/radeonsi/si_shader.c | 19 ++++++++++++-------
src/gallium/drivers/radeonsi/si_shader.h | 1 +
src/gallium/drivers/radeonsi/si_state.c | 17 ++++++-----------
4 files changed, 29 insertions(+), 33 deletions(-)
diff --git a/src/gallium/drivers/radeonsi/si_nir_optim.c b/src/gallium/drivers/radeonsi/si_nir_optim.c
index 0374c870c5a..993bb04fb20 100644
--- a/src/gallium/drivers/radeonsi/si_nir_optim.c
+++ b/src/gallium/drivers/radeonsi/si_nir_optim.c
@@ -175,19 +175,16 @@ si_nir_is_output_const_if_tex_is_const(nir_shader *shader, float *in, float *out
util_bitcount64(shader->info.outputs_written) != 1)
return false;
- /* Clone the shader */
- nir_shader *sh = nir_shader_clone(ralloc_parent(shader), shader);
-
struct replace_param p;
memcpy(p.value, in, 4 * sizeof(float));
p.texunit = texunit;
/* Test if the single store_output only depends on constants and a single texture op */
- if (nir_shader_instructions_pass(sh, store_instr_depends_on_tex, nir_metadata_all, &p)) {
+ if (nir_shader_instructions_pass(shader, store_instr_depends_on_tex, nir_metadata_all, &p)) {
assert(*p.texunit != -1);
/* Replace nir_tex_instr using texunit by vec4(v) */
- nir_shader_instructions_pass(sh, replace_tex_by_imm,
+ nir_shader_instructions_pass(shader, replace_tex_by_imm,
nir_metadata_block_index |
nir_metadata_dominance, &p);
@@ -195,20 +192,18 @@ si_nir_is_output_const_if_tex_is_const(nir_shader *shader, float *in, float *out
bool progress;
do {
progress = false;
- NIR_PASS(progress, sh, nir_copy_prop);
- NIR_PASS(progress, sh, nir_opt_remove_phis);
- NIR_PASS(progress, sh, nir_opt_dce);
- NIR_PASS(progress, sh, nir_opt_dead_cf);
- NIR_PASS(progress, sh, nir_opt_algebraic);
- NIR_PASS(progress, sh, nir_opt_constant_folding);
+ NIR_PASS(progress, shader, nir_copy_prop);
+ NIR_PASS(progress, shader, nir_opt_remove_phis);
+ NIR_PASS(progress, shader, nir_opt_dce);
+ NIR_PASS(progress, shader, nir_opt_dead_cf);
+ NIR_PASS(progress, shader, nir_opt_algebraic);
+ NIR_PASS(progress, shader, nir_opt_constant_folding);
} while (progress);
/* Is the output a constant value? */
- if (get_output_as_const_value(sh, out)) {
- ralloc_free(sh);
+ if (get_output_as_const_value(shader, out))
return true;
- }
}
- ralloc_free(sh);
+
return false;
}
diff --git a/src/gallium/drivers/radeonsi/si_shader.c b/src/gallium/drivers/radeonsi/si_shader.c
index 68c61ec4305..c4d81298a27 100644
--- a/src/gallium/drivers/radeonsi/si_shader.c
+++ b/src/gallium/drivers/radeonsi/si_shader.c
@@ -1515,6 +1515,17 @@ static bool si_lower_io_to_mem(const union si_shader_key *key,
return false;
}
+struct nir_shader *si_deserialize_shader(struct si_shader_selector *sel)
+{
+ struct pipe_screen *screen = &sel->screen->b;
+ const void *options = screen->get_compiler_options(screen, PIPE_SHADER_IR_NIR,
+ pipe_shader_type_from_mesa(sel->stage));
+
+ struct blob_reader blob_reader;
+ blob_reader_init(&blob_reader, sel->nir_binary, sel->nir_size);
+ return nir_deserialize(NULL, options, &blob_reader);
+}
+
struct nir_shader *si_get_nir_shader(struct si_shader_selector *sel,
const union si_shader_key *key,
bool *free_nir,
@@ -1526,14 +1537,8 @@ struct nir_shader *si_get_nir_shader(struct si_shader_selector *sel,
if (sel->nir) {
nir = sel->nir;
} else if (sel->nir_binary) {
- struct pipe_screen *screen = &sel->screen->b;
- const void *options = screen->get_compiler_options(screen, PIPE_SHADER_IR_NIR,
- pipe_shader_type_from_mesa(sel->stage));
-
- struct blob_reader blob_reader;
- blob_reader_init(&blob_reader, sel->nir_binary, sel->nir_size);
+ nir = si_deserialize_shader(sel);
*free_nir = true;
- nir = nir_deserialize(NULL, options, &blob_reader);
} else {
return NULL;
}
diff --git a/src/gallium/drivers/radeonsi/si_shader.h b/src/gallium/drivers/radeonsi/si_shader.h
index c86e2f27f2a..8c38792e6de 100644
--- a/src/gallium/drivers/radeonsi/si_shader.h
+++ b/src/gallium/drivers/radeonsi/si_shader.h
@@ -979,6 +979,7 @@ void si_shader_dump_stats_for_shader_db(struct si_screen *screen, struct si_shad
void si_multiwave_lds_size_workaround(struct si_screen *sscreen, unsigned *lds_size);
const char *si_get_shader_name(const struct si_shader *shader);
void si_shader_binary_clean(struct si_shader_binary *binary);
+struct nir_shader *si_deserialize_shader(struct si_shader_selector *sel);
/* si_shader_info.c */
void si_nir_scan_shader(struct si_screen *sscreen, const struct nir_shader *nir,
diff --git a/src/gallium/drivers/radeonsi/si_state.c b/src/gallium/drivers/radeonsi/si_state.c
index fb31de37ac3..c16dfa3aa3b 100644
--- a/src/gallium/drivers/radeonsi/si_state.c
+++ b/src/gallium/drivers/radeonsi/si_state.c
@@ -656,15 +656,12 @@ static bool si_check_blend_dst_sampler_noop(struct si_context *sctx)
if (sctx->framebuffer.state.nr_cbufs == 1) {
struct si_shader_selector *sel = sctx->shader.ps.cso;
- /* Wait for the shader to be ready. */
- util_queue_fence_wait(&sel->ready);
-
- assert(!sel->nir);
-
- bool free_nir;
if (unlikely(sel->info.writes_1_if_tex_is_1 == 0xff)) {
- struct nir_shader *nir =
- si_get_nir_shader(sel, &sctx->shader.ps.key, &free_nir, 0);
+ /* Wait for the shader to be ready. */
+ util_queue_fence_wait(&sel->ready);
+ assert(sel->nir_binary);
+
+ struct nir_shader *nir = si_deserialize_shader(sel);
/* Determine if this fragment shader always writes vec4(1) if a specific texture
* is all 1s.
@@ -679,9 +676,7 @@ static bool si_check_blend_dst_sampler_noop(struct si_context *sctx)
sel->info.writes_1_if_tex_is_1 = 0;
}
- assert(free_nir);
- if (free_nir)
- ralloc_free(nir);
+ ralloc_free(nir);
}
if (sel->info.writes_1_if_tex_is_1 &&
More information about the mesa-commit
mailing list