nir/lower_double_ops: lower fract()

At least i965 hardware does not have native support for fract() on doubles.

Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
This commit is contained in:
Iago Toral Quiroga
2016-01-05 09:14:51 +01:00
committed by Samuel Iglesias Gonsálvez
parent 126a1ac03f
commit bf91df7f7f
2 changed files with 15 additions and 0 deletions

View File

@@ -2420,6 +2420,7 @@ typedef enum {
nir_lower_dtrunc = (1 << 3), nir_lower_dtrunc = (1 << 3),
nir_lower_dfloor = (1 << 4), nir_lower_dfloor = (1 << 4),
nir_lower_dceil = (1 << 5), nir_lower_dceil = (1 << 5),
nir_lower_dfract = (1 << 6)
} nir_lower_doubles_options; } nir_lower_doubles_options;
void nir_lower_doubles(nir_shader *shader, nir_lower_doubles_options options); void nir_lower_doubles(nir_shader *shader, nir_lower_doubles_options options);

View File

@@ -383,6 +383,12 @@ lower_ceil(nir_builder *b, nir_ssa_def *src)
nir_fadd(b, tr, nir_imm_double(b, 1.0))); nir_fadd(b, tr, nir_imm_double(b, 1.0)));
} }
static nir_ssa_def *
lower_fract(nir_builder *b, nir_ssa_def *src)
{
return nir_fsub(b, src, nir_ffloor(b, src));
}
static void static void
lower_doubles_instr(nir_alu_instr *instr, nir_lower_doubles_options options) lower_doubles_instr(nir_alu_instr *instr, nir_lower_doubles_options options)
{ {
@@ -421,6 +427,11 @@ lower_doubles_instr(nir_alu_instr *instr, nir_lower_doubles_options options)
return; return;
break; break;
case nir_op_ffract:
if (!(options & nir_lower_dfract))
return;
break;
default: default:
return; return;
} }
@@ -453,6 +464,9 @@ lower_doubles_instr(nir_alu_instr *instr, nir_lower_doubles_options options)
case nir_op_fceil: case nir_op_fceil:
result = lower_ceil(&bld, src); result = lower_ceil(&bld, src);
break; break;
case nir_op_ffract:
result = lower_fract(&bld, src);
break;
default: default:
unreachable("unhandled opcode"); unreachable("unhandled opcode");
} }