s/Tungsten Graphics/VMware/
[mesa.git] / src / mesa / drivers / dri / i965 / brw_curbe.c
index 877b22fec19ad165ae29a67ca8448e698f8aa442..9e556fb6361822d81a566a2b9f1bd5f82feafdb2 100644 (file)
@@ -1,8 +1,8 @@
 /*
  Copyright (C) Intel Corp.  2006.  All Rights Reserved.
- Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
+ Intel funded Tungsten Graphics to
  develop this 3D driver.
+
  Permission is hereby granted, free of charge, to any person obtaining
  a copy of this software and associated documentation files (the
  "Software"), to deal in the Software without restriction, including
  distribute, sublicense, and/or sell copies of the Software, and to
  permit persons to whom the Software is furnished to do so, subject to
  the following conditions:
+
  The above copyright notice and this permission notice (including the
  next paragraph) shall be included in all copies or substantial
  portions of the Software.
+
  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 NONINFRINGEMENT.
  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.
+
  **********************************************************************/
  /*
   * Authors:
-  *   Keith Whitwell <keith@tungstengraphics.com>
+  *   Keith Whitwell <keithw@vmware.com>
   */
 
 
  */
 static void calculate_curbe_offsets( struct brw_context *brw )
 {
-   struct gl_context *ctx = &brw->intel.ctx;
+   struct gl_context *ctx = &brw->ctx;
    /* CACHE_NEW_WM_PROG */
    const GLuint nr_fp_regs = (brw->wm.prog_data->nr_params + 15) / 16;
-   
+
    /* BRW_NEW_VERTEX_PROGRAM */
-   const GLuint nr_vp_regs = (brw->vs.prog_data->nr_params + 15) / 16;
+   const GLuint nr_vp_regs = (brw->vs.prog_data->base.nr_params + 15) / 16;
    GLuint nr_clip_regs = 0;
    GLuint total_regs;
 
    /* _NEW_TRANSFORM */
    if (ctx->Transform.ClipPlanesEnabled) {
-      GLuint nr_planes = 6 + brw_count_bits(ctx->Transform.ClipPlanesEnabled);
+      GLuint nr_planes = 6 + _mesa_bitcount_64(ctx->Transform.ClipPlanesEnabled);
       nr_clip_regs = (nr_planes * 4 + 15) / 16;
    }
 
@@ -88,7 +88,7 @@ static void calculate_curbe_offsets( struct brw_context *brw )
     * the fragment and vertex program
     * api's.  It's not clear what happens
     * when both VP and FP want to use 128
-    * parameters, though. 
+    * parameters, though.
     */
    assert(total_regs <= 32);
 
@@ -102,7 +102,7 @@ static void calculate_curbe_offsets( struct brw_context *brw )
 
       GLuint reg = 0;
 
-      /* Calculate a new layout: 
+      /* Calculate a new layout:
        */
       reg = 0;
       brw->curbe.wm_start = reg;
@@ -133,7 +133,7 @@ const struct brw_tracked_state brw_curbe_offsets = {
       .brw  = BRW_NEW_VERTEX_PROGRAM | BRW_NEW_CONTEXT,
       .cache = CACHE_NEW_WM_PROG
    },
-   .prepare = calculate_curbe_offsets
+   .emit = calculate_curbe_offsets
 };
 
 
@@ -146,22 +146,22 @@ const struct brw_tracked_state brw_curbe_offsets = {
  */
 void brw_upload_cs_urb_state(struct brw_context *brw)
 {
-   struct brw_cs_urb_state cs_urb;
-   memset(&cs_urb, 0, sizeof(cs_urb));
-
+   BEGIN_BATCH(2);
    /* It appears that this is the state packet for the CS unit, ie. the
     * urb entries detailed here are housed in the CS range from the
     * URB_FENCE command.
     */
-   cs_urb.header.opcode = CMD_CS_URB_STATE;
-   cs_urb.header.length = sizeof(cs_urb)/4 - 2;
+   OUT_BATCH(CMD_CS_URB_STATE << 16 | (2-2));
 
    /* BRW_NEW_URB_FENCE */
-   cs_urb.bits0.nr_urb_entries = brw->urb.nr_cs_entries;
-   cs_urb.bits0.urb_entry_size = brw->urb.csize - 1;
-
-   assert(brw->urb.nr_cs_entries);
-   BRW_CACHED_BATCH_STRUCT(brw, &cs_urb);
+   if (brw->urb.csize == 0) {
+      OUT_BATCH(0);
+   } else {
+      /* BRW_NEW_URB_FENCE */
+      assert(brw->urb.nr_cs_entries);
+      OUT_BATCH((brw->urb.csize - 1) << 4 | brw->urb.nr_cs_entries);
+   }
+   CACHED_BATCH();
 }
 
 static GLfloat fixed_plane[6][4] = {
@@ -177,19 +177,19 @@ static GLfloat fixed_plane[6][4] = {
  * cache mechanism, but maybe would benefit from a comparison against
  * the current uploaded set of constants.
  */
-static void prepare_constant_buffer(struct brw_context *brw)
+static void
+brw_upload_constant_buffer(struct brw_context *brw)
 {
-   struct gl_context *ctx = &brw->intel.ctx;
-   const struct brw_vertex_program *vp =
-      brw_vertex_program_const(brw->vertex_program);
+   struct gl_context *ctx = &brw->ctx;
    const GLuint sz = brw->curbe.total_size;
    const GLuint bufsz = sz * 16 * sizeof(GLfloat);
    GLfloat *buf;
    GLuint i;
+   gl_clip_plane *clip_planes;
 
    if (sz == 0) {
       brw->curbe.last_bufsz  = 0;
-      return;
+      goto emit;
    }
 
    buf = brw->curbe.next_buf;
@@ -200,15 +200,11 @@ static void prepare_constant_buffer(struct brw_context *brw)
 
       /* copy float constants */
       for (i = 0; i < brw->wm.prog_data->nr_params; i++) {
-        buf[offset + i] = convert_param(brw->wm.prog_data->param_convert[i],
-                                        *brw->wm.prog_data->param[i]);
+        buf[offset + i] = *brw->wm.prog_data->param[i];
       }
    }
 
-
-   /* The clipplanes are actually delivered to both CLIP and VS units.
-    * VS uses them to calculate the outcode bitmasks.
-    */
+   /* clipper constants */
    if (brw->curbe.clip_size) {
       GLuint offset = brw->curbe.clip_start * 16;
       GLuint j;
@@ -225,13 +221,13 @@ static void prepare_constant_buffer(struct brw_context *brw)
       /* Clip planes: _NEW_TRANSFORM plus _NEW_PROJECTION to get to
        * clip-space:
        */
-      assert(MAX_CLIP_PLANES == 6);
+      clip_planes = brw_select_clip_planes(ctx);
       for (j = 0; j < MAX_CLIP_PLANES; j++) {
         if (ctx->Transform.ClipPlanesEnabled & (1<<j)) {
-           buf[offset + i * 4 + 0] = ctx->Transform._ClipUserPlane[j][0];
-           buf[offset + i * 4 + 1] = ctx->Transform._ClipUserPlane[j][1];
-           buf[offset + i * 4 + 2] = ctx->Transform._ClipUserPlane[j][2];
-           buf[offset + i * 4 + 3] = ctx->Transform._ClipUserPlane[j][3];
+           buf[offset + i * 4 + 0] = clip_planes[j][0];
+           buf[offset + i * 4 + 1] = clip_planes[j][1];
+           buf[offset + i * 4 + 2] = clip_planes[j][2];
+           buf[offset + i * 4 + 3] = clip_planes[j][3];
            i++;
         }
       }
@@ -240,23 +236,14 @@ static void prepare_constant_buffer(struct brw_context *brw)
    /* vertex shader constants */
    if (brw->curbe.vs_size) {
       GLuint offset = brw->curbe.vs_start * 16;
-      GLuint nr = brw->vs.prog_data->nr_params / 4;
 
-      /* Load the subset of push constants that will get used when
-       * we also have a pull constant buffer.
-       */
-      for (i = 0; i < vp->program.Base.Parameters->NumParameters; i++) {
-        if (brw->vs.constant_map[i] != -1) {
-           assert(brw->vs.constant_map[i] <= nr);
-           memcpy(buf + offset + brw->vs.constant_map[i] * 4,
-                  vp->program.Base.Parameters->ParameterValues[i],
-                  4 * sizeof(float));
-        }
+      for (i = 0; i < brw->vs.prog_data->base.nr_params; i++) {
+         buf[offset + i] = *brw->vs.prog_data->base.param[i];
       }
    }
 
    if (0) {
-      for (i = 0; i < sz*16; i+=4) 
+      for (i = 0; i < sz*16; i+=4)
         printf("curbe %d.%d: %f %f %f %f\n", i/8, i&4,
                buf[i+0], buf[i+1], buf[i+2], buf[i+3]);
 
@@ -290,7 +277,7 @@ static void prepare_constant_buffer(struct brw_context *brw)
         /* Allocate a single page for CURBE entries for this batchbuffer.
          * They're generally around 64b.
          */
-        brw->curbe.curbe_bo = drm_intel_bo_alloc(brw->intel.bufmgr, "CURBE",
+        brw->curbe.curbe_bo = drm_intel_bo_alloc(brw->bufmgr, "CURBE",
                                                  4096, 1 << 6);
         brw->curbe.curbe_next_offset = 0;
         drm_intel_gem_bo_map_gtt(brw->curbe.curbe_bo);
@@ -308,8 +295,6 @@ static void prepare_constant_buffer(struct brw_context *brw)
             bufsz);
    }
 
-   brw_add_validated_bo(brw, brw->curbe.curbe_bo);
-
    /* Because this provokes an action (ie copy the constants into the
     * URB), it shouldn't be shortcircuited if identical to the
     * previous time - because eg. the urb destination may have
@@ -323,32 +308,21 @@ static void prepare_constant_buffer(struct brw_context *brw)
     * flushes as necessary when doublebuffering of CURBEs isn't
     * possible.
     */
-}
-
-static void emit_constant_buffer(struct brw_context *brw)
-{
-   struct intel_context *intel = &brw->intel;
-   GLuint sz = brw->curbe.total_size;
 
+emit:
    BEGIN_BATCH(2);
-   if (sz == 0) {
+   if (brw->curbe.total_size == 0) {
       OUT_BATCH((CMD_CONST_BUFFER << 16) | (2 - 2));
       OUT_BATCH(0);
    } else {
       OUT_BATCH((CMD_CONST_BUFFER << 16) | (1 << 8) | (2 - 2));
       OUT_RELOC(brw->curbe.curbe_bo,
                I915_GEM_DOMAIN_INSTRUCTION, 0,
-               (sz - 1) + brw->curbe.curbe_offset);
+               (brw->curbe.total_size - 1) + brw->curbe.curbe_offset);
    }
    ADVANCE_BATCH();
 }
 
-/* This tracked state is unique in that the state it monitors varies
- * dynamically depending on the parameters tracked by the fragment and
- * vertex programs.  This is the template used as a starting point,
- * each context will maintain a copy of this internally and update as
- * required.
- */
 const struct brw_tracked_state brw_constant_buffer = {
    .dirty = {
       .mesa = _NEW_PROGRAM_CONSTANTS,
@@ -358,9 +332,8 @@ const struct brw_tracked_state brw_constant_buffer = {
               BRW_NEW_PSP | /* Implicit - hardware requires this, not used above */
               BRW_NEW_CURBE_OFFSETS |
               BRW_NEW_BATCH),
-      .cache = (CACHE_NEW_WM_PROG) 
+      .cache = (CACHE_NEW_WM_PROG)
    },
-   .prepare = prepare_constant_buffer,
-   .emit = emit_constant_buffer,
+   .emit = brw_upload_constant_buffer,
 };