r600g: Fix special negative immediate constants when using ABS modifier.

Some constants (like 1.0 and 0.5) could be inlined as immediate inputs
without using their literal value. The r600_bytecode_special_constants()
function emulates the negative of these constants by using NEG modifier.

However some shaders define -1.0 constant and want to use it as 1.0.
They do so by using ABS modifier. But r600_bytecode_special_constants()
set NEG in addition to ABS. Since NEG modifier have priority over ABS one,
we get -|1.0| as result, instead of |1.0|.

The patch simply prevents the additional switching of NEG when ABS is set.

[According to Ivan Kalvachev, this bug was fond via
https://github.com/iXit/Mesa-3D/issues/126 and
https://github.com/iXit/Mesa-3D/issues/127]

Signed-off-by: Ivan Kalvachev <ikalvachev@gmail.com>
Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
CC: <mesa-stable@lists.freedesktop.org>
This commit is contained in:
Ivan Kalvachev
2015-10-25 01:16:58 +03:00
committed by Nicolai Hähnle
parent 24c90888ae
commit f75f21a24a
3 changed files with 6 additions and 6 deletions

View File

@@ -635,7 +635,7 @@ static int replace_gpr_with_pv_ps(struct r600_bytecode *bc,
return 0; return 0;
} }
void r600_bytecode_special_constants(uint32_t value, unsigned *sel, unsigned *neg) void r600_bytecode_special_constants(uint32_t value, unsigned *sel, unsigned *neg, unsigned abs)
{ {
switch(value) { switch(value) {
case 0: case 0:
@@ -655,11 +655,11 @@ void r600_bytecode_special_constants(uint32_t value, unsigned *sel, unsigned *ne
break; break;
case 0xBF800000: /* -1.0f */ case 0xBF800000: /* -1.0f */
*sel = V_SQ_ALU_SRC_1; *sel = V_SQ_ALU_SRC_1;
*neg ^= 1; *neg ^= !abs;
break; break;
case 0xBF000000: /* -0.5f */ case 0xBF000000: /* -0.5f */
*sel = V_SQ_ALU_SRC_0_5; *sel = V_SQ_ALU_SRC_0_5;
*neg ^= 1; *neg ^= !abs;
break; break;
default: default:
*sel = V_SQ_ALU_SRC_LITERAL; *sel = V_SQ_ALU_SRC_LITERAL;
@@ -1208,7 +1208,7 @@ int r600_bytecode_add_alu_type(struct r600_bytecode *bc,
} }
if (nalu->src[i].sel == V_SQ_ALU_SRC_LITERAL) if (nalu->src[i].sel == V_SQ_ALU_SRC_LITERAL)
r600_bytecode_special_constants(nalu->src[i].value, r600_bytecode_special_constants(nalu->src[i].value,
&nalu->src[i].sel, &nalu->src[i].neg); &nalu->src[i].sel, &nalu->src[i].neg, nalu->src[i].abs);
} }
if (nalu->dst.sel >= bc->ngpr) { if (nalu->dst.sel >= bc->ngpr) {
bc->ngpr = nalu->dst.sel + 1; bc->ngpr = nalu->dst.sel + 1;

View File

@@ -255,7 +255,7 @@ int r600_bytecode_add_cfinst(struct r600_bytecode *bc,
int r600_bytecode_add_alu_type(struct r600_bytecode *bc, int r600_bytecode_add_alu_type(struct r600_bytecode *bc,
const struct r600_bytecode_alu *alu, unsigned type); const struct r600_bytecode_alu *alu, unsigned type);
void r600_bytecode_special_constants(uint32_t value, void r600_bytecode_special_constants(uint32_t value,
unsigned *sel, unsigned *neg); unsigned *sel, unsigned *neg, unsigned abs);
void r600_bytecode_disasm(struct r600_bytecode *bc); void r600_bytecode_disasm(struct r600_bytecode *bc);
void r600_bytecode_alu_read(struct r600_bytecode *bc, void r600_bytecode_alu_read(struct r600_bytecode *bc,
struct r600_bytecode_alu *alu, uint32_t word0, uint32_t word1); struct r600_bytecode_alu *alu, uint32_t word0, uint32_t word1);

View File

@@ -1008,7 +1008,7 @@ static void tgsi_src(struct r600_shader_ctx *ctx,
(tgsi_src->Register.SwizzleX == tgsi_src->Register.SwizzleW)) { (tgsi_src->Register.SwizzleX == tgsi_src->Register.SwizzleW)) {
index = tgsi_src->Register.Index * 4 + tgsi_src->Register.SwizzleX; index = tgsi_src->Register.Index * 4 + tgsi_src->Register.SwizzleX;
r600_bytecode_special_constants(ctx->literals[index], &r600_src->sel, &r600_src->neg); r600_bytecode_special_constants(ctx->literals[index], &r600_src->sel, &r600_src->neg, r600_src->abs);
if (r600_src->sel != V_SQ_ALU_SRC_LITERAL) if (r600_src->sel != V_SQ_ALU_SRC_LITERAL)
return; return;
} }