#include "ir_print_visitor.h"
#include "program.h"
+extern "C" struct gl_shader *
+_mesa_new_shader(GLcontext *ctx, GLuint name, GLenum type);
+
+/* Copied from shader_api.c for the stand-alone compiler.
+ */
+struct gl_shader *
+_mesa_new_shader(GLcontext *ctx, GLuint name, GLenum type)
+{
+ struct gl_shader *shader;
+ assert(type == GL_FRAGMENT_SHADER || type == GL_VERTEX_SHADER);
+ shader = talloc_zero(NULL, struct gl_shader);
+ if (shader) {
+ shader->Type = type;
+ shader->Name = name;
+ shader->RefCount = 1;
+ }
+ return shader;
+}
+
/* Returned string will have 'ctx' as its talloc owner. */
static char *
load_text_file(void *ctx, const char *file_name)
compile_shader(struct gl_shader *shader)
{
struct _mesa_glsl_parse_state *state;
+ struct gl_extensions ext;
state = talloc_zero(talloc_parent(shader), struct _mesa_glsl_parse_state);
state->symbols = new(shader) glsl_symbol_table;
state->info_log = talloc_strdup(shader, "");
state->error = false;
- state->temp_index = 0;
state->loop_or_switch_nesting = NULL;
state->ARB_texture_rectangle_enable = true;
+ memset(&ext, 0, sizeof(ext));
+ state->extensions = &ext;
+ /* 1.10 minimums. */
+ state->Const.MaxLights = 8;
+ state->Const.MaxClipPlanes = 8;
+ state->Const.MaxTextureUnits = 2;
+
+ /* More than the 1.10 minimum to appease parser tests taken from
+ * apps that (hopefully) already checked the number of coords.
+ */
+ state->Const.MaxTextureCoords = 4;
+
+ state->Const.MaxVertexAttribs = 16;
+ state->Const.MaxVertexUniformComponents = 512;
+ state->Const.MaxVaryingFloats = 32;
+ state->Const.MaxVertexTextureImageUnits = 0;
+ state->Const.MaxCombinedTextureImageUnits = 2;
+ state->Const.MaxTextureImageUnits = 2;
+ state->Const.MaxFragmentUniformComponents = 64;
+
state->Const.MaxDrawBuffers = 2;
- /* Create a new context for the preprocessor output. Ultimately, this
- * should probably be the parser context, but there isn't one yet.
- */
const char *source = shader->Source;
- state->error = preprocess(shader, &source, &state->info_log);
+ state->error = preprocess(state, &source, &state->info_log, &ext);
if (!state->error) {
_mesa_glsl_lexer_ctor(state, source);
if (!state->error && !state->translation_unit.is_empty())
_mesa_ast_to_hir(shader->ir, state);
- validate_ir_tree(shader->ir);
-
/* Print out the unoptimized IR. */
if (!state->error && dump_hir) {
+ validate_ir_tree(shader->ir);
_mesa_print_ir(shader->ir, state);
}
progress = do_constant_variable_unlinked(shader->ir) || progress;
progress = do_constant_folding(shader->ir) || progress;
progress = do_vec_index_to_swizzle(shader->ir) || progress;
+ progress = do_vec_index_to_cond_assign(shader->ir) || progress;
progress = do_swizzle_swizzle(shader->ir) || progress;
} while (progress);
+
+ validate_ir_tree(shader->ir);
}
- validate_ir_tree(shader->ir);
/* Print out the resulting IR */
if (!state->error && dump_lir) {
shader->symbols = state->symbols;
shader->CompileStatus = !state->error;
+ shader->Version = state->language_version;
+ memcpy(shader->builtins_to_link, state->builtins_to_link,
+ sizeof(shader->builtins_to_link[0]) * state->num_builtins_to_link);
+ shader->num_builtins_to_link = state->num_builtins_to_link;
if (shader->InfoLog)
talloc_free(shader->InfoLog);
shader->InfoLog = state->info_log;
+ /* Retain any live IR, but trash the rest. */
+ reparent_ir(shader->ir, shader);
+
talloc_free(state);
return;
if (argc <= optind)
usage_fail(argv[0]);
- struct glsl_program *whole_program;
+ struct gl_shader_program *whole_program;
- whole_program = talloc_zero (NULL, struct glsl_program);
+ whole_program = talloc_zero (NULL, struct gl_shader_program);
assert(whole_program != NULL);
for (/* empty */; argc > optind; optind++) {
if ((status == EXIT_SUCCESS) && do_link) {
link_shaders(whole_program);
status = (whole_program->LinkStatus) ? EXIT_SUCCESS : EXIT_FAILURE;
+
+ if (strlen(whole_program->InfoLog) > 0)
+ printf("Info log for linking:\n%s\n", whole_program->InfoLog);
}
+ for (unsigned i = 0; i < whole_program->_NumLinkedShaders; i++)
+ talloc_free(whole_program->_LinkedShaders[i]);
+
talloc_free(whole_program);
_mesa_glsl_release_types();
+ _mesa_glsl_release_functions();
return status;
}