From 022d9c6cf6a67385d84ff33ce095f5c7f9f6d0cc Mon Sep 17 00:00:00 2001 From: marha Date: Wed, 28 Jul 2010 18:15:53 +0000 Subject: Update to mesa 7,8,2 --- mesalib/src/mesa/shader/program.c | 4 +- mesalib/src/mesa/shader/shader_api.c | 79 +++++++++++++++------- mesalib/src/mesa/shader/slang/slang_codegen.c | 3 +- .../src/mesa/shader/slang/slang_compile_variable.h | 2 +- mesalib/src/mesa/shader/slang/slang_link.c | 5 +- 5 files changed, 62 insertions(+), 31 deletions(-) (limited to 'mesalib/src/mesa/shader') diff --git a/mesalib/src/mesa/shader/program.c b/mesalib/src/mesa/shader/program.c index f4f701b54..f77a77375 100644 --- a/mesalib/src/mesa/shader/program.c +++ b/mesalib/src/mesa/shader/program.c @@ -625,7 +625,7 @@ replace_registers(struct prog_instruction *inst, GLuint numInst, GLuint i, j; for (i = 0; i < numInst; i++) { /* src regs */ - for (j = 0; j < _mesa_num_inst_src_regs(inst->Opcode); j++) { + for (j = 0; j < _mesa_num_inst_src_regs(inst[i].Opcode); j++) { if (inst[i].SrcReg[j].File == oldFile && inst[i].SrcReg[j].Index == oldIndex) { inst[i].SrcReg[j].File = newFile; @@ -652,7 +652,7 @@ adjust_param_indexes(struct prog_instruction *inst, GLuint numInst, { GLuint i, j; for (i = 0; i < numInst; i++) { - for (j = 0; j < _mesa_num_inst_src_regs(inst->Opcode); j++) { + for (j = 0; j < _mesa_num_inst_src_regs(inst[i].Opcode); j++) { GLuint f = inst[i].SrcReg[j].File; if (f == PROGRAM_CONSTANT || f == PROGRAM_UNIFORM || diff --git a/mesalib/src/mesa/shader/shader_api.c b/mesalib/src/mesa/shader/shader_api.c index 940fe2d03..5e87bb405 100644 --- a/mesalib/src/mesa/shader/shader_api.c +++ b/mesalib/src/mesa/shader/shader_api.c @@ -1259,6 +1259,54 @@ lookup_uniform_parameter(GLcontext *ctx, GLuint program, GLint location, } +/** + * GLGL uniform arrays and structs require special handling. + * + * The GL_ARB_shader_objects spec says that if you use + * glGetUniformLocation to get the location of an array, you CANNOT + * access other elements of the array by adding an offset to the + * returned location. For example, you must call + * glGetUniformLocation("foo[16]") if you want to set the 16th element + * of the array with glUniform(). + * + * HOWEVER, some other OpenGL drivers allow accessing array elements + * by adding an offset to the returned array location. And some apps + * seem to depend on that behaviour. + * + * Mesa's gl_uniform_list doesn't directly support this since each + * entry in the list describes one uniform variable, not one uniform + * element. We could insert dummy entries in the list for each array + * element after [0] but that causes complications elsewhere. + * + * We solve this problem by encoding two values in the location that's + * returned by glGetUniformLocation(): + * a) index into gl_uniform_list::Uniforms[] for the uniform + * b) an array/field offset (0 for simple types) + * + * These two values are encoded in the high and low halves of a GLint. + * By putting the uniform number in the high part and the offset in the + * low part, we can support the unofficial ability to index into arrays + * by adding offsets to the location value. + */ +static void +merge_location_offset(GLint *location, GLint offset) +{ + *location = (*location << 16) | offset; +} + + +/** + * Seperate the uniform location and parameter offset. See above. + */ +static void +split_location_offset(GLint *location, GLint *offset) +{ + *offset = *location & 0xffff; + *location = *location >> 16; +} + + + /** * Called via ctx->Driver.GetUniformfv(). */ @@ -1268,6 +1316,9 @@ _mesa_get_uniformfv(GLcontext *ctx, GLuint program, GLint location, { struct gl_program *prog; GLint paramPos; + GLint offset; + + split_location_offset(&location, &offset); lookup_uniform_parameter(ctx, program, location, &prog, ¶mPos); @@ -1298,7 +1349,10 @@ _mesa_get_uniformiv(GLcontext *ctx, GLuint program, GLint location, { struct gl_program *prog; GLint paramPos; + GLint offset; + split_location_offset(&location, &offset); + lookup_uniform_parameter(ctx, program, location, &prog, ¶mPos); if (prog) { @@ -1318,31 +1372,6 @@ _mesa_get_uniformiv(GLcontext *ctx, GLuint program, GLint location, } -/** - * The value returned by GetUniformLocation actually encodes two things: - * 1. the index into the prog->Uniforms[] array for the uniform - * 2. an offset in the prog->ParameterValues[] array for specifying array - * elements or structure fields. - * This function merges those two values. - */ -static void -merge_location_offset(GLint *location, GLint offset) -{ - *location = *location | (offset << 16); -} - - -/** - * Seperate the uniform location and parameter offset. See above. - */ -static void -split_location_offset(GLint *location, GLint *offset) -{ - *offset = (*location >> 16); - *location = *location & 0xffff; -} - - /** * Called via ctx->Driver.GetUniformLocation(). * diff --git a/mesalib/src/mesa/shader/slang/slang_codegen.c b/mesalib/src/mesa/shader/slang/slang_codegen.c index ecb2f6d5c..7d5e5eb29 100644 --- a/mesalib/src/mesa/shader/slang/slang_codegen.c +++ b/mesalib/src/mesa/shader/slang/slang_codegen.c @@ -4187,11 +4187,10 @@ _slang_gen_variable(slang_assemble_ctx * A, slang_operation *oper) slang_atom name = oper->var ? oper->var->a_name : oper->a_id; slang_variable *var = _slang_variable_locate(oper->locals, name, GL_TRUE); slang_ir_node *n; - if (!var) { + if (!var || !var->declared) { slang_info_log_error(A->log, "undefined variable '%s'", (char *) name); return NULL; } - assert(var->declared); n = new_var(A, var); return n; } diff --git a/mesalib/src/mesa/shader/slang/slang_compile_variable.h b/mesalib/src/mesa/shader/slang/slang_compile_variable.h index b4585599f..5c9d248b3 100644 --- a/mesalib/src/mesa/shader/slang/slang_compile_variable.h +++ b/mesalib/src/mesa/shader/slang/slang_compile_variable.h @@ -41,7 +41,7 @@ typedef struct slang_variable_ GLuint size; /**< Variable's size in bytes */ GLboolean is_global; GLboolean isTemp; /**< a named temporary (__resultTmp) */ - GLboolean declared; /**< for debug */ + GLboolean declared; /**< has the var been declared? */ struct slang_ir_storage_ *store; /**< Storage for this var */ } slang_variable; diff --git a/mesalib/src/mesa/shader/slang/slang_link.c b/mesalib/src/mesa/shader/slang/slang_link.c index 7c7bfbdbc..e8dca0142 100644 --- a/mesalib/src/mesa/shader/slang/slang_link.c +++ b/mesalib/src/mesa/shader/slang/slang_link.c @@ -921,7 +921,10 @@ _slang_link(GLcontext *ctx, if (!vertNotify || !fragNotify) { /* driver rejected one/both of the vertex/fragment programs */ - link_error(shProg, "Vertex and/or fragment program rejected by driver\n"); + if (!shProg->InfoLog) { + link_error(shProg, + "Vertex and/or fragment program rejected by driver\n"); + } } else { shProg->LinkStatus = (shProg->VertexProgram || shProg->FragmentProgram); -- cgit v1.2.3