diff options
Diffstat (limited to 'mesalib/src/mesa/program')
-rw-r--r-- | mesalib/src/mesa/program/hash_table.h | 18 | ||||
-rw-r--r-- | mesalib/src/mesa/program/ir_to_mesa.cpp | 170 | ||||
-rw-r--r-- | mesalib/src/mesa/program/ir_to_mesa.h | 89 | ||||
-rw-r--r-- | mesalib/src/mesa/program/prog_print.c | 4 | ||||
-rw-r--r-- | mesalib/src/mesa/program/prog_print.h | 239 | ||||
-rw-r--r-- | mesalib/src/mesa/program/program.c | 2 |
6 files changed, 254 insertions, 268 deletions
diff --git a/mesalib/src/mesa/program/hash_table.h b/mesalib/src/mesa/program/hash_table.h index bfe221b24..941d28a4c 100644 --- a/mesalib/src/mesa/program/hash_table.h +++ b/mesalib/src/mesa/program/hash_table.h @@ -32,6 +32,7 @@ #define HASH_TABLE_H #include <string.h> +#include <stdlib.h> #include <stdint.h> #include <limits.h> #include <assert.h> @@ -100,6 +101,10 @@ extern void *hash_table_find(struct hash_table *ht, const void *key); * calls to \c hash_table_find and \c hash_table_remove will return or remove, * repsectively, the most recently added instance of \c key. * + * \warning + * The value passed by \c key is kept in the hash table and is used by later + * calls to \c hash_table_find. + * * \sa hash_table_replace */ extern void hash_table_insert(struct hash_table *ht, void *data, @@ -204,6 +209,7 @@ public: ~string_to_uint_map() { + hash_table_call_foreach(this->ht, delete_key, NULL); hash_table_dtor(this->ht); } @@ -243,10 +249,20 @@ public: * because UINT_MAX+1 = 0. */ assert(value != UINT_MAX); - hash_table_replace(ht, (void *) (intptr_t) (value + 1), key); + hash_table_replace(this->ht, + (void *) (intptr_t) (value + 1), + strdup(key)); } private: + static void delete_key(const void *key, void *data, void *closure) + { + (void) data; + (void) closure; + + free((char *)key); + } + struct hash_table *ht; }; diff --git a/mesalib/src/mesa/program/ir_to_mesa.cpp b/mesalib/src/mesa/program/ir_to_mesa.cpp index 5be44bc51..fecab50f7 100644 --- a/mesalib/src/mesa/program/ir_to_mesa.cpp +++ b/mesalib/src/mesa/program/ir_to_mesa.cpp @@ -41,12 +41,13 @@ #include "ir_optimization.h" #include "ast.h" -extern "C" { #include "main/mtypes.h" -#include "main/shaderapi.h" #include "main/shaderobj.h" -#include "main/uniforms.h" #include "program/hash_table.h" + +extern "C" { +#include "main/shaderapi.h" +#include "main/uniforms.h" #include "program/prog_instruction.h" #include "program/prog_optimize.h" #include "program/prog_print.h" @@ -2587,121 +2588,83 @@ check_resources(const struct gl_context *ctx, } - -struct uniform_sort { - struct gl_uniform *u; - int pos; -}; - -/* The shader_program->Uniforms list is almost sorted in increasing - * uniform->{Frag,Vert}Pos locations, but not quite when there are - * uniforms shared between targets. We need to add parameters in - * increasing order for the targets. - */ static int -sort_uniforms(const void *a, const void *b) +add_uniform_to_shader(ir_variable *var, + struct gl_program_parameter_list *params, + unsigned int &next_sampler) { - struct uniform_sort *u1 = (struct uniform_sort *)a; - struct uniform_sort *u2 = (struct uniform_sort *)b; - - return u1->pos - u2->pos; -} + const glsl_type *type = var->type; + unsigned int size; -/* Add the uniforms to the parameters. The linker chose locations - * in our parameters lists (which weren't created yet), which the - * uniforms code will use to poke values into our parameters list - * when uniforms are updated. - */ -static void -add_uniforms_to_parameters_list(struct gl_shader_program *shader_program, - struct gl_shader *shader, - struct gl_program *prog) -{ - unsigned int i; - unsigned int next_sampler = 0, num_uniforms = 0; - struct uniform_sort *sorted_uniforms; + if (type->is_vector() || type->is_scalar()) { + size = type->vector_elements; + } else { + size = type_size(type) * 4; + } - sorted_uniforms = ralloc_array(NULL, struct uniform_sort, - shader_program->Uniforms->NumUniforms); + gl_register_file file; + if (type->is_sampler() || + (type->is_array() && type->fields.array->is_sampler())) { + file = PROGRAM_SAMPLER; + } else { + file = PROGRAM_UNIFORM; + } - for (i = 0; i < shader_program->Uniforms->NumUniforms; i++) { - struct gl_uniform *uniform = shader_program->Uniforms->Uniforms + i; - int parameter_index = -1; + int index = _mesa_lookup_parameter_index(params, -1, var->name); + if (index < 0) { + index = _mesa_add_parameter(params, file, + var->name, size, type->gl_type, + NULL, NULL, 0x0); - switch (shader->Type) { - case GL_VERTEX_SHADER: - parameter_index = uniform->VertPos; - break; - case GL_FRAGMENT_SHADER: - parameter_index = uniform->FragPos; - break; - case GL_GEOMETRY_SHADER: - parameter_index = uniform->GeomPos; - break; - } - - /* Only add uniforms used in our target. */ - if (parameter_index != -1) { - sorted_uniforms[num_uniforms].pos = parameter_index; - sorted_uniforms[num_uniforms].u = uniform; - num_uniforms++; + /* Sampler uniform values are stored in prog->SamplerUnits, + * and the entry in that array is selected by this index we + * store in ParameterValues[]. + */ + if (file == PROGRAM_SAMPLER) { + for (unsigned int j = 0; j < size / 4; j++) + params->ParameterValues[index + j][0].f = next_sampler++; } } - qsort(sorted_uniforms, num_uniforms, sizeof(struct uniform_sort), - sort_uniforms); - - for (i = 0; i < num_uniforms; i++) { - struct gl_uniform *uniform = sorted_uniforms[i].u; - int parameter_index = sorted_uniforms[i].pos; - const glsl_type *type = uniform->Type; - unsigned int size; - - if (type->is_vector() || - type->is_scalar()) { - size = type->vector_elements; - } else { - size = type_size(type) * 4; - } + return index; +} - gl_register_file file; - if (type->is_sampler() || - (type->is_array() && type->fields.array->is_sampler())) { - file = PROGRAM_SAMPLER; - } else { - file = PROGRAM_UNIFORM; - } +/** + * Generate the program parameters list for the user uniforms in a shader + * + * \param shader_program Linked shader program. This is only used to + * emit possible link errors to the info log. + * \param sh Shader whose uniforms are to be processed. + * \param params Parameter list to be filled in. + */ +void +_mesa_generate_parameters_list_for_uniforms(struct gl_shader_program + *shader_program, + struct gl_shader *sh, + struct gl_program_parameter_list + *params) +{ + unsigned int next_sampler = 0; - GLint index = _mesa_lookup_parameter_index(prog->Parameters, -1, - uniform->Name); + foreach_list(node, sh->ir) { + ir_variable *var = ((ir_instruction *) node)->as_variable(); - if (index < 0) { - index = _mesa_add_parameter(prog->Parameters, file, - uniform->Name, size, type->gl_type, - NULL, NULL, 0x0); + if ((var == NULL) || (var->mode != ir_var_uniform) + || (strncmp(var->name, "gl_", 3) == 0)) + continue; - /* Sampler uniform values are stored in prog->SamplerUnits, - * and the entry in that array is selected by this index we - * store in ParameterValues[]. - */ - if (file == PROGRAM_SAMPLER) { - for (unsigned int j = 0; j < size / 4; j++) - prog->Parameters->ParameterValues[index + j][0].f = next_sampler++; - } + int loc = add_uniform_to_shader(var, params, next_sampler); - /* The location chosen in the Parameters list here (returned - * from _mesa_add_uniform) has to match what the linker chose. - */ - if (index != parameter_index) { - linker_error(shader_program, - "Allocation of uniform `%s' to target failed " - "(%d vs %d)\n", - uniform->Name, index, parameter_index); - } + /* The location chosen in the Parameters list here (returned from + * _mesa_add_parameter) has to match what the linker chose. + */ + if (var->location != loc) { + linker_error(shader_program, + "Allocation of uniform `%s' to target failed " + "(%d vs %d)\n", + var->name, loc, var->location); } } - - ralloc_free(sorted_uniforms); } static void @@ -3045,7 +3008,8 @@ get_mesa_program(struct gl_context *ctx, v.shader_program = shader_program; v.options = options; - add_uniforms_to_parameters_list(shader_program, shader, prog); + _mesa_generate_parameters_list_for_uniforms(shader_program, shader, + prog->Parameters); /* Emit Mesa IR for main(). */ visit_exec_list(shader->ir, &v); diff --git a/mesalib/src/mesa/program/ir_to_mesa.h b/mesalib/src/mesa/program/ir_to_mesa.h index e708bb769..d046b0fcf 100644 --- a/mesalib/src/mesa/program/ir_to_mesa.h +++ b/mesalib/src/mesa/program/ir_to_mesa.h @@ -1,41 +1,48 @@ -/*
- * Copyright © 2010 Intel Corporation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include "main/glheader.h"
-
-struct gl_context;
-struct gl_shader;
-struct gl_shader_program;
-
-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
-}
-#endif
+/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include "main/glheader.h" + +struct gl_context; +struct gl_shader; +struct gl_shader_program; + +#ifdef __cplusplus +extern "C" { +#endif + +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 +} + +void +_mesa_generate_parameters_list_for_uniforms(struct gl_shader_program + *shader_program, + struct gl_shader *sh, + struct gl_program_parameter_list + *params); +#endif diff --git a/mesalib/src/mesa/program/prog_print.c b/mesalib/src/mesa/program/prog_print.c index 70412b1fa..dfccc60f6 100644 --- a/mesalib/src/mesa/program/prog_print.c +++ b/mesalib/src/mesa/program/prog_print.c @@ -1068,9 +1068,9 @@ _mesa_write_shader_to_file(const struct gl_shader *shader) * _mesa_write_shader_to_file function. */ void -_mesa_append_uniforms_to_file(const struct gl_shader *shader, - const struct gl_program *prog) +_mesa_append_uniforms_to_file(const struct gl_shader *shader) { + const struct gl_program *const prog = shader->Program; const char *type; char filename[100]; FILE *f; diff --git a/mesalib/src/mesa/program/prog_print.h b/mesalib/src/mesa/program/prog_print.h index caeedb779..b95ec2be5 100644 --- a/mesalib/src/mesa/program/prog_print.h +++ b/mesalib/src/mesa/program/prog_print.h @@ -1,120 +1,119 @@ -/*
- * Mesa 3-D graphics library
- * Version: 6.5.3
- *
- * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-
-#ifndef PROG_PRINT_H
-#define PROG_PRINT_H
-
-#include <stdio.h>
-
-#include "main/glheader.h"
-#include "main/mtypes.h"
-
-struct gl_program;
-struct gl_program_parameter_list;
-struct gl_shader;
-struct prog_instruction;
-
-
-/**
- * The output style to use when printing programs.
- */
-typedef enum {
- PROG_PRINT_ARB,
- PROG_PRINT_NV,
- PROG_PRINT_DEBUG
-} gl_prog_print_mode;
-
-
-extern const char *
-_mesa_register_file_name(gl_register_file f);
-
-extern void
-_mesa_print_vp_inputs(GLbitfield inputs);
-
-extern void
-_mesa_print_fp_inputs(GLbitfield inputs);
-
-extern const char *
-_mesa_condcode_string(GLuint condcode);
-
-extern const char *
-_mesa_swizzle_string(GLuint swizzle, GLuint negateBase, GLboolean extended);
-
-const char *
-_mesa_writemask_string(GLuint writeMask);
-
-extern void
-_mesa_print_swizzle(GLuint swizzle);
-
-extern void
-_mesa_fprint_alu_instruction(FILE *f,
- const struct prog_instruction *inst,
- const char *opcode_string, GLuint numRegs,
- gl_prog_print_mode mode,
- const struct gl_program *prog);
-
-extern void
-_mesa_print_alu_instruction(const struct prog_instruction *inst,
- const char *opcode_string, GLuint numRegs);
-
-extern void
-_mesa_print_instruction(const struct prog_instruction *inst);
-
-extern GLint
-_mesa_fprint_instruction_opt(FILE *f,
- const struct prog_instruction *inst,
- GLint indent,
- gl_prog_print_mode mode,
- const struct gl_program *prog);
-
-extern GLint
-_mesa_print_instruction_opt(const struct prog_instruction *inst, GLint indent,
- gl_prog_print_mode mode,
- const struct gl_program *prog);
-
-extern void
-_mesa_print_program(const struct gl_program *prog);
-
-extern void
-_mesa_fprint_program_opt(FILE *f,
- const struct gl_program *prog, gl_prog_print_mode mode,
- GLboolean lineNumbers);
-
-extern void
-_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);
-
-
-extern void
-_mesa_write_shader_to_file(const struct gl_shader *shader);
-
-extern void
-_mesa_append_uniforms_to_file(const struct gl_shader *shader,
- const struct gl_program *prog);
-
-
-#endif /* PROG_PRINT_H */
+/* + * Mesa 3-D graphics library + * Version: 6.5.3 + * + * Copyright (C) 1999-2007 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + + +#ifndef PROG_PRINT_H +#define PROG_PRINT_H + +#include <stdio.h> + +#include "main/glheader.h" +#include "main/mtypes.h" + +struct gl_program; +struct gl_program_parameter_list; +struct gl_shader; +struct prog_instruction; + + +/** + * The output style to use when printing programs. + */ +typedef enum { + PROG_PRINT_ARB, + PROG_PRINT_NV, + PROG_PRINT_DEBUG +} gl_prog_print_mode; + + +extern const char * +_mesa_register_file_name(gl_register_file f); + +extern void +_mesa_print_vp_inputs(GLbitfield inputs); + +extern void +_mesa_print_fp_inputs(GLbitfield inputs); + +extern const char * +_mesa_condcode_string(GLuint condcode); + +extern const char * +_mesa_swizzle_string(GLuint swizzle, GLuint negateBase, GLboolean extended); + +const char * +_mesa_writemask_string(GLuint writeMask); + +extern void +_mesa_print_swizzle(GLuint swizzle); + +extern void +_mesa_fprint_alu_instruction(FILE *f, + const struct prog_instruction *inst, + const char *opcode_string, GLuint numRegs, + gl_prog_print_mode mode, + const struct gl_program *prog); + +extern void +_mesa_print_alu_instruction(const struct prog_instruction *inst, + const char *opcode_string, GLuint numRegs); + +extern void +_mesa_print_instruction(const struct prog_instruction *inst); + +extern GLint +_mesa_fprint_instruction_opt(FILE *f, + const struct prog_instruction *inst, + GLint indent, + gl_prog_print_mode mode, + const struct gl_program *prog); + +extern GLint +_mesa_print_instruction_opt(const struct prog_instruction *inst, GLint indent, + gl_prog_print_mode mode, + const struct gl_program *prog); + +extern void +_mesa_print_program(const struct gl_program *prog); + +extern void +_mesa_fprint_program_opt(FILE *f, + const struct gl_program *prog, gl_prog_print_mode mode, + GLboolean lineNumbers); + +extern void +_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); + + +extern void +_mesa_write_shader_to_file(const struct gl_shader *shader); + +extern void +_mesa_append_uniforms_to_file(const struct gl_shader *shader); + + +#endif /* PROG_PRINT_H */ diff --git a/mesalib/src/mesa/program/program.c b/mesalib/src/mesa/program/program.c index 4d6c60b9d..736652529 100644 --- a/mesalib/src/mesa/program/program.c +++ b/mesalib/src/mesa/program/program.c @@ -140,7 +140,7 @@ _mesa_free_program_data(struct gl_context *ctx) #endif #if FEATURE_NV_fragment_program || FEATURE_ARB_fragment_program _mesa_reference_fragprog(ctx, &ctx->FragmentProgram.Current, NULL); - _mesa_delete_program_cache(ctx, ctx->FragmentProgram.Cache); + _mesa_delete_shader_cache(ctx, ctx->FragmentProgram.Cache); #endif #if FEATURE_ARB_geometry_shader4 _mesa_reference_geomprog(ctx, &ctx->GeometryProgram.Current, NULL); |