gallium/u_blit: remove useless memset calls
[mesa.git] / src / mesa / program / programopt.c
index 5ad9571f757b3e3de05293c99874231dddfc5982..389ea218b488b87a98a49ddabad607cdca0970dd 100644 (file)
@@ -230,15 +230,25 @@ _mesa_insert_mvp_code(struct gl_context *ctx, struct gl_vertex_program *vprog)
 
 
 /**
- * Append extra instructions onto the given fragment program to implement
- * the fog mode specified by fprog->FogOption.
- * The fragment.fogcoord input is used to compute the fog blend factor.
+ * Append instructions to implement fog
  *
- * XXX with a little work, this function could be adapted to add fog code
+ * The \c fragment.fogcoord input is used to compute the fog blend factor.
+ *
+ * \param ctx      The GL context
+ * \param fprog    Fragment program that fog instructions will be appended to.
+ * \param fog_mode Fog mode.  One of \c GL_EXP, \c GL_EXP2, or \c GL_LINEAR.
+ * \param saturate True if writes to color outputs should be clamped to [0, 1]
+ *
+ * \note
+ * This function sets \c FRAG_BIT_FOGC in \c fprog->Base.InputsRead.
+ *
+ * \todo With a little work, this function could be adapted to add fog code
  * to vertex programs too.
  */
 void
-_mesa_append_fog_code(struct gl_context *ctx, struct gl_fragment_program *fprog, GLboolean saturate)
+_mesa_append_fog_code(struct gl_context *ctx,
+                     struct gl_fragment_program *fprog, GLenum fog_mode,
+                     GLboolean saturate)
 {
    static const gl_state_index fogPStateOpt[STATE_LENGTH]
       = { STATE_INTERNAL, STATE_FOG_PARAMS_OPTIMIZED, 0, 0, 0 };
@@ -251,9 +261,14 @@ _mesa_append_fog_code(struct gl_context *ctx, struct gl_fragment_program *fprog,
    GLint fogPRefOpt, fogColorRef; /* state references */
    GLuint colorTemp, fogFactorTemp; /* temporary registerss */
 
-   if (fprog->FogOption == GL_NONE) {
+   if (fog_mode == GL_NONE) {
       _mesa_problem(ctx, "_mesa_append_fog_code() called for fragment program"
-                    " with FogOption == GL_NONE");
+                    " with fog_mode == GL_NONE");
+      return;
+   }
+
+   if (!(fprog->Base.OutputsWritten & (1 << FRAG_RESULT_COLOR))) {
+      /* program doesn't output color, so nothing to do */
       return;
    }
 
@@ -301,7 +316,7 @@ _mesa_append_fog_code(struct gl_context *ctx, struct gl_fragment_program *fprog,
 
    /* emit instructions to compute fog blending factor */
    /* this is always clamped to [0, 1] regardless of fragment clamping */
-   if (fprog->FogOption == GL_LINEAR) {
+   if (fog_mode == GL_LINEAR) {
       /* MAD fogFactorTemp.x, fragment.fogcoord.x, fogPRefOpt.x, fogPRefOpt.y; */
       inst->Opcode = OPCODE_MAD;
       inst->DstReg.File = PROGRAM_TEMPORARY;
@@ -320,7 +335,7 @@ _mesa_append_fog_code(struct gl_context *ctx, struct gl_fragment_program *fprog,
       inst++;
    }
    else {
-      ASSERT(fprog->FogOption == GL_EXP || fprog->FogOption == GL_EXP2);
+      ASSERT(fog_mode == GL_EXP || fog_mode == 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; */
@@ -331,12 +346,12 @@ _mesa_append_fog_code(struct gl_context *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_mode == 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_mode == GL_EXP2) {
          /* MUL fogFactorTemp.x, fogFactorTemp.x, fogFactorTemp.x; */
          inst->Opcode = OPCODE_MUL;
          inst->DstReg.File = PROGRAM_TEMPORARY;
@@ -397,7 +412,7 @@ _mesa_append_fog_code(struct gl_context *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; */
+   assert(fprog->Base.OutputsWritten & (1 << FRAG_RESULT_COLOR));
 }
 
 
@@ -616,7 +631,7 @@ _mesa_nop_fragment_program(struct gl_context *ctx, struct gl_fragment_program *p
 
    prog->Base.Instructions = inst;
    prog->Base.NumInstructions = 2;
-   prog->Base.InputsRead = 1 << inputAttr;
+   prog->Base.InputsRead = BITFIELD64_BIT(inputAttr);
    prog->Base.OutputsWritten = BITFIELD64_BIT(FRAG_RESULT_COLOR);
 }
 
@@ -660,7 +675,7 @@ _mesa_nop_vertex_program(struct gl_context *ctx, struct gl_vertex_program *prog)
 
    prog->Base.Instructions = inst;
    prog->Base.NumInstructions = 2;
-   prog->Base.InputsRead = 1 << inputAttr;
+   prog->Base.InputsRead = BITFIELD64_BIT(inputAttr);
    prog->Base.OutputsWritten = BITFIELD64_BIT(VERT_RESULT_COL0);
 
    /*