summaryrefslogtreecommitdiffstats
path: root/src/glsl
diff options
context:
space:
mode:
Diffstat (limited to 'src/glsl')
-rw-r--r--src/glsl/linker.cpp48
-rw-r--r--src/glsl/list.h19
-rw-r--r--src/glsl/main.cpp47
-rw-r--r--src/glsl/program.h22
4 files changed, 67 insertions, 69 deletions
diff --git a/src/glsl/linker.cpp b/src/glsl/linker.cpp
index 8547f74ce65..df71f21b546 100644
--- a/src/glsl/linker.cpp
+++ b/src/glsl/linker.cpp
@@ -128,10 +128,10 @@ linker_error_printf(glsl_program *prog, const char *fmt, ...)
void
-invalidate_variable_locations(glsl_shader *sh, enum ir_variable_mode mode,
+invalidate_variable_locations(gl_shader *sh, enum ir_variable_mode mode,
int generic_base)
{
- foreach_list(node, &sh->ir) {
+ foreach_list(node, sh->ir) {
ir_variable *const var = ((ir_instruction *) node)->as_variable();
if ((var == NULL) || (var->mode != (unsigned) mode))
@@ -187,7 +187,7 @@ count_attribute_slots(const glsl_type *t)
*/
bool
validate_vertex_shader_executable(struct glsl_program *prog,
- struct glsl_shader *shader)
+ struct gl_shader *shader)
{
if (shader == NULL)
return true;
@@ -198,7 +198,7 @@ validate_vertex_shader_executable(struct glsl_program *prog,
}
find_assignment_visitor find("gl_Position");
- find.run(&shader->ir);
+ find.run(shader->ir);
if (!find.variable_found()) {
linker_error_printf(prog,
"vertex shader does not write to `gl_Position'\n");
@@ -216,7 +216,7 @@ validate_vertex_shader_executable(struct glsl_program *prog,
*/
bool
validate_fragment_shader_executable(struct glsl_program *prog,
- struct glsl_shader *shader)
+ struct gl_shader *shader)
{
if (shader == NULL)
return true;
@@ -229,8 +229,8 @@ validate_fragment_shader_executable(struct glsl_program *prog,
find_assignment_visitor frag_color("gl_FragColor");
find_assignment_visitor frag_data("gl_FragData");
- frag_color.run(&shader->ir);
- frag_data.run(&shader->ir);
+ frag_color.run(shader->ir);
+ frag_data.run(shader->ir);
if (!frag_color.variable_found() && !frag_data.variable_found()) {
linker_error_printf(prog, "fragment shader does not write to "
@@ -259,7 +259,7 @@ cross_validate_uniforms(struct glsl_program *prog)
*/
glsl_symbol_table uniforms;
for (unsigned i = 0; i < prog->_NumLinkedShaders; i++) {
- foreach_list(node, &prog->_LinkedShaders[i]->ir) {
+ foreach_list(node, prog->_LinkedShaders[i]->ir) {
ir_variable *const var = ((ir_instruction *) node)->as_variable();
if ((var == NULL) || (var->mode != ir_var_uniform))
@@ -309,7 +309,7 @@ cross_validate_uniforms(struct glsl_program *prog)
*/
bool
cross_validate_outputs_to_inputs(struct glsl_program *prog,
- glsl_shader *producer, glsl_shader *consumer)
+ gl_shader *producer, gl_shader *consumer)
{
glsl_symbol_table parameters;
/* FINISHME: Figure these out dynamically. */
@@ -318,7 +318,7 @@ cross_validate_outputs_to_inputs(struct glsl_program *prog,
/* Find all shader outputs in the "producer" stage.
*/
- foreach_list(node, &producer->ir) {
+ foreach_list(node, producer->ir) {
ir_variable *const var = ((ir_instruction *) node)->as_variable();
/* FINISHME: For geometry shaders, this should also look for inout
@@ -335,7 +335,7 @@ cross_validate_outputs_to_inputs(struct glsl_program *prog,
* matching outputs already in the symbol table must have the same type and
* qualifiers.
*/
- foreach_list(node, &consumer->ir) {
+ foreach_list(node, consumer->ir) {
ir_variable *const input = ((ir_instruction *) node)->as_variable();
/* FINISHME: For geometry shaders, this should also look for inout
@@ -423,7 +423,7 @@ assign_uniform_locations(struct glsl_program *prog)
for (unsigned i = 0; i < prog->_NumLinkedShaders; i++) {
unsigned next_position = 0;
- foreach_list(node, &prog->_LinkedShaders[i]->ir) {
+ foreach_list(node, prog->_LinkedShaders[i]->ir) {
ir_variable *const var = ((ir_instruction *) node)->as_variable();
if ((var == NULL) || (var->mode != ir_var_uniform))
@@ -540,7 +540,7 @@ assign_attribute_locations(glsl_program *prog, unsigned max_attribute_index)
unsigned used_locations = (max_attribute_index >= 32)
? ~0 : ~((1 << max_attribute_index) - 1);
- glsl_shader *const sh = prog->_LinkedShaders[0];
+ gl_shader *const sh = prog->_LinkedShaders[0];
assert(sh->Type == GL_VERTEX_SHADER);
/* Operate in a total of four passes.
@@ -644,7 +644,7 @@ assign_attribute_locations(glsl_program *prog, unsigned max_attribute_index)
unsigned num_attr = 0;
- foreach_list(node, &sh->ir) {
+ foreach_list(node, sh->ir) {
ir_variable *const var = ((ir_instruction *) node)->as_variable();
if ((var == NULL) || (var->mode != ir_var_in))
@@ -694,7 +694,7 @@ assign_attribute_locations(glsl_program *prog, unsigned max_attribute_index)
void
-assign_varying_locations(glsl_shader *producer, glsl_shader *consumer)
+assign_varying_locations(gl_shader *producer, gl_shader *consumer)
{
/* FINISHME: Set dynamically when geometry shader support is added. */
unsigned output_index = VERT_RESULT_VAR0;
@@ -714,7 +714,7 @@ assign_varying_locations(glsl_shader *producer, glsl_shader *consumer)
invalidate_variable_locations(producer, ir_var_out, VERT_RESULT_VAR0);
invalidate_variable_locations(consumer, ir_var_in, FRAG_ATTRIB_VAR0);
- foreach_list(node, &producer->ir) {
+ foreach_list(node, producer->ir) {
ir_variable *const output_var = ((ir_instruction *) node)->as_variable();
if ((output_var == NULL) || (output_var->mode != ir_var_out)
@@ -740,7 +740,7 @@ assign_varying_locations(glsl_shader *producer, glsl_shader *consumer)
input_index++;
}
- foreach_list(node, &producer->ir) {
+ foreach_list(node, producer->ir) {
ir_variable *const var = ((ir_instruction *) node)->as_variable();
if ((var == NULL) || (var->mode != ir_var_out))
@@ -752,7 +752,7 @@ assign_varying_locations(glsl_shader *producer, glsl_shader *consumer)
var->shader_out = (var->location != -1);
}
- foreach_list(node, &consumer->ir) {
+ foreach_list(node, consumer->ir) {
ir_variable *const var = ((ir_instruction *) node)->as_variable();
if ((var == NULL) || (var->mode != ir_var_in))
@@ -780,13 +780,13 @@ link_shaders(struct glsl_program *prog)
/* Separate the shaders into groups based on their type.
*/
- struct glsl_shader **vert_shader_list;
+ struct gl_shader **vert_shader_list;
unsigned num_vert_shaders = 0;
- struct glsl_shader **frag_shader_list;
+ struct gl_shader **frag_shader_list;
unsigned num_frag_shaders = 0;
- vert_shader_list = (struct glsl_shader **)
- calloc(2 * prog->NumShaders, sizeof(struct glsl_shader *));
+ vert_shader_list = (struct gl_shader **)
+ calloc(2 * prog->NumShaders, sizeof(struct gl_shader *));
frag_shader_list = &vert_shader_list[prog->NumShaders];
for (unsigned i = 0; i < prog->NumShaders; i++) {
@@ -817,8 +817,8 @@ link_shaders(struct glsl_program *prog)
goto done;
- prog->_LinkedShaders = (struct glsl_shader **)
- calloc(2, sizeof(struct glsl_shader *));
+ prog->_LinkedShaders = (struct gl_shader **)
+ calloc(2, sizeof(struct gl_shader *));
prog->_NumLinkedShaders = 0;
if (num_vert_shaders > 0) {
diff --git a/src/glsl/list.h b/src/glsl/list.h
index 7732d66d7a6..d449bdd8b12 100644
--- a/src/glsl/list.h
+++ b/src/glsl/list.h
@@ -272,6 +272,25 @@ struct exec_list {
struct exec_node *tail_pred;
#ifdef __cplusplus
+ /* Callers of this talloc-based new need not call delete. It's
+ * easier to just talloc_free 'ctx' (or any of its ancestors). */
+ static void* operator new(size_t size, void *ctx)
+ {
+ void *node;
+
+ node = talloc_size(ctx, size);
+ assert(node != NULL);
+
+ return node;
+ }
+
+ /* If the user *does* call delete, that's OK, we will just
+ * talloc_free in that case. */
+ static void operator delete(void *node)
+ {
+ talloc_free(node);
+ }
+
exec_list()
{
make_empty();
diff --git a/src/glsl/main.cpp b/src/glsl/main.cpp
index f1dab7b576a..e78af42ac65 100644
--- a/src/glsl/main.cpp
+++ b/src/glsl/main.cpp
@@ -38,14 +38,13 @@
/* Returned string will have 'ctx' as its talloc owner. */
static char *
-load_text_file(void *ctx, const char *file_name, size_t *size)
+load_text_file(void *ctx, const char *file_name)
{
char *text = NULL;
struct stat st;
ssize_t total_read = 0;
int fd = open(file_name, O_RDONLY);
- *size = 0;
if (fd < 0) {
return NULL;
}
@@ -70,7 +69,6 @@ load_text_file(void *ctx, const char *file_name, size_t *size)
} while (total_read < st.st_size);
text[total_read] = '\0';
- *size = total_read;
}
}
@@ -102,7 +100,7 @@ const struct option compiler_opts[] = {
};
void
-compile_shader(struct glsl_shader *shader)
+compile_shader(struct gl_shader *shader)
{
struct _mesa_glsl_parse_state *state;
@@ -145,40 +143,40 @@ compile_shader(struct glsl_shader *shader)
printf("\n\n");
}
- shader->ir.make_empty();
+ shader->ir = new(shader) exec_list;
if (!state->error && !state->translation_unit.is_empty())
- _mesa_ast_to_hir(&shader->ir, state);
+ _mesa_ast_to_hir(shader->ir, state);
- validate_ir_tree(&shader->ir);
+ validate_ir_tree(shader->ir);
/* Print out the unoptimized IR. */
if (!state->error && dump_hir) {
- _mesa_print_ir(&shader->ir, state);
+ _mesa_print_ir(shader->ir, state);
}
/* Optimization passes */
- if (!state->error && !shader->ir.is_empty()) {
+ if (!state->error && !shader->ir->is_empty()) {
bool progress;
do {
progress = false;
- progress = do_function_inlining(&shader->ir) || progress;
- progress = do_if_simplification(&shader->ir) || progress;
- progress = do_copy_propagation(&shader->ir) || progress;
- progress = do_dead_code_local(&shader->ir) || progress;
- progress = do_dead_code_unlinked(state, &shader->ir) || progress;
- 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_swizzle_swizzle(&shader->ir) || progress;
+ progress = do_function_inlining(shader->ir) || progress;
+ progress = do_if_simplification(shader->ir) || progress;
+ progress = do_copy_propagation(shader->ir) || progress;
+ progress = do_dead_code_local(shader->ir) || progress;
+ progress = do_dead_code_unlinked(state, shader->ir) || progress;
+ 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_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) {
- _mesa_print_ir(&shader->ir, state);
+ _mesa_print_ir(shader->ir, state);
}
shader->symbols = state->symbols;
@@ -214,12 +212,12 @@ main(int argc, char **argv)
assert(whole_program != NULL);
for (/* empty */; argc > optind; optind++) {
- whole_program->Shaders = (struct glsl_shader **)
+ whole_program->Shaders = (struct gl_shader **)
talloc_realloc(whole_program, whole_program->Shaders,
- struct glsl_shader *, whole_program->NumShaders + 1);
+ struct gl_shader *, whole_program->NumShaders + 1);
assert(whole_program->Shaders != NULL);
- struct glsl_shader *shader = talloc_zero(whole_program, glsl_shader);
+ struct gl_shader *shader = talloc_zero(whole_program, gl_shader);
whole_program->Shaders[whole_program->NumShaders] = shader;
whole_program->NumShaders++;
@@ -238,8 +236,7 @@ main(int argc, char **argv)
else
usage_fail(argv[0]);
- shader->Source = load_text_file(whole_program,
- argv[optind], &shader->SourceLen);
+ shader->Source = load_text_file(whole_program, argv[optind]);
if (shader->Source == NULL) {
printf("File \"%s\" does not exist.\n", argv[optind]);
exit(EXIT_FAILURE);
diff --git a/src/glsl/program.h b/src/glsl/program.h
index fd8197a45a6..19c3a3e611b 100644
--- a/src/glsl/program.h
+++ b/src/glsl/program.h
@@ -30,24 +30,6 @@ extern "C" {
}
/**
- * Based on gl_shader in Mesa's mtypes.h.
- */
-struct glsl_shader {
- GLenum Type;
- GLuint Name;
- GLint RefCount;
- GLboolean DeletePending;
- GLboolean CompileStatus;
- const GLchar *Source; /**< Source code string */
- size_t SourceLen;
- GLchar *InfoLog;
-
- struct exec_list ir;
- struct glsl_symbol_table *symbols;
- struct gl_shader *mesa_shader;
-};
-
-/**
* Based on gl_shader_program in Mesa's mtypes.h.
*/
struct glsl_program {
@@ -57,14 +39,14 @@ struct glsl_program {
GLboolean DeletePending;
GLuint NumShaders; /**< number of attached shaders */
- struct glsl_shader **Shaders; /**< List of attached the shaders */
+ struct gl_shader **Shaders; /**< List of attached the shaders */
/**
* Per-stage shaders resulting from the first stage of linking.
*/
/*@{*/
unsigned _NumLinkedShaders;
- struct glsl_shader **_LinkedShaders;
+ struct gl_shader **_LinkedShaders;
/*@}*/
/** User-defined attribute bindings (glBindAttribLocation) */