[Mesa-dev] [PATCH] nir: Only float and double types can be matrices

Jason Ekstrand jason at jlekstrand.net
Wed Dec 7 01:56:13 UTC 2016


Reviewed-by: Jason Ekstrand <jason at jlekstrand.net>

Might be worth adding something to nir_validate at some point.  Doesn't
have to be today though.

--Jason

On Tue, Dec 6, 2016 at 5:32 PM, Ian Romanick <idr at freedesktop.org> wrote:

> From: Ian Romanick <ian.d.romanick at intel.com>
>
> In 19a541f (nir: Get rid of nir_constant_data) a number of places that
> operated on nir_constant::values were mechanically converted to operate
> on the whole array without regard for the base type.  Only
> GLSL_TYPE_FLOAT and GLSL_TYPE_DOUBLE can be matrices, so only those
> types can have data in the non-0 array element.
>
> See also b870394.
>
> Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
> Cc: Jason Ekstrand <jason.ekstrand at intel.com>
> Cc: Iago Toral Quiroga <itoral at igalia.com>
> ---
>  src/compiler/glsl/glsl_to_nir.cpp | 32 ++++++++++++++++++--------------
>  src/compiler/nir/nir_print.c      | 11 ++++++-----
>  2 files changed, 24 insertions(+), 19 deletions(-)
>
> diff --git a/src/compiler/glsl/glsl_to_nir.cpp
> b/src/compiler/glsl/glsl_to_nir.cpp
> index 4debc37..18a53b6 100644
> --- a/src/compiler/glsl/glsl_to_nir.cpp
> +++ b/src/compiler/glsl/glsl_to_nir.cpp
> @@ -207,17 +207,21 @@ constant_copy(ir_constant *ir, void *mem_ctx)
>     ret->num_elements = 0;
>     switch (ir->type->base_type) {
>     case GLSL_TYPE_UINT:
> -      for (unsigned c = 0; c < cols; c++) {
> -         for (unsigned r = 0; r < rows; r++)
> -            ret->values[c].u32[r] = ir->value.u[c * rows + r];
> -      }
> +      /* Only float base types can be matrices. */
> +      assert(cols == 1);
> +
> +      for (unsigned r = 0; r < rows; r++)
> +         ret->values[0].u32[r] = ir->value.u[r];
> +
>        break;
>
>     case GLSL_TYPE_INT:
> -      for (unsigned c = 0; c < cols; c++) {
> -         for (unsigned r = 0; r < rows; r++)
> -            ret->values[c].i32[r] = ir->value.i[c * rows + r];
> -      }
> +      /* Only float base types can be matrices. */
> +      assert(cols == 1);
> +
> +      for (unsigned r = 0; r < rows; r++)
> +         ret->values[0].i32[r] = ir->value.i[r];
> +
>        break;
>
>     case GLSL_TYPE_FLOAT:
> @@ -235,12 +239,12 @@ constant_copy(ir_constant *ir, void *mem_ctx)
>        break;
>
>     case GLSL_TYPE_BOOL:
> -      for (unsigned c = 0; c < cols; c++) {
> -         for (unsigned r = 0; r < rows; r++) {
> -            ret->values[c].u32[r] = ir->value.b[c * rows + r] ?
> -                                    NIR_TRUE : NIR_FALSE;
> -         }
> -      }
> +      /* Only float base types can be matrices. */
> +      assert(cols == 1);
> +
> +      for (unsigned r = 0; r < rows; r++)
> +         ret->values[0].u32[r] = ir->value.b[r] ? NIR_TRUE : NIR_FALSE;
> +
>        break;
>
>     case GLSL_TYPE_STRUCT:
> diff --git a/src/compiler/nir/nir_print.c b/src/compiler/nir/nir_print.c
> index eb5f57f..e51b6f5 100644
> --- a/src/compiler/nir/nir_print.c
> +++ b/src/compiler/nir/nir_print.c
> @@ -303,11 +303,12 @@ print_constant(nir_constant *c, const struct
> glsl_type *type, print_state *state
>     case GLSL_TYPE_UINT:
>     case GLSL_TYPE_INT:
>     case GLSL_TYPE_BOOL:
> -      for (i = 0; i < cols; i++) {
> -         for (j = 0; j < rows; j++) {
> -            if (i + j > 0) fprintf(fp, ", ");
> -            fprintf(fp, "0x%08x", c->values[i].u32[j]);
> -         }
> +      /* Only float base types can be matrices. */
> +      assert(cols == 1);
> +
> +      for (i = 0; i < rows; i++) {
> +         if (i > 0) fprintf(fp, ", ");
> +         fprintf(fp, "0x%08x", c->values[0].u32[i]);
>        }
>        break;
>
> --
> 2.7.4
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20161206/6bdbbc84/attachment.html>


More information about the mesa-dev mailing list