[Mesa-dev] [PATCH v2 06/31] glsl: allow to declare bindless samplers/images as non-uniform

Timothy Arceri tarceri at itsqueeze.com
Wed Apr 26 02:13:45 UTC 2017


On 24/04/17 20:35, Samuel Pitoiset wrote:
> The ARB_bindless_texture spec says:
> 
>     "Replace Section 4.1.7 (Samplers), p. 25"
> 
>     "Samplers may be declared as shader inputs and outputs, as uniform
>      variables, as temporary variables, and as function parameters."
> 
>     "Replace Section 4.1.X, (Images)"
> 
>     "Images may be declared as shader inputs and outputs, as uniform
>      variables, as temporary variables, and as function parameters."
> 
> Signed-off-by: Samuel Pitoiset <samuel.pitoiset at gmail.com>
> ---
>   src/compiler/glsl/ast_to_hir.cpp | 67 +++++++++++++++++++++++++++++++++-------
>   1 file changed, 55 insertions(+), 12 deletions(-)
> 
> diff --git a/src/compiler/glsl/ast_to_hir.cpp b/src/compiler/glsl/ast_to_hir.cpp
> index c9772ff83e..85015e140e 100644
> --- a/src/compiler/glsl/ast_to_hir.cpp
> +++ b/src/compiler/glsl/ast_to_hir.cpp
> @@ -3312,11 +3312,26 @@ apply_image_qualifier_to_variable(const struct ast_type_qualifier *qual,
>         return;
>      }
>   
> -   if (var->data.mode != ir_var_uniform &&
> -       var->data.mode != ir_var_function_in) {
> -      _mesa_glsl_error(loc, state, "image variables may only be declared as "
> -                       "function parameters or uniform-qualified "
> -                       "global variables");
> +   if (state->has_bindless()) {
> +      if (var->data.mode != ir_var_auto &&
> +          var->data.mode != ir_var_uniform &&
> +          var->data.mode != ir_var_shader_in &&
> +          var->data.mode != ir_var_shader_out &&
> +          var->data.mode != ir_var_function_in &&
> +          var->data.mode != ir_var_function_out &&
> +          var->data.mode != ir_var_function_inout) {
> +         _mesa_glsl_error(loc, state, "bindless image variables may only be "
> +                          "declared as shader inputs and outputs, as uniform "
> +                          "variables, as temporary variables and as function "
> +                          "parameters");
> +      }
> +   } else {
> +      if (var->data.mode != ir_var_uniform &&
> +          var->data.mode != ir_var_function_in) {
> +         _mesa_glsl_error(loc, state, "image variables may only be declared as "
> +                          "function parameters or uniform-qualified "
> +                          "global variables");
> +      }
>      }
>   

This could be written in slightly less lines:

    if (var->data.mode != ir_var_uniform &&
        var->data.mode != ir_var_function_in) {
       if (state->has_bindless() &&
           var->data.mode != ir_var_auto &&
           var->data.mode != ir_var_shader_in &&
           var->data.mode != ir_var_shader_out &&
           var->data.mode != ir_var_function_out &&
           var->data.mode != ir_var_function_inout) {
          _mesa_glsl_error(loc, state, "bindless image variables may 
only be "
                           "declared as shader inputs and outputs, as 
uniform "
                           "variables, as temporary variables and as 
function "
                           "parameters");
       } else {
          _mesa_glsl_error(loc, state, "image variables may only be 
declared as "
                           "function parameters or uniform-qualified "
                           "global variables");
       }
    }

You could also turn this into a helper that is shared between samplers 
and images.

I can live without the first suggestion. But I'd like to see this as a 
shared helper. With that this is:

Reviewed-by: Timothy Arceri <tarceri at itsqueeze.com>


>      var->data.image_read_only |= qual->flags.q.read_only;
> @@ -3656,11 +3671,26 @@ apply_layout_qualifier_to_variable(const struct ast_type_qualifier *qual,
>      }
>   
>      if (var->type->contains_sampler()) {
> -      if (var->data.mode != ir_var_uniform &&
> -          var->data.mode != ir_var_function_in) {
> -         _mesa_glsl_error(loc, state, "sampler variables may only be declared "
> -                          "as function parameters or uniform-qualified "
> -                          "global variables");
> +      if (state->has_bindless()) {
> +         if (var->data.mode != ir_var_auto &&
> +             var->data.mode != ir_var_uniform &&
> +             var->data.mode != ir_var_shader_in &&
> +             var->data.mode != ir_var_shader_out &&
> +             var->data.mode != ir_var_function_in &&
> +             var->data.mode != ir_var_function_out &&
> +             var->data.mode != ir_var_function_inout) {
> +            _mesa_glsl_error(loc, state, "bindless sampler variables may only "
> +                             "be declared as shader inputs and outputs, as "
> +                             "uniform variables, as temporary variables and as "
> +                             "function parameters");
> +         }
> +      } else {
> +         if (var->data.mode != ir_var_uniform &&
> +             var->data.mode != ir_var_function_in) {
> +            _mesa_glsl_error(loc, state, "sampler variables may only be "
> +                             "declared as function parameters or "
> +                             "uniform-qualified global variables");
> +         }
>         }
>      }
>   
> @@ -5268,9 +5298,22 @@ ast_declarator_list::hir(exec_list *instructions,
>          *
>          *    "[Opaque types] can only be declared as function
>          *     parameters or uniform-qualified variables."
> +       *
> +       * The ARB_bindless_texture spec says:
> +       *
> +       * "Replace Section 4.1.7 (Samplers), p. 25"
> +       *
> +       * "Samplers may be declared as shader inputs and outputs, as uniform
> +       *  variables, as temporary variables, and as function parameters."
> +       *
> +       * "Replace Section 4.1.X, (Images)"
> +       *
> +       * "Images may be declared as shader inputs and outputs, as uniform
> +       *  variables, as temporary variables, and as function parameters."
>          */
> -      if (var_type->contains_opaque() &&
> -          !this->type->qualifier.flags.q.uniform) {
> +      if (!this->type->qualifier.flags.q.uniform &&
> +          (var_type->contains_atomic() ||
> +           (!state->has_bindless() && var_type->contains_opaque()))) {
>            _mesa_glsl_error(&loc, state,
>                             "opaque variables must be declared uniform");
>         }
> 


More information about the mesa-dev mailing list