6 print "/* $version builtins */\n\n";
8 my @files = <builtins
/$version/*>;
9 foreach $file (@files) {
10 push(@vars, process_file
($file));
13 print "static const char *functions_for_$version [] = {\n";
14 foreach $var (@vars) {
23 # Change from builtins/110/foo to builtins_110_foo
24 my $var = $file; $var =~ s!/!_!g;
26 print "static const char *$var = {\n";
27 open SRC
, "<", "$file" or die $!;
40 /* DO NOT MODIFY - automatically generated by generate_builtins.pl */
42 * Copyright ©
2010 Intel Corporation
44 * Permission is hereby granted
, free of charge
, to any person obtaining a
45 * copy of this software
and associated documentation files
(the
"Software"),
46 * to deal
in the Software without restriction
, including without limitation
47 * the rights to
use, copy
, modify
, merge
, publish
, distribute
, sublicense
,
48 * and/or sell copies of the Software
, and to permit persons to whom the
49 * Software is furnished to
do so
, subject to the following conditions
:
51 * The above copyright notice
and this permission notice
(including the
next
52 * paragraph
) shall be included
in all copies
or substantial portions of the
55 * THE SOFTWARE IS PROVIDED
"AS IS", WITHOUT WARRANTY OF ANY KIND
, EXPRESS OR
56 * IMPLIED
, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY
,
57 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
. IN NO EVENT SHALL
58 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM
, DAMAGES OR OTHER
59 * LIABILITY
, WHETHER IN AN ACTION OF CONTRACT
, TORT OR OTHERWISE
, ARISING
60 * FROM
, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
61 * DEALINGS IN THE SOFTWARE
.
65 #include "main/compiler.h"
66 #include "glsl_parser_extras.h"
67 #include "ir_reader.h"
70 extern
"C" struct gl_shader
*
71 _mesa_new_shader
(GLcontext
*ctx
, GLuint name
, GLenum type
);
74 read_builtins
(GLenum target
, const char
**functions
, unsigned count
)
76 gl_shader
*sh
= _mesa_new_shader
(NULL
, 0, target
);
77 struct _mesa_glsl_parse_state
*st
=
78 new
(sh
) _mesa_glsl_parse_state
(NULL
, target
, sh
);
80 st
->language_version = 130;
81 st
->ARB_texture_rectangle_enable = true
;
82 st
->EXT_texture_array_enable = true
;
83 _mesa_glsl_initialize_types
(st
);
85 sh
->ir = new
(sh
) exec_list
;
86 sh
->symbols = st
->symbols;
88 for (unsigned i
= 0; i
< count
; i
++) {
89 _mesa_glsl_read_ir
(st
, sh
->ir, functions
[i
]);
92 printf("error reading builtin: %.35s ...\n", functions
[i
]);
99 reparent_ir
(sh
->ir, sh
);
107 @versions = sort(<builtins
/[1-9A
-Z
]*>);
108 foreach $version (@versions) {
109 $version =~ s!builtins/!!g;
110 process_version
($version);
114 void
*builtin_mem_ctx
= NULL
;
117 _mesa_glsl_release_functions
(void
)
119 talloc_free
(builtin_mem_ctx
);
123 _mesa_glsl_initialize_functions
(exec_list
*instructions
,
124 struct _mesa_glsl_parse_state
*state)
126 if (builtin_mem_ctx
== NULL
)
127 builtin_mem_ctx
= talloc_init
("GLSL built-in functions");
129 state->num_builtins_to_link = 0;
132 foreach $version_xs (@versions) {
134 if ($version_xs =~ /_vs/) {
135 $check = "state->target == vertex_shader && ";
136 } elsif ($version_xs =~ /_fs/) {
137 $check = "state->target == fragment_shader && ";
139 $version = $version_xs;
140 $version =~ s/_[vf]s//g;
142 if ($version =~ /^[1-9][0-9][0-9]/) {
143 $check = "${check}state->language_version >= $version";
145 # Not a version...an extension name
146 $check = "${check}state->${version}_enable";
148 print " if ($check) {\n";
149 print " static gl_shader *sh = NULL;\n";
151 print " if (sh == NULL) {\n";
152 print " sh = read_builtins(GL_VERTEX_SHADER, functions_for_$version_xs,\n";
153 print " Elements(functions_for_$version_xs));\n";
154 print " talloc_steal(builtin_mem_ctx, sh);\n";
157 print " import_prototypes(sh->ir, instructions, state->symbols, state);\n";
158 print " state->builtins_to_link[state->num_builtins_to_link] = sh;\n";
159 print " state->num_builtins_to_link++;\n";