gallium: Drop pipe_texture->cpp and pipe_surface->cpp.
authorJosé Fonseca <jrfonseca@tungstengraphics.com>
Fri, 27 Jun 2008 10:37:56 +0000 (19:37 +0900)
committerJosé Fonseca <jrfonseca@tungstengraphics.com>
Fri, 27 Jun 2008 10:37:56 +0000 (19:37 +0900)
The chars-per-pixel concept falls apart with compressed and yuv images,
where more than one pixel are coded in a single data block.

34 files changed:
src/gallium/auxiliary/draw/draw_pipe_aaline.c
src/gallium/auxiliary/draw/draw_pipe_pstipple.c
src/gallium/auxiliary/util/p_tile.c
src/gallium/auxiliary/util/p_util.c
src/gallium/auxiliary/util/u_blit.c
src/gallium/auxiliary/util/u_gen_mipmap.c
src/gallium/drivers/i915simple/i915_blit.c
src/gallium/drivers/i915simple/i915_context.h
src/gallium/drivers/i915simple/i915_state_emit.c
src/gallium/drivers/i915simple/i915_state_sampler.c
src/gallium/drivers/i915simple/i915_surface.c
src/gallium/drivers/i915simple/i915_texture.c
src/gallium/drivers/i965simple/brw_context.h
src/gallium/drivers/i965simple/brw_misc_state.c
src/gallium/drivers/i965simple/brw_surface.c
src/gallium/drivers/i965simple/brw_tex_layout.c
src/gallium/drivers/i965simple/brw_wm_surface_state.c
src/gallium/drivers/softpipe/sp_surface.c
src/gallium/drivers/softpipe/sp_texture.c
src/gallium/drivers/softpipe/sp_texture.h
src/gallium/include/pipe/p_format.h
src/gallium/include/pipe/p_state.h
src/gallium/include/pipe/p_util.h
src/gallium/winsys/xlib/brw_aub.c
src/gallium/winsys/xlib/xm_winsys.c
src/gallium/winsys/xlib/xm_winsys_aub.c
src/mesa/state_tracker/st_cb_accum.c
src/mesa/state_tracker/st_cb_bitmap.c
src/mesa/state_tracker/st_cb_drawpixels.c
src/mesa/state_tracker/st_cb_fbo.c
src/mesa/state_tracker/st_cb_readpixels.c
src/mesa/state_tracker/st_cb_texture.c
src/mesa/state_tracker/st_gen_mipmap.c
src/mesa/state_tracker/st_texture.c

index ecdebca5f1270bc9d1a7967b5f19e289dcc810d8..3dd7ee19fd1b87c674f1e5f8162642f058423b46 100644 (file)
@@ -398,7 +398,7 @@ aaline_create_texture(struct aaline_stage *aaline)
    texTemp.width[0] = 1 << MAX_TEXTURE_LEVEL;
    texTemp.height[0] = 1 << MAX_TEXTURE_LEVEL;
    texTemp.depth[0] = 1;
-   texTemp.cpp = 1;
+   pf_get_block(texTemp.format, &texTemp.block);
 
    aaline->texture = screen->texture_create(screen, &texTemp);
    if (!aaline->texture)
@@ -439,7 +439,7 @@ aaline_create_texture(struct aaline_stage *aaline)
             else {
                d = 255;
             }
-            data[i * surface->pitch + j] = d;
+            data[i * surface->stride + j] = d;
          }
       }
 
index 4087cf7a491d7ee3517216fc6e7e9202d5eb3309..1f63f943656087e89f31826c9898e2eec449187f 100644 (file)
@@ -394,11 +394,11 @@ pstip_update_texture(struct pstip_stage *pstip)
       for (j = 0; j < 32; j++) {
          if (stipple[i] & (bit31 >> j)) {
             /* fragment "on" */
-            data[i * surface->pitch + j] = 0;
+            data[i * surface->stride + j] = 0;
          }
          else {
             /* fragment "off" */
-            data[i * surface->pitch + j] = 255;
+            data[i * surface->stride + j] = 255;
          }
       }
    }
@@ -426,7 +426,7 @@ pstip_create_texture(struct pstip_stage *pstip)
    texTemp.width[0] = 32;
    texTemp.height[0] = 32;
    texTemp.depth[0] = 1;
-   texTemp.cpp = 1;
+   pf_get_block(texTemp.format, &texTemp.block);
 
    pstip->texture = screen->texture_create(screen, &texTemp);
    if (pstip->texture == NULL)
index 5728757d2fb492a2f98a15cdc070eb9a2367cb67..ab603ff6e4d270370879b3ac5ed4f6393ae913cd 100644 (file)
@@ -48,34 +48,23 @@ void
 pipe_get_tile_raw(struct pipe_context *pipe,
                   struct pipe_surface *ps,
                   uint x, uint y, uint w, uint h,
-                  void *p, int dst_stride)
+                  void *dst, int dst_stride)
 {
    struct pipe_screen *screen = pipe->screen;
-   const uint cpp = ps->cpp;
-   const ubyte *pSrc;
-   const uint src_stride = ps->pitch * cpp;
-   ubyte *pDest;
-   uint i;
-
-   if (dst_stride == 0) {
-      dst_stride = w * cpp;
-   }
+   const void *src;
 
    if (pipe_clip_tile(x, y, &w, &h, ps))
       return;
 
-   pSrc = (const ubyte *) screen->surface_map(screen, ps,
-                                              PIPE_BUFFER_USAGE_CPU_READ);
-   assert(pSrc);                /* XXX: proper error handling! */
+   if (dst_stride == 0)
+      dst_stride = pf_get_nblocksx(&ps->block, w) * ps->block.size;
 
-   pSrc += (y * ps->pitch + x) * cpp;
-   pDest = (ubyte *) p;
+   src = screen->surface_map(screen, ps, PIPE_BUFFER_USAGE_CPU_READ);
+   assert(src);
+   if(!src)
+      return;
 
-   for (i = 0; i < h; i++) {
-      memcpy(pDest, pSrc, w * cpp);
-      pDest += dst_stride;
-      pSrc += src_stride;
-   }
+   pipe_copy_rect(dst, &ps->block, dst_stride, 0, 0, w, h, src, ps->stride, x, y);
 
    screen->surface_unmap(screen, ps);
 }
@@ -89,34 +78,23 @@ void
 pipe_put_tile_raw(struct pipe_context *pipe,
                   struct pipe_surface *ps,
                   uint x, uint y, uint w, uint h,
-                  const void *p, int src_stride)
+                  const void *src, int src_stride)
 {
    struct pipe_screen *screen = pipe->screen;
-   const uint cpp = ps->cpp;
-   const ubyte *pSrc;
-   const uint dst_stride = ps->pitch * cpp;
-   ubyte *pDest;
-   uint i;
-
-   if (src_stride == 0) {
-      src_stride = w * cpp;
-   }
+   void *dst;
 
    if (pipe_clip_tile(x, y, &w, &h, ps))
       return;
 
-   pSrc = (const ubyte *) p;
+   if (src_stride == 0)
+      src_stride = pf_get_nblocksx(&ps->block, w) * ps->block.size;
 
-   pDest = screen->surface_map(screen, ps, PIPE_BUFFER_USAGE_CPU_WRITE);
-   assert(pDest);               /* XXX: proper error handling */
-
-   pDest += (y * ps->pitch + x) * cpp;
+   dst = screen->surface_map(screen, ps, PIPE_BUFFER_USAGE_CPU_WRITE);
+   assert(dst);
+   if(!dst)
+      return;
 
-   for (i = 0; i < h; i++) {
-      memcpy(pDest, pSrc, w * cpp);
-      pDest += dst_stride;
-      pSrc += src_stride;
-   }
+   pipe_copy_rect(dst, &ps->block, ps->stride, x, y, w, h, src, src_stride, 0, 0);
 
    screen->surface_unmap(screen, ps);
 }
@@ -692,12 +670,12 @@ pipe_get_tile_rgba(struct pipe_context *pipe,
    if (pipe_clip_tile(x, y, &w, &h, ps))
       return;
 
-   packed = MALLOC(h * w * ps->cpp);
+   packed = MALLOC(pf_get_nblocks(&ps->block, w, h) * ps->block.size);
 
    if (!packed)
       return;
 
-   pipe_get_tile_raw(pipe, ps, x, y, w, h, packed, w * ps->cpp);
+   pipe_get_tile_raw(pipe, ps, x, y, w, h, packed, 0);
 
    switch (ps->format) {
    case PIPE_FORMAT_A8R8G8B8_UNORM:
@@ -774,7 +752,7 @@ pipe_put_tile_rgba(struct pipe_context *pipe,
    if (pipe_clip_tile(x, y, &w, &h, ps))
       return;
 
-   packed = MALLOC(h * w * ps->cpp);
+   packed = MALLOC(pf_get_nblocks(&ps->block, w, h) * ps->block.size);
 
    if (!packed)
       return;
@@ -829,7 +807,7 @@ pipe_put_tile_rgba(struct pipe_context *pipe,
       assert(0);
    }
 
-   pipe_put_tile_raw(pipe, ps, x, y, w, h, packed, w * ps->cpp);
+   pipe_put_tile_raw(pipe, ps, x, y, w, h, packed, 0);
 
    FREE(packed);
 }
@@ -846,14 +824,14 @@ pipe_get_tile_z(struct pipe_context *pipe,
 {
    struct pipe_screen *screen = pipe->screen;
    const uint dstStride = w;
-   void *map;
+   ubyte *map;
    uint *pDest = z;
    uint i, j;
 
    if (pipe_clip_tile(x, y, &w, &h, ps))
       return;
 
-   map = screen->surface_map(screen, ps, PIPE_BUFFER_USAGE_CPU_READ);
+   map = (ubyte *)screen->surface_map(screen, ps, PIPE_BUFFER_USAGE_CPU_READ);
    if (!map) {
       assert(0);
       return;
@@ -863,11 +841,11 @@ pipe_get_tile_z(struct pipe_context *pipe,
    case PIPE_FORMAT_Z32_UNORM:
       {
          const uint *pSrc
-            = (const uint *)map  + (y * ps->pitch + x);
+            = (const uint *)(map  + y * ps->stride + x*4);
          for (i = 0; i < h; i++) {
             memcpy(pDest, pSrc, 4 * w);
             pDest += dstStride;
-            pSrc += ps->pitch;
+            pSrc += ps->stride/4;
          }
       }
       break;
@@ -875,28 +853,28 @@ pipe_get_tile_z(struct pipe_context *pipe,
    case PIPE_FORMAT_X8Z24_UNORM:
       {
          const uint *pSrc
-            = (const uint *)map + (y * ps->pitch + x);
+            = (const uint *)(map + y * ps->stride + x*4);
          for (i = 0; i < h; i++) {
             for (j = 0; j < w; j++) {
                /* convert 24-bit Z to 32-bit Z */
                pDest[j] = (pSrc[j] << 8) | (pSrc[j] & 0xff);
             }
             pDest += dstStride;
-            pSrc += ps->pitch;
+            pSrc += ps->stride/4;
          }
       }
       break;
    case PIPE_FORMAT_Z16_UNORM:
       {
          const ushort *pSrc
-            = (const ushort *)map + (y * ps->pitch + x);
+            = (const ushort *)(map + y * ps->stride + x*2);
          for (i = 0; i < h; i++) {
             for (j = 0; j < w; j++) {
                /* convert 16-bit Z to 32-bit Z */
                pDest[j] = (pSrc[j] << 16) | pSrc[j];
             }
             pDest += dstStride;
-            pSrc += ps->pitch;
+            pSrc += ps->stride/2;
          }
       }
       break;
@@ -917,13 +895,13 @@ pipe_put_tile_z(struct pipe_context *pipe,
    struct pipe_screen *screen = pipe->screen;
    const uint srcStride = w;
    const uint *pSrc = zSrc;
-   void *map;
+   ubyte *map;
    uint i, j;
 
    if (pipe_clip_tile(x, y, &w, &h, ps))
       return;
 
-   map = screen->surface_map(screen, ps, PIPE_BUFFER_USAGE_CPU_WRITE);
+   map = (ubyte *)screen->surface_map(screen, ps, PIPE_BUFFER_USAGE_CPU_WRITE);
    if (!map) {
       assert(0);
       return;
@@ -932,10 +910,10 @@ pipe_put_tile_z(struct pipe_context *pipe,
    switch (ps->format) {
    case PIPE_FORMAT_Z32_UNORM:
       {
-         uint *pDest = (uint *) map + (y * ps->pitch + x);
+         uint *pDest = (uint *) (map + y * ps->stride + x*4);
          for (i = 0; i < h; i++) {
             memcpy(pDest, pSrc, 4 * w);
-            pDest += ps->pitch;
+            pDest += ps->stride/4;
             pSrc += srcStride;
          }
       }
@@ -943,26 +921,26 @@ pipe_put_tile_z(struct pipe_context *pipe,
    case PIPE_FORMAT_S8Z24_UNORM:
    case PIPE_FORMAT_X8Z24_UNORM:
       {
-         uint *pDest = (uint *) map + (y * ps->pitch + x);
+         uint *pDest = (uint *) (map + y * ps->stride + x*4);
          for (i = 0; i < h; i++) {
             for (j = 0; j < w; j++) {
                /* convert 32-bit Z to 24-bit Z (0 stencil) */
                pDest[j] = pSrc[j] >> 8;
             }
-            pDest += ps->pitch;
+            pDest += ps->stride/4;
             pSrc += srcStride;
          }
       }
       break;
    case PIPE_FORMAT_Z16_UNORM:
       {
-         ushort *pDest = (ushort *) map + (y * ps->pitch + x);
+         ushort *pDest = (ushort *) (map + y * ps->stride + x*2);
          for (i = 0; i < h; i++) {
             for (j = 0; j < w; j++) {
                /* convert 32-bit Z to 16-bit Z */
                pDest[j] = pSrc[j] >> 16;
             }
-            pDest += ps->pitch;
+            pDest += ps->stride/2;
             pSrc += srcStride;
          }
       }
index 4e60b1b841855253b368e5343a239aa6032901c0..271be4edf14481a134cbd082ee34438405bf4bbe 100644 (file)
@@ -32,6 +32,7 @@
 
 #include "pipe/p_defines.h"
 #include "pipe/p_util.h"
+#include "pipe/p_format.h"
 
 
 /**
  */
 void
 pipe_copy_rect(ubyte * dst,
-               unsigned cpp,
-               unsigned dst_pitch,
+               const struct pipe_format_block *block,
+               unsigned dst_stride,
                unsigned dst_x,
                unsigned dst_y,
                unsigned width,
                unsigned height,
                const ubyte * src,
-               int src_pitch,
+               int src_stride,
                unsigned src_x, 
                int src_y)
 {
    unsigned i;
-   int src_pitch_pos = src_pitch < 0 ? -src_pitch : src_pitch;
+   int src_stride_pos = src_stride < 0 ? -src_stride : src_stride;
 
-   assert(cpp > 0);
+   assert(block->size > 0);
+   assert(block->width > 0);
+   assert(block->height > 0);
    assert(src_x >= 0);
    assert(src_y >= 0);
    assert(dst_x >= 0);
    assert(dst_y >= 0);
 
-   dst_pitch *= cpp;
-   src_pitch *= cpp;
-   src_pitch_pos *= cpp;
-   dst += dst_x * cpp;
-   src += src_x * cpp;
-   dst += dst_y * dst_pitch;
-   src += src_y * src_pitch_pos;
-   width *= cpp;
+   dst_x /= block->width;
+   dst_y /= block->height;
+   width = (width + block->width - 1)/block->width;
+   height = (height + block->height - 1)/block->height;
+   src_x /= block->width;
+   src_y /= block->height;
+   
+   dst += dst_x * block->size;
+   src += src_x * block->size;
+   dst += dst_y * dst_stride;
+   src += src_y * src_stride_pos;
+   width *= block->size;
 
-   if (width == dst_pitch && width == src_pitch)
+   if (width == dst_stride && width == src_stride)
       memcpy(dst, src, height * width);
    else {
       for (i = 0; i < height; i++) {
          memcpy(dst, src, width);
-         dst += dst_pitch;
-         src += src_pitch;
+         dst += dst_stride;
+         src += src_stride;
       }
    }
 }
+
+void
+pipe_fill_rect(ubyte * dst,
+               const struct pipe_format_block *block,
+               unsigned dst_stride,
+               unsigned dst_x,
+               unsigned dst_y,
+               unsigned width,
+               unsigned height,
+               uint32_t value)
+{
+   unsigned i, j;
+   unsigned width_size;
+
+   assert(block->size > 0);
+   assert(block->width > 0);
+   assert(block->height > 0);
+   assert(dst_x >= 0);
+   assert(dst_y >= 0);
+
+   dst_x /= block->width;
+   dst_y /= block->height;
+   width = (width + block->width - 1)/block->width;
+   height = (height + block->height - 1)/block->height;
+   
+   dst += dst_x * block->size;
+   dst += dst_y * dst_stride;
+   width_size = width * block->size;
+   
+   switch (block->size) {
+   case 1:
+      if(dst_stride == width_size)
+        memset(dst, (ubyte) value, height * width_size);
+      else {
+        for (i = 0; i < height; i++) {
+           memset(dst, (ubyte) value, width_size);
+           dst += dst_stride;
+        }
+      }
+      break;
+   case 2:
+      for (i = 0; i < height; i++) {
+        uint16_t *row = (uint16_t *)dst;
+        for (j = 0; j < width; j++)
+           *row++ = (uint16_t) value;
+        dst += dst_stride;
+      }
+      break;
+   case 4:
+      for (i = 0; i < height; i++) {
+        uint32_t *row = (uint32_t *)dst;
+        for (j = 0; j < width; j++)
+           *row++ = value;
+        dst += dst_stride;
+      }
+      break;
+   default:
+        assert(0);
+        break;
+   }
+}
index 6555dcd58821ee7bd8ef124d2a24aed8ebac4ec8..ae779335dc0b10eade7254e77be288c32e0ae41c 100644 (file)
@@ -324,7 +324,7 @@ util_blit_pixels(struct blit_state *ctx,
    texTemp.height[0] = srcH;
    texTemp.depth[0] = 1;
    texTemp.compressed = 0;
-   texTemp.cpp = pf_get_size(src->format);
+   pf_get_block(src->format, &texTemp.block);
 
    tex = screen->texture_create(screen, &texTemp);
    if (!tex)
index 7d71aefda9d88eb047c61a11c120733a626974f0..5313a8008a969f17fb4d6d843d9a3dcdd8914d62 100644 (file)
@@ -625,7 +625,9 @@ make_2d_mipmap(struct gen_mipmap_state *ctx,
    struct pipe_winsys *winsys = pipe->winsys;
    const uint zslice = 0;
    uint dstLevel;
-   const int bpt = pf_get_size(pt->format);
+   
+   assert(pt->block.width == 1);
+   assert(pt->block.height == 1);
 
    for (dstLevel = baseLevel + 1; dstLevel <= lastLevel; dstLevel++) {
       const uint srcLevel = dstLevel - 1;
@@ -646,9 +648,9 @@ make_2d_mipmap(struct gen_mipmap_state *ctx,
 
       reduce_2d(pt->format,
                 srcSurf->width, srcSurf->height,
-                srcSurf->pitch * bpt, srcMap,
+                srcSurf->stride, srcMap,
                 dstSurf->width, dstSurf->height,
-                dstSurf->pitch * bpt, dstMap);
+                dstSurf->stride, dstMap);
 
       winsys->buffer_unmap(winsys, srcSurf->buffer);
       winsys->buffer_unmap(winsys, dstSurf->buffer);
index 22f91fab926f547f582908fcfae44afd4d084896..45fae4c9995a73391f0725f702d16ae809e7482b 100644 (file)
@@ -47,8 +47,6 @@ i915_fill_blit(struct i915_context *i915,
 {
    unsigned BR13, CMD;
 
-   dst_pitch *= (short) cpp;
-
    switch (cpp) {
    case 1:
    case 2:
index 5d411a66486e2f8a63bbbab6d97690449948ab08..c8db4f608c59b426194bd64217d7ec40f98b62ee 100644 (file)
@@ -188,9 +188,9 @@ struct i915_texture {
 
    /* Derived from the above:
     */
-   unsigned pitch;
-   unsigned depth_pitch;          /* per-image on i945? */
-   unsigned total_height;
+   unsigned stride;
+   unsigned depth_stride;          /* per-image on i945? */
+   unsigned total_nblocksy;
 
    unsigned tiled;
 
index 19d968fd8b63dbb4ceaadfffec98e79aa171d78d..9bd6f92323d09129b85ff8f53c024159881e2a2d 100644 (file)
@@ -211,7 +211,7 @@ i915_emit_hardware_state(struct i915_context *i915 )
       struct pipe_surface *depth_surface = i915->framebuffer.zsbuf;
 
       if (cbuf_surface) {
-        unsigned cpitch = (cbuf_surface->pitch * cbuf_surface->cpp);
+        unsigned cpitch = cbuf_surface->stride;
         unsigned ctile = BUF_3D_USE_FENCE;
         if (cbuf_surface->texture &&
               ((struct i915_texture*)(cbuf_surface->texture))->tiled) {
@@ -232,7 +232,7 @@ i915_emit_hardware_state(struct i915_context *i915 )
       /* What happens if no zbuf??
        */
       if (depth_surface) {
-        unsigned zpitch = (depth_surface->pitch * depth_surface->cpp);
+        unsigned zpitch = depth_surface->stride;
         unsigned ztile = BUF_3D_USE_FENCE;
         if (depth_surface->texture &&
               ((struct i915_texture*)(depth_surface->texture))->tiled) {
index 379aff38460edfeb6c273e3908cefa2622f2a9d0..7868f21ca6a2dbdbaae97f6ab8f40e61c3f295b5 100644 (file)
@@ -242,7 +242,7 @@ i915_update_texture(struct i915_context *i915,
    assert(depth);
 
    format = translate_texture_format(pt->format);
-   pitch = tex->pitch * pt->cpp;
+   pitch = tex->stride;
 
    assert(format);
    assert(pitch);
index cc55a0910ed0dcacbfc0a41e625593f8cbe535b5..0061b22f2688ff114efd4f7969452ead8fe32489 100644 (file)
@@ -48,7 +48,9 @@ i915_surface_copy(struct pipe_context *pipe,
                  unsigned srcx, unsigned srcy, unsigned width, unsigned height)
 {
    assert( dst != src );
-   assert( dst->cpp == src->cpp );
+   assert( dst->block.size == src->block.size );
+   assert( dst->block.width == src->block.height );
+   assert( dst->block.height == src->block.height );
 
    if (0) {
       void *dst_map = pipe->screen->surface_map( pipe->screen,
@@ -60,38 +62,30 @@ i915_surface_copy(struct pipe_context *pipe,
                                                        PIPE_BUFFER_USAGE_CPU_READ );
       
       pipe_copy_rect(dst_map,
-                     dst->cpp,
-                     dst->pitch,
+                     &dst->block,
+                     dst->stride,
                      dstx, dsty, 
                      width, height, 
                      src_map, 
-                     do_flip ? -(int) src->pitch : src->pitch
+                     do_flip ? -(int) src->stride : src->stride
                      srcx, do_flip ? height - 1 - srcy : srcy);
 
       pipe->screen->surface_unmap(pipe->screen, src);
       pipe->screen->surface_unmap(pipe->screen, dst);
    }
    else {
+      assert(dst->block.width == 1);
+      assert(dst->block.height == 1);
       i915_copy_blit( i915_context(pipe),
                       do_flip,
-                     dst->cpp,
-                     (short) src->pitch, src->buffer, src->offset,
-                     (short) dst->pitch, dst->buffer, dst->offset,
+                      dst->block.size,
+                     (short) src->stride/src->block.size, src->buffer, src->offset,
+                     (short) dst->stride/dst->block.size, dst->buffer, dst->offset,
                      (short) srcx, (short) srcy, (short) dstx, (short) dsty, (short) width, (short) height );
    }
 }
 
 
-/* Fill a rectangular sub-region.  Need better logic about when to
- * push buffers into AGP - will currently do so whenever possible.
- */
-static void *
-get_pointer(struct pipe_surface *dst, void *dst_map, unsigned x, unsigned y)
-{
-   return (char *)dst_map + (y * dst->pitch + x) * dst->cpp;
-}
-
-
 static void
 i915_surface_fill(struct pipe_context *pipe,
                  struct pipe_surface *dst,
@@ -99,50 +93,20 @@ i915_surface_fill(struct pipe_context *pipe,
                  unsigned width, unsigned height, unsigned value)
 {
    if (0) {
-      unsigned i, j;
       void *dst_map = pipe->screen->surface_map( pipe->screen,
                                                  dst,
                                                  PIPE_BUFFER_USAGE_CPU_WRITE );
 
-
-      switch (dst->cpp) {
-      case 1: {
-        ubyte *row = get_pointer(dst, dst_map, dstx, dsty);
-        for (i = 0; i < height; i++) {
-           memset(row, value, width);
-           row += dst->pitch;
-        }
-      }
-        break;
-      case 2: {
-        ushort *row = get_pointer(dst, dst_map, dstx, dsty);
-        for (i = 0; i < height; i++) {
-           for (j = 0; j < width; j++)
-              row[j] = (ushort) value;
-           row += dst->pitch;
-        }
-      }
-        break;
-      case 4: {
-        unsigned *row = get_pointer(dst, dst_map, dstx, dsty);
-        for (i = 0; i < height; i++) {
-           for (j = 0; j < width; j++)
-              row[j] = value;
-           row += dst->pitch;
-        }
-      }
-        break;
-      default:
-        assert(0);
-        break;
-      }
+      pipe_fill_rect(dst_map, &dst->block, dst->stride, dstx, dsty, width, height, value);
 
       pipe->screen->surface_unmap(pipe->screen, dst);
    }
    else {
+      assert(dst->block.width == 1);
+      assert(dst->block.height == 1);
       i915_fill_blit( i915_context(pipe),
-                     dst->cpp,
-                     (short) dst->pitch
+                     dst->block.size,
+                     (short) dst->stride/dst->block.size
                      dst->buffer, dst->offset,
                      (short) dstx, (short) dsty, 
                      (short) width, (short) height, 
index b2e490c7db1766fd66ec7a6e3ad29d8ceeacef93..2815e61345cdcd24ac4eea485f3af012f193db7c 100644 (file)
@@ -109,6 +109,9 @@ i915_miptree_set_level_info(struct i915_texture *tex,
    pt->width[level] = w;
    pt->height[level] = h;
    pt->depth[level] = d;
+   
+   pt->nblocksx[level] = pf_get_nblocksx(&pt->block, w);
+   pt->nblocksy[level] = pf_get_nblocksy(&pt->block, h);
 
    tex->nr_images[level] = nr_images;
 
@@ -140,7 +143,7 @@ i915_miptree_set_image_offset(struct i915_texture *tex,
 
    assert(img < tex->nr_images[level]);
 
-   tex->image_offset[level][img] = (x + y * tex->pitch);
+   tex->image_offset[level][img] = y * tex->stride + x * tex->base.block.size;
 
    /*
    printf("%s level %d img %d pos %d,%d image_offset %x\n",
@@ -162,7 +165,7 @@ i915_displaytarget_layout(struct i915_texture *tex)
 {
    struct pipe_texture *pt = &tex->base;
 
-   if (pt->last_level > 0 || pt->cpp != 4)
+   if (pt->last_level > 0 || pt->block.size != 4)
       return 0;
 
    i915_miptree_set_level_info( tex, 0, 1,
@@ -172,18 +175,18 @@ i915_displaytarget_layout(struct i915_texture *tex)
    i915_miptree_set_image_offset( tex, 0, 0, 0, 0 );
 
    if (tex->base.width[0] >= 128) {
-      tex->pitch = power_of_two(tex->base.width[0] * pt->cpp) / pt->cpp;
-      tex->total_height = round_up(tex->base.height[0], 8);
+      tex->stride = power_of_two(tex->base.nblocksx[0] * pt->block.size);
+      tex->total_nblocksy = round_up(tex->base.nblocksy[0], 8);
       tex->tiled = 1;
    } else {
-      tex->pitch = round_up(tex->base.width[0], 64 / pt->cpp);
-      tex->total_height = tex->base.height[0];
+      tex->stride = round_up(tex->base.nblocksx[0] * pt->block.size, 64);
+      tex->total_nblocksy = tex->base.nblocksy[0];
    }
 
    /*
    printf("%s size: %d,%d,%d offset %d,%d (0x%x)\n", __FUNCTION__,
-      tex->base.width[0], tex->base.height[0], pt->cpp,
-      tex->pitch, tex->total_height, tex->pitch * tex->total_height * 4);
+      tex->base.width[0], tex->base.height[0], pt->block.size,
+      tex->stride, tex->total_nblocksy, tex->stride * tex->total_nblocksy);
    */
 
    return 1;
@@ -193,12 +196,14 @@ static void
 i945_miptree_layout_2d( struct i915_texture *tex )
 {
    struct pipe_texture *pt = &tex->base;
-   int align_h = 2, align_w = 4;
+   const int align_x = 2, align_y = 4;
    unsigned level;
    unsigned x = 0;
    unsigned y = 0;
    unsigned width = pt->width[0];
    unsigned height = pt->height[0];
+   unsigned nblocksx = pt->nblocksx[0];
+   unsigned nblocksy = pt->nblocksy[0];
 
 #if 0 /* used for tiled display targets */
    if (pt->last_level == 0 && pt->cpp == 4)
@@ -206,7 +211,7 @@ i945_miptree_layout_2d( struct i915_texture *tex )
         return;
 #endif
 
-   tex->pitch = pt->width[0];
+   tex->stride = round_up(pt->nblocksx[0] * pt->block.size, 4);
 
    /* May need to adjust pitch to accomodate the placement of
     * the 2nd mipmap level.  This occurs when the alignment
@@ -214,47 +219,43 @@ i945_miptree_layout_2d( struct i915_texture *tex )
     * 2nd mipmap level out past the width of its parent.
     */
    if (pt->last_level > 0) {
-      unsigned mip1_width = align_int(minify(pt->width[0]), align_w)
-                       + minify(minify(pt->width[0]));
+      unsigned mip1_nblocksx 
+        = align_int(pf_get_nblocksx(&pt->block, minify(width)), align_x)
+         + pf_get_nblocksx(&pt->block, minify(minify(width)));
 
-      if (mip1_width > pt->width[0])
-        tex->pitch = mip1_width;
+      if (mip1_nblocksx > nblocksx)
+        tex->stride = mip1_nblocksx * pt->block.size;
    }
 
-   /* Pitch must be a whole number of dwords, even though we
-    * express it in texels.
+   /* Pitch must be a whole number of dwords
     */
-   tex->pitch = align_int(tex->pitch * pt->cpp, 64) / pt->cpp;
-   tex->total_height = 0;
+   tex->stride = align_int(tex->stride, 64);
+   tex->total_nblocksy = 0;
 
    for (level = 0; level <= pt->last_level; level++) {
-      unsigned img_height;
-
       i915_miptree_set_level_info(tex, level, 1, width, height, 1);
       i915_miptree_set_image_offset(tex, level, 0, x, y);
 
-      if (pt->compressed)
-        img_height = MAX2(1, height/4);
-      else
-        img_height = align_int(height, align_h);
-
+      nblocksy = align_int(nblocksy, align_y);
 
       /* Because the images are packed better, the final offset
        * might not be the maximal one:
        */
-      tex->total_height = MAX2(tex->total_height, y + img_height);
+      tex->total_nblocksy = MAX2(tex->total_nblocksy, y + nblocksy);
 
       /* Layout_below: step right after second mipmap level.
        */
       if (level == 1) {
-        x += align_int(width, align_w);
+        x += align_int(nblocksx, align_x);
       }
       else {
-        y += img_height;
+        y += nblocksy;
       }
 
       width  = minify(width);
       height = minify(height);
+      nblocksx = pf_get_nblocksx(&pt->block, width);
+      nblocksy = pf_get_nblocksy(&pt->block, height);
    }
 }
 
@@ -264,15 +265,16 @@ i945_miptree_layout_cube(struct i915_texture *tex)
    struct pipe_texture *pt = &tex->base;
    unsigned level;
 
-   const unsigned dim = pt->width[0];
+   const unsigned nblocks = pt->nblocksx[0];
    unsigned face;
-   unsigned lvlWidth = pt->width[0], lvlHeight = pt->height[0];
+   unsigned width = pt->width[0];
+   unsigned height = pt->height[0];
 
    /*
    printf("%s %i, %i\n", __FUNCTION__, pt->width[0], pt->height[0]);
    */
 
-   assert(lvlWidth == lvlHeight); /* cubemap images are square */
+   assert(width == height); /* cubemap images are square */
 
    /*
     * XXX Should only be used for compressed formats. But lets
@@ -282,35 +284,32 @@ i945_miptree_layout_cube(struct i915_texture *tex)
     * determined either by the old-style packing of cubemap faces,
     * or the final row of 4x4, 2x2 and 1x1 faces below this.
     */
-   if (dim > 32)
-      tex->pitch = ((dim * pt->cpp * 2 + 3) & ~3) / pt->cpp;
+   if (nblocks > 32)
+      tex->stride = round_up(nblocks * pt->block.size * 2, 4);
    else
-      tex->pitch = 14 * 8;
+      tex->stride = 14 * 8 * pt->block.size;
 
-   /*
-    * XXX The 4 is only needed for compressed formats. See above.
-    */
-   tex->total_height = dim * 4 + 4;
+   tex->total_nblocksy = nblocks * 4;
 
    /* Set all the levels to effectively occupy the whole rectangular region.
    */
    for (level = 0; level <= pt->last_level; level++) {
-      i915_miptree_set_level_info(tex, level, 6, lvlWidth, lvlHeight, 1);
-      lvlWidth /= 2;
-      lvlHeight /= 2;
+      i915_miptree_set_level_info(tex, level, 6, width, height, 1);
+      width /= 2;
+      height /= 2;
    }
 
    for (face = 0; face < 6; face++) {
-      unsigned x = initial_offsets[face][0] * dim;
-      unsigned y = initial_offsets[face][1] * dim;
-      unsigned d = dim;
+      unsigned x = initial_offsets[face][0] * nblocks;
+      unsigned y = initial_offsets[face][1] * nblocks;
+      unsigned d = nblocks;
 
 #if 0 /* Fix and enable this code for compressed formats */
-      if (dim == 4 && face >= 4) {
+      if (nblocks == 4 && face >= 4) {
          y = tex->total_height - 4;
          x = (face - 4) * 8;
       }
-      else if (dim < 4 && (face > 0)) {
+      else if (nblocks < 4 && (face > 0)) {
          y = tex->total_height - 4;
          x = face * 8;
       }
@@ -369,28 +368,28 @@ i915_miptree_layout(struct i915_texture * tex)
 
    switch (pt->target) {
    case PIPE_TEXTURE_CUBE: {
-         const unsigned dim = pt->width[0];
+         const unsigned nblocks = pt->nblocksx[0];
          unsigned face;
-         unsigned lvlWidth = pt->width[0], lvlHeight = pt->height[0];
+         unsigned width = pt->width[0], height = pt->height[0];
 
-         assert(lvlWidth == lvlHeight); /* cubemap images are square */
+         assert(width == height); /* cubemap images are square */
 
          /* double pitch for cube layouts */
-         tex->pitch = ((dim * pt->cpp * 2 + 3) & ~3) / pt->cpp;
-         tex->total_height = dim * 4;
+         tex->stride = round_up(nblocks * pt->block.size * 2, 4);
+         tex->total_nblocksy = nblocks * 4;
 
          for (level = 0; level <= pt->last_level; level++) {
             i915_miptree_set_level_info(tex, level, 6,
-                                         lvlWidth, lvlHeight,
+                                         width, height,
                                          1);
-            lvlWidth /= 2;
-            lvlHeight /= 2;
+            width /= 2;
+            height /= 2;
          }
 
          for (face = 0; face < 6; face++) {
-            unsigned x = initial_offsets[face][0] * dim;
-            unsigned y = initial_offsets[face][1] * dim;
-            unsigned d = dim;
+            unsigned x = initial_offsets[face][0] * nblocks;
+            unsigned y = initial_offsets[face][1] * nblocks;
+            unsigned d = nblocks;
 
             for (level = 0; level <= pt->last_level; level++) {
                i915_miptree_set_image_offset(tex, level, face, x, y);
@@ -405,25 +404,29 @@ i915_miptree_layout(struct i915_texture * tex)
          unsigned width = pt->width[0];
          unsigned height = pt->height[0];
          unsigned depth = pt->depth[0];
-         unsigned stack_height = 0;
+         unsigned nblocksx = pt->nblocksx[0];
+         unsigned nblocksy = pt->nblocksy[0];
+         unsigned stack_nblocksy = 0;
 
          /* Calculate the size of a single slice. 
           */
-         tex->pitch = ((pt->width[0] * pt->cpp + 3) & ~3) / pt->cpp;
+         tex->stride = round_up(pt->nblocksx[0] * pt->block.size, 4);
 
          /* XXX: hardware expects/requires 9 levels at minimum.
           */
          for (level = 0; level <= MAX2(8, pt->last_level);
               level++) {
             i915_miptree_set_level_info(tex, level, depth,
-                                         width, height, depth);
+                                        width, height, depth);
 
 
-            stack_height += MAX2(2, height);
+            stack_nblocksy += MAX2(2, nblocksy);
 
             width = minify(width);
             height = minify(height);
             depth = minify(depth);
+            nblocksx = pf_get_nblocksx(&pt->block, width);
+            nblocksy = pf_get_nblocksy(&pt->block, height);
          }
 
          /* Fixup depth image_offsets: 
@@ -433,7 +436,7 @@ i915_miptree_layout(struct i915_texture * tex)
             unsigned i;
             for (i = 0; i < depth; i++) 
                i915_miptree_set_image_offset(tex, level, i,
-                                              0, i * stack_height);
+                                             0, i * stack_nblocksy);
 
             depth = minify(depth);
          }
@@ -443,33 +446,33 @@ i915_miptree_layout(struct i915_texture * tex)
           * remarkable how wasteful of memory the i915 texture layouts
           * are.  They are largely fixed in the i945.
           */
-         tex->total_height = stack_height * pt->depth[0];
+         tex->total_nblocksy = stack_nblocksy * pt->depth[0];
          break;
       }
 
    default:{
          unsigned width = pt->width[0];
          unsigned height = pt->height[0];
-        unsigned img_height;
+         unsigned nblocksx = pt->nblocksx[0];
+         unsigned nblocksy = pt->nblocksy[0];
 
-         tex->pitch = ((pt->width[0] * pt->cpp + 3) & ~3) / pt->cpp;
-         tex->total_height = 0;
+         tex->stride = round_up(pt->nblocksx[0] * pt->block.size, 4);
+         tex->total_nblocksy = 0;
 
          for (level = 0; level <= pt->last_level; level++) {
             i915_miptree_set_level_info(tex, level, 1,
-                                         width, height, 1);
+                                        width, height, 1);
             i915_miptree_set_image_offset(tex, level, 0,
-                                           0, tex->total_height);
+                                          0, tex->total_nblocksy);
 
-            if (pt->compressed)
-               img_height = MAX2(1, height / 4);
-            else
-               img_height = (MAX2(2, height) + 1) & ~1;
+            nblocksy = round_up(MAX2(2, nblocksy), 2);
 
-           tex->total_height += img_height;
+           tex->total_nblocksy += nblocksy;
 
             width = minify(width);
             height = minify(height);
+            nblocksx = pf_get_nblocksx(&pt->block, width);
+            nblocksy = pf_get_nblocksy(&pt->block, height);
          }
          break;
       }
@@ -477,7 +480,7 @@ i915_miptree_layout(struct i915_texture * tex)
    /*
    DBG("%s: %dx%dx%d - sz 0x%x\n", __FUNCTION__,
        tex->pitch,
-       tex->total_height, pt->cpp, tex->pitch * tex->total_height * pt->cpp);
+       tex->total_nblocksy, pt->block.size, tex->stride * tex->total_nblocksy);
    */
 
    return TRUE;
@@ -498,14 +501,16 @@ i945_miptree_layout(struct i915_texture * tex)
          unsigned width = pt->width[0];
          unsigned height = pt->height[0];
          unsigned depth = pt->depth[0];
+         unsigned nblocksx = pt->nblocksx[0];
+         unsigned nblocksy = pt->nblocksy[0];
          unsigned pack_x_pitch, pack_x_nr;
          unsigned pack_y_pitch;
 
-         tex->pitch = ((pt->width[0] * pt->cpp + 3) & ~3) / pt->cpp;
-         tex->total_height = 0;
+         tex->stride = round_up(pt->nblocksx[0] * pt->block.size, 4);
+         tex->total_nblocksy = 0;
 
-         pack_y_pitch = MAX2(pt->height[0], 2);
-         pack_x_pitch = tex->pitch;
+         pack_y_pitch = MAX2(pt->nblocksy[0], 2);
+         pack_x_pitch = tex->stride / pt->block.size;
          pack_x_nr = 1;
 
          for (level = 0; level <= pt->last_level; level++) {
@@ -515,11 +520,11 @@ i945_miptree_layout(struct i915_texture * tex)
             unsigned q, j;
 
             i915_miptree_set_level_info(tex, level, nr_images,
-                                         width, height, depth);
+                                        width, height, depth);
 
             for (q = 0; q < nr_images;) {
                for (j = 0; j < pack_x_nr && q < nr_images; j++, q++) {
-                  i915_miptree_set_image_offset(tex, level, q, x, y + tex->total_height);
+                  i915_miptree_set_image_offset(tex, level, q, x, y + tex->total_nblocksy);
                   x += pack_x_pitch;
                }
 
@@ -528,12 +533,12 @@ i945_miptree_layout(struct i915_texture * tex)
             }
 
 
-            tex->total_height += y;
+            tex->total_nblocksy += y;
 
             if (pack_x_pitch > 4) {
                pack_x_pitch >>= 1;
                pack_x_nr <<= 1;
-               assert(pack_x_pitch * pack_x_nr <= tex->pitch);
+               assert(pack_x_pitch * pack_x_nr * pt->block.size <= tex->stride);
             }
 
             if (pack_y_pitch > 2) {
@@ -543,6 +548,8 @@ i945_miptree_layout(struct i915_texture * tex)
             width = minify(width);
             height = minify(height);
             depth = minify(depth);
+            nblocksx = pf_get_nblocksx(&pt->block, width);
+            nblocksy = pf_get_nblocksy(&pt->block, height);
          }
          break;
       }
@@ -560,7 +567,7 @@ i945_miptree_layout(struct i915_texture * tex)
    /*
    DBG("%s: %dx%dx%d - sz 0x%x\n", __FUNCTION__,
        tex->pitch,
-       tex->total_height, pt->cpp, tex->pitch * tex->total_height * pt->cpp);
+       tex->total_nblocksy, pt->block.size, tex->stride * tex->total_nblocksy);
    */
 
    return TRUE;
@@ -582,6 +589,9 @@ i915_texture_create(struct pipe_screen *screen,
    tex->base.refcount = 1;
    tex->base.screen = screen;
 
+   tex->base.nblocksx[0] = pf_get_nblocksx(&tex->base.block, tex->base.width[0]);
+   tex->base.nblocksy[0] = pf_get_nblocksy(&tex->base.block, tex->base.height[0]);
+   
    if (i915screen->is_i945) {
       if (!i945_miptree_layout(tex))
         goto fail;
@@ -592,8 +602,8 @@ i915_texture_create(struct pipe_screen *screen,
 
    tex->buffer = ws->buffer_create(ws, 64,
                                   PIPE_BUFFER_USAGE_PIXEL,
-                                  tex->pitch * tex->base.cpp *
-                                  tex->total_height);
+                                  tex->stride *
+                                  tex->total_nblocksy);
 
    if (!tex->buffer)
       goto fail;
@@ -648,13 +658,13 @@ i915_get_tex_surface(struct pipe_screen *screen,
    unsigned offset;  /* in bytes */
 
    if (pt->target == PIPE_TEXTURE_CUBE) {
-      offset = tex->image_offset[level][face] * pt->cpp;
+      offset = tex->image_offset[level][face];
    }
    else if (pt->target == PIPE_TEXTURE_3D) {
-      offset = tex->image_offset[level][zslice] * pt->cpp;
+      offset = tex->image_offset[level][zslice];
    }
    else {
-      offset = tex->image_offset[level][0] * pt->cpp;
+      offset = tex->image_offset[level][0];
       assert(face == 0);
       assert(zslice == 0);
    }
@@ -666,10 +676,12 @@ i915_get_tex_surface(struct pipe_screen *screen,
       pipe_texture_reference(&ps->texture, pt);
       pipe_buffer_reference(ws, &ps->buffer, tex->buffer);
       ps->format = pt->format;
-      ps->cpp = pt->cpp;
       ps->width = pt->width[level];
       ps->height = pt->height[level];
-      ps->pitch = tex->pitch;
+      ps->block = pt->block;
+      ps->nblocksx = pt->nblocksx[level];
+      ps->nblocksy = pt->nblocksy[level];
+      ps->stride = tex->stride;
       ps->offset = offset;
       ps->usage = flags;
       ps->status = PIPE_SURFACE_STATUS_DEFINED;
@@ -680,7 +692,7 @@ i915_get_tex_surface(struct pipe_screen *screen,
 static struct pipe_texture *
 i915_texture_blanket(struct pipe_screen * screen,
                      const struct pipe_texture *base,
-                     const unsigned *pitch,
+                     const unsigned *stride,
                      struct pipe_buffer *buffer)
 {
    struct i915_texture *tex;
@@ -699,7 +711,7 @@ i915_texture_blanket(struct pipe_screen * screen,
 
    tex->base = *base;
 
-   tex->pitch = pitch[0];
+   tex->stride = stride[0];
 
    i915_miptree_set_level_info(tex, 0, 1, base->width[0], base->height[0], 1);
    i915_miptree_set_image_offset(tex, 0, 0, 0, 0);
index 8ac6b4e689729a3d0c720f3768d209e34fd1c975..2cae7665f78361b0c11a8af383b92ecc6556f983 100644 (file)
@@ -231,9 +231,9 @@ struct brw_texture {
 
    /* Derived from the above:
     */
-   unsigned pitch;
+   unsigned stride;
    unsigned depth_pitch;          /* per-image on i945? */
-   unsigned total_height;
+   unsigned total_nblocksy;
 
    unsigned nr_images[PIPE_MAX_TEXTURE_LEVELS];
 
index 925049ecc19f5e6002824f319292228f6adffdd2..be812c5da92f67dc92c8dd380a8438502c1b104a 100644 (file)
@@ -224,7 +224,9 @@ static void upload_depthbuffer(struct brw_context *brw)
    } else {
       unsigned int format;
 
-      switch (depth_surface->cpp) {
+      assert(depth_surface->block.width == 1);
+      assert(depth_surface->block.height == 1);
+      switch (depth_surface->block.size) {
       case 2:
         format = BRW_DEPTHFORMAT_D16_UNORM;
         break;
@@ -239,7 +241,7 @@ static void upload_depthbuffer(struct brw_context *brw)
         return;
       }
 
-      OUT_BATCH(((depth_surface->pitch * depth_surface->cpp) - 1) |
+      OUT_BATCH((depth_surface->stride - 1) |
                (format << 18) |
                (BRW_TILEWALK_YMAJOR << 26) |
 //             (depth_surface->region->tiled << 27) |
@@ -247,7 +249,7 @@ static void upload_depthbuffer(struct brw_context *brw)
       OUT_RELOC(depth_surface->buffer,
                PIPE_BUFFER_USAGE_GPU_READ | PIPE_BUFFER_USAGE_GPU_WRITE, 0);
       OUT_BATCH((BRW_SURFACE_MIPMAPLAYOUT_BELOW << 1) |
-               ((depth_surface->pitch - 1) << 6) |
+               ((depth_surface->stride/depth_surface->block.size - 1) << 6) |
                ((depth_surface->height - 1) << 19));
       OUT_BATCH(0);
    }
index 3d98a2bf199eead8be0386b3df873d4e6be81c97..0be3dfc7438859022f738fa660b94e8c6cd5d900 100644 (file)
@@ -47,8 +47,10 @@ brw_surface_copy(struct pipe_context *pipe,
                  struct pipe_surface *src,
                  unsigned srcx, unsigned srcy, unsigned width, unsigned height)
 {
-   assert(dst != src);
-   assert(dst->cpp == src->cpp);
+   assert( dst != src );
+   assert( dst->block.size == src->block.size );
+   assert( dst->block.width == src->block.height );
+   assert( dst->block.height == src->block.height );
 
    if (0) {
       void *dst_map = pipe->screen->surface_map( pipe->screen,
@@ -60,37 +62,30 @@ brw_surface_copy(struct pipe_context *pipe,
                                                        PIPE_BUFFER_USAGE_CPU_READ );
       
       pipe_copy_rect(dst_map,
-                     dst->cpp,
-                     dst->pitch,
+                     &dst->block,
+                     dst->stride,
                      dstx, dsty, 
                      width, height, 
                      src_map, 
-                     do_flip ? -(int) src->pitch : src->pitch
+                     do_flip ? -(int) src->stride : src->stride
                      srcx, do_flip ? height - 1 - srcy : srcy);
 
       pipe->screen->surface_unmap(pipe->screen, src);
       pipe->screen->surface_unmap(pipe->screen, dst);
    }
    else {
+      assert(dst->block.width == 1);
+      assert(dst->block.height == 1);
       brw_copy_blit(brw_context(pipe),
                     do_flip,
-                    dst->cpp,
-                    (short) src->pitch, src->buffer, src->offset, FALSE,
-                    (short) dst->pitch, dst->buffer, dst->offset, FALSE,
+                    dst->block.size,
+                    (short) src->stride/src->block.size, src->buffer, src->offset, FALSE,
+                    (short) dst->stride/dst->block.size, dst->buffer, dst->offset, FALSE,
                     (short) srcx, (short) srcy, (short) dstx, (short) dsty,
                     (short) width, (short) height, PIPE_LOGICOP_COPY);
    }
 }
 
-/* Fill a rectangular sub-region.  Need better logic about when to
- * push buffers into AGP - will currently do so whenever possible.
- */
-static void *
-get_pointer(struct pipe_surface *dst, void *dst_map, unsigned x, unsigned y)
-{
-   return (char *)dst_map + (y * dst->pitch + x) * dst->cpp;
-}
-
 
 static void
 brw_surface_fill(struct pipe_context *pipe,
@@ -99,50 +94,20 @@ brw_surface_fill(struct pipe_context *pipe,
                  unsigned width, unsigned height, unsigned value)
 {
    if (0) {
-      unsigned i, j;
       void *dst_map = pipe->screen->surface_map( pipe->screen,
                                                  dst,
                                                  PIPE_BUFFER_USAGE_CPU_WRITE );
 
-
-      switch (dst->cpp) {
-      case 1: {
-        ubyte *row = get_pointer(dst, dst_map, dstx, dsty);
-        for (i = 0; i < height; i++) {
-           memset(row, value, width);
-           row += dst->pitch;
-        }
-      }
-        break;
-      case 2: {
-        ushort *row = get_pointer(dst, dst_map, dstx, dsty);
-        for (i = 0; i < height; i++) {
-           for (j = 0; j < width; j++)
-              row[j] = (ushort) value;
-           row += dst->pitch;
-        }
-      }
-        break;
-      case 4: {
-        unsigned *row = get_pointer(dst, dst_map, dstx, dsty);
-        for (i = 0; i < height; i++) {
-           for (j = 0; j < width; j++)
-              row[j] = value;
-           row += dst->pitch;
-        }
-      }
-        break;
-      default:
-        assert(0);
-        break;
-      }
+      pipe_fill_rect(dst_map, &dst->block, dst->stride, dstx, dsty, width, height, value);
 
       pipe->screen->surface_unmap(pipe->screen, dst);
    }
    else {
+      assert(dst->block.width == 1);
+      assert(dst->block.height == 1);
       brw_fill_blit(brw_context(pipe),
-                    dst->cpp,
-                    (short) dst->pitch,
+                    dst->block.size,
+                    (short) dst->stride/dst->block.size, 
                     dst->buffer, dst->offset, FALSE,
                     (short) dstx, (short) dsty,
                     (short) width, (short) height,
index 78ae0b1223e25362aca3abb39af738b058de2a8e..8c7725605bea896c3c5a453f6f70058b8d7fd971 100644 (file)
@@ -81,7 +81,7 @@ static void intel_miptree_set_image_offset(struct brw_texture *tex,
       assert(x == 0 && y == 0);
    assert(img < tex->nr_images[level]);
 
-   tex->image_offset[level][img] = (x + y * tex->pitch) * pt->cpp;
+   tex->image_offset[level][img] = y * tex->stride + x * pt->block.size;
 }
 
 static void intel_miptree_set_level_info(struct brw_texture *tex,
@@ -97,8 +97,11 @@ static void intel_miptree_set_level_info(struct brw_texture *tex,
    pt->width[level] = w;
    pt->height[level] = h;
    pt->depth[level] = d;
+   
+   pt->nblocksx[level] = pf_get_nblocksx(&pt->block, w);
+   pt->nblocksy[level] = pf_get_nblocksy(&pt->block, h);
 
-   tex->level_offset[level] = (x + y * tex->pitch) * pt->cpp;
+   tex->level_offset[level] = y * tex->stride + x * tex->base.block.size;
    tex->nr_images[level] = nr_images;
 
    /*
@@ -123,77 +126,60 @@ static void intel_miptree_set_level_info(struct brw_texture *tex,
 static void i945_miptree_layout_2d(struct brw_texture *tex)
 {
    struct pipe_texture *pt = &tex->base;
-   unsigned align_h = 2, align_w = 4;
+   const int align_x = 2, align_y = 4;
    unsigned level;
    unsigned x = 0;
    unsigned y = 0;
    unsigned width = pt->width[0];
    unsigned height = pt->height[0];
+   unsigned nblocksx = pt->nblocksx[0];
+   unsigned nblocksy = pt->nblocksy[0];
 
-   tex->pitch = pt->width[0];
-
-#if 0
-   if (pt->compressed) {
-      align_w = intel_compressed_alignment(pt->internal_format);
-      tex->pitch = ALIGN(pt->width[0], align_w);
-   }
-#endif
+   tex->stride = align(pt->nblocksx[0] * pt->block.size, 4);
 
    /* May need to adjust pitch to accomodate the placement of
-    * the 2nd mipmap.  This occurs when the alignment
+    * the 2nd mipmap level.  This occurs when the alignment
     * constraints of mipmap placement push the right edge of the
-    * 2nd mipmap out past the width of its parent.
+    * 2nd mipmap level out past the width of its parent.
     */
    if (pt->last_level > 0) {
-      unsigned mip1_width;
-
-      if (pt->compressed) {
-         mip1_width = align(minify(pt->width[0]), align_w)
-                      + align(minify(minify(pt->width[0])), align_w);
-      } else {
-         mip1_width = align(minify(pt->width[0]), align_w)
-                      + minify(minify(pt->width[0]));
-      }
+      unsigned mip1_nblocksx 
+        = align_int(pf_get_nblocksx(&pt->block, minify(width)), align_x)
+         + pf_get_nblocksx(&pt->block, minify(minify(width)));
 
-      if (mip1_width > tex->pitch) {
-         tex->pitch = mip1_width;
-      }
+      if (mip1_nblocksx > nblocksx)
+        tex->stride = mip1_nblocksx * pt->block.size;
    }
 
-   /* Pitch must be a whole number of dwords, even though we
-    * express it in texels.
+   /* Pitch must be a whole number of dwords
     */
-   tex->pitch = align(tex->pitch * pt->cpp, 4) / pt->cpp;
-   tex->total_height = 0;
+   tex->stride = align_int(tex->stride, 64);
+   tex->total_nblocksy = 0;
 
    for (level = 0; level <= pt->last_level; level++) {
-      unsigned img_height;
-
       intel_miptree_set_level_info(tex, level, 1, x, y, width,
                                   height, 1);
 
-      if (pt->compressed)
-        img_height = MAX2(1, height/4);
-      else
-        img_height = align(height, align_h);
-
+      nblocksy = align_int(nblocksy, align_y);
 
       /* Because the images are packed better, the final offset
        * might not be the maximal one:
        */
-      tex->total_height = MAX2(tex->total_height, y + img_height);
+      tex->total_nblocksy = MAX2(tex->total_nblocksy, y + nblocksy);
 
-      /* Layout_below: step right after second mipmap.
+      /* Layout_below: step right after second mipmap level.
        */
       if (level == 1) {
-        x += align(width, align_w);
+        x += align_int(nblocksx, align_x);
       }
       else {
-        y += img_height;
+        y += nblocksy;
       }
 
       width  = minify(width);
       height = minify(height);
+      nblocksx = pf_get_nblocksx(&pt->block, width);
+      nblocksy = pf_get_nblocksy(&pt->block, height);
    }
 }
 
@@ -210,26 +196,20 @@ static boolean brw_miptree_layout(struct brw_texture *tex)
       unsigned width  = pt->width[0];
       unsigned height = pt->height[0];
       unsigned depth = pt->depth[0];
+      unsigned nblocksx = pt->nblocksx[0];
+      unsigned nblocksy = pt->nblocksy[0];
       unsigned pack_x_pitch, pack_x_nr;
       unsigned pack_y_pitch;
       unsigned level;
       unsigned align_h = 2;
       unsigned align_w = 4;
 
-      tex->total_height = 0;
-#if 0
-      if (pt->compressed) {
-         align_w = intel_compressed_alignment(pt->internal_format);
-         pt->pitch = align(width, align_w);
-         pack_y_pitch = (height + 3) / 4;
-      } else
-#endif
-      {
-         tex->pitch = align(pt->width[0] * pt->cpp, 4) / pt->cpp;
-         pack_y_pitch = align(pt->height[0], align_h);
-      }
+      tex->total_nblocksy = 0;
+
+      tex->stride = align(pt->nblocksx[0], 4);
+      pack_y_pitch = align(pt->nblocksy[0], align_h);
 
-      pack_x_pitch = tex->pitch;
+      pack_x_pitch = tex->stride / pt->block.size;
       pack_x_nr = 1;
 
       for (level = 0; level <= pt->last_level; level++) {
@@ -239,7 +219,7 @@ static boolean brw_miptree_layout(struct brw_texture *tex)
         uint q, j;
 
         intel_miptree_set_level_info(tex, level, nr_images,
-                                     0, tex->total_height,
+                                     0, tex->total_nblocksy,
                                      width, height, depth);
 
         for (q = 0; q < nr_images;) {
@@ -253,10 +233,12 @@ static boolean brw_miptree_layout(struct brw_texture *tex)
         }
 
 
-        tex->total_height += y;
+        tex->total_nblocksy += y;
         width  = minify(width);
         height = minify(height);
         depth  = minify(depth);
+         nblocksx = pf_get_nblocksx(&pt->block, width);
+         nblocksy = pf_get_nblocksy(&pt->block, height);
 
          if (pt->compressed) {
             pack_y_pitch = (height + 3) / 4;
@@ -269,7 +251,7 @@ static boolean brw_miptree_layout(struct brw_texture *tex)
             if (pack_x_pitch > 4) {
                pack_x_pitch >>= 1;
                pack_x_nr <<= 1;
-               assert(pack_x_pitch * pack_x_nr <= tex->pitch);
+               assert(pack_x_pitch * pack_x_nr * pt->block.size <= tex->stride);
             }
 
             if (pack_y_pitch > 2) {
@@ -289,9 +271,9 @@ static boolean brw_miptree_layout(struct brw_texture *tex)
 #if 0
    PRINT("%s: %dx%dx%d - sz 0x%x\n", __FUNCTION__,
        pt->pitch,
-       pt->total_height,
-       pt->cpp,
-       pt->pitch * pt->total_height * pt->cpp );
+       pt->total_nblocksy,
+       pt->block.size,
+       pt->stride * pt->total_nblocksy );
 #endif
 
    return TRUE;
@@ -309,11 +291,14 @@ brw_texture_create_screen(struct pipe_screen *screen,
       tex->base = *templat;
       tex->base.refcount = 1;
 
+      tex->base.nblocksx[0] = pf_get_nblocksx(&tex->base.block, tex->base.width[0]);
+      tex->base.nblocksy[0] = pf_get_nblocksy(&tex->base.block, tex->base.height[0]);
+   
       if (brw_miptree_layout(tex))
         tex->buffer = ws->buffer_create(ws, 64,
                                          PIPE_BUFFER_USAGE_PIXEL,
-                                         tex->pitch * tex->base.cpp *
-                                         tex->total_height);
+                                         tex->stride *
+                                         tex->total_nblocksy);
 
       if (!tex->buffer) {
         FREE(tex);
@@ -370,10 +355,10 @@ brw_get_tex_surface_screen(struct pipe_screen *screen,
    offset = tex->level_offset[level];
 
    if (pt->target == PIPE_TEXTURE_CUBE) {
-      offset += tex->image_offset[level][face] * pt->cpp;
+      offset += tex->image_offset[level][face];
    }
    else if (pt->target == PIPE_TEXTURE_3D) {
-      offset += tex->image_offset[level][zslice] * pt->cpp;
+      offset += tex->image_offset[level][zslice];
    }
    else {
       assert(face == 0);
@@ -386,10 +371,12 @@ brw_get_tex_surface_screen(struct pipe_screen *screen,
       assert(ps->refcount);
       pipe_buffer_reference(ws, &ps->buffer, tex->buffer);
       ps->format = pt->format;
-      ps->cpp = pt->cpp;
       ps->width = pt->width[level];
       ps->height = pt->height[level];
-      ps->pitch = tex->pitch;
+      ps->block = pt->block;
+      ps->nblocksx = pt->nblocksx[level];
+      ps->nblocksy = pt->nblocksy[level];
+      ps->stride = tex->stride;
       ps->offset = offset;
    }
    return ps;
index 69e56dc8bd3fa0b4929f0c1bcf7f83bf41ccb71e..1a326f99186c93a5097006dedc88f5952b9030b5 100644 (file)
@@ -160,7 +160,7 @@ void brw_update_texture_surface( struct brw_context *brw,
 
    surf.ss3.tile_walk = BRW_TILEWALK_XMAJOR;
    surf.ss3.tiled_surface = 0; /* always zero */
-   surf.ss3.pitch = tObj->pitch - 1;
+   surf.ss3.pitch = tObj->stride - 1;
    surf.ss3.depth = tObj->base.depth[0] - 1;
 
    surf.ss4.min_lod = 0;
@@ -197,7 +197,7 @@ static void upload_wm_surfaces(struct brw_context *brw )
       memset(&surf, 0, sizeof(surf));
 
       if (pipe_surface != NULL) {
-        if (pipe_surface->cpp == 4)
+        if (pipe_surface->block.size == 4)
            surf.ss0.surface_format = BRW_SURFACEFORMAT_B8G8R8A8_UNORM;
         else
            surf.ss0.surface_format = BRW_SURFACEFORMAT_B5G6R5_UNORM;
@@ -210,7 +210,7 @@ static void upload_wm_surfaces(struct brw_context *brw )
         surf.ss2.height = pipe_surface->height - 1;
         surf.ss3.tile_walk = BRW_TILEWALK_XMAJOR;
         surf.ss3.tiled_surface = 0;
-        surf.ss3.pitch = (pipe_surface->pitch * pipe_surface->cpp) - 1;
+        surf.ss3.pitch = pipe_surface->stride - 1;
       } else {
         surf.ss0.surface_format = BRW_SURFACEFORMAT_B8G8R8A8_UNORM;
         surf.ss0.surface_type = BRW_SURFACE_NULL;
index 9fd48aeccc5e69a6b993b4b9a5276e64daefe535..7dc15c38d1026eeaabb7f639554fe41fdcef0809 100644 (file)
@@ -58,18 +58,20 @@ sp_surface_copy(struct pipe_context *pipe,
                                                     src,
                                                     PIPE_BUFFER_USAGE_CPU_READ );
 
-   assert(dst->cpp == src->cpp);
+   assert(dst->block.size == src->block.size);
+   assert(dst->block.width == src->block.width);
+   assert(dst->block.height == src->block.height);
    assert(src_map);
    assert(dst_map);
 
    /* If do_flip, invert src_y position and pass negative src stride */
    pipe_copy_rect(dst_map,
-                  dst->cpp,
-                  dst->pitch,
+                  &dst->block,
+                  dst->stride,
                   dstx, dsty,
                   width, height,
                   src_map,
-                  do_flip ? -(int) src->pitch : src->pitch,
+                  do_flip ? -(int) src->stride : src->stride,
                   srcx, do_flip ? src->height - 1 - srcy : srcy);
 
    pipe->screen->surface_unmap(pipe->screen, src);
@@ -80,7 +82,7 @@ sp_surface_copy(struct pipe_context *pipe,
 static void *
 get_pointer(struct pipe_surface *dst, void *dst_map, unsigned x, unsigned y)
 {
-   return (char *)dst_map + (y * dst->pitch + x) * dst->cpp;
+   return (char *)dst_map + y / dst->block.height * dst->stride + x / dst->block.width * dst->block.size;
 }
 
 
@@ -102,39 +104,14 @@ sp_surface_fill(struct pipe_context *pipe,
                                               dst,
                                               PIPE_BUFFER_USAGE_CPU_WRITE );
 
-   assert(dst->pitch > 0);
-   assert(width <= dst->pitch);
+   assert(dst->stride > 0);
 
 
-   switch (dst->cpp) {
+   switch (dst->block.size) {
    case 1:
-      {
-        ubyte *row = get_pointer(dst, dst_map, dstx, dsty);
-         for (i = 0; i < height; i++) {
-            memset(row, value, width);
-        row += dst->pitch;
-         }
-      }
-      break;
    case 2:
-      {
-         ushort *row = get_pointer(dst, dst_map, dstx, dsty);
-         for (i = 0; i < height; i++) {
-            for (j = 0; j < width; j++)
-               row[j] = (ushort) value;
-            row += dst->pitch;
-         }
-      }
-      break;
    case 4:
-      {
-         unsigned *row = get_pointer(dst, dst_map, dstx, dsty);
-         for (i = 0; i < height; i++) {
-            for (j = 0; j < width; j++)
-               row[j] = value;
-            row += dst->pitch;
-         }
-      }
+      pipe_fill_rect(dst_map, &dst->block, dst->stride, dstx, dsty, width, height, value);
       break;
    case 8:
       {
@@ -155,7 +132,7 @@ sp_surface_fill(struct pipe_context *pipe,
                row[j*4+2] = val2;
                row[j*4+3] = val3;
             }
-            row += dst->pitch * 4;
+            row += dst->stride/2;
          }
       }
       break;
index 2ef17a220b455c68ed1b135837a0cf65f6eb3fba..4db045cdc3de8616dd9b296ee1b745bb66b1c060 100644 (file)
@@ -71,13 +71,15 @@ softpipe_texture_layout(struct pipe_screen *screen,
       pt->width[level] = width;
       pt->height[level] = height;
       pt->depth[level] = depth;
-      spt->pitch[level] = width;
+      pt->nblocksx[level] = pf_get_nblocksx(&pt->block, width);  
+      pt->nblocksy[level] = pf_get_nblocksy(&pt->block, height);  
+      spt->stride[level] = pt->nblocksx[level]*pt->block.size;
 
       spt->level_offset[level] = buffer_size;
 
-      buffer_size += (((pt->compressed) ? MAX2(1, height/4) : height) *
+      buffer_size += (pt->nblocksy[level] *
                       ((pt->target == PIPE_TEXTURE_CUBE) ? 6 : depth) *
-                      width * pt->cpp);
+                      spt->stride[level]);
 
       width  = minify(width);
       height = minify(height);
@@ -121,7 +123,7 @@ softpipe_displaytarget_layout(struct pipe_screen *screen,
    /* Now extract the goodies: 
     */
    spt->buffer = surf.buffer;
-   spt->pitch[0] = surf.pitch;
+   spt->stride[0] = surf.stride;
 
    return spt->buffer != NULL;
 }
@@ -195,10 +197,12 @@ softpipe_get_tex_surface(struct pipe_screen *screen,
       assert(ps->winsys);
       pipe_buffer_reference(ws, &ps->buffer, spt->buffer);
       ps->format = pt->format;
-      ps->cpp = pt->cpp;
+      ps->block = pt->block;
       ps->width = pt->width[level];
       ps->height = pt->height[level];
-      ps->pitch = spt->pitch[level];
+      ps->nblocksx = pt->nblocksx[level];
+      ps->nblocksy = pt->nblocksy[level];
+      ps->stride = spt->stride[level];
       ps->offset = spt->level_offset[level];
       ps->usage = usage;
       
@@ -228,8 +232,8 @@ softpipe_get_tex_surface(struct pipe_screen *screen,
 
       if (pt->target == PIPE_TEXTURE_CUBE || pt->target == PIPE_TEXTURE_3D) {
         ps->offset += ((pt->target == PIPE_TEXTURE_CUBE) ? face : zslice) *
-                      (pt->compressed ? ps->height/4 : ps->height) *
-                      ps->width * ps->cpp;
+                      ps->nblocksy *
+                      ps->stride;
       }
       else {
         assert(face == 0);
index 0e1017632c9f5df81d5daf7e44e303931abf848d..bf437a7c61842ebed4d80c27ca3282d1fb045bbf 100644 (file)
@@ -42,7 +42,7 @@ struct softpipe_texture
    struct pipe_texture base;
 
    unsigned long level_offset[PIPE_MAX_TEXTURE_LEVELS];
-   unsigned long pitch[PIPE_MAX_TEXTURE_LEVELS];
+   unsigned long stride[PIPE_MAX_TEXTURE_LEVELS];
 
    /* The data is held here:
     */
index d973fb357be28345d1a779b577a4928460db0b27..a2c6155d0189e555853de00a9bc722fe87a31a28 100644 (file)
@@ -501,6 +501,47 @@ pf_get_block(enum pipe_format format, struct pipe_format_block *block)
    }
 }
 
+static INLINE unsigned
+pf_get_nblocksx(const struct pipe_format_block *block, unsigned x)
+{
+   return (x + block->width - 1)/block->width;
+}
+
+static INLINE unsigned
+pf_get_nblocksy(const struct pipe_format_block *block, unsigned y)
+{
+   return (y + block->height - 1)/block->height;
+}
+
+static INLINE unsigned
+pf_get_nblocks(const struct pipe_format_block *block, unsigned width, unsigned height)
+{
+   return pf_get_nblocksx(block, width)*pf_get_nblocksy(block, height);
+}
+
+static INLINE void
+pipe_rect_to_blocks(const struct pipe_format_block *block,
+                    unsigned *width, unsigned *height,
+                    unsigned *src_x, unsigned *src_y,
+                   unsigned *dst_x, unsigned *dst_y)
+{
+   assert(block->size > 0);
+   assert(block->width > 0);
+   assert(block->height > 0);
+   if(width)
+      *width = pf_get_nblocksx(block, *width);
+   if(height)
+      *height = pf_get_nblocksy(block, *height);
+   if(src_x)
+      *src_x /= block->width;
+   if(src_y)
+      *src_y /= block->height;
+   if(dst_x)
+      *dst_x /= block->width;
+   if(dst_y)
+      *dst_y /= block->height;
+}
+
 #ifdef __cplusplus
 }
 #endif
index e7ee8c97ed73e076c982d69c804446914bc579e9..2992e2f3b3049990a61bd443404be124274e6ada 100644 (file)
@@ -267,10 +267,12 @@ struct pipe_surface
    enum pipe_format format;      /**< PIPE_FORMAT_x */
    unsigned status;              /**< PIPE_SURFACE_STATUS_x */
    unsigned clear_value;         /**< XXX may be temporary */
-   unsigned cpp;                 /**< bytes per pixel */
    unsigned width;
    unsigned height;
-   unsigned pitch;               /**< in pixels */
+   struct pipe_format_block block;
+   unsigned nblocksx;
+   unsigned nblocksy;
+   unsigned stride;              /**< in bytes */
    unsigned layout;              /**< PIPE_SURFACE_LAYOUT_x */
    unsigned offset;              /**< offset from start of buffer, in bytes */
    unsigned refcount;
@@ -303,7 +305,10 @@ struct pipe_texture
    unsigned height[PIPE_MAX_TEXTURE_LEVELS];
    unsigned depth[PIPE_MAX_TEXTURE_LEVELS];
 
-   unsigned cpp:8;
+   struct pipe_format_block block;
+   unsigned nblocksx[PIPE_MAX_TEXTURE_LEVELS];
+   unsigned nblocksy[PIPE_MAX_TEXTURE_LEVELS];
+
    unsigned last_level:8;    /**< Index of last mipmap level present/defined */
    unsigned compressed:1;
    
index cf2447822ab6dc3dfc60eb19440b92da9239bbdd..7dcdd282875ac9cc503083003c04ca7d64b6b398 100644 (file)
@@ -31,6 +31,7 @@
 #include "p_config.h"
 #include "p_compiler.h"
 #include "p_debug.h"
+#include "p_format.h"
 #include "p_pointer.h"
 #include <math.h>
 #include <stdarg.h>
@@ -401,11 +402,15 @@ static INLINE int align(int value, int alignment)
 
 /* util/p_util.c
  */
-extern void pipe_copy_rect(ubyte * dst, unsigned cpp, unsigned dst_pitch,
-                           unsigned dst_x, unsigned dst_y, unsigned width,
-                           unsigned height, const ubyte * src,
-                           int src_pitch, unsigned src_x, int src_y);
-
+extern void pipe_copy_rect(ubyte * dst, const struct pipe_format_block *block,
+                           unsigned dst_stride, unsigned dst_x, unsigned dst_y,
+                           unsigned width, unsigned height, const ubyte * src,
+                           int src_stride, unsigned src_x, int src_y);
+
+extern void
+pipe_fill_rect(ubyte * dst, const struct pipe_format_block *block,
+               unsigned dst_stride, unsigned dst_x, unsigned dst_y,
+               unsigned width, unsigned height, uint32_t value);
 
 
 #if defined(_MSC_VER) 
index 10eedd8402d3a8fb3172bb74cd72bc15e314d864..6e814ce5d1199519114add1b7b8a5ea14abf1043 100644 (file)
@@ -322,7 +322,10 @@ void brw_aub_dump_bmp( struct brw_aubfile *aubfile,
    struct aub_dump_bmp db;
    unsigned format;
 
-   if (surface->cpp == 4)
+   assert(surface->block.width == 1);
+   assert(surface->block.height == 1);
+   
+   if (surface->block.size == 4)
       format = 0x7;
    else
       format = 0x3;
@@ -331,8 +334,8 @@ void brw_aub_dump_bmp( struct brw_aubfile *aubfile,
    db.xmin = 0;
    db.ymin = 0;
    db.format = format;
-   db.bpp = surface->cpp * 8;
-   db.pitch = surface->pitch;
+   db.bpp = surface->block.size * 8;
+   db.pitch = surface->stride/surface->block.size;
    db.xsize = surface->width;
    db.ysize = surface->height;
    db.addr = gtt_offset;
index b14758f333656ac9fa37ae9d55cb5d01df548e01..9225ee510df0c11b5e21f33e65d69a478e6c92c5 100644 (file)
@@ -364,9 +364,10 @@ xmesa_display_surface(XMesaBuffer b, const struct pipe_surface *surf)
       return;
    }
 
-
    if (XSHM_ENABLED(xm_buf) && (xm_buf->tempImage == NULL)) {
-      alloc_shm_ximage(xm_buf, b, surf->pitch, surf->height);
+      assert(surf->block.width == 1);
+      assert(surf->block.height == 1);
+      alloc_shm_ximage(xm_buf, b, surf->stride/surf->block.size, surf->height);
    }
 
    ximage = (XSHM_ENABLED(xm_buf)) ? xm_buf->tempImage : b->tempImage;
@@ -386,7 +387,7 @@ xmesa_display_surface(XMesaBuffer b, const struct pipe_surface *surf)
       /* update XImage's fields */
       ximage->width = surf->width;
       ximage->height = surf->height;
-      ximage->bytes_per_line = surf->pitch * surf->cpp;
+      ximage->bytes_per_line = surf->stride;
 
       XPutImage(b->xm_visual->display, b->drawable, b->gc,
                 ximage, 0, 0, 0, 0, surf->width, surf->height);
@@ -497,18 +498,21 @@ xm_surface_alloc_storage(struct pipe_winsys *winsys,
    surf->width = width;
    surf->height = height;
    surf->format = format;
-   surf->cpp = pf_get_size(format);
-   surf->pitch = round_up(width, alignment / surf->cpp);
+   pf_get_block(format, &surf->block);
+   surf->nblocksx = pf_get_nblocksx(&surf->block, width);
+   surf->nblocksy = pf_get_nblocksy(&surf->block, height);
+   surf->stride = round_up(surf->nblocksx * surf->block.size, alignment);
    surf->usage = flags;
 
-#ifdef GALLIUM_CELL /* XXX a bit of a hack */
-   height = round_up(height, TILE_SIZE);
-#endif
-
    assert(!surf->buffer);
    surf->buffer = winsys->buffer_create(winsys, alignment,
                                         PIPE_BUFFER_USAGE_PIXEL,
-                                        surf->pitch * surf->cpp * height);
+#ifdef GALLIUM_CELL /* XXX a bit of a hack */
+                                        surf->stride * round_up(surf->nblocksy, TILE_SIZE));
+#else
+                                        surf->stride * surf->nblocksy);
+#endif
+
    if(!surf->buffer)
       return -1;
    
index 77376099f0d01a3d6b1c07e204604bddc3476463..7fc9debdd54ea28f536d423316cebb95dedc9461 100644 (file)
@@ -279,22 +279,25 @@ aub_i915_surface_alloc_storage(struct pipe_winsys *winsys,
                                unsigned flags,
                                unsigned tex_usage)
 {
-    const unsigned alignment = 64;
-
-    surf->width = width;
-    surf->height = height;
-    surf->format = format;
-    surf->cpp = pf_get_size(format);
-    surf->pitch = round_up(width, alignment / surf->cpp);
-
-    assert(!surf->buffer);
-    surf->buffer = winsys->buffer_create(winsys, alignment,
-                                         PIPE_BUFFER_USAGE_PIXEL,
-                                         surf->pitch * surf->cpp * height);
+   const unsigned alignment = 64;
+
+   surf->width = width;
+   surf->height = height;
+   surf->format = format;
+   pf_get_block(format, &surf->block);
+   surf->nblocksx = pf_get_nblocksx(&surf->block, width);
+   surf->nblocksy = pf_get_nblocksy(&surf->block, height);
+   surf->stride = round_up(surf->nblocksx * surf->block.size, alignment);
+   surf->usage = flags;
+
+   assert(!surf->buffer);
+   surf->buffer = winsys->buffer_create(winsys, alignment,
+                                        PIPE_BUFFER_USAGE_PIXEL,
+                                        surf->stride * surf->nblocksy);
     if(!surf->buffer)
-        return -1;
+       return -1;
 
-    return 0;
+   return 0;
 }
 
 static void
index 8098d75e18f337a78755f74bb9db78e92f5cda8e..809a906ba357e089358b4195fb3aecce468695a1 100644 (file)
@@ -66,15 +66,17 @@ acc_get_tile_rgba(struct pipe_context *pipe, struct pipe_surface *acc_ps,
                   uint x, uint y, uint w, uint h, float *p)
 {
    const enum pipe_format f = acc_ps->format;
-   const int cpp = acc_ps->cpp;
+   const struct pipe_format_block b = acc_ps->block;
 
    acc_ps->format = DEFAULT_ACCUM_PIPE_FORMAT;
-   acc_ps->cpp = 8;
+   acc_ps->block.size = 8;
+   acc_ps->block.width = 1;
+   acc_ps->block.height = 1;
 
    pipe_get_tile_rgba(pipe, acc_ps, x, y, w, h, p);
 
    acc_ps->format = f;
-   acc_ps->cpp = cpp;
+   acc_ps->block = b;
 }
 
 
@@ -88,15 +90,17 @@ acc_put_tile_rgba(struct pipe_context *pipe, struct pipe_surface *acc_ps,
                   uint x, uint y, uint w, uint h, const float *p)
 {
    enum pipe_format f = acc_ps->format;
-   const int cpp = acc_ps->cpp;
+   const struct pipe_format_block b = acc_ps->block;
 
    acc_ps->format = DEFAULT_ACCUM_PIPE_FORMAT;
-   acc_ps->cpp = 8;
+   acc_ps->block.size = 8;
+   acc_ps->block.width = 1;
+   acc_ps->block.height = 1;
 
    pipe_put_tile_rgba(pipe, acc_ps, x, y, w, h, p);
 
    acc_ps->format = f;
-   acc_ps->cpp = cpp;
+   acc_ps->block = b;
 }
 
 
@@ -111,7 +115,7 @@ st_clear_accum_buffer(GLcontext *ctx, struct gl_renderbuffer *rb)
    const GLint ypos = ctx->DrawBuffer->_Ymin;
    const GLint width = ctx->DrawBuffer->_Xmax - xpos;
    const GLint height = ctx->DrawBuffer->_Ymax - ypos;
-   GLvoid *map;
+   GLubyte *map;
 
    acc_ps = screen->get_tex_surface(screen, acc_strb->texture, 0, 0, 0,
                                     PIPE_BUFFER_USAGE_CPU_WRITE);
@@ -128,8 +132,7 @@ st_clear_accum_buffer(GLcontext *ctx, struct gl_renderbuffer *rb)
          GLshort a = FLOAT_TO_SHORT(ctx->Accum.ClearColor[3]);
          int i, j;
          for (i = 0; i < height; i++) {
-            GLshort *dst = ((GLshort *) map
-                            + ((ypos + i) * acc_ps->pitch + xpos) * 4);
+            GLshort *dst = (GLshort *) (map + (ypos + i) * acc_ps->stride + xpos * 8);
             for (j = 0; j < width; j++) {
                dst[0] = r;
                dst[1] = g;
@@ -168,8 +171,7 @@ accum_mad(GLcontext *ctx, GLfloat scale, GLfloat bias,
       {
          int i, j;
          for (i = 0; i < height; i++) {
-            GLshort *acc = ((GLshort *) map
-                            + ((ypos + i) * acc_ps->pitch + xpos) * 4);
+            GLshort *acc = (GLshort *) (map + (ypos + i) * acc_ps->stride + xpos * 8);
             for (j = 0; j < width * 4; j++) {
                float val = SHORT_TO_FLOAT(acc[j]) * scale + bias;
                acc[j] = FLOAT_TO_SHORT(val);
index 6fa3cbd533c4cf50fece2d63b6b09521de9f626c..f3bc3b85841afba1959aaffdb4d2ddf297cc0725 100644 (file)
@@ -341,9 +341,9 @@ make_bitmap_texture(GLcontext *ctx, GLsizei width, GLsizei height,
    dest = screen->surface_map(screen, surface, PIPE_BUFFER_USAGE_CPU_WRITE);
 
    /* Put image into texture surface */
-   memset(dest, 0xff, height * surface->pitch);
+   memset(dest, 0xff, height * surface->stride);
    unpack_bitmap(ctx->st, 0, 0, width, height, unpack, bitmap,
-                 dest, surface->pitch);
+                 dest, surface->stride);
 
    _mesa_unmap_bitmap_pbo(ctx, unpack);
 
index d8f1d2367c1fa2d3c109e3c0331bd562cdad0d90..a7781f3ab2a291c792298c53f69ad0c0964395fd 100644 (file)
@@ -382,7 +382,7 @@ make_texture(struct st_context *st,
                                     mformat,          /* gl_texture_format */
                                     dest,             /* dest */
                                     0, 0, 0,          /* dstX/Y/Zoffset */
-                                    surface->pitch * cpp, /* dstRowStride, bytes */
+                                    surface->stride,  /* dstRowStride, bytes */
                                     &dstImageOffsets, /* dstImageOffsets */
                                     width, height, 1, /* size */
                                     format, type,     /* src format/type */
@@ -786,13 +786,13 @@ draw_stencil_pixels(GLcontext *ctx, GLint x, GLint y,
             switch (ps->format) {
             case PIPE_FORMAT_S8_UNORM:
                {
-                  ubyte *dest = stmap + spanY * ps->pitch + spanX;
+                  ubyte *dest = stmap + spanY * ps->stride + spanX;
                   memcpy(dest, values, spanWidth);
                }
                break;
             case PIPE_FORMAT_S8Z24_UNORM:
                {
-                  uint *dest = (uint *) stmap + spanY * ps->pitch + spanX;
+                  uint *dest = (uint *) (stmap + spanY * ps->stride + spanX*4);
                   GLint k;
                   for (k = 0; k < spanWidth; k++) {
                      uint p = dest[k];
@@ -903,6 +903,9 @@ copy_stencil_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
    psDraw = screen->get_tex_surface(screen, rbDraw->texture, 0, 0, 0,
                                     PIPE_BUFFER_USAGE_CPU_WRITE);
 
+   assert(psDraw->block.width == 1);
+   assert(psDraw->block.height == 1);
+   
    /* map the stencil buffer */
    drawMap = screen->surface_map(screen, psDraw, PIPE_BUFFER_USAGE_CPU_WRITE);
 
@@ -919,7 +922,7 @@ copy_stencil_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
          y = ctx->DrawBuffer->Height - y - 1;
       }
 
-      dst = drawMap + (y * psDraw->pitch + dstx) * psDraw->cpp;
+      dst = drawMap + y * psDraw->stride + dstx * psDraw->block.size;
       src = buffer + i * width;
 
       switch (psDraw->format) {
index db25ddd615225b9a6d4e6bc65a0a9e9dab8ba379..1067caf9b378594a548d656b236f0b439c69d03b 100644 (file)
@@ -113,7 +113,7 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb,
 
    template.target = PIPE_TEXTURE_2D;
    template.compressed = 0;
-   template.cpp = pf_get_size(template.format);
+   pf_get_block(template.format, &template.block);
    template.width[0] = width;
    template.height[0] = height;
    template.depth[0] = 1;
@@ -171,10 +171,12 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb,
 
    assert(strb->surface->buffer);
    assert(strb->surface->format);
-   assert(strb->surface->cpp);
+   assert(strb->surface->block.size);
+   assert(strb->surface->block.width);
+   assert(strb->surface->block.height);
    assert(strb->surface->width == width);
    assert(strb->surface->height == height);
-   assert(strb->surface->pitch);
+   assert(strb->surface->stride);
 
 
    return strb->surface != NULL;
index c5193631a7577db4692335e77e1ad65a7f097f04..09d9c29e4465e9ecd74ada6507ccecad3df1db58 100644 (file)
@@ -94,13 +94,13 @@ st_read_stencil_pixels(GLcontext *ctx, GLint x, GLint y,
       switch (ps->format) {
       case PIPE_FORMAT_S8_UNORM:
          {
-            const ubyte *src = stmap + srcY * ps->pitch + x;
+            const ubyte *src = stmap + srcY * ps->stride + x;
             memcpy(values, src, width);
          }
          break;
       case PIPE_FORMAT_S8Z24_UNORM:
          {
-            const uint *src = (uint *) stmap + srcY * ps->pitch + x;
+            const uint *src = (uint *) (stmap + srcY * ps->stride + x*4);
             GLint k;
             for (k = 0; k < width; k++) {
                values[k] = src[k] >> 24;
@@ -109,7 +109,7 @@ st_read_stencil_pixels(GLcontext *ctx, GLint x, GLint y,
          break;
       case PIPE_FORMAT_Z24S8_UNORM:
          {
-            const uint *src = (uint *) stmap + srcY * ps->pitch + x;
+            const uint *src = (uint *) (stmap + srcY * ps->stride + x*4);
             GLint k;
             for (k = 0; k < width; k++) {
                values[k] = src[k] & 0xff;
index 7d52d1da1b61436d998d55134467f108588b2cd8..b9aa513d7238c438df8452ca93a98b6bb2116f76 100644 (file)
@@ -658,7 +658,7 @@ st_TexImage(GLcontext * ctx,
       texImage->Data = st_texture_image_map(ctx->st, stImage, 0,
                                             PIPE_BUFFER_USAGE_CPU_WRITE);
       if (stImage->surface)
-         dstRowStride = stImage->surface->pitch * stImage->surface->cpp;
+         dstRowStride = stImage->surface->stride;
    }
    else {
       /* Allocate regular memory and store the image there temporarily.   */
@@ -820,7 +820,7 @@ st_get_tex_image(GLcontext * ctx, GLenum target, GLint level,
        */
       texImage->Data = st_texture_image_map(ctx->st, stImage, 0,
                                             PIPE_BUFFER_USAGE_CPU_READ);
-      texImage->RowStride = stImage->surface->pitch;
+      texImage->RowStride = stImage->surface->stride / stImage->pt->block.size;
    }
    else {
       /* Otherwise, the image should actually be stored in
@@ -925,7 +925,7 @@ st_TexSubimage(GLcontext * ctx,
       texImage->Data = st_texture_image_map(ctx->st, stImage, zoffset, 
                                             PIPE_BUFFER_USAGE_CPU_WRITE);
       if (stImage->surface)
-         dstRowStride = stImage->surface->pitch * stImage->surface->cpp;
+         dstRowStride = stImage->surface->stride;
    }
 
    if (!texImage->Data) {
@@ -1425,9 +1425,11 @@ copy_image_data_to_texture(struct st_context *st,
                                stImage->face,
                                dstLevel,
                                stImage->base.Data,
-                               stImage->base.RowStride,
+                               stImage->base.RowStride * 
+                               stObj->pt->block.size,
                                stImage->base.RowStride *
-                               stImage->base.Height);
+                               stImage->base.Height *
+                               stObj->pt->block.size);
       _mesa_align_free(stImage->base.Data);
       stImage->base.Data = NULL;
    }
@@ -1477,6 +1479,7 @@ st_finalize_texture(GLcontext *ctx,
       pipe_texture_reference(&stObj->pt, firstImage->pt);
    }
 
+   /* FIXME: determine format block instead of cpp */
    if (firstImage->base.IsCompressed) {
       comp_byte = compressed_num_bytes(firstImage->base.TexFormat->MesaFormat);
       cpp = comp_byte;
@@ -1497,7 +1500,9 @@ st_finalize_texture(GLcontext *ctx,
           stObj->pt->width[0] != firstImage->base.Width2 ||
           stObj->pt->height[0] != firstImage->base.Height2 ||
           stObj->pt->depth[0] != firstImage->base.Depth2 ||
-          stObj->pt->cpp != cpp ||
+          stObj->pt->block.size != cpp ||
+          stObj->pt->block.width != 1 ||
+          stObj->pt->block.height != 1 ||
           stObj->pt->compressed != firstImage->base.IsCompressed) {
          pipe_texture_release(&stObj->pt);
          ctx->st->dirty.st |= ST_NEW_FRAMEBUFFER;
index 851f17c3b46758808e1c286a3192c4ea3cca761f..2fc00df4298a3c46e88ea9416b846deee4f7374d 100644 (file)
@@ -137,10 +137,10 @@ fallback_generate_mipmap(GLcontext *ctx, GLenum target,
       _mesa_generate_mipmap_level(target, datatype, comps,
                    0 /*border*/,
                    pt->width[srcLevel], pt->height[srcLevel], pt->depth[srcLevel],
-                   srcSurf->pitch * srcSurf->cpp, /* stride in bytes */
+                   srcSurf->stride, /* stride in bytes */
                    srcData,
                    pt->width[dstLevel], pt->height[dstLevel], pt->depth[dstLevel],
-                   dstSurf->pitch * dstSurf->cpp, /* stride in bytes */
+                   dstSurf->stride, /* stride in bytes */
                    dstData);
 
       pipe_buffer_unmap(pipe, srcSurf->buffer);
index 9553b34e317b178980691d1da27dd79931cfaba2..8222826e7a744851d6f370336391a2dd62e6407e 100644 (file)
@@ -98,7 +98,7 @@ st_texture_create(struct st_context *st,
    pt.height[0] = height0;
    pt.depth[0] = depth0;
    pt.compressed = compress_byte ? 1 : 0;
-   pt.cpp = pt.compressed ? compress_byte : st_sizeof_format(format);
+   pf_get_block(format, &pt.block);
    pt.tex_usage = usage;
 
    newtex = screen->texture_create(screen, &pt);
@@ -231,16 +231,19 @@ static void
 st_surface_data(struct pipe_context *pipe,
                struct pipe_surface *dst,
                unsigned dstx, unsigned dsty,
-               const void *src, unsigned src_pitch,
+               const void *src, unsigned src_stride,
                unsigned srcx, unsigned srcy, unsigned width, unsigned height)
 {
    struct pipe_screen *screen = pipe->screen;
    void *map = screen->surface_map(screen, dst, PIPE_BUFFER_USAGE_CPU_WRITE);
 
    pipe_copy_rect(map,
-                  dst->cpp,
-                  dst->pitch,
-                  dstx, dsty, width, height, src, src_pitch, srcx, srcy);
+                  &dst->block,
+                  dst->stride,
+                  dstx, dsty, 
+                  width, height, 
+                  src, src_stride, 
+                  srcx, srcy);
 
    screen->surface_unmap(screen, dst);
 }
@@ -254,34 +257,29 @@ st_texture_image_data(struct pipe_context *pipe,
                       GLuint face,
                       GLuint level,
                       void *src,
-                      GLuint src_row_pitch, GLuint src_image_pitch)
+                      GLuint src_row_stride, GLuint src_image_stride)
 {
    struct pipe_screen *screen = pipe->screen;
    GLuint depth = dst->depth[level];
    GLuint i;
-   GLuint height = 0;
    const GLubyte *srcUB = src;
    struct pipe_surface *dst_surface;
 
    DBG("%s\n", __FUNCTION__);
    for (i = 0; i < depth; i++) {
-      height = dst->height[level];
-      if(dst->compressed)
-        height /= 4;
-
       dst_surface = screen->get_tex_surface(screen, dst, face, level, i,
                                             PIPE_BUFFER_USAGE_CPU_WRITE);
 
       st_surface_data(pipe, dst_surface,
                      0, 0,                             /* dstx, dsty */
                      srcUB,
-                     src_row_pitch,
+                     src_row_stride,
                      0, 0,                             /* source x, y */
-                     dst->width[level], height);       /* width, height */
+                     dst->width[level], dst->height[level]);       /* width, height */
 
       screen->tex_surface_release(screen, &dst_surface);
 
-      srcUB += src_image_pitch * dst->cpp;
+      srcUB += src_image_stride;
    }
 }