panfrost/blend: Inline blend constants
If we're going to key them in NIR, we might as well get the benefit of constant folding them too. Signed-off-by: Alyssa Rosenzweig <alyssa@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10652>
This commit is contained in:
parent
ba39367b96
commit
1378c67bcf
|
@ -1172,26 +1172,6 @@ bi_emit_intrinsic(bi_builder *b, nir_intrinsic_instr *instr)
|
|||
nir_dest_num_components(instr->dest), 0);
|
||||
break;
|
||||
|
||||
case nir_intrinsic_load_blend_const_color_r_float:
|
||||
bi_mov_i32_to(b, dst,
|
||||
bi_imm_f32(b->shader->inputs->blend.constants[0]));
|
||||
break;
|
||||
|
||||
case nir_intrinsic_load_blend_const_color_g_float:
|
||||
bi_mov_i32_to(b, dst,
|
||||
bi_imm_f32(b->shader->inputs->blend.constants[1]));
|
||||
break;
|
||||
|
||||
case nir_intrinsic_load_blend_const_color_b_float:
|
||||
bi_mov_i32_to(b, dst,
|
||||
bi_imm_f32(b->shader->inputs->blend.constants[2]));
|
||||
break;
|
||||
|
||||
case nir_intrinsic_load_blend_const_color_a_float:
|
||||
bi_mov_i32_to(b, dst,
|
||||
bi_imm_f32(b->shader->inputs->blend.constants[3]));
|
||||
break;
|
||||
|
||||
case nir_intrinsic_load_sample_positions_pan:
|
||||
bi_mov_i32_to(b, bi_word(dst, 0),
|
||||
bi_fau(BIR_FAU_SAMPLE_POS_ARRAY, false));
|
||||
|
|
|
@ -449,6 +449,31 @@ get_equation_str(const struct pan_blend_rt_state *rt_state,
|
|||
}
|
||||
}
|
||||
|
||||
static bool
|
||||
pan_inline_blend_constants(nir_builder *b, nir_instr *instr, void *data)
|
||||
{
|
||||
if (instr->type != nir_instr_type_intrinsic)
|
||||
return false;
|
||||
|
||||
nir_intrinsic_instr *intr = nir_instr_as_intrinsic(instr);
|
||||
if (intr->intrinsic != nir_intrinsic_load_blend_const_color_rgba)
|
||||
return false;
|
||||
|
||||
float *floats = data;
|
||||
const nir_const_value constants[4] = {
|
||||
{ .f32 = floats[0] },
|
||||
{ .f32 = floats[1] },
|
||||
{ .f32 = floats[2] },
|
||||
{ .f32 = floats[3] }
|
||||
};
|
||||
|
||||
b->cursor = nir_after_instr(instr);
|
||||
nir_ssa_def *constant = nir_build_imm(b, 4, 32, constants);
|
||||
nir_ssa_def_rewrite_uses(&intr->dest.ssa, constant);
|
||||
nir_instr_remove(instr);
|
||||
return true;
|
||||
}
|
||||
|
||||
nir_shader *
|
||||
pan_blend_create_shader(const struct panfrost_device *dev,
|
||||
const struct pan_blend_state *state,
|
||||
|
@ -481,8 +506,7 @@ pan_blend_create_shader(const struct panfrost_device *dev,
|
|||
.logicop_func = state->logicop_func,
|
||||
.colormask = rt_state->equation.color_mask,
|
||||
.half = nir_type == nir_type_float16,
|
||||
.format = rt_state->format,
|
||||
.scalar = pan_is_bifrost(dev),
|
||||
.format = rt_state->format
|
||||
};
|
||||
|
||||
if (!rt_state->equation.blend_enable) {
|
||||
|
@ -551,6 +575,9 @@ pan_blend_create_shader(const struct panfrost_device *dev,
|
|||
options.src1 = s_src[1];
|
||||
|
||||
NIR_PASS_V(b.shader, nir_lower_blend, options);
|
||||
nir_shader_instructions_pass(b.shader, pan_inline_blend_constants,
|
||||
nir_metadata_block_index | nir_metadata_dominance,
|
||||
(void *) state->constants);
|
||||
|
||||
return b.shader;
|
||||
}
|
||||
|
@ -674,9 +701,6 @@ pan_blend_get_shader_locked(const struct panfrost_device *dev,
|
|||
.rt_formats = { key.format },
|
||||
};
|
||||
|
||||
if (key.has_constants)
|
||||
memcpy(inputs.blend.constants, state->constants, sizeof(inputs.blend.constants));
|
||||
|
||||
if (pan_is_bifrost(dev)) {
|
||||
inputs.blend.bifrost_blend_desc =
|
||||
pan_blend_get_bifrost_desc(dev, key.format, key.rt, 0);
|
||||
|
|
|
@ -1858,18 +1858,6 @@ emit_intrinsic(compiler_context *ctx, nir_intrinsic_instr *instr)
|
|||
break;
|
||||
}
|
||||
|
||||
case nir_intrinsic_load_blend_const_color_rgba: {
|
||||
assert(ctx->inputs->is_blend);
|
||||
reg = nir_dest_index(&instr->dest);
|
||||
|
||||
midgard_instruction ins = v_mov(SSA_FIXED_REGISTER(REGISTER_CONSTANT), reg);
|
||||
ins.has_constants = true;
|
||||
memcpy(ins.constants.f32, ctx->inputs->blend.constants,
|
||||
sizeof(ctx->inputs->blend.constants));
|
||||
emit_mir_instruction(ctx, ins);
|
||||
break;
|
||||
}
|
||||
|
||||
case nir_intrinsic_store_output:
|
||||
case nir_intrinsic_store_combined_output_pan:
|
||||
assert(nir_src_is_const(instr->src[1]) && "no indirect outputs");
|
||||
|
|
|
@ -122,7 +122,6 @@ struct panfrost_compile_inputs {
|
|||
struct {
|
||||
unsigned rt;
|
||||
unsigned nr_samples;
|
||||
float constants[4];
|
||||
uint64_t bifrost_blend_desc;
|
||||
} blend;
|
||||
unsigned sysval_ubo;
|
||||
|
|
Loading…
Reference in New Issue