[Mesa-dev] [PATCH 19/23] glsl: Add image built-in function generator.

Kenneth Graunke kenneth at whitecape.org
Thu Dec 12 13:55:50 PST 2013


On 11/26/2013 12:02 AM, Francisco Jerez wrote:
[snip]
> +   add_image_function("imageLoad",
> +                      image_builtin_builder(*this)
> +                      .emit_stub("__intrinsic_image_load")
> +                      .has_return()
> +                      .has_vector_data_type()
> +                      .has_float_data_type()
> +                      .read_only());

I agree with Paul...I'm not a huge fan of using this pattern here.

Using true/false, i.e.
add_image_function("imageLoad", true, true, true, true, false, ...);
is clearly awful.

But what about using a flags bitfield?  Something like:

enum image_function_flags {
   RETURNS_DATA                    = (1 << 0),
   HAS_VECTOR_DATA_TYPE            = (1 << 1),
   SUPPORTS_FLOATING_POINT_IMAGES  = (1 << 2),
   READ_ONLY                       = (1 << 3),
   EMIT_STUB                       = (1 << 4),
};

and then:

void
add_image_function(const char *name,
                   unsigned num_arguments,
                   uint32_t flags);

i.e.
add_image_function("imageLoad", 0,
                   RETURNS_DATA |
                   HAS_VECTOR_DATA_TYPE |
                   SUPPORTS_FLOATING_POINT_IMAGES |
                   READ_ONLY);

That remains readable, like your code, but follows an extremely common
pattern we already use all over the place.

--Ken


More information about the mesa-dev mailing list