summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/glsl/builtin_function.cpp22
-rwxr-xr-xsrc/glsl/builtins/tools/generate_builtins.pl7
2 files changed, 18 insertions, 11 deletions
diff --git a/src/glsl/builtin_function.cpp b/src/glsl/builtin_function.cpp
index 75e058c41c8..fbb2638fc93 100644
--- a/src/glsl/builtin_function.cpp
+++ b/src/glsl/builtin_function.cpp
@@ -4748,6 +4748,10 @@ static const char *functions_for_EXT_texture_array_fs [] = {
builtins_EXT_texture_array_fs_textures,
};
+#ifndef Elements
+#define Elements(x) (sizeof(x)/sizeof(*(x)))
+#endif
+
void
_mesa_glsl_initialize_functions(exec_list *instructions,
struct _mesa_glsl_parse_state *state)
@@ -4755,46 +4759,46 @@ _mesa_glsl_initialize_functions(exec_list *instructions,
if (state->language_version >= 110)
read_builtins(state, instructions,
functions_for_110,
- sizeof(functions_for_110) / sizeof(const char *));
+ Elements(functions_for_110));
if (state->target == fragment_shader && state->language_version >= 110)
read_builtins(state, instructions,
functions_for_110_fs,
- sizeof(functions_for_110_fs) / sizeof(const char *));
+ Elements(functions_for_110_fs));
if (state->target == vertex_shader && state->language_version >= 110)
read_builtins(state, instructions,
functions_for_110_vs,
- sizeof(functions_for_110_vs) / sizeof(const char *));
+ Elements(functions_for_110_vs));
if (state->language_version >= 120)
read_builtins(state, instructions,
functions_for_120,
- sizeof(functions_for_120) / sizeof(const char *));
+ Elements(functions_for_120));
if (state->language_version >= 130)
read_builtins(state, instructions,
functions_for_130,
- sizeof(functions_for_130) / sizeof(const char *));
+ Elements(functions_for_130));
if (state->target == fragment_shader && state->language_version >= 130)
read_builtins(state, instructions,
functions_for_130_fs,
- sizeof(functions_for_130_fs) / sizeof(const char *));
+ Elements(functions_for_130_fs));
if (state->ARB_texture_rectangle_enable)
read_builtins(state, instructions,
functions_for_ARB_texture_rectangle,
- sizeof(functions_for_ARB_texture_rectangle) / sizeof(const char *));
+ Elements(functions_for_ARB_texture_rectangle));
if (state->EXT_texture_array_enable)
read_builtins(state, instructions,
functions_for_EXT_texture_array,
- sizeof(functions_for_EXT_texture_array) / sizeof(const char *));
+ Elements(functions_for_EXT_texture_array));
if (state->target == fragment_shader && state->EXT_texture_array_enable)
read_builtins(state, instructions,
functions_for_EXT_texture_array_fs,
- sizeof(functions_for_EXT_texture_array_fs) / sizeof(const char *));
+ Elements(functions_for_EXT_texture_array_fs));
}
diff --git a/src/glsl/builtins/tools/generate_builtins.pl b/src/glsl/builtins/tools/generate_builtins.pl
index 8b640ab8ff9..a0b5c1f421c 100755
--- a/src/glsl/builtins/tools/generate_builtins.pl
+++ b/src/glsl/builtins/tools/generate_builtins.pl
@@ -91,6 +91,10 @@ foreach $version (@versions) {
}
print << 'EOF';
+#ifndef Elements
+#define Elements(x) (sizeof(x)/sizeof(*(x)))
+#endif
+
void
_mesa_glsl_initialize_functions(exec_list *instructions,
struct _mesa_glsl_parse_state *state)
@@ -116,8 +120,7 @@ foreach $version_xs (@versions) {
print " if ($check)\n";
print " read_builtins(state, instructions,\n";
print " functions_for_$version_xs,\n";
- print " sizeof(functions_for_$version_xs) / ";
- print "sizeof(const char *));\n\n"
+ print " Elements(functions_for_$version_xs));\n\n"
}
print "}\n";