brw_fs_alloc_reg_sets(compiler);
brw_vec4_alloc_reg_set(compiler);
+ compiler->precise_trig = env_var_as_boolean("INTEL_PRECISE_TRIG", false);
+
compiler->scalar_stage[MESA_SHADER_VERTEX] =
devinfo->gen >= 8 && !(INTEL_DEBUG & DEBUG_VEC4VS);
compiler->scalar_stage[MESA_SHADER_TESS_CTRL] = false;
bool scalar_stage[MESA_SHADER_STAGES];
struct gl_shader_compiler_options glsl_compiler_options[MESA_SHADER_STAGES];
+
+ /**
+ * Apply workarounds for SIN and COS output range problems.
+ * This can negatively impact performance.
+ */
+ bool precise_trig;
};
break;
case nir_op_fsin:
- inst = bld.emit(SHADER_OPCODE_SIN, result, op[0]);
+ if (!compiler->precise_trig) {
+ inst = bld.emit(SHADER_OPCODE_SIN, result, op[0]);
+ } else {
+ fs_reg tmp = bld.vgrf(BRW_REGISTER_TYPE_F);
+ inst = bld.emit(SHADER_OPCODE_SIN, tmp, op[0]);
+ inst = bld.MUL(result, tmp, brw_imm_f(0.99997));
+ }
inst->saturate = instr->dest.saturate;
break;
case nir_op_fcos:
- inst = bld.emit(SHADER_OPCODE_COS, result, op[0]);
+ if (!compiler->precise_trig) {
+ inst = bld.emit(SHADER_OPCODE_COS, result, op[0]);
+ } else {
+ fs_reg tmp = bld.vgrf(BRW_REGISTER_TYPE_F);
+ inst = bld.emit(SHADER_OPCODE_COS, tmp, op[0]);
+ inst = bld.MUL(result, tmp, brw_imm_f(0.99997));
+ }
inst->saturate = instr->dest.saturate;
break;
break;
case nir_op_fsin:
- inst = emit_math(SHADER_OPCODE_SIN, dst, op[0]);
+ if (!compiler->precise_trig) {
+ inst = emit_math(SHADER_OPCODE_SIN, dst, op[0]);
+ } else {
+ src_reg tmp = src_reg(this, glsl_type::vec4_type);
+ inst = emit_math(SHADER_OPCODE_SIN, dst_reg(tmp), op[0]);
+ inst = emit(MUL(dst, tmp, brw_imm_f(0.99997)));
+ }
inst->saturate = instr->dest.saturate;
break;
case nir_op_fcos:
- inst = emit_math(SHADER_OPCODE_COS, dst, op[0]);
+ if (!compiler->precise_trig) {
+ inst = emit_math(SHADER_OPCODE_COS, dst, op[0]);
+ } else {
+ src_reg tmp = src_reg(this, glsl_type::vec4_type);
+ inst = emit_math(SHADER_OPCODE_COS, dst_reg(tmp), op[0]);
+ inst = emit(MUL(dst, tmp, brw_imm_f(0.99997)));
+ }
inst->saturate = instr->dest.saturate;
break;