intel: Make intel_region's pitch be bytes instead of pixels.
authorEric Anholt <eric@anholt.net>
Thu, 10 Jan 2013 23:11:28 +0000 (15:11 -0800)
committerEric Anholt <eric@anholt.net>
Fri, 18 Jan 2013 20:48:13 +0000 (12:48 -0800)
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 <kenneth@whitecape.org>
21 files changed:
src/mesa/drivers/dri/i915/i830_texstate.c
src/mesa/drivers/dri/i915/i915_texstate.c
src/mesa/drivers/dri/i915/i915_vtbl.c
src/mesa/drivers/dri/i965/brw_misc_state.c
src/mesa/drivers/dri/i965/brw_wm_surface_state.c
src/mesa/drivers/dri/i965/gen6_blorp.cpp
src/mesa/drivers/dri/i965/gen7_blorp.cpp
src/mesa/drivers/dri/i965/gen7_misc_state.c
src/mesa/drivers/dri/i965/gen7_wm_surface_state.c
src/mesa/drivers/dri/intel/intel_blit.c
src/mesa/drivers/dri/intel/intel_context.c
src/mesa/drivers/dri/intel/intel_mipmap_tree.c
src/mesa/drivers/dri/intel/intel_pixel_bitmap.c
src/mesa/drivers/dri/intel/intel_pixel_read.c
src/mesa/drivers/dri/intel/intel_regions.c
src/mesa/drivers/dri/intel/intel_regions.h
src/mesa/drivers/dri/intel/intel_screen.c
src/mesa/drivers/dri/intel/intel_tex_copy.c
src/mesa/drivers/dri/intel/intel_tex_image.c
src/mesa/drivers/dri/intel/intel_tex_subimage.c
src/mesa/drivers/dri/intel/intel_tex_validate.c

index 73ab55e6d405b1a8e7185c7c15d6208ec246a064..f186faca09d2fa757668b45e35c708057a307724 100644 (file)
@@ -150,7 +150,7 @@ i830_update_tex_unit(struct intel_context *intel, GLuint unit, GLuint ss3)
 
    drm_intel_bo_reference(intelObj->mt->region->bo);
    i830->state.tex_buffer[unit] = intelObj->mt->region->bo;
-   pitch = intelObj->mt->region->pitch * intelObj->mt->cpp;
+   pitch = intelObj->mt->region->pitch;
 
    /* XXX: This calculation is probably broken for tiled images with
     * a non-page-aligned offset.
index 94a8e5522ecfa890fe6009109d28ecee311c46bd..2f3286920d5182fb4af931de1eae7c2506248012 100644 (file)
@@ -141,7 +141,7 @@ i915_update_tex_unit(struct intel_context *intel, GLuint unit, GLuint ss3)
    struct intel_texture_object *intelObj = intel_texture_object(tObj);
    struct gl_texture_image *firstImage;
    struct gl_sampler_object *sampler = _mesa_get_samplerobj(ctx, unit);
-   GLuint *state = i915->state.Tex[unit], format, pitch;
+   GLuint *state = i915->state.Tex[unit], format;
    GLint lodbias, aniso = 0;
    GLubyte border[4];
    GLfloat maxlod;
@@ -169,7 +169,6 @@ i915_update_tex_unit(struct intel_context *intel, GLuint unit, GLuint ss3)
 
    format = translate_texture_format(firstImage->TexFormat,
                                     tObj->DepthMode);
-   pitch = intelObj->mt->region->pitch * intelObj->mt->cpp;
 
    state[I915_TEXREG_MS3] =
       (((firstImage->Height - 1) << MS3_HEIGHT_SHIFT) |
@@ -187,7 +186,7 @@ i915_update_tex_unit(struct intel_context *intel, GLuint unit, GLuint ss3)
     */
    maxlod = MIN2(sampler->MaxLod, tObj->_MaxLevel - tObj->BaseLevel);
    state[I915_TEXREG_MS4] =
-      ((((pitch / 4) - 1) << MS4_PITCH_SHIFT) |
+      ((((intelObj->mt->region->pitch / 4) - 1) << MS4_PITCH_SHIFT) |
        MS4_CUBE_FACE_ENA_MASK |
        (U_FIXED(CLAMP(maxlod, 0.0, 11.0), 2) << MS4_MAX_LOD_SHIFT) |
        ((firstImage->Depth - 1) << MS4_VOLUME_DEPTH_SHIFT));
index e78dbc8f13f147571517bbafe28f3e5f9ba80f3d..91fde5587f9f14fd612aa2804dac66b966a9dbec 100644 (file)
@@ -531,7 +531,7 @@ i915_set_buf_info_for_region(uint32_t *state, struct intel_region *region,
    state[1] = buffer_id;
 
    if (region != NULL) {
-      state[1] |= BUF_3D_PITCH(region->pitch * region->cpp);
+      state[1] |= BUF_3D_PITCH(region->pitch);
 
       if (region->tiling != I915_TILING_NONE) {
         state[1] |= BUF_3D_TILED_SURFACE;
index d7724e3e07b8d8627f6a91107e0ffc3932da81d9..1024c4247fdc24f5d0dd247e88e22a7792a7b103 100644 (file)
@@ -656,7 +656,7 @@ static void emit_depthbuffer(struct brw_context *brw)
 
       BEGIN_BATCH(len);
       OUT_BATCH(_3DSTATE_DEPTH_BUFFER << 16 | (len - 2));
-      OUT_BATCH(((region->pitch * region->cpp) - 1) |
+      OUT_BATCH((region->pitch - 1) |
                (brw_depthbuffer_format(brw) << 18) |
                ((hiz_mt ? 1 : 0) << 21) | /* separate stencil enable */
                ((hiz_mt ? 1 : 0) << 22) | /* hiz enable */
@@ -695,7 +695,7 @@ static void emit_depthbuffer(struct brw_context *brw)
       if (hiz_mt) {
         BEGIN_BATCH(3);
         OUT_BATCH((_3DSTATE_HIER_DEPTH_BUFFER << 16) | (3 - 2));
-        OUT_BATCH(hiz_mt->region->pitch * hiz_mt->region->cpp - 1);
+        OUT_BATCH(hiz_mt->region->pitch - 1);
         OUT_RELOC(hiz_mt->region->bo,
                   I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER,
                   brw->depthstencil.hiz_offset);
@@ -719,7 +719,7 @@ static void emit_depthbuffer(struct brw_context *brw)
           *    The pitch must be set to 2x the value computed based on width, as
           *    the stencil buffer is stored with two rows interleaved.
           */
-        OUT_BATCH(2 * region->pitch * region->cpp - 1);
+        OUT_BATCH(2 * region->pitch - 1);
         OUT_RELOC(region->bo,
                   I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER,
                   brw->depthstencil.stencil_offset);
index a2a875fa8b8c94c32371cc90d5ff24f6b8953fc5..233cd9be050a59015ffc6eaef5db44f4157bf8bf 100644 (file)
@@ -832,7 +832,7 @@ brw_update_texture_surface(struct gl_context *ctx,
 
    surf[3] = (brw_get_surface_tiling_bits(intelObj->mt->region->tiling) |
              (depth - 1) << BRW_SURFACE_DEPTH_SHIFT |
-             ((intelObj->mt->region->pitch * intelObj->mt->cpp) - 1) <<
+             (intelObj->mt->region->pitch - 1) <<
              BRW_SURFACE_PITCH_SHIFT);
 
    surf[4] = 0;
@@ -1205,7 +1205,7 @@ brw_update_renderbuffer_surface(struct brw_context *brw,
              (rb->Height - 1) << BRW_SURFACE_HEIGHT_SHIFT);
 
    surf[3] = (brw_get_surface_tiling_bits(region->tiling) |
-             ((region->pitch * region->cpp) - 1) << BRW_SURFACE_PITCH_SHIFT);
+             (region->pitch - 1) << BRW_SURFACE_PITCH_SHIFT);
 
    surf[4] = brw_get_surface_num_multisamples(mt->num_samples);
 
index 13dbd30d71f1ec6230f667bf0a92e23fa1953029..eb618988f2ad29dc6c0333ffe44802e8aed0e67f 100644 (file)
@@ -421,7 +421,7 @@ gen6_blorp_emit_surface_state(struct brw_context *brw,
    uint32_t tiling = surface->map_stencil_as_y_tiled
       ? BRW_SURFACE_TILED | BRW_SURFACE_TILED_Y
       : brw_get_surface_tiling_bits(region->tiling);
-   uint32_t pitch_bytes = region->pitch * region->cpp;
+   uint32_t pitch_bytes = region->pitch;
    if (surface->map_stencil_as_y_tiled)
       pitch_bytes *= 2;
    surf[3] = (tiling |
@@ -844,9 +844,7 @@ gen6_blorp_emit_depth_stencil_config(struct brw_context *brw,
 
       BEGIN_BATCH(7);
       OUT_BATCH(_3DSTATE_DEPTH_BUFFER << 16 | (7 - 2));
-      uint32_t pitch_bytes =
-         params->depth.mt->region->pitch * params->depth.mt->region->cpp;
-      OUT_BATCH((pitch_bytes - 1) |
+      OUT_BATCH((params->depth.mt->region->pitch - 1) |
                 params->depth_format << 18 |
                 1 << 21 | /* separate stencil enable */
                 1 << 22 | /* hiz enable */
@@ -876,7 +874,7 @@ gen6_blorp_emit_depth_stencil_config(struct brw_context *brw,
 
       BEGIN_BATCH(3);
       OUT_BATCH((_3DSTATE_HIER_DEPTH_BUFFER << 16) | (3 - 2));
-      OUT_BATCH(hiz_region->pitch * hiz_region->cpp - 1);
+      OUT_BATCH(hiz_region->pitch - 1);
       OUT_RELOC(hiz_region->bo,
                 I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER,
                 hiz_offset);
index e30f6ef8f1681de4ddceade1b70a6aee16dad1a7..21caa0afbc61411328e4f4bdf8a8480117efa51a 100644 (file)
@@ -188,7 +188,7 @@ gen7_blorp_emit_surface_state(struct brw_context *brw,
    surf[2] = SET_FIELD(width - 1, GEN7_SURFACE_WIDTH) |
              SET_FIELD(height - 1, GEN7_SURFACE_HEIGHT);
 
-   uint32_t pitch_bytes = region->pitch * region->cpp;
+   uint32_t pitch_bytes = region->pitch;
    if (surface->map_stencil_as_y_tiled)
       pitch_bytes *= 2;
    surf[3] = pitch_bytes - 1;
@@ -619,9 +619,7 @@ gen7_blorp_emit_depth_stencil_config(struct brw_context *brw,
 
       BEGIN_BATCH(7);
       OUT_BATCH(GEN7_3DSTATE_DEPTH_BUFFER << 16 | (7 - 2));
-      uint32_t pitch_bytes =
-         params->depth.mt->region->pitch * params->depth.mt->region->cpp;
-      OUT_BATCH((pitch_bytes - 1) |
+      OUT_BATCH((params->depth.mt->region->pitch - 1) |
                 params->depth_format << 18 |
                 1 << 22 | /* hiz enable */
                 1 << 28 | /* depth write */
@@ -648,7 +646,7 @@ gen7_blorp_emit_depth_stencil_config(struct brw_context *brw,
 
       BEGIN_BATCH(3);
       OUT_BATCH((GEN7_3DSTATE_HIER_DEPTH_BUFFER << 16) | (3 - 2));
-      OUT_BATCH(hiz_region->pitch * hiz_region->cpp - 1);
+      OUT_BATCH(hiz_region->pitch - 1);
       OUT_RELOC(hiz_region->bo,
                 I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER,
                 hiz_offset);
index 75e917926c45be0cc11d983da5a73c5703a0795c..7e46398a8af22c45f37023d75d4bda9e5862b8b0 100644 (file)
@@ -83,7 +83,7 @@ static void emit_depthbuffer(struct brw_context *brw)
       /* _NEW_DEPTH, _NEW_STENCIL */
       BEGIN_BATCH(7);
       OUT_BATCH(GEN7_3DSTATE_DEPTH_BUFFER << 16 | (7 - 2));
-      OUT_BATCH(((region->pitch * region->cpp) - 1) |
+      OUT_BATCH((region->pitch - 1) |
                (brw_depthbuffer_format(brw) << 18) |
                ((hiz_mt ? 1 : 0) << 22) | /* hiz enable */
                ((stencil_mt != NULL && ctx->Stencil.WriteMask != 0) << 27) |
@@ -109,7 +109,7 @@ static void emit_depthbuffer(struct brw_context *brw)
    } else {
       BEGIN_BATCH(3);
       OUT_BATCH(GEN7_3DSTATE_HIER_DEPTH_BUFFER << 16 | (3 - 2));
-      OUT_BATCH(hiz_mt->region->pitch * hiz_mt->region->cpp - 1);
+      OUT_BATCH(hiz_mt->region->pitch - 1);
       OUT_RELOC(hiz_mt->region->bo,
                 I915_GEM_DOMAIN_RENDER,
                 I915_GEM_DOMAIN_RENDER,
@@ -143,7 +143,7 @@ static void emit_depthbuffer(struct brw_context *brw)
        * indicate that it does.
        */
       OUT_BATCH(enabled |
-               (2 * stencil_mt->region->pitch * stencil_mt->region->cpp - 1));
+               (2 * stencil_mt->region->pitch - 1));
       OUT_RELOC(stencil_mt->region->bo,
                I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER,
                brw->depthstencil.stencil_offset);
index 13e8ba8ecdc5c78c291fac8d962a6670e64d7a64..05e9e75841d06036fd05812f69469cfaa7f735c5 100644 (file)
@@ -112,8 +112,7 @@ gen7_set_surface_mcs_info(struct brw_context *brw,
    /* Compute the pitch in units of tiles.  To do this we need to divide the
     * pitch in bytes by 128, since a single Y-tile is 128 bytes wide.
     */
-   unsigned pitch_bytes = mcs_mt->region->pitch * mcs_mt->cpp;
-   unsigned pitch_tiles = pitch_bytes / 128;
+   unsigned pitch_tiles = mcs_mt->region->pitch / 128;
 
    /* The upper 20 bits of surface state DWORD 6 are the upper 20 bits of the
     * GPU address of the MCS buffer; the lower 12 bits contain other control
@@ -332,7 +331,7 @@ gen7_update_texture_surface(struct gl_context *ctx,
    surf[2] = SET_FIELD(width - 1, GEN7_SURFACE_WIDTH) |
              SET_FIELD(height - 1, GEN7_SURFACE_HEIGHT);
    surf[3] = SET_FIELD(depth - 1, BRW_SURFACE_DEPTH) |
-             ((intelObj->mt->region->pitch * intelObj->mt->cpp) - 1);
+             ((intelObj->mt->region->pitch) - 1);
 
    surf[5] = intelObj->_MaxLevel - tObj->BaseLevel; /* mip count */
 
@@ -529,7 +528,7 @@ gen7_update_renderbuffer_surface(struct brw_context *brw,
 
    surf[2] = SET_FIELD(rb->Width - 1, GEN7_SURFACE_WIDTH) |
              SET_FIELD(rb->Height - 1, GEN7_SURFACE_HEIGHT);
-   surf[3] = (region->pitch * region->cpp) - 1;
+   surf[3] = region->pitch - 1;
 
    surf[4] = gen7_surface_msaa_bits(irb->mt->num_samples, irb->mt->msaa_layout);
 
index 9351df72505b4bcbbf1131836ae977455dcbaf21..4b86f0eb0e14cb8ced207719f829f128c673da3a 100644 (file)
@@ -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;
index 7bfc49a7f0592ec7944cecb20744aadccdf28300..ab97d664f365e8bc4de5bda7d2ecd6f93849de5b 100644 (file)
@@ -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)
index ad4378141d699e06ce9fd20e9c98929ae8387d18..ce03afad68ab7c8623a51f4ec944170ef431967d 100644 (file)
@@ -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) {
index 6105b42945166b909d28f3167634482d100b8a9b..954dfc50b141b325443cd76944189699f3d2c3f0 100644 (file)
@@ -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,
index 1e524cd9230954dadc960731683fb5fc3299c39e..bb9ce994913a92a6efc29272af13d1fb9e5bb030 100644 (file)
@@ -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,
index d9e026b27eafc3e0f65dc3250b840f711ff64b71..89d91b0f8feed520eb806fdd6accc944473c354b 100644 (file)
@@ -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) {
index 8737a6de19406a18e7253517670c5c2ca1e6b387..1aff5d9f3b01cac1a601be140092f1c8702c8889 100644 (file)
@@ -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 */
 
index 659a2e63b845f0ae09f2a758b6b0663e3852c411..c0b63d3c1d35230daff2d65540a97b3e8b1d582d 100644 (file)
@@ -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;
 }
index 47b8dc3b3ae39e530ad5372de83da35829d82a39..1af7b1c5671d6be651d556d73b2b2424dc17d8f2 100644 (file)
@@ -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,
index 387f5a591b5ea5d6aee880b4ac19a10410af8d4f..8e5b4b4774937d98cf94ab65998dbe1d7f80a594 100644 (file)
@@ -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);
index bf9d2dc8fbd1c5948bf34540661257b2dc2ab754..7a2f713c88fb170cb7060d74f6067a3433475e65 100644 (file)
@@ -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) {
index c849366dbdbc16baf1daf28392128f05cd2da157..6aaed60b962b193f03d0e2e6508dd618338562f5 100644 (file)
@@ -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