[Mesa-dev] [PATCH] glsl: reject samplers not declared as uniform/function parameters

Samuel Pitoiset samuel.pitoiset at gmail.com
Fri Feb 24 12:29:09 UTC 2017



On 02/24/2017 12:29 PM, Samuel Pitoiset wrote:
>
>
> On 02/24/2017 12:28 PM, Timothy Arceri wrote:
>>
>>
>> On 24/02/17 21:50, Samuel Pitoiset wrote:
>>> From section 4.1.7 of the GLSL 4.40 spec:
>>>
>>>    "The opaque types declare variables that are effectively opaque
>>>    handles to other objects.  These objects are accessed through
>>>    built-in functions, not through direct reading or writing of
>>>    the declared variable.  They  can only be declared as function
>>>    parameters or in uniform- qualified variables."
>>>
>>> Image variables and atomic counters are already rejected in this
>>> situation.
>>>
>>> Note that opaque variables can't be treated as l-values, which
>>> means only the 'in' function parameter is allowed.
>>>
>>> Signed-off-by: Samuel Pitoiset <samuel.pitoiset at gmail.com>
>>
>> Seems reasonable but can we have a few simple compile piglit tests to go
>> with this?
>
> Sure, I can do that.

Well, not needed to add new tests actually. All situations are already 
covered.

However, the commit message should be slightly improved because opaque 
variables are already rejected. This patch only adds more consistent 
regarding image variables and atomic counters (a similar message is 
displayed for them).

>
>>
>> Reviewed-by: Timothy Arceri <tarceri at itsqueeze.com>
>>
>>> ---
>>>  src/compiler/glsl/ast_to_hir.cpp | 9 +++++++++
>>>  1 file changed, 9 insertions(+)
>>>
>>> diff --git a/src/compiler/glsl/ast_to_hir.cpp
>>> b/src/compiler/glsl/ast_to_hir.cpp
>>> index 22803e89c7..3279149d34 100644
>>> --- a/src/compiler/glsl/ast_to_hir.cpp
>>> +++ b/src/compiler/glsl/ast_to_hir.cpp
>>> @@ -3601,6 +3601,15 @@ 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");
>>> +      }
>>> +   }
>>> +
>>>     /* Is the 'layout' keyword used with parameters that allow relaxed
>>> checking.
>>>      * Many implementations of
>>> GL_ARB_fragment_coord_conventions_enable and some
>>>      * implementations (only Mesa?)
>>> GL_ARB_explicit_attrib_location_enable
>>>


More information about the mesa-dev mailing list