From c1d68da5e28102f76cd795cc86288d86354b70eb Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Tue, 30 Apr 2024 15:38:17 -0400 Subject: [PATCH] asahi: plumb tri fan flatshading through common not yet used in the GL driver but we should probably fix that. Signed-off-by: Alyssa Rosenzweig Part-of: --- src/asahi/compiler/agx_compile.c | 3 --- src/asahi/compiler/agx_compile.h | 1 + src/asahi/compiler/agx_nir.h | 1 - .../compiler/agx_nir_lower_interpolation.c | 12 +++++++++--- .../drivers/asahi/agx_nir_lower_sysvals.c | 3 +++ src/gallium/drivers/asahi/agx_state.c | 17 ++++++----------- 6 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/asahi/compiler/agx_compile.c b/src/asahi/compiler/agx_compile.c index b87c1d061f6..2c158ffccf0 100644 --- a/src/asahi/compiler/agx_compile.c +++ b/src/asahi/compiler/agx_compile.c @@ -3335,9 +3335,6 @@ agx_compile_shader_nir(nir_shader *nir, struct agx_shader_key *key, bool needs_libagx = true /* TODO: Optimize */; - if (nir->info.stage == MESA_SHADER_FRAGMENT) - NIR_PASS(_, nir, agx_nir_lower_interpolation); - NIR_PASS(_, nir, nir_lower_vars_to_ssa); if (needs_libagx) { diff --git a/src/asahi/compiler/agx_compile.h b/src/asahi/compiler/agx_compile.h index 5bbf734e18a..68e259868c3 100644 --- a/src/asahi/compiler/agx_compile.h +++ b/src/asahi/compiler/agx_compile.h @@ -234,6 +234,7 @@ void agx_link_libagx(nir_shader *nir, const nir_shader *libagx); void agx_preprocess_nir(nir_shader *nir, const nir_shader *libagx); bool agx_nir_lower_discard_zs_emit(nir_shader *s); bool agx_nir_lower_sample_mask(nir_shader *s); +bool agx_nir_lower_interpolation(nir_shader *s); bool agx_nir_lower_cull_distance_fs(struct nir_shader *s, unsigned nr_distances); diff --git a/src/asahi/compiler/agx_nir.h b/src/asahi/compiler/agx_nir.h index 83c9ad87093..f370905c2b2 100644 --- a/src/asahi/compiler/agx_nir.h +++ b/src/asahi/compiler/agx_nir.h @@ -9,7 +9,6 @@ struct nir_shader; -bool agx_nir_lower_interpolation(struct nir_shader *s); bool agx_nir_lower_algebraic_late(struct nir_shader *shader); bool agx_nir_fuse_selects(struct nir_shader *shader); bool agx_nir_fuse_algebraic_late(struct nir_shader *shader); diff --git a/src/asahi/compiler/agx_nir_lower_interpolation.c b/src/asahi/compiler/agx_nir_lower_interpolation.c index 8cb29492372..b5e9597c4e1 100644 --- a/src/asahi/compiler/agx_nir_lower_interpolation.c +++ b/src/asahi/compiler/agx_nir_lower_interpolation.c @@ -4,7 +4,7 @@ */ #include "compiler/shader_enums.h" -#include "agx_nir.h" +#include "agx_compile.h" #include "nir.h" #include "nir_builder.h" #include "nir_builder_opcodes.h" @@ -82,8 +82,14 @@ interpolate_at_offset(nir_builder *b, nir_def *cf, nir_def *offset, static nir_def * interpolate_flat(nir_builder *b, nir_def *coefficients) { - /* Same value anywhere, so just take the constant (affine) component */ - return nir_channel(b, coefficients, 2); + /* Same value anywhere, so just take the constant (affine) component. For + * triangle fans with the first provoking vertex, the CF layout is slightly + * different. I am unsure why, but Apple does the same and the bcsel is + * required for corrctness. + */ + return nir_bcsel(b, nir_load_is_first_fan_agx(b), + nir_channel(b, coefficients, 1), + nir_channel(b, coefficients, 2)); } static enum glsl_interp_mode diff --git a/src/gallium/drivers/asahi/agx_nir_lower_sysvals.c b/src/gallium/drivers/asahi/agx_nir_lower_sysvals.c index e1afb663d11..93466e1ffe3 100644 --- a/src/gallium/drivers/asahi/agx_nir_lower_sysvals.c +++ b/src/gallium/drivers/asahi/agx_nir_lower_sysvals.c @@ -198,6 +198,9 @@ lower_intrinsic(nir_builder *b, nir_intrinsic_instr *intr, case nir_intrinsic_load_uvs_index_agx: return load_sysval_root( b, 1, 16, &u->uvs_index[nir_intrinsic_io_semantics(intr).location]); + case nir_intrinsic_load_is_first_fan_agx: + /* TODO: Plumb this so we can stop using geometry shaders for this case */ + return nir_imm_false(b); default: break; } diff --git a/src/gallium/drivers/asahi/agx_state.c b/src/gallium/drivers/asahi/agx_state.c index 4355a106b16..bf29cd04f5e 100644 --- a/src/gallium/drivers/asahi/agx_state.c +++ b/src/gallium/drivers/asahi/agx_state.c @@ -1564,6 +1564,10 @@ agx_compile_nir(struct agx_device *dev, nir_shader *nir, .secondary = secondary, }; + if (nir->info.stage == MESA_SHADER_FRAGMENT) { + NIR_PASS(_, nir, agx_nir_lower_interpolation); + } + /* We always use dynamic sample shading in the GL driver. Indicate that. */ if (nir->info.stage == MESA_SHADER_FRAGMENT && nir->info.fs.uses_sample_shading) @@ -4190,21 +4194,12 @@ agx_needs_passthrough_gs(struct agx_context *ctx, return true; } - /* Experimentally, G13 does not seem to pick the right provoking vertex for - * triangle fans with first provoking. Inserting a GS for this case lets us - * use our (correct) shader-based input assembly, translating to - * appropriately oriented triangles and working around the hardware issue. - * This warrants more investigation in case we're just misconfiguring the - * hardware, but as tri fans are absent in Metal and GL defaults to last - * vertex, this is a plausible part of the hardware to be broken (or absent). - * - * Affects piglit clipflat. - */ + /* TODO: Handle fans properly, we need to plumb a sysval. */ if (info->mode == MESA_PRIM_TRIANGLE_FAN && ctx->rast->base.flatshade_first && ctx->stage[MESA_SHADER_FRAGMENT].shader->info.inputs_flat_shaded) { - perf_debug_ctx(ctx, "Using passthrough GS due to tri fan bug"); + perf_debug_ctx(ctx, "Using passthrough GS due to first tri fans"); return true; }