[Mesa-dev] [PATCH v2 15/28] glsl: Add ubo lowering support for doubles

Ian Romanick idr at freedesktop.org
Fri Feb 6 00:08:16 PST 2015


On 02/06/2015 06:56 AM, Ilia Mirkin wrote:
> From: Dave Airlie <airlied at gmail.com>
> 
> Signed-off-by: Dave Airlie <airlied at redhat.com>
> Reviewed-by: Matt Turner <mattst88 at gmail.com>
> ---
>  src/glsl/lower_ubo_reference.cpp | 12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)
> 
> diff --git a/src/glsl/lower_ubo_reference.cpp b/src/glsl/lower_ubo_reference.cpp
> index 43dd067..b1eaf62 100644
> --- a/src/glsl/lower_ubo_reference.cpp
> +++ b/src/glsl/lower_ubo_reference.cpp
> @@ -510,16 +510,22 @@ lower_ubo_reference_visitor::emit_ubo_loads(ir_dereference *deref,
>        base_ir->insert_before(assign(deref->clone(mem_ctx, NULL),
>  				    ubo_load(deref->type, offset)));
>     } else {
> +      unsigned N = deref->type->is_double() ? 8 : 4;
> +
>        /* We're dereffing a column out of a row-major matrix, so we
>         * gather the vector from each stored row.
>        */
> -      assert(deref->type->base_type == GLSL_TYPE_FLOAT);
> +      assert(deref->type->base_type == GLSL_TYPE_FLOAT ||
> +             deref->type->base_type == GLSL_TYPE_DOUBLE);
>        /* Matrices, row_major or not, are stored as if they were
>         * arrays of vectors of the appropriate size in std140.
>         * Arrays have their strides rounded up to a vec4, so the
>         * matrix stride is always 16.
>         */

The comment needs to be updated since the matrix stride is now either 16
or 32.

> -      unsigned matrix_stride = 16;
> +      unsigned matrix_stride = 4 * N;

This calculation is wrong.  A dmat2 will end up with a stride of 32 when
it should be 16.

> +
> +      const glsl_type *ubo_type = deref->type->base_type == GLSL_TYPE_FLOAT ?
> +         glsl_type::float_type : glsl_type::double_type;
>  
>        for (unsigned i = 0; i < deref->type->vector_elements; i++) {
>  	 ir_rvalue *chan_offset =
> @@ -527,7 +533,7 @@ lower_ubo_reference_visitor::emit_ubo_loads(ir_dereference *deref,
>  		new(mem_ctx) ir_constant(deref_offset + i * matrix_stride));
>  
>  	 base_ir->insert_before(assign(deref->clone(mem_ctx, NULL),
> -				       ubo_load(glsl_type::float_type,
> +				       ubo_load(ubo_type,
>  						chan_offset),
>  				       (1U << i)));
>        }
> 



More information about the mesa-dev mailing list