From: Caio Oliveira Date: Tue, 12 Sep 2023 20:43:09 +0000 (-0700) Subject: compiler/types: Use a string table for builtin type names X-Git-Tag: upstream/23.3.3~1906 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=edd3cd67c2f69a81fec0595ec1469a71521d6043;p=platform%2Fupstream%2Fmesa.git 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 Part-of: --- diff --git a/src/compiler/builtin_types_c.py b/src/compiler/builtin_types_c.py index cc90228..0386bf5 100644 --- a/src/compiler/builtin_types_c.py +++ b/src/compiler/builtin_types_c.py @@ -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)) diff --git a/src/compiler/glsl_types.h b/src/compiler/glsl_types.h index dfcd0c6..938dc78 100644 --- a/src/compiler/glsl_types.h +++ b/src/compiler/glsl_types.h @@ -304,6 +304,8 @@ struct glsl_type { */ unsigned packed:1; + unsigned has_builtin_name:1; + /** * \name Vector and matrix element counts * diff --git a/src/compiler/nir_types.cpp b/src/compiler/nir_types.cpp index 1f396cb..e167105 100644 --- a/src/compiler/nir_types.cpp +++ b/src/compiler/nir_types.cpp @@ -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