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 "opt_add_neg_to_sub.h"
46 class dead_variable_visitor
: public ir_hierarchical_visitor
{
48 dead_variable_visitor()
50 variables
= _mesa_set_create(NULL
,
52 _mesa_key_pointer_equal
);
55 virtual ~dead_variable_visitor()
57 _mesa_set_destroy(variables
, NULL
);
60 virtual ir_visitor_status
visit(ir_variable
*ir
)
62 /* If the variable is auto or temp, add it to the set of variables that
63 * are candidates for removal.
65 if (ir
->data
.mode
!= ir_var_auto
&& ir
->data
.mode
!= ir_var_temporary
)
66 return visit_continue
;
68 _mesa_set_add(variables
, ir
);
70 return visit_continue
;
73 virtual ir_visitor_status
visit(ir_dereference_variable
*ir
)
75 struct set_entry
*entry
= _mesa_set_search(variables
, ir
->var
);
77 /* If a variable is dereferenced at all, remove it from the set of
78 * variables that are candidates for removal.
81 _mesa_set_remove(variables
, entry
);
83 return visit_continue
;
86 void remove_dead_variables()
88 struct set_entry
*entry
;
90 set_foreach(variables
, entry
) {
91 ir_variable
*ir
= (ir_variable
*) entry
->key
;
93 assert(ir
->ir_type
== ir_type_variable
);
103 init_gl_program(struct gl_program
*prog
, GLenum target
, bool is_arb_asm
)
105 mtx_init(&prog
->Mutex
, mtx_plain
);
108 prog
->Format
= GL_PROGRAM_FORMAT_ASCII_ARB
;
109 prog
->is_arb_asm
= is_arb_asm
;
111 /* default mapping from samplers to texture units */
112 for (int i
= 0; i
< MAX_SAMPLERS
; i
++)
113 prog
->SamplerUnits
[i
] = i
;
117 new_program(struct gl_context
*ctx
, GLenum target
, GLuint id
, bool is_arb_asm
)
120 case GL_VERTEX_PROGRAM_ARB
: /* == GL_VERTEX_PROGRAM_NV */
121 case GL_GEOMETRY_PROGRAM_NV
:
122 case GL_TESS_CONTROL_PROGRAM_NV
:
123 case GL_TESS_EVALUATION_PROGRAM_NV
:
124 case GL_FRAGMENT_PROGRAM_ARB
:
125 case GL_COMPUTE_PROGRAM_NV
: {
126 struct gl_program
*prog
= rzalloc(NULL
, struct gl_program
);
127 init_gl_program(prog
, target
, is_arb_asm
);
131 printf("bad target in new_program\n");
136 static const struct standalone_options
*options
;
139 initialize_context(struct gl_context
*ctx
, gl_api api
)
141 initialize_context_to_defaults(ctx
, api
);
143 /* The standalone compiler needs to claim support for almost
144 * everything in order to compile the built-in functions.
146 ctx
->Const
.GLSLVersion
= options
->glsl_version
;
147 ctx
->Extensions
.ARB_ES3_compatibility
= true;
148 ctx
->Const
.MaxComputeWorkGroupCount
[0] = 65535;
149 ctx
->Const
.MaxComputeWorkGroupCount
[1] = 65535;
150 ctx
->Const
.MaxComputeWorkGroupCount
[2] = 65535;
151 ctx
->Const
.MaxComputeWorkGroupSize
[0] = 1024;
152 ctx
->Const
.MaxComputeWorkGroupSize
[1] = 1024;
153 ctx
->Const
.MaxComputeWorkGroupSize
[2] = 64;
154 ctx
->Const
.MaxComputeWorkGroupInvocations
= 1024;
155 ctx
->Const
.MaxComputeSharedMemorySize
= 32768;
156 ctx
->Const
.MaxComputeVariableGroupSize
[0] = 512;
157 ctx
->Const
.MaxComputeVariableGroupSize
[1] = 512;
158 ctx
->Const
.MaxComputeVariableGroupSize
[2] = 64;
159 ctx
->Const
.MaxComputeVariableGroupInvocations
= 512;
160 ctx
->Const
.Program
[MESA_SHADER_COMPUTE
].MaxTextureImageUnits
= 16;
161 ctx
->Const
.Program
[MESA_SHADER_COMPUTE
].MaxUniformComponents
= 1024;
162 ctx
->Const
.Program
[MESA_SHADER_COMPUTE
].MaxCombinedUniformComponents
= 1024;
163 ctx
->Const
.Program
[MESA_SHADER_COMPUTE
].MaxInputComponents
= 0; /* not used */
164 ctx
->Const
.Program
[MESA_SHADER_COMPUTE
].MaxOutputComponents
= 0; /* not used */
165 ctx
->Const
.Program
[MESA_SHADER_COMPUTE
].MaxAtomicBuffers
= 8;
166 ctx
->Const
.Program
[MESA_SHADER_COMPUTE
].MaxAtomicCounters
= 8;
167 ctx
->Const
.Program
[MESA_SHADER_COMPUTE
].MaxImageUniforms
= 8;
168 ctx
->Const
.Program
[MESA_SHADER_COMPUTE
].MaxUniformBlocks
= 12;
170 switch (ctx
->Const
.GLSLVersion
) {
172 ctx
->Const
.MaxClipPlanes
= 0;
173 ctx
->Const
.MaxCombinedTextureImageUnits
= 8;
174 ctx
->Const
.MaxDrawBuffers
= 2;
175 ctx
->Const
.MinProgramTexelOffset
= 0;
176 ctx
->Const
.MaxProgramTexelOffset
= 0;
177 ctx
->Const
.MaxLights
= 0;
178 ctx
->Const
.MaxTextureCoordUnits
= 0;
179 ctx
->Const
.MaxTextureUnits
= 8;
181 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
= 8;
182 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxTextureImageUnits
= 0;
183 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxUniformComponents
= 128 * 4;
184 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxCombinedUniformComponents
= 128 * 4;
185 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxInputComponents
= 0; /* not used */
186 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxOutputComponents
= 32;
188 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxTextureImageUnits
=
189 ctx
->Const
.MaxCombinedTextureImageUnits
;
190 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxUniformComponents
= 16 * 4;
191 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxCombinedUniformComponents
= 16 * 4;
192 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxInputComponents
=
193 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxOutputComponents
;
194 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxOutputComponents
= 0; /* not used */
196 ctx
->Const
.MaxVarying
= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxOutputComponents
/ 4;
200 ctx
->Const
.MaxClipPlanes
= 6;
201 ctx
->Const
.MaxCombinedTextureImageUnits
= 2;
202 ctx
->Const
.MaxDrawBuffers
= 1;
203 ctx
->Const
.MinProgramTexelOffset
= 0;
204 ctx
->Const
.MaxProgramTexelOffset
= 0;
205 ctx
->Const
.MaxLights
= 8;
206 ctx
->Const
.MaxTextureCoordUnits
= 2;
207 ctx
->Const
.MaxTextureUnits
= 2;
209 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
= 16;
210 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxTextureImageUnits
= 0;
211 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxUniformComponents
= 512;
212 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxCombinedUniformComponents
= 512;
213 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxInputComponents
= 0; /* not used */
214 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxOutputComponents
= 32;
216 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxTextureImageUnits
=
217 ctx
->Const
.MaxCombinedTextureImageUnits
;
218 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxUniformComponents
= 64;
219 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxCombinedUniformComponents
= 64;
220 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxInputComponents
=
221 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxOutputComponents
;
222 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxOutputComponents
= 0; /* not used */
224 ctx
->Const
.MaxVarying
= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxOutputComponents
/ 4;
228 ctx
->Const
.MaxClipPlanes
= 8;
229 ctx
->Const
.MaxCombinedTextureImageUnits
= 16;
230 ctx
->Const
.MaxDrawBuffers
= 8;
231 ctx
->Const
.MinProgramTexelOffset
= -8;
232 ctx
->Const
.MaxProgramTexelOffset
= 7;
233 ctx
->Const
.MaxLights
= 8;
234 ctx
->Const
.MaxTextureCoordUnits
= 8;
235 ctx
->Const
.MaxTextureUnits
= 2;
237 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
= 16;
238 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxTextureImageUnits
= 16;
239 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxUniformComponents
= 1024;
240 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxCombinedUniformComponents
= 1024;
241 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxInputComponents
= 0; /* not used */
242 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxOutputComponents
= 64;
244 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxTextureImageUnits
= 16;
245 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxUniformComponents
= 1024;
246 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxCombinedUniformComponents
= 1024;
247 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxInputComponents
=
248 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxOutputComponents
;
249 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxOutputComponents
= 0; /* not used */
251 ctx
->Const
.MaxVarying
= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxOutputComponents
/ 4;
261 ctx
->Const
.MaxClipPlanes
= 8;
262 ctx
->Const
.MaxDrawBuffers
= 8;
263 ctx
->Const
.MinProgramTexelOffset
= -8;
264 ctx
->Const
.MaxProgramTexelOffset
= 7;
265 ctx
->Const
.MaxLights
= 8;
266 ctx
->Const
.MaxTextureCoordUnits
= 8;
267 ctx
->Const
.MaxTextureUnits
= 2;
269 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
= 16;
270 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxTextureImageUnits
= 16;
271 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxUniformComponents
= 1024;
272 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxCombinedUniformComponents
= 1024;
273 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxInputComponents
= 0; /* not used */
274 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxOutputComponents
= 64;
276 ctx
->Const
.Program
[MESA_SHADER_GEOMETRY
].MaxTextureImageUnits
= 16;
277 ctx
->Const
.Program
[MESA_SHADER_GEOMETRY
].MaxUniformComponents
= 1024;
278 ctx
->Const
.Program
[MESA_SHADER_GEOMETRY
].MaxCombinedUniformComponents
= 1024;
279 ctx
->Const
.Program
[MESA_SHADER_GEOMETRY
].MaxInputComponents
=
280 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxOutputComponents
;
281 ctx
->Const
.Program
[MESA_SHADER_GEOMETRY
].MaxOutputComponents
= 128;
283 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxTextureImageUnits
= 16;
284 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxUniformComponents
= 1024;
285 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxCombinedUniformComponents
= 1024;
286 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxInputComponents
=
287 ctx
->Const
.Program
[MESA_SHADER_GEOMETRY
].MaxOutputComponents
;
288 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxOutputComponents
= 0; /* not used */
290 ctx
->Const
.MaxCombinedTextureImageUnits
=
291 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxTextureImageUnits
292 + ctx
->Const
.Program
[MESA_SHADER_GEOMETRY
].MaxTextureImageUnits
293 + ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxTextureImageUnits
;
295 ctx
->Const
.MaxGeometryOutputVertices
= 256;
296 ctx
->Const
.MaxGeometryTotalOutputComponents
= 1024;
298 ctx
->Const
.MaxVarying
= 60 / 4;
301 ctx
->Const
.MaxClipPlanes
= 8;
302 ctx
->Const
.MaxCombinedTextureImageUnits
= 32;
303 ctx
->Const
.MaxDrawBuffers
= 4;
304 ctx
->Const
.MinProgramTexelOffset
= -8;
305 ctx
->Const
.MaxProgramTexelOffset
= 7;
306 ctx
->Const
.MaxLights
= 0;
307 ctx
->Const
.MaxTextureCoordUnits
= 0;
308 ctx
->Const
.MaxTextureUnits
= 0;
310 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
= 16;
311 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxTextureImageUnits
= 16;
312 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxUniformComponents
= 1024;
313 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxCombinedUniformComponents
= 1024;
314 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxInputComponents
= 0; /* not used */
315 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxOutputComponents
= 16 * 4;
317 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxTextureImageUnits
= 16;
318 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxUniformComponents
= 224;
319 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxCombinedUniformComponents
= 224;
320 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxInputComponents
= 15 * 4;
321 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxOutputComponents
= 0; /* not used */
323 ctx
->Const
.MaxVarying
= ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxInputComponents
/ 4;
327 ctx
->Const
.GenerateTemporaryNames
= true;
328 ctx
->Const
.MaxPatchVertices
= 32;
330 /* GL_ARB_explicit_uniform_location, GL_MAX_UNIFORM_LOCATIONS */
331 ctx
->Const
.MaxUserAssignableUniformLocations
=
332 4 * MESA_SHADER_STAGES
* MAX_UNIFORMS
;
334 ctx
->Driver
.NewProgram
= new_program
;
337 /* Returned string will have 'ctx' as its ralloc owner. */
339 load_text_file(void *ctx
, const char *file_name
)
343 size_t total_read
= 0;
344 FILE *fp
= fopen(file_name
, "rb");
350 fseek(fp
, 0L, SEEK_END
);
352 fseek(fp
, 0L, SEEK_SET
);
354 text
= (char *) ralloc_size(ctx
, size
+ 1);
357 size_t bytes
= fread(text
+ total_read
,
358 1, size
- total_read
, fp
);
359 if (bytes
< size
- total_read
) {
370 } while (total_read
< size
);
372 text
[total_read
] = '\0';
382 compile_shader(struct gl_context
*ctx
, struct gl_shader
*shader
)
384 struct _mesa_glsl_parse_state
*state
=
385 new(shader
) _mesa_glsl_parse_state(ctx
, shader
->Stage
, shader
);
387 _mesa_glsl_compile_shader(ctx
, shader
, options
->dump_ast
, options
->dump_hir
);
389 /* Print out the resulting IR */
390 if (!state
->error
&& options
->dump_lir
) {
391 _mesa_print_ir(stdout
, shader
->ir
, state
);
397 extern "C" struct gl_shader_program
*
398 standalone_compile_shader(const struct standalone_options
*_options
,
399 unsigned num_files
, char* const* files
)
401 int status
= EXIT_SUCCESS
;
402 static struct gl_context local_ctx
;
403 struct gl_context
*ctx
= &local_ctx
;
404 bool glsl_es
= false;
408 switch (options
->glsl_version
) {
428 fprintf(stderr
, "Unrecognized GLSL version `%d'\n", options
->glsl_version
);
433 initialize_context(ctx
, API_OPENGLES2
);
435 initialize_context(ctx
, options
->glsl_version
> 130 ? API_OPENGL_CORE
: API_OPENGL_COMPAT
);
438 struct gl_shader_program
*whole_program
;
440 whole_program
= rzalloc (NULL
, struct gl_shader_program
);
441 assert(whole_program
!= NULL
);
442 whole_program
->data
= rzalloc(whole_program
, struct gl_shader_program_data
);
443 assert(whole_program
->data
!= NULL
);
444 whole_program
->data
->InfoLog
= ralloc_strdup(whole_program
->data
, "");
446 /* Created just to avoid segmentation faults */
447 whole_program
->AttributeBindings
= new string_to_uint_map
;
448 whole_program
->FragDataBindings
= new string_to_uint_map
;
449 whole_program
->FragDataIndexBindings
= new string_to_uint_map
;
451 for (unsigned i
= 0; i
< num_files
; i
++) {
452 whole_program
->Shaders
=
453 reralloc(whole_program
, whole_program
->Shaders
,
454 struct gl_shader
*, whole_program
->NumShaders
+ 1);
455 assert(whole_program
->Shaders
!= NULL
);
457 struct gl_shader
*shader
= rzalloc(whole_program
, gl_shader
);
459 whole_program
->Shaders
[whole_program
->NumShaders
] = shader
;
460 whole_program
->NumShaders
++;
462 const unsigned len
= strlen(files
[i
]);
466 const char *const ext
= & files
[i
][len
- 5];
467 /* TODO add support to read a .shader_test */
468 if (strncmp(".vert", ext
, 5) == 0 || strncmp(".glsl", ext
, 5) == 0)
469 shader
->Type
= GL_VERTEX_SHADER
;
470 else if (strncmp(".tesc", ext
, 5) == 0)
471 shader
->Type
= GL_TESS_CONTROL_SHADER
;
472 else if (strncmp(".tese", ext
, 5) == 0)
473 shader
->Type
= GL_TESS_EVALUATION_SHADER
;
474 else if (strncmp(".geom", ext
, 5) == 0)
475 shader
->Type
= GL_GEOMETRY_SHADER
;
476 else if (strncmp(".frag", ext
, 5) == 0)
477 shader
->Type
= GL_FRAGMENT_SHADER
;
478 else if (strncmp(".comp", ext
, 5) == 0)
479 shader
->Type
= GL_COMPUTE_SHADER
;
482 shader
->Stage
= _mesa_shader_enum_to_shader_stage(shader
->Type
);
484 shader
->Source
= load_text_file(whole_program
, files
[i
]);
485 if (shader
->Source
== NULL
) {
486 printf("File \"%s\" does not exist.\n", files
[i
]);
490 compile_shader(ctx
, shader
);
492 if (strlen(shader
->InfoLog
) > 0) {
493 if (!options
->just_log
)
494 printf("Info log for %s:\n", files
[i
]);
496 printf("%s", shader
->InfoLog
);
497 if (!options
->just_log
)
501 if (!shader
->CompileStatus
) {
502 status
= EXIT_FAILURE
;
507 if (status
== EXIT_SUCCESS
) {
508 _mesa_clear_shader_program_data(ctx
, whole_program
);
510 if (options
->do_link
) {
511 link_shaders(ctx
, whole_program
);
513 const gl_shader_stage stage
= whole_program
->Shaders
[0]->Stage
;
515 whole_program
->data
->LinkStatus
= GL_TRUE
;
516 whole_program
->_LinkedShaders
[stage
] =
517 link_intrastage_shaders(whole_program
/* mem_ctx */,
520 whole_program
->Shaders
,
524 /* Par-linking can fail, for example, if there are undefined external
527 if (whole_program
->_LinkedShaders
[stage
] != NULL
) {
528 assert(whole_program
->data
->LinkStatus
);
530 struct gl_shader_compiler_options
*const compiler_options
=
531 &ctx
->Const
.ShaderCompilerOptions
[stage
];
533 exec_list
*const ir
=
534 whole_program
->_LinkedShaders
[stage
]->ir
;
538 progress
= do_function_inlining(ir
);
540 progress
= do_common_optimization(ir
,
550 status
= (whole_program
->data
->LinkStatus
) ? EXIT_SUCCESS
: EXIT_FAILURE
;
552 if (strlen(whole_program
->data
->InfoLog
) > 0) {
554 if (!options
->just_log
)
555 printf("Info log for linking:\n");
556 printf("%s", whole_program
->data
->InfoLog
);
557 if (!options
->just_log
)
561 for (unsigned i
= 0; i
< MESA_SHADER_STAGES
; i
++) {
562 struct gl_linked_shader
*shader
= whole_program
->_LinkedShaders
[i
];
567 add_neg_to_sub_visitor v
;
568 visit_list_elements(&v
, shader
->ir
);
570 dead_variable_visitor dv
;
571 visit_list_elements(&dv
, shader
->ir
);
572 dv
.remove_dead_variables();
575 if (options
->dump_builder
) {
576 for (unsigned i
= 0; i
< MESA_SHADER_STAGES
; i
++) {
577 struct gl_linked_shader
*shader
= whole_program
->_LinkedShaders
[i
];
582 _mesa_print_builder_for_ir(stdout
, shader
->ir
);
587 return whole_program
;
590 for (unsigned i
= 0; i
< MESA_SHADER_STAGES
; i
++) {
591 if (whole_program
->_LinkedShaders
[i
])
592 ralloc_free(whole_program
->_LinkedShaders
[i
]->Program
);
595 ralloc_free(whole_program
);
600 standalone_compiler_cleanup(struct gl_shader_program
*whole_program
)
602 for (unsigned i
= 0; i
< MESA_SHADER_STAGES
; i
++) {
603 if (whole_program
->_LinkedShaders
[i
])
604 ralloc_free(whole_program
->_LinkedShaders
[i
]->Program
);
607 delete whole_program
->AttributeBindings
;
608 delete whole_program
->FragDataBindings
;
609 delete whole_program
->FragDataIndexBindings
;
611 ralloc_free(whole_program
);
612 _mesa_glsl_release_types();
613 _mesa_glsl_release_builtin_functions();