diff options
author | Alyssa Rosenzweig <alyssa@rosenzweig.io> | 2021-07-11 18:07:53 -0400 |
---|---|---|
committer | Marge Bot <eric+marge@anholt.net> | 2021-07-11 22:32:41 +0000 |
commit | dd98918a5a6d9d1b7e17a7bd70bb2cb73801e321 (patch) | |
tree | 341877bf93bdb2c3a6af0831d1779ce61287a2cb /src/asahi | |
parent | 3291779c21355066b9c9170cbe0b770f51803393 (diff) |
agx: Flip point coordinates because OpenGL
Fixes dEQP-GLES2.functional.shaders.builtin_variable.pointcoord
Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11818>
Diffstat (limited to 'src/asahi')
-rw-r--r-- | src/asahi/compiler/agx_compile.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/asahi/compiler/agx_compile.c b/src/asahi/compiler/agx_compile.c index ef1fe82b778..64b28f8e999 100644 --- a/src/asahi/compiler/agx_compile.c +++ b/src/asahi/compiler/agx_compile.c @@ -1103,6 +1103,39 @@ agx_lower_front_face(struct nir_builder *b, return true; } +static bool +agx_lower_point_coord(struct nir_builder *b, + nir_instr *instr, UNUSED 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_deref) + return false; + + nir_deref_instr *deref = nir_src_as_deref(intr->src[0]); + nir_variable *var = nir_deref_instr_get_variable(deref); + + if (var->data.mode != nir_var_shader_in) + return false; + + if (var->data.location != VARYING_SLOT_PNTC) + return false; + + assert(intr->dest.is_ssa); + assert(intr->dest.ssa.num_components == 2); + + b->cursor = nir_after_instr(&intr->instr); + nir_ssa_def *def = nir_load_deref(b, deref); + nir_ssa_def *y = nir_channel(b, def, 1); + nir_ssa_def *flipped_y = nir_fadd_imm(b, nir_fneg(b, y), 1.0); + nir_ssa_def *flipped = nir_vec2(b, nir_channel(b, def, 0), flipped_y); + nir_ssa_def_rewrite_uses(&intr->dest.ssa, flipped); + return true; +} + static void agx_optimize_nir(nir_shader *nir) { @@ -1304,6 +1337,11 @@ agx_compile_shader_nir(nir_shader *nir, /* Lower from OpenGL [-1, 1] to [0, 1] if half-z is not set */ if (!key->vs.clip_halfz) NIR_PASS_V(nir, nir_lower_clip_halfz); + } else if (ctx->stage == MESA_SHADER_FRAGMENT) { + /* Flip point coordinate since OpenGL and Metal disagree */ + NIR_PASS_V(nir, nir_shader_instructions_pass, + agx_lower_point_coord, + nir_metadata_block_index | nir_metadata_dominance, NULL); } NIR_PASS_V(nir, nir_split_var_copies); |