[Mesa-dev] [PATCH 6/8] spirv: Add better parameter validation for vector and matrix types

Jason Ekstrand jason at jlekstrand.net
Mon Dec 11 22:46:17 UTC 2017


On Mon, Dec 11, 2017 at 10:05 AM, Ian Romanick <idr at freedesktop.org> wrote:

> On 12/07/2017 08:12 AM, Jason Ekstrand wrote:
> > ---
> >  src/compiler/spirv/spirv_to_nir.c | 14 +++++++++++---
> >  1 file changed, 11 insertions(+), 3 deletions(-)
> >
> > diff --git a/src/compiler/spirv/spirv_to_nir.c
> b/src/compiler/spirv/spirv_to_nir.c
> > index 11c8c2a..4b93b11 100644
> > --- a/src/compiler/spirv/spirv_to_nir.c
> > +++ b/src/compiler/spirv/spirv_to_nir.c
> > @@ -934,7 +934,11 @@ vtn_handle_type(struct vtn_builder *b, SpvOp opcode,
> >        struct vtn_type *base = vtn_value(b, w[2],
> vtn_value_type_type)->type;
> >        unsigned elems = w[3];
> >
> > -      vtn_assert(glsl_type_is_scalar(base->type));
> > +      vtn_fail_if(base->base_type != vtn_base_type_scalar,
> > +                  "Base type for OpTypeVector must be a scalar");
> > +      vtn_fail_if(elems < 2 || elems > 4,
> > +                  "Invalid component count for OpTypeVector");
> > +
> >        val->type->base_type = vtn_base_type_vector;
> >        val->type->type = glsl_vector_type(glsl_get_base_type(base->type),
> elems);
> >        val->type->length = elems;
> > @@ -947,12 +951,16 @@ vtn_handle_type(struct vtn_builder *b, SpvOp
> opcode,
> >        struct vtn_type *base = vtn_value(b, w[2],
> vtn_value_type_type)->type;
> >        unsigned columns = w[3];
> >
> > -      vtn_assert(glsl_type_is_vector(base->type));
> > +      vtn_fail_if(columns < 2 || columns > 4,
> > +                  "Invalid column count for OpTypeMatrix");
> > +
>
> I think we should still check glsl_type_is_vector here.  The
> glsl_type_is_error check below will catch that case, but we'll give a
> better error message with the explicit check here.
>

Sure.  I'll add something and send a v2.


> >        val->type->base_type = vtn_base_type_matrix;
> >        val->type->type = glsl_matrix_type(glsl_get_
> base_type(base->type),
> >                                           glsl_get_vector_elements(base-
> >type),
> >                                           columns);
> > -      vtn_assert(!glsl_type_is_error(val->type->type));
> > +      vtn_fail_if(glsl_type_is_error(val->type->type),
> > +                  "Unsupported base type for OpTypeMatrix");
> > +      assert(!glsl_type_is_error(val->type->type));
> >        val->type->length = columns;
> >        val->type->array_element = base;
> >        val->type->row_major = false;
> >
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20171211/34acf9be/attachment.html>


More information about the mesa-dev mailing list