From d2aa0783e581bf3dc5e6c7e000eae92dfa3d4b64 Mon Sep 17 00:00:00 2001 From: Gert Wollny Date: Wed, 30 Dec 2020 11:15:04 +0100 Subject: [PATCH] vshader: Emit code to query texture levels from uniform on GLES This fixes all piglits from: spec@arb_texture_query_levels v2: use tgsi_proc_to_prefix Signed-off-by: Gert Wollny Acked-by: Rohan Garg --- src/vrend_shader.c | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/src/vrend_shader.c b/src/vrend_shader.c index 05283a4..a2dd41f 100644 --- a/src/vrend_shader.c +++ b/src/vrend_shader.c @@ -2238,6 +2238,7 @@ static void set_texture_reqs(struct dump_ctx *ctx, } // TODO Consider exposing non-const ctx-> members as args to make *ctx const + /* size queries are pretty much separate */ static void emit_txq(struct dump_ctx *ctx, const struct tgsi_full_instruction *inst, @@ -2286,6 +2287,10 @@ static void emit_txq(struct dump_ctx *ctx, emit_buff(&ctx->glsl_strbufs, "%s%s = %s(textureQueryLevels(%s));\n", dst, get_wm_string(twm), get_string(dtypeprefix), srcs[sampler_index]); + else + emit_buff(&ctx->glsl_strbufs, "%s%s = %s(%s_texlod[%s]);\n", dst, get_wm_string(twm), + get_string(dtypeprefix), tgsi_proc_to_prefix(ctx->info.processor), + srcs[sampler_index]); } if (inst->Dst[0].Register.WriteMask & 0x7) { @@ -4114,16 +4119,28 @@ get_source_info(struct dump_ctx *ctx, strbuf_fmt(src_buf, "%s%s(%sconst%d[%d]%s)", prefix, get_string(csp), cname, dim, src->Register.Index, swizzle); } } else if (src->Register.File == TGSI_FILE_SAMPLER) { - const char *cname = tgsi_proc_to_prefix(ctx->prog_type); - if (ctx->info.indirect_files & (1 << TGSI_FILE_SAMPLER)) { - int basearrayidx = lookup_sampler_array(ctx, src->Register.Index); - if (src->Register.Indirect) { - strbuf_fmt(src_buf, "%ssamp%d[addr%d+%d]%s", cname, basearrayidx, src->Indirect.Index, src->Register.Index - basearrayidx, swizzle); + if (!ctx->cfg->use_gles || + !(inst->Instruction.Opcode == TGSI_OPCODE_TXQ) || + !(inst->Dst[0].Register.WriteMask & 0x8)) { + const char *cname = tgsi_proc_to_prefix(ctx->prog_type); + if (ctx->info.indirect_files & (1 << TGSI_FILE_SAMPLER)) { + int basearrayidx = lookup_sampler_array(ctx, src->Register.Index); + if (src->Register.Indirect) { + strbuf_fmt(src_buf, "%ssamp%d[addr%d+%d]%s", cname, basearrayidx, src->Indirect.Index, src->Register.Index - basearrayidx, swizzle); + } else { + strbuf_fmt(src_buf, "%ssamp%d[%d]%s", cname, basearrayidx, src->Register.Index - basearrayidx, swizzle); + } } else { - strbuf_fmt(src_buf, "%ssamp%d[%d]%s", cname, basearrayidx, src->Register.Index - basearrayidx, swizzle); + strbuf_fmt(src_buf, "%ssamp%d%s", cname, src->Register.Index, swizzle); } } else { - strbuf_fmt(src_buf, "%ssamp%d%s", cname, src->Register.Index, swizzle); + /* This is probably incorrect, we assume that the base-index is the sum of all arrays sizes up + * to this array of samplers */ + if (ctx->info.indirect_files & (1 << TGSI_FILE_SAMPLER) && src->Register.Indirect) { + strbuf_fmt(src_buf, "addr%d+%d", src->Indirect.Index, src->Register.Index); + } else { + strbuf_fmt(src_buf, "%d", src->Register.Index); + } } sinfo->sreg_index = src->Register.Index; } else if (src->Register.File == TGSI_FILE_IMAGE) { @@ -5898,11 +5915,14 @@ static int emit_ios_common(const struct dump_ctx *ctx, } } + unsigned n_samplers = 0; if (ctx->info.indirect_files & (1 << TGSI_FILE_SAMPLER)) { for (i = 0; i < ctx->num_sampler_arrays; i++) { uint32_t first = ctx->sampler_arrays[i].first; uint32_t range = ctx->sampler_arrays[i].array_size; + emit_sampler_decl(ctx, glsl_strbufs, shadow_samp_mask, first, range, ctx->samplers + first); + n_samplers += range; } } else { uint nsamp = util_last_bit(ctx->samplers_used); @@ -5912,9 +5932,13 @@ static int emit_ios_common(const struct dump_ctx *ctx, continue; emit_sampler_decl(ctx, glsl_strbufs, shadow_samp_mask, i, 0, ctx->samplers + i); + ++n_samplers; } } + if (ctx->cfg->use_gles && n_samplers) + emit_hdrf(glsl_strbufs, "uniform int %s_texlod[%d];\n", tgsi_proc_to_prefix(ctx->info.processor), n_samplers); + if (ctx->info.indirect_files & (1 << TGSI_FILE_IMAGE)) { for (i = 0; i < ctx->num_image_arrays; i++) { uint32_t first = ctx->image_arrays[i].first;