i965: Fix SIN/COS precision problems.

Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
This commit is contained in:
Kenneth Graunke 2016-01-27 12:21:04 -08:00
parent b833e7a63c
commit 4acfc9effb
2 changed files with 40 additions and 12 deletions

View File

@ -715,15 +715,29 @@ fs_visitor::nir_emit_alu(const fs_builder &bld, nir_alu_instr *instr)
inst->saturate = instr->dest.saturate;
break;
case nir_op_fsin:
inst = bld.emit(SHADER_OPCODE_SIN, result, op[0]);
inst->saturate = instr->dest.saturate;
case nir_op_fsin: {
fs_reg tmp = bld.vgrf(BRW_REGISTER_TYPE_F);
inst = bld.emit(SHADER_OPCODE_SIN, tmp, op[0]);
if (instr->dest.saturate) {
inst->dst = result;
inst->saturate = true;
} else {
bld.MUL(result, tmp, brw_imm_f(0.99997));
}
break;
}
case nir_op_fcos:
inst = bld.emit(SHADER_OPCODE_COS, result, op[0]);
inst->saturate = instr->dest.saturate;
case nir_op_fcos: {
fs_reg tmp = bld.vgrf(BRW_REGISTER_TYPE_F);
inst = bld.emit(SHADER_OPCODE_COS, tmp, op[0]);
if (instr->dest.saturate) {
inst->dst = result;
inst->saturate = true;
} else {
bld.MUL(result, tmp, brw_imm_f(0.99997));
}
break;
}
case nir_op_fddx:
if (fs_key->high_quality_derivatives) {

View File

@ -1086,15 +1086,29 @@ vec4_visitor::nir_emit_alu(nir_alu_instr *instr)
inst->saturate = instr->dest.saturate;
break;
case nir_op_fsin:
inst = emit_math(SHADER_OPCODE_SIN, dst, op[0]);
inst->saturate = instr->dest.saturate;
case nir_op_fsin: {
src_reg tmp = src_reg(this, glsl_type::vec4_type);
inst = emit_math(SHADER_OPCODE_SIN, dst_reg(tmp), op[0]);
if (instr->dest.saturate) {
inst->dst = dst;
inst->saturate = true;
} else {
emit(MUL(dst, tmp, brw_imm_f(0.99997)));
}
break;
}
case nir_op_fcos:
inst = emit_math(SHADER_OPCODE_COS, dst, op[0]);
inst->saturate = instr->dest.saturate;
case nir_op_fcos: {
src_reg tmp = src_reg(this, glsl_type::vec4_type);
inst = emit_math(SHADER_OPCODE_COS, dst_reg(tmp), op[0]);
if (instr->dest.saturate) {
inst->dst = dst;
inst->saturate = true;
} else {
emit(MUL(dst, tmp, brw_imm_f(0.99997)));
}
break;
}
case nir_op_idiv:
case nir_op_udiv: