i915: reference __DRI_ATTRIB_SWAP_COPY token over the GLX one
[mesa.git] / src / mesa / drivers / dri / i915 / i915_program.c
index 507adf1d3dca0560e2fa63ced4212c61ace5261f..20a47804249ed16bb3d9d300c3b48e45e64e4eb8 100644 (file)
@@ -1,6 +1,6 @@
 /**************************************************************************
  * 
- * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * Copyright 2003 VMware, Inc.
  * All Rights Reserved.
  * 
  * Permission is hereby granted, free of charge, to any person obtaining a
@@ -18,7 +18,7 @@
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -322,7 +322,7 @@ i915_emit_const1f(struct i915_fragment_program * p, GLfloat c0)
       }
    }
 
-   fprintf(stderr, "%s: out of constants\n", __FUNCTION__);
+   fprintf(stderr, "%s: out of constants\n", __func__);
    p->error = 1;
    return 0;
 }
@@ -359,7 +359,7 @@ i915_emit_const2f(struct i915_fragment_program * p, GLfloat c0, GLfloat c1)
       }
    }
 
-   fprintf(stderr, "%s: out of constants\n", __FUNCTION__);
+   fprintf(stderr, "%s: out of constants\n", __func__);
    p->error = 1;
    return 0;
 }
@@ -391,7 +391,7 @@ i915_emit_const4f(struct i915_fragment_program * p,
       }
    }
 
-   fprintf(stderr, "%s: out of constants\n", __FUNCTION__);
+   fprintf(stderr, "%s: out of constants\n", __func__);
    p->error = 1;
    return 0;
 }
@@ -430,7 +430,7 @@ i915_emit_param4fv(struct i915_fragment_program * p, const GLfloat * values)
       }
    }
 
-   fprintf(stderr, "%s: out of constants\n", __FUNCTION__);
+   fprintf(stderr, "%s: out of constants\n", __func__);
    p->error = 1;
    return 0;
 }
@@ -442,14 +442,16 @@ i915_emit_param4fv(struct i915_fragment_program * p, const GLfloat * values)
 void
 i915_program_error(struct i915_fragment_program *p, const char *fmt, ...)
 {
-   va_list args;
+   if (unlikely((INTEL_DEBUG & (DEBUG_WM | DEBUG_PERF)) != 0)) {
+      va_list args;
 
-   fprintf(stderr, "i915_program_error: ");
-   va_start(args, fmt);
-   vfprintf(stderr, fmt, args);
-   va_end(args);
+      fprintf(stderr, "i915_program_error: ");
+      va_start(args, fmt);
+      vfprintf(stderr, fmt, args);
+      va_end(args);
 
-   fprintf(stderr, "\n");
+      fprintf(stderr, "\n");
+   }
    p->error = 1;
 }
 
@@ -480,7 +482,7 @@ i915_init_program(struct i915_context *i915, struct i915_fragment_program *p)
    p->decl_t = 0;
    p->temp_flag = 0xffff000;
    p->utemp_flag = ~0x7;
-   p->wpos_tex = -1;
+   p->wpos_tex = I915_WPOS_TEX_INVALID;
    p->depth_written = 0;
    p->nr_params = 0;
 
@@ -515,18 +517,18 @@ i915_fini_program(struct i915_fragment_program *p)
    }
 
    if (p->error) {
-      p->FragProg.Base.NumNativeInstructions = 0;
-      p->FragProg.Base.NumNativeAluInstructions = 0;
-      p->FragProg.Base.NumNativeTexInstructions = 0;
-      p->FragProg.Base.NumNativeTexIndirections = 0;
+      p->FragProg.arb.NumNativeInstructions = 0;
+      p->FragProg.arb.NumNativeAluInstructions = 0;
+      p->FragProg.arb.NumNativeTexInstructions = 0;
+      p->FragProg.arb.NumNativeTexIndirections = 0;
    }
    else {
-      p->FragProg.Base.NumNativeInstructions = (p->nr_alu_insn +
+      p->FragProg.arb.NumNativeInstructions = (p->nr_alu_insn +
                                                 p->nr_tex_insn +
                                                 p->nr_decl_insn);
-      p->FragProg.Base.NumNativeAluInstructions = p->nr_alu_insn;
-      p->FragProg.Base.NumNativeTexInstructions = p->nr_tex_insn;
-      p->FragProg.Base.NumNativeTexIndirections = p->nr_tex_indirect;
+      p->FragProg.arb.NumNativeAluInstructions = p->nr_alu_insn;
+      p->FragProg.arb.NumNativeTexInstructions = p->nr_tex_insn;
+      p->FragProg.arb.NumNativeTexIndirections = p->nr_tex_indirect;
    }
 
    p->declarations[0] |= program_size + decl_size - 2;
@@ -538,7 +540,6 @@ i915_upload_program(struct i915_context *i915,
 {
    GLuint program_size = p->csr - p->program;
    GLuint decl_size = p->decl - p->declarations;
-   GLuint nr;
 
    if (p->error)
       return;
@@ -555,33 +556,33 @@ i915_upload_program(struct i915_context *i915,
       i915->state.ProgramSize = decl_size + program_size;
    }
 
-   nr = p->nr_constants;
-   if (i915->state.ConstantSize != 2 + nr*4 ||
-       memcmp(i915->state.Constant + 2,
-             p->constant, 4*sizeof(int)*nr)) {
-      if (nr) {
-        I915_ACTIVESTATE(i915, I915_UPLOAD_CONSTANTS, 1);
-        I915_STATECHANGE(i915, I915_UPLOAD_CONSTANTS);
-
-        i915->state.Constant[0] = _3DSTATE_PIXEL_SHADER_CONSTANTS | (nr * 4);
-        i915->state.Constant[1] = (1 << nr) -1;
-
-        memcpy(&i915->state.Constant[2], p->constant, 4 * sizeof(int) * nr);
-        i915->state.ConstantSize = 2 + nr * 4;
-
-        if (0) {
-           GLuint i;
-           for (i = 0; i < nr; i++) {
-              fprintf(stderr, "const[%d]: %f %f %f %f\n", i,
-                      p->constant[i][0],
-                      p->constant[i][1], p->constant[i][2], p->constant[i][3]);
-           }
-        }
-      }
-      else {
-        I915_ACTIVESTATE(i915, I915_UPLOAD_CONSTANTS, 0);
+   /* Always seemed to get a failure if I used memcmp() to
+    * shortcircuit this state upload.  Needs further investigation?
+    */
+   if (p->nr_constants) {
+      GLuint nr = p->nr_constants;
+
+      I915_ACTIVESTATE(i915, I915_UPLOAD_CONSTANTS, 1);
+      I915_STATECHANGE(i915, I915_UPLOAD_CONSTANTS);
+
+      i915->state.Constant[0] = _3DSTATE_PIXEL_SHADER_CONSTANTS | ((nr) * 4);
+      i915->state.Constant[1] = (1 << (nr - 1)) | ((1 << (nr - 1)) - 1);
+
+      memcpy(&i915->state.Constant[2], p->constant, 4 * sizeof(int) * (nr));
+      i915->state.ConstantSize = 2 + (nr) * 4;
+
+      if (0) {
+         GLuint i;
+         for (i = 0; i < nr; i++) {
+            fprintf(stderr, "const[%d]: %f %f %f %f\n", i,
+                    p->constant[i][0],
+                    p->constant[i][1], p->constant[i][2], p->constant[i][3]);
+         }
       }
    }
+   else {
+      I915_ACTIVESTATE(i915, I915_UPLOAD_CONSTANTS, 0);
+   }
 
    p->on_hardware = 1;
 }