aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Fonseca <[email protected]>2008-06-27 19:37:56 +0900
committerJosé Fonseca <[email protected]>2008-06-27 19:37:56 +0900
commit4ddd65967915ca4846f2831bc676c878a29dae4a (patch)
treef2c66e355d5e9ea6f80531f995ccc25166d06fc3
parent05cfb4c4b84b4e3119112c381ceffc583a4ef5fe (diff)
gallium: Drop pipe_texture->cpp and pipe_surface->cpp.
The chars-per-pixel concept falls apart with compressed and yuv images, where more than one pixel are coded in a single data block.
-rw-r--r--src/gallium/auxiliary/draw/draw_pipe_aaline.c4
-rw-r--r--src/gallium/auxiliary/draw/draw_pipe_pstipple.c6
-rw-r--r--src/gallium/auxiliary/util/p_tile.c98
-rw-r--r--src/gallium/auxiliary/util/p_util.c100
-rw-r--r--src/gallium/auxiliary/util/u_blit.c2
-rw-r--r--src/gallium/auxiliary/util/u_gen_mipmap.c8
-rw-r--r--src/gallium/drivers/i915simple/i915_blit.c2
-rw-r--r--src/gallium/drivers/i915simple/i915_context.h6
-rw-r--r--src/gallium/drivers/i915simple/i915_state_emit.c4
-rw-r--r--src/gallium/drivers/i915simple/i915_state_sampler.c2
-rw-r--r--src/gallium/drivers/i915simple/i915_surface.c68
-rw-r--r--src/gallium/drivers/i915simple/i915_texture.c196
-rw-r--r--src/gallium/drivers/i965simple/brw_context.h4
-rw-r--r--src/gallium/drivers/i965simple/brw_misc_state.c8
-rw-r--r--src/gallium/drivers/i965simple/brw_surface.c69
-rw-r--r--src/gallium/drivers/i965simple/brw_tex_layout.c117
-rw-r--r--src/gallium/drivers/i965simple/brw_wm_surface_state.c6
-rw-r--r--src/gallium/drivers/softpipe/sp_surface.c45
-rw-r--r--src/gallium/drivers/softpipe/sp_texture.c20
-rw-r--r--src/gallium/drivers/softpipe/sp_texture.h2
-rw-r--r--src/gallium/include/pipe/p_format.h41
-rw-r--r--src/gallium/include/pipe/p_state.h11
-rw-r--r--src/gallium/include/pipe/p_util.h15
-rw-r--r--src/gallium/winsys/xlib/brw_aub.c9
-rw-r--r--src/gallium/winsys/xlib/xm_winsys.c24
-rw-r--r--src/gallium/winsys/xlib/xm_winsys_aub.c31
-rw-r--r--src/mesa/state_tracker/st_cb_accum.c24
-rw-r--r--src/mesa/state_tracker/st_cb_bitmap.c4
-rw-r--r--src/mesa/state_tracker/st_cb_drawpixels.c11
-rw-r--r--src/mesa/state_tracker/st_cb_fbo.c8
-rw-r--r--src/mesa/state_tracker/st_cb_readpixels.c6
-rw-r--r--src/mesa/state_tracker/st_cb_texture.c17
-rw-r--r--src/mesa/state_tracker/st_gen_mipmap.c4
-rw-r--r--src/mesa/state_tracker/st_texture.c26
34 files changed, 513 insertions, 485 deletions
diff --git a/src/gallium/auxiliary/draw/draw_pipe_aaline.c b/src/gallium/auxiliary/draw/draw_pipe_aaline.c
index ecdebca5f12..3dd7ee19fd1 100644
--- a/src/gallium/auxiliary/draw/draw_pipe_aaline.c
+++ b/src/gallium/auxiliary/draw/draw_pipe_aaline.c
@@ -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;
}
}
diff --git a/src/gallium/auxiliary/draw/draw_pipe_pstipple.c b/src/gallium/auxiliary/draw/draw_pipe_pstipple.c
index 4087cf7a491..1f63f943656 100644
--- a/src/gallium/auxiliary/draw/draw_pipe_pstipple.c
+++ b/src/gallium/auxiliary/draw/draw_pipe_pstipple.c
@@ -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)
diff --git a/src/gallium/auxiliary/util/p_tile.c b/src/gallium/auxiliary/util/p_tile.c
index 5728757d2fb..ab603ff6e4d 100644
--- a/src/gallium/auxiliary/util/p_tile.c
+++ b/src/gallium/auxiliary/util/p_tile.c
@@ -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;
}
}
diff --git a/src/gallium/auxiliary/util/p_util.c b/src/gallium/auxiliary/util/p_util.c
index 4e60b1b8418..271be4edf14 100644
--- a/src/gallium/auxiliary/util/p_util.c
+++ b/src/gallium/auxiliary/util/p_util.c
@@ -32,6 +32,7 @@
#include "pipe/p_defines.h"
#include "pipe/p_util.h"
+#include "pipe/p_format.h"
/**
@@ -41,42 +42,109 @@
*/
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;
+ }
+}
diff --git a/src/gallium/auxiliary/util/u_blit.c b/src/gallium/auxiliary/util/u_blit.c
index 6555dcd5882..ae779335dc0 100644
--- a/src/gallium/auxiliary/util/u_blit.c
+++ b/src/gallium/auxiliary/util/u_blit.c
@@ -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)
diff --git a/src/gallium/auxiliary/util/u_gen_mipmap.c b/src/gallium/auxiliary/util/u_gen_mipmap.c
index 7d71aefda9d..5313a8008a9 100644
--- a/src/gallium/auxiliary/util/u_gen_mipmap.c
+++ b/src/gallium/auxiliary/util/u_gen_mipmap.c
@@ -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);
diff --git a/src/gallium/drivers/i915simple/i915_blit.c b/src/gallium/drivers/i915simple/i915_blit.c
index 22f91fab926..45fae4c9995 100644
--- a/src/gallium/drivers/i915simple/i915_blit.c
+++ b/src/gallium/drivers/i915simple/i915_blit.c
@@ -47,8 +47,6 @@ i915_fill_blit(struct i915_context *i915,
{
unsigned BR13, CMD;
- dst_pitch *= (short) cpp;
-
switch (cpp) {
case 1:
case 2:
diff --git a/src/gallium/drivers/i915simple/i915_context.h b/src/gallium/drivers/i915simple/i915_context.h
index 5d411a66486..c8db4f608c5 100644
--- a/src/gallium/drivers/i915simple/i915_context.h
+++ b/src/gallium/drivers/i915simple/i915_context.h
@@ -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;
diff --git a/src/gallium/drivers/i915simple/i915_state_emit.c b/src/gallium/drivers/i915simple/i915_state_emit.c
index 19d968fd8b6..9bd6f92323d 100644
--- a/src/gallium/drivers/i915simple/i915_state_emit.c
+++ b/src/gallium/drivers/i915simple/i915_state_emit.c
@@ -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) {
diff --git a/src/gallium/drivers/i915simple/i915_state_sampler.c b/src/gallium/drivers/i915simple/i915_state_sampler.c
index 379aff38460..7868f21ca6a 100644
--- a/src/gallium/drivers/i915simple/i915_state_sampler.c
+++ b/src/gallium/drivers/i915simple/i915_state_sampler.c
@@ -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);
diff --git a/src/gallium/drivers/i915simple/i915_surface.c b/src/gallium/drivers/i915simple/i915_surface.c
index cc55a0910ed..0061b22f268 100644
--- a/src/gallium/drivers/i915simple/i915_surface.c
+++ b/src/gallium/drivers/i915simple/i915_surface.c
@@ -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,
diff --git a/src/gallium/drivers/i915simple/i915_texture.c b/src/gallium/drivers/i915simple/i915_texture.c
index b2e490c7db1..2815e61345c 100644
--- a/src/gallium/drivers/i915simple/i915_texture.c
+++ b/src/gallium/drivers/i915simple/i915_texture.c
@@ -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);
diff --git a/src/gallium/drivers/i965simple/brw_context.h b/src/gallium/drivers/i965simple/brw_context.h
index 8ac6b4e6897..2cae7665f78 100644
--- a/src/gallium/drivers/i965simple/brw_context.h
+++ b/src/gallium/drivers/i965simple/brw_context.h
@@ -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];
diff --git a/src/gallium/drivers/i965simple/brw_misc_state.c b/src/gallium/drivers/i965simple/brw_misc_state.c
index 925049ecc19..be812c5da92 100644
--- a/src/gallium/drivers/i965simple/brw_misc_state.c
+++ b/src/gallium/drivers/i965simple/brw_misc_state.c
@@ -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);
}
diff --git a/src/gallium/drivers/i965simple/brw_surface.c b/src/gallium/drivers/i965simple/brw_surface.c
index 3d98a2bf199..0be3dfc7438 100644
--- a/src/gallium/drivers/i965simple/brw_surface.c
+++ b/src/gallium/drivers/i965simple/brw_surface.c
@@ -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,
diff --git a/src/gallium/drivers/i965simple/brw_tex_layout.c b/src/gallium/drivers/i965simple/brw_tex_layout.c
index 78ae0b1223e..8c7725605be 100644
--- a/src/gallium/drivers/i965simple/brw_tex_layout.c
+++ b/src/gallium/drivers/i965simple/brw_tex_layout.c
@@ -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;
diff --git a/src/gallium/drivers/i965simple/brw_wm_surface_state.c b/src/gallium/drivers/i965simple/brw_wm_surface_state.c
index 69e56dc8bd3..1a326f99186 100644
--- a/src/gallium/drivers/i965simple/brw_wm_surface_state.c
+++ b/src/gallium/drivers/i965simple/brw_wm_surface_state.c
@@ -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;
diff --git a/src/gallium/drivers/softpipe/sp_surface.c b/src/gallium/drivers/softpipe/sp_surface.c
index 9fd48aeccc5..7dc15c38d10 100644
--- a/src/gallium/drivers/softpipe/sp_surface.c
+++ b/src/gallium/drivers/softpipe/sp_surface.c
@@ -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;
diff --git a/src/gallium/drivers/softpipe/sp_texture.c b/src/gallium/drivers/softpipe/sp_texture.c
index 2ef17a220b4..4db045cdc3d 100644
--- a/src/gallium/drivers/softpipe/sp_texture.c
+++ b/src/gallium/drivers/softpipe/sp_texture.c
@@ -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);
diff --git a/src/gallium/drivers/softpipe/sp_texture.h b/src/gallium/drivers/softpipe/sp_texture.h
index 0e1017632c9..bf437a7c618 100644
--- a/src/gallium/drivers/softpipe/sp_texture.h
+++ b/src/gallium/drivers/softpipe/sp_texture.h
@@ -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:
*/
diff --git a/src/gallium/include/pipe/p_format.h b/src/gallium/include/pipe/p_format.h
index d973fb357be..a2c6155d018 100644
--- a/src/gallium/include/pipe/p_format.h
+++ b/src/gallium/include/pipe/p_format.h
@@ -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
diff --git a/src/gallium/include/pipe/p_state.h b/src/gallium/include/pipe/p_state.h
index e7ee8c97ed7..2992e2f3b30 100644
--- a/src/gallium/include/pipe/p_state.h
+++ b/src/gallium/include/pipe/p_state.h
@@ -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;
diff --git a/src/gallium/include/pipe/p_util.h b/src/gallium/include/pipe/p_util.h
index cf2447822ab..7dcdd282875 100644
--- a/src/gallium/include/pipe/p_util.h
+++ b/src/gallium/include/pipe/p_util.h
@@ -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)
diff --git a/src/gallium/winsys/xlib/brw_aub.c b/src/gallium/winsys/xlib/brw_aub.c
index 10eedd8402d..6e814ce5d11 100644
--- a/src/gallium/winsys/xlib/brw_aub.c
+++ b/src/gallium/winsys/xlib/brw_aub.c
@@ -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;
diff --git a/src/gallium/winsys/xlib/xm_winsys.c b/src/gallium/winsys/xlib/xm_winsys.c
index b14758f3336..9225ee510df 100644
--- a/src/gallium/winsys/xlib/xm_winsys.c
+++ b/src/gallium/winsys/xlib/xm_winsys.c
@@ -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;
diff --git a/src/gallium/winsys/xlib/xm_winsys_aub.c b/src/gallium/winsys/xlib/xm_winsys_aub.c
index 77376099f0d..7fc9debdd54 100644
--- a/src/gallium/winsys/xlib/xm_winsys_aub.c
+++ b/src/gallium/winsys/xlib/xm_winsys_aub.c
@@ -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
diff --git a/src/mesa/state_tracker/st_cb_accum.c b/src/mesa/state_tracker/st_cb_accum.c
index 8098d75e18f..809a906ba35 100644
--- a/src/mesa/state_tracker/st_cb_accum.c
+++ b/src/mesa/state_tracker/st_cb_accum.c
@@ -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);
diff --git a/src/mesa/state_tracker/st_cb_bitmap.c b/src/mesa/state_tracker/st_cb_bitmap.c
index 6fa3cbd533c..f3bc3b85841 100644
--- a/src/mesa/state_tracker/st_cb_bitmap.c
+++ b/src/mesa/state_tracker/st_cb_bitmap.c
@@ -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);
diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c
index d8f1d2367c1..a7781f3ab2a 100644
--- a/src/mesa/state_tracker/st_cb_drawpixels.c
+++ b/src/mesa/state_tracker/st_cb_drawpixels.c
@@ -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) {
diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c
index db25ddd6152..1067caf9b37 100644
--- a/src/mesa/state_tracker/st_cb_fbo.c
+++ b/src/mesa/state_tracker/st_cb_fbo.c
@@ -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;
diff --git a/src/mesa/state_tracker/st_cb_readpixels.c b/src/mesa/state_tracker/st_cb_readpixels.c
index c5193631a75..09d9c29e446 100644
--- a/src/mesa/state_tracker/st_cb_readpixels.c
+++ b/src/mesa/state_tracker/st_cb_readpixels.c
@@ -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;
diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c
index 7d52d1da1b6..b9aa513d723 100644
--- a/src/mesa/state_tracker/st_cb_texture.c
+++ b/src/mesa/state_tracker/st_cb_texture.c
@@ -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;
diff --git a/src/mesa/state_tracker/st_gen_mipmap.c b/src/mesa/state_tracker/st_gen_mipmap.c
index 851f17c3b46..2fc00df4298 100644
--- a/src/mesa/state_tracker/st_gen_mipmap.c
+++ b/src/mesa/state_tracker/st_gen_mipmap.c
@@ -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);
diff --git a/src/mesa/state_tracker/st_texture.c b/src/mesa/state_tracker/st_texture.c
index 9553b34e317..8222826e7a7 100644
--- a/src/mesa/state_tracker/st_texture.c
+++ b/src/mesa/state_tracker/st_texture.c
@@ -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;
}
}