glsl2: Add ir_unop_fract as an expression type.

Most backends will prefer seeing this to seeing (a - floor(a)), so
represent it explicitly.
This commit is contained in:
Eric Anholt
2010-07-01 10:37:11 -07:00
parent 5e4dd061d1
commit d925c91730
6 changed files with 33 additions and 8 deletions

View File

@@ -781,22 +781,22 @@ static const char *builtins_110_fract = {
" (signature float\n"
" (parameters\n"
" (declare (in) float x))\n"
" ((return (expression float - (var_ref x) (expression float floor (var_ref x))))))\n"
" ((return (expression float fract (var_ref x)))))\n"
"\n"
" (signature vec2\n"
" (parameters\n"
" (declare (in) vec2 x))\n"
" ((return (expression vec2 - (var_ref x) (expression vec2 floor (var_ref x))))))\n"
" ((return (expression vec2 fract (var_ref x)))))\n"
"\n"
" (signature vec3\n"
" (parameters\n"
" (declare (in) vec3 x))\n"
" ((return (expression vec3 - (var_ref x) (expression vec3 floor (var_ref x))))))\n"
" ((return (expression vec3 fract (var_ref x)))))\n"
"\n"
" (signature vec4\n"
" (parameters\n"
" (declare (in) vec4 x))\n"
" ((return (expression vec4 - (var_ref x) (expression vec4 floor (var_ref x))))))\n"
" ((return (expression vec4 fract (var_ref x)))))\n"
"))\n"
"\n"
};

View File

@@ -2,21 +2,21 @@
(signature float
(parameters
(declare (in) float x))
((return (expression float - (var_ref x) (expression float floor (var_ref x))))))
((return (expression float fract (var_ref x)))))
(signature vec2
(parameters
(declare (in) vec2 x))
((return (expression vec2 - (var_ref x) (expression vec2 floor (var_ref x))))))
((return (expression vec2 fract (var_ref x)))))
(signature vec3
(parameters
(declare (in) vec3 x))
((return (expression vec3 - (var_ref x) (expression vec3 floor (var_ref x))))))
((return (expression vec3 fract (var_ref x)))))
(signature vec4
(parameters
(declare (in) vec4 x))
((return (expression vec4 - (var_ref x) (expression vec4 floor (var_ref x))))))
((return (expression vec4 fract (var_ref x)))))
))

View File

@@ -72,6 +72,7 @@ ir_expression::get_num_operands(ir_expression_operation op)
1, /* ir_unop_trunc */
1, /* ir_unop_ceil */
1, /* ir_unop_floor */
1, /* ir_unop_fract */
1, /* ir_unop_sin */
1, /* ir_unop_cos */
@@ -137,6 +138,7 @@ static const char *const operator_strs[] = {
"trunc",
"ceil",
"floor",
"fract",
"sin",
"cos",
"dFdx",

View File

@@ -528,6 +528,7 @@ enum ir_expression_operation {
ir_unop_trunc,
ir_unop_ceil,
ir_unop_floor,
ir_unop_fract,
/*@}*/
/**

View File

@@ -187,6 +187,24 @@ ir_constant_visitor::visit(ir_expression *ir)
}
break;
case ir_unop_fract:
for (c = 0; c < ir->operands[0]->type->components(); c++) {
switch (ir->type->base_type) {
case GLSL_TYPE_UINT:
data.u[c] = 0;
break;
case GLSL_TYPE_INT:
data.i[c] = 0;
break;
case GLSL_TYPE_FLOAT:
data.f[c] = op[0]->value.f[c] - floor(op[0]->value.f[c]);
break;
default:
assert(0);
}
}
break;
case ir_unop_neg:
for (c = 0; c < ir->operands[0]->type->components(); c++) {
switch (ir->type->base_type) {

View File

@@ -782,6 +782,10 @@ ir_to_mesa_visitor::visit(ir_expression *ir)
case ir_unop_floor:
ir_to_mesa_emit_op1(ir, OPCODE_FLR, result_dst, op[0]);
break;
case ir_unop_fract:
ir_to_mesa_emit_op1(ir, OPCODE_FRC, result_dst, op[0]);
break;
case ir_binop_min:
ir_to_mesa_emit_op2(ir, OPCODE_MIN, result_dst, op[0], op[1]);
break;