diff options
author | Timothy Arceri <timothy.arceri@collabora.com> | 2015-12-01 10:34:18 +1100 |
---|---|---|
committer | Timothy Arceri <timothy.arceri@collabora.com> | 2015-12-15 13:10:44 +1100 |
commit | 0aeb9b3e5eab57ae5d96047cee7b2c58811b455b (patch) | |
tree | 92d2368f2f6e7122cd6ec95aa4fa6167f5eb3b32 /src/glsl/link_interface_blocks.cpp | |
parent | 183c606066b1b260acb189e46a40cb71e63b44aa (diff) |
glsl: add support for explicit locations inside interface blocks
This change also adds explicit location support for structs and interfaces which
is currently missing in Mesa but is allowed with SSO and GLSL 1.50+.
Reviewed-by: Edward O'Callaghan <eocallaghan@alterapraxis.com>
Diffstat (limited to 'src/glsl/link_interface_blocks.cpp')
-rw-r--r-- | src/glsl/link_interface_blocks.cpp | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/src/glsl/link_interface_blocks.cpp b/src/glsl/link_interface_blocks.cpp index 61ba0785d63..64c30fea9a3 100644 --- a/src/glsl/link_interface_blocks.cpp +++ b/src/glsl/link_interface_blocks.cpp @@ -166,9 +166,19 @@ public: */ ir_variable *lookup(ir_variable *var) { - const struct hash_entry *entry = - _mesa_hash_table_search(ht, var->get_interface_type()->name); - return entry ? (ir_variable *) entry->data : NULL; + if (var->data.explicit_location && + var->data.location >= VARYING_SLOT_VAR0) { + char location_str[11]; + snprintf(location_str, 11, "%d", var->data.location); + + const struct hash_entry *entry = + _mesa_hash_table_search(ht, location_str); + return entry ? (ir_variable *) entry->data : NULL; + } else { + const struct hash_entry *entry = + _mesa_hash_table_search(ht, var->get_interface_type()->name); + return entry ? (ir_variable *) entry->data : NULL; + } } /** @@ -176,7 +186,19 @@ public: */ void store(ir_variable *var) { - _mesa_hash_table_insert(ht, var->get_interface_type()->name, var); + if (var->data.explicit_location && + var->data.location >= VARYING_SLOT_VAR0) { + /* If explicit location is given then lookup the variable by location. + * We turn the location into a string and use this as the hash key + * rather than the name. Note: We allocate enough space for a 32-bit + * unsigned location value which is overkill but future proof. + */ + char location_str[11]; + snprintf(location_str, 11, "%d", var->data.location); + _mesa_hash_table_insert(ht, ralloc_strdup(mem_ctx, location_str), var); + } else { + _mesa_hash_table_insert(ht, var->get_interface_type()->name, var); + } } private: |