From ff29ff5fad2ac2329334bd956c0ec4fc7d70046f Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Tue, 13 Sep 2022 12:04:32 -0400 Subject: [PATCH] panfrost: Upload default sampler for txf In NIR, txf does not take a sampler. However, in the hardware it does take a sampler. If there is no sampler bound and we use txf, the hardware will read back all-0's due to bounds checking. As a workaround, bind a trivial sampler and use that. As-is this workaround is Valhall specific, making use of an extra resource table. I'm punting on generalizing back to Bifrost until I can discuss the issue in more depth with Jason and Karol and figure out the right fix. Fixes api.image_properties_query. Signed-off-by: Alyssa Rosenzweig Part-of: --- src/gallium/drivers/panfrost/pan_cmdstream.c | 22 +++++++++++++++++--- src/panfrost/bifrost/bifrost_compile.c | 4 +++- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/gallium/drivers/panfrost/pan_cmdstream.c b/src/gallium/drivers/panfrost/pan_cmdstream.c index 3550933a44a..01cd8c99587 100644 --- a/src/gallium/drivers/panfrost/pan_cmdstream.c +++ b/src/gallium/drivers/panfrost/pan_cmdstream.c @@ -3246,6 +3246,14 @@ panfrost_emit_primitive(struct panfrost_context *ctx, } #if PAN_ARCH >= 9 +static mali_ptr +panfrost_upload_wa_sampler(struct panfrost_batch *batch) +{ + struct panfrost_ptr T = pan_pool_alloc_desc(&batch->pool.base, SAMPLER); + pan_pack(T.cpu, SAMPLER, cfg); + return T.gpu; +} + static mali_ptr panfrost_emit_resources(struct panfrost_batch *batch, enum pipe_shader_type stage, @@ -3267,9 +3275,17 @@ panfrost_emit_resources(struct panfrost_batch *batch, batch->textures[stage], ctx->sampler_view_count[stage]); - panfrost_make_resource_table(T, PAN_TABLE_SAMPLER, - batch->samplers[stage], - ctx->sampler_count[stage]); + + if (ctx->sampler_count[stage]) { + panfrost_make_resource_table(T, PAN_TABLE_SAMPLER, + batch->samplers[stage], + ctx->sampler_count[stage]); + } else { + /* We always need at least 1 sampler for txf to work */ + panfrost_make_resource_table(T, PAN_TABLE_SAMPLER, + panfrost_upload_wa_sampler(batch), + 1); + } panfrost_make_resource_table(T, PAN_TABLE_IMAGE, batch->images[stage], diff --git a/src/panfrost/bifrost/bifrost_compile.c b/src/panfrost/bifrost/bifrost_compile.c index 5b3b7f10c5e..f96ae460f97 100644 --- a/src/panfrost/bifrost/bifrost_compile.c +++ b/src/panfrost/bifrost/bifrost_compile.c @@ -3666,7 +3666,9 @@ 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] = { }; - bi_index sampler = bi_imm_u32(instr->sampler_index); + + bool has_sampler = nir_tex_instr_need_sampler(instr); + bi_index sampler = bi_imm_u32(has_sampler ? instr->sampler_index : 0); bi_index texture = bi_imm_u32(instr->texture_index); uint32_t tables = (PAN_TABLE_SAMPLER << 11) | (PAN_TABLE_TEXTURE << 27);