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
)
106 mtx_init(&prog
->Mutex
, mtx_plain
);
109 prog
->Format
= GL_PROGRAM_FORMAT_ASCII_ARB
;
110 prog
->is_arb_asm
= is_arb_asm
;
114 new_program(struct gl_context
*ctx
, GLenum target
, GLuint id
, bool is_arb_asm
)
117 case GL_VERTEX_PROGRAM_ARB
: /* == GL_VERTEX_PROGRAM_NV */
118 case GL_GEOMETRY_PROGRAM_NV
:
119 case GL_TESS_CONTROL_PROGRAM_NV
:
120 case GL_TESS_EVALUATION_PROGRAM_NV
:
121 case GL_FRAGMENT_PROGRAM_ARB
:
122 case GL_COMPUTE_PROGRAM_NV
: {
123 struct gl_program
*prog
= rzalloc(NULL
, struct gl_program
);
124 init_gl_program(prog
, target
, is_arb_asm
);
128 printf("bad target in new_program\n");
133 static const struct standalone_options
*options
;
136 initialize_context(struct gl_context
*ctx
, gl_api api
)
138 initialize_context_to_defaults(ctx
, api
);
140 /* The standalone compiler needs to claim support for almost
141 * everything in order to compile the built-in functions.
143 ctx
->Const
.GLSLVersion
= options
->glsl_version
;
144 ctx
->Extensions
.ARB_ES3_compatibility
= true;
145 ctx
->Const
.MaxComputeWorkGroupCount
[0] = 65535;
146 ctx
->Const
.MaxComputeWorkGroupCount
[1] = 65535;
147 ctx
->Const
.MaxComputeWorkGroupCount
[2] = 65535;
148 ctx
->Const
.MaxComputeWorkGroupSize
[0] = 1024;
149 ctx
->Const
.MaxComputeWorkGroupSize
[1] = 1024;
150 ctx
->Const
.MaxComputeWorkGroupSize
[2] = 64;
151 ctx
->Const
.MaxComputeWorkGroupInvocations
= 1024;
152 ctx
->Const
.MaxComputeSharedMemorySize
= 32768;
153 ctx
->Const
.MaxComputeVariableGroupSize
[0] = 512;
154 ctx
->Const
.MaxComputeVariableGroupSize
[1] = 512;
155 ctx
->Const
.MaxComputeVariableGroupSize
[2] = 64;
156 ctx
->Const
.MaxComputeVariableGroupInvocations
= 512;
157 ctx
->Const
.Program
[MESA_SHADER_COMPUTE
].MaxTextureImageUnits
= 16;
158 ctx
->Const
.Program
[MESA_SHADER_COMPUTE
].MaxUniformComponents
= 1024;
159 ctx
->Const
.Program
[MESA_SHADER_COMPUTE
].MaxCombinedUniformComponents
= 1024;
160 ctx
->Const
.Program
[MESA_SHADER_COMPUTE
].MaxInputComponents
= 0; /* not used */
161 ctx
->Const
.Program
[MESA_SHADER_COMPUTE
].MaxOutputComponents
= 0; /* not used */
162 ctx
->Const
.Program
[MESA_SHADER_COMPUTE
].MaxAtomicBuffers
= 8;
163 ctx
->Const
.Program
[MESA_SHADER_COMPUTE
].MaxAtomicCounters
= 8;
164 ctx
->Const
.Program
[MESA_SHADER_COMPUTE
].MaxImageUniforms
= 8;
165 ctx
->Const
.Program
[MESA_SHADER_COMPUTE
].MaxUniformBlocks
= 12;
167 switch (ctx
->Const
.GLSLVersion
) {
169 ctx
->Const
.MaxClipPlanes
= 0;
170 ctx
->Const
.MaxCombinedTextureImageUnits
= 8;
171 ctx
->Const
.MaxDrawBuffers
= 2;
172 ctx
->Const
.MinProgramTexelOffset
= 0;
173 ctx
->Const
.MaxProgramTexelOffset
= 0;
174 ctx
->Const
.MaxLights
= 0;
175 ctx
->Const
.MaxTextureCoordUnits
= 0;
176 ctx
->Const
.MaxTextureUnits
= 8;
178 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
= 8;
179 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxTextureImageUnits
= 0;
180 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxUniformComponents
= 128 * 4;
181 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxCombinedUniformComponents
= 128 * 4;
182 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxInputComponents
= 0; /* not used */
183 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxOutputComponents
= 32;
185 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxTextureImageUnits
=
186 ctx
->Const
.MaxCombinedTextureImageUnits
;
187 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxUniformComponents
= 16 * 4;
188 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxCombinedUniformComponents
= 16 * 4;
189 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxInputComponents
=
190 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxOutputComponents
;
191 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxOutputComponents
= 0; /* not used */
193 ctx
->Const
.MaxVarying
= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxOutputComponents
/ 4;
197 ctx
->Const
.MaxClipPlanes
= 6;
198 ctx
->Const
.MaxCombinedTextureImageUnits
= 2;
199 ctx
->Const
.MaxDrawBuffers
= 1;
200 ctx
->Const
.MinProgramTexelOffset
= 0;
201 ctx
->Const
.MaxProgramTexelOffset
= 0;
202 ctx
->Const
.MaxLights
= 8;
203 ctx
->Const
.MaxTextureCoordUnits
= 2;
204 ctx
->Const
.MaxTextureUnits
= 2;
206 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
= 16;
207 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxTextureImageUnits
= 0;
208 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxUniformComponents
= 512;
209 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxCombinedUniformComponents
= 512;
210 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxInputComponents
= 0; /* not used */
211 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxOutputComponents
= 32;
213 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxTextureImageUnits
=
214 ctx
->Const
.MaxCombinedTextureImageUnits
;
215 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxUniformComponents
= 64;
216 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxCombinedUniformComponents
= 64;
217 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxInputComponents
=
218 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxOutputComponents
;
219 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxOutputComponents
= 0; /* not used */
221 ctx
->Const
.MaxVarying
= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxOutputComponents
/ 4;
225 ctx
->Const
.MaxClipPlanes
= 8;
226 ctx
->Const
.MaxCombinedTextureImageUnits
= 16;
227 ctx
->Const
.MaxDrawBuffers
= 8;
228 ctx
->Const
.MinProgramTexelOffset
= -8;
229 ctx
->Const
.MaxProgramTexelOffset
= 7;
230 ctx
->Const
.MaxLights
= 8;
231 ctx
->Const
.MaxTextureCoordUnits
= 8;
232 ctx
->Const
.MaxTextureUnits
= 2;
234 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
= 16;
235 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxTextureImageUnits
= 16;
236 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxUniformComponents
= 1024;
237 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxCombinedUniformComponents
= 1024;
238 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxInputComponents
= 0; /* not used */
239 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxOutputComponents
= 64;
241 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxTextureImageUnits
= 16;
242 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxUniformComponents
= 1024;
243 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxCombinedUniformComponents
= 1024;
244 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxInputComponents
=
245 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxOutputComponents
;
246 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxOutputComponents
= 0; /* not used */
248 ctx
->Const
.MaxVarying
= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxOutputComponents
/ 4;
258 ctx
->Const
.MaxClipPlanes
= 8;
259 ctx
->Const
.MaxDrawBuffers
= 8;
260 ctx
->Const
.MinProgramTexelOffset
= -8;
261 ctx
->Const
.MaxProgramTexelOffset
= 7;
262 ctx
->Const
.MaxLights
= 8;
263 ctx
->Const
.MaxTextureCoordUnits
= 8;
264 ctx
->Const
.MaxTextureUnits
= 2;
266 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
= 16;
267 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxTextureImageUnits
= 16;
268 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxUniformComponents
= 1024;
269 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxCombinedUniformComponents
= 1024;
270 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxInputComponents
= 0; /* not used */
271 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxOutputComponents
= 64;
273 ctx
->Const
.Program
[MESA_SHADER_GEOMETRY
].MaxTextureImageUnits
= 16;
274 ctx
->Const
.Program
[MESA_SHADER_GEOMETRY
].MaxUniformComponents
= 1024;
275 ctx
->Const
.Program
[MESA_SHADER_GEOMETRY
].MaxCombinedUniformComponents
= 1024;
276 ctx
->Const
.Program
[MESA_SHADER_GEOMETRY
].MaxInputComponents
=
277 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxOutputComponents
;
278 ctx
->Const
.Program
[MESA_SHADER_GEOMETRY
].MaxOutputComponents
= 128;
280 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxTextureImageUnits
= 16;
281 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxUniformComponents
= 1024;
282 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxCombinedUniformComponents
= 1024;
283 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxInputComponents
=
284 ctx
->Const
.Program
[MESA_SHADER_GEOMETRY
].MaxOutputComponents
;
285 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxOutputComponents
= 0; /* not used */
287 ctx
->Const
.MaxCombinedTextureImageUnits
=
288 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxTextureImageUnits
289 + ctx
->Const
.Program
[MESA_SHADER_GEOMETRY
].MaxTextureImageUnits
290 + ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxTextureImageUnits
;
292 ctx
->Const
.MaxGeometryOutputVertices
= 256;
293 ctx
->Const
.MaxGeometryTotalOutputComponents
= 1024;
295 ctx
->Const
.MaxVarying
= 60 / 4;
298 ctx
->Const
.MaxClipPlanes
= 8;
299 ctx
->Const
.MaxCombinedTextureImageUnits
= 32;
300 ctx
->Const
.MaxDrawBuffers
= 4;
301 ctx
->Const
.MinProgramTexelOffset
= -8;
302 ctx
->Const
.MaxProgramTexelOffset
= 7;
303 ctx
->Const
.MaxLights
= 0;
304 ctx
->Const
.MaxTextureCoordUnits
= 0;
305 ctx
->Const
.MaxTextureUnits
= 0;
307 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
= 16;
308 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxTextureImageUnits
= 16;
309 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxUniformComponents
= 1024;
310 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxCombinedUniformComponents
= 1024;
311 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxInputComponents
= 0; /* not used */
312 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxOutputComponents
= 16 * 4;
314 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxTextureImageUnits
= 16;
315 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxUniformComponents
= 224;
316 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxCombinedUniformComponents
= 224;
317 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxInputComponents
= 15 * 4;
318 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxOutputComponents
= 0; /* not used */
320 ctx
->Const
.MaxVarying
= ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxInputComponents
/ 4;
324 ctx
->Const
.GenerateTemporaryNames
= true;
325 ctx
->Const
.MaxPatchVertices
= 32;
327 /* GL_ARB_explicit_uniform_location, GL_MAX_UNIFORM_LOCATIONS */
328 ctx
->Const
.MaxUserAssignableUniformLocations
=
329 4 * MESA_SHADER_STAGES
* MAX_UNIFORMS
;
331 ctx
->Driver
.NewProgram
= new_program
;
334 /* Returned string will have 'ctx' as its ralloc owner. */
336 load_text_file(void *ctx
, const char *file_name
)
340 size_t total_read
= 0;
341 FILE *fp
= fopen(file_name
, "rb");
347 fseek(fp
, 0L, SEEK_END
);
349 fseek(fp
, 0L, SEEK_SET
);
351 text
= (char *) ralloc_size(ctx
, size
+ 1);
354 size_t bytes
= fread(text
+ total_read
,
355 1, size
- total_read
, fp
);
356 if (bytes
< size
- total_read
) {
367 } while (total_read
< size
);
369 text
[total_read
] = '\0';
379 compile_shader(struct gl_context
*ctx
, struct gl_shader
*shader
)
381 struct _mesa_glsl_parse_state
*state
=
382 new(shader
) _mesa_glsl_parse_state(ctx
, shader
->Stage
, shader
);
384 _mesa_glsl_compile_shader(ctx
, shader
, options
->dump_ast
, options
->dump_hir
);
386 /* Print out the resulting IR */
387 if (!state
->error
&& options
->dump_lir
) {
388 _mesa_print_ir(stdout
, shader
->ir
, state
);
394 extern "C" struct gl_shader_program
*
395 standalone_compile_shader(const struct standalone_options
*_options
,
396 unsigned num_files
, char* const* files
)
398 int status
= EXIT_SUCCESS
;
399 static struct gl_context local_ctx
;
400 struct gl_context
*ctx
= &local_ctx
;
401 bool glsl_es
= false;
405 switch (options
->glsl_version
) {
425 fprintf(stderr
, "Unrecognized GLSL version `%d'\n", options
->glsl_version
);
430 initialize_context(ctx
, API_OPENGLES2
);
432 initialize_context(ctx
, options
->glsl_version
> 130 ? API_OPENGL_CORE
: API_OPENGL_COMPAT
);
435 struct gl_shader_program
*whole_program
;
437 whole_program
= rzalloc (NULL
, struct gl_shader_program
);
438 assert(whole_program
!= NULL
);
439 whole_program
->data
= rzalloc(whole_program
, struct gl_shader_program_data
);
440 assert(whole_program
->data
!= NULL
);
441 whole_program
->data
->InfoLog
= ralloc_strdup(whole_program
->data
, "");
443 /* Created just to avoid segmentation faults */
444 whole_program
->AttributeBindings
= new string_to_uint_map
;
445 whole_program
->FragDataBindings
= new string_to_uint_map
;
446 whole_program
->FragDataIndexBindings
= new string_to_uint_map
;
448 for (unsigned i
= 0; i
< num_files
; i
++) {
449 whole_program
->Shaders
=
450 reralloc(whole_program
, whole_program
->Shaders
,
451 struct gl_shader
*, whole_program
->NumShaders
+ 1);
452 assert(whole_program
->Shaders
!= NULL
);
454 struct gl_shader
*shader
= rzalloc(whole_program
, gl_shader
);
456 whole_program
->Shaders
[whole_program
->NumShaders
] = shader
;
457 whole_program
->NumShaders
++;
459 const unsigned len
= strlen(files
[i
]);
463 const char *const ext
= & files
[i
][len
- 5];
464 /* TODO add support to read a .shader_test */
465 if (strncmp(".vert", ext
, 5) == 0 || strncmp(".glsl", ext
, 5) == 0)
466 shader
->Type
= GL_VERTEX_SHADER
;
467 else if (strncmp(".tesc", ext
, 5) == 0)
468 shader
->Type
= GL_TESS_CONTROL_SHADER
;
469 else if (strncmp(".tese", ext
, 5) == 0)
470 shader
->Type
= GL_TESS_EVALUATION_SHADER
;
471 else if (strncmp(".geom", ext
, 5) == 0)
472 shader
->Type
= GL_GEOMETRY_SHADER
;
473 else if (strncmp(".frag", ext
, 5) == 0)
474 shader
->Type
= GL_FRAGMENT_SHADER
;
475 else if (strncmp(".comp", ext
, 5) == 0)
476 shader
->Type
= GL_COMPUTE_SHADER
;
479 shader
->Stage
= _mesa_shader_enum_to_shader_stage(shader
->Type
);
481 shader
->Source
= load_text_file(whole_program
, files
[i
]);
482 if (shader
->Source
== NULL
) {
483 printf("File \"%s\" does not exist.\n", files
[i
]);
487 compile_shader(ctx
, shader
);
489 if (strlen(shader
->InfoLog
) > 0) {
490 if (!options
->just_log
)
491 printf("Info log for %s:\n", files
[i
]);
493 printf("%s", shader
->InfoLog
);
494 if (!options
->just_log
)
498 if (!shader
->CompileStatus
) {
499 status
= EXIT_FAILURE
;
504 if (status
== EXIT_SUCCESS
) {
505 _mesa_clear_shader_program_data(ctx
, whole_program
);
507 if (options
->do_link
) {
508 link_shaders(ctx
, whole_program
);
510 const gl_shader_stage stage
= whole_program
->Shaders
[0]->Stage
;
512 whole_program
->data
->LinkStatus
= linking_success
;
513 whole_program
->_LinkedShaders
[stage
] =
514 link_intrastage_shaders(whole_program
/* mem_ctx */,
517 whole_program
->Shaders
,
521 /* Par-linking can fail, for example, if there are undefined external
524 if (whole_program
->_LinkedShaders
[stage
] != NULL
) {
525 assert(whole_program
->data
->LinkStatus
);
527 struct gl_shader_compiler_options
*const compiler_options
=
528 &ctx
->Const
.ShaderCompilerOptions
[stage
];
530 exec_list
*const ir
=
531 whole_program
->_LinkedShaders
[stage
]->ir
;
535 progress
= do_function_inlining(ir
);
537 progress
= do_common_optimization(ir
,
547 status
= (whole_program
->data
->LinkStatus
) ? EXIT_SUCCESS
: EXIT_FAILURE
;
549 if (strlen(whole_program
->data
->InfoLog
) > 0) {
551 if (!options
->just_log
)
552 printf("Info log for linking:\n");
553 printf("%s", whole_program
->data
->InfoLog
);
554 if (!options
->just_log
)
558 for (unsigned i
= 0; i
< MESA_SHADER_STAGES
; i
++) {
559 struct gl_linked_shader
*shader
= whole_program
->_LinkedShaders
[i
];
564 add_neg_to_sub_visitor v
;
565 visit_list_elements(&v
, shader
->ir
);
567 dead_variable_visitor dv
;
568 visit_list_elements(&dv
, shader
->ir
);
569 dv
.remove_dead_variables();
572 if (options
->dump_builder
) {
573 for (unsigned i
= 0; i
< MESA_SHADER_STAGES
; i
++) {
574 struct gl_linked_shader
*shader
= whole_program
->_LinkedShaders
[i
];
579 _mesa_print_builder_for_ir(stdout
, shader
->ir
);
584 return whole_program
;
587 for (unsigned i
= 0; i
< MESA_SHADER_STAGES
; i
++) {
588 if (whole_program
->_LinkedShaders
[i
])
589 ralloc_free(whole_program
->_LinkedShaders
[i
]->Program
);
592 ralloc_free(whole_program
);
597 standalone_compiler_cleanup(struct gl_shader_program
*whole_program
)
599 for (unsigned i
= 0; i
< MESA_SHADER_STAGES
; i
++) {
600 if (whole_program
->_LinkedShaders
[i
])
601 ralloc_free(whole_program
->_LinkedShaders
[i
]->Program
);
604 delete whole_program
->AttributeBindings
;
605 delete whole_program
->FragDataBindings
;
606 delete whole_program
->FragDataIndexBindings
;
608 ralloc_free(whole_program
);
609 _mesa_glsl_release_types();
610 _mesa_glsl_release_builtin_functions();