[virglrenderer-devel] [PATCH 1/4] vrend_shader: add conversion table
Gurchetan Singh
gurchetansingh at chromium.org
Tue May 8 19:06:29 UTC 2018
This associates the conversions / casts with enums. The idea is
to make conversion into a string the last step in the process.
---
src/vrend_shader.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 56 insertions(+)
diff --git a/src/vrend_shader.c b/src/vrend_shader.c
index 9db9800..b5e60cf 100644
--- a/src/vrend_shader.c
+++ b/src/vrend_shader.c
@@ -151,6 +151,62 @@ struct dump_ctx {
bool uses_gpu_shader5;
};
+enum vrend_type_conversion {
+ TYPE_CONVERSION_NONE = 0,
+ FLOAT = 1,
+ VEC2 = 2,
+ VEC3 = 3,
+ VEC4 = 4,
+ INT = 5,
+ IVEC2 = 6,
+ IVEC3 = 7,
+ IVEC4 = 8,
+ UINT = 9,
+ UVEC2 = 10,
+ UVEC3 = 11,
+ UVEC4 = 12,
+ FLOAT_BITS_TO_UINT = 13,
+ UINT_BITS_TO_FLOAT = 14,
+ FLOAT_BITS_TO_INT = 15,
+ INT_BITS_TO_FLOAT = 16,
+};
+
+struct vrend_conversion_table {
+ enum vrend_type_conversion conv;
+ const char *string;
+};
+
+static const struct vrend_conversion_table conversion_table[] =
+{
+ {TYPE_CONVERSION_NONE, ""},
+ {FLOAT, "float"},
+ {VEC2, "vec2"},
+ {VEC3, "vec3"},
+ {VEC4, "vec4"},
+ {INT, "int"},
+ {IVEC2, "ivec2"},
+ {IVEC3, "ivec3"},
+ {IVEC4, "ivec4"},
+ {UINT, "uint"},
+ {UVEC2, "uvec2"},
+ {UVEC3, "uvec3"},
+ {UVEC4, "uvec4"},
+ {FLOAT_BITS_TO_UINT, "floatBitsToUint"},
+ {UINT_BITS_TO_FLOAT, "uintBitsToFloat"},
+ {FLOAT_BITS_TO_INT, "floatBitsToInt"},
+ {INT_BITS_TO_FLOAT, "intBitsToFloat"},
+};
+
+static inline const char *get_string(enum vrend_type_conversion conv)
+{
+ if (conv >= ARRAY_SIZE(conversion_table)) {
+ printf("Unable to find the correct conversion\n");
+ return conversion_table[TYPE_CONVERSION_NONE].string;
+ }
+
+ return conversion_table[conv].string;
+}
+
static inline const char *tgsi_proc_to_prefix(int shader_type)
{
switch (shader_type) {
--
2.17.0.441.gb46fe60e1d-goog
More information about the virglrenderer-devel
mailing list