mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-01-21 05:03:48 +08:00
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@amd.com> Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com> Signed-off-by: Qiang Yu <yuq825@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16705>
This commit is contained in:
parent
3aa70d92ce
commit
05b829cd0c
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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;
|
||||
|
||||
if (unlikely(sel->info.writes_1_if_tex_is_1 == 0xff)) {
|
||||
/* Wait for the shader to be ready. */
|
||||
util_queue_fence_wait(&sel->ready);
|
||||
assert(sel->nir_binary);
|
||||
|
||||
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);
|
||||
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,8 +676,6 @@ 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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user