Module: Mesa Branch: staging/22.2 Commit: 9146b229fcca238d20e738e6f90fbfb23aff85ae URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=9146b229fcca238d20e738e6f90fbfb23aff85ae
Author: Alyssa Rosenzweig <[email protected]> Date: Thu Sep 1 15:11:36 2022 -0400 pan/bi: Fix dual texturing with uniforms The GLSL code sequence: texture2D(tex0, u_coords) + texture2D(tex1, u_coords) will be optimized to TEXC_DUAL tex0/tex1, u_coords, #texture_descriptor If this optimization happens after lowering FAU, the resulting TEXC instruction is unschedulable: both the uniform and the constant descriptor fight for the same FAU slot. However, if this optimization happens before lowering FAU, then the FAU lowering will move the descriptor into a register, complicating the dual texturing fixup in RA. To fix this interaction, fuse dual texturing before lowering FAU and keep texture descriptors as constants when lowering FAU of TEXC. Fixes scheduling failure in piglit drawoverhead -test 3 with uniform reordering. Fixes: a4d3a296477 ("pan/bi: Enable dual texture fusing pass") Fixes: 6b2eda6b729 ("pan/bi: Reorder pushed uniforms to avoid moves") Signed-off-by: Alyssa Rosenzweig <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18378> (cherry picked from commit c5b9a01feaa6e46827a8af003767d561d5c22fec) --- .pick_status.json | 2 +- src/panfrost/bifrost/bi_schedule.c | 8 ++++++++ src/panfrost/bifrost/bifrost_compile.c | 23 +++++++++++++---------- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index e21ad5d0254..f4e017226bb 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -5593,7 +5593,7 @@ "description": "pan/bi: Fix dual texturing with uniforms", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": "a4d3a2964771c3d26967ecab4d7c187a8b2d8002" }, diff --git a/src/panfrost/bifrost/bi_schedule.c b/src/panfrost/bifrost/bi_schedule.c index e30b10fb8ad..bf3eb5ee9f0 100644 --- a/src/panfrost/bifrost/bi_schedule.c +++ b/src/panfrost/bifrost/bi_schedule.c @@ -2015,6 +2015,14 @@ bi_lower_fau(bi_context *ctx) if (ins->op == BI_OPCODE_ATEST) fau = ins->src[2]; + /* Dual texturing requires the texture operation descriptor + * encoded as an immediate so we can fix up. + */ + if (ins->op == BI_OPCODE_TEXC) { + assert(ins->src[3].type == BI_INDEX_CONSTANT); + constants[cwords++] = ins->src[3].value; + } + bi_foreach_src(ins, s) { if (bi_check_fau_src(ins, s, constants, &cwords, &fau)) continue; diff --git a/src/panfrost/bifrost/bifrost_compile.c b/src/panfrost/bifrost/bifrost_compile.c index e91c3763ec1..9757a3aa7e1 100644 --- a/src/panfrost/bifrost/bifrost_compile.c +++ b/src/panfrost/bifrost/bifrost_compile.c @@ -5093,16 +5093,6 @@ bi_compile_variant_nir(nir_shader *nir, if (bifrost_debug & BIFROST_DBG_SHADERS && !skip_internal) bi_print_shader(ctx, stdout); - if (ctx->arch <= 8) { - bi_lower_fau(ctx); - } - - /* Lowering FAU can create redundant moves. Run CSE+DCE to clean up. */ - if (likely(optimize)) { - bi_opt_cse(ctx); - bi_opt_dead_code_eliminate(ctx); - } - /* Analyze before register allocation to avoid false dependencies. The * skip bit is a function of only the data flow graph and is invariant * under valid scheduling. Helpers are only defined for fragment @@ -5117,6 +5107,19 @@ bi_compile_variant_nir(nir_shader *nir, bi_opt_fuse_dual_texture(ctx); } + /* Lower FAU after fusing dual texture, because fusing dual texture + * creates new immediates that themselves may need lowering. + */ + if (ctx->arch <= 8) { + bi_lower_fau(ctx); + } + + /* Lowering FAU can create redundant moves. Run CSE+DCE to clean up. */ + if (likely(optimize)) { + bi_opt_cse(ctx); + bi_opt_dead_code_eliminate(ctx); + } + if (likely(!(bifrost_debug & BIFROST_DBG_NOPSCHED))) bi_pressure_schedule(ctx);
