intel: Add a helper function for getting miptree size from a texture image.
authorEric Anholt <eric@anholt.net>
Thu, 29 Sep 2011 18:30:18 +0000 (11:30 -0700)
committerEric Anholt <eric@anholt.net>
Mon, 3 Oct 2011 20:29:38 +0000 (13:29 -0700)
With 1D array textures, we no longer agree between the GL information
about width/height/depth of a texture and how we lay out a miptree.

src/mesa/drivers/dri/i965/brw_wm_surface_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_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_image.c
src/mesa/drivers/dri/intel/intel_tex_validate.c

index aae1eed83f20492d8c81ac9b87097c22f85d51d0..452ee4e7926e8f648dd2025803203253b1b05a38 100644 (file)
@@ -231,6 +231,9 @@ brw_update_texture_surface( struct gl_context *ctx, GLuint unit )
    struct gl_sampler_object *sampler = _mesa_get_samplerobj(ctx, unit);
    const GLuint surf_index = SURF_INDEX_TEXTURE(unit);
    uint32_t *surf;
+   int width, height, depth;
+
+   intel_miptree_get_dimensions_for_image(firstImage, &width, &height, &depth);
 
    surf = brw_state_batch(brw, AUB_TRACE_SURFACE_STATE,
                          6 * 4, 32, &brw->wm.surf_offset[surf_index]);
@@ -247,11 +250,11 @@ brw_update_texture_surface( struct gl_context *ctx, GLuint unit )
    surf[1] = intelObj->mt->region->bo->offset; /* reloc */
 
    surf[2] = ((intelObj->_MaxLevel - tObj->BaseLevel) << BRW_SURFACE_LOD_SHIFT |
-             (firstImage->Width - 1) << BRW_SURFACE_WIDTH_SHIFT |
-             (firstImage->Height - 1) << BRW_SURFACE_HEIGHT_SHIFT);
+             (width - 1) << BRW_SURFACE_WIDTH_SHIFT |
+             (height - 1) << BRW_SURFACE_HEIGHT_SHIFT);
 
    surf[3] = (brw_get_surface_tiling_bits(intelObj->mt->region->tiling) |
-             (firstImage->Depth - 1) << BRW_SURFACE_DEPTH_SHIFT |
+             (depth - 1) << BRW_SURFACE_DEPTH_SHIFT |
              ((intelObj->mt->region->pitch * intelObj->mt->cpp) - 1) <<
              BRW_SURFACE_PITCH_SHIFT);
 
index b148c53deead9b34d3380393617cc72e95809a32..50a3385dcb3f36207b1771c97746187268d2283f 100644 (file)
@@ -64,6 +64,9 @@ gen7_update_texture_surface(struct gl_context *ctx, GLuint unit)
    struct gl_sampler_object *sampler = _mesa_get_samplerobj(ctx, unit);
    const GLuint surf_index = SURF_INDEX_TEXTURE(unit);
    struct gen7_surface_state *surf;
+   int width, height, depth;
+
+   intel_miptree_get_dimensions_for_image(firstImage, &width, &height, &depth);
 
    surf = brw_state_batch(brw, AUB_TRACE_SURFACE_STATE,
                          sizeof(*surf), 32, &brw->wm.surf_offset[surf_index]);
@@ -97,11 +100,11 @@ gen7_update_texture_surface(struct gl_context *ctx, GLuint unit)
 
    surf->ss1.base_addr = intelObj->mt->region->bo->offset; /* reloc */
 
-   surf->ss2.width = firstImage->Width - 1;
-   surf->ss2.height = firstImage->Height - 1;
+   surf->ss2.width = width - 1;
+   surf->ss2.height = height - 1;
 
    surf->ss3.pitch = (intelObj->mt->region->pitch * intelObj->mt->cpp) - 1;
-   surf->ss3.depth = firstImage->Depth - 1;
+   surf->ss3.depth = depth - 1;
 
    /* ss4: ignored? */
 
index f0401b7aa0c7147f13d6a55941d6f762fb84410a..166da2a090060d0be86c43f9d6c4ea59ba06624f 100644 (file)
@@ -525,8 +525,13 @@ intel_set_teximage_alpha_to_one(struct gl_context *ctx,
    int pitch, cpp;
    drm_intel_bo *aper_array[2];
    struct intel_region *region = intel_image->mt->region;
+   int width, height, depth;
    BATCH_LOCALS;
 
+   intel_miptree_get_dimensions_for_image(&intel_image->base.Base,
+                                          &width, &height, &depth);
+   assert(depth == 1);
+
    assert(intel_image->base.Base.TexFormat == MESA_FORMAT_ARGB8888);
 
    /* get dest x/y in destination texture */
@@ -538,8 +543,8 @@ intel_set_teximage_alpha_to_one(struct gl_context *ctx,
 
    x1 = image_x;
    y1 = image_y;
-   x2 = image_x + intel_image->base.Base.Width;
-   y2 = image_y + intel_image->base.Base.Height;
+   x2 = image_x + width;
+   y2 = image_y + height;
 
    pitch = region->pitch;
    cpp = region->cpp;
index d87dabb3606e5ce3a5e12c69f7c526ae94b1d3b9..3a503a73155bbd12db4846de3a5dca18ccd73901 100644 (file)
@@ -483,6 +483,7 @@ intel_update_wrapper(struct gl_context *ctx, struct intel_renderbuffer *irb,
 {
    struct intel_context *intel = intel_context(ctx);
    struct intel_texture_image *intel_image = intel_texture_image(texImage);
+   int width, height, depth;
 
    if (!intel_span_supports_format(texImage->TexFormat)) {
       DBG("Render to texture BAD FORMAT %s\n",
@@ -492,12 +493,14 @@ intel_update_wrapper(struct gl_context *ctx, struct intel_renderbuffer *irb,
       DBG("Render to texture %s\n", _mesa_get_format_name(texImage->TexFormat));
    }
 
+   intel_miptree_get_dimensions_for_image(texImage, &width, &height, &depth);
+
    irb->Base.Format = texImage->TexFormat;
    irb->Base.DataType = intel_mesa_format_to_rb_datatype(texImage->TexFormat);
    irb->Base.InternalFormat = texImage->InternalFormat;
    irb->Base._BaseFormat = _mesa_base_tex_format(ctx, irb->Base.InternalFormat);
-   irb->Base.Width = texImage->Width;
-   irb->Base.Height = texImage->Height;
+   irb->Base.Width = width;
+   irb->Base.Height = height;
 
    irb->Base.Delete = intel_delete_renderbuffer;
    irb->Base.AllocStorage = intel_nop_alloc_storage;
@@ -730,14 +733,15 @@ intel_render_texture(struct gl_context * ctx,
        */
       struct intel_context *intel = intel_context(ctx);
       struct intel_mipmap_tree *new_mt;
+      int width, height, depth;
+
+      intel_miptree_get_dimensions_for_image(image, &width, &height, &depth);
 
       new_mt = intel_miptree_create(intel, image->TexObject->Target,
                                    intel_image->base.Base.TexFormat,
                                    intel_image->base.Base.Level,
                                    intel_image->base.Base.Level,
-                                   intel_image->base.Base.Width,
-                                   intel_image->base.Base.Height,
-                                   intel_image->base.Base.Depth,
+                                    width, height, depth,
                                    GL_TRUE);
 
       intel_miptree_copy_teximage(intel, intel_image, new_mt);
index 553a21e817c8c7ffbca7d0e71b0d279ca767dbf7..683dfb9a045ae1616bceaf62e01530754369a2d3 100644 (file)
@@ -214,6 +214,23 @@ intel_miptree_release(struct intel_mipmap_tree **mt)
    *mt = NULL;
 }
 
+void
+intel_miptree_get_dimensions_for_image(struct gl_texture_image *image,
+                                       int *width, int *height, int *depth)
+{
+   switch (image->TexObject->Target) {
+   case GL_TEXTURE_1D_ARRAY:
+      *width = image->Width;
+      *height = 1;
+      *depth = image->Height;
+      break;
+   default:
+      *width = image->Width;
+      *height = image->Height;
+      *depth = image->Depth;
+      break;
+   }
+}
 
 /**
  * Can the image be pulled into a unified mipmap tree?  This mirrors
@@ -227,6 +244,7 @@ intel_miptree_match_image(struct intel_mipmap_tree *mt,
 {
    struct intel_texture_image *intelImage = intel_texture_image(image);
    GLuint level = intelImage->base.Base.Level;
+   int width, height, depth;
 
    /* Images with borders are never pulled into mipmap trees. */
    if (image->Border)
@@ -235,13 +253,15 @@ intel_miptree_match_image(struct intel_mipmap_tree *mt,
    if (image->TexFormat != mt->format)
       return GL_FALSE;
 
+   intel_miptree_get_dimensions_for_image(image, &width, &height, &depth);
+
    /* Test image dimensions against the base level image adjusted for
     * minification.  This will also catch images not present in the
     * tree, changed targets, etc.
     */
-   if (image->Width != mt->level[level].width ||
-       image->Height != mt->level[level].height ||
-       image->Depth != mt->level[level].depth)
+   if (width != mt->level[level].width ||
+       height != mt->level[level].height ||
+       depth != mt->level[level].depth)
       return GL_FALSE;
 
    return GL_TRUE;
index 7c0a3e3caadc7651cfb98d4a7967b6c41156203c..22295aae3b8ba76a0dd510e13fc538acc5cc0a1c 100644 (file)
@@ -171,6 +171,10 @@ intel_miptree_get_image_offset(struct intel_mipmap_tree *mt,
                               GLuint level, GLuint face, GLuint depth,
                               GLuint *x, GLuint *y);
 
+void
+intel_miptree_get_dimensions_for_image(struct gl_texture_image *image,
+                                       int *width, int *height, int *depth);
+
 void intel_miptree_set_level_info(struct intel_mipmap_tree *mt,
                                   GLuint level,
                                   GLuint nr_images,
index 706ec3e37a92a97f209ff442a0605af80d379276..6c6e8a7ae4322aca6bfa7a64dc14a64e9fef8cf0 100644 (file)
@@ -53,22 +53,21 @@ intel_miptree_create_for_teximage(struct intel_context *intel,
 {
    GLuint firstLevel;
    GLuint lastLevel;
-   GLuint width = intelImage->base.Base.Width;
-   GLuint height = intelImage->base.Base.Height;
-   GLuint depth = intelImage->base.Base.Depth;
+   int width, height, depth;
    GLuint i;
 
+   intel_miptree_get_dimensions_for_image(&intelImage->base.Base,
+                                          &width, &height, &depth);
+
    DBG("%s\n", __FUNCTION__);
 
    if (intelImage->base.Base.Border)
       return NULL;
 
    if (intelImage->base.Base.Level > intelObj->base.BaseLevel &&
-       (intelImage->base.Base.Width == 1 ||
-        (intelObj->base.Target != GL_TEXTURE_1D &&
-         intelImage->base.Base.Height == 1) ||
-        (intelObj->base.Target == GL_TEXTURE_3D &&
-         intelImage->base.Base.Depth == 1))) {
+       (width == 1 ||
+        (intelObj->base.Target != GL_TEXTURE_1D && height == 1) ||
+        (intelObj->base.Target == GL_TEXTURE_3D && depth == 1))) {
       /* For this combination, we're at some lower mipmap level and
        * some important dimension is 1.  We can't extrapolate up to a
        * likely base level width/height/depth for a full mipmap stack
@@ -231,9 +230,10 @@ intel_tex_image_s8z24_scattergather(struct intel_context *intel,
    struct gl_context *ctx = &intel->ctx;
    struct gl_renderbuffer *depth_rb = intel_image->depth_rb;
    struct gl_renderbuffer *stencil_rb = intel_image->stencil_rb;
+   int w, h, d;
 
-   int w = intel_image->base.Base.Width;
-   int h = intel_image->base.Base.Height;
+   intel_miptree_get_dimensions_for_image(&intel_image->base.Base, &w, &h, &d);
+   assert(d == 1); /* FINISHME */
 
    uint32_t depth_row[w];
    uint8_t stencil_row[w];
@@ -292,15 +292,17 @@ intel_tex_image_s8z24_create_renderbuffers(struct intel_context *intel,
                                           struct intel_texture_image *image)
 {
    struct gl_context *ctx = &intel->ctx;
-
    bool ok = true;
-   int width = image->base.Base.Width;
-   int height = image->base.Base.Height;
+   int width, height, depth;
    struct gl_renderbuffer *drb;
    struct gl_renderbuffer *srb;
    struct intel_renderbuffer *idrb;
    struct intel_renderbuffer *isrb;
 
+   intel_miptree_get_dimensions_for_image(&image->base.Base,
+                                          &width, &height, &depth);
+   assert(depth == 1); /* FINISHME */
+
    assert(intel->has_separate_stencil);
    assert(image->base.Base.TexFormat == MESA_FORMAT_S8_Z24);
    assert(image->mt != NULL);
index a2299ee14d1c0486f0bbbf57cb90b3f39547c2d2..c06279ce25ea68b9f0ff23f93481b4d27731e479 100644 (file)
@@ -41,6 +41,7 @@ intel_finalize_mipmap_tree(struct intel_context *intel, GLuint unit)
    GLuint face, i;
    GLuint nr_faces = 0;
    struct intel_texture_image *firstImage;
+   int width, height, depth;
 
    /* We know/require this is true by now: 
     */
@@ -58,6 +59,9 @@ intel_finalize_mipmap_tree(struct intel_context *intel, GLuint unit)
       return GL_FALSE;
    }
 
+   intel_miptree_get_dimensions_for_image(&firstImage->base.Base,
+                                          &width, &height, &depth);
+
    /* Check tree can hold all active levels.  Check tree matches
     * target, imageFormat, etc.
     *
@@ -71,9 +75,9 @@ intel_finalize_mipmap_tree(struct intel_context *intel, GLuint unit)
        intelObj->mt->format != firstImage->base.Base.TexFormat ||
        intelObj->mt->first_level != tObj->BaseLevel ||
        intelObj->mt->last_level < intelObj->_MaxLevel ||
-       intelObj->mt->width0 != firstImage->base.Base.Width ||
-       intelObj->mt->height0 != firstImage->base.Base.Height ||
-       intelObj->mt->depth0 != firstImage->base.Base.Depth)) {
+       intelObj->mt->width0 != width ||
+       intelObj->mt->height0 != height ||
+       intelObj->mt->depth0 != depth)) {
       intel_miptree_release(&intelObj->mt);
    }
 
@@ -86,9 +90,9 @@ intel_finalize_mipmap_tree(struct intel_context *intel, GLuint unit)
                                          firstImage->base.Base.TexFormat,
                                           tObj->BaseLevel,
                                           intelObj->_MaxLevel,
-                                          firstImage->base.Base.Width,
-                                          firstImage->base.Base.Height,
-                                          firstImage->base.Base.Depth,
+                                          width,
+                                          height,
+                                          depth,
                                          GL_TRUE);
       if (!intelObj->mt)
          return GL_FALSE;