vshader: add support for extended tg4 from arb_gpu_shader5.

This just adds backend conversion support for the extended
texture gather instructions used for arb_gpu_shader5.

Signed-off-by: Dave Airlie <airlied@redhat.com>
macos/master
Dave Airlie 7 years ago
parent 622e1f52ae
commit 192169f8e0
  1. 59
      src/vrend_shader.c

@ -1205,6 +1205,8 @@ static int translate_tex(struct dump_ctx *ctx,
case TGSI_TEXTURE_3D: case TGSI_TEXTURE_3D:
if (inst->Instruction.Opcode == TGSI_OPCODE_TXP) if (inst->Instruction.Opcode == TGSI_OPCODE_TXP)
twm = ""; twm = "";
else if (inst->Instruction.Opcode == TGSI_OPCODE_TG4)
twm = ".xy";
else else
twm = ".xyz"; twm = ".xyz";
txfi = "ivec3"; txfi = "ivec3";
@ -1228,6 +1230,9 @@ static int translate_tex(struct dump_ctx *ctx,
case TGSI_TEXTURE_SHADOWCUBE_ARRAY: case TGSI_TEXTURE_SHADOWCUBE_ARRAY:
case TGSI_TEXTURE_CUBE_ARRAY: case TGSI_TEXTURE_CUBE_ARRAY:
default: default:
if (inst->Instruction.Opcode == TGSI_OPCODE_TG4 && inst->Texture.Texture != TGSI_TEXTURE_CUBE_ARRAY)
twm = ".xyz";
else
twm = ""; twm = "";
txfi = ""; txfi = "";
break; break;
@ -1283,8 +1288,23 @@ static int translate_tex(struct dump_ctx *ctx,
snprintf(bias, 128, ", %s%s, %s%s", srcs[1], gwm, srcs[2], gwm); snprintf(bias, 128, ", %s%s, %s%s", srcs[1], gwm, srcs[2], gwm);
sampler_index = 3; sampler_index = 3;
} else if (inst->Instruction.Opcode == TGSI_OPCODE_TG4) { } else if (inst->Instruction.Opcode == TGSI_OPCODE_TG4) {
sampler_index = 2; sampler_index = 2;
ctx->uses_tg4 = true; ctx->uses_tg4 = true;
if (inst->Texture.NumOffsets > 1 || is_shad)
ctx->uses_gpu_shader5 = true;
if (inst->Texture.NumOffsets == 1) {
if (inst->TexOffsets[0].File != TGSI_FILE_IMMEDIATE)
ctx->uses_gpu_shader5 = true;
}
if (is_shad) {
if (inst->Texture.Texture == TGSI_TEXTURE_SHADOWCUBE ||
inst->Texture.Texture == TGSI_TEXTURE_SHADOW2D_ARRAY ||
inst->Texture.Texture == TGSI_TEXTURE_SHADOWCUBE_ARRAY)
snprintf(bias, 64, ", %s.w", srcs[0]);
else
snprintf(bias, 64, ", %s.z", srcs[0]);
}
} else } else
bias[0] = 0; bias[0] = 0;
@ -1308,7 +1328,9 @@ static int translate_tex(struct dump_ctx *ctx,
else else
tex_ext = "Grad"; tex_ext = "Grad";
} else if (inst->Instruction.Opcode == TGSI_OPCODE_TG4) { } else if (inst->Instruction.Opcode == TGSI_OPCODE_TG4) {
if (inst->Texture.NumOffsets == 1) if (inst->Texture.NumOffsets == 4)
tex_ext = "GatherOffsets";
else if (inst->Texture.NumOffsets == 1)
tex_ext = "GatherOffset"; tex_ext = "GatherOffset";
else else
tex_ext = "Gather"; tex_ext = "Gather";
@ -1324,6 +1346,7 @@ static int translate_tex(struct dump_ctx *ctx,
fprintf(stderr, "Immediate exceeded, max is %lu\n", ARRAY_SIZE(ctx->imm)); fprintf(stderr, "Immediate exceeded, max is %lu\n", ARRAY_SIZE(ctx->imm));
return false; return false;
} }
if (inst->TexOffsets[0].File == TGSI_FILE_IMMEDIATE) {
struct immed *imd = &ctx->imm[inst->TexOffsets[0].Index]; struct immed *imd = &ctx->imm[inst->TexOffsets[0].Index];
switch (inst->Texture.Texture) { switch (inst->Texture.Texture) {
case TGSI_TEXTURE_1D: case TGSI_TEXTURE_1D:
@ -1348,7 +1371,37 @@ static int translate_tex(struct dump_ctx *ctx,
fprintf(stderr, "unhandled texture: %x\n", inst->Texture.Texture); fprintf(stderr, "unhandled texture: %x\n", inst->Texture.Texture);
return false; return false;
} }
} else if (inst->TexOffsets[0].File == TGSI_FILE_TEMPORARY) {
switch (inst->Texture.Texture) {
case TGSI_TEXTURE_1D:
case TGSI_TEXTURE_1D_ARRAY:
case TGSI_TEXTURE_SHADOW1D:
case TGSI_TEXTURE_SHADOW1D_ARRAY:
snprintf(offbuf, 120, ", int(floatBitsToInt(temps[%d].%c))",
inst->TexOffsets[0].Index, get_swiz_char(inst->TexOffsets[0].SwizzleX));
break;
case TGSI_TEXTURE_RECT:
case TGSI_TEXTURE_SHADOWRECT:
case TGSI_TEXTURE_2D:
case TGSI_TEXTURE_2D_ARRAY:
case TGSI_TEXTURE_SHADOW2D:
case TGSI_TEXTURE_SHADOW2D_ARRAY:
snprintf(offbuf, 120, ", ivec2(floatBitsToInt(temps[%d].%c), floatBitsToInt(temps[%d].%c))",
inst->TexOffsets[0].Index, get_swiz_char(inst->TexOffsets[0].SwizzleX),
inst->TexOffsets[0].Index, get_swiz_char(inst->TexOffsets[0].SwizzleY));
break;
case TGSI_TEXTURE_3D:
snprintf(offbuf, 120, ", ivec2(floatBitsToInt(temps[%d].%c), floatBitsToInt(temps[%d].%c), floatBitsToInt(temps[%d].%c)",
inst->TexOffsets[0].Index, get_swiz_char(inst->TexOffsets[0].SwizzleX),
inst->TexOffsets[0].Index, get_swiz_char(inst->TexOffsets[0].SwizzleY),
inst->TexOffsets[0].Index, get_swiz_char(inst->TexOffsets[0].SwizzleZ));
break;
default:
fprintf(stderr, "unhandled texture: %x\n", inst->Texture.Texture);
return false;
break;
}
}
if (inst->Instruction.Opcode == TGSI_OPCODE_TXL || inst->Instruction.Opcode == TGSI_OPCODE_TXL2 || inst->Instruction.Opcode == TGSI_OPCODE_TXD) { if (inst->Instruction.Opcode == TGSI_OPCODE_TXL || inst->Instruction.Opcode == TGSI_OPCODE_TXL2 || inst->Instruction.Opcode == TGSI_OPCODE_TXD) {
char tmp[128]; char tmp[128];
strcpy(tmp, offbuf); strcpy(tmp, offbuf);
@ -1365,7 +1418,7 @@ static int translate_tex(struct dump_ctx *ctx,
snprintf(buf, 255, "%s = texture2DRect(%s, %s.xy)%s;\n", dsts[0], srcs[sampler_index], srcs[0], writemask); snprintf(buf, 255, "%s = texture2DRect(%s, %s.xy)%s;\n", dsts[0], srcs[sampler_index], srcs[0], writemask);
else if (inst->Texture.Texture == TGSI_TEXTURE_SHADOWRECT) else if (inst->Texture.Texture == TGSI_TEXTURE_SHADOWRECT)
snprintf(buf, 255, "%s = shadow2DRect(%s, %s.xyz)%s;\n", dsts[0], srcs[sampler_index], srcs[0], writemask); snprintf(buf, 255, "%s = shadow2DRect(%s, %s.xyz)%s;\n", dsts[0], srcs[sampler_index], srcs[0], writemask);
} else if (is_shad) { /* TGSI returns 1.0 in alpha */ } 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 char *cname = tgsi_proc_to_prefix(ctx->prog_type);
const struct tgsi_full_src_register *src = &inst->Src[sampler_index]; const struct tgsi_full_src_register *src = &inst->Src[sampler_index];
snprintf(buf, 255, "%s = %s(%s(vec4(vec4(texture%s(%s, %s%s%s%s)) * %sshadmask%d + %sshadadd%d)%s));\n", dsts[0], dstconv, dtypeprefix, tex_ext, srcs[sampler_index], srcs[0], twm, offbuf, bias, cname, src->Register.Index, cname, src->Register.Index, writemask); snprintf(buf, 255, "%s = %s(%s(vec4(vec4(texture%s(%s, %s%s%s%s)) * %sshadmask%d + %sshadadd%d)%s));\n", dsts[0], dstconv, dtypeprefix, tex_ext, srcs[sampler_index], srcs[0], twm, offbuf, bias, cname, src->Register.Index, cname, src->Register.Index, writemask);

Loading…
Cancel
Save