[Mesa-dev] [PATCH 2/2] glsl: update default precision qualifiers when they are set in the shader

Samuel Iglesias Gonsálvez siglesias at igalia.com
Fri Oct 21 06:17:43 UTC 2016



On 21/10/16 07:48, Timothy Arceri wrote:
> On Thu, 2016-10-20 at 12:39 +0200, Samuel Iglesias Gonsálvez wrote:
>> For that, we use gls_symbol_table::set_default_precision_qualifier()
>> that
>> can update an existing definition or add a new one if it doesn't
>> exist.
>>
>> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=97804
>> Signed-off-by: Samuel Iglesias Gonsálvez <siglesias at igalia.com>
> 
> Hi Samuel,
> 
> It looks like the parser pushes and pops scope of the symbol table so
> these changes should work. However it would be nice to see some piglit
> tests for this before landing these patches.
> 

Sure, I will write them.

>> ---
>>  src/compiler/glsl/ast_to_hir.cpp        |  2 +-
>>  src/compiler/glsl/glsl_symbol_table.cpp | 15 +++++++++++++++
>>  src/compiler/glsl/glsl_symbol_table.h   |  2 ++
>>  3 files changed, 18 insertions(+), 1 deletion(-)
>>
>> diff --git a/src/compiler/glsl/ast_to_hir.cpp
>> b/src/compiler/glsl/ast_to_hir.cpp
>> index 6e2f253..cc50ff8 100644
>> --- a/src/compiler/glsl/ast_to_hir.cpp
>> +++ b/src/compiler/glsl/ast_to_hir.cpp
>> @@ -6559,7 +6559,7 @@ ast_type_specifier::hir(exec_list
>> *instructions,
>>            * is a slight abuse of the symbol table, but it has the
>> semantics
>>            * that we want.
>>            */
>> -         state->symbols->add_default_precision_qualifier(this-
>>> type_name,
>> +         state->symbols->set_default_precision_qualifier(this-
>>> type_name,
>>                                                           this-
>>> default_precision);
>>        }
>>  
>> diff --git a/src/compiler/glsl/glsl_symbol_table.cpp
>> b/src/compiler/glsl/glsl_symbol_table.cpp
>> index 6d7baad..11e5c00 100644
>> --- a/src/compiler/glsl/glsl_symbol_table.cpp
>> +++ b/src/compiler/glsl/glsl_symbol_table.cpp
>> @@ -258,6 +258,21 @@ int
>> glsl_symbol_table::get_default_precision_qualifier(const char
>> *type_name)
>>     return entry->a->default_precision;
>>  }
>>  
>> +bool glsl_symbol_table::set_default_precision_qualifier(const char
>> *type_name,
>> +                                                        int
>> precision)
>> +{
>> +   char *name = ralloc_asprintf(mem_ctx, "#default_precision_%s",
>> type_name);
>> +   symbol_table_entry *entry = get_entry(name);
>> +   if (!entry)
>> +      return add_default_precision_qualifier(type_name, precision);
> 
> I think I would rather just see this completely
> replace add_default_precision_qualifier() rather than duplicating a
> bunch of code. What do you think? I don't think avoiding
> the get_entry() call saves us much.
> 

Right, I though that too. I will write a v2 with that change.

Thanks,

Sam

>> +
>> +   ast_type_specifier *default_specifier = new(mem_ctx)
>> ast_type_specifier(name);
>> +   default_specifier->default_precision = precision;
>> +
>> +   entry = new(mem_ctx) symbol_table_entry(default_specifier);
>> +   return _mesa_symbol_table_replace_symbol(table, -1, name, entry)
>> == 0;
>> +}
>> +
>>  symbol_table_entry *glsl_symbol_table::get_entry(const char *name)
>>  {
>>     return (symbol_table_entry *)
>> diff --git a/src/compiler/glsl/glsl_symbol_table.h
>> b/src/compiler/glsl/glsl_symbol_table.h
>> index 2f94d4c..69a6912 100644
>> --- a/src/compiler/glsl/glsl_symbol_table.h
>> +++ b/src/compiler/glsl/glsl_symbol_table.h
>> @@ -90,6 +90,8 @@ struct glsl_symbol_table {
>>     const glsl_type *get_interface(const char *name,
>>                                    enum ir_variable_mode mode);
>>     int get_default_precision_qualifier(const char *type_name);
>> +   bool set_default_precision_qualifier(const char *type_name, int
>> precision);
>> +
>>     /*@}*/
>>  
>>     /**
> 

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20161021/22abe442/attachment-0001.sig>


More information about the mesa-dev mailing list