diff options
author | Thomas Balling Sørensen <tball@tball-laptop.(none)> | 2010-10-26 12:49:41 +0200 |
---|---|---|
committer | Thomas Balling Sørensen <tball@tball-laptop.(none)> | 2010-10-26 12:49:41 +0200 |
commit | dbf3a15313eed930a3d8fdde12e457259c43651b (patch) | |
tree | 78bc54fa866ff1e97e61802f52dabe3f4f3380b1 /src/mesa/program | |
parent | 1dccc4cfaa423f15ab582d2a0253a84a0ae0b9fa (diff) | |
parent | 547e7619aac74ae13bdaa7fdf403a4ceb5212467 (diff) |
Merge branch 'master' into pipe-video
Conflicts:
src/gallium/include/pipe/p_format.h
Diffstat (limited to 'src/mesa/program')
28 files changed, 224 insertions, 128 deletions
diff --git a/src/mesa/program/arbprogparse.c b/src/mesa/program/arbprogparse.c index f834aaf5686..ca63e72c085 100644 --- a/src/mesa/program/arbprogparse.c +++ b/src/mesa/program/arbprogparse.c @@ -64,7 +64,7 @@ having three separate program parameter arrays. void -_mesa_parse_arb_fragment_program(GLcontext* ctx, GLenum target, +_mesa_parse_arb_fragment_program(struct gl_context* ctx, GLenum target, const GLvoid *str, GLsizei len, struct gl_fragment_program *program) { @@ -162,7 +162,7 @@ _mesa_parse_arb_fragment_program(GLcontext* ctx, GLenum target, * object unchanged. */ void -_mesa_parse_arb_vertex_program(GLcontext *ctx, GLenum target, +_mesa_parse_arb_vertex_program(struct gl_context *ctx, GLenum target, const GLvoid *str, GLsizei len, struct gl_vertex_program *program) { diff --git a/src/mesa/program/arbprogparse.h b/src/mesa/program/arbprogparse.h index 980d39fb9fe..08e25a1c168 100644 --- a/src/mesa/program/arbprogparse.h +++ b/src/mesa/program/arbprogparse.h @@ -29,12 +29,12 @@ #include "main/mtypes.h" extern void -_mesa_parse_arb_vertex_program(GLcontext *ctx, GLenum target, +_mesa_parse_arb_vertex_program(struct gl_context *ctx, GLenum target, const GLvoid *str, GLsizei len, struct gl_vertex_program *program); extern void -_mesa_parse_arb_fragment_program(GLcontext *ctx, GLenum target, +_mesa_parse_arb_fragment_program(struct gl_context *ctx, GLenum target, const GLvoid *str, GLsizei len, struct gl_fragment_program *program); diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp index 5c92bc9865d..bdd3fd92ffc 100644 --- a/src/mesa/program/ir_to_mesa.cpp +++ b/src/mesa/program/ir_to_mesa.cpp @@ -26,8 +26,7 @@ /** * \file ir_to_mesa.cpp * - * Translates the IR to ARB_fragment_program text if possible, - * printing the result + * Translate GLSL IR to Mesa's gl_program representation. */ #include <stdio.h> @@ -184,7 +183,7 @@ public: function_entry *current_function; - GLcontext *ctx; + struct gl_context *ctx; struct gl_program *prog; struct gl_shader_program *shader_program; struct gl_shader_compiler_options *options; @@ -288,19 +287,22 @@ ir_to_mesa_dst_reg ir_to_mesa_address_reg = { PROGRAM_ADDRESS, 0, WRITEMASK_X, COND_TR, NULL }; -static void fail_link(struct gl_shader_program *prog, const char *fmt, ...) PRINTFLIKE(2, 3); +static void +fail_link(struct gl_shader_program *prog, const char *fmt, ...) PRINTFLIKE(2, 3); -static void fail_link(struct gl_shader_program *prog, const char *fmt, ...) - { - va_list args; - va_start(args, fmt); - prog->InfoLog = talloc_vasprintf_append(prog->InfoLog, fmt, args); - va_end(args); +static void +fail_link(struct gl_shader_program *prog, const char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + prog->InfoLog = talloc_vasprintf_append(prog->InfoLog, fmt, args); + va_end(args); - prog->LinkStatus = GL_FALSE; - } + prog->LinkStatus = GL_FALSE; +} -static int swizzle_for_size(int size) +static int +swizzle_for_size(int size) { int size_swizzles[4] = { MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_X, SWIZZLE_X, SWIZZLE_X), @@ -309,6 +311,7 @@ static int swizzle_for_size(int size) MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_W), }; + assert((size >= 1) && (size <= 4)); return size_swizzles[size - 1]; } @@ -1127,6 +1130,7 @@ ir_to_mesa_visitor::visit(ir_expression *ir) case ir_binop_bit_and: case ir_binop_bit_xor: case ir_binop_bit_or: + case ir_unop_round_even: assert(!"GLSL 1.30 features unsupported"); break; } @@ -2159,7 +2163,7 @@ add_uniforms_to_parameters_list(struct gl_shader_program *shader_program, } static void -set_uniform_initializer(GLcontext *ctx, void *mem_ctx, +set_uniform_initializer(struct gl_context *ctx, void *mem_ctx, struct gl_shader_program *shader_program, const char *name, const glsl_type *type, ir_constant *val) @@ -2229,13 +2233,17 @@ set_uniform_initializer(GLcontext *ctx, void *mem_ctx, } static void -set_uniform_initializers(GLcontext *ctx, +set_uniform_initializers(struct gl_context *ctx, struct gl_shader_program *shader_program) { void *mem_ctx = NULL; - for (unsigned int i = 0; i < shader_program->_NumLinkedShaders; i++) { + for (unsigned int i = 0; i < MESA_SHADER_TYPES; i++) { struct gl_shader *shader = shader_program->_LinkedShaders[i]; + + if (shader == NULL) + continue; + foreach_iter(exec_list_iterator, iter, *shader->ir) { ir_instruction *ir = (ir_instruction *)iter.get(); ir_variable *var = ir->as_variable(); @@ -2254,8 +2262,12 @@ set_uniform_initializers(GLcontext *ctx, talloc_free(mem_ctx); } + +/** + * Convert a shader's GLSL IR into a Mesa gl_program. + */ struct gl_program * -get_mesa_program(GLcontext *ctx, struct gl_shader_program *shader_program, +get_mesa_program(struct gl_context *ctx, struct gl_shader_program *shader_program, struct gl_shader *shader) { ir_to_mesa_visitor v; @@ -2344,10 +2356,12 @@ get_mesa_program(GLcontext *ctx, struct gl_shader_program *shader_program, mesa_instruction_annotation = talloc_array(v.mem_ctx, ir_instruction *, num_instructions); + /* Convert ir_mesa_instructions into prog_instructions. + */ mesa_inst = mesa_instructions; i = 0; foreach_iter(exec_list_iterator, iter, v.instructions) { - ir_to_mesa_instruction *inst = (ir_to_mesa_instruction *)iter.get(); + const ir_to_mesa_instruction *inst = (ir_to_mesa_instruction *)iter.get(); mesa_inst->Opcode = inst->op; mesa_inst->CondUpdate = inst->cond_update; @@ -2368,6 +2382,7 @@ get_mesa_program(GLcontext *ctx, struct gl_shader_program *shader_program, if (mesa_inst->DstReg.RelAddr) prog->IndirectRegisterFiles |= 1 << mesa_inst->DstReg.File; + /* Update program's bitmask of indirectly accessed register files */ for (unsigned src = 0; src < 3; src++) if (mesa_inst->SrcReg[src].RelAddr) prog->IndirectRegisterFiles |= 1 << mesa_inst->SrcReg[src].File; @@ -2429,8 +2444,14 @@ get_mesa_program(GLcontext *ctx, struct gl_shader_program *shader_program, } extern "C" { + +/** + * Called via ctx->Driver.CompilerShader(). + * This is a no-op. + * XXX can we remove the ctx->Driver.CompileShader() hook? + */ GLboolean -_mesa_ir_compile_shader(GLcontext *ctx, struct gl_shader *shader) +_mesa_ir_compile_shader(struct gl_context *ctx, struct gl_shader *shader) { assert(shader->CompileStatus); (void) ctx; @@ -2438,15 +2459,25 @@ _mesa_ir_compile_shader(GLcontext *ctx, struct gl_shader *shader) return GL_TRUE; } + +/** + * Link a shader. + * Called via ctx->Driver.LinkShader() + * This actually involves converting GLSL IR into Mesa gl_programs with + * code lowering and other optimizations. + */ GLboolean -_mesa_ir_link_shader(GLcontext *ctx, struct gl_shader_program *prog) +_mesa_ir_link_shader(struct gl_context *ctx, struct gl_shader_program *prog) { assert(prog->LinkStatus); - for (unsigned i = 0; i < prog->_NumLinkedShaders; i++) { + for (unsigned i = 0; i < MESA_SHADER_TYPES; i++) { + if (prog->_LinkedShaders[i] == NULL) + continue; + bool progress; exec_list *ir = prog->_LinkedShaders[i]->ir; - struct gl_shader_compiler_options *options = + const struct gl_shader_compiler_options *options = &ctx->ShaderCompilerOptions[_mesa_shader_type_to_index(prog->_LinkedShaders[i]->Type)]; do { @@ -2487,10 +2518,13 @@ _mesa_ir_link_shader(GLcontext *ctx, struct gl_shader_program *prog) validate_ir_tree(ir); } - for (unsigned i = 0; i < prog->_NumLinkedShaders; i++) { + for (unsigned i = 0; i < MESA_SHADER_TYPES; i++) { struct gl_program *linked_prog; bool ok = true; + if (prog->_LinkedShaders[i] == NULL) + continue; + linked_prog = get_mesa_program(ctx, prog, prog->_LinkedShaders[i]); switch (prog->_LinkedShaders[i]->Type) { @@ -2516,8 +2550,12 @@ _mesa_ir_link_shader(GLcontext *ctx, struct gl_shader_program *prog) return GL_TRUE; } + +/** + * Compile a GLSL shader. Called via glCompileShader(). + */ void -_mesa_glsl_compile_shader(GLcontext *ctx, struct gl_shader *shader) +_mesa_glsl_compile_shader(struct gl_context *ctx, struct gl_shader *shader) { struct _mesa_glsl_parse_state *state = new(shader) _mesa_glsl_parse_state(ctx, shader->Type, shader); @@ -2600,8 +2638,12 @@ _mesa_glsl_compile_shader(GLcontext *ctx, struct gl_shader *shader) } } + +/** + * Link a GLSL shader program. Called via glLinkProgram(). + */ void -_mesa_glsl_link_shader(GLcontext *ctx, struct gl_shader_program *prog) +_mesa_glsl_link_shader(struct gl_context *ctx, struct gl_shader_program *prog) { unsigned int i; diff --git a/src/mesa/program/ir_to_mesa.h b/src/mesa/program/ir_to_mesa.h index ecaacde4bb0..7197615f949 100644 --- a/src/mesa/program/ir_to_mesa.h +++ b/src/mesa/program/ir_to_mesa.h @@ -28,10 +28,10 @@ extern "C" { #include "main/config.h" #include "main/mtypes.h" -void _mesa_glsl_compile_shader(GLcontext *ctx, struct gl_shader *sh); -void _mesa_glsl_link_shader(GLcontext *ctx, struct gl_shader_program *prog); -GLboolean _mesa_ir_compile_shader(GLcontext *ctx, struct gl_shader *shader); -GLboolean _mesa_ir_link_shader(GLcontext *ctx, struct gl_shader_program *prog); +void _mesa_glsl_compile_shader(struct gl_context *ctx, struct gl_shader *sh); +void _mesa_glsl_link_shader(struct gl_context *ctx, struct gl_shader_program *prog); +GLboolean _mesa_ir_compile_shader(struct gl_context *ctx, struct gl_shader *shader); +GLboolean _mesa_ir_link_shader(struct gl_context *ctx, struct gl_shader_program *prog); #ifdef __cplusplus } diff --git a/src/mesa/program/nvfragparse.c b/src/mesa/program/nvfragparse.c index 0de3c5804d2..8516b5fc1ff 100644 --- a/src/mesa/program/nvfragparse.c +++ b/src/mesa/program/nvfragparse.c @@ -141,7 +141,7 @@ static const struct instruction_pattern Instructions[] = { * _successfully_ parsed the program text. */ struct parse_state { - GLcontext *ctx; + struct gl_context *ctx; const GLubyte *start; /* start of program string */ const GLubyte *pos; /* current position */ const GLubyte *curLine; @@ -1463,7 +1463,7 @@ Parse_InstructionSequence(struct parse_state *parseState, * indicates the position of the error in 'str'. */ void -_mesa_parse_nv_fragment_program(GLcontext *ctx, GLenum dstTarget, +_mesa_parse_nv_fragment_program(struct gl_context *ctx, GLenum dstTarget, const GLubyte *str, GLsizei len, struct gl_fragment_program *program) { diff --git a/src/mesa/program/nvfragparse.h b/src/mesa/program/nvfragparse.h index e28a6c49349..3e85dd2c30b 100644 --- a/src/mesa/program/nvfragparse.h +++ b/src/mesa/program/nvfragparse.h @@ -33,7 +33,7 @@ #include "main/mtypes.h" extern void -_mesa_parse_nv_fragment_program(GLcontext *ctx, GLenum target, +_mesa_parse_nv_fragment_program(struct gl_context *ctx, GLenum target, const GLubyte *str, GLsizei len, struct gl_fragment_program *program); diff --git a/src/mesa/program/nvvertparse.c b/src/mesa/program/nvvertparse.c index 1ac83d0e59d..bdd44a45133 100644 --- a/src/mesa/program/nvvertparse.c +++ b/src/mesa/program/nvvertparse.c @@ -54,7 +54,7 @@ * program attributes. */ struct parse_state { - GLcontext *ctx; + struct gl_context *ctx; const GLubyte *start; const GLubyte *pos; const GLubyte *curLine; @@ -1282,7 +1282,7 @@ Parse_Program(struct parse_state *parseState, * indicates the position of the error in 'str'. */ void -_mesa_parse_nv_vertex_program(GLcontext *ctx, GLenum dstTarget, +_mesa_parse_nv_vertex_program(struct gl_context *ctx, GLenum dstTarget, const GLubyte *str, GLsizei len, struct gl_vertex_program *program) { diff --git a/src/mesa/program/nvvertparse.h b/src/mesa/program/nvvertparse.h index 91ef79e6c3c..e98e867320f 100644 --- a/src/mesa/program/nvvertparse.h +++ b/src/mesa/program/nvvertparse.h @@ -32,7 +32,7 @@ #include "main/mtypes.h" extern void -_mesa_parse_nv_vertex_program(GLcontext *ctx, GLenum target, +_mesa_parse_nv_vertex_program(struct gl_context *ctx, GLenum target, const GLubyte *str, GLsizei len, struct gl_vertex_program *program); diff --git a/src/mesa/program/prog_cache.c b/src/mesa/program/prog_cache.c index 8af689754bb..56ca59890de 100644 --- a/src/mesa/program/prog_cache.c +++ b/src/mesa/program/prog_cache.c @@ -104,7 +104,7 @@ rehash(struct gl_program_cache *cache) static void -clear_cache(GLcontext *ctx, struct gl_program_cache *cache) +clear_cache(struct gl_context *ctx, struct gl_program_cache *cache) { struct cache_item *c, *next; GLuint i; @@ -145,7 +145,7 @@ _mesa_new_program_cache(void) void -_mesa_delete_program_cache(GLcontext *ctx, struct gl_program_cache *cache) +_mesa_delete_program_cache(struct gl_context *ctx, struct gl_program_cache *cache) { clear_cache(ctx, cache); free(cache->items); @@ -178,7 +178,7 @@ _mesa_search_program_cache(struct gl_program_cache *cache, void -_mesa_program_cache_insert(GLcontext *ctx, +_mesa_program_cache_insert(struct gl_context *ctx, struct gl_program_cache *cache, const void *key, GLuint keysize, struct gl_program *program) diff --git a/src/mesa/program/prog_cache.h b/src/mesa/program/prog_cache.h index bfe8f99d445..4907ae3030e 100644 --- a/src/mesa/program/prog_cache.h +++ b/src/mesa/program/prog_cache.h @@ -41,7 +41,7 @@ extern struct gl_program_cache * _mesa_new_program_cache(void); extern void -_mesa_delete_program_cache(GLcontext *ctx, struct gl_program_cache *pc); +_mesa_delete_program_cache(struct gl_context *ctx, struct gl_program_cache *pc); extern struct gl_program * @@ -49,7 +49,7 @@ _mesa_search_program_cache(struct gl_program_cache *cache, const void *key, GLuint keysize); extern void -_mesa_program_cache_insert(GLcontext *ctx, +_mesa_program_cache_insert(struct gl_context *ctx, struct gl_program_cache *cache, const void *key, GLuint keysize, struct gl_program *program); diff --git a/src/mesa/program/prog_execute.c b/src/mesa/program/prog_execute.c index 2ae5bc572af..1d97a077f52 100644 --- a/src/mesa/program/prog_execute.c +++ b/src/mesa/program/prog_execute.c @@ -296,7 +296,7 @@ fetch_vector4ui(const struct prog_src_register *source, * XXX this currently only works for fragment program input attribs. */ static void -fetch_vector4_deriv(GLcontext * ctx, +fetch_vector4_deriv(struct gl_context * ctx, const struct prog_src_register *source, const struct gl_program_machine *machine, char xOrY, GLfloat result[4]) @@ -380,7 +380,7 @@ fetch_vector1ui(const struct prog_src_register *source, * Fetch texel from texture. Use partial derivatives when possible. */ static INLINE void -fetch_texel(GLcontext *ctx, +fetch_texel(struct gl_context *ctx, const struct gl_program_machine *machine, const struct prog_instruction *inst, const GLfloat texcoord[4], GLfloat lodBias, @@ -630,7 +630,7 @@ store_vector4ui(const struct prog_instruction *inst, * \return GL_TRUE if program completed or GL_FALSE if program executed KIL. */ GLboolean -_mesa_execute_program(GLcontext * ctx, +_mesa_execute_program(struct gl_context * ctx, const struct gl_program *program, struct gl_program_machine *machine) { diff --git a/src/mesa/program/prog_execute.h b/src/mesa/program/prog_execute.h index f59b65176ff..cefd468c36b 100644 --- a/src/mesa/program/prog_execute.h +++ b/src/mesa/program/prog_execute.h @@ -29,10 +29,10 @@ #include "main/mtypes.h" -typedef void (*FetchTexelLodFunc)(GLcontext *ctx, const GLfloat texcoord[4], +typedef void (*FetchTexelLodFunc)(struct gl_context *ctx, const GLfloat texcoord[4], GLfloat lambda, GLuint unit, GLfloat color[4]); -typedef void (*FetchTexelDerivFunc)(GLcontext *ctx, const GLfloat texcoord[4], +typedef void (*FetchTexelDerivFunc)(struct gl_context *ctx, const GLfloat texcoord[4], const GLfloat texdx[4], const GLfloat texdy[4], GLfloat lodBias, @@ -74,11 +74,11 @@ struct gl_program_machine extern void -_mesa_get_program_register(GLcontext *ctx, gl_register_file file, +_mesa_get_program_register(struct gl_context *ctx, gl_register_file file, GLuint index, GLfloat val[4]); extern GLboolean -_mesa_execute_program(GLcontext *ctx, +_mesa_execute_program(struct gl_context *ctx, const struct gl_program *program, struct gl_program_machine *machine); diff --git a/src/mesa/program/prog_optimize.c b/src/mesa/program/prog_optimize.c index 0dc779073db..96971f2eda4 100644 --- a/src/mesa/program/prog_optimize.c +++ b/src/mesa/program/prog_optimize.c @@ -1216,7 +1216,7 @@ _mesa_reallocate_registers(struct gl_program *prog) #if 0 static void -print_it(GLcontext *ctx, struct gl_program *program, const char *txt) { +print_it(struct gl_context *ctx, struct gl_program *program, const char *txt) { fprintf(stderr, "%s (%u inst):\n", txt, program->NumInstructions); _mesa_print_program(program); _mesa_print_program_parameters(ctx, program); @@ -1230,7 +1230,7 @@ print_it(GLcontext *ctx, struct gl_program *program, const char *txt) { * instructions, temp regs, etc. */ void -_mesa_optimize_program(GLcontext *ctx, struct gl_program *program) +_mesa_optimize_program(struct gl_context *ctx, struct gl_program *program) { GLboolean any_change; diff --git a/src/mesa/program/prog_optimize.h b/src/mesa/program/prog_optimize.h index 06cd9cb2c20..00f1080449b 100644 --- a/src/mesa/program/prog_optimize.h +++ b/src/mesa/program/prog_optimize.h @@ -41,6 +41,6 @@ _mesa_find_temp_intervals(const struct prog_instruction *instructions, GLint intEnd[MAX_PROGRAM_TEMPS]); extern void -_mesa_optimize_program(GLcontext *ctx, struct gl_program *program); +_mesa_optimize_program(struct gl_context *ctx, struct gl_program *program); #endif diff --git a/src/mesa/program/prog_parameter.c b/src/mesa/program/prog_parameter.c index 6bf8a081b02..3570cab118b 100644 --- a/src/mesa/program/prog_parameter.c +++ b/src/mesa/program/prog_parameter.c @@ -378,18 +378,9 @@ _mesa_add_state_reference(struct gl_program_parameter_list *paramList, /* Check if the state reference is already in the list */ for (index = 0; index < (GLint) paramList->NumParameters; index++) { - GLuint i, match = 0; - for (i = 0; i < STATE_LENGTH; i++) { - if (paramList->Parameters[index].StateIndexes[i] == stateTokens[i]) { - match++; - } - else { - break; - } - } - if (match == STATE_LENGTH) { - /* this state reference is already in the parameter list */ - return index; + if (!memcmp(paramList->Parameters[index].StateIndexes, + stateTokens, STATE_LENGTH * sizeof(gl_state_index))) { + return index; } } diff --git a/src/mesa/program/prog_print.c b/src/mesa/program/prog_print.c index 00aa6de963b..79c01020eb2 100644 --- a/src/mesa/program/prog_print.c +++ b/src/mesa/program/prog_print.c @@ -909,7 +909,7 @@ binary(GLbitfield64 val) */ static void _mesa_fprint_program_parameters(FILE *f, - GLcontext *ctx, + struct gl_context *ctx, const struct gl_program *prog) { GLuint i; @@ -951,7 +951,7 @@ _mesa_fprint_program_parameters(FILE *f, * Print all of a program's parameters/fields to stderr. */ void -_mesa_print_program_parameters(GLcontext *ctx, const struct gl_program *prog) +_mesa_print_program_parameters(struct gl_context *ctx, const struct gl_program *prog) { _mesa_fprint_program_parameters(stderr, ctx, prog); } diff --git a/src/mesa/program/prog_print.h b/src/mesa/program/prog_print.h index 78b90aeb4d6..f080b3fd2e6 100644 --- a/src/mesa/program/prog_print.h +++ b/src/mesa/program/prog_print.h @@ -100,7 +100,7 @@ _mesa_fprint_program_opt(FILE *f, GLboolean lineNumbers); extern void -_mesa_print_program_parameters(GLcontext *ctx, const struct gl_program *prog); +_mesa_print_program_parameters(struct gl_context *ctx, const struct gl_program *prog); extern void _mesa_print_parameter_list(const struct gl_program_parameter_list *list); diff --git a/src/mesa/program/prog_statevars.c b/src/mesa/program/prog_statevars.c index c6fb42b9a69..baac29ff0dd 100644 --- a/src/mesa/program/prog_statevars.c +++ b/src/mesa/program/prog_statevars.c @@ -46,7 +46,7 @@ * The program parser will produce the state[] values. */ static void -_mesa_fetch_state(GLcontext *ctx, const gl_state_index state[], +_mesa_fetch_state(struct gl_context *ctx, const gl_state_index state[], GLfloat *value) { switch (state[0]) { @@ -1049,7 +1049,7 @@ _mesa_program_state_string(const gl_state_index state[STATE_LENGTH]) * This would be called at glBegin time when using a fragment program. */ void -_mesa_load_state_parameters(GLcontext *ctx, +_mesa_load_state_parameters(struct gl_context *ctx, struct gl_program_parameter_list *paramList) { GLuint i; @@ -1103,7 +1103,7 @@ load_transpose_matrix(GLfloat registers[][4], GLuint pos, * glBegin/glEnd, not per-vertex. */ void -_mesa_load_tracked_matrices(GLcontext *ctx) +_mesa_load_tracked_matrices(struct gl_context *ctx) { GLuint i; diff --git a/src/mesa/program/prog_statevars.h b/src/mesa/program/prog_statevars.h index cfce226fb49..6e5be53630c 100644 --- a/src/mesa/program/prog_statevars.h +++ b/src/mesa/program/prog_statevars.h @@ -125,7 +125,7 @@ typedef enum gl_state_index_ { extern void -_mesa_load_state_parameters(GLcontext *ctx, +_mesa_load_state_parameters(struct gl_context *ctx, struct gl_program_parameter_list *paramList); @@ -138,7 +138,7 @@ _mesa_program_state_string(const gl_state_index state[STATE_LENGTH]); extern void -_mesa_load_tracked_matrices(GLcontext *ctx); +_mesa_load_tracked_matrices(struct gl_context *ctx); #endif /* PROG_STATEVARS_H */ diff --git a/src/mesa/program/program.c b/src/mesa/program/program.c index 06b9539bda6..4cacde9aed1 100644 --- a/src/mesa/program/program.c +++ b/src/mesa/program/program.c @@ -49,7 +49,7 @@ struct gl_program _mesa_DummyProgram; * Init context's vertex/fragment program state */ void -_mesa_init_program(GLcontext *ctx) +_mesa_init_program(struct gl_context *ctx) { GLuint i; @@ -128,7 +128,7 @@ _mesa_init_program(GLcontext *ctx) * Free a context's vertex/fragment program state */ void -_mesa_free_program_data(GLcontext *ctx) +_mesa_free_program_data(struct gl_context *ctx) { #if FEATURE_NV_vertex_program || FEATURE_ARB_vertex_program _mesa_reference_vertprog(ctx, &ctx->VertexProgram.Current, NULL); @@ -161,7 +161,7 @@ _mesa_free_program_data(GLcontext *ctx) * shared state. */ void -_mesa_update_default_objects_program(GLcontext *ctx) +_mesa_update_default_objects_program(struct gl_context *ctx) { #if FEATURE_NV_vertex_program || FEATURE_ARB_vertex_program _mesa_reference_vertprog(ctx, &ctx->VertexProgram.Current, @@ -203,7 +203,7 @@ _mesa_update_default_objects_program(GLcontext *ctx) * This is generally called from within the parsers. */ void -_mesa_set_program_error(GLcontext *ctx, GLint pos, const char *string) +_mesa_set_program_error(struct gl_context *ctx, GLint pos, const char *string) { ctx->Program.ErrorPos = pos; free((void *) ctx->Program.ErrorString); @@ -260,7 +260,7 @@ _mesa_find_line_column(const GLubyte *string, const GLubyte *pos, * Initialize a new vertex/fragment program object. */ static struct gl_program * -_mesa_init_program_struct( GLcontext *ctx, struct gl_program *prog, +_mesa_init_program_struct( struct gl_context *ctx, struct gl_program *prog, GLenum target, GLuint id) { (void) ctx; @@ -286,7 +286,7 @@ _mesa_init_program_struct( GLcontext *ctx, struct gl_program *prog, * Initialize a new fragment program object. */ struct gl_program * -_mesa_init_fragment_program( GLcontext *ctx, struct gl_fragment_program *prog, +_mesa_init_fragment_program( struct gl_context *ctx, struct gl_fragment_program *prog, GLenum target, GLuint id) { if (prog) @@ -300,7 +300,7 @@ _mesa_init_fragment_program( GLcontext *ctx, struct gl_fragment_program *prog, * Initialize a new vertex program object. */ struct gl_program * -_mesa_init_vertex_program( GLcontext *ctx, struct gl_vertex_program *prog, +_mesa_init_vertex_program( struct gl_context *ctx, struct gl_vertex_program *prog, GLenum target, GLuint id) { if (prog) @@ -314,7 +314,7 @@ _mesa_init_vertex_program( GLcontext *ctx, struct gl_vertex_program *prog, * Initialize a new geometry program object. */ struct gl_program * -_mesa_init_geometry_program( GLcontext *ctx, struct gl_geometry_program *prog, +_mesa_init_geometry_program( struct gl_context *ctx, struct gl_geometry_program *prog, GLenum target, GLuint id) { if (prog) @@ -337,7 +337,7 @@ _mesa_init_geometry_program( GLcontext *ctx, struct gl_geometry_program *prog, * \return pointer to new program object */ struct gl_program * -_mesa_new_program(GLcontext *ctx, GLenum target, GLuint id) +_mesa_new_program(struct gl_context *ctx, GLenum target, GLuint id) { struct gl_program *prog; switch (target) { @@ -372,7 +372,7 @@ _mesa_new_program(GLcontext *ctx, GLenum target, GLuint id) * by a device driver function. */ void -_mesa_delete_program(GLcontext *ctx, struct gl_program *prog) +_mesa_delete_program(struct gl_context *ctx, struct gl_program *prog) { (void) ctx; ASSERT(prog); @@ -406,7 +406,7 @@ _mesa_delete_program(GLcontext *ctx, struct gl_program *prog) * casts elsewhere. */ struct gl_program * -_mesa_lookup_program(GLcontext *ctx, GLuint id) +_mesa_lookup_program(struct gl_context *ctx, GLuint id) { if (id) return (struct gl_program *) _mesa_HashLookup(ctx->Shared->Programs, id); @@ -419,7 +419,7 @@ _mesa_lookup_program(GLcontext *ctx, GLuint id) * Reference counting for vertex/fragment programs */ void -_mesa_reference_program(GLcontext *ctx, +_mesa_reference_program(struct gl_context *ctx, struct gl_program **ptr, struct gl_program *prog) { @@ -486,7 +486,7 @@ _mesa_reference_program(GLcontext *ctx, * made by a device driver. */ struct gl_program * -_mesa_clone_program(GLcontext *ctx, const struct gl_program *prog) +_mesa_clone_program(struct gl_context *ctx, const struct gl_program *prog) { struct gl_program *clone; @@ -729,7 +729,7 @@ adjust_param_indexes(struct prog_instruction *inst, GLuint numInst, * the first program go to the inputs of the second program. */ struct gl_program * -_mesa_combine_programs(GLcontext *ctx, +_mesa_combine_programs(struct gl_context *ctx, const struct gl_program *progA, const struct gl_program *progB) { @@ -796,7 +796,7 @@ _mesa_combine_programs(GLcontext *ctx, if (p->Type == PROGRAM_STATE_VAR && p->StateIndexes[0] == STATE_INTERNAL && p->StateIndexes[1] == STATE_CURRENT_ATTRIB && - p->StateIndexes[2] == VERT_ATTRIB_COLOR0) { + (int) p->StateIndexes[2] == (int) VERT_ATTRIB_COLOR0) { progB_inputsRead |= FRAG_BIT_COL0; progB_colorFile = PROGRAM_STATE_VAR; progB_colorIndex = i; @@ -923,7 +923,7 @@ _mesa_find_free_register(const GLboolean used[], * behaviour. */ void -_mesa_postprocess_program(GLcontext *ctx, struct gl_program *prog) +_mesa_postprocess_program(struct gl_context *ctx, struct gl_program *prog) { static const GLfloat white[4] = { 0.5, 0.5, 0.5, 0.5 }; GLuint i; diff --git a/src/mesa/program/program.h b/src/mesa/program/program.h index 03b1066f326..70cc2c3aaed 100644 --- a/src/mesa/program/program.h +++ b/src/mesa/program/program.h @@ -48,16 +48,16 @@ extern struct gl_program _mesa_DummyProgram; extern void -_mesa_init_program(GLcontext *ctx); +_mesa_init_program(struct gl_context *ctx); extern void -_mesa_free_program_data(GLcontext *ctx); +_mesa_free_program_data(struct gl_context *ctx); extern void -_mesa_update_default_objects_program(GLcontext *ctx); +_mesa_update_default_objects_program(struct gl_context *ctx); extern void -_mesa_set_program_error(GLcontext *ctx, GLint pos, const char *string); +_mesa_set_program_error(struct gl_context *ctx, GLint pos, const char *string); extern const GLubyte * _mesa_find_line_column(const GLubyte *string, const GLubyte *pos, @@ -65,36 +65,36 @@ _mesa_find_line_column(const GLubyte *string, const GLubyte *pos, extern struct gl_program * -_mesa_init_vertex_program(GLcontext *ctx, +_mesa_init_vertex_program(struct gl_context *ctx, struct gl_vertex_program *prog, GLenum target, GLuint id); extern struct gl_program * -_mesa_init_fragment_program(GLcontext *ctx, +_mesa_init_fragment_program(struct gl_context *ctx, struct gl_fragment_program *prog, GLenum target, GLuint id); extern struct gl_program * -_mesa_init_geometry_program(GLcontext *ctx, +_mesa_init_geometry_program(struct gl_context *ctx, struct gl_geometry_program *prog, GLenum target, GLuint id); extern struct gl_program * -_mesa_new_program(GLcontext *ctx, GLenum target, GLuint id); +_mesa_new_program(struct gl_context *ctx, GLenum target, GLuint id); extern void -_mesa_delete_program(GLcontext *ctx, struct gl_program *prog); +_mesa_delete_program(struct gl_context *ctx, struct gl_program *prog); extern struct gl_program * -_mesa_lookup_program(GLcontext *ctx, GLuint id); +_mesa_lookup_program(struct gl_context *ctx, GLuint id); extern void -_mesa_reference_program(GLcontext *ctx, +_mesa_reference_program(struct gl_context *ctx, struct gl_program **ptr, struct gl_program *prog); static INLINE void -_mesa_reference_vertprog(GLcontext *ctx, +_mesa_reference_vertprog(struct gl_context *ctx, struct gl_vertex_program **ptr, struct gl_vertex_program *prog) { @@ -103,7 +103,7 @@ _mesa_reference_vertprog(GLcontext *ctx, } static INLINE void -_mesa_reference_fragprog(GLcontext *ctx, +_mesa_reference_fragprog(struct gl_context *ctx, struct gl_fragment_program **ptr, struct gl_fragment_program *prog) { @@ -112,7 +112,7 @@ _mesa_reference_fragprog(GLcontext *ctx, } static INLINE void -_mesa_reference_geomprog(GLcontext *ctx, +_mesa_reference_geomprog(struct gl_context *ctx, struct gl_geometry_program **ptr, struct gl_geometry_program *prog) { @@ -121,24 +121,24 @@ _mesa_reference_geomprog(GLcontext *ctx, } extern struct gl_program * -_mesa_clone_program(GLcontext *ctx, const struct gl_program *prog); +_mesa_clone_program(struct gl_context *ctx, const struct gl_program *prog); static INLINE struct gl_vertex_program * -_mesa_clone_vertex_program(GLcontext *ctx, +_mesa_clone_vertex_program(struct gl_context *ctx, const struct gl_vertex_program *prog) { return (struct gl_vertex_program *) _mesa_clone_program(ctx, &prog->Base); } static INLINE struct gl_geometry_program * -_mesa_clone_geometry_program(GLcontext *ctx, +_mesa_clone_geometry_program(struct gl_context *ctx, const struct gl_geometry_program *prog) { return (struct gl_geometry_program *) _mesa_clone_program(ctx, &prog->Base); } static INLINE struct gl_fragment_program * -_mesa_clone_fragment_program(GLcontext *ctx, +_mesa_clone_fragment_program(struct gl_context *ctx, const struct gl_fragment_program *prog) { return (struct gl_fragment_program *) _mesa_clone_program(ctx, &prog->Base); @@ -152,7 +152,7 @@ extern GLboolean _mesa_delete_instructions(struct gl_program *prog, GLuint start, GLuint count); extern struct gl_program * -_mesa_combine_programs(GLcontext *ctx, +_mesa_combine_programs(struct gl_context *ctx, const struct gl_program *progA, const struct gl_program *progB); @@ -166,7 +166,7 @@ _mesa_find_free_register(const GLboolean used[], GLuint maxRegs, GLuint firstReg); extern void -_mesa_postprocess_program(GLcontext *ctx, struct gl_program *prog); +_mesa_postprocess_program(struct gl_context *ctx, struct gl_program *prog); /* keep these in the same order as TGSI_PROCESSOR_* */ diff --git a/src/mesa/program/program_parse.tab.c b/src/mesa/program/program_parse.tab.c index 08ead30defe..baef311d0c1 100644 --- a/src/mesa/program/program_parse.tab.c +++ b/src/mesa/program/program_parse.tab.c @@ -5604,7 +5604,7 @@ yyerror(YYLTYPE *locp, struct asm_parser_state *state, const char *s) GLboolean -_mesa_parse_arb_program(GLcontext *ctx, GLenum target, const GLubyte *str, +_mesa_parse_arb_program(struct gl_context *ctx, GLenum target, const GLubyte *str, GLsizei len, struct asm_parser_state *state) { struct asm_instruction *inst; diff --git a/src/mesa/program/program_parse.y b/src/mesa/program/program_parse.y index cf621ae4244..784ea28c17a 100644 --- a/src/mesa/program/program_parse.y +++ b/src/mesa/program/program_parse.y @@ -2643,7 +2643,7 @@ yyerror(YYLTYPE *locp, struct asm_parser_state *state, const char *s) GLboolean -_mesa_parse_arb_program(GLcontext *ctx, GLenum target, const GLubyte *str, +_mesa_parse_arb_program(struct gl_context *ctx, GLenum target, const GLubyte *str, GLsizei len, struct asm_parser_state *state) { struct asm_instruction *inst; diff --git a/src/mesa/program/program_parser.h b/src/mesa/program/program_parser.h index be952d4b9c8..d689eef7958 100644 --- a/src/mesa/program/program_parser.h +++ b/src/mesa/program/program_parser.h @@ -24,10 +24,7 @@ #include "main/config.h" -#ifndef MTYPES_H -struct __GLcontextRec; -typedef struct __GLcontextRec GLcontext; -#endif +struct gl_context; enum asm_type { at_none, @@ -131,7 +128,7 @@ struct asm_instruction { struct asm_parser_state { - GLcontext *ctx; + struct gl_context *ctx; struct gl_program *prog; /** @@ -237,7 +234,7 @@ typedef struct YYLTYPE { #define YYLTYPE_IS_TRIVIAL 1 -extern GLboolean _mesa_parse_arb_program(GLcontext *ctx, GLenum target, +extern GLboolean _mesa_parse_arb_program(struct gl_context *ctx, GLenum target, const GLubyte *str, GLsizei len, struct asm_parser_state *state); diff --git a/src/mesa/program/programopt.c b/src/mesa/program/programopt.c index fb2ebe6338f..f92881f8337 100644 --- a/src/mesa/program/programopt.c +++ b/src/mesa/program/programopt.c @@ -46,7 +46,7 @@ * May be used to implement the position_invariant option. */ static void -_mesa_insert_mvp_dp4_code(GLcontext *ctx, struct gl_vertex_program *vprog) +_mesa_insert_mvp_dp4_code(struct gl_context *ctx, struct gl_vertex_program *vprog) { struct prog_instruction *newInst; const GLuint origLen = vprog->Base.NumInstructions; @@ -114,7 +114,7 @@ _mesa_insert_mvp_dp4_code(GLcontext *ctx, struct gl_vertex_program *vprog) static void -_mesa_insert_mvp_mad_code(GLcontext *ctx, struct gl_vertex_program *vprog) +_mesa_insert_mvp_mad_code(struct gl_context *ctx, struct gl_vertex_program *vprog) { struct prog_instruction *newInst; const GLuint origLen = vprog->Base.NumInstructions; @@ -216,7 +216,7 @@ _mesa_insert_mvp_mad_code(GLcontext *ctx, struct gl_vertex_program *vprog) void -_mesa_insert_mvp_code(GLcontext *ctx, struct gl_vertex_program *vprog) +_mesa_insert_mvp_code(struct gl_context *ctx, struct gl_vertex_program *vprog) { if (ctx->mvp_with_dp4) _mesa_insert_mvp_dp4_code( ctx, vprog ); @@ -238,7 +238,7 @@ _mesa_insert_mvp_code(GLcontext *ctx, struct gl_vertex_program *vprog) * to vertex programs too. */ void -_mesa_append_fog_code(GLcontext *ctx, struct gl_fragment_program *fprog) +_mesa_append_fog_code(struct gl_context *ctx, struct gl_fragment_program *fprog) { static const gl_state_index fogPStateOpt[STATE_LENGTH] = { STATE_INTERNAL, STATE_FOG_PARAMS_OPTIMIZED, 0, 0, 0 }; @@ -585,7 +585,7 @@ _mesa_remove_output_reads(struct gl_program *prog, gl_register_file type) * This is for debug/test purposes. */ void -_mesa_nop_fragment_program(GLcontext *ctx, struct gl_fragment_program *prog) +_mesa_nop_fragment_program(struct gl_context *ctx, struct gl_fragment_program *prog) { struct prog_instruction *inst; GLuint inputAttr; @@ -626,7 +626,7 @@ _mesa_nop_fragment_program(GLcontext *ctx, struct gl_fragment_program *prog) * transforms vertex position and emits color. */ void -_mesa_nop_vertex_program(GLcontext *ctx, struct gl_vertex_program *prog) +_mesa_nop_vertex_program(struct gl_context *ctx, struct gl_vertex_program *prog) { struct prog_instruction *inst; GLuint inputAttr; diff --git a/src/mesa/program/programopt.h b/src/mesa/program/programopt.h index 4af6357f976..ef6f1bd0794 100644 --- a/src/mesa/program/programopt.h +++ b/src/mesa/program/programopt.h @@ -29,10 +29,10 @@ #include "main/mtypes.h" extern void -_mesa_insert_mvp_code(GLcontext *ctx, struct gl_vertex_program *vprog); +_mesa_insert_mvp_code(struct gl_context *ctx, struct gl_vertex_program *vprog); extern void -_mesa_append_fog_code(GLcontext *ctx, struct gl_fragment_program *fprog); +_mesa_append_fog_code(struct gl_context *ctx, struct gl_fragment_program *fprog); extern void _mesa_count_texture_indirections(struct gl_program *prog); @@ -44,10 +44,10 @@ extern void _mesa_remove_output_reads(struct gl_program *prog, gl_register_file type); extern void -_mesa_nop_fragment_program(GLcontext *ctx, struct gl_fragment_program *prog); +_mesa_nop_fragment_program(struct gl_context *ctx, struct gl_fragment_program *prog); extern void -_mesa_nop_vertex_program(GLcontext *ctx, struct gl_vertex_program *prog); +_mesa_nop_vertex_program(struct gl_context *ctx, struct gl_vertex_program *prog); #endif /* PROGRAMOPT_H */ diff --git a/src/mesa/program/register_allocate.c b/src/mesa/program/register_allocate.c index 03f04697bfb..ada6e356419 100644 --- a/src/mesa/program/register_allocate.c +++ b/src/mesa/program/register_allocate.c @@ -72,6 +72,7 @@ struct ra_node { unsigned int adjacency_count; unsigned int reg; GLboolean in_stack; + float spill_cost; }; struct ra_graph { @@ -359,3 +360,66 @@ ra_get_node_reg(struct ra_graph *g, unsigned int n) { return g->nodes[n].reg; } + +static float +ra_get_spill_benefit(struct ra_graph *g, unsigned int n) +{ + int j; + float benefit = 0; + int n_class = g->nodes[n].class; + + /* Define the benefit of eliminating an interference between n, j + * through spilling as q(C, B) / p(C). This is similar to the + * "count number of edges" approach of traditional graph coloring, + * but takes classes into account. + */ + for (j = 0; j < g->count; j++) { + if (j != n && g->nodes[n].adjacency[j]) { + unsigned int j_class = g->nodes[j].class; + benefit += ((float)g->regs->classes[n_class]->q[j_class] / + g->regs->classes[n_class]->p); + break; + } + } + + return benefit; +} + +/** + * Returns a node number to be spilled according to the cost/benefit using + * the pq test, or -1 if there are no spillable nodes. + */ +int +ra_get_best_spill_node(struct ra_graph *g) +{ + unsigned int best_node = -1; + unsigned int best_benefit = 0.0; + unsigned int n; + + for (n = 0; n < g->count; n++) { + float cost = g->nodes[n].spill_cost; + float benefit; + + if (cost <= 0.0) + continue; + + benefit = ra_get_spill_benefit(g, n); + + if (benefit / cost > best_benefit) { + best_benefit = benefit / cost; + best_node = n; + } + } + + return best_node; +} + +/** + * Only nodes with a spill cost set (cost != 0.0) will be considered + * for register spilling. + */ +void +ra_set_node_spill_cost(struct ra_graph *g, unsigned int n, float cost) +{ + g->nodes[n].spill_cost = cost; +} diff --git a/src/mesa/program/register_allocate.h b/src/mesa/program/register_allocate.h index 42647b50b8f..198b89f2d7d 100644 --- a/src/mesa/program/register_allocate.h +++ b/src/mesa/program/register_allocate.h @@ -65,5 +65,7 @@ GLboolean ra_select(struct ra_graph *g); GLboolean ra_allocate_no_spills(struct ra_graph *g); unsigned int ra_get_node_reg(struct ra_graph *g, unsigned int n); +void ra_set_node_spill_cost(struct ra_graph *g, unsigned int n, float cost); +int ra_get_best_spill_node(struct ra_graph *g); /** @} */ |