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)
else {
d = 255;
}
- data[i * surface->pitch + j] = d;
+ data[i * surface->stride + j] = d;
}
}
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;
}
}
}
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)
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);
}
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);
}
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:
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;
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);
}
{
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;
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;
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;
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;
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;
}
}
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;
}
}
#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;
+ }
+}
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)
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;
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);
{
unsigned BR13, CMD;
- dst_pitch *= (short) cpp;
-
switch (cpp) {
case 1:
case 2:
/* 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;
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) {
/* 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) {
assert(depth);
format = translate_texture_format(pt->format);
- pitch = tex->pitch * pt->cpp;
+ pitch = tex->stride;
assert(format);
assert(pitch);
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,
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,
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,
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;
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",
{
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,
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;
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)
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
* 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);
}
}
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
* 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;
}
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);
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:
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);
}
* 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;
}
/*
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;
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++) {
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;
}
}
- 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) {
width = minify(width);
height = minify(height);
depth = minify(depth);
+ nblocksx = pf_get_nblocksx(&pt->block, width);
+ nblocksy = pf_get_nblocksy(&pt->block, height);
}
break;
}
/*
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;
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;
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;
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);
}
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;
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;
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);
/* 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];
} 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;
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) |
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);
}
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,
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,
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,
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,
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;
/*
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);
}
}
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++) {
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;) {
}
- 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;
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) {
#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;
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);
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);
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;
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;
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;
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;
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);
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;
}
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:
{
row[j*4+2] = val2;
row[j*4+3] = val3;
}
- row += dst->pitch * 4;
+ row += dst->stride/2;
}
}
break;
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);
/* Now extract the goodies:
*/
spt->buffer = surf.buffer;
- spt->pitch[0] = surf.pitch;
+ spt->stride[0] = surf.stride;
return spt->buffer != NULL;
}
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;
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);
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:
*/
}
}
+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
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;
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;
#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>
/* 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)
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;
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;
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;
/* 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);
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;
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
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;
}
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;
}
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);
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;
{
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);
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);
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 */
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];
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);
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) {
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;
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;
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;
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;
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. */
*/
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
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) {
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;
}
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;
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;
_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);
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);
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);
}
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;
}
}