<div dir="ltr">On 18 June 2013 02:10, Eric Anholt <span dir="ltr"><<a href="mailto:eric@anholt.net" target="_blank">eric@anholt.net</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
... and move the mesa-core-specific code into Mesa core. This code had no<br>
relation to ir_to_mesa.cpp, since it was also used by intel and<br>
state_tracker, and most of it was duplicated with the standalone compiler<br>
(which has periodically drifted from the Mesa copy).<br></blockquote><div><br></div><div>This patch is:<br><br></div><div>Acked-by: Paul Berry <<a href="mailto:stereotype441@gmail.com">stereotype441@gmail.com</a>><br>
<br></div><div>The remainder of the series is:<br><br>Reviewed-by: Paul Berry <<a href="mailto:stereotype441@gmail.com">stereotype441@gmail.com</a>><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
---<br>
src/glsl/glsl_parser_extras.cpp | 83 ++++++++++++++++++++++++++++++++++++<br>
src/glsl/glsl_parser_extras.h | 2 +<br>
src/glsl/main.cpp | 59 +-------------------------<br>
src/glsl/program.h | 16 ++++++-<br>
src/mesa/main/shaderapi.c | 57 ++++++++++++++++++++-----<br>
src/mesa/program/ir_to_mesa.cpp | 94 -----------------------------------------<br>
src/mesa/program/ir_to_mesa.h | 1 -<br>
7 files changed, 146 insertions(+), 166 deletions(-)<br>
<br>
diff --git a/src/glsl/glsl_parser_extras.cpp b/src/glsl/glsl_parser_extras.cpp<br>
index 7b827ba..f142d73 100644<br>
--- a/src/glsl/glsl_parser_extras.cpp<br>
+++ b/src/glsl/glsl_parser_extras.cpp<br>
@@ -28,6 +28,7 @@<br>
extern "C" {<br>
#include "main/core.h" /* for struct gl_context */<br>
#include "main/context.h"<br>
+#include "main/shaderobj.h"<br>
}<br>
<br>
#include "ralloc.h"<br>
@@ -1237,6 +1238,88 @@ ast_struct_specifier::ast_struct_specifier(const char *identifier,<br>
this->declarations.push_degenerate_list_at_head(&declarator_list->link);<br>
}<br>
<br>
+extern "C" {<br>
+<br>
+void<br>
+_mesa_glsl_compile_shader(struct gl_context *ctx, struct gl_shader *shader,<br>
+ bool dump_ast, bool dump_hir)<br>
+{<br>
+ struct _mesa_glsl_parse_state *state =<br>
+ new(shader) _mesa_glsl_parse_state(ctx, shader->Type, shader);<br>
+ const char *source = shader->Source;<br>
+<br>
+ state->error = glcpp_preprocess(state, &source, &state->info_log,<br>
+ &ctx->Extensions, ctx);<br>
+<br>
+ if (!state->error) {<br>
+ _mesa_glsl_lexer_ctor(state, source);<br>
+ _mesa_glsl_parse(state);<br>
+ _mesa_glsl_lexer_dtor(state);<br>
+ }<br>
+<br>
+ if (dump_ast) {<br>
+ foreach_list_const(n, &state->translation_unit) {<br>
+ ast_node *ast = exec_node_data(ast_node, n, link);<br>
+ ast->print();<br>
+ }<br>
+ printf("\n\n");<br>
+ }<br>
+<br>
+ ralloc_free(shader->ir);<br>
+ shader->ir = new(shader) exec_list;<br>
+ if (!state->error && !state->translation_unit.is_empty())<br>
+ _mesa_ast_to_hir(shader->ir, state);<br>
+<br>
+ if (!state->error) {<br>
+ validate_ir_tree(shader->ir);<br>
+<br>
+ /* Print out the unoptimized IR. */<br>
+ if (dump_hir) {<br>
+ _mesa_print_ir(shader->ir, state);<br>
+ }<br>
+ }<br>
+<br>
+<br>
+ if (!state->error && !shader->ir->is_empty()) {<br>
+ struct gl_shader_compiler_options *options =<br>
+ &ctx->ShaderCompilerOptions[_mesa_shader_type_to_index(shader->Type)];<br>
+<br>
+ /* Do some optimization at compile time to reduce shader IR size<br>
+ * and reduce later work if the same shader is linked multiple times<br>
+ */<br>
+ while (do_common_optimization(shader->ir, false, false, 32, options))<br>
+ ;<br>
+<br>
+ validate_ir_tree(shader->ir);<br>
+ }<br>
+<br>
+ if (shader->InfoLog)<br>
+ ralloc_free(shader->InfoLog);<br>
+<br>
+ shader->symbols = state->symbols;<br>
+ shader->CompileStatus = !state->error;<br>
+ shader->InfoLog = state->info_log;<br>
+ shader->Version = state->language_version;<br>
+ shader->InfoLog = state->info_log;<br>
+ shader->IsES = state->es_shader;<br>
+<br>
+ memcpy(shader->builtins_to_link, state->builtins_to_link,<br>
+ sizeof(shader->builtins_to_link[0]) * state->num_builtins_to_link);<br>
+ shader->num_builtins_to_link = state->num_builtins_to_link;<br>
+<br>
+ if (shader->UniformBlocks)<br>
+ ralloc_free(shader->UniformBlocks);<br>
+ shader->NumUniformBlocks = state->num_uniform_blocks;<br>
+ shader->UniformBlocks = state->uniform_blocks;<br>
+ ralloc_steal(shader, shader->UniformBlocks);<br>
+<br>
+ /* Retain any live IR, but trash the rest. */<br>
+ reparent_ir(shader->ir, shader->ir);<br>
+<br>
+ ralloc_free(state);<br>
+}<br>
+<br>
+} /* extern "C" */<br>
/**<br>
* Do the set of common optimizations passes<br>
*<br>
diff --git a/src/glsl/glsl_parser_extras.h b/src/glsl/glsl_parser_extras.h<br>
index 7f478df..cf296e9 100644<br>
--- a/src/glsl/glsl_parser_extras.h<br>
+++ b/src/glsl/glsl_parser_extras.h<br>
@@ -342,6 +342,8 @@ extern int _mesa_glsl_lex(union YYSTYPE *yylval, YYLTYPE *yylloc,<br>
<br>
extern int _mesa_glsl_parse(struct _mesa_glsl_parse_state *);<br>
<br>
+extern void compile_shader();<br>
+<br>
/**<br>
* Process elements of the #extension directive<br>
*<br>
diff --git a/src/glsl/main.cpp b/src/glsl/main.cpp<br>
index 5713ee5..60bc628 100644<br>
--- a/src/glsl/main.cpp<br>
+++ b/src/glsl/main.cpp<br>
@@ -143,70 +143,13 @@ compile_shader(struct gl_context *ctx, struct gl_shader *shader)<br>
struct _mesa_glsl_parse_state *state =<br>
new(shader) _mesa_glsl_parse_state(ctx, shader->Type, shader);<br>
<br>
- const char *source = shader->Source;<br>
- state->error = glcpp_preprocess(state, &source, &state->info_log,<br>
- state->extensions, ctx) != 0;<br>
-<br>
- if (!state->error) {<br>
- _mesa_glsl_lexer_ctor(state, source);<br>
- _mesa_glsl_parse(state);<br>
- _mesa_glsl_lexer_dtor(state);<br>
- }<br>
-<br>
- if (dump_ast) {<br>
- foreach_list_const(n, &state->translation_unit) {<br>
- ast_node *ast = exec_node_data(ast_node, n, link);<br>
- ast->print();<br>
- }<br>
- printf("\n\n");<br>
- }<br>
-<br>
- shader->ir = new(shader) exec_list;<br>
- if (!state->error && !state->translation_unit.is_empty())<br>
- _mesa_ast_to_hir(shader->ir, state);<br>
-<br>
- /* Print out the unoptimized IR. */<br>
- if (!state->error && dump_hir) {<br>
- validate_ir_tree(shader->ir);<br>
- _mesa_print_ir(shader->ir, state);<br>
- }<br>
-<br>
- /* Optimization passes */<br>
- if (!state->error && !shader->ir->is_empty()) {<br>
- const struct gl_shader_compiler_options *opts =<br>
- &ctx->ShaderCompilerOptions[_mesa_shader_type_to_index(shader->Type)];<br>
- bool progress;<br>
- do {<br>
- progress = do_common_optimization(shader->ir, false, false, 32, opts);<br>
- } while (progress);<br>
-<br>
- validate_ir_tree(shader->ir);<br>
- }<br>
-<br>
+ _mesa_glsl_compile_shader(ctx, shader, dump_ast, dump_hir);<br>
<br>
/* Print out the resulting IR */<br>
if (!state->error && dump_lir) {<br>
_mesa_print_ir(shader->ir, state);<br>
}<br>
<br>
- shader->symbols = state->symbols;<br>
- shader->CompileStatus = !state->error;<br>
- shader->Version = state->language_version;<br>
- shader->IsES = state->es_shader;<br>
- memcpy(shader->builtins_to_link, state->builtins_to_link,<br>
- sizeof(shader->builtins_to_link[0]) * state->num_builtins_to_link);<br>
- shader->num_builtins_to_link = state->num_builtins_to_link;<br>
-<br>
- if (shader->InfoLog)<br>
- ralloc_free(shader->InfoLog);<br>
-<br>
- shader->InfoLog = state->info_log;<br>
-<br>
- /* Retain any live IR, but trash the rest. */<br>
- reparent_ir(shader->ir, shader);<br>
-<br>
- ralloc_free(state);<br>
-<br>
return;<br>
}<br>
<br>
diff --git a/src/glsl/program.h b/src/glsl/program.h<br>
index 6a76d4d..f15113a 100644<br>
--- a/src/glsl/program.h<br>
+++ b/src/glsl/program.h<br>
@@ -24,15 +24,27 @@<br>
<br>
#include "main/core.h"<br>
<br>
+#ifdef __cplusplus<br>
+extern "C" {<br>
+#endif<br>
+<br>
+extern void<br>
+_mesa_glsl_compile_shader(struct gl_context *ctx, struct gl_shader *shader,<br>
+ bool dump_ast, bool dump_hir);<br>
+<br>
+#ifdef __cplusplus<br>
+} /* extern "C" */<br>
+#endif<br>
+<br>
extern void<br>
link_shaders(struct gl_context *ctx, struct gl_shader_program *prog);<br>
<br>
extern void<br>
-linker_error(gl_shader_program *prog, const char *fmt, ...)<br>
+linker_error(struct gl_shader_program *prog, const char *fmt, ...)<br>
PRINTFLIKE(2, 3);<br>
<br>
extern void<br>
-linker_warning(gl_shader_program *prog, const char *fmt, ...)<br>
+linker_warning(struct gl_shader_program *prog, const char *fmt, ...)<br>
PRINTFLIKE(2, 3);<br>
<br>
extern long<br>
diff --git a/src/mesa/main/shaderapi.c b/src/mesa/main/shaderapi.c<br>
index 88518ca..4f9e785 100644<br>
--- a/src/mesa/main/shaderapi.c<br>
+++ b/src/mesa/main/shaderapi.c<br>
@@ -48,11 +48,14 @@<br>
#include "main/transformfeedback.h"<br>
#include "main/uniforms.h"<br>
#include "program/program.h"<br>
+#include "program/prog_print.h"<br>
#include "program/prog_parameter.h"<br>
#include "ralloc.h"<br>
#include <stdbool.h><br>
#include "../glsl/glsl_parser_extras.h"<br>
+#include "../glsl/ir.h"<br>
#include "../glsl/ir_uniform.h"<br>
+#include "../glsl/program.h"<br>
<br>
/** Define this to enable shader substitution (see below) */<br>
#define SHADER_SUBST 0<br>
@@ -731,27 +734,59 @@ shader_source(struct gl_context *ctx, GLuint shader, const GLchar *source)<br>
static void<br>
compile_shader(struct gl_context *ctx, GLuint shaderObj)<br>
{<br>
- struct gl_shader *sh;<br>
+ struct gl_shader *shader;<br>
struct gl_shader_compiler_options *options;<br>
<br>
- sh = _mesa_lookup_shader_err(ctx, shaderObj, "glCompileShader");<br>
- if (!sh)<br>
+ shader = _mesa_lookup_shader_err(ctx, shaderObj, "glCompileShader");<br>
+ if (!shader)<br>
return;<br>
<br>
- options = &ctx->ShaderCompilerOptions[_mesa_shader_type_to_index(sh->Type)];<br>
+ options = &ctx->ShaderCompilerOptions[_mesa_shader_type_to_index(shader->Type)];<br>
<br>
/* set default pragma state for shader */<br>
- sh->Pragmas = options->DefaultPragmas;<br>
+ shader->Pragmas = options->DefaultPragmas;<br>
<br>
- /* this call will set the sh->CompileStatus field to indicate if<br>
- * compilation was successful.<br>
- */<br>
- _mesa_glsl_compile_shader(ctx, sh);<br>
+ if (!shader->Source) {<br>
+ /* If the user called glCompileShader without first calling<br>
+ * glShaderSource, we should fail to compile, but not raise a GL_ERROR.<br>
+ */<br>
+ shader->CompileStatus = GL_FALSE;<br>
+ } else {<br>
+ if (ctx->Shader.Flags & GLSL_DUMP) {<br>
+ printf("GLSL source for %s shader %d:\n",<br>
+ _mesa_glsl_shader_target_name(shader->Type), shader->Name);<br>
+ printf("%s\n", shader->Source);<br>
+ }<br>
+<br>
+ /* this call will set the shader->CompileStatus field to indicate if<br>
+ * compilation was successful.<br>
+ */<br>
+ _mesa_glsl_compile_shader(ctx, shader, false, false);<br>
+<br>
+ if (ctx->Shader.Flags & GLSL_LOG) {<br>
+ _mesa_write_shader_to_file(shader);<br>
+ }<br>
+<br>
+ if (ctx->Shader.Flags & GLSL_DUMP) {<br>
+ if (shader->CompileStatus) {<br>
+ printf("GLSL IR for shader %d:\n", shader->Name);<br>
+ _mesa_print_ir(shader->ir, NULL);<br>
+ printf("\n\n");<br>
+ } else {<br>
+ printf("GLSL shader %d failed to compile.\n", shader->Name);<br>
+ }<br>
+ if (shader->InfoLog && shader->InfoLog[0] != 0) {<br>
+ printf("GLSL shader %d info log:\n", shader->Name);<br>
+ printf("%s\n", shader->InfoLog);<br>
+ }<br>
+ }<br>
+<br>
+ }<br>
<br>
- if (sh->CompileStatus == GL_FALSE &&<br>
+ if (shader->CompileStatus == GL_FALSE &&<br>
(ctx->Shader.Flags & GLSL_REPORT_ERRORS)) {<br>
_mesa_debug(ctx, "Error compiling shader %u:\n%s\n",<br>
- sh->Name, sh->InfoLog);<br>
+ shader->Name, shader->InfoLog);<br>
}<br>
}<br>
<br>
diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp<br>
index a915974..35a9b84 100644<br>
--- a/src/mesa/program/ir_to_mesa.cpp<br>
+++ b/src/mesa/program/ir_to_mesa.cpp<br>
@@ -3097,100 +3097,6 @@ _mesa_ir_link_shader(struct gl_context *ctx, struct gl_shader_program *prog)<br>
return prog->LinkStatus;<br>
}<br>
<br>
-<br>
-/**<br>
- * Compile a GLSL shader. Called via glCompileShader().<br>
- */<br>
-void<br>
-_mesa_glsl_compile_shader(struct gl_context *ctx, struct gl_shader *shader)<br>
-{<br>
- struct _mesa_glsl_parse_state *state =<br>
- new(shader) _mesa_glsl_parse_state(ctx, shader->Type, shader);<br>
-<br>
- const char *source = shader->Source;<br>
- /* Check if the user called glCompileShader without first calling<br>
- * glShaderSource. This should fail to compile, but not raise a GL_ERROR.<br>
- */<br>
- if (source == NULL) {<br>
- shader->CompileStatus = GL_FALSE;<br>
- return;<br>
- }<br>
-<br>
- state->error = glcpp_preprocess(state, &source, &state->info_log,<br>
- &ctx->Extensions, ctx);<br>
-<br>
- if (ctx->Shader.Flags & GLSL_DUMP) {<br>
- printf("GLSL source for %s shader %d:\n",<br>
- _mesa_glsl_shader_target_name(state->target), shader->Name);<br>
- printf("%s\n", shader->Source);<br>
- }<br>
-<br>
- if (!state->error) {<br>
- _mesa_glsl_lexer_ctor(state, source);<br>
- _mesa_glsl_parse(state);<br>
- _mesa_glsl_lexer_dtor(state);<br>
- }<br>
-<br>
- ralloc_free(shader->ir);<br>
- shader->ir = new(shader) exec_list;<br>
- if (!state->error && !state->translation_unit.is_empty())<br>
- _mesa_ast_to_hir(shader->ir, state);<br>
-<br>
- if (!state->error && !shader->ir->is_empty()) {<br>
- validate_ir_tree(shader->ir);<br>
- struct gl_shader_compiler_options *options =<br>
- &ctx->ShaderCompilerOptions[_mesa_shader_type_to_index(shader->Type)];<br>
-<br>
- /* Do some optimization at compile time to reduce shader IR size<br>
- * and reduce later work if the same shader is linked multiple times<br>
- */<br>
- while (do_common_optimization(shader->ir, false, false, 32, options))<br>
- ;<br>
-<br>
- validate_ir_tree(shader->ir);<br>
- }<br>
-<br>
- shader->symbols = state->symbols;<br>
-<br>
- shader->CompileStatus = !state->error;<br>
- shader->InfoLog = state->info_log;<br>
- shader->Version = state->language_version;<br>
- shader->IsES = state->es_shader;<br>
- memcpy(shader->builtins_to_link, state->builtins_to_link,<br>
- sizeof(shader->builtins_to_link[0]) * state->num_builtins_to_link);<br>
- shader->num_builtins_to_link = state->num_builtins_to_link;<br>
-<br>
- if (ctx->Shader.Flags & GLSL_LOG) {<br>
- _mesa_write_shader_to_file(shader);<br>
- }<br>
-<br>
- if (ctx->Shader.Flags & GLSL_DUMP) {<br>
- if (shader->CompileStatus) {<br>
- printf("GLSL IR for shader %d:\n", shader->Name);<br>
- _mesa_print_ir(shader->ir, NULL);<br>
- printf("\n\n");<br>
- } else {<br>
- printf("GLSL shader %d failed to compile.\n", shader->Name);<br>
- }<br>
- if (shader->InfoLog && shader->InfoLog[0] != 0) {<br>
- printf("GLSL shader %d info log:\n", shader->Name);<br>
- printf("%s\n", shader->InfoLog);<br>
- }<br>
- }<br>
-<br>
- if (shader->UniformBlocks)<br>
- ralloc_free(shader->UniformBlocks);<br>
- shader->NumUniformBlocks = state->num_uniform_blocks;<br>
- shader->UniformBlocks = state->uniform_blocks;<br>
- ralloc_steal(shader, shader->UniformBlocks);<br>
-<br>
- /* Retain any live IR, but trash the rest. */<br>
- reparent_ir(shader->ir, shader->ir);<br>
-<br>
- ralloc_free(state);<br>
-}<br>
-<br>
-<br>
/**<br>
* Link a GLSL shader program. Called via glLinkProgram().<br>
*/<br>
diff --git a/src/mesa/program/ir_to_mesa.h b/src/mesa/program/ir_to_mesa.h<br>
index aa053d9..2488a45 100644<br>
--- a/src/mesa/program/ir_to_mesa.h<br>
+++ b/src/mesa/program/ir_to_mesa.h<br>
@@ -33,7 +33,6 @@ struct gl_context;<br>
struct gl_shader;<br>
struct gl_shader_program;<br>
<br>
-void _mesa_glsl_compile_shader(struct gl_context *ctx, struct gl_shader *sh);<br>
void _mesa_glsl_link_shader(struct gl_context *ctx, struct gl_shader_program *prog);<br>
GLboolean _mesa_ir_compile_shader(struct gl_context *ctx, struct gl_shader *shader);<br>
GLboolean _mesa_ir_link_shader(struct gl_context *ctx, struct gl_shader_program *prog);<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.8.3.rc0<br>
<br>
_______________________________________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/mesa-dev" target="_blank">http://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
</font></span></blockquote></div><br></div></div>