[Mesa-dev] [RFC PATCH 22/26] glsl: add ARB_bindless_texture conversions

Nicolai Hähnle nhaehnle at gmail.com
Tue Apr 18 18:10:42 UTC 2017


On 11.04.2017 18:48, Samuel Pitoiset wrote:
> The ARB_bindless_texture spec says:
>
>    "Modify Section 5.4.1, Conversion and Scalar Constructors, p. 60"
>
>     (add the following constructors:)
>
>       // In the following four constructors, the low 32 bits of the sampler
>       // type correspond to the .x component of the uvec2 and the high 32 bits
>       // correspond to the .y component.
>       uvec2(any sampler type)     // Converts a sampler type to a
>                                   //   pair of 32-bit unsigned integers
>       any sampler type(uvec2)     // Converts a pair of 32-bit unsigned integers to
>                                   //   a sampler type
>       uvec2(any image type)       // Converts an image type to a
>                                   //   pair of 32-bit unsigned integers
>       any image type(uvec2)       // Converts a pair of 32-bit unsigned integers to
>                                   //   an image type
>
> Signed-off-by: Samuel Pitoiset <samuel.pitoiset at gmail.com>
> ---
>  src/compiler/glsl/ast_function.cpp | 95 ++++++++++++++++++++++++++++++++------
>  1 file changed, 82 insertions(+), 13 deletions(-)
>
> diff --git a/src/compiler/glsl/ast_function.cpp b/src/compiler/glsl/ast_function.cpp
> index 95ec2db173..8485503e3d 100644
> --- a/src/compiler/glsl/ast_function.cpp
> +++ b/src/compiler/glsl/ast_function.cpp
> @@ -30,7 +30,8 @@
>  #include "builtin_functions.h"
>
>  static ir_rvalue *
> -convert_component(ir_rvalue *src, const glsl_type *desired_type);
> +convert_component(ir_rvalue *src, const glsl_type *desired_type,
> +                  const glsl_type *ctor_type);
>
>  static unsigned
>  process_parameters(exec_list *instructions, exec_list *actual_parameters,
> @@ -405,7 +406,7 @@ fix_parameter(void *mem_ctx, ir_rvalue *actual, const glsl_type *formal_type,
>      */
>     ir_rvalue *rhs = new(mem_ctx) ir_dereference_variable(tmp);
>     if (actual->type != formal_type)
> -      rhs = convert_component(rhs, actual->type);
> +      rhs = convert_component(rhs, actual->type, NULL);
>
>     ir_rvalue *lhs = actual;
>     if (expr != NULL && expr->operation == ir_binop_vector_extract) {
> @@ -452,7 +453,7 @@ generate_call(exec_list *instructions, ir_function_signature *sig,
>           case ir_var_const_in:
>           case ir_var_function_in: {
>              ir_rvalue *converted
> -               = convert_component(actual, formal->type);
> +               = convert_component(actual, formal->type, NULL);
>              actual->replace_with(converted);
>              break;
>           }
> @@ -728,7 +729,8 @@ no_matching_function_error(const char *name,
>   * section (GLSL 1.10 section 5.4.1), not the "Implicit Conversions" rules.
>   */
>  static ir_rvalue *
> -convert_component(ir_rvalue *src, const glsl_type *desired_type)
> +convert_component(ir_rvalue *src, const glsl_type *desired_type,
> +                  const glsl_type *ctor_type)
>  {
>     void *ctx = ralloc_parent(src);
>     const unsigned a = desired_type->base_type;
> @@ -738,8 +740,8 @@ convert_component(ir_rvalue *src, const glsl_type *desired_type)
>     if (src->type->is_error())
>        return src;
>
> -   assert(a <= GLSL_TYPE_BOOL);
> -   assert(b <= GLSL_TYPE_BOOL);
> +   assert(a <= GLSL_TYPE_BINDLESS_IMAGE);
> +   assert(b <= GLSL_TYPE_BINDLESS_IMAGE);
>
>     if (a == b)
>        return src;
> @@ -767,6 +769,12 @@ convert_component(ir_rvalue *src, const glsl_type *desired_type)
>        case GLSL_TYPE_INT64:
>           result = new(ctx) ir_expression(ir_unop_i642u, src);
>           break;
> +      case GLSL_TYPE_BINDLESS_SAMPLER:
> +         result = new(ctx) ir_expression(ir_unop_unpack_sampler_2x32, src);
> +         break;
> +      case GLSL_TYPE_BINDLESS_IMAGE:
> +         result = new(ctx) ir_expression(ir_unop_unpack_image_2x32, src);
> +         break;
>        }
>        break;
>     case GLSL_TYPE_INT:
> @@ -909,6 +917,35 @@ convert_component(ir_rvalue *src, const glsl_type *desired_type)
>           break;
>        }
>        break;
> +   case GLSL_TYPE_BINDLESS_SAMPLER:
> +      switch (b) {
> +      case GLSL_TYPE_UINT:
> +         result = new(ctx) ir_expression(ir_unop_pack_sampler_2x32, src);
> +
> +         assert(ctor_type);
> +         result->type = glsl_type::get_sampler_instance(
> +            (glsl_sampler_dim)ctor_type->sampler_dimensionality,
> +            ctor_type->sampler_shadow,
> +            ctor_type->sampler_array,
> +            (glsl_base_type)ctor_type->sampled_type,
> +            true);
> +         break;
> +      }
> +      break;
> +   case GLSL_TYPE_BINDLESS_IMAGE:
> +      switch (b) {
> +      case GLSL_TYPE_UINT:
> +         result = new(ctx) ir_expression(ir_unop_pack_image_2x32, src);
> +
> +         assert(ctor_type);
> +         result->type = glsl_type::get_image_instance(
> +            (glsl_sampler_dim)ctor_type->sampler_dimensionality,
> +            ctor_type->sampler_array,
> +            (glsl_base_type)ctor_type->sampled_type,
> +            true);
> +         break;
> +      }
> +      break;
>     }
>
>     assert(result != NULL);
> @@ -957,7 +994,7 @@ implicitly_convert_component(ir_rvalue * &from, const glsl_base_type to,
>            * to use it here because we already checked that the implicit
>            * conversion is legal.
>            */
> -         result = convert_component(from, desired_type);
> +         result = convert_component(from, desired_type, NULL);
>        }
>     }
>
> @@ -2036,7 +2073,9 @@ ast_function_expression::hir(exec_list *instructions,
>              return ir_rvalue::error_value(ctx);
>           }
>
> -         if (!result->type->is_numeric() && !result->type->is_boolean()) {
> +         if (!result->type->is_numeric() && !result->type->is_boolean() &&
> +             !result->type->is_bindless_sampler() &&
> +             !result->type->is_bindless_image()) {
>              _mesa_glsl_error(& loc, state, "cannot construct `%s' from a "
>                               "non-numeric data type",
>                               constructor_type->name);
> @@ -2128,11 +2167,41 @@ ast_function_expression::hir(exec_list *instructions,
>
>        /* Type cast each parameter and, if possible, fold constants.*/
>        foreach_in_list_safe(ir_rvalue, ir, &actual_parameters) {
> -         const glsl_type *desired_type =
> -            glsl_type::get_instance(constructor_type->base_type,
> -                                    ir->type->vector_elements,
> -                                    ir->type->matrix_columns);
> -         ir_rvalue *result = convert_component(ir, desired_type);
> +         const glsl_type *desired_type;
> +
> +         if (ir->type->is_bindless_sampler() ||
> +             ir->type->is_bindless_image()) {
> +            /* Convert a sampler/image type to a pair of 32-bit unsigned
> +             * integers as defined by ARB_bindless_texture. */
> +            desired_type = glsl_type::uvec2_type;

Where do you generate type errors for uvec3(sampler_type)? Or other 
incorrect combinations like that.


> +         } else if (constructor_type->is_bindless_sampler() ||
> +                    constructor_type->is_bindless_image()) {
> +            /* Convert a pair of 32-bit unsigned integers to a sampler or image
> +             * type as defined by ARB_bindless_texture. */
> +            if (constructor_type->is_bindless_sampler()) {
> +               desired_type = glsl_type::get_sampler_instance(
> +                     (glsl_sampler_dim)constructor_type->sampler_dimensionality,
> +                     constructor_type->sampler_shadow,
> +                     constructor_type->sampler_array,
> +                     (glsl_base_type)constructor_type->sampled_type,
> +                     true);
> +            } else {
> +               desired_type = glsl_type::get_image_instance(
> +                     (glsl_sampler_dim)constructor_type->sampler_dimensionality,
> +                     constructor_type->sampler_array,
> +                     (glsl_base_type)constructor_type->sampled_type,
> +                     true);
> +
> +            }

And similarly, where's the type check for samplerXXX(uvec3_val) etc.?

Cheers,
Nicolai


> +         } else {
> +            desired_type =
> +               glsl_type::get_instance(constructor_type->base_type,
> +                                       ir->type->vector_elements,
> +                                       ir->type->matrix_columns);
> +         }
> +
> +         ir_rvalue *result = convert_component(ir, desired_type,
> +                                               constructor_type);
>
>           /* Attempt to convert the parameter to a constant valued expression.
>            * After doing so, track whether or not all the parameters to the
>


-- 
Lerne, wie die Welt wirklich ist,
Aber vergiss niemals, wie sie sein sollte.


More information about the mesa-dev mailing list