summaryrefslogtreecommitdiffstats
path: root/src/glsl/builtins/tools
diff options
context:
space:
mode:
authorIan Romanick <[email protected]>2010-07-20 11:29:46 -0700
committerIan Romanick <[email protected]>2010-07-21 15:52:58 -0700
commitd5be2acae379783c4aa31243e0a88a9e67e6ca7e (patch)
tree91ebf30796116f1b4d20b6f2fe420a085a59d59e /src/glsl/builtins/tools
parent4ccd3c548b9b9a2fee79342445f68d73525bfcdb (diff)
linker: Link built-in functions instead of including them in every shader
This is an invasive set of changes. Each user shader tracks a set of other shaders that contain built-in functions. During compilation, function prototypes are imported from these shaders. During linking, the shaders are linked with these built-in-function shaders just like with any other shader.
Diffstat (limited to 'src/glsl/builtins/tools')
-rwxr-xr-xsrc/glsl/builtins/tools/generate_builtins.pl63
1 files changed, 52 insertions, 11 deletions
diff --git a/src/glsl/builtins/tools/generate_builtins.pl b/src/glsl/builtins/tools/generate_builtins.pl
index a0b5c1f421c..61d511da1d4 100755
--- a/src/glsl/builtins/tools/generate_builtins.pl
+++ b/src/glsl/builtins/tools/generate_builtins.pl
@@ -64,22 +64,41 @@ print << 'EOF';
#include <stdio.h>
#include "glsl_parser_extras.h"
#include "ir_reader.h"
+#include "program.h"
-void
-read_builtins(_mesa_glsl_parse_state *st, exec_list *instructions,
- const char **functions, unsigned count)
+extern "C" struct gl_shader *
+_mesa_new_shader(GLcontext *ctx, GLuint name, GLenum type);
+
+gl_shader *
+read_builtins(GLenum target, const char **functions, unsigned count)
{
- if (st->error)
- return;
+ gl_shader *sh = _mesa_new_shader(NULL, 0, target);
+ struct _mesa_glsl_parse_state *st =
+ new(sh) _mesa_glsl_parse_state(NULL, target, sh);
+
+ st->language_version = 130;
+ st->ARB_texture_rectangle_enable = true;
+ st->EXT_texture_array_enable = true;
+ _mesa_glsl_initialize_types(st);
+
+ sh->ir = new(sh) exec_list;
+ sh->symbols = st->symbols;
for (unsigned i = 0; i < count; i++) {
- _mesa_glsl_read_ir(st, instructions, functions[i]);
+ _mesa_glsl_read_ir(st, sh->ir, functions[i]);
if (st->error) {
printf("error reading builtin: %.35s ...\n", functions[i]);
- return;
+ delete st;
+ talloc_free(sh);
+ return NULL;
}
}
+
+ reparent_ir(sh->ir, sh);
+ delete st;
+
+ return sh;
}
EOF
@@ -95,10 +114,22 @@ print << 'EOF';
#define Elements(x) (sizeof(x)/sizeof(*(x)))
#endif
+void *builtin_mem_ctx = NULL;
+
+void
+_mesa_glsl_release_functions(void)
+{
+ talloc_free(builtin_mem_ctx);
+}
+
void
_mesa_glsl_initialize_functions(exec_list *instructions,
struct _mesa_glsl_parse_state *state)
{
+ if (builtin_mem_ctx == NULL)
+ builtin_mem_ctx = talloc_init("GLSL built-in functions");
+
+ state->num_builtins_to_link = 0;
EOF
foreach $version_xs (@versions) {
@@ -117,10 +148,20 @@ foreach $version_xs (@versions) {
# Not a version...an extension name
$check = "${check}state->${version}_enable";
}
- print " if ($check)\n";
- print " read_builtins(state, instructions,\n";
- print " functions_for_$version_xs,\n";
- print " Elements(functions_for_$version_xs));\n\n"
+ print " if ($check) {\n";
+ print " static gl_shader *sh = NULL;\n";
+ print "\n";
+ print " if (sh == NULL) {\n";
+ print " sh = read_builtins(GL_VERTEX_SHADER, functions_for_$version_xs,\n";
+ print " Elements(functions_for_$version_xs));\n";
+ print " talloc_steal(builtin_mem_ctx, sh);\n";
+ print " }\n";
+ print "\n";
+ print " import_prototypes(sh->ir, instructions, state->symbols, state);\n";
+ print " state->builtins_to_link[state->num_builtins_to_link] = sh;\n";
+ print " state->num_builtins_to_link++;\n";
+ print " }\n";
+ print "\n";
}
print "}\n";