diff options
Diffstat (limited to 'src/glsl/ir_constant_expression.cpp')
-rw-r--r-- | src/glsl/ir_constant_expression.cpp | 36 |
1 files changed, 27 insertions, 9 deletions
diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index 4fd6d09a3a..2a30848965 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -86,7 +86,7 @@ ir_expression::constant_expression_value() components = op[1]->type->components(); } - void *ctx = talloc_parent(this); + void *ctx = ralloc_parent(this); /* Handle array operations here, rather than below. */ if (op[0]->type->is_array()) { @@ -507,6 +507,7 @@ ir_expression::constant_expression_value() break; case ir_binop_div: + /* FINISHME: Emit warning when division-by-zero is detected. */ assert(op[0]->type == op[1]->type || op0_scalar || op1_scalar); for (unsigned c = 0, c0 = 0, c1 = 0; c < components; @@ -514,10 +515,18 @@ ir_expression::constant_expression_value() switch (op[0]->type->base_type) { case GLSL_TYPE_UINT: - data.u[c] = op[0]->value.u[c0] / op[1]->value.u[c1]; + if (op[1]->value.u[c1] == 0) { + data.u[c] = 0; + } else { + data.u[c] = op[0]->value.u[c0] / op[1]->value.u[c1]; + } break; case GLSL_TYPE_INT: - data.i[c] = op[0]->value.i[c0] / op[1]->value.i[c1]; + if (op[1]->value.i[c1] == 0) { + data.i[c] = 0; + } else { + data.i[c] = op[0]->value.i[c0] / op[1]->value.i[c1]; + } break; case GLSL_TYPE_FLOAT: data.f[c] = op[0]->value.f[c0] / op[1]->value.f[c1]; @@ -529,6 +538,7 @@ ir_expression::constant_expression_value() break; case ir_binop_mod: + /* FINISHME: Emit warning when division-by-zero is detected. */ assert(op[0]->type == op[1]->type || op0_scalar || op1_scalar); for (unsigned c = 0, c0 = 0, c1 = 0; c < components; @@ -536,10 +546,18 @@ ir_expression::constant_expression_value() switch (op[0]->type->base_type) { case GLSL_TYPE_UINT: - data.u[c] = op[0]->value.u[c0] % op[1]->value.u[c1]; + if (op[1]->value.u[c1] == 0) { + data.u[c] = 0; + } else { + data.u[c] = op[0]->value.u[c0] % op[1]->value.u[c1]; + } break; case GLSL_TYPE_INT: - data.i[c] = op[0]->value.i[c0] % op[1]->value.i[c1]; + if (op[1]->value.i[c1] == 0) { + data.i[c] = 0; + } else { + data.i[c] = op[0]->value.i[c0] % op[1]->value.i[c1]; + } break; case GLSL_TYPE_FLOAT: /* We don't use fmod because it rounds toward zero; GLSL specifies @@ -845,7 +863,7 @@ ir_swizzle::constant_expression_value() } } - void *ctx = talloc_parent(this); + void *ctx = ralloc_parent(this); return new(ctx) ir_constant(this->type, &data); } return NULL; @@ -868,7 +886,7 @@ ir_dereference_variable::constant_expression_value() if (!var->constant_value) return NULL; - return var->constant_value->clone(talloc_parent(var), NULL); + return var->constant_value->clone(ralloc_parent(var), NULL); } @@ -879,7 +897,7 @@ ir_dereference_array::constant_expression_value() ir_constant *idx = this->array_index->constant_expression_value(); if ((array != NULL) && (idx != NULL)) { - void *ctx = talloc_parent(this); + void *ctx = ralloc_parent(this); if (array->type->is_matrix()) { /* Array access of a matrix results in a vector. */ @@ -984,7 +1002,7 @@ ir_call::constant_expression_value() * - Fill "data" with appopriate constant data * - Return an ir_constant directly. */ - void *mem_ctx = talloc_parent(this); + void *mem_ctx = ralloc_parent(this); ir_expression *expr = NULL; ir_constant_data data; |