Looks good Ian.

The only reason I can think of for retaining it was hw with fragement shaders 
*and* fixed function fog handling, ie the i915.  But mesa never properly 
supported that and now fog is always incorporated into the fragment shader, so 
removing this code is a nice cleanup.

Keith
________________________________________
From: Ian Romanick [[email protected]]
Sent: Friday, September 25, 2009 5:44 PM
To: [email protected]
Cc: Ian Romanick
Subject: [Mesa3d-dev] [PATCH] Kill FogOption from gl_fragment_program

From: Ian Romanick <[email protected]>

FogOption was only set as transient state during compilation of
ARB_fragment_program or during generation of a texenv program.  Once
either of those routines is complete, FogOption is always GL_NONE.

Signed-off-by: Ian Romanick <[email protected]>
---
 src/mesa/drivers/dri/i915/i915_fragprog.c          |    9 ---------
 src/mesa/drivers/dri/i915/i915_state.c             |   12 ++----------
 src/mesa/drivers/dri/i965/brw_program.c            |    5 -----
 .../drivers/dri/r300/compiler/r300_fragprog_emit.c |    2 --
 .../drivers/dri/r300/compiler/r500_fragprog_emit.c |    3 ---
 src/mesa/main/mtypes.h                             |    1 -
 src/mesa/main/texenvprogram.c                      |   13 +++++--------
 src/mesa/shader/arbprogparse.c                     |   16 ++++++++--------
 src/mesa/shader/program.c                          |    1 -
 src/mesa/shader/programopt.c                       |   19 ++++++++++---------
 src/mesa/shader/programopt.h                       |    3 ++-
 src/mesa/swrast/s_context.c                        |    9 ++-------
 src/mesa/tnl/t_context.c                           |    2 +-
 13 files changed, 30 insertions(+), 65 deletions(-)

diff --git a/src/mesa/drivers/dri/i915/i915_fragprog.c 
b/src/mesa/drivers/dri/i915/i915_fragprog.c
index 2db10c6..a434533 100644
--- a/src/mesa/drivers/dri/i915/i915_fragprog.c
+++ b/src/mesa/drivers/dri/i915/i915_fragprog.c
@@ -1041,15 +1041,6 @@ i915ProgramStringNotify(GLcontext * ctx,
    if (target == GL_FRAGMENT_PROGRAM_ARB) {
       struct i915_fragment_program *p = (struct i915_fragment_program *) prog;
       p->translated = 0;
-
-      /* Hack: make sure fog is correctly enabled according to this
-       * fragment program's fog options.
-       */
-      if (p->FragProg.FogOption) {
-         /* add extra instructions to do fog, then turn off FogOption field */
-         _mesa_append_fog_code(ctx, &p->FragProg);
-         p->FragProg.FogOption = GL_NONE;
-      }
    }

    _tnl_program_string(ctx, target, prog);
diff --git a/src/mesa/drivers/dri/i915/i915_state.c 
b/src/mesa/drivers/dri/i915/i915_state.c
index b60efea..624676b 100644
--- a/src/mesa/drivers/dri/i915/i915_state.c
+++ b/src/mesa/drivers/dri/i915/i915_state.c
@@ -673,23 +673,15 @@ i915_update_fog(GLcontext * ctx)
    struct i915_context *i915 = I915_CONTEXT(ctx);
    GLenum mode;
    GLboolean enabled;
-   GLboolean try_pixel_fog;
+   GLboolean try_pixel_fog = 0;

-   if (ctx->FragmentProgram._Current) {
-      /* Pull in static fog state from program */
-      mode = ctx->FragmentProgram._Current->FogOption;
-      enabled = (mode != GL_NONE);
-      try_pixel_fog = 0;
-   }
-   else {
+   if (!ctx->FragmentProgram._Current) {
       enabled = ctx->Fog.Enabled;
       mode = ctx->Fog.Mode;
 #if 0
       /* XXX - DISABLED -- Need ortho fallback */
       try_pixel_fog = (ctx->Fog.FogCoordinateSource == GL_FRAGMENT_DEPTH_EXT
                        && ctx->Hint.Fog == GL_NICEST);
-#else
-      try_pixel_fog = 0;
 #endif
    }

diff --git a/src/mesa/drivers/dri/i965/brw_program.c 
b/src/mesa/drivers/dri/i965/brw_program.c
index bac6918..94d94a3 100644
--- a/src/mesa/drivers/dri/i965/brw_program.c
+++ b/src/mesa/drivers/dri/i965/brw_program.c
@@ -124,11 +124,6 @@ static void brwProgramStringNotify( GLcontext *ctx,
       const struct brw_fragment_program *curFP =
          brw_fragment_program_const(brw->fragment_program);

-      if (fprog->FogOption) {
-         _mesa_append_fog_code(ctx, fprog);
-         fprog->FogOption = GL_NONE;
-      }
-
       if (newFP == curFP)
         brw->state.dirty.brw |= BRW_NEW_FRAGMENT_PROGRAM;
       newFP->id = brw->program_id++;
diff --git a/src/mesa/drivers/dri/r300/compiler/r300_fragprog_emit.c 
b/src/mesa/drivers/dri/r300/compiler/r300_fragprog_emit.c
index c7227bb..d5ff9b7 100644
--- a/src/mesa/drivers/dri/r300/compiler/r300_fragprog_emit.c
+++ b/src/mesa/drivers/dri/r300/compiler/r300_fragprog_emit.c
@@ -34,8 +34,6 @@
  * \author Ben Skeggs <[email protected]>
  *
  * \author Jerome Glisse <[email protected]>
- *
- * \todo FogOption
  */

 #include "r300_fragprog.h"
diff --git a/src/mesa/drivers/dri/r300/compiler/r500_fragprog_emit.c 
b/src/mesa/drivers/dri/r300/compiler/r500_fragprog_emit.c
index d694725..eebb504 100644
--- a/src/mesa/drivers/dri/r300/compiler/r500_fragprog_emit.c
+++ b/src/mesa/drivers/dri/r300/compiler/r500_fragprog_emit.c
@@ -38,9 +38,6 @@
  * \author Corbin Simpson <[email protected]>
  *
  * \todo Depth write, WPOS/FOGC inputs
- *
- * \todo FogOption
- *
  */

 #include "r500_fragprog.h"
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index d7bf768..aaa5282 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -1841,7 +1841,6 @@ struct gl_vertex_program
 struct gl_fragment_program
 {
    struct gl_program Base;   /**< base class */
-   GLenum FogOption;
    GLboolean UsesKill;          /**< shader uses KIL instruction */
 };

diff --git a/src/mesa/main/texenvprogram.c b/src/mesa/main/texenvprogram.c
index d7e77e7..1d86ec8 100644
--- a/src/mesa/main/texenvprogram.c
+++ b/src/mesa/main/texenvprogram.c
@@ -1405,6 +1405,7 @@ create_new_program(GLcontext *ctx, struct state_key *key,
    struct texenv_fragment_program p;
    GLuint unit;
    struct ureg cf, out;
+   GLenum fog_option = GL_NONE;

    _mesa_memset(&p, 0, sizeof(p));
    p.state = key;
@@ -1497,14 +1498,11 @@ create_new_program(GLcontext *ctx, struct state_key 
*key,

    if (key->fog_enabled) {
       /* Pull fog mode from GLcontext, the value in the state key is
-       * a reduced value and not what is expected in FogOption
+       * a reduced value.
        */
-      p.program->FogOption = ctx->Fog.Mode;
+      fog_option = ctx->Fog.Mode;
       p.program->Base.InputsRead |= FRAG_BIT_FOGC;
    }
-   else {
-      p.program->FogOption = GL_NONE;
-   }

    if (p.program->Base.NumTexIndirections > 
ctx->Const.FragmentProgram.MaxTexIndirections)
       program_error(&p, "Exceeded max nr indirect texture lookups");
@@ -1528,9 +1526,8 @@ create_new_program(GLcontext *ctx, struct state_key *key,
    _mesa_copy_instructions(p.program->Base.Instructions, instBuffer,
                            p.program->Base.NumInstructions);

-   if (p.program->FogOption) {
-      _mesa_append_fog_code(ctx, p.program);
-      p.program->FogOption = GL_NONE;
+   if (fog_option) {
+      _mesa_append_fog_code(ctx, p.program, fog_option);
    }


diff --git a/src/mesa/shader/arbprogparse.c b/src/mesa/shader/arbprogparse.c
index 05ee4f5..06923f9 100644
--- a/src/mesa/shader/arbprogparse.c
+++ b/src/mesa/shader/arbprogparse.c
@@ -74,6 +74,7 @@ _mesa_parse_arb_fragment_program(GLcontext* ctx, GLenum 
target,
    struct gl_program prog;
    struct asm_parser_state state;
    GLuint i;
+   GLenum fog_option;

    ASSERT(target == GL_FRAGMENT_PROGRAM_ARB);

@@ -116,15 +117,15 @@ _mesa_parse_arb_fragment_program(GLcontext* ctx, GLenum 
target,
    }
    program->Base.ShadowSamplers = prog.ShadowSamplers;
    switch (state.option.Fog) {
-   case OPTION_FOG_EXP:    program->FogOption = GL_EXP;    break;
-   case OPTION_FOG_EXP2:   program->FogOption = GL_EXP2;   break;
-   case OPTION_FOG_LINEAR: program->FogOption = GL_LINEAR; break;
-   default:                program->FogOption = GL_NONE;   break;
+   case OPTION_FOG_EXP:    fog_option = GL_EXP;    break;
+   case OPTION_FOG_EXP2:   fog_option = GL_EXP2;   break;
+   case OPTION_FOG_LINEAR: fog_option = GL_LINEAR; break;
+   default:                fog_option = GL_NONE;   break;
    }

    program->UsesKill            = state.fragment.UsesKill;

-   if (program->FogOption)
+   if (fog_option)
       program->Base.InputsRead |= FRAG_BIT_FOGC;

    if (program->Base.Instructions)
@@ -140,9 +141,8 @@ _mesa_parse_arb_fragment_program(GLcontext* ctx, GLenum 
target,
     * there's no hardware that wants to do fog in a discrete stage separate
     * from the fragment shader.
     */
-   if (program->FogOption != GL_NONE) {
-      _mesa_append_fog_code(ctx, program);
-      program->FogOption = GL_NONE;
+   if (fog_option) {
+      _mesa_append_fog_code(ctx, program, fog_option);
    }

 #if DEBUG_FP
diff --git a/src/mesa/shader/program.c b/src/mesa/shader/program.c
index 532adf4..669100f 100644
--- a/src/mesa/shader/program.c
+++ b/src/mesa/shader/program.c
@@ -503,7 +503,6 @@ _mesa_clone_program(GLcontext *ctx, const struct gl_program 
*prog)
          const struct gl_fragment_program *fp
             = (const struct gl_fragment_program *) prog;
          struct gl_fragment_program *fpc = (struct gl_fragment_program *) 
clone;
-         fpc->FogOption = fp->FogOption;
          fpc->UsesKill = fp->UsesKill;
       }
       break;
diff --git a/src/mesa/shader/programopt.c b/src/mesa/shader/programopt.c
index f70c75c..5c382a3 100644
--- a/src/mesa/shader/programopt.c
+++ b/src/mesa/shader/programopt.c
@@ -231,14 +231,15 @@ _mesa_insert_mvp_code(GLcontext *ctx, struct 
gl_vertex_program *vprog)

 /**
  * Append extra instructions onto the given fragment program to implement
- * the fog mode specified by fprog->FogOption.
+ * the fog mode specified by \c fog_option.
  * The fragment.fogcoord input is used to compute the fog blend factor.
  *
  * XXX with a little work, this function could be adapted to add fog code
  * to vertex programs too.
  */
 void
-_mesa_append_fog_code(GLcontext *ctx, struct gl_fragment_program *fprog)
+_mesa_append_fog_code(GLcontext *ctx, struct gl_fragment_program *fprog,
+                     GLenum fog_option)
 {
    static const gl_state_index fogPStateOpt[STATE_LENGTH]
       = { STATE_INTERNAL, STATE_FOG_PARAMS_OPTIMIZED, 0, 0, 0 };
@@ -251,9 +252,9 @@ _mesa_append_fog_code(GLcontext *ctx, struct 
gl_fragment_program *fprog)
    GLint fogPRefOpt, fogColorRef; /* state references */
    GLuint colorTemp, fogFactorTemp; /* temporary registerss */

-   if (fprog->FogOption == GL_NONE) {
+   if (fog_option == GL_NONE) {
       _mesa_problem(ctx, "_mesa_append_fog_code() called for fragment program"
-                    " with FogOption == GL_NONE");
+                    " with fog_option == GL_NONE");
       return;
    }

@@ -300,7 +301,7 @@ _mesa_append_fog_code(GLcontext *ctx, struct 
gl_fragment_program *fprog)
    _mesa_init_instructions(inst, 5);

    /* emit instructions to compute fog blending factor */
-   if (fprog->FogOption == GL_LINEAR) {
+   if (fog_option == GL_LINEAR) {
       /* MAD fogFactorTemp.x, fragment.fogcoord.x, fogPRefOpt.x, fogPRefOpt.y; 
*/
       inst->Opcode = OPCODE_MAD;
       inst->DstReg.File = PROGRAM_TEMPORARY;
@@ -319,7 +320,7 @@ _mesa_append_fog_code(GLcontext *ctx, struct 
gl_fragment_program *fprog)
       inst++;
    }
    else {
-      ASSERT(fprog->FogOption == GL_EXP || fprog->FogOption == GL_EXP2);
+      ASSERT(fog_option == GL_EXP || fog_option == GL_EXP2);
       /* fogPRefOpt.z = d/ln(2), fogPRefOpt.w = d/sqrt(ln(2) */
       /* EXP: MUL fogFactorTemp.x, fogPRefOpt.z, fragment.fogcoord.x; */
       /* EXP2: MUL fogFactorTemp.x, fogPRefOpt.w, fragment.fogcoord.x; */
@@ -330,12 +331,12 @@ _mesa_append_fog_code(GLcontext *ctx, struct 
gl_fragment_program *fprog)
       inst->SrcReg[0].File = PROGRAM_STATE_VAR;
       inst->SrcReg[0].Index = fogPRefOpt;
       inst->SrcReg[0].Swizzle
-         = (fprog->FogOption == GL_EXP) ? SWIZZLE_ZZZZ : SWIZZLE_WWWW;
+         = (fog_option == GL_EXP) ? SWIZZLE_ZZZZ : SWIZZLE_WWWW;
       inst->SrcReg[1].File = PROGRAM_INPUT;
       inst->SrcReg[1].Index = FRAG_ATTRIB_FOGC;
       inst->SrcReg[1].Swizzle = SWIZZLE_XXXX;
       inst++;
-      if (fprog->FogOption == GL_EXP2) {
+      if (fog_option == GL_EXP2) {
          /* MUL fogFactorTemp.x, fogFactorTemp.x, fogFactorTemp.x; */
          inst->Opcode = OPCODE_MUL;
          inst->DstReg.File = PROGRAM_TEMPORARY;
@@ -396,7 +397,7 @@ _mesa_append_fog_code(GLcontext *ctx, struct 
gl_fragment_program *fprog)
    fprog->Base.Instructions = newInst;
    fprog->Base.NumInstructions = inst - newInst;
    fprog->Base.InputsRead |= FRAG_BIT_FOGC;
-   /* XXX do this?  fprog->FogOption = GL_NONE; */
+   /* XXX do this?  fog_option = GL_NONE; */
 }


diff --git a/src/mesa/shader/programopt.h b/src/mesa/shader/programopt.h
index 96acaf9..071f835 100644
--- a/src/mesa/shader/programopt.h
+++ b/src/mesa/shader/programopt.h
@@ -31,7 +31,8 @@ extern void
 _mesa_insert_mvp_code(GLcontext *ctx, struct gl_vertex_program *vprog);

 extern void
-_mesa_append_fog_code(GLcontext *ctx, struct gl_fragment_program *fprog);
+_mesa_append_fog_code(GLcontext *ctx, struct gl_fragment_program *fprog,
+                     GLenum fog_option);

 extern void
 _mesa_count_texture_indirections(struct gl_program *prog);
diff --git a/src/mesa/swrast/s_context.c b/src/mesa/swrast/s_context.c
index abf0008..5f5ffae 100644
--- a/src/mesa/swrast/s_context.c
+++ b/src/mesa/swrast/s_context.c
@@ -245,13 +245,8 @@ _swrast_update_fog_state( GLcontext *ctx )

    /* determine if fog is needed, and if so, which fog mode */
    swrast->_FogEnabled = GL_FALSE;
-   if (fp && fp->Base.Target == GL_FRAGMENT_PROGRAM_ARB) {
-      if (fp->FogOption != GL_NONE) {
-         swrast->_FogEnabled = GL_TRUE;
-         swrast->_FogMode = fp->FogOption;
-      }
-   }
-   else if (ctx->Fog.Enabled) {
+   if (((fp == NULL) || (fp->Base.Target != GL_FRAGMENT_PROGRAM_ARB))
+       && ctx->Fog.Enabled) {
       swrast->_FogEnabled = GL_TRUE;
       swrast->_FogMode = ctx->Fog.Mode;
    }
diff --git a/src/mesa/tnl/t_context.c b/src/mesa/tnl/t_context.c
index f2771cd..6bb8a08 100644
--- a/src/mesa/tnl/t_context.c
+++ b/src/mesa/tnl/t_context.c
@@ -150,7 +150,7 @@ _tnl_InvalidateState( GLcontext *ctx, GLuint new_state )
       RENDERINPUTS_SET( tnl->render_inputs_bitset, _TNL_ATTRIB_FOG );
    }
    else if (fp) {
-      if (fp->FogOption != GL_NONE || (fp->Base.InputsRead & FRAG_BIT_FOGC)) {
+      if (fp->Base.InputsRead & FRAG_BIT_FOGC) {
          /* fragment program needs fog coord */
          RENDERINPUTS_SET( tnl->render_inputs_bitset, _TNL_ATTRIB_FOG );
       }
--
1.6.4.3


------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
Mesa3d-dev mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mesa3d-dev

------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
Mesa3d-dev mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mesa3d-dev

Reply via email to