summaryrefslogtreecommitdiffstats
path: root/src/mesa/drivers/dri/intel
diff options
context:
space:
mode:
authorEric Anholt <[email protected]>2013-01-10 15:11:28 -0800
committerEric Anholt <[email protected]>2013-01-18 12:48:13 -0800
commit60894edeef973e86a73067276f658b72f84271b6 (patch)
tree8ad06635586742380f5f429eecae0502057597d5 /src/mesa/drivers/dri/intel
parent8fd62e80ae1985b1dc466ecddbbed1e48edb08f9 (diff)
intel: Make intel_region's pitch be bytes instead of pixels.
We almost never want a stride in pixels -- if you're doing anything with a stride, you're specifying an offset or incrementing a pointer, and in both cases you had to multiply by cpp to get the bytes value you wanted. But worse, on the way to creating a region from a new tiled BO, we divided by cpp to get pitch in pixels, and for an RGB32 buffer (an upcoming change) the pitch wouldn't divide exactly, and we'd end up with a wrong stride in our region. Reviewed-by: Kenneth Graunke <[email protected]>
Diffstat (limited to 'src/mesa/drivers/dri/intel')
-rw-r--r--src/mesa/drivers/dri/intel/intel_blit.c8
-rw-r--r--src/mesa/drivers/dri/intel/intel_context.c2
-rw-r--r--src/mesa/drivers/dri/intel/intel_mipmap_tree.c24
-rw-r--r--src/mesa/drivers/dri/intel/intel_pixel_bitmap.c2
-rw-r--r--src/mesa/drivers/dri/intel/intel_pixel_read.c2
-rw-r--r--src/mesa/drivers/dri/intel/intel_regions.c10
-rw-r--r--src/mesa/drivers/dri/intel/intel_regions.h2
-rw-r--r--src/mesa/drivers/dri/intel/intel_screen.c17
-rw-r--r--src/mesa/drivers/dri/intel/intel_tex_copy.c4
-rw-r--r--src/mesa/drivers/dri/intel/intel_tex_image.c9
-rw-r--r--src/mesa/drivers/dri/intel/intel_tex_subimage.c6
-rw-r--r--src/mesa/drivers/dri/intel/intel_tex_validate.c10
12 files changed, 46 insertions, 50 deletions
diff --git a/src/mesa/drivers/dri/intel/intel_blit.c b/src/mesa/drivers/dri/intel/intel_blit.c
index 9351df72505..4b86f0eb0e1 100644
--- a/src/mesa/drivers/dri/intel/intel_blit.c
+++ b/src/mesa/drivers/dri/intel/intel_blit.c
@@ -292,7 +292,7 @@ intelClearWithBlit(struct gl_context *ctx, GLbitfield mask)
DBG("%s dst:buf(%p)/%d %d,%d sz:%dx%d\n",
__FUNCTION__,
- region->bo, (pitch * cpp),
+ region->bo, pitch,
x1, y1, x2 - x1, y2 - y1);
BR13 = 0xf0 << 16;
@@ -316,7 +316,7 @@ intelClearWithBlit(struct gl_context *ctx, GLbitfield mask)
pitch /= 4;
}
#endif
- BR13 |= (pitch * cpp);
+ BR13 |= pitch;
if (is_depth_stencil) {
clear_val = clear_depth_value;
@@ -560,7 +560,7 @@ intel_set_teximage_alpha_to_one(struct gl_context *ctx,
DBG("%s dst:buf(%p)/%d %d,%d sz:%dx%d\n",
__FUNCTION__,
- intel_image->mt->region->bo, (pitch * cpp),
+ intel_image->mt->region->bo, pitch,
x1, y1, x2 - x1, y2 - y1);
BR13 = br13_for_cpp(cpp) | 0xf0 << 16;
@@ -575,7 +575,7 @@ intel_set_teximage_alpha_to_one(struct gl_context *ctx,
pitch /= 4;
}
#endif
- BR13 |= (pitch * cpp);
+ BR13 |= pitch;
/* do space check before going any further */
aper_array[0] = intel->batch.bo;
diff --git a/src/mesa/drivers/dri/intel/intel_context.c b/src/mesa/drivers/dri/intel/intel_context.c
index 7bfc49a7f05..ab97d664f36 100644
--- a/src/mesa/drivers/dri/intel/intel_context.c
+++ b/src/mesa/drivers/dri/intel/intel_context.c
@@ -1074,7 +1074,7 @@ intel_process_dri2_buffer(struct intel_context *intel,
buffer->cpp,
drawable->w,
drawable->h,
- buffer->pitch / buffer->cpp,
+ buffer->pitch,
buffer->name,
buffer_name);
if (!region)
diff --git a/src/mesa/drivers/dri/intel/intel_mipmap_tree.c b/src/mesa/drivers/dri/intel/intel_mipmap_tree.c
index ad4378141d6..ce03afad68a 100644
--- a/src/mesa/drivers/dri/intel/intel_mipmap_tree.c
+++ b/src/mesa/drivers/dri/intel/intel_mipmap_tree.c
@@ -720,16 +720,16 @@ intel_miptree_copy_slice(struct intel_context *intel,
DBG("validate blit mt %s %p %d,%d/%d -> mt %s %p %d,%d/%d (%dx%d)\n",
_mesa_get_format_name(src_mt->format),
- src_mt, src_x, src_y, src_mt->region->pitch * src_mt->region->cpp,
+ src_mt, src_x, src_y, src_mt->region->pitch,
_mesa_get_format_name(dst_mt->format),
- dst_mt, dst_x, dst_y, dst_mt->region->pitch * dst_mt->region->cpp,
+ dst_mt, dst_x, dst_y, dst_mt->region->pitch,
width, height);
if (!intelEmitCopyBlit(intel,
dst_mt->region->cpp,
- src_mt->region->pitch * src_mt->region->cpp, src_mt->region->bo,
+ src_mt->region->pitch, src_mt->region->bo,
0, src_mt->region->tiling,
- dst_mt->region->pitch * dst_mt->region->cpp, dst_mt->region->bo,
+ dst_mt->region->pitch, dst_mt->region->bo,
0, dst_mt->region->tiling,
src_x, src_y,
dst_x, dst_y,
@@ -1118,7 +1118,7 @@ intel_miptree_map_gtt(struct intel_context *intel,
x += image_x;
y += image_y;
- map->stride = mt->region->pitch * mt->cpp;
+ map->stride = mt->region->pitch;
map->ptr = base + y * map->stride + x * mt->cpp;
}
@@ -1165,7 +1165,7 @@ intel_miptree_map_blit(struct intel_context *intel,
if (!intelEmitCopyBlit(intel,
mt->region->cpp,
- mt->region->pitch * mt->region->cpp, mt->region->bo,
+ mt->region->pitch, mt->region->bo,
0, mt->region->tiling,
map->stride, map->bo,
0, I915_TILING_NONE,
@@ -1327,15 +1327,15 @@ intel_miptree_unmap_etc(struct intel_context *intel,
image_y += map->y;
uint8_t *dst = intel_region_map(intel, mt->region, map->mode)
- + image_y * mt->region->pitch * mt->region->cpp
+ + image_y * mt->region->pitch
+ image_x * mt->region->cpp;
if (mt->etc_format == MESA_FORMAT_ETC1_RGB8)
- _mesa_etc1_unpack_rgba8888(dst, mt->region->pitch * mt->region->cpp,
+ _mesa_etc1_unpack_rgba8888(dst, mt->region->pitch,
map->ptr, map->stride,
map->w, map->h);
else
- _mesa_unpack_etc2_format(dst, mt->region->pitch * mt->region->cpp,
+ _mesa_unpack_etc2_format(dst, mt->region->pitch,
map->ptr, map->stride,
map->w, map->h, mt->etc_format);
@@ -1394,7 +1394,8 @@ intel_miptree_map_depthstencil(struct intel_context *intel,
map_x + s_image_x,
map_y + s_image_y,
intel->has_swizzling);
- ptrdiff_t z_offset = ((map_y + z_image_y) * z_mt->region->pitch +
+ ptrdiff_t z_offset = ((map_y + z_image_y) *
+ (z_mt->region->pitch / 4) +
(map_x + z_image_x));
uint8_t s = s_map[s_offset];
uint32_t z = z_map[z_offset];
@@ -1453,7 +1454,8 @@ intel_miptree_unmap_depthstencil(struct intel_context *intel,
x + s_image_x + map->x,
y + s_image_y + map->y,
intel->has_swizzling);
- ptrdiff_t z_offset = ((y + z_image_y) * z_mt->region->pitch +
+ ptrdiff_t z_offset = ((y + z_image_y) *
+ (z_mt->region->pitch / 4) +
(x + z_image_x));
if (map_z32f_x24s8) {
diff --git a/src/mesa/drivers/dri/intel/intel_pixel_bitmap.c b/src/mesa/drivers/dri/intel/intel_pixel_bitmap.c
index 6105b429451..954dfc50b14 100644
--- a/src/mesa/drivers/dri/intel/intel_pixel_bitmap.c
+++ b/src/mesa/drivers/dri/intel/intel_pixel_bitmap.c
@@ -274,7 +274,7 @@ do_blit_bitmap( struct gl_context *ctx,
(GLubyte *)stipple,
sz,
color,
- dst->pitch * dst->cpp,
+ dst->pitch,
dst->bo,
0,
dst->tiling,
diff --git a/src/mesa/drivers/dri/intel/intel_pixel_read.c b/src/mesa/drivers/dri/intel/intel_pixel_read.c
index 1e524cd9230..bb9ce994913 100644
--- a/src/mesa/drivers/dri/intel/intel_pixel_read.c
+++ b/src/mesa/drivers/dri/intel/intel_pixel_read.c
@@ -151,7 +151,7 @@ do_blit_readpixels(struct gl_context * ctx,
if (!intelEmitCopyBlit(intel,
src->cpp,
- src->pitch * src->cpp, src->bo, 0, src->tiling,
+ src->pitch, src->bo, 0, src->tiling,
rowLength * src->cpp, dst_buffer, dst_offset, false,
x, y,
dst_x, dst_y,
diff --git a/src/mesa/drivers/dri/intel/intel_regions.c b/src/mesa/drivers/dri/intel/intel_regions.c
index d9e026b27ea..89d91b0f8fe 100644
--- a/src/mesa/drivers/dri/intel/intel_regions.c
+++ b/src/mesa/drivers/dri/intel/intel_regions.c
@@ -210,7 +210,7 @@ intel_region_alloc(struct intel_screen *screen,
return NULL;
region = intel_region_alloc_internal(screen, cpp, width, height,
- aligned_pitch / cpp, tiling, buffer);
+ aligned_pitch, tiling, buffer);
if (region == NULL) {
drm_intel_bo_unreference(buffer);
return NULL;
@@ -344,8 +344,6 @@ _mesa_copy_rect(GLubyte * dst,
{
GLuint i;
- dst_pitch *= cpp;
- src_pitch *= cpp;
dst += dst_x * cpp;
src += src_x * cpp;
dst += dst_y * dst_pitch;
@@ -391,8 +389,8 @@ intel_region_copy(struct intel_context *intel,
return intelEmitCopyBlit(intel,
dst->cpp,
- src_pitch * src->cpp, src->bo, src_offset, src->tiling,
- dst->pitch * dst->cpp, dst->bo, dst_offset, dst->tiling,
+ src_pitch, src->bo, src_offset, src->tiling,
+ dst->pitch, dst->bo, dst_offset, dst->tiling,
srcx, srcy, dstx, dsty, width, height,
logicop);
}
@@ -440,7 +438,7 @@ intel_region_get_aligned_offset(struct intel_region *region, uint32_t x,
uint32_t y, bool map_stencil_as_y_tiled)
{
int cpp = region->cpp;
- uint32_t pitch = region->pitch * cpp;
+ uint32_t pitch = region->pitch;
uint32_t tiling = region->tiling;
if (map_stencil_as_y_tiled) {
diff --git a/src/mesa/drivers/dri/intel/intel_regions.h b/src/mesa/drivers/dri/intel/intel_regions.h
index 8737a6de194..1aff5d9f3b0 100644
--- a/src/mesa/drivers/dri/intel/intel_regions.h
+++ b/src/mesa/drivers/dri/intel/intel_regions.h
@@ -63,7 +63,7 @@ struct intel_region
GLuint cpp; /**< bytes per pixel */
GLuint width; /**< in pixels */
GLuint height; /**< in pixels */
- GLuint pitch; /**< in pixels */
+ GLuint pitch; /**< in bytes */
GLubyte *map; /**< only non-NULL when region is actually mapped */
GLuint map_refcount; /**< Reference count for mapping */
diff --git a/src/mesa/drivers/dri/intel/intel_screen.c b/src/mesa/drivers/dri/intel/intel_screen.c
index 659a2e63b84..c0b63d3c1d3 100644
--- a/src/mesa/drivers/dri/intel/intel_screen.c
+++ b/src/mesa/drivers/dri/intel/intel_screen.c
@@ -145,14 +145,14 @@ aub_dump_bmp(struct gl_context *ctx)
continue;
}
+ assert(irb->mt->region->pitch % irb->mt->region->cpp == 0);
drm_intel_gem_bo_aub_dump_bmp(irb->mt->region->bo,
irb->draw_x,
irb->draw_y,
irb->Base.Base.Width,
irb->Base.Base.Height,
format,
- irb->mt->region->pitch *
- irb->mt->region->cpp,
+ irb->mt->region->pitch,
0);
}
}
@@ -414,7 +414,7 @@ intel_query_image(__DRIimage *image, int attrib, int *value)
{
switch (attrib) {
case __DRI_IMAGE_ATTRIB_STRIDE:
- *value = image->region->pitch * image->region->cpp;
+ *value = image->region->pitch;
return true;
case __DRI_IMAGE_ATTRIB_HANDLE:
*value = image->region->bo->handle;
@@ -523,7 +523,7 @@ intel_create_image_from_names(__DRIscreen *screen,
static __DRIimage *
intel_from_planar(__DRIimage *parent, int plane, void *loaderPrivate)
{
- int width, height, offset, stride, dri_format, cpp, index, pitch;
+ int width, height, offset, stride, dri_format, index;
struct intel_image_format *f;
uint32_t mask_x, mask_y;
__DRIimage *image;
@@ -544,9 +544,7 @@ intel_from_planar(__DRIimage *parent, int plane, void *loaderPrivate)
stride = parent->strides[index];
image = intel_allocate_image(dri_format, loaderPrivate);
- cpp = _mesa_get_format_bytes(image->format); /* safe since no none format */
- pitch = stride / cpp;
- if (offset + height * cpp * pitch > parent->region->bo->size) {
+ if (offset + height * stride > parent->region->bo->size) {
_mesa_warning(NULL, "intel_create_sub_image: subimage out of bounds");
free(image);
return NULL;
@@ -561,7 +559,7 @@ intel_from_planar(__DRIimage *parent, int plane, void *loaderPrivate)
image->region->cpp = _mesa_get_format_bytes(image->format);
image->region->width = width;
image->region->height = height;
- image->region->pitch = pitch;
+ image->region->pitch = stride;
image->region->refcount = 1;
image->region->bo = parent->region->bo;
drm_intel_bo_reference(image->region->bo);
@@ -1244,8 +1242,7 @@ intelAllocateBuffer(__DRIscreen *screen,
intelBuffer->base.attachment = attachment;
intelBuffer->base.cpp = intelBuffer->region->cpp;
- intelBuffer->base.pitch =
- intelBuffer->region->pitch * intelBuffer->region->cpp;
+ intelBuffer->base.pitch = intelBuffer->region->pitch;
return &intelBuffer->base;
}
diff --git a/src/mesa/drivers/dri/intel/intel_tex_copy.c b/src/mesa/drivers/dri/intel/intel_tex_copy.c
index 47b8dc3b3ae..1af7b1c5671 100644
--- a/src/mesa/drivers/dri/intel/intel_tex_copy.c
+++ b/src/mesa/drivers/dri/intel/intel_tex_copy.c
@@ -125,11 +125,11 @@ intel_copy_texsubimage(struct intel_context *intel,
/* blit from src buffer to texture */
if (!intelEmitCopyBlit(intel,
intelImage->mt->cpp,
- src_pitch * region->cpp,
+ src_pitch,
region->bo,
0,
region->tiling,
- intelImage->mt->region->pitch * intelImage->mt->cpp,
+ intelImage->mt->region->pitch,
intelImage->mt->region->bo,
0,
intelImage->mt->region->tiling,
diff --git a/src/mesa/drivers/dri/intel/intel_tex_image.c b/src/mesa/drivers/dri/intel/intel_tex_image.c
index 387f5a591b5..8e5b4b47749 100644
--- a/src/mesa/drivers/dri/intel/intel_tex_image.c
+++ b/src/mesa/drivers/dri/intel/intel_tex_image.c
@@ -139,7 +139,7 @@ try_pbo_upload(struct gl_context *ctx,
struct intel_context *intel = intel_context(ctx);
struct intel_buffer_object *pbo = intel_buffer_object(unpack->BufferObj);
GLuint src_offset, src_stride;
- GLuint dst_x, dst_y, dst_stride;
+ GLuint dst_x, dst_y;
drm_intel_bo *dst_buffer, *src_buffer;
if (!_mesa_is_bufferobj(unpack->BufferObj))
@@ -188,13 +188,11 @@ try_pbo_upload(struct gl_context *ctx,
intelImage->base.Base.Face,
&dst_x, &dst_y);
- dst_stride = intelImage->mt->region->pitch * intelImage->mt->region->cpp;
-
if (!intelEmitCopyBlit(intel,
intelImage->mt->cpp,
src_stride, src_buffer,
src_offset, false,
- dst_stride, dst_buffer, 0,
+ intelImage->mt->region->pitch, dst_buffer, 0,
intelImage->mt->region->tiling,
0, 0, dst_x, dst_y, image->Width, image->Height,
GL_COPY)) {
@@ -278,7 +276,8 @@ intel_set_texture_image_region(struct gl_context *ctx,
intel_texobj->needs_validate = true;
intel_image->mt->offset = offset;
- intel_image->base.RowStride = region->pitch;
+ assert(region->pitch % region->cpp == 0);
+ intel_image->base.RowStride = region->pitch / region->cpp;
/* Immediately validate the image to the object. */
intel_miptree_reference(&intel_texobj->mt, intel_image->mt);
diff --git a/src/mesa/drivers/dri/intel/intel_tex_subimage.c b/src/mesa/drivers/dri/intel/intel_tex_subimage.c
index bf9d2dc8fbd..7a2f713c88f 100644
--- a/src/mesa/drivers/dri/intel/intel_tex_subimage.c
+++ b/src/mesa/drivers/dri/intel/intel_tex_subimage.c
@@ -129,8 +129,6 @@ intel_blit_texsubimage(struct gl_context * ctx,
}
bool ret;
- unsigned int dst_pitch = intelImage->mt->region->pitch *
- intelImage->mt->cpp;
drm_intel_gem_bo_unmap_gtt(temp_bo);
@@ -138,7 +136,7 @@ intel_blit_texsubimage(struct gl_context * ctx,
intelImage->mt->cpp,
dstRowStride,
temp_bo, 0, false,
- dst_pitch,
+ intelImage->mt->region->pitch,
intelImage->mt->region->bo, 0,
intelImage->mt->region->tiling,
0, 0, blit_x, blit_y, width, height,
@@ -268,7 +266,7 @@ intel_texsubimage_tiled_memcpy(struct gl_context * ctx,
const uint32_t cpp = 4; /* chars per pixel of GL_BGRA */
const uint32_t swizzle_width_pixels = 16;
- const uint32_t stride_bytes = image->mt->region->pitch * cpp;
+ const uint32_t stride_bytes = image->mt->region->pitch;
const uint32_t width_tiles = stride_bytes / tile_width_bytes;
for (uint32_t y_pixels = yoffset; y_pixels < y_max_pixels; ++y_pixels) {
diff --git a/src/mesa/drivers/dri/intel/intel_tex_validate.c b/src/mesa/drivers/dri/intel/intel_tex_validate.c
index c849366dbdb..6aaed60b962 100644
--- a/src/mesa/drivers/dri/intel/intel_tex_validate.c
+++ b/src/mesa/drivers/dri/intel/intel_tex_validate.c
@@ -172,7 +172,8 @@ intel_tex_map_image_for_swrast(struct intel_context *intel,
*/
for (i = 0; i < mt->level[level].depth; i++) {
intel_miptree_get_image_offset(mt, level, i, &x, &y);
- intel_image->base.ImageOffsets[i] = x + y * mt->region->pitch;
+ intel_image->base.ImageOffsets[i] = x + y * (mt->region->pitch /
+ mt->region->cpp);
}
DBG("%s \n", __FUNCTION__);
@@ -183,13 +184,14 @@ intel_tex_map_image_for_swrast(struct intel_context *intel,
intel_miptree_get_image_offset(mt, level, face, &x, &y);
DBG("%s: (%d,%d) -> (%d, %d)/%d\n",
- __FUNCTION__, face, level, x, y, mt->region->pitch * mt->cpp);
+ __FUNCTION__, face, level, x, y, mt->region->pitch);
intel_image->base.Map = intel_region_map(intel, mt->region, mode) +
- (x + y * mt->region->pitch) * mt->cpp;
+ x * mt->cpp + y * mt->region->pitch;
}
- intel_image->base.RowStride = mt->region->pitch;
+ assert(mt->region->pitch % mt->region->cpp == 0);
+ intel_image->base.RowStride = mt->region->pitch / mt->region->cpp;
}
static void