[Mesa-dev] [PATCH 04/10] glsl: make compiler options per-target

Luca Barbieri luca at luca-barbieri.com
Sun Sep 5 18:30:46 PDT 2010


This allows us to specify different options, especially useful for chips
without unified shaders.
---
 src/mesa/main/mtypes.h                 |   15 ++++++++++++---
 src/mesa/main/nvprogram.c              |    4 +++-
 src/mesa/main/shaderapi.c              |   31 ++++++++++++++++++++-----------
 src/mesa/program/ir_to_mesa.cpp        |   12 +++++++++---
 src/mesa/state_tracker/st_extensions.c |    6 ++++--
 5 files changed, 48 insertions(+), 20 deletions(-)

diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index d2d7b10..657df68 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
  */
@@ -3215,6 +3223,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 100ff2c..3a570b7 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 cc350c9..2977a29 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.
diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp
index d61698b..d73e338 100644
--- a/src/mesa/program/ir_to_mesa.cpp
+++ b/src/mesa/program/ir_to_mesa.cpp
@@ -186,6 +186,7 @@ public:
    GLcontext *ctx;
    struct gl_program *prog;
    struct gl_shader_program *shader_program;
+   struct gl_shader_compiler_options *options;
 
    int next_temp;
 
@@ -2110,7 +2111,7 @@ ir_to_mesa_visitor::visit(ir_if *ir)
    ir->condition->accept(this);
    assert(this->result.file != PROGRAM_UNDEFINED);
 
-   if (ctx->Shader.EmitCondCodes) {
+   if (options->EmitCondCodes) {
       cond_inst = (ir_to_mesa_instruction *)this->instructions.get_tail();
 
       /* See if we actually generated any instruction for generating
@@ -2540,6 +2541,8 @@ get_mesa_program(GLcontext *ctx, struct gl_shader_program *shader_program,
    GLenum target;
    const char *target_string;
    GLboolean progress;
+   struct gl_shader_compiler_options *options =
+         &ctx->ShaderCompilerOptions[_mesa_shader_type_to_index(shader->Type)];
 
    switch (shader->Type) {
    case GL_VERTEX_SHADER:
@@ -2566,6 +2569,7 @@ get_mesa_program(GLcontext *ctx, struct gl_shader_program *shader_program,
    v.ctx = ctx;
    v.prog = prog;
    v.shader_program = shader_program;
+   v.options = options;
 
    add_uniforms_to_parameters_list(shader_program, shader, prog);
 
@@ -2643,7 +2647,7 @@ get_mesa_program(GLcontext *ctx, struct gl_shader_program *shader_program,
          if (mesa_inst->SrcReg[src].RelAddr)
             prog->IndirectRegisterFiles |= 1 << mesa_inst->SrcReg[src].File;
 
-      if (ctx->Shader.EmitNoIfs && mesa_inst->Opcode == OPCODE_IF) {
+      if (options->EmitNoIfs && mesa_inst->Opcode == OPCODE_IF) {
 	 fail_link(shader_program, "Couldn't flatten if statement\n");
       }
 
@@ -2717,6 +2721,8 @@ _mesa_ir_link_shader(GLcontext *ctx, struct gl_shader_program *prog)
    for (unsigned i = 0; i < prog->_NumLinkedShaders; i++) {
       bool progress;
       exec_list *ir = prog->_LinkedShaders[i]->ir;
+      struct gl_shader_compiler_options *options =
+            &ctx->ShaderCompilerOptions[_mesa_shader_type_to_index(prog->_LinkedShaders[i]->Type)];
 
       do {
 	 progress = false;
@@ -2729,7 +2735,7 @@ _mesa_ir_link_shader(GLcontext *ctx, struct gl_shader_program *prog)
 
 	 progress = do_common_optimization(ir, true) || progress;
 
-	 if (ctx->Shader.EmitNoIfs)
+	 if (options->EmitNoIfs)
 	    progress = do_if_to_cond_assign(ir) || progress;
 
 	 progress = do_vec_index_to_cond_assign(ir) || progress;
diff --git a/src/mesa/state_tracker/st_extensions.c b/src/mesa/state_tracker/st_extensions.c
index acb9526..82be149 100644
--- a/src/mesa/state_tracker/st_extensions.c
+++ b/src/mesa/state_tracker/st_extensions.c
@@ -68,6 +68,7 @@ void st_init_limits(struct st_context *st)
    struct pipe_screen *screen = st->pipe->screen;
    struct gl_constants *c = &st->ctx->Const;
    struct gl_program_constants *pc;
+   unsigned i;
 
    c->MaxTextureLevels
       = _min(screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_2D_LEVELS),
@@ -136,8 +137,9 @@ void st_init_limits(struct st_context *st)
 
    /* Is TGSI_OPCODE_CONT supported? */
    /* XXX separate query for early function return? */
-   st->ctx->Shader.EmitContReturn =
-      screen->get_param(screen, PIPE_CAP_TGSI_CONT_SUPPORTED);
+   for(i = 0; i < MESA_SHADER_TYPES; ++i)
+      st->ctx->ShaderCompilerOptions[i].EmitContReturn =
+            screen->get_param(screen, PIPE_CAP_TGSI_CONT_SUPPORTED);
 
    /* Quads always follow GL provoking rules. */
    c->QuadsFollowProvokingVertexConvention = GL_FALSE;
-- 
1.7.0.4



More information about the mesa-dev mailing list