intel: Add a helper function for getting miptree size from a texture image.

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.
This commit is contained in:
Eric Anholt
2011-09-29 11:30:18 -07:00
parent 2e0aefc1b9
commit fd99cd0e10
8 changed files with 80 additions and 35 deletions

View 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);

View 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? */

View 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;

View 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);

View 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;

View 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,

View 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);

View 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;