From f1e51b0ea4a7b2b6f02ed95814e0d73d27795d15 Mon Sep 17 00:00:00 2001 From: Tapani Pälli Date: Wed, 3 Sep 2014 13:12:54 +0300 Subject: SQUASH: support double when constructing matrix from scalar MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Patch adds support for both const and non-const cases. Patch makes following Piglit test pass: glsl-double-conversion-constructor-01.shader_test Signed-off-by: Tapani Pälli --- src/glsl/ast_function.cpp | 17 +++++++++++------ src/glsl/ir.cpp | 13 ++++++++++--- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/glsl/ast_function.cpp b/src/glsl/ast_function.cpp index a66d7309447..36ad66691d2 100644 --- a/src/glsl/ast_function.cpp +++ b/src/glsl/ast_function.cpp @@ -1203,16 +1203,21 @@ emit_inline_matrix_constructor(const glsl_type *type, /* Assign the scalar to the X component of a vec4, and fill the remaining * components with zero. */ + glsl_base_type param_base_type = first_param->type->base_type; + assert(param_base_type == GLSL_TYPE_FLOAT || + param_base_type == GLSL_TYPE_DOUBLE); ir_variable *rhs_var = - new(ctx) ir_variable(glsl_type::vec4_type, "mat_ctor_vec", - ir_var_temporary); + new(ctx) ir_variable(glsl_type::get_instance(param_base_type, 4, 1), + "mat_ctor_vec", + ir_var_temporary); instructions->push_tail(rhs_var); ir_constant_data zero; - zero.f[0] = 0.0; - zero.f[1] = 0.0; - zero.f[2] = 0.0; - zero.f[3] = 0.0; + for (unsigned i = 0; i < 4; i++) + if (param_base_type == GLSL_TYPE_FLOAT) + zero.f[i] = 0.0; + else + zero.d[i] = 0.0; ir_instruction *inst = new(ctx) ir_assignment(new(ctx) ir_dereference_variable(rhs_var), diff --git a/src/glsl/ir.cpp b/src/glsl/ir.cpp index 37dbc96cd67..4db7fa9a9f9 100644 --- a/src/glsl/ir.cpp +++ b/src/glsl/ir.cpp @@ -800,9 +800,16 @@ ir_constant::ir_constant(const struct glsl_type *type, exec_list *value_list) if (value->type->is_scalar() && value->next->is_tail_sentinel()) { if (type->is_matrix()) { /* Matrix - fill diagonal (rest is already set to 0) */ - assert(type->base_type == GLSL_TYPE_FLOAT); - for (unsigned i = 0; i < type->matrix_columns; i++) - this->value.f[i * type->vector_elements + i] = value->value.f[0]; + assert(type->base_type == GLSL_TYPE_FLOAT || + type->base_type == GLSL_TYPE_DOUBLE); + for (unsigned i = 0; i < type->matrix_columns; i++) { + if (type->base_type == GLSL_TYPE_FLOAT) + this->value.f[i * type->vector_elements + i] = + value->value.f[0]; + else + this->value.d[i * type->vector_elements + i] = + value->value.d[0]; + } } else { /* Vector or scalar - fill all components */ switch (type->base_type) { -- cgit v1.2.3