2 * Copyright © 2008, 2009 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
25 /** @file standalone.cpp
27 * Standalone compiler helper lib. Used by standalone glsl_compiler and
28 * also available to drivers to implement their own standalone compiler
29 * with driver backend.
33 #include "glsl_parser_extras.h"
34 #include "ir_optimization.h"
36 #include "loop_analysis.h"
37 #include "standalone_scaffolding.h"
38 #include "standalone.h"
39 #include "util/string_to_uint_map.h"
42 #include "glsl_parser_extras.h"
43 #include "ir_builder_print_visitor.h"
44 #include "builtin_functions.h"
45 #include "opt_add_neg_to_sub.h"
47 class dead_variable_visitor
: public ir_hierarchical_visitor
{
49 dead_variable_visitor()
51 variables
= _mesa_set_create(NULL
,
53 _mesa_key_pointer_equal
);
56 virtual ~dead_variable_visitor()
58 _mesa_set_destroy(variables
, NULL
);
61 virtual ir_visitor_status
visit(ir_variable
*ir
)
63 /* If the variable is auto or temp, add it to the set of variables that
64 * are candidates for removal.
66 if (ir
->data
.mode
!= ir_var_auto
&& ir
->data
.mode
!= ir_var_temporary
)
67 return visit_continue
;
69 _mesa_set_add(variables
, ir
);
71 return visit_continue
;
74 virtual ir_visitor_status
visit(ir_dereference_variable
*ir
)
76 struct set_entry
*entry
= _mesa_set_search(variables
, ir
->var
);
78 /* If a variable is dereferenced at all, remove it from the set of
79 * variables that are candidates for removal.
82 _mesa_set_remove(variables
, entry
);
84 return visit_continue
;
87 void remove_dead_variables()
89 struct set_entry
*entry
;
91 set_foreach(variables
, entry
) {
92 ir_variable
*ir
= (ir_variable
*) entry
->key
;
94 assert(ir
->ir_type
== ir_type_variable
);
104 init_gl_program(struct gl_program
*prog
, GLenum target
, bool is_arb_asm
)
107 prog
->Format
= GL_PROGRAM_FORMAT_ASCII_ARB
;
108 prog
->is_arb_asm
= is_arb_asm
;
112 new_program(struct gl_context
*ctx
, GLenum target
, GLuint id
, bool is_arb_asm
)
115 case GL_VERTEX_PROGRAM_ARB
: /* == GL_VERTEX_PROGRAM_NV */
116 case GL_GEOMETRY_PROGRAM_NV
:
117 case GL_TESS_CONTROL_PROGRAM_NV
:
118 case GL_TESS_EVALUATION_PROGRAM_NV
:
119 case GL_FRAGMENT_PROGRAM_ARB
:
120 case GL_COMPUTE_PROGRAM_NV
: {
121 struct gl_program
*prog
= rzalloc(NULL
, struct gl_program
);
122 init_gl_program(prog
, target
, is_arb_asm
);
126 printf("bad target in new_program\n");
131 static const struct standalone_options
*options
;
134 initialize_context(struct gl_context
*ctx
, gl_api api
)
136 initialize_context_to_defaults(ctx
, api
);
138 /* The standalone compiler needs to claim support for almost
139 * everything in order to compile the built-in functions.
141 ctx
->Const
.GLSLVersion
= options
->glsl_version
;
142 ctx
->Extensions
.ARB_ES3_compatibility
= true;
143 ctx
->Const
.MaxComputeWorkGroupCount
[0] = 65535;
144 ctx
->Const
.MaxComputeWorkGroupCount
[1] = 65535;
145 ctx
->Const
.MaxComputeWorkGroupCount
[2] = 65535;
146 ctx
->Const
.MaxComputeWorkGroupSize
[0] = 1024;
147 ctx
->Const
.MaxComputeWorkGroupSize
[1] = 1024;
148 ctx
->Const
.MaxComputeWorkGroupSize
[2] = 64;
149 ctx
->Const
.MaxComputeWorkGroupInvocations
= 1024;
150 ctx
->Const
.MaxComputeSharedMemorySize
= 32768;
151 ctx
->Const
.MaxComputeVariableGroupSize
[0] = 512;
152 ctx
->Const
.MaxComputeVariableGroupSize
[1] = 512;
153 ctx
->Const
.MaxComputeVariableGroupSize
[2] = 64;
154 ctx
->Const
.MaxComputeVariableGroupInvocations
= 512;
155 ctx
->Const
.Program
[MESA_SHADER_COMPUTE
].MaxTextureImageUnits
= 16;
156 ctx
->Const
.Program
[MESA_SHADER_COMPUTE
].MaxUniformComponents
= 1024;
157 ctx
->Const
.Program
[MESA_SHADER_COMPUTE
].MaxCombinedUniformComponents
= 1024;
158 ctx
->Const
.Program
[MESA_SHADER_COMPUTE
].MaxInputComponents
= 0; /* not used */
159 ctx
->Const
.Program
[MESA_SHADER_COMPUTE
].MaxOutputComponents
= 0; /* not used */
160 ctx
->Const
.Program
[MESA_SHADER_COMPUTE
].MaxAtomicBuffers
= 8;
161 ctx
->Const
.Program
[MESA_SHADER_COMPUTE
].MaxAtomicCounters
= 8;
162 ctx
->Const
.Program
[MESA_SHADER_COMPUTE
].MaxImageUniforms
= 8;
163 ctx
->Const
.Program
[MESA_SHADER_COMPUTE
].MaxUniformBlocks
= 12;
165 switch (ctx
->Const
.GLSLVersion
) {
167 ctx
->Const
.MaxClipPlanes
= 0;
168 ctx
->Const
.MaxCombinedTextureImageUnits
= 8;
169 ctx
->Const
.MaxDrawBuffers
= 2;
170 ctx
->Const
.MinProgramTexelOffset
= 0;
171 ctx
->Const
.MaxProgramTexelOffset
= 0;
172 ctx
->Const
.MaxLights
= 0;
173 ctx
->Const
.MaxTextureCoordUnits
= 0;
174 ctx
->Const
.MaxTextureUnits
= 8;
176 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
= 8;
177 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxTextureImageUnits
= 0;
178 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxUniformComponents
= 128 * 4;
179 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxCombinedUniformComponents
= 128 * 4;
180 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxInputComponents
= 0; /* not used */
181 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxOutputComponents
= 32;
183 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxTextureImageUnits
=
184 ctx
->Const
.MaxCombinedTextureImageUnits
;
185 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxUniformComponents
= 16 * 4;
186 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxCombinedUniformComponents
= 16 * 4;
187 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxInputComponents
=
188 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxOutputComponents
;
189 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxOutputComponents
= 0; /* not used */
191 ctx
->Const
.MaxVarying
= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxOutputComponents
/ 4;
195 ctx
->Const
.MaxClipPlanes
= 6;
196 ctx
->Const
.MaxCombinedTextureImageUnits
= 2;
197 ctx
->Const
.MaxDrawBuffers
= 1;
198 ctx
->Const
.MinProgramTexelOffset
= 0;
199 ctx
->Const
.MaxProgramTexelOffset
= 0;
200 ctx
->Const
.MaxLights
= 8;
201 ctx
->Const
.MaxTextureCoordUnits
= 2;
202 ctx
->Const
.MaxTextureUnits
= 2;
204 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
= 16;
205 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxTextureImageUnits
= 0;
206 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxUniformComponents
= 512;
207 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxCombinedUniformComponents
= 512;
208 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxInputComponents
= 0; /* not used */
209 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxOutputComponents
= 32;
211 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxTextureImageUnits
=
212 ctx
->Const
.MaxCombinedTextureImageUnits
;
213 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxUniformComponents
= 64;
214 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxCombinedUniformComponents
= 64;
215 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxInputComponents
=
216 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxOutputComponents
;
217 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxOutputComponents
= 0; /* not used */
219 ctx
->Const
.MaxVarying
= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxOutputComponents
/ 4;
223 ctx
->Const
.MaxClipPlanes
= 8;
224 ctx
->Const
.MaxCombinedTextureImageUnits
= 16;
225 ctx
->Const
.MaxDrawBuffers
= 8;
226 ctx
->Const
.MinProgramTexelOffset
= -8;
227 ctx
->Const
.MaxProgramTexelOffset
= 7;
228 ctx
->Const
.MaxLights
= 8;
229 ctx
->Const
.MaxTextureCoordUnits
= 8;
230 ctx
->Const
.MaxTextureUnits
= 2;
232 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
= 16;
233 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxTextureImageUnits
= 16;
234 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxUniformComponents
= 1024;
235 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxCombinedUniformComponents
= 1024;
236 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxInputComponents
= 0; /* not used */
237 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxOutputComponents
= 64;
239 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxTextureImageUnits
= 16;
240 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxUniformComponents
= 1024;
241 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxCombinedUniformComponents
= 1024;
242 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxInputComponents
=
243 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxOutputComponents
;
244 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxOutputComponents
= 0; /* not used */
246 ctx
->Const
.MaxVarying
= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxOutputComponents
/ 4;
256 ctx
->Const
.MaxClipPlanes
= 8;
257 ctx
->Const
.MaxDrawBuffers
= 8;
258 ctx
->Const
.MinProgramTexelOffset
= -8;
259 ctx
->Const
.MaxProgramTexelOffset
= 7;
260 ctx
->Const
.MaxLights
= 8;
261 ctx
->Const
.MaxTextureCoordUnits
= 8;
262 ctx
->Const
.MaxTextureUnits
= 2;
264 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
= 16;
265 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxTextureImageUnits
= 16;
266 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxUniformComponents
= 1024;
267 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxCombinedUniformComponents
= 1024;
268 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxInputComponents
= 0; /* not used */
269 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxOutputComponents
= 64;
271 ctx
->Const
.Program
[MESA_SHADER_GEOMETRY
].MaxTextureImageUnits
= 16;
272 ctx
->Const
.Program
[MESA_SHADER_GEOMETRY
].MaxUniformComponents
= 1024;
273 ctx
->Const
.Program
[MESA_SHADER_GEOMETRY
].MaxCombinedUniformComponents
= 1024;
274 ctx
->Const
.Program
[MESA_SHADER_GEOMETRY
].MaxInputComponents
=
275 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxOutputComponents
;
276 ctx
->Const
.Program
[MESA_SHADER_GEOMETRY
].MaxOutputComponents
= 128;
278 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxTextureImageUnits
= 16;
279 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxUniformComponents
= 1024;
280 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxCombinedUniformComponents
= 1024;
281 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxInputComponents
=
282 ctx
->Const
.Program
[MESA_SHADER_GEOMETRY
].MaxOutputComponents
;
283 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxOutputComponents
= 0; /* not used */
285 ctx
->Const
.MaxCombinedTextureImageUnits
=
286 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxTextureImageUnits
287 + ctx
->Const
.Program
[MESA_SHADER_GEOMETRY
].MaxTextureImageUnits
288 + ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxTextureImageUnits
;
290 ctx
->Const
.MaxGeometryOutputVertices
= 256;
291 ctx
->Const
.MaxGeometryTotalOutputComponents
= 1024;
293 ctx
->Const
.MaxVarying
= 60 / 4;
296 ctx
->Const
.MaxClipPlanes
= 8;
297 ctx
->Const
.MaxCombinedTextureImageUnits
= 32;
298 ctx
->Const
.MaxDrawBuffers
= 4;
299 ctx
->Const
.MinProgramTexelOffset
= -8;
300 ctx
->Const
.MaxProgramTexelOffset
= 7;
301 ctx
->Const
.MaxLights
= 0;
302 ctx
->Const
.MaxTextureCoordUnits
= 0;
303 ctx
->Const
.MaxTextureUnits
= 0;
305 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
= 16;
306 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxTextureImageUnits
= 16;
307 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxUniformComponents
= 1024;
308 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxCombinedUniformComponents
= 1024;
309 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxInputComponents
= 0; /* not used */
310 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxOutputComponents
= 16 * 4;
312 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxTextureImageUnits
= 16;
313 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxUniformComponents
= 224;
314 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxCombinedUniformComponents
= 224;
315 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxInputComponents
= 15 * 4;
316 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxOutputComponents
= 0; /* not used */
318 ctx
->Const
.MaxVarying
= ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxInputComponents
/ 4;
322 ctx
->Const
.GenerateTemporaryNames
= true;
323 ctx
->Const
.MaxPatchVertices
= 32;
325 /* GL_ARB_explicit_uniform_location, GL_MAX_UNIFORM_LOCATIONS */
326 ctx
->Const
.MaxUserAssignableUniformLocations
=
327 4 * MESA_SHADER_STAGES
* MAX_UNIFORMS
;
329 ctx
->Driver
.NewProgram
= new_program
;
332 /* Returned string will have 'ctx' as its ralloc owner. */
334 load_text_file(void *ctx
, const char *file_name
)
338 size_t total_read
= 0;
339 FILE *fp
= fopen(file_name
, "rb");
345 fseek(fp
, 0L, SEEK_END
);
347 fseek(fp
, 0L, SEEK_SET
);
349 text
= (char *) ralloc_size(ctx
, size
+ 1);
352 size_t bytes
= fread(text
+ total_read
,
353 1, size
- total_read
, fp
);
354 if (bytes
< size
- total_read
) {
365 } while (total_read
< size
);
367 text
[total_read
] = '\0';
377 compile_shader(struct gl_context
*ctx
, struct gl_shader
*shader
)
379 struct _mesa_glsl_parse_state
*state
=
380 new(shader
) _mesa_glsl_parse_state(ctx
, shader
->Stage
, shader
);
382 _mesa_glsl_compile_shader(ctx
, shader
, options
->dump_ast
,
383 options
->dump_hir
, true);
385 /* Print out the resulting IR */
386 if (!state
->error
&& options
->dump_lir
) {
387 _mesa_print_ir(stdout
, shader
->ir
, state
);
393 extern "C" struct gl_shader_program
*
394 standalone_compile_shader(const struct standalone_options
*_options
,
395 unsigned num_files
, char* const* files
)
397 int status
= EXIT_SUCCESS
;
398 static struct gl_context local_ctx
;
399 struct gl_context
*ctx
= &local_ctx
;
400 bool glsl_es
= false;
404 switch (options
->glsl_version
) {
424 fprintf(stderr
, "Unrecognized GLSL version `%d'\n", options
->glsl_version
);
429 initialize_context(ctx
, API_OPENGLES2
);
431 initialize_context(ctx
, options
->glsl_version
> 130 ? API_OPENGL_CORE
: API_OPENGL_COMPAT
);
434 struct gl_shader_program
*whole_program
;
436 whole_program
= rzalloc (NULL
, struct gl_shader_program
);
437 assert(whole_program
!= NULL
);
438 whole_program
->data
= rzalloc(whole_program
, struct gl_shader_program_data
);
439 assert(whole_program
->data
!= NULL
);
440 whole_program
->data
->InfoLog
= ralloc_strdup(whole_program
->data
, "");
442 /* Created just to avoid segmentation faults */
443 whole_program
->AttributeBindings
= new string_to_uint_map
;
444 whole_program
->FragDataBindings
= new string_to_uint_map
;
445 whole_program
->FragDataIndexBindings
= new string_to_uint_map
;
447 for (unsigned i
= 0; i
< num_files
; i
++) {
448 whole_program
->Shaders
=
449 reralloc(whole_program
, whole_program
->Shaders
,
450 struct gl_shader
*, whole_program
->NumShaders
+ 1);
451 assert(whole_program
->Shaders
!= NULL
);
453 struct gl_shader
*shader
= rzalloc(whole_program
, gl_shader
);
455 whole_program
->Shaders
[whole_program
->NumShaders
] = shader
;
456 whole_program
->NumShaders
++;
458 const unsigned len
= strlen(files
[i
]);
462 const char *const ext
= & files
[i
][len
- 5];
463 /* TODO add support to read a .shader_test */
464 if (strncmp(".vert", ext
, 5) == 0 || strncmp(".glsl", ext
, 5) == 0)
465 shader
->Type
= GL_VERTEX_SHADER
;
466 else if (strncmp(".tesc", ext
, 5) == 0)
467 shader
->Type
= GL_TESS_CONTROL_SHADER
;
468 else if (strncmp(".tese", ext
, 5) == 0)
469 shader
->Type
= GL_TESS_EVALUATION_SHADER
;
470 else if (strncmp(".geom", ext
, 5) == 0)
471 shader
->Type
= GL_GEOMETRY_SHADER
;
472 else if (strncmp(".frag", ext
, 5) == 0)
473 shader
->Type
= GL_FRAGMENT_SHADER
;
474 else if (strncmp(".comp", ext
, 5) == 0)
475 shader
->Type
= GL_COMPUTE_SHADER
;
478 shader
->Stage
= _mesa_shader_enum_to_shader_stage(shader
->Type
);
480 shader
->Source
= load_text_file(whole_program
, files
[i
]);
481 if (shader
->Source
== NULL
) {
482 printf("File \"%s\" does not exist.\n", files
[i
]);
486 compile_shader(ctx
, shader
);
488 if (strlen(shader
->InfoLog
) > 0) {
489 if (!options
->just_log
)
490 printf("Info log for %s:\n", files
[i
]);
492 printf("%s", shader
->InfoLog
);
493 if (!options
->just_log
)
497 if (!shader
->CompileStatus
) {
498 status
= EXIT_FAILURE
;
503 if (status
== EXIT_SUCCESS
) {
504 _mesa_clear_shader_program_data(ctx
, whole_program
);
506 if (options
->do_link
) {
507 link_shaders(ctx
, whole_program
);
509 const gl_shader_stage stage
= whole_program
->Shaders
[0]->Stage
;
511 whole_program
->data
->LinkStatus
= linking_success
;
512 whole_program
->_LinkedShaders
[stage
] =
513 link_intrastage_shaders(whole_program
/* mem_ctx */,
516 whole_program
->Shaders
,
520 /* Par-linking can fail, for example, if there are undefined external
523 if (whole_program
->_LinkedShaders
[stage
] != NULL
) {
524 assert(whole_program
->data
->LinkStatus
);
526 struct gl_shader_compiler_options
*const compiler_options
=
527 &ctx
->Const
.ShaderCompilerOptions
[stage
];
529 exec_list
*const ir
=
530 whole_program
->_LinkedShaders
[stage
]->ir
;
534 progress
= do_function_inlining(ir
);
536 progress
= do_common_optimization(ir
,
546 status
= (whole_program
->data
->LinkStatus
) ? EXIT_SUCCESS
: EXIT_FAILURE
;
548 if (strlen(whole_program
->data
->InfoLog
) > 0) {
550 if (!options
->just_log
)
551 printf("Info log for linking:\n");
552 printf("%s", whole_program
->data
->InfoLog
);
553 if (!options
->just_log
)
557 for (unsigned i
= 0; i
< MESA_SHADER_STAGES
; i
++) {
558 struct gl_linked_shader
*shader
= whole_program
->_LinkedShaders
[i
];
563 add_neg_to_sub_visitor v
;
564 visit_list_elements(&v
, shader
->ir
);
566 dead_variable_visitor dv
;
567 visit_list_elements(&dv
, shader
->ir
);
568 dv
.remove_dead_variables();
571 if (options
->dump_builder
) {
572 for (unsigned i
= 0; i
< MESA_SHADER_STAGES
; i
++) {
573 struct gl_linked_shader
*shader
= whole_program
->_LinkedShaders
[i
];
578 _mesa_print_builder_for_ir(stdout
, shader
->ir
);
583 return whole_program
;
586 for (unsigned i
= 0; i
< MESA_SHADER_STAGES
; i
++) {
587 if (whole_program
->_LinkedShaders
[i
])
588 ralloc_free(whole_program
->_LinkedShaders
[i
]->Program
);
591 ralloc_free(whole_program
);
596 standalone_compiler_cleanup(struct gl_shader_program
*whole_program
)
598 for (unsigned i
= 0; i
< MESA_SHADER_STAGES
; i
++) {
599 if (whole_program
->_LinkedShaders
[i
])
600 ralloc_free(whole_program
->_LinkedShaders
[i
]->Program
);
603 delete whole_program
->AttributeBindings
;
604 delete whole_program
->FragDataBindings
;
605 delete whole_program
->FragDataIndexBindings
;
607 ralloc_free(whole_program
);
608 _mesa_glsl_release_types();
609 _mesa_glsl_release_builtin_functions();