[Piglit] [PATCH v2 1/5] arb_uniform_buffer_object: Random test generation infrastructure

Daniel Martin consume.noise at gmail.com
Thu Sep 25 15:28:09 PDT 2014


Hi Ian,

I haven't tested the code, but while scroling through I've found at
least one mistake (the second comment below):

On Thu, Sep 25, 2014 at 01:36:40PM -0700, Ian Romanick wrote:
> From: Ian Romanick <ian.d.romanick at intel.com>
...
> +def vector_base_type(type):
> +    """Return the type of an element from a vector."""
> +    if not isvector(type):
> +        raise Exception("Non-vector type {}".format(type))
> +
> +    if type[0] == 'v':
> +        return "float"
> +    elif type[0] == 'i':
> +        return "int"
> +    elif type[0] == 'u':
> +        return "uint"
> +    elif type[0] == 'b':
> +        return "bool"
> +    elif type[0] == 'd':
> +        return "double"
> +    else:
> +        raise Exception("Unknown vector type {}".format(type))

Imho it would look better if you replace the if/elif/else with a
dictionary lookup:

    type_map = {'v':"float", 'i':"int", ...}

    try:
        return type_map[type[0]]
    except KeyError:
        pass

    raise Exception("Unknown vector type {}".format(type))

...
> +class unique_name_dict:
> +    """Helper class to generate a unique name for each field.
> +
> +    Fields for each particular type have names based on the type.  Each name
> +    is suffixed by a number, and the number is incremented each time a field
> +    of that type is created.  For example, the first int field will be named
> +    "i1", and the second will be named "i2".
> +    """
> +
> +    def __init__(self):
> +        self.names = {}
> +
> +    def trim_name(self, type):
> +        """Internal method to reduce a type name to a canonical form
> +
> +        These names are used to track the type in the self.names dict.
> +
> +        Array types have the arrayness stripped.  Vector types have vector
> +        count stripped.  Matrix types are converted to canonical "mat#x#"
> +        form.  All other type names are unmodified.
> +        """
> +        if isarray(type):
> +            t = array_base_type(type)
> +        else:
> +            t = type
> +
> +        if ismatrix(t):
> +            # Canonicalize matrix type names.
> +            c, r = matrix_dimensions(t)
> +
> +            name = "mat{}x{}".format(c, r)
> +            if t[0] == "d":
> +                name = "d" + name
> +
> +            return name
> +        elif isscalar(t):
> +            return t
> +        elif isvector:

isvector misses a (t) here.

...
> +if __name__ == "__main__":    
...
> +    blocks = generate_block_list(
> +        glsl_version,
> +        packing,
> +        fields,
> +        layouts)
> +
> +    print emit_shader_test(
> +        blocks,
> +        packing,
> +        glsl_version,
> +        extensions)

This print statement doesn't work with python3, but a print() would (as
well as with python2(.6)).


Cheers,
    Daniel Martin


More information about the Piglit mailing list