From 3403b5cb0ec9bedd00a8e0f880af761c9fffce1d Mon Sep 17 00:00:00 2001 From: Gert Wollny Date: Fri, 8 Mar 2019 15:35:09 +0100 Subject: [PATCH] shader: Further fixes for the 1D texture emulation on GLES Fixes piglits on GLES host: tex-miplevel-selection * 1D* The only piglits that are not fixed from the tex-miplevel-selection are those including sampler1DArrayShadow. emulating these by using sampler2DArrayShadow is not always possible, because GLSL doesn't provide the required overloads. Namely textureOffset, textureLod, textureLodOffset, and texture with bias parameter are not available. Signed-off-by: Gert Wollny Reviewed-By: Reviewed-by: Gurchetan Singh --- src/vrend_shader.c | 44 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/src/vrend_shader.c b/src/vrend_shader.c index 50fca15..a7d16c3 100644 --- a/src/vrend_shader.c +++ b/src/vrend_shader.c @@ -2333,7 +2333,13 @@ static void translate_tex(struct dump_ctx *ctx, snprintf(bias, 64, ", int(%s.w)", srcs[0]); } } else if (inst->Instruction.Opcode == TGSI_OPCODE_TXD) { - snprintf(bias, 128, ", %s%s, %s%s", srcs[1], get_wm_string(gwm), srcs[2], get_wm_string(gwm)); + if (ctx->cfg->use_gles && (inst->Texture.Texture == TGSI_TEXTURE_1D || + inst->Texture.Texture == TGSI_TEXTURE_SHADOW1D || + inst->Texture.Texture == TGSI_TEXTURE_1D_ARRAY || + inst->Texture.Texture == TGSI_TEXTURE_SHADOW1D_ARRAY)) + snprintf(bias, 128, ", vec2(%s%s, 0), vec2(%s%s, 0)", srcs[1], get_wm_string(gwm), srcs[2], get_wm_string(gwm)); + else + snprintf(bias, 128, ", %s%s, %s%s", srcs[1], get_wm_string(gwm), srcs[2], get_wm_string(gwm)); sampler_index = 3; } else if (inst->Instruction.Opcode == TGSI_OPCODE_TG4) { sampler_index = 2; @@ -2448,16 +2454,40 @@ static void translate_tex(struct dump_ctx *ctx, } else if (is_shad && inst->Instruction.Opcode != TGSI_OPCODE_TG4) { /* TGSI returns 1.0 in alpha */ const char *cname = tgsi_proc_to_prefix(ctx->prog_type); const struct tgsi_full_src_register *src = &inst->Src[sampler_index]; - emit_buff(ctx, "%s = %s(%s(vec4(vec4(texture%s(%s, %s%s%s%s)) * %sshadmask%d + %sshadadd%d)%s));\n", dsts[0], get_string(dinfo->dstconv), get_string(dtypeprefix), tex_ext, srcs[sampler_index], srcs[0], get_wm_string(twm), offbuf, bias, cname, src->Register.Index, cname, src->Register.Index, writemask); + + if (ctx->cfg->use_gles && + (inst->Texture.Texture == TGSI_TEXTURE_SHADOW1D || + inst->Texture.Texture == TGSI_TEXTURE_SHADOW1D_ARRAY)) { + if (inst->Texture.Texture == TGSI_TEXTURE_SHADOW1D) { + if (inst->Instruction.Opcode == TGSI_OPCODE_TXP) + emit_buff(ctx, "%s = %s(%s(vec4(vec4(texture%s(%s, vec4(%s%s.xzw, 0).xwyz %s%s)) * %sshadmask%d + %sshadadd%d)%s));\n", dsts[0], get_string(dinfo->dstconv), get_string(dtypeprefix), tex_ext, srcs[sampler_index], srcs[0], get_wm_string(twm), offbuf, bias, cname, src->Register.Index, cname, src->Register.Index, writemask); + else + emit_buff(ctx, "%s = %s(%s(vec4(vec4(texture%s(%s, vec3(%s%s.xz, 0).xzy %s%s)) * %sshadmask%d + %sshadadd%d)%s));\n", dsts[0], get_string(dinfo->dstconv), get_string(dtypeprefix), tex_ext, srcs[sampler_index], srcs[0], get_wm_string(twm), offbuf, bias, cname, src->Register.Index, cname, src->Register.Index, writemask); + } else if (inst->Texture.Texture == TGSI_TEXTURE_SHADOW1D_ARRAY) { + emit_buff(ctx, "%s = %s(%s(vec4(vec4(texture%s(%s, vec4(%s%s, 0).xwyz %s%s)) * %sshadmask%d + %sshadadd%d)%s));\n", dsts[0], get_string(dinfo->dstconv), get_string(dtypeprefix), tex_ext, srcs[sampler_index], srcs[0], get_wm_string(twm), offbuf, bias, cname, src->Register.Index, cname, src->Register.Index, writemask); + } + } else + emit_buff(ctx, "%s = %s(%s(vec4(vec4(texture%s(%s, %s%s%s%s)) * %sshadmask%d + %sshadadd%d)%s));\n", dsts[0], get_string(dinfo->dstconv), get_string(dtypeprefix), tex_ext, srcs[sampler_index], srcs[0], get_wm_string(twm), offbuf, bias, cname, src->Register.Index, cname, src->Register.Index, writemask); } else { /* OpenGL ES do not support 1D texture * so we use a 2D texture with a parameter set to 0.5 */ - if (ctx->cfg->use_gles && inst->Texture.Texture == TGSI_TEXTURE_1D) { - if (inst->Instruction.Opcode == TGSI_OPCODE_TXP) - emit_buff(ctx, "%s = %s(%s(texture2D(%s, vec2(%s.x / %s.w, 0.5))%s));\n", dsts[0], get_string(dinfo->dstconv), get_string(dtypeprefix), srcs[sampler_index], srcs[0], srcs[0], dinfo->dst_override_no_wm[0] ? "" : writemask); - else - emit_buff(ctx, "%s = %s(%s(texture2D(%s, vec2(%s%s%s%s, 0.5))%s));\n", dsts[0], get_string(dinfo->dstconv), get_string(dtypeprefix), srcs[sampler_index], srcs[0], get_wm_string(twm), offbuf, bias, dinfo->dst_override_no_wm[0] ? "" : writemask); + if (ctx->cfg->use_gles && + (inst->Texture.Texture == TGSI_TEXTURE_1D || + inst->Texture.Texture == TGSI_TEXTURE_1D_ARRAY)) { + if (inst->Texture.Texture == TGSI_TEXTURE_1D) { + if (inst->Instruction.Opcode == TGSI_OPCODE_TXP) + emit_buff(ctx, "%s = %s(%s(texture%s(%s, vec3(%s.xw, 0).xzy %s%s)%s));\n", dsts[0], get_string(dinfo->dstconv), get_string(dtypeprefix), tex_ext, srcs[sampler_index], srcs[0], offbuf, bias, dinfo->dst_override_no_wm[0] ? "" : writemask); + else + emit_buff(ctx, "%s = %s(%s(texture%s(%s, vec2(%s%s, 0.5) %s%s)%s));\n", dsts[0], get_string(dinfo->dstconv), get_string(dtypeprefix), tex_ext, srcs[sampler_index], srcs[0], get_wm_string(twm), + offbuf, bias, dinfo->dst_override_no_wm[0] ? "" : writemask); + } else if (inst->Texture.Texture == TGSI_TEXTURE_1D_ARRAY) { + if (inst->Instruction.Opcode == TGSI_OPCODE_TXP) + emit_buff(ctx, "%s = %s(%s(texture%s(%s, vec3(%s.x / %s.w, 0, %s.y) %s%s)%s));\n", dsts[0], get_string(dinfo->dstconv), get_string(dtypeprefix), tex_ext, srcs[sampler_index], srcs[0], srcs[0], srcs[0], offbuf, bias, dinfo->dst_override_no_wm[0] ? "" : writemask); + else + emit_buff(ctx, "%s = %s(%s(texture%s(%s, vec3(%s%s, 0).xzy %s%s)%s));\n", dsts[0], get_string(dinfo->dstconv), get_string(dtypeprefix), tex_ext, srcs[sampler_index], srcs[0], get_wm_string(twm), + offbuf, bias, dinfo->dst_override_no_wm[0] ? "" : writemask); + } } else { emit_buff(ctx, "%s = %s(%s(texture%s(%s, %s%s%s%s)%s));\n", dsts[0], get_string(dinfo->dstconv), get_string(dtypeprefix), tex_ext, srcs[sampler_index], srcs[0], get_wm_string(twm), offbuf, bias, dinfo->dst_override_no_wm[0] ? "" : writemask); }