intel: Move the teximage mapping logic to a miptree level/slice mapping.
authorEric Anholt <eric@anholt.net>
Mon, 28 Nov 2011 19:17:11 +0000 (11:17 -0800)
committerEric Anholt <eric@anholt.net>
Wed, 7 Dec 2011 21:36:57 +0000 (13:36 -0800)
This will let us share teximage mapping logic with renderbuffer
mapping, which has an intel_mipmap_tree but not a gl_texture_image.

Reviewed-by: Chad Versace <chad.versace@linux.intel.com>
src/mesa/drivers/dri/intel/intel_mipmap_tree.c
src/mesa/drivers/dri/intel/intel_mipmap_tree.h
src/mesa/drivers/dri/intel/intel_tex.c

index 3e4baa1bfb57ae8ca6c3d971edc504f881766fdc..78d572f23850f41668d0e10a001050ea93ef5034 100644 (file)
@@ -732,3 +732,83 @@ intel_miptree_all_slices_resolve_depth(struct intel_context *intel,
                                           INTEL_NEED_DEPTH_RESOLVE,
                                           intel->vtbl.resolve_depth_slice);
 }
+
+void
+intel_miptree_map(struct intel_context *intel,
+                 struct intel_mipmap_tree *mt,
+                 unsigned int level,
+                 unsigned int slice,
+                 unsigned int x,
+                 unsigned int y,
+                 unsigned int w,
+                 unsigned int h,
+                 GLbitfield mode,
+                 void **out_ptr,
+                 int *out_stride)
+{
+   unsigned int bw, bh;
+   void *base;
+   unsigned int image_x, image_y;
+
+   if (mt->stencil_mt) {
+      /* The miptree has depthstencil format, but uses separate stencil. The
+       * embedded stencil miptree contains the real stencil data, so gather
+       * that into the depthstencil miptree.
+       *
+       * FIXME: Avoid the gather if the texture is mapped as write-only.
+       */
+      intel_miptree_s8z24_gather(intel, mt, level, slice);
+   }
+
+   intel_miptree_slice_resolve_depth(intel, mt, level, slice);
+   if (mode & GL_MAP_WRITE_BIT) {
+      intel_miptree_slice_set_needs_hiz_resolve(mt, level, slice);
+   }
+
+   /* For compressed formats, the stride is the number of bytes per
+    * row of blocks.  intel_miptree_get_image_offset() already does
+    * the divide.
+    */
+   _mesa_get_format_block_size(mt->format, &bw, &bh);
+   assert(y % bh == 0);
+   y /= bh;
+
+   base = intel_region_map(intel, mt->region, mode);
+   /* Note that in the case of cube maps, the caller must have passed the slice
+    * number referencing the face.
+    */
+   intel_miptree_get_image_offset(mt, level, 0, slice, &image_x, &image_y);
+   x += image_x;
+   y += image_y;
+
+   *out_stride = mt->region->pitch * mt->cpp;
+   *out_ptr = base + y * *out_stride + x * mt->cpp;
+
+   DBG("%s: %d,%d %dx%d from mt %p (%s) %d,%d = %p/%d\n", __FUNCTION__,
+       x - image_x, y - image_y, w, h,
+       mt, _mesa_get_format_name(mt->format),
+       x, y, *out_ptr, *out_stride);
+}
+
+void
+intel_miptree_unmap(struct intel_context *intel,
+                   struct intel_mipmap_tree *mt,
+                   unsigned int level,
+                   unsigned int slice)
+{
+   DBG("%s: mt %p (%s) level %d slice %d\n", __FUNCTION__,
+       mt, _mesa_get_format_name(mt->format), level, slice);
+
+   intel_region_unmap(intel, mt->region);
+
+   if (mt->stencil_mt) {
+      /* The miptree has depthstencil format, but uses separate stencil. The
+       * embedded stencil miptree must contain the real stencil data after
+       * unmapping, so copy it from the depthstencil miptree into the stencil
+       * miptree.
+       *
+       * FIXME: Avoid the scatter if the texture was mapped as read-only.
+       */
+      intel_miptree_s8z24_scatter(intel, mt, level, slice);
+   }
+}
index fda704b9065d17423a6cda32ea9c0c13d03eadd3..56541d5b60cee9b07404cb927a34cb53aac1f713 100644 (file)
@@ -364,4 +364,23 @@ void i945_miptree_layout(struct intel_mipmap_tree *mt);
 void brw_miptree_layout(struct intel_context *intel,
                        struct intel_mipmap_tree *mt);
 
+void
+intel_miptree_map(struct intel_context *intel,
+                 struct intel_mipmap_tree *mt,
+                 unsigned int level,
+                 unsigned int slice,
+                 unsigned int x,
+                 unsigned int y,
+                 unsigned int w,
+                 unsigned int h,
+                 GLbitfield mode,
+                 void **out_ptr,
+                 int *out_stride);
+
+void
+intel_miptree_unmap(struct intel_context *intel,
+                   struct intel_mipmap_tree *mt,
+                   unsigned int level,
+                   unsigned int slice);
+
 #endif
index 9884a57d0fef720722960c9c1039be449da120e4..2ebd654e1aecb72e3233884927ec554fa704e5e1 100644 (file)
@@ -150,9 +150,6 @@ intel_map_texture_image(struct gl_context *ctx,
    struct intel_context *intel = intel_context(ctx);
    struct intel_texture_image *intel_image = intel_texture_image(tex_image);
    struct intel_mipmap_tree *mt = intel_image->mt;
-   unsigned int bw, bh;
-   void *base;
-   unsigned int image_x, image_y;
 
    /* Our texture data is always stored in a miptree. */
    assert(mt);
@@ -161,41 +158,14 @@ intel_map_texture_image(struct gl_context *ctx,
    assert(tex_image->TexObject->Target != GL_TEXTURE_1D_ARRAY ||
          h == 1);
 
-   if (mt->stencil_mt) {
-      /* The miptree has depthstencil format, but uses separate stencil. The
-       * embedded stencil miptree contains the real stencil data, so gather
-       * that into the depthstencil miptree.
-       *
-       * FIXME: Avoid the gather if the texture is mapped as write-only.
-       */
-      intel_miptree_s8z24_gather(intel, mt, tex_image->Level, slice);
-   }
-
-   intel_miptree_slice_resolve_depth(intel, mt, tex_image->Level, slice);
-   if (mode & GL_MAP_WRITE_BIT) {
-      intel_miptree_slice_set_needs_hiz_resolve(mt, tex_image->Level, slice);
-   }
-
-   /* For compressed formats, the stride is the number of bytes per
-    * row of blocks.  intel_miptree_get_image_offset() already does
-    * the divide.
+   /* intel_miptree_map operates on a unified "slice" number that references the
+    * cube face, since it's all just slices to the miptree code.
     */
-   _mesa_get_format_block_size(tex_image->TexFormat, &bw, &bh);
-   assert(y % bh == 0);
-   y /= bh;
-
-   base = intel_region_map(intel, mt->region, mode);
-   intel_miptree_get_image_offset(mt, tex_image->Level, tex_image->Face,
-                                 slice, &image_x, &image_y);
-   x += image_x;
-   y += image_y;
-
-   *stride = mt->region->pitch * mt->cpp;
-   *map = base + y * *stride + x * mt->cpp;
-
-   DBG("%s: %d,%d %dx%d from mt %p %d,%d = %p/%d\n", __FUNCTION__,
-       x - image_x, y - image_y, w, h,
-       mt, x, y, *map, *stride);
+   if (tex_image->TexObject->Target == GL_TEXTURE_CUBE_MAP)
+      slice = tex_image->Face;
+
+   intel_miptree_map(intel, mt, tex_image->Level, slice, x, y, w, h, mode,
+                    (void **)map, stride);
 }
 
 static void
@@ -206,18 +176,10 @@ intel_unmap_texture_image(struct gl_context *ctx,
    struct intel_texture_image *intel_image = intel_texture_image(tex_image);
    struct intel_mipmap_tree *mt = intel_image->mt;
 
-   intel_region_unmap(intel, intel_image->mt->region);
+   if (tex_image->TexObject->Target == GL_TEXTURE_CUBE_MAP)
+      slice = tex_image->Face;
 
-   if (mt->stencil_mt) {
-      /* The miptree has depthstencil format, but uses separate stencil. The
-       * embedded stencil miptree must contain the real stencil data after
-       * unmapping, so copy it from the depthstencil miptree into the stencil
-       * miptree.
-       *
-       * FIXME: Avoid the scatter if the texture was mapped as read-only.
-       */
-      intel_miptree_s8z24_scatter(intel, mt, tex_image->Level, slice);
-   }
+   intel_miptree_unmap(intel, mt, tex_image->Level, slice);
 }
 
 void