diff options
author | Ian Romanick <[email protected]> | 2010-08-16 19:08:53 -0700 |
---|---|---|
committer | Ian Romanick <[email protected]> | 2010-08-16 19:08:53 -0700 |
commit | 6c03c576cc49bbb008de66d374f4302ff0fe0390 (patch) | |
tree | 7ddeb3ee88532d9aef8728b9aa256edf7c125247 /src/mesa/main | |
parent | 15a3b42e135a3a2cb463ec3cff80a55dd8528051 (diff) | |
parent | a433cd286c60eb9d4c2114f042709eda0f3de676 (diff) |
Merge branch 'glsl2'
Conflicts:
src/mesa/program/prog_optimize.c
Diffstat (limited to 'src/mesa/main')
-rw-r--r-- | src/mesa/main/dd.h | 21 | ||||
-rw-r--r-- | src/mesa/main/imports.h | 29 | ||||
-rw-r--r-- | src/mesa/main/mtypes.h | 24 | ||||
-rw-r--r-- | src/mesa/main/shaderapi.c | 10 | ||||
-rw-r--r-- | src/mesa/main/shaderobj.c | 18 | ||||
-rw-r--r-- | src/mesa/main/shaderobj.h | 24 |
6 files changed, 111 insertions, 15 deletions
diff --git a/src/mesa/main/dd.h b/src/mesa/main/dd.h index 825073ca886..71d0f570e4b 100644 --- a/src/mesa/main/dd.h +++ b/src/mesa/main/dd.h @@ -595,6 +595,27 @@ struct dd_function_table { /*@}*/ + /** + * \name GLSL shader/program functions. + */ + /*@{*/ + /** + * Called when a shader is compiled. + * + * Note that not all shader objects get ShaderCompile called on + * them. Notably, the shaders containing builtin functions do not + * have CompileShader() called, so if lowering passes are done they + * need to also be performed in LinkShader(). + */ + GLboolean (*CompileShader)(GLcontext *ctx, struct gl_shader *shader); + /** + * Called when a shader program is linked. + * + * This gives drivers an opportunity to clone the IR and make their + * own transformations on it for the purposes of code generation. + */ + GLboolean (*LinkShader)(GLcontext *ctx, struct gl_shader_program *shader); + /*@}*/ /** * \name State-changing functions. diff --git a/src/mesa/main/imports.h b/src/mesa/main/imports.h index 9c2ffd66d69..e967b147311 100644 --- a/src/mesa/main/imports.h +++ b/src/mesa/main/imports.h @@ -116,6 +116,35 @@ typedef union { GLfloat f; GLint i; } fi_type; #endif +/** + * \name Work-arounds for platforms that lack C99 math functions + */ +/*@{*/ +#if (defined(_XOPEN_SOURCE) && (_XOPEN_SOURCE < 600)) && !defined(_ISOC99_SOURCE) \ + && (!defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L)) \ + && (!defined(_MSC_VER) || (_MSC_VER < 1400)) +#define acosf(f) ((float) acos(f)) +#define asinf(f) ((float) asin(f)) +#define atan2f(x,y) ((float) atan2(x,y)) +#define atanf(f) ((float) atan(f)) +#define cielf(f) ((float) ciel(f)) +#define cosf(f) ((float) cos(f)) +#define coshf(f) ((float) cosh(f)) +#define expf(f) ((float) exp(f)) +#define exp2f(f) ((float) exp2(f)) +#define floorf(f) ((float) floor(f)) +#define logf(f) ((float) log(f)) +#define log2f(f) ((float) log2(f)) +#define powf(x,y) ((float) pow(x,y)) +#define sinf(f) ((float) sin(f)) +#define sinhf(f) ((float) sinh(f)) +#define sqrtf(f) ((float) sqrt(f)) +#define tanf(f) ((float) tan(f)) +#define tanhf(f) ((float) tanh(f)) +#define truncf(f) ((float) trunc(f)) +#endif +/*@}*/ + /*** *** LOG2: Log base 2 of float ***/ diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index 8d92892ad7d..b8bcda56bfa 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -2084,6 +2084,15 @@ struct gl_shader struct gl_program *Program; /**< Post-compile assembly code */ GLchar *InfoLog; struct gl_sl_pragmas Pragmas; + + unsigned Version; /**< GLSL version used for linking */ + + struct exec_list *ir; + struct glsl_symbol_table *symbols; + + /** Shaders containing built-in functions that are used for linking. */ + struct gl_shader *builtins_to_link[16]; + unsigned num_builtins_to_link; }; @@ -2129,6 +2138,16 @@ struct gl_shader_program GLboolean Validated; GLboolean _Used; /**< Ever used for drawing? */ GLchar *InfoLog; + + unsigned Version; /**< GLSL version used for linking */ + + /** + * Per-stage shaders resulting from the first stage of linking. + */ + /*@{*/ + GLuint _NumLinkedShaders; + struct gl_shader *_LinkedShaders[2]; + /*@}*/ }; @@ -2154,6 +2173,11 @@ struct gl_shader_state GLboolean EmitCondCodes; /**< Use condition codes? */ GLboolean EmitComments; /**< Annotated instructions */ GLboolean EmitNVTempInitialization; /**< 0-fill NV temp registers */ + /** + * Attempts to flatten all ir_if (OPCODE_IF) for GPUs that can't + * support control flow. + */ + GLboolean EmitNoIfs; void *MemPool; GLbitfield Flags; /**< Mask of GLSL_x flags */ struct gl_sl_pragmas DefaultPragmas; /**< Default #pragma settings */ diff --git a/src/mesa/main/shaderapi.c b/src/mesa/main/shaderapi.c index 9cb2391035d..89b9557e84f 100644 --- a/src/mesa/main/shaderapi.c +++ b/src/mesa/main/shaderapi.c @@ -48,6 +48,7 @@ #include "program/prog_uniform.h" #include "slang/slang_compile.h" #include "slang/slang_link.h" +#include "talloc.h" /** Define this to enable shader substitution (see below) */ @@ -99,6 +100,7 @@ _mesa_init_shader_state(GLcontext *ctx) ctx->Shader.EmitContReturn = GL_TRUE; ctx->Shader.EmitCondCodes = GL_FALSE; ctx->Shader.EmitComments = GL_FALSE; + ctx->Shader.EmitNoIfs = GL_FALSE; ctx->Shader.Flags = get_shader_flags(); /* Default pragma settings */ @@ -800,7 +802,7 @@ compile_shader(GLcontext *ctx, GLuint shaderObj) /* this call will set the sh->CompileStatus field to indicate if * compilation was successful. */ - (void) _slang_compile(ctx, sh); + _mesa_glsl_compile_shader(ctx, sh); } @@ -826,7 +828,7 @@ link_program(GLcontext *ctx, GLuint program) FLUSH_VERTICES(ctx, _NEW_PROGRAM); - _slang_link(ctx, program, shProg); + _mesa_glsl_link_shader(ctx, shProg); /* debug code */ if (0) { @@ -1051,9 +1053,9 @@ validate_program(GLcontext *ctx, GLuint program) if (!shProg->Validated) { /* update info log */ if (shProg->InfoLog) { - free(shProg->InfoLog); + talloc_free(shProg->InfoLog); } - shProg->InfoLog = _mesa_strdup(errMsg); + shProg->InfoLog = talloc_strdup(shProg, errMsg); } } diff --git a/src/mesa/main/shaderobj.c b/src/mesa/main/shaderobj.c index 14bbb2e4bc3..863d50fbe55 100644 --- a/src/mesa/main/shaderobj.c +++ b/src/mesa/main/shaderobj.c @@ -36,7 +36,7 @@ #include "program/program.h" #include "program/prog_parameter.h" #include "program/prog_uniform.h" - +#include "talloc.h" /**********************************************************************/ /*** Shader object functions ***/ @@ -92,13 +92,13 @@ _mesa_reference_shader(GLcontext *ctx, struct gl_shader **ptr, * Allocate a new gl_shader object, initialize it. * Called via ctx->Driver.NewShader() */ -static struct gl_shader * +struct gl_shader * _mesa_new_shader(GLcontext *ctx, GLuint name, GLenum type) { struct gl_shader *shader; assert(type == GL_FRAGMENT_SHADER || type == GL_VERTEX_SHADER || type == GL_GEOMETRY_SHADER_ARB); - shader = CALLOC_STRUCT(gl_shader); + shader = talloc_zero(NULL, struct gl_shader); if (shader) { shader->Type = type; shader->Name = name; @@ -117,10 +117,8 @@ __mesa_delete_shader(GLcontext *ctx, struct gl_shader *sh) { if (sh->Source) free((void *) sh->Source); - if (sh->InfoLog) - free(sh->InfoLog); _mesa_reference_program(ctx, &sh->Program, NULL); - free(sh); + talloc_free(sh); } @@ -235,7 +233,7 @@ static struct gl_shader_program * _mesa_new_shader_program(GLcontext *ctx, GLuint name) { struct gl_shader_program *shProg; - shProg = CALLOC_STRUCT(gl_shader_program); + shProg = talloc_zero(NULL, struct gl_shader_program); if (shProg) { shProg->Type = GL_SHADER_PROGRAM_MESA; shProg->Name = name; @@ -305,7 +303,7 @@ _mesa_free_shader_program_data(GLcontext *ctx, } if (shProg->InfoLog) { - free(shProg->InfoLog); + talloc_free(shProg->InfoLog); shProg->InfoLog = NULL; } @@ -328,7 +326,7 @@ __mesa_delete_shader_program(GLcontext *ctx, struct gl_shader_program *shProg) { _mesa_free_shader_program_data(ctx, shProg); - free(shProg); + talloc_free(shProg); } @@ -389,4 +387,6 @@ _mesa_init_shader_object_functions(struct dd_function_table *driver) driver->DeleteShader = __mesa_delete_shader; driver->NewShaderProgram = _mesa_new_shader_program; driver->DeleteShaderProgram = __mesa_delete_shader_program; + driver->CompileShader = _mesa_ir_compile_shader; + driver->LinkShader = _mesa_ir_link_shader; } diff --git a/src/mesa/main/shaderobj.h b/src/mesa/main/shaderobj.h index d6b37b45963..1b96316b67b 100644 --- a/src/mesa/main/shaderobj.h +++ b/src/mesa/main/shaderobj.h @@ -27,8 +27,22 @@ #define SHADEROBJ_H -#include "glheader.h" -#include "mtypes.h" +#include "main/glheader.h" +#include "main/mtypes.h" +#include "program/ir_to_mesa.h" + +#ifdef __cplusplus +extern "C" { +#endif +/** + * Internal functions + */ + +extern void +_mesa_init_shader_state(GLcontext * ctx); + +extern void +_mesa_free_shader_state(GLcontext *ctx); extern void @@ -48,6 +62,9 @@ _mesa_reference_shader_program(GLcontext *ctx, struct gl_shader_program **ptr, struct gl_shader_program *shProg); +extern struct gl_shader * +_mesa_new_shader(GLcontext *ctx, GLuint name, GLenum type); + extern struct gl_shader_program * _mesa_lookup_shader_program(GLcontext *ctx, GLuint name); @@ -74,5 +91,8 @@ _mesa_init_shader_state(GLcontext *ctx); extern void _mesa_free_shader_state(GLcontext *ctx); +#ifdef __cplusplus +} +#endif #endif /* SHADEROBJ_H */ |