From b9cc2b2a98ccdd53d57534ebb9c0702917598dd5 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Thu, 30 Mar 2023 14:00:46 -0400 Subject: [PATCH] pan/{mdg,bi}: Always use sampler 0 for txf Now that we upload workaround samplers for txf, sampler 0 is guaranteed to be valid but other samplers are not. So ignore whatever the current sampler_index value is (it's formally undefined in NIR) and use 0, which we know is valid. We already do this on Valhall for OpenCL, just need to generalize for Midgard and Bifrost. Signed-off-by: Alyssa Rosenzweig Reviewed-by: Italo Nicola Reviewed-by: Boris Brezillon Part-of: --- src/panfrost/compiler/bifrost_compile.c | 12 +++++++++--- src/panfrost/midgard/midgard_compile.c | 8 ++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/panfrost/compiler/bifrost_compile.c b/src/panfrost/compiler/bifrost_compile.c index 830751a0736..b2c35aa8a1b 100644 --- a/src/panfrost/compiler/bifrost_compile.c +++ b/src/panfrost/compiler/bifrost_compile.c @@ -3534,9 +3534,7 @@ bi_emit_tex_valhall(bi_builder *b, nir_tex_instr *instr) /* 32-bit indices to be allocated as consecutive staging registers */ bi_index sregs[VALHALL_TEX_SREG_COUNT] = {}; - - bool has_sampler = nir_tex_instr_need_sampler(instr); - bi_index sampler = bi_imm_u32(has_sampler ? instr->sampler_index : 0); + bi_index sampler = bi_imm_u32(instr->sampler_index); bi_index texture = bi_imm_u32(instr->texture_index); uint32_t tables = (PAN_TABLE_SAMPLER << 11) | (PAN_TABLE_TEXTURE << 27); @@ -3779,6 +3777,14 @@ bi_is_simple_tex(nir_tex_instr *instr) static void bi_emit_tex(bi_builder *b, nir_tex_instr *instr) { + /* If txf is used, we assume there is a valid sampler bound at index 0. Use + * it for txf operations, since there may be no other valid samplers. This is + * a workaround: txf does not require a sampler in NIR (so sampler_index is + * undefined) but we need one in the hardware. This is ABI with the driver. + */ + if (!nir_tex_instr_need_sampler(instr)) + instr->sampler_index = 0; + if (b->shader->arch >= 9) bi_emit_tex_valhall(b, instr); else if (bi_is_simple_tex(instr)) diff --git a/src/panfrost/midgard/midgard_compile.c b/src/panfrost/midgard/midgard_compile.c index 2dab5fc9a8a..8b103dea84d 100644 --- a/src/panfrost/midgard/midgard_compile.c +++ b/src/panfrost/midgard/midgard_compile.c @@ -2334,6 +2334,14 @@ emit_texop_native(compiler_context *ctx, nir_tex_instr *instr, int texture_index = instr->texture_index; int sampler_index = instr->sampler_index; + /* If txf is used, we assume there is a valid sampler bound at index 0. Use + * it for txf operations, since there may be no other valid samplers. This is + * a workaround: txf does not require a sampler in NIR (so sampler_index is + * undefined) but we need one in the hardware. This is ABI with the driver. + */ + if (!nir_tex_instr_need_sampler(instr)) + sampler_index = 0; + nir_alu_type dest_base = nir_alu_type_get_base_type(instr->dest_type); /* texture instructions support float outmods */