diff options
Diffstat (limited to 'src/glsl/main.cpp')
-rw-r--r-- | src/glsl/main.cpp | 82 |
1 files changed, 30 insertions, 52 deletions
diff --git a/src/glsl/main.cpp b/src/glsl/main.cpp index 36597d0bcd0..9b041aafe42 100644 --- a/src/glsl/main.cpp +++ b/src/glsl/main.cpp @@ -24,11 +24,6 @@ #include <cstdio> #include <getopt.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <unistd.h> - #include "ast.h" #include "glsl_parser_extras.h" #include "glsl_parser.h" @@ -111,38 +106,40 @@ static char * 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_t size; + size_t total_read = 0; + FILE *fp = fopen(file_name, "rb"); - if (fd < 0) { + if (!fp) { return NULL; } - if (fstat(fd, & st) == 0) { - text = (char *) talloc_size(ctx, st.st_size + 1); - if (text != NULL) { - do { - ssize_t bytes = read(fd, text + total_read, - st.st_size - total_read); - if (bytes < 0) { - free(text); - text = NULL; - break; - } - - if (bytes == 0) { - break; - } - - total_read += bytes; - } while (total_read < st.st_size); - - text[total_read] = '\0'; - } + fseek(fp, 0L, SEEK_END); + size = ftell(fp); + fseek(fp, 0L, SEEK_SET); + + text = (char *) talloc_size(ctx, size + 1); + if (text != NULL) { + do { + size_t bytes = fread(text + total_read, + 1, size - total_read, fp); + if (bytes < size - total_read) { + free(text); + text = NULL; + break; + } + + if (bytes == 0) { + break; + } + + total_read += bytes; + } while (total_read < size); + + text[total_read] = '\0'; } - close(fd); + fclose(fp); return text; } @@ -189,7 +186,7 @@ compile_shader(struct gl_context *ctx, struct gl_shader *shader) const char *source = shader->Source; state->error = preprocess(state, &source, &state->info_log, - state->extensions, ctx->API); + state->extensions, ctx->API) != 0; if (!state->error) { _mesa_glsl_lexer_ctor(state, source); @@ -219,26 +216,7 @@ compile_shader(struct gl_context *ctx, struct gl_shader *shader) 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(shader->ir) || progress; - progress = do_tree_grafting(shader->ir) || progress; - progress = do_constant_propagation(shader->ir) || progress; - progress = do_constant_variable_unlinked(shader->ir) || progress; - progress = do_constant_folding(shader->ir) || progress; - progress = do_algebraic(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; - - loop_state *ls = analyze_loop_variables(shader->ir); - progress = set_loop_controls(shader->ir, ls) || progress; - progress = unroll_loops(shader->ir, ls, 32) || progress; - delete ls; + progress = do_common_optimization(shader->ir, false, 32); } while (progress); validate_ir_tree(shader->ir); |