mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-01 14:38:06 +02:00
compiler/types: Use a string table for builtin type names
This avoids the relocations for each of the builtin type names, allowing all the builtin data to be loaded in read-only memory. Reviewed-by: Adam Jackson <ajax@redhat.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25191>
This commit is contained in:
parent
53149cdd6e
commit
edd3cd67c2
3 changed files with 31 additions and 5 deletions
|
|
@ -17,13 +17,20 @@ template = """\
|
|||
#include "glsl_types.h"
|
||||
#include "util/glheader.h"
|
||||
|
||||
const char glsl_type_builtin_names[] =
|
||||
%for n in NAME_ARRAY:
|
||||
"${n}"
|
||||
%endfor
|
||||
;
|
||||
|
||||
%for t in BUILTIN_TYPES:
|
||||
const struct glsl_type glsl_type_builtin_${t["name"]} = {
|
||||
%for k, v in t.items():
|
||||
%if v is None:
|
||||
%if v is None or k == "name":
|
||||
<% continue %>
|
||||
%elif k == "name":
|
||||
.name_id = (uintptr_t) "${v}",
|
||||
%elif k == "name_id":
|
||||
.name_id = ${v},
|
||||
.has_builtin_name = 1,
|
||||
%else:
|
||||
.${k} = ${v},
|
||||
%endif
|
||||
|
|
@ -38,5 +45,16 @@ if len(sys.argv) < 2:
|
|||
|
||||
output = sys.argv[1]
|
||||
|
||||
# Add padding to make sure zero is an invalid name.
|
||||
invalid = "INVALID"
|
||||
NAME_ARRAY = [invalid + "\\0"]
|
||||
id = len(invalid) + 1
|
||||
|
||||
for t in BUILTIN_TYPES:
|
||||
name = t["name"]
|
||||
NAME_ARRAY.append(name + "\\0")
|
||||
t["name_id"] = id
|
||||
id += len(name) + 1
|
||||
|
||||
with open(output, 'w') as f:
|
||||
f.write(Template(template).render(BUILTIN_TYPES=BUILTIN_TYPES))
|
||||
f.write(Template(template).render(BUILTIN_TYPES=BUILTIN_TYPES, NAME_ARRAY=NAME_ARRAY))
|
||||
|
|
|
|||
|
|
@ -304,6 +304,8 @@ struct glsl_type {
|
|||
*/
|
||||
unsigned packed:1;
|
||||
|
||||
unsigned has_builtin_name:1;
|
||||
|
||||
/**
|
||||
* \name Vector and matrix element counts
|
||||
*
|
||||
|
|
|
|||
|
|
@ -28,10 +28,16 @@
|
|||
#include "nir_types.h"
|
||||
#include "nir_gl_types.h"
|
||||
|
||||
extern "C" const char glsl_type_builtin_names[];
|
||||
|
||||
const char *
|
||||
glsl_get_type_name(const glsl_type *type)
|
||||
{
|
||||
return (const char *)type->name_id;
|
||||
if (type->has_builtin_name) {
|
||||
return &glsl_type_builtin_names[type->name_id];
|
||||
} else {
|
||||
return (const char *) type->name_id;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue