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 "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"
46 #include "main/mtypes.h"
47 #include "program/program.h"
49 class dead_variable_visitor
: public ir_hierarchical_visitor
{
51 dead_variable_visitor()
53 variables
= _mesa_pointer_set_create(NULL
);
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 set_foreach(variables
, entry
) {
90 ir_variable
*ir
= (ir_variable
*) entry
->key
;
92 assert(ir
->ir_type
== ir_type_variable
);
102 init_gl_program(struct gl_program
*prog
, bool is_arb_asm
, GLenum target
)
105 prog
->Format
= GL_PROGRAM_FORMAT_ASCII_ARB
;
106 prog
->is_arb_asm
= is_arb_asm
;
107 prog
->info
.stage
= (gl_shader_stage
)_mesa_program_enum_to_shader_stage(target
);
110 static struct gl_program
*
111 new_program(UNUSED
struct gl_context
*ctx
, GLenum target
,
112 UNUSED 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
, is_arb_asm
, target
);
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
);
137 _mesa_glsl_builtin_functions_init_or_ref();
139 /* The standalone compiler needs to claim support for almost
140 * everything in order to compile the built-in functions.
142 ctx
->Const
.GLSLVersion
= options
->glsl_version
;
143 ctx
->Extensions
.ARB_ES3_compatibility
= true;
144 ctx
->Extensions
.ARB_ES3_1_compatibility
= true;
145 ctx
->Extensions
.ARB_ES3_2_compatibility
= true;
146 ctx
->Const
.MaxComputeWorkGroupCount
[0] = 65535;
147 ctx
->Const
.MaxComputeWorkGroupCount
[1] = 65535;
148 ctx
->Const
.MaxComputeWorkGroupCount
[2] = 65535;
149 ctx
->Const
.MaxComputeWorkGroupSize
[0] = 1024;
150 ctx
->Const
.MaxComputeWorkGroupSize
[1] = 1024;
151 ctx
->Const
.MaxComputeWorkGroupSize
[2] = 64;
152 ctx
->Const
.MaxComputeWorkGroupInvocations
= 1024;
153 ctx
->Const
.MaxComputeSharedMemorySize
= 32768;
154 ctx
->Const
.MaxComputeVariableGroupSize
[0] = 512;
155 ctx
->Const
.MaxComputeVariableGroupSize
[1] = 512;
156 ctx
->Const
.MaxComputeVariableGroupSize
[2] = 64;
157 ctx
->Const
.MaxComputeVariableGroupInvocations
= 512;
158 ctx
->Const
.Program
[MESA_SHADER_COMPUTE
].MaxTextureImageUnits
= 16;
159 ctx
->Const
.Program
[MESA_SHADER_COMPUTE
].MaxUniformComponents
= 1024;
160 ctx
->Const
.Program
[MESA_SHADER_COMPUTE
].MaxCombinedUniformComponents
= 1024;
161 ctx
->Const
.Program
[MESA_SHADER_COMPUTE
].MaxInputComponents
= 0; /* not used */
162 ctx
->Const
.Program
[MESA_SHADER_COMPUTE
].MaxOutputComponents
= 0; /* not used */
163 ctx
->Const
.Program
[MESA_SHADER_COMPUTE
].MaxAtomicBuffers
= 8;
164 ctx
->Const
.Program
[MESA_SHADER_COMPUTE
].MaxAtomicCounters
= 8;
165 ctx
->Const
.Program
[MESA_SHADER_COMPUTE
].MaxImageUniforms
= 8;
166 ctx
->Const
.Program
[MESA_SHADER_COMPUTE
].MaxUniformBlocks
= 12;
168 switch (ctx
->Const
.GLSLVersion
) {
170 ctx
->Const
.MaxClipPlanes
= 0;
171 ctx
->Const
.MaxCombinedTextureImageUnits
= 8;
172 ctx
->Const
.MaxDrawBuffers
= 2;
173 ctx
->Const
.MinProgramTexelOffset
= 0;
174 ctx
->Const
.MaxProgramTexelOffset
= 0;
175 ctx
->Const
.MaxLights
= 0;
176 ctx
->Const
.MaxTextureCoordUnits
= 0;
177 ctx
->Const
.MaxTextureUnits
= 8;
179 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
= 8;
180 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxTextureImageUnits
= 0;
181 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxUniformComponents
= 128 * 4;
182 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxCombinedUniformComponents
= 128 * 4;
183 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxInputComponents
= 0; /* not used */
184 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxOutputComponents
= 32;
186 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxTextureImageUnits
=
187 ctx
->Const
.MaxCombinedTextureImageUnits
;
188 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxUniformComponents
= 16 * 4;
189 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxCombinedUniformComponents
= 16 * 4;
190 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxInputComponents
=
191 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxOutputComponents
;
192 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxOutputComponents
= 0; /* not used */
194 ctx
->Const
.MaxVarying
= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxOutputComponents
/ 4;
198 ctx
->Const
.MaxClipPlanes
= 6;
199 ctx
->Const
.MaxCombinedTextureImageUnits
= 2;
200 ctx
->Const
.MaxDrawBuffers
= 1;
201 ctx
->Const
.MinProgramTexelOffset
= 0;
202 ctx
->Const
.MaxProgramTexelOffset
= 0;
203 ctx
->Const
.MaxLights
= 8;
204 ctx
->Const
.MaxTextureCoordUnits
= 2;
205 ctx
->Const
.MaxTextureUnits
= 2;
207 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
= 16;
208 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxTextureImageUnits
= 0;
209 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxUniformComponents
= 512;
210 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxCombinedUniformComponents
= 512;
211 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxInputComponents
= 0; /* not used */
212 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxOutputComponents
= 32;
214 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxTextureImageUnits
=
215 ctx
->Const
.MaxCombinedTextureImageUnits
;
216 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxUniformComponents
= 64;
217 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxCombinedUniformComponents
= 64;
218 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxInputComponents
=
219 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxOutputComponents
;
220 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxOutputComponents
= 0; /* not used */
222 ctx
->Const
.MaxVarying
= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxOutputComponents
/ 4;
226 ctx
->Const
.MaxClipPlanes
= 8;
227 ctx
->Const
.MaxCombinedTextureImageUnits
= 16;
228 ctx
->Const
.MaxDrawBuffers
= 8;
229 ctx
->Const
.MinProgramTexelOffset
= -8;
230 ctx
->Const
.MaxProgramTexelOffset
= 7;
231 ctx
->Const
.MaxLights
= 8;
232 ctx
->Const
.MaxTextureCoordUnits
= 8;
233 ctx
->Const
.MaxTextureUnits
= 2;
234 ctx
->Const
.MaxUniformBufferBindings
= 84;
235 ctx
->Const
.MaxVertexStreams
= 4;
236 ctx
->Const
.MaxTransformFeedbackBuffers
= 4;
238 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
= 16;
239 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxTextureImageUnits
= 16;
240 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxUniformComponents
= 1024;
241 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxCombinedUniformComponents
= 1024;
242 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxInputComponents
= 0; /* not used */
243 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxOutputComponents
= 64;
245 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxTextureImageUnits
= 16;
246 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxUniformComponents
= 1024;
247 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxCombinedUniformComponents
= 1024;
248 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxInputComponents
=
249 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxOutputComponents
;
250 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxOutputComponents
= 0; /* not used */
252 ctx
->Const
.MaxVarying
= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxOutputComponents
/ 4;
263 ctx
->Const
.MaxClipPlanes
= 8;
264 ctx
->Const
.MaxDrawBuffers
= 8;
265 ctx
->Const
.MinProgramTexelOffset
= -8;
266 ctx
->Const
.MaxProgramTexelOffset
= 7;
267 ctx
->Const
.MaxLights
= 8;
268 ctx
->Const
.MaxTextureCoordUnits
= 8;
269 ctx
->Const
.MaxTextureUnits
= 2;
270 ctx
->Const
.MaxUniformBufferBindings
= 84;
271 ctx
->Const
.MaxVertexStreams
= 4;
272 ctx
->Const
.MaxTransformFeedbackBuffers
= 4;
273 ctx
->Const
.MaxShaderStorageBufferBindings
= 4;
274 ctx
->Const
.MaxShaderStorageBlockSize
= 4096;
275 ctx
->Const
.MaxAtomicBufferBindings
= 4;
277 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
= 16;
278 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxTextureImageUnits
= 16;
279 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxUniformComponents
= 1024;
280 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxCombinedUniformComponents
= 1024;
281 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxInputComponents
= 0; /* not used */
282 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxOutputComponents
= 64;
284 ctx
->Const
.Program
[MESA_SHADER_GEOMETRY
].MaxTextureImageUnits
= 16;
285 ctx
->Const
.Program
[MESA_SHADER_GEOMETRY
].MaxUniformComponents
= 1024;
286 ctx
->Const
.Program
[MESA_SHADER_GEOMETRY
].MaxCombinedUniformComponents
= 1024;
287 ctx
->Const
.Program
[MESA_SHADER_GEOMETRY
].MaxInputComponents
=
288 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxOutputComponents
;
289 ctx
->Const
.Program
[MESA_SHADER_GEOMETRY
].MaxOutputComponents
= 128;
291 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxTextureImageUnits
= 16;
292 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxUniformComponents
= 1024;
293 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxCombinedUniformComponents
= 1024;
294 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxInputComponents
=
295 ctx
->Const
.Program
[MESA_SHADER_GEOMETRY
].MaxOutputComponents
;
296 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxOutputComponents
= 0; /* not used */
298 ctx
->Const
.MaxCombinedTextureImageUnits
=
299 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxTextureImageUnits
300 + ctx
->Const
.Program
[MESA_SHADER_GEOMETRY
].MaxTextureImageUnits
301 + ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxTextureImageUnits
;
303 ctx
->Const
.MaxGeometryOutputVertices
= 256;
304 ctx
->Const
.MaxGeometryTotalOutputComponents
= 1024;
306 ctx
->Const
.MaxVarying
= 60 / 4;
309 ctx
->Const
.MaxClipPlanes
= 8;
310 ctx
->Const
.MaxCombinedTextureImageUnits
= 32;
311 ctx
->Const
.MaxDrawBuffers
= 4;
312 ctx
->Const
.MinProgramTexelOffset
= -8;
313 ctx
->Const
.MaxProgramTexelOffset
= 7;
314 ctx
->Const
.MaxLights
= 0;
315 ctx
->Const
.MaxTextureCoordUnits
= 0;
316 ctx
->Const
.MaxTextureUnits
= 0;
317 ctx
->Const
.MaxUniformBufferBindings
= 84;
318 ctx
->Const
.MaxVertexStreams
= 4;
319 ctx
->Const
.MaxTransformFeedbackBuffers
= 4;
321 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
= 16;
322 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxTextureImageUnits
= 16;
323 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxUniformComponents
= 1024;
324 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxCombinedUniformComponents
= 1024;
325 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxInputComponents
= 0; /* not used */
326 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxOutputComponents
= 16 * 4;
328 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxTextureImageUnits
= 16;
329 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxUniformComponents
= 224;
330 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxCombinedUniformComponents
= 224;
331 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxInputComponents
= 15 * 4;
332 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxOutputComponents
= 0; /* not used */
334 ctx
->Const
.MaxVarying
= ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxInputComponents
/ 4;
338 ctx
->Const
.GenerateTemporaryNames
= true;
339 ctx
->Const
.MaxPatchVertices
= 32;
341 /* GL_ARB_explicit_uniform_location, GL_MAX_UNIFORM_LOCATIONS */
342 ctx
->Const
.MaxUserAssignableUniformLocations
=
343 4 * MESA_SHADER_STAGES
* MAX_UNIFORMS
;
345 ctx
->Driver
.NewProgram
= new_program
;
348 /* Returned string will have 'ctx' as its ralloc owner. */
350 load_text_file(void *ctx
, const char *file_name
)
354 size_t total_read
= 0;
355 FILE *fp
= fopen(file_name
, "rb");
361 fseek(fp
, 0L, SEEK_END
);
363 fseek(fp
, 0L, SEEK_SET
);
365 text
= (char *) ralloc_size(ctx
, size
+ 1);
368 size_t bytes
= fread(text
+ total_read
,
369 1, size
- total_read
, fp
);
370 if (bytes
< size
- total_read
) {
381 } while (total_read
< size
);
383 text
[total_read
] = '\0';
393 compile_shader(struct gl_context
*ctx
, struct gl_shader
*shader
)
395 struct _mesa_glsl_parse_state
*state
=
396 new(shader
) _mesa_glsl_parse_state(ctx
, shader
->Stage
, shader
);
398 _mesa_glsl_compile_shader(ctx
, shader
, options
->dump_ast
,
399 options
->dump_hir
, true);
401 /* Print out the resulting IR */
402 if (!state
->error
&& options
->dump_lir
) {
403 _mesa_print_ir(stdout
, shader
->ir
, state
);
409 extern "C" struct gl_shader_program
*
410 standalone_compile_shader(const struct standalone_options
*_options
,
411 unsigned num_files
, char* const* files
, struct gl_context
*ctx
)
413 int status
= EXIT_SUCCESS
;
414 bool glsl_es
= false;
418 switch (options
->glsl_version
) {
439 fprintf(stderr
, "Unrecognized GLSL version `%d'\n", options
->glsl_version
);
444 initialize_context(ctx
, API_OPENGLES2
);
446 initialize_context(ctx
, options
->glsl_version
> 130 ? API_OPENGL_CORE
: API_OPENGL_COMPAT
);
449 if (options
->lower_precision
) {
450 for (unsigned i
= MESA_SHADER_VERTEX
; i
<= MESA_SHADER_FRAGMENT
; i
++) {
451 struct gl_shader_compiler_options
*options
=
452 &ctx
->Const
.ShaderCompilerOptions
[i
];
453 options
->LowerPrecision
= true;
457 struct gl_shader_program
*whole_program
;
459 whole_program
= rzalloc (NULL
, struct gl_shader_program
);
460 assert(whole_program
!= NULL
);
461 whole_program
->data
= rzalloc(whole_program
, struct gl_shader_program_data
);
462 assert(whole_program
->data
!= NULL
);
463 whole_program
->data
->InfoLog
= ralloc_strdup(whole_program
->data
, "");
465 /* Created just to avoid segmentation faults */
466 whole_program
->AttributeBindings
= new string_to_uint_map
;
467 whole_program
->FragDataBindings
= new string_to_uint_map
;
468 whole_program
->FragDataIndexBindings
= new string_to_uint_map
;
470 for (unsigned i
= 0; i
< num_files
; i
++) {
471 whole_program
->Shaders
=
472 reralloc(whole_program
, whole_program
->Shaders
,
473 struct gl_shader
*, whole_program
->NumShaders
+ 1);
474 assert(whole_program
->Shaders
!= NULL
);
476 struct gl_shader
*shader
= rzalloc(whole_program
, gl_shader
);
478 whole_program
->Shaders
[whole_program
->NumShaders
] = shader
;
479 whole_program
->NumShaders
++;
481 const unsigned len
= strlen(files
[i
]);
485 const char *const ext
= & files
[i
][len
- 5];
486 /* TODO add support to read a .shader_test */
487 if (strncmp(".vert", ext
, 5) == 0 || strncmp(".glsl", ext
, 5) == 0)
488 shader
->Type
= GL_VERTEX_SHADER
;
489 else if (strncmp(".tesc", ext
, 5) == 0)
490 shader
->Type
= GL_TESS_CONTROL_SHADER
;
491 else if (strncmp(".tese", ext
, 5) == 0)
492 shader
->Type
= GL_TESS_EVALUATION_SHADER
;
493 else if (strncmp(".geom", ext
, 5) == 0)
494 shader
->Type
= GL_GEOMETRY_SHADER
;
495 else if (strncmp(".frag", ext
, 5) == 0)
496 shader
->Type
= GL_FRAGMENT_SHADER
;
497 else if (strncmp(".comp", ext
, 5) == 0)
498 shader
->Type
= GL_COMPUTE_SHADER
;
501 shader
->Stage
= _mesa_shader_enum_to_shader_stage(shader
->Type
);
503 shader
->Source
= load_text_file(whole_program
, files
[i
]);
504 if (shader
->Source
== NULL
) {
505 printf("File \"%s\" does not exist.\n", files
[i
]);
509 compile_shader(ctx
, shader
);
511 if (strlen(shader
->InfoLog
) > 0) {
512 if (!options
->just_log
)
513 printf("Info log for %s:\n", files
[i
]);
515 printf("%s", shader
->InfoLog
);
516 if (!options
->just_log
)
520 if (!shader
->CompileStatus
) {
521 status
= EXIT_FAILURE
;
526 if (status
== EXIT_SUCCESS
) {
527 _mesa_clear_shader_program_data(ctx
, whole_program
);
529 if (options
->do_link
) {
530 link_shaders(ctx
, whole_program
);
532 const gl_shader_stage stage
= whole_program
->Shaders
[0]->Stage
;
534 whole_program
->data
->LinkStatus
= LINKING_SUCCESS
;
535 whole_program
->_LinkedShaders
[stage
] =
536 link_intrastage_shaders(whole_program
/* mem_ctx */,
539 whole_program
->Shaders
,
543 /* Par-linking can fail, for example, if there are undefined external
546 if (whole_program
->_LinkedShaders
[stage
] != NULL
) {
547 assert(whole_program
->data
->LinkStatus
);
549 struct gl_shader_compiler_options
*const compiler_options
=
550 &ctx
->Const
.ShaderCompilerOptions
[stage
];
552 exec_list
*const ir
=
553 whole_program
->_LinkedShaders
[stage
]->ir
;
557 progress
= do_function_inlining(ir
);
559 progress
= do_common_optimization(ir
,
569 status
= (whole_program
->data
->LinkStatus
) ? EXIT_SUCCESS
: EXIT_FAILURE
;
571 if (strlen(whole_program
->data
->InfoLog
) > 0) {
573 if (!options
->just_log
)
574 printf("Info log for linking:\n");
575 printf("%s", whole_program
->data
->InfoLog
);
576 if (!options
->just_log
)
580 for (unsigned i
= 0; i
< MESA_SHADER_STAGES
; i
++) {
581 struct gl_linked_shader
*shader
= whole_program
->_LinkedShaders
[i
];
586 add_neg_to_sub_visitor v
;
587 visit_list_elements(&v
, shader
->ir
);
589 dead_variable_visitor dv
;
590 visit_list_elements(&dv
, shader
->ir
);
591 dv
.remove_dead_variables();
594 if (options
->dump_builder
) {
595 for (unsigned i
= 0; i
< MESA_SHADER_STAGES
; i
++) {
596 struct gl_linked_shader
*shader
= whole_program
->_LinkedShaders
[i
];
601 _mesa_print_builder_for_ir(stdout
, shader
->ir
);
606 return whole_program
;
609 for (unsigned i
= 0; i
< MESA_SHADER_STAGES
; i
++) {
610 if (whole_program
->_LinkedShaders
[i
])
611 ralloc_free(whole_program
->_LinkedShaders
[i
]->Program
);
614 ralloc_free(whole_program
);
619 standalone_compiler_cleanup(struct gl_shader_program
*whole_program
)
621 for (unsigned i
= 0; i
< MESA_SHADER_STAGES
; i
++) {
622 if (whole_program
->_LinkedShaders
[i
])
623 ralloc_free(whole_program
->_LinkedShaders
[i
]->Program
);
626 delete whole_program
->AttributeBindings
;
627 delete whole_program
->FragDataBindings
;
628 delete whole_program
->FragDataIndexBindings
;
630 ralloc_free(whole_program
);
631 _mesa_glsl_builtin_functions_decref();