intel: Add implementation of MapTextureImage/UnmapTextureImage.
authorEric Anholt <eric@anholt.net>
Fri, 29 Jul 2011 21:35:01 +0000 (14:35 -0700)
committerEric Anholt <eric@anholt.net>
Mon, 29 Aug 2011 17:10:03 +0000 (10:10 -0700)
Reviewed-by: Brian Paul <brianp@vmware.com>
src/mesa/drivers/dri/intel/intel_tex.c
src/mesa/drivers/dri/intel/intel_tex.h
src/mesa/drivers/dri/intel/intel_tex_image.c

index 1c607246cd6716b912f868fa292dcb98f81e6c7e..4faa01a8627ff6c2280efa3ba05ae766f379484b 100644 (file)
@@ -71,6 +71,88 @@ intel_free_texture_image_buffer(struct gl_context * ctx,
    }
 }
 
+/**
+ * Map texture memory/buffer into user space.
+ * Note: the region of interest parameters are ignored here.
+ * \param mapOut  returns start of mapping of region of interest
+ * \param rowStrideOut  returns row stride in bytes
+ */
+static void
+intel_map_texture_image(struct gl_context *ctx,
+                       struct gl_texture_image *tex_image,
+                       GLuint slice,
+                       GLuint x, GLuint y, GLuint w, GLuint h,
+                       GLbitfield mode,
+                       GLubyte **map,
+                       GLint *stride)
+{
+   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;
+
+   if (intel_image->stencil_rb) {
+      /*
+       * The texture has packed depth/stencil format, but uses separate
+       * stencil. The texture's embedded stencil buffer contains the real
+       * stencil data, so copy that into the miptree.
+       */
+      intel_tex_image_s8z24_gather(intel, intel_image);
+   }
+
+   /* 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;
+
+   if (likely(mt)) {
+      void *base = intel_region_map(intel, mt->region);
+      unsigned int image_x, image_y;
+
+      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;
+   } else {
+      /* texture data is in malloc'd memory */
+      GLuint width = tex_image->Width;
+      GLuint height = ALIGN(tex_image->Height, bh) / bh;
+      GLuint texelSize = _mesa_get_format_bytes(tex_image->TexFormat);
+
+      assert(map);
+
+      *stride = _mesa_format_row_stride(tex_image->TexFormat, width);
+      *map = tex_image->Data + (slice * height + y) * *stride + x * texelSize;
+
+      return;
+   }
+}
+
+static void
+intel_unmap_texture_image(struct gl_context *ctx,
+                         struct gl_texture_image *tex_image, GLuint slice)
+{
+   struct intel_context *intel = intel_context(ctx);
+   struct intel_texture_image *intel_image = intel_texture_image(tex_image);
+
+   intel_region_unmap(intel, intel_image->mt->region);
+
+   if (intel_image->stencil_rb) {
+      /*
+       * The texture has packed depth/stencil format, but uses separate
+       * stencil. The texture's embedded stencil buffer contains the real
+       * stencil data, so copy that into the miptree.
+       */
+      intel_tex_image_s8z24_scatter(intel, intel_image);
+   }
+}
+
 /**
  * Called via ctx->Driver.GenerateMipmap()
  * This is basically a wrapper for _mesa_meta_GenerateMipmap() which checks
@@ -125,4 +207,6 @@ intelInitTextureFuncs(struct dd_function_table *functions)
    functions->NewTextureImage = intelNewTextureImage;
    functions->DeleteTexture = intelDeleteTextureObject;
    functions->FreeTextureImageBuffer = intel_free_texture_image_buffer;
+   functions->MapTextureImage = intel_map_texture_image;
+   functions->UnmapTextureImage = intel_unmap_texture_image;
 }
index 52462f39d54893252b967e83818bf336b9b60450..1eaa3cc9167ef7fa813a5f196fec8b6033d1270c 100644 (file)
@@ -63,6 +63,12 @@ void intel_tex_map_images(struct intel_context *intel,
 void intel_tex_unmap_images(struct intel_context *intel,
                             struct intel_texture_object *intelObj);
 
+void intel_tex_image_s8z24_scatter(struct intel_context *intel,
+                                  struct intel_texture_image *intel_image);
+
+void intel_tex_image_s8z24_gather(struct intel_context *intel,
+                                 struct intel_texture_image *intel_image);
+
 int intel_compressed_num_bytes(GLuint mesaFormat);
 
 GLboolean intel_copy_texsubimage(struct intel_context *intel,
index 4149f4510ef9c4ebcde4a53ab62efc2a72ede44f..29a6d3be2a6d1fbfaa043b95741cc3c6167b09a8 100644 (file)
@@ -312,7 +312,7 @@ intel_tex_image_s8z24_scattergather(struct intel_context *intel,
 /**
  * Copy the x8 bits from intel_image->depth_rb to intel_image->stencil_rb.
  */
-static void
+void
 intel_tex_image_s8z24_scatter(struct intel_context *intel,
                              struct intel_texture_image *intel_image)
 {
@@ -323,7 +323,7 @@ intel_tex_image_s8z24_scatter(struct intel_context *intel,
  * Copy the data in intel_image->stencil_rb to the x8 bits in
  * intel_image->depth_rb.
  */
-static void
+void
 intel_tex_image_s8z24_gather(struct intel_context *intel,
                             struct intel_texture_image *intel_image)
 {