intel: pass zslice to intel_miptree_image_offset()
authorBrian Paul <brianp@vmware.com>
Mon, 12 Oct 2009 23:37:06 +0000 (17:37 -0600)
committerBrian Paul <brianp@vmware.com>
Tue, 13 Oct 2009 00:12:00 +0000 (18:12 -0600)
This lets us get rid of intel_miptree_depth_offsets() and simplify all
of the calling code.

src/mesa/drivers/dri/i915/i830_texstate.c
src/mesa/drivers/dri/i915/i915_texstate.c
src/mesa/drivers/dri/intel/intel_fbo.c
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_copy.c
src/mesa/drivers/dri/intel/intel_tex_image.c

index 6f998fa6f773826eae70dcba0f9f476370cb72e4..f270a1378126fb7fc405e93f702c9573a5d26577 100644 (file)
@@ -162,9 +162,8 @@ i830_update_tex_unit(struct intel_context *intel, GLuint unit, GLuint ss3)
    } else {
       dri_bo_reference(intelObj->mt->region->buffer);
       i830->state.tex_buffer[unit] = intelObj->mt->region->buffer;
-      i830->state.tex_offset[unit] = intel_miptree_image_offset(intelObj->mt,
-                                                               0, intelObj->
-                                                               firstLevel);
+      i830->state.tex_offset[unit] =
+         intel_miptree_image_offset(intelObj->mt, 0, intelObj->firstLevel, 0);
 
       format = translate_texture_format(firstImage->TexFormat->MesaFormat,
                                        firstImage->InternalFormat);
index 32d4b30cf9a610ea02bb1e7f96790ab60c30f399..b2f82f5655110cb55ce71d2faec5bfdbbc5fecad 100644 (file)
@@ -173,9 +173,8 @@ i915_update_tex_unit(struct intel_context *intel, GLuint unit, GLuint ss3)
    } else {
       dri_bo_reference(intelObj->mt->region->buffer);
       i915->state.tex_buffer[unit] = intelObj->mt->region->buffer;
-      i915->state.tex_offset[unit] =  intel_miptree_image_offset(intelObj->mt,
-                                                                0, intelObj->
-                                                                firstLevel);
+      i915->state.tex_offset[unit] =
+         intel_miptree_image_offset(intelObj->mt, 0, intelObj->firstLevel, 0);
 
       format = translate_texture_format(firstImage->TexFormat->MesaFormat, 
                                        firstImage->InternalFormat,
index 8dfb24290d5c2323818f56c81c088f9c3db86e3d..2e613718051b3f21c2c2a64321fa194e9337ab6d 100644 (file)
@@ -618,15 +618,8 @@ intel_render_texture(GLcontext * ctx,
    }
 
    /* compute offset of the particular 2D image within the texture region */
-   imageOffset = intel_miptree_image_offset(intel_image->mt,
-                                            att->CubeMapFace,
-                                            att->TextureLevel);
-
-   if (att->Texture->Target == GL_TEXTURE_3D) {
-      const GLuint *offsets = intel_miptree_depth_offsets(intel_image->mt,
-                                                          att->TextureLevel);
-      imageOffset += offsets[att->Zoffset];
-   }
+   imageOffset = intel_miptree_image_offset(intel_image->mt, att->CubeMapFace,
+                                            att->TextureLevel, att->Zoffset);
 
    /* store that offset in the region */
    intel_image->mt->region->draw_offset = imageOffset;
index 4f5101a312870ff7df302238d0feca45a8035d88..d9d2edfe190ee218eb7c0971017f3987a0d08f5b 100644 (file)
@@ -395,33 +395,26 @@ intel_miptree_set_image_offset(struct intel_mipmap_tree *mt,
 }
 
 
-/* Although we use the image_offset[] array to store relative offsets
- * to cube faces, Mesa doesn't know anything about this and expects
- * each cube face to be treated as a separate image.
- *
- * These functions present that view to mesa:
+/**
+ * Return offset to the start of a 2D slice of a texture (a mipmap level,
+ * cube face, 3D Z slice).
+ * \param mt  the texture object/miptree
+ * \param face  cube map face in [0,5] or zero for non-cube textures
+ * \param level  mipmap level
+ * \param zslice  Z slice of a 3D texture, or zero for non-3D textures
  */
-const GLuint *
-intel_miptree_depth_offsets(struct intel_mipmap_tree *mt, GLuint level)
-{
-   static const GLuint zero = 0;
-
-   if (mt->target != GL_TEXTURE_3D || mt->level[level].nr_images == 1)
-      return &zero;
-   else
-      return mt->level[level].image_offset;
-}
-
-
 GLuint
-intel_miptree_image_offset(struct intel_mipmap_tree *mt,
-                          GLuint face, GLuint level)
+intel_miptree_image_offset(const struct intel_mipmap_tree *mt,
+                           GLuint face, GLuint level, GLuint zslice)
 {
+   GLuint offset = mt->level[level].level_offset;
+
    if (mt->target == GL_TEXTURE_CUBE_MAP_ARB)
-      return (mt->level[level].level_offset +
-             mt->level[level].image_offset[face]);
-   else
-      return mt->level[level].level_offset;
+      offset += mt->level[level].image_offset[face];
+   else if (mt->target == GL_TEXTURE_3D)
+      offset += mt->level[level].image_offset[zslice];
+
+   return offset;
 }
 
 
@@ -459,7 +452,7 @@ intel_miptree_image_map(struct intel_context * intel,
    }
 
    return (intel_region_map(intel, mt->region) +
-           intel_miptree_image_offset(mt, face, level));
+           intel_miptree_image_offset(mt, face, level, 0));
 }
 
 void
@@ -484,19 +477,18 @@ intel_miptree_image_data(struct intel_context *intel,
                         GLuint src_image_pitch)
 {
    GLuint depth = dst->level[level].depth;
-   GLuint dst_offset = intel_miptree_image_offset(dst, face, level);
-   const GLuint *dst_depth_offset = intel_miptree_depth_offsets(dst, level);
    GLuint i;
    GLuint height = 0;
 
    DBG("%s: %d/%d\n", __FUNCTION__, face, level);
    for (i = 0; i < depth; i++) {
+      GLuint dst_offset = intel_miptree_image_offset(dst, face, level, i);
       height = dst->level[level].height;
       if(dst->compressed)
         height = (height + 3) / 4;
       intel_region_data(intel,
                        dst->region,
-                       dst_offset + dst_depth_offset[i], /* dst_offset */
+                       dst_offset,
                        0, 0,                             /* dstx, dsty */
                        src,
                        src_row_pitch,
@@ -519,10 +511,6 @@ intel_miptree_image_copy(struct intel_context *intel,
    GLuint width = src->level[level].width;
    GLuint height = src->level[level].height;
    GLuint depth = src->level[level].depth;
-   GLuint dst_offset = intel_miptree_image_offset(dst, face, level);
-   GLuint src_offset = intel_miptree_image_offset(src, face, level);
-   const GLuint *dst_depth_offset = intel_miptree_depth_offsets(dst, level);
-   const GLuint *src_depth_offset = intel_miptree_depth_offsets(src, level);
    GLuint i;
    GLboolean success;
 
@@ -535,10 +523,13 @@ intel_miptree_image_copy(struct intel_context *intel,
    }
 
    for (i = 0; i < depth; i++) {
+      GLuint dst_offset = intel_miptree_image_offset(dst, face, level, i);
+      GLuint src_offset = intel_miptree_image_offset(src, face, level, i);
+
       success = intel_region_copy(intel,
-                                 dst->region, dst_offset + dst_depth_offset[i],
+                                 dst->region, dst_offset,
                                  0, 0,
-                                 src->region, src_offset + src_depth_offset[i],
+                                 src->region, src_offset,
                                  0, 0, width, height, GL_COPY);
       if (!success) {
         GLubyte *src_ptr, *dst_ptr;
@@ -546,11 +537,11 @@ intel_miptree_image_copy(struct intel_context *intel,
         src_ptr = intel_region_map(intel, src->region);
         dst_ptr = intel_region_map(intel, dst->region);
 
-        _mesa_copy_rect(dst_ptr + dst_offset + dst_depth_offset[i],
+        _mesa_copy_rect(dst_ptr + dst_offset,
                         dst->cpp,
                         dst->pitch,
                         0, 0, width, height,
-                        src_ptr + src_offset + src_depth_offset[i],
+                        src_ptr + src_offset,
                         src->pitch,
                         0, 0);
         intel_region_unmap(intel, src->region);
index c890b2a0d047488747dc2db7aaaaa36a02da5ec8..c08f9cd8b66c81f7d311211340c65ad6b1c79a1f 100644 (file)
@@ -177,17 +177,9 @@ void intel_miptree_image_unmap(struct intel_context *intel,
                                struct intel_mipmap_tree *mt);
 
 
-/* Return the linear offset of an image relative to the start of the
- * tree:
- */
-GLuint intel_miptree_image_offset(struct intel_mipmap_tree *mt,
-                                  GLuint face, GLuint level);
-
-/* Return pointers to each 2d slice within an image.  Indexed by depth
- * value.
- */
-const GLuint *intel_miptree_depth_offsets(struct intel_mipmap_tree *mt,
-                                          GLuint level);
+GLuint
+intel_miptree_image_offset(const struct intel_mipmap_tree *mt,
+                           GLuint face, GLuint level, GLuint zslice);
 
 
 void intel_miptree_set_level_info(struct intel_mipmap_tree *mt,
index f3e312420dde31127f2984c9b4e8380f33b1bb03..99cd818417d8149394ddc10e5f1893736ce72b90 100644 (file)
@@ -117,7 +117,7 @@ do_copy_texsubimage(struct intel_context *intel,
                                                 INTEL_WRITE_PART);
       GLuint image_offset = intel_miptree_image_offset(intelImage->mt,
                                                        intelImage->face,
-                                                       intelImage->level);
+                                                       intelImage->level, 0);
       const GLint orig_x = x;
       const GLint orig_y = y;
       GLshort src_pitch;
index 5c915178e756b538044f88f414a88e9bcb105a0e..dcc613449f01a1e8c35da1ad332d52c53a4a9055 100644 (file)
@@ -222,7 +222,8 @@ try_pbo_upload(struct intel_context *intel,
 
    dst_offset = intel_miptree_image_offset(intelImage->mt,
                                            intelImage->face,
-                                           intelImage->level);
+                                           intelImage->level,
+                                           0 /* zslice */);
 
    dst_stride = intelImage->mt->pitch;
 
@@ -281,8 +282,8 @@ try_pbo_zcopy(struct intel_context *intel,
 
    dst_offset = intel_miptree_image_offset(intelImage->mt,
                                            intelImage->face,
-                                           intelImage->level);
-
+                                           intelImage->level,
+                                           0 /* zslice */);
    dst_stride = intelImage->mt->pitch;
 
    if (src_stride != dst_stride || dst_offset != 0 || src_offset != 0) {