From 6d3a2c97f4a78e85545286e0e126cd3a27bd1cbd Mon Sep 17 00:00:00 2001 From: Luca Barbieri Date: Sun, 5 Sep 2010 18:49:54 +0200 Subject: glsl: make compiler options per-target This allows us to specify different options, especially useful for chips without unified shaders. Signed-off-by: Ian Romanick --- src/mesa/main/mtypes.h | 15 ++++++++++++--- src/mesa/main/nvprogram.c | 4 +++- src/mesa/main/shaderapi.c | 31 ++++++++++++++++++++----------- 3 files changed, 35 insertions(+), 15 deletions(-) (limited to 'src/mesa/main') diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index 7d5ce7040b..61cd93c364 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -2175,6 +2175,16 @@ struct gl_shader_program struct gl_shader_state { struct gl_shader_program *CurrentProgram; /**< The user-bound program */ + void *MemPool; + + GLbitfield Flags; /**< Mask of GLSL_x flags */ +}; + +/** + * Compiler options for a single GLSL shaders type + */ +struct gl_shader_compiler_options +{ /** Driver-selectable options: */ GLboolean EmitHighLevelInstructions; /**< IF/ELSE/ENDIF vs. BRA, etc. */ GLboolean EmitContReturn; /**< Emit CONT/RET opcodes? */ @@ -2186,12 +2196,10 @@ struct gl_shader_state * support control flow. */ GLboolean EmitNoIfs; - void *MemPool; - GLbitfield Flags; /**< Mask of GLSL_x flags */ + struct gl_sl_pragmas DefaultPragmas; /**< Default #pragma settings */ }; - /** * Transform feedback object state */ @@ -3212,6 +3220,7 @@ struct __GLcontextRec struct gl_ati_fragment_shader_state ATIFragmentShader; struct gl_shader_state Shader; /**< GLSL shader object state */ + struct gl_shader_compiler_options ShaderCompilerOptions[MESA_SHADER_TYPES]; struct gl_query_state Query; /**< occlusion, timer queries */ diff --git a/src/mesa/main/nvprogram.c b/src/mesa/main/nvprogram.c index 100ff2c4ab..3a570b7dda 100644 --- a/src/mesa/main/nvprogram.c +++ b/src/mesa/main/nvprogram.c @@ -516,8 +516,10 @@ _mesa_emit_nv_temp_initialization(GLcontext *ctx, { struct prog_instruction *inst; GLuint i; + struct gl_shader_compiler_options* options = + &ctx->ShaderCompilerOptions[_mesa_program_target_to_index(program->Target)]; - if (!ctx->Shader.EmitNVTempInitialization) + if (!options->EmitNVTempInitialization) return; /* We'll swizzle up a zero temporary so we can use it for the diff --git a/src/mesa/main/shaderapi.c b/src/mesa/main/shaderapi.c index cc350c93b9..2977a29ab7 100644 --- a/src/mesa/main/shaderapi.c +++ b/src/mesa/main/shaderapi.c @@ -94,18 +94,24 @@ _mesa_init_shader_state(GLcontext *ctx) /* Device drivers may override these to control what kind of instructions * are generated by the GLSL compiler. */ - ctx->Shader.EmitHighLevelInstructions = GL_TRUE; - 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(); + struct gl_shader_compiler_options options; + GLuint i; + options.EmitHighLevelInstructions = GL_TRUE; + options.EmitContReturn = GL_TRUE; + options.EmitCondCodes = GL_FALSE; + options.EmitComments = GL_FALSE; + options.EmitNoIfs = GL_FALSE; /* Default pragma settings */ - ctx->Shader.DefaultPragmas.IgnoreOptimize = GL_FALSE; - ctx->Shader.DefaultPragmas.IgnoreDebug = GL_FALSE; - ctx->Shader.DefaultPragmas.Optimize = GL_TRUE; - ctx->Shader.DefaultPragmas.Debug = GL_FALSE; + options.DefaultPragmas.IgnoreOptimize = GL_FALSE; + options.DefaultPragmas.IgnoreDebug = GL_FALSE; + options.DefaultPragmas.Optimize = GL_TRUE; + options.DefaultPragmas.Debug = GL_FALSE; + + for(i = 0; i < MESA_SHADER_TYPES; ++i) + memcpy(&ctx->ShaderCompilerOptions[i], &options, sizeof(options)); + + ctx->Shader.Flags = get_shader_flags(); } @@ -789,13 +795,16 @@ static void compile_shader(GLcontext *ctx, GLuint shaderObj) { struct gl_shader *sh; + struct gl_shader_compiler_options *options; sh = _mesa_lookup_shader_err(ctx, shaderObj, "glCompileShader"); if (!sh) return; + options = &ctx->ShaderCompilerOptions[_mesa_shader_type_to_index(sh->Type)]; + /* set default pragma state for shader */ - sh->Pragmas = ctx->Shader.DefaultPragmas; + sh->Pragmas = options->DefaultPragmas; /* this call will set the sh->CompileStatus field to indicate if * compilation was successful. -- cgit v1.2.3