From: Eric Anholt Date: Mon, 28 Nov 2011 23:49:01 +0000 (-0800) Subject: intel: Move the gtt-particular texture mapping logic to a helper function. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=baeaa062e92afbec47fad73fd3d464a1e7d1fe08;p=mesa.git intel: Move the gtt-particular texture mapping logic to a helper function. This code will be incrementally moving to a model like intel_fbo.c's renderbuffer mapping with helper functions, as I move that code here. Reviewed-by: Chad Versace --- diff --git a/src/mesa/drivers/dri/intel/intel_mipmap_tree.c b/src/mesa/drivers/dri/intel/intel_mipmap_tree.c index f7228d8cfd0..8f2a433e75a 100644 --- a/src/mesa/drivers/dri/intel/intel_mipmap_tree.c +++ b/src/mesa/drivers/dri/intel/intel_mipmap_tree.c @@ -733,38 +733,17 @@ intel_miptree_all_slices_resolve_depth(struct intel_context *intel, 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) +static void +intel_miptree_map_gtt(struct intel_context *intel, + struct intel_mipmap_tree *mt, + struct intel_miptree_map *map, + unsigned int level, unsigned int slice) { - struct intel_miptree_map *map; unsigned int bw, bh; void *base; unsigned int image_x, image_y; - - map = calloc(1, sizeof(struct intel_miptree_map)); - if (!map){ - *out_ptr = NULL; - *out_stride = 0; - return; - } - - assert(!mt->level[level].slice[slice].map); - mt->level[level].slice[slice].map = map; - map->mode = mode; - map->x = x; - map->y = y; - map->w = w; - map->h = h; + int x = map->x; + int y = map->y; if (mt->stencil_mt) { /* The miptree has depthstencil format, but uses separate stencil. The @@ -776,11 +755,6 @@ intel_miptree_map(struct intel_context *intel, 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. @@ -789,7 +763,7 @@ intel_miptree_map(struct intel_context *intel, assert(y % bh == 0); y /= bh; - base = intel_region_map(intel, mt->region, mode); + base = intel_region_map(intel, mt->region, map->mode); /* Note that in the case of cube maps, the caller must have passed the slice * number referencing the face. */ @@ -800,15 +774,74 @@ intel_miptree_map(struct intel_context *intel, map->stride = mt->region->pitch * mt->cpp; map->ptr = base + y * map->stride + x * mt->cpp; - *out_ptr = map->ptr; - *out_stride = map->stride; - DBG("%s: %d,%d %dx%d from mt %p (%s) %d,%d = %p/%d\n", __FUNCTION__, map->x, map->y, map->w, map->h, mt, _mesa_get_format_name(mt->format), x, y, map->ptr, map->stride); } +static void +intel_miptree_unmap_gtt(struct intel_context *intel, + struct intel_mipmap_tree *mt, + struct intel_miptree_map *map, + unsigned int level, + unsigned int 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); + } +} + +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) +{ + struct intel_miptree_map *map; + + map = calloc(1, sizeof(struct intel_miptree_map)); + if (!map){ + *out_ptr = NULL; + *out_stride = 0; + return; + } + + assert(!mt->level[level].slice[slice].map); + mt->level[level].slice[slice].map = map; + map->mode = mode; + map->x = x; + map->y = y; + map->w = w; + map->h = h; + + intel_miptree_slice_resolve_depth(intel, mt, level, slice); + if (map->mode & GL_MAP_WRITE_BIT) { + intel_miptree_slice_set_needs_hiz_resolve(mt, level, slice); + } + + intel_miptree_map_gtt(intel, mt, map, level, slice); + + *out_ptr = map->ptr; + *out_stride = map->stride; +} + void intel_miptree_unmap(struct intel_context *intel, struct intel_mipmap_tree *mt, @@ -823,18 +856,7 @@ intel_miptree_unmap(struct intel_context *intel, 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); - } + intel_miptree_unmap_gtt(intel, mt, map, level, slice); mt->level[level].slice[slice].map = NULL; free(map);