From a43a09bc0e27cc00fd23d238649aa886c52d2fb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Corentin=20No=C3=ABl?= Date: Mon, 21 Mar 2022 11:20:41 +0100 Subject: [PATCH] shader: Make sure to use textureSize with the correct arguments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In the case of gsampler2DRect, there is no second argument to be provided to textureSize. Makes the `spec@arb_texture_rectangle@copyteximage rect samples=2` not crash. Signed-off-by: Corentin Noël Part-of: --- src/vrend_shader.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/vrend_shader.c b/src/vrend_shader.c index 13ed063c3..48ed1d9c9 100644 --- a/src/vrend_shader.c +++ b/src/vrend_shader.c @@ -2882,23 +2882,40 @@ static void translate_tex(struct dump_ctx *ctx, vrend_shader_sampler_views_mask_get(ctx->key->sampler_views_emulated_rect_mask, sinfo->sreg_index)) { char buf[255]; + const char *bias = ""; const char *new_srcs[4] = { buf, srcs[1], srcs[2], srcs[3] }; + /* No LOD for these texture types, but on GLES we emulate RECT by using + * a normal 2D texture, so we have to give LOD 0 */ + switch (inst->Texture.Texture) { + case TGSI_TEXTURE_BUFFER: + case TGSI_TEXTURE_2D_MSAA: + case TGSI_TEXTURE_2D_ARRAY_MSAA: + break; + case TGSI_TEXTURE_RECT: + case TGSI_TEXTURE_SHADOWRECT: + if (!ctx->cfg->use_gles) + break; + /* fallthrough */ + default: + bias = ", 0"; + } + switch (inst->Instruction.Opcode) { case TGSI_OPCODE_TXP: - snprintf(buf, 255, "vec4(%s)/vec4(textureSize(%s, 0), 1, 1)", srcs[0], srcs[sampler_index]); + snprintf(buf, 255, "vec4(%s)/vec4(textureSize(%s%s), 1, 1)", srcs[0], srcs[sampler_index], bias); break; case TGSI_OPCODE_TG4: - snprintf(buf, 255, "%s.xy/vec2(textureSize(%s, 0))", srcs[0], srcs[sampler_index]); + snprintf(buf, 255, "%s.xy/vec2(textureSize(%s%s))", srcs[0], srcs[sampler_index], bias); break; default: /* Non TG4 ops have the compare value in the z components */ if (inst->Texture.Texture == TGSI_TEXTURE_SHADOWRECT) { - snprintf(buf, 255, "vec3(%s.xy/vec2(textureSize(%s, 0)), %s.z)", srcs[0], srcs[sampler_index], srcs[0]); + snprintf(buf, 255, "vec3(%s.xy/vec2(textureSize(%s%s)), %s.z)", srcs[0], srcs[sampler_index], bias, srcs[0]); } else - snprintf(buf, 255, "%s.xy/vec2(textureSize(%s, 0))", srcs[0], srcs[sampler_index]); + snprintf(buf, 255, "%s.xy/vec2(textureSize(%s%s))", srcs[0], srcs[sampler_index], bias); } srcs = new_srcs; } -- GitLab