i915: Fix some warnings
[mesa.git] / src / gallium / drivers / i915simple / i915_state_emit.c
index 3339287f498b89653ad30630548f2e66690b84bf..1e1fb968b47336e40e8bdd5ecb0ad0ea6f52a47a 100644 (file)
@@ -99,7 +99,11 @@ i915_emit_hardware_state(struct i915_context *i915 )
                              2 + I915_TEX_UNITS*3 + 
                              2 + I915_TEX_UNITS*3 +
                              2 + I915_MAX_CONSTANT*4 + 
+#if 0
                              i915->current.program_len + 
+#else
+                             i915->fs->program_len + 
+#endif
                              6 
                            ) * 3/2; /* plus 50% margin */
    const unsigned relocs = ( I915_TEX_UNITS +
@@ -111,7 +115,7 @@ i915_emit_hardware_state(struct i915_context *i915 )
 #endif
    
    if(!BEGIN_BATCH(dwords, relocs)) {
-      FLUSH_BATCH();
+      FLUSH_BATCH(NULL);
       assert(BEGIN_BATCH(dwords, relocs));
    }
 
@@ -207,33 +211,47 @@ i915_emit_hardware_state(struct i915_context *i915 )
       struct pipe_surface *depth_surface = i915->framebuffer.zsbuf;
 
       if (cbuf_surface) {
-        unsigned pitch = (cbuf_surface->pitch * cbuf_surface->cpp);
+        unsigned ctile = BUF_3D_USE_FENCE;
+         struct i915_texture *tex = (struct i915_texture *)
+                                    cbuf_surface->texture;
+         assert(tex);
+
+        if (tex && tex->tiled) {
+           ctile = BUF_3D_TILED_SURFACE;
+        }
 
         OUT_BATCH(_3DSTATE_BUF_INFO_CMD);
 
-        OUT_BATCH(BUF_3D_ID_COLOR_BACK | 
-                  BUF_3D_PITCH(pitch) |  /* pitch in bytes */
-                  BUF_3D_USE_FENCE);
+        OUT_BATCH(BUF_3D_ID_COLOR_BACK |
+                  BUF_3D_PITCH(tex->stride) |  /* pitch in bytes */
+                  ctile);
 
-        OUT_RELOC(cbuf_surface->buffer,
+        OUT_RELOC(tex->buffer,
                   I915_BUFFER_ACCESS_WRITE,
-                  0);
+                  cbuf_surface->offset);
       }
 
       /* What happens if no zbuf??
        */
       if (depth_surface) {
-        unsigned zpitch = (depth_surface->pitch * depth_surface->cpp);
-                        
+        unsigned ztile = BUF_3D_USE_FENCE;
+         struct i915_texture *tex = (struct i915_texture *)
+                                    depth_surface->texture;
+         assert(tex);
+
+        if (tex && tex->tiled) {
+           ztile = BUF_3D_TILED_SURFACE;
+        }
+
         OUT_BATCH(_3DSTATE_BUF_INFO_CMD);
 
         OUT_BATCH(BUF_3D_ID_DEPTH |
-                  BUF_3D_PITCH(zpitch) |  /* pitch in bytes */
-                  BUF_3D_USE_FENCE);
+                  BUF_3D_PITCH(tex->stride) |  /* pitch in bytes */
+                  ztile);
 
-        OUT_RELOC(depth_surface->buffer,
+        OUT_RELOC(tex->buffer,
                   I915_BUFFER_ACCESS_WRITE,
-                  0);
+                  depth_surface->offset);
       }
    
       {
@@ -263,12 +281,6 @@ i915_emit_hardware_state(struct i915_context *i915 )
       /* 2 + I915_TEX_UNITS*3 dwords, I915_TEX_UNITS relocs */
       if (i915->hardware_dirty & (I915_HW_MAP | I915_HW_SAMPLER))
       {
-        /* XXX: we were refering to sampler state
-         * (current.sampler_enable_nr) below, but only checking
-         * I915_HW_MAP above.  Should probably calculate the enabled
-         * flags separately - but there will be further rework of
-         * state so perhaps not necessary yet.
-         */
          const uint nr = i915->current.sampler_enable_nr;
          if (nr) {
             const uint enabled = i915->current.sampler_enable_flags;
@@ -325,15 +337,34 @@ i915_emit_hardware_state(struct i915_context *i915 )
    /* 2 + I915_MAX_CONSTANT*4 dwords, 0 relocs */
    if (i915->hardware_dirty & I915_HW_PROGRAM)
    {
-      const uint nr = i915->current.num_constants[PIPE_SHADER_FRAGMENT];
-      assert(nr <= I915_MAX_CONSTANT);
-      if (nr > 0) {
-         const uint *c
-            = (const uint *) i915->current.constants[PIPE_SHADER_FRAGMENT];
+      /* Collate the user-defined constants with the fragment shader's
+       * immediates according to the constant_flags[] array.
+       */
+      const uint nr = i915->fs->num_constants;
+      if (nr) {
          uint i;
+
          OUT_BATCH( _3DSTATE_PIXEL_SHADER_CONSTANTS | (nr * 4) );
          OUT_BATCH( (1 << (nr - 1)) | ((1 << (nr - 1)) - 1) );
+
          for (i = 0; i < nr; i++) {
+            const uint *c;
+            if (i915->fs->constant_flags[i] == I915_CONSTFLAG_USER) {
+               /* grab user-defined constant */
+               c = (uint *) i915->current.constants[PIPE_SHADER_FRAGMENT][i];
+            }
+            else {
+               /* emit program constant */
+               c = (uint *) i915->fs->constants[i];
+            }
+#if 0 /* debug */
+            {
+               float *f = (float *) c;
+               printf("Const %2d: %f %f %f %f %s\n", i, f[0], f[1], f[2], f[3],
+                      (i915->fs->constant_flags[i] == I915_CONSTFLAG_USER
+                       ? "user" : "immediate"));
+            }
+#endif
             OUT_BATCH(*c++);
             OUT_BATCH(*c++);
             OUT_BATCH(*c++);
@@ -348,9 +379,9 @@ i915_emit_hardware_state(struct i915_context *i915 )
    {
       uint i;
       /* we should always have, at least, a pass-through program */
-      assert(i915->current.program_len > 0);
-      for (i = 0; i < i915->current.program_len; i++) {
-         OUT_BATCH(i915->current.program[i]);
+      assert(i915->fs->program_len > 0);
+      for (i = 0; i < i915->fs->program_len; i++) {
+         OUT_BATCH(i915->fs->program[i]);
       }
    }
 
@@ -359,6 +390,7 @@ i915_emit_hardware_state(struct i915_context *i915 )
    {
       uint w, h;
       boolean k = framebuffer_size(&i915->framebuffer, &w, &h);
+      (void)k;
       assert(k);
 
       OUT_BATCH(_3DSTATE_DRAW_RECT_CMD);