softpipe: update to new draw interfaces
[mesa.git] / src / gallium / drivers / softpipe / sp_quad_blend.c
index 8be8025f40cbc58234351fb9aa2c0b88540dfad9..e134e443374c78f706fce112ce41ec108e33b689 100644 (file)
  */
 
 #include "pipe/p_defines.h"
-#include "pipe/p_util.h"
+#include "util/u_math.h"
+#include "util/u_memory.h"
 #include "sp_context.h"
-#include "sp_headers.h"
+#include "sp_quad.h"
 #include "sp_surface.h"
 #include "sp_tile_cache.h"
-#include "sp_quad.h"
+#include "sp_quad_pipe.h"
 
 
 #define VEC4_COPY(DST, SRC) \
@@ -104,7 +105,7 @@ logicop_quad(struct quad_stage *qs, struct quad_header *quad)
    uint cbuf;
 
    /* loop over colorbuffer outputs */
-   for (cbuf = 0; cbuf < softpipe->framebuffer.num_cbufs; cbuf++) {
+   for (cbuf = 0; cbuf < softpipe->framebuffer.nr_cbufs; cbuf++) {
       float dest[4][QUAD_SIZE];
       ubyte src[4][4], dst[4][4], res[4][4];
       uint *src4 = (uint *) src;
@@ -113,14 +114,14 @@ logicop_quad(struct quad_stage *qs, struct quad_header *quad)
       struct softpipe_cached_tile *
          tile = sp_get_cached_tile(softpipe,
                                    softpipe->cbuf_cache[cbuf],
-                                   quad->x0, quad->y0);
-      float (*quadColor)[4] = quad->outputs.color[cbuf];
+                                   quad->input.x0, quad->input.y0);
+      float (*quadColor)[4] = quad->output.color[cbuf];
       uint i, j;
 
       /* get/swizzle dest colors */
       for (j = 0; j < QUAD_SIZE; j++) {
-         int x = (quad->x0 & (TILE_SIZE-1)) + (j & 1);
-         int y = (quad->y0 & (TILE_SIZE-1)) + (j >> 1);
+         int x = (quad->input.x0 & (TILE_SIZE-1)) + (j & 1);
+         int y = (quad->input.y0 & (TILE_SIZE-1)) + (j >> 1);
          for (i = 0; i < 4; i++) {
             dest[i][j] = tile->data.color[y][x][i];
          }
@@ -128,15 +129,15 @@ logicop_quad(struct quad_stage *qs, struct quad_header *quad)
 
       /* convert to ubyte */
       for (j = 0; j < 4; j++) { /* loop over R,G,B,A channels */
-         UNCLAMPED_FLOAT_TO_UBYTE(dst[j][0], dest[j][0]); /* P0 */
-         UNCLAMPED_FLOAT_TO_UBYTE(dst[j][1], dest[j][1]); /* P1 */
-         UNCLAMPED_FLOAT_TO_UBYTE(dst[j][2], dest[j][2]); /* P2 */
-         UNCLAMPED_FLOAT_TO_UBYTE(dst[j][3], dest[j][3]); /* P3 */
-
-         UNCLAMPED_FLOAT_TO_UBYTE(src[j][0], quadColor[j][0]); /* P0 */
-         UNCLAMPED_FLOAT_TO_UBYTE(src[j][1], quadColor[j][1]); /* P1 */
-         UNCLAMPED_FLOAT_TO_UBYTE(src[j][2], quadColor[j][2]); /* P2 */
-         UNCLAMPED_FLOAT_TO_UBYTE(src[j][3], quadColor[j][3]); /* P3 */
+         dst[j][0] = float_to_ubyte(dest[j][0]); /* P0 */
+         dst[j][1] = float_to_ubyte(dest[j][1]); /* P1 */
+         dst[j][2] = float_to_ubyte(dest[j][2]); /* P2 */
+         dst[j][3] = float_to_ubyte(dest[j][3]); /* P3 */
+
+         src[j][0] = float_to_ubyte(quadColor[j][0]); /* P0 */
+         src[j][1] = float_to_ubyte(quadColor[j][1]); /* P1 */
+         src[j][2] = float_to_ubyte(quadColor[j][2]); /* P2 */
+         src[j][3] = float_to_ubyte(quadColor[j][3]); /* P3 */
       }
 
       switch (softpipe->blend->logicop_func) {
@@ -209,10 +210,10 @@ logicop_quad(struct quad_stage *qs, struct quad_header *quad)
       }
 
       for (j = 0; j < 4; j++) {
-         quadColor[j][0] = UBYTE_TO_FLOAT(res[j][0]);
-         quadColor[j][1] = UBYTE_TO_FLOAT(res[j][1]);
-         quadColor[j][2] = UBYTE_TO_FLOAT(res[j][2]);
-         quadColor[j][3] = UBYTE_TO_FLOAT(res[j][3]);
+         quadColor[j][0] = ubyte_to_float(res[j][0]);
+         quadColor[j][1] = ubyte_to_float(res[j][1]);
+         quadColor[j][2] = ubyte_to_float(res[j][2]);
+         quadColor[j][3] = ubyte_to_float(res[j][3]);
       }
    }
 
@@ -232,25 +233,25 @@ blend_quad(struct quad_stage *qs, struct quad_header *quad)
    struct softpipe_context *softpipe = qs->softpipe;
    uint cbuf;
 
+   if (softpipe->blend->logicop_enable) {
+      logicop_quad(qs, quad);
+      return;
+   }
+
    /* loop over colorbuffer outputs */
-   for (cbuf = 0; cbuf < softpipe->framebuffer.num_cbufs; cbuf++) {
+   for (cbuf = 0; cbuf < softpipe->framebuffer.nr_cbufs; cbuf++) {
       float source[4][QUAD_SIZE], dest[4][QUAD_SIZE];
       struct softpipe_cached_tile *tile
          = sp_get_cached_tile(softpipe,
                               softpipe->cbuf_cache[cbuf],
-                              quad->x0, quad->y0);
-      float (*quadColor)[4] = quad->outputs.color[cbuf];
+                              quad->input.x0, quad->input.y0);
+      float (*quadColor)[4] = quad->output.color[cbuf];
       uint i, j;
 
-      if (softpipe->blend->logicop_enable) {
-         logicop_quad(qs, quad);
-         return;
-      }
-
       /* get/swizzle dest colors */
       for (j = 0; j < QUAD_SIZE; j++) {
-         int x = (quad->x0 & (TILE_SIZE-1)) + (j & 1);
-         int y = (quad->y0 & (TILE_SIZE-1)) + (j >> 1);
+         int x = (quad->input.x0 & (TILE_SIZE-1)) + (j & 1);
+         int y = (quad->input.y0 & (TILE_SIZE-1)) + (j >> 1);
          for (i = 0; i < 4; i++) {
             dest[i][j] = tile->data.color[y][x][i];
          }
@@ -294,11 +295,12 @@ blend_quad(struct quad_stage *qs, struct quad_header *quad)
       case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE:
          {
             const float *alpha = quadColor[3];
-            float diff[4];
+            float diff[4], temp[4];
             VEC4_SUB(diff, one, dest[3]);
-            VEC4_MIN(source[0], alpha, diff); /* R */
-            VEC4_MIN(source[1], alpha, diff); /* G */
-            VEC4_MIN(source[2], alpha, diff); /* B */
+            VEC4_MIN(temp, alpha, diff);
+            VEC4_MUL(source[0], quadColor[0], temp); /* R */
+            VEC4_MUL(source[1], quadColor[1], temp); /* G */
+            VEC4_MUL(source[2], quadColor[2], temp); /* B */
          }
          break;
       case PIPE_BLENDFACTOR_CONST_COLOR:
@@ -426,12 +428,8 @@ blend_quad(struct quad_stage *qs, struct quad_header *quad)
          VEC4_MUL(source[3], quadColor[3], dest[3]); /* A */
          break;
       case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE:
-         {
-            const float *alpha = quadColor[3];
-            float diff[4];
-            VEC4_SUB(diff, one, dest[3]);
-            VEC4_MIN(source[3], alpha, diff); /* A */
-         }
+         /* multiply alpha by 1.0 */
+         VEC4_COPY(source[3], quadColor[3]); /* A */
          break;
       case PIPE_BLENDFACTOR_CONST_COLOR:
          /* fall-through */
@@ -561,7 +559,7 @@ blend_quad(struct quad_stage *qs, struct quad_header *quad)
       case PIPE_BLENDFACTOR_INV_DST_ALPHA:
          {
             float inv_comp[4];
-            VEC4_SUB(inv_comp, one, quadColor[3]); /* A */
+            VEC4_SUB(inv_comp, one, dest[3]); /* A */
             VEC4_MUL(dest[0], inv_comp, dest[0]); /* R */
             VEC4_MUL(dest[1], inv_comp, dest[1]); /* G */
             VEC4_MUL(dest[2], inv_comp, dest[2]); /* B */