nir/lower_alpha: extend to support dynamic a2c

Signed-off-by: Simon Perretta <simon.perretta@imgtec.com>
Reviewed-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/37512>
This commit is contained in:
Simon Perretta 2025-08-28 17:14:20 +01:00 committed by Marge Bot
parent 63c4ecfae0
commit 2a7ebf2ae0
9 changed files with 34 additions and 16 deletions

View file

@ -473,7 +473,7 @@ agx_nir_fs_epilog(nir_builder *b, const void *key_)
/* Alpha-to-coverage must be lowered before alpha-to-one */
if (key->blend.alpha_to_coverage)
NIR_PASS(_, b->shader, nir_lower_alpha_to_coverage, tib.nr_samples,
false);
false, NULL);
/* Depth/stencil writes must be deferred until after all discards,
* particularly alpha-to-coverage.

View file

@ -1103,7 +1103,7 @@ v3d_nir_lower_fs_early(struct v3d_compile *c)
assert(c->fs_key->msaa);
NIR_PASS(_, c->s, nir_lower_alpha_to_coverage,
V3D_MAX_SAMPLES, true);
V3D_MAX_SAMPLES, true, NULL);
}
if (c->fs_key->sample_alpha_to_one)

View file

@ -5455,7 +5455,8 @@ bool nir_lower_vec_to_regs(nir_shader *shader, nir_instr_writemask_filter_cb cb,
bool nir_lower_alpha_to_coverage(nir_shader *shader,
uint8_t nr_samples,
bool has_intrinsic);
bool has_intrinsic,
nir_def *dyn_enable);
bool nir_lower_alpha_to_one(nir_shader *shader);

View file

@ -28,7 +28,7 @@ alpha_to_coverage(nir_builder *b, nir_def *alpha, uint8_t nr_samples, bool has_i
* monolithic pixel shader or a fragment epilogue.
*/
bool
nir_lower_alpha_to_coverage(nir_shader *shader, uint8_t nr_samples, bool has_intrinsic)
nir_lower_alpha_to_coverage(nir_shader *shader, uint8_t nr_samples, bool has_intrinsic, nir_def *dyn_enable)
{
/* If we are not using the intrinsic we need to know the sample count. */
assert(has_intrinsic || nr_samples);
@ -72,6 +72,8 @@ nir_lower_alpha_to_coverage(nir_shader *shader, uint8_t nr_samples, bool has_int
nir_builder *b = &_b;
nir_def *alpha = nir_channel(b, rgba, 3);
if (dyn_enable)
alpha = nir_bcsel(b, dyn_enable, alpha, nir_imm_floatN_t(b, 1.0f, alpha->bit_size));
nir_def *mask = alpha_to_coverage(b, alpha, nr_samples, has_intrinsic);
/* Discard samples that aren't covered */

View file

@ -1761,10 +1761,10 @@ bool pco_nir_link_multiview(nir_shader *producer,
pco_data *consumer_data);
bool pco_nir_lower_algebraic(nir_shader *shader);
bool pco_nir_lower_algebraic_late(nir_shader *shader);
bool pco_nir_lower_alpha_to_coverage(nir_shader *shader);
bool pco_nir_lower_atomics(nir_shader *shader, pco_data *data);
bool pco_nir_lower_barriers(nir_shader *shader, pco_data *data);
bool pco_nir_lower_clip_cull_vars(nir_shader *shader);
bool pco_nir_lower_demote_samples(nir_shader *shader);
bool pco_nir_lower_fs_intrinsics(nir_shader *shader);
bool pco_nir_lower_vs_intrinsics(nir_shader *shader);
bool pco_nir_lower_images(nir_shader *shader, pco_data *data);

View file

@ -886,10 +886,7 @@ void pco_lower_nir(pco_ctx *ctx, nir_shader *nir, pco_data *data)
NIR_PASS(_, nir, pco_nir_lower_tex, data, ctx);
if (nir->info.stage == MESA_SHADER_FRAGMENT) {
if (data->fs.uses.alpha_to_coverage) {
NIR_PASS(_, nir, nir_lower_alpha_to_coverage, 0, true);
NIR_PASS(_, nir, pco_nir_lower_demote_samples);
}
NIR_PASS(_, nir, pco_nir_lower_alpha_to_coverage);
NIR_PASS(_, nir, nir_lower_blend, &data->fs.blend_opts);

View file

@ -702,13 +702,27 @@ static bool lower_demote_samples(nir_builder *b,
return true;
}
bool pco_nir_lower_demote_samples(nir_shader *s)
bool pco_nir_lower_alpha_to_coverage(nir_shader *shader)
{
assert(s->info.stage == MESA_SHADER_FRAGMENT);
return nir_shader_intrinsics_pass(s,
lower_demote_samples,
nir_metadata_control_flow,
NULL);
if (shader->info.internal)
return false;
nir_builder b = nir_builder_create(nir_shader_get_entrypoint(shader));
b.cursor =
nir_before_block(nir_start_block(nir_shader_get_entrypoint(shader)));
nir_def *a2c_enabled = nir_ine_imm(
&b,
nir_ubitfield_extract_imm(&b, nir_load_fs_meta_pco(&b), 25, 1),
0);
nir_lower_alpha_to_coverage(shader, 0, true, a2c_enabled);
nir_shader_intrinsics_pass(shader,
lower_demote_samples,
nir_metadata_control_flow,
NULL);
return true;
}
static nir_def *

View file

@ -4233,6 +4233,10 @@ static VkResult pvr_setup_descriptor_mappings(
cmd_buffer->vk.dynamic_graphics_state.cb.color_write_enables
<< 1;
if (cmd_buffer->vk.dynamic_graphics_state.ms
.alpha_to_coverage_enable)
fs_meta |= (1 << 25);
struct pvr_suballoc_bo *fs_meta_bo;
result = pvr_cmd_buffer_upload_general(cmd_buffer,
&fs_meta,

View file

@ -391,7 +391,7 @@ static void pvr_physical_device_get_supported_features(
.extendedDynamicState3PolygonMode = false,
.extendedDynamicState3RasterizationSamples = true,
.extendedDynamicState3SampleMask = true,
.extendedDynamicState3AlphaToCoverageEnable = false,
.extendedDynamicState3AlphaToCoverageEnable = true,
.extendedDynamicState3AlphaToOneEnable = true,
.extendedDynamicState3LogicOpEnable = false,
.extendedDynamicState3ColorBlendEnable = false,