[Mesa-dev] [PATCH 07/17] swrast: Replace ImageOffsets with an ImageSlices pointer.
Brian Paul
brianp at vmware.com
Tue Apr 30 07:07:49 PDT 2013
On 04/22/2013 10:14 AM, Eric Anholt wrote:
> This is a step toward allowing drivers to use their normal mapping paths,
> instead of requiring that all slice mappings come from an aligned offset
> from the first slice's map.
>
> This incidentally fixes missing slice handling in FXT1 swrast.
> ---
> src/mesa/drivers/dri/intel/intel_tex_validate.c | 37 ++++--------
> src/mesa/drivers/dri/radeon/radeon_texture.c | 13 ++---
> src/mesa/main/texcompress.c | 2 +-
> src/mesa/main/texcompress.h | 3 +-
> src/mesa/main/texcompress_etc.c | 51 +++++++----------
> src/mesa/main/texcompress_fxt1.c | 8 +--
> src/mesa/main/texcompress_rgtc.c | 70 +++++++++--------------
> src/mesa/main/texcompress_s3tc.c | 56 ++++++++----------
> src/mesa/swrast/s_context.h | 2 +-
> src/mesa/swrast/s_texfetch.c | 5 +-
> src/mesa/swrast/s_texfetch_tmp.h | 4 +-
> src/mesa/swrast/s_texrender.c | 14 +----
> src/mesa/swrast/s_texture.c | 54 +++++++++--------
> 13 files changed, 127 insertions(+), 192 deletions(-)
>
> diff --git a/src/mesa/drivers/dri/intel/intel_tex_validate.c b/src/mesa/drivers/dri/intel/intel_tex_validate.c
> index c880bce..6068733 100644
> --- a/src/mesa/drivers/dri/intel/intel_tex_validate.c
> +++ b/src/mesa/drivers/dri/intel/intel_tex_validate.c
> @@ -163,34 +163,19 @@ intel_tex_map_image_for_swrast(struct intel_context *intel,
> for (int i = 0; i< mt->level[level].depth; i++)
> intel_miptree_slice_resolve_depth(intel, mt, level, i);
>
> - if (mt->target == GL_TEXTURE_3D ||
> - mt->target == GL_TEXTURE_2D_ARRAY ||
> - mt->target == GL_TEXTURE_1D_ARRAY) {
> - int i;
> -
> - /* ImageOffsets[] is only used for swrast's fetch_texel_3d, so we can't
> - * share code with the normal path.
> - */
> - for (i = 0; i< mt->level[level].depth; i++) {
> - intel_miptree_get_image_offset(mt, level, i,&x,&y);
> - intel_image->base.ImageOffsets[i] = x + y * (mt->region->pitch /
> - mt->region->cpp);
> - }
> -
> - DBG("%s \n", __FUNCTION__);
> -
> - intel_image->base.Map = intel_miptree_map_raw(intel, mt);
> - } else {
> - assert(intel_image->base.Base.Depth == 1);
> - intel_miptree_get_image_offset(mt, level, face,&x,&y);
> -
> - DBG("%s: (%d,%d) -> (%d, %d)/%d\n",
> - __FUNCTION__, face, level, x, y, mt->region->pitch);
> -
> - intel_image->base.Map = intel_miptree_map_raw(intel, mt) +
> - x * mt->cpp + y * mt->region->pitch;
> + void *map = intel_miptree_map_raw(intel, mt);
> +
> + for (int i = 0; i< mt->level[level].depth; i++) {
> + intel_miptree_get_image_offset(mt, level, i,&x,&y);
> + intel_image->base.ImageSlices[i] = (map +
> + y * mt->region->pitch +
> + x * mt->cpp);
> + DBG("%s: (%d,%d,%d) -> (%d, %d)/%d\n",
> + __FUNCTION__, face, level, i, x, y, mt->region->pitch);
> }
>
> + intel_image->base.Map = intel_image->base.ImageSlices[0];
> +
> assert(mt->region->pitch % mt->region->cpp == 0);
> intel_image->base.RowStride = mt->region->pitch / mt->region->cpp;
> }
> diff --git a/src/mesa/drivers/dri/radeon/radeon_texture.c b/src/mesa/drivers/dri/radeon/radeon_texture.c
> index 23942cb..aa2f734 100644
> --- a/src/mesa/drivers/dri/radeon/radeon_texture.c
> +++ b/src/mesa/drivers/dri/radeon/radeon_texture.c
> @@ -638,7 +638,6 @@ radeon_swrast_map_image(radeonContextPtr rmesa,
> radeon_mipmap_tree *mt;
> GLuint texel_size;
> radeon_mipmap_level *lvl;
> - int rs;
>
> if (!image || !image->mt)
> return;
> @@ -650,18 +649,16 @@ radeon_swrast_map_image(radeonContextPtr rmesa,
>
> lvl =&image->mt->levels[level];
>
> - rs = lvl->rowstride / texel_size;
> -
> radeon_bo_map(mt->bo, 1);
>
> image->base.Map = mt->bo->ptr + lvl->faces[face].offset;
> - if (mt->target == GL_TEXTURE_3D) {
> - int i;
>
> - for (i = 0; i< mt->levels[level].depth; i++)
> - image->base.ImageOffsets[i] = rs * lvl->height * i;
> + for (int i = 0; i< mt->levels[level].depth; i++) {
> + image->base.ImageSlices[i] =
> + image->base.Map + (lvl->rowstride * lvl->height * i);
> }
> - image->base.RowStride = rs;
> +
> + image->base.RowStride = lvl->rowstride / texel_size;
> }
>
> static void
> diff --git a/src/mesa/main/texcompress.c b/src/mesa/main/texcompress.c
> index f74ac5d..1afd51c 100644
> --- a/src/mesa/main/texcompress.c
> +++ b/src/mesa/main/texcompress.c
> @@ -587,7 +587,7 @@ _mesa_decompress_image(gl_format format, GLuint width, GLuint height,
>
> for (j = 0; j< height; j++) {
> for (i = 0; i< width; i++) {
> - fetch(src, NULL, stride, i, j, 0, dest);
> + fetch(src, stride, i, j, dest);
> dest += 4;
> }
> }
> diff --git a/src/mesa/main/texcompress.h b/src/mesa/main/texcompress.h
> index 50c0293..772e1a9 100644
> --- a/src/mesa/main/texcompress.h
> +++ b/src/mesa/main/texcompress.h
> @@ -50,9 +50,8 @@ _mesa_compressed_image_address(GLint col, GLint row, GLint img,
>
> /** A function to fetch one texel from a compressed texture */
> typedef void (*compressed_fetch_func)(const GLubyte *map,
> - const GLuint imageOffsets[],
> GLint rowStride,
> - GLint i, GLint j, GLint k,
> + GLint i, GLint j,
> GLfloat *texel);
>
> extern compressed_fetch_func
> diff --git a/src/mesa/main/texcompress_etc.c b/src/mesa/main/texcompress_etc.c
> index 442f844..a06d29f 100644
> --- a/src/mesa/main/texcompress_etc.c
> +++ b/src/mesa/main/texcompress_etc.c
> @@ -1222,8 +1222,8 @@ _mesa_unpack_etc2_format(uint8_t *dst_row,
>
>
> static void
> -fetch_etc1_rgb8(const GLubyte *map, const GLuint imageOffsets[],
> - GLint rowStride, GLint i, GLint j, GLint k,
> +fetch_etc1_rgb8(const GLubyte *map,
> + GLint rowStride, GLint i, GLint j,
> GLfloat *texel)
> {
> struct etc1_block block;
> @@ -1243,9 +1243,8 @@ fetch_etc1_rgb8(const GLubyte *map, const GLuint imageOffsets[],
>
>
> static void
> -fetch_etc2_rgb8(const GLubyte *map, const GLuint imageOffsets[],
> - GLint rowStride, GLint i, GLint j, GLint k,
> - GLfloat *texel)
> +fetch_etc2_rgb8(const GLubyte *map,
> + GLint rowStride, GLint i, GLint j, GLfloat *texel)
> {
> struct etc2_block block;
> uint8_t dst[3];
> @@ -1265,9 +1264,8 @@ fetch_etc2_rgb8(const GLubyte *map, const GLuint imageOffsets[],
> }
>
> static void
> -fetch_etc2_srgb8(const GLubyte *map, const GLuint imageOffsets[],
> - GLint rowStride, GLint i, GLint j, GLint k,
> - GLfloat *texel)
> +fetch_etc2_srgb8(const GLubyte *map,
> + GLint rowStride, GLint i, GLint j, GLfloat *texel)
> {
> struct etc2_block block;
> uint8_t dst[3];
> @@ -1287,9 +1285,8 @@ fetch_etc2_srgb8(const GLubyte *map, const GLuint imageOffsets[],
> }
>
> static void
> -fetch_etc2_rgba8_eac(const GLubyte *map, const GLuint imageOffsets[],
> - GLint rowStride, GLint i, GLint j, GLint k,
> - GLfloat *texel)
> +fetch_etc2_rgba8_eac(const GLubyte *map,
> + GLint rowStride, GLint i, GLint j, GLfloat *texel)
> {
> struct etc2_block block;
> uint8_t dst[4];
> @@ -1307,9 +1304,8 @@ fetch_etc2_rgba8_eac(const GLubyte *map, const GLuint imageOffsets[],
> }
>
> static void
> -fetch_etc2_srgb8_alpha8_eac(const GLubyte *map, const GLuint imageOffsets[],
> - GLint rowStride, GLint i, GLint j, GLint k,
> - GLfloat *texel)
> +fetch_etc2_srgb8_alpha8_eac(const GLubyte *map,
> + GLint rowStride, GLint i, GLint j, GLfloat *texel)
> {
> struct etc2_block block;
> uint8_t dst[4];
> @@ -1327,9 +1323,8 @@ fetch_etc2_srgb8_alpha8_eac(const GLubyte *map, const GLuint imageOffsets[],
> }
>
> static void
> -fetch_etc2_r11_eac(const GLubyte *map, const GLuint imageOffsets[],
> - GLint rowStride, GLint i, GLint j, GLint k,
> - GLfloat *texel)
> +fetch_etc2_r11_eac(const GLubyte *map,
> + GLint rowStride, GLint i, GLint j, GLfloat *texel)
> {
> struct etc2_block block;
> GLushort dst;
> @@ -1347,9 +1342,8 @@ fetch_etc2_r11_eac(const GLubyte *map, const GLuint imageOffsets[],
> }
>
> static void
> -fetch_etc2_rg11_eac(const GLubyte *map, const GLuint imageOffsets[],
> - GLint rowStride, GLint i, GLint j, GLint k,
> - GLfloat *texel)
> +fetch_etc2_rg11_eac(const GLubyte *map,
> + GLint rowStride, GLint i, GLint j, GLfloat *texel)
> {
> struct etc2_block block;
> GLushort dst[2];
> @@ -1372,9 +1366,8 @@ fetch_etc2_rg11_eac(const GLubyte *map, const GLuint imageOffsets[],
> }
>
> static void
> -fetch_etc2_signed_r11_eac(const GLubyte *map, const GLuint imageOffsets[],
> - GLint rowStride, GLint i, GLint j, GLint k,
> - GLfloat *texel)
> +fetch_etc2_signed_r11_eac(const GLubyte *map,
> + GLint rowStride, GLint i, GLint j, GLfloat *texel)
> {
> struct etc2_block block;
> GLushort dst;
> @@ -1392,9 +1385,8 @@ fetch_etc2_signed_r11_eac(const GLubyte *map, const GLuint imageOffsets[],
> }
>
> static void
> -fetch_etc2_signed_rg11_eac(const GLubyte *map, const GLuint imageOffsets[],
> - GLint rowStride, GLint i, GLint j, GLint k,
> - GLfloat *texel)
> +fetch_etc2_signed_rg11_eac(const GLubyte *map,
> + GLint rowStride, GLint i, GLint j, GLfloat *texel)
> {
> struct etc2_block block;
> GLushort dst[2];
> @@ -1418,8 +1410,7 @@ fetch_etc2_signed_rg11_eac(const GLubyte *map, const GLuint imageOffsets[],
>
> static void
> fetch_etc2_rgb8_punchthrough_alpha1(const GLubyte *map,
> - const GLuint imageOffsets[],
> - GLint rowStride, GLint i, GLint j, GLint k,
> + GLint rowStride, GLint i, GLint j,
> GLfloat *texel)
> {
> struct etc2_block block;
> @@ -1440,10 +1431,8 @@ fetch_etc2_rgb8_punchthrough_alpha1(const GLubyte *map,
>
> static void
> fetch_etc2_srgb8_punchthrough_alpha1(const GLubyte *map,
> - const GLuint imageOffsets[],
> GLint rowStride,
> - GLint i, GLint j, GLint k,
> - GLfloat *texel)
> + GLint i, GLint j, GLfloat *texel)
> {
> struct etc2_block block;
> uint8_t dst[4];
> diff --git a/src/mesa/main/texcompress_fxt1.c b/src/mesa/main/texcompress_fxt1.c
> index 2d60d56..231e595 100644
> --- a/src/mesa/main/texcompress_fxt1.c
> +++ b/src/mesa/main/texcompress_fxt1.c
> @@ -1615,8 +1615,8 @@ fxt1_decode_1 (const void *texture, GLint stride, /* in pixels */
>
>
> static void
> -fetch_rgb_fxt1(const GLubyte *map, const GLuint imageOffsets[],
> - GLint rowStride, GLint i, GLint j, GLint k, GLfloat *texel)
> +fetch_rgb_fxt1(const GLubyte *map,
> + GLint rowStride, GLint i, GLint j, GLfloat *texel)
> {
> GLubyte rgba[4];
> fxt1_decode_1(map, rowStride, i, j, rgba);
> @@ -1628,8 +1628,8 @@ fetch_rgb_fxt1(const GLubyte *map, const GLuint imageOffsets[],
>
>
> static void
> -fetch_rgba_fxt1(const GLubyte *map, const GLuint imageOffsets[],
> - GLint rowStride, GLint i, GLint j, GLint k, GLfloat *texel)
> +fetch_rgba_fxt1(const GLubyte *map,
> + GLint rowStride, GLint i, GLint j, GLfloat *texel)
> {
> GLubyte rgba[4];
> fxt1_decode_1(map, rowStride, i, j, rgba);
> diff --git a/src/mesa/main/texcompress_rgtc.c b/src/mesa/main/texcompress_rgtc.c
> index a700661..7afd8ff 100644
> --- a/src/mesa/main/texcompress_rgtc.c
> +++ b/src/mesa/main/texcompress_rgtc.c
> @@ -318,12 +318,11 @@ _mesa_texstore_signed_rg_rgtc2(TEXSTORE_PARAMS)
>
>
> static void
> -fetch_red_rgtc1(const GLubyte *map, const GLuint imageOffsets[],
> - GLint rowStride, GLint i, GLint j, GLint k, GLfloat *texel)
> +fetch_red_rgtc1(const GLubyte *map,
> + GLint rowStride, GLint i, GLint j, GLfloat *texel)
> {
> GLubyte red;
> - GLuint sliceOffset = k ? imageOffsets[k] / 2 : 0;
> - unsigned_fetch_texel_rgtc(rowStride, map + sliceOffset, i, j,&red, 1);
> + unsigned_fetch_texel_rgtc(rowStride, map, i, j,&red, 1);
> texel[RCOMP] = UBYTE_TO_FLOAT(red);
> texel[GCOMP] = 0.0;
> texel[BCOMP] = 0.0;
> @@ -331,12 +330,11 @@ fetch_red_rgtc1(const GLubyte *map, const GLuint imageOffsets[],
> }
>
> static void
> -fetch_l_latc1(const GLubyte *map, const GLuint imageOffsets[],
> - GLint rowStride, GLint i, GLint j, GLint k, GLfloat *texel)
> +fetch_l_latc1(const GLubyte *map,
> + GLint rowStride, GLint i, GLint j, GLfloat *texel)
> {
> GLubyte red;
> - GLuint sliceOffset = k ? imageOffsets[k] / 2 : 0;
> - unsigned_fetch_texel_rgtc(rowStride, map + sliceOffset, i, j,&red, 1);
> + unsigned_fetch_texel_rgtc(rowStride, map, i, j,&red, 1);
> texel[RCOMP] =
> texel[GCOMP] =
> texel[BCOMP] = UBYTE_TO_FLOAT(red);
> @@ -344,13 +342,11 @@ fetch_l_latc1(const GLubyte *map, const GLuint imageOffsets[],
> }
>
> static void
> -fetch_signed_red_rgtc1(const GLubyte *map, const GLuint imageOffsets[],
> - GLint rowStride, GLint i, GLint j, GLint k,
> - GLfloat *texel)
> +fetch_signed_red_rgtc1(const GLubyte *map,
> + GLint rowStride, GLint i, GLint j, GLfloat *texel)
> {
> GLbyte red;
> - GLuint sliceOffset = k ? imageOffsets[k] / 2 : 0;
> - signed_fetch_texel_rgtc(rowStride, (const GLbyte *) map + sliceOffset,
> + signed_fetch_texel_rgtc(rowStride, (const GLbyte *) map,
> i, j,&red, 1);
> texel[RCOMP] = BYTE_TO_FLOAT_TEX(red);
> texel[GCOMP] = 0.0;
> @@ -359,13 +355,11 @@ fetch_signed_red_rgtc1(const GLubyte *map, const GLuint imageOffsets[],
> }
>
> static void
> -fetch_signed_l_latc1(const GLubyte *map, const GLuint imageOffsets[],
> - GLint rowStride, GLint i, GLint j, GLint k,
> - GLfloat *texel)
> +fetch_signed_l_latc1(const GLubyte *map,
> + GLint rowStride, GLint i, GLint j, GLfloat *texel)
> {
> GLbyte red;
> - GLuint sliceOffset = k ? imageOffsets[k] / 2 : 0;
> - signed_fetch_texel_rgtc(rowStride, (GLbyte *) map + sliceOffset,
> + signed_fetch_texel_rgtc(rowStride, (GLbyte *) map,
> i, j,&red, 1);
> texel[RCOMP] =
> texel[GCOMP] =
> @@ -374,17 +368,15 @@ fetch_signed_l_latc1(const GLubyte *map, const GLuint imageOffsets[],
> }
>
> static void
> -fetch_rg_rgtc2(const GLubyte *map, const GLuint imageOffsets[],
> - GLint rowStride, GLint i, GLint j, GLint k,
> - GLfloat *texel)
> +fetch_rg_rgtc2(const GLubyte *map,
> + GLint rowStride, GLint i, GLint j, GLfloat *texel)
> {
> GLubyte red, green;
> - GLuint sliceOffset = k ? imageOffsets[k] : 0;
> unsigned_fetch_texel_rgtc(rowStride,
> - map + sliceOffset,
> + map,
> i, j,&red, 2);
> unsigned_fetch_texel_rgtc(rowStride,
> - map + sliceOffset + 8,
> + map + 8,
> i, j,&green, 2);
> texel[RCOMP] = UBYTE_TO_FLOAT(red);
> texel[GCOMP] = UBYTE_TO_FLOAT(green);
> @@ -393,17 +385,15 @@ fetch_rg_rgtc2(const GLubyte *map, const GLuint imageOffsets[],
> }
>
> static void
> -fetch_la_latc2(const GLubyte *map, const GLuint imageOffsets[],
> - GLint rowStride, GLint i, GLint j, GLint k,
> - GLfloat *texel)
> +fetch_la_latc2(const GLubyte *map,
> + GLint rowStride, GLint i, GLint j, GLfloat *texel)
> {
> GLubyte red, green;
> - GLuint sliceOffset = k ? imageOffsets[k] : 0;
> unsigned_fetch_texel_rgtc(rowStride,
> - map + sliceOffset,
> + map,
> i, j,&red, 2);
> unsigned_fetch_texel_rgtc(rowStride,
> - map + sliceOffset + 8,
> + map + 8,
> i, j,&green, 2);
> texel[RCOMP] =
> texel[GCOMP] =
> @@ -413,17 +403,15 @@ fetch_la_latc2(const GLubyte *map, const GLuint imageOffsets[],
>
>
> static void
> -fetch_signed_rg_rgtc2(const GLubyte *map, const GLuint imageOffsets[],
> - GLint rowStride, GLint i, GLint j, GLint k,
> - GLfloat *texel)
> +fetch_signed_rg_rgtc2(const GLubyte *map,
> + GLint rowStride, GLint i, GLint j, GLfloat *texel)
> {
> GLbyte red, green;
> - GLuint sliceOffset = k ? imageOffsets[k] : 0;
> signed_fetch_texel_rgtc(rowStride,
> - (GLbyte *) map + sliceOffset,
> + (GLbyte *) map,
> i, j,&red, 2);
> signed_fetch_texel_rgtc(rowStride,
> - (GLbyte *) map + sliceOffset + 8,
> + (GLbyte *) map + 8,
> i, j,&green, 2);
> texel[RCOMP] = BYTE_TO_FLOAT_TEX(red);
> texel[GCOMP] = BYTE_TO_FLOAT_TEX(green);
> @@ -433,17 +421,15 @@ fetch_signed_rg_rgtc2(const GLubyte *map, const GLuint imageOffsets[],
>
>
> static void
> -fetch_signed_la_latc2(const GLubyte *map, const GLuint imageOffsets[],
> - GLint rowStride, GLint i, GLint j, GLint k,
> - GLfloat *texel)
> +fetch_signed_la_latc2(const GLubyte *map,
> + GLint rowStride, GLint i, GLint j, GLfloat *texel)
> {
> GLbyte red, green;
> - GLuint sliceOffset = k ? imageOffsets[k] : 0;
> signed_fetch_texel_rgtc(rowStride,
> - (GLbyte *) map + sliceOffset,
> + (GLbyte *) map,
> i, j,&red, 2);
> signed_fetch_texel_rgtc(rowStride,
> - (GLbyte *) map + sliceOffset + 8,
> + (GLbyte *) map + 8,
> i, j,&green, 2);
> texel[RCOMP] =
> texel[GCOMP] =
> diff --git a/src/mesa/main/texcompress_s3tc.c b/src/mesa/main/texcompress_s3tc.c
> index 4c162b1..ed4bb38 100644
> --- a/src/mesa/main/texcompress_s3tc.c
> +++ b/src/mesa/main/texcompress_s3tc.c
> @@ -344,13 +344,12 @@ problem(const char *func)
>
>
> static void
> -fetch_rgb_dxt1(const GLubyte *map, const GLuint imageOffsets[],
> - GLint rowStride, GLint i, GLint j, GLint k, GLfloat *texel)
> +fetch_rgb_dxt1(const GLubyte *map,
> + GLint rowStride, GLint i, GLint j, GLfloat *texel)
> {
> if (fetch_ext_rgb_dxt1) {
> - GLuint sliceOffset = k ? imageOffsets[k] / 2 : 0;
> GLubyte tex[4];
> - fetch_ext_rgb_dxt1(rowStride, map + sliceOffset, i, j, tex);
> + fetch_ext_rgb_dxt1(rowStride, map, i, j, tex);
> texel[RCOMP] = UBYTE_TO_FLOAT(tex[RCOMP]);
> texel[GCOMP] = UBYTE_TO_FLOAT(tex[GCOMP]);
> texel[BCOMP] = UBYTE_TO_FLOAT(tex[BCOMP]);
> @@ -362,13 +361,12 @@ fetch_rgb_dxt1(const GLubyte *map, const GLuint imageOffsets[],
> }
>
> static void
> -fetch_rgba_dxt1(const GLubyte *map, const GLuint imageOffsets[],
> - GLint rowStride, GLint i, GLint j, GLint k, GLfloat *texel)
> +fetch_rgba_dxt1(const GLubyte *map,
> + GLint rowStride, GLint i, GLint j, GLfloat *texel)
> {
> if (fetch_ext_rgba_dxt1) {
> - GLuint sliceOffset = k ? imageOffsets[k] / 2 : 0;
> GLubyte tex[4];
> - fetch_ext_rgba_dxt1(rowStride, map + sliceOffset, i, j, tex);
> + fetch_ext_rgba_dxt1(rowStride, map, i, j, tex);
> texel[RCOMP] = UBYTE_TO_FLOAT(tex[RCOMP]);
> texel[GCOMP] = UBYTE_TO_FLOAT(tex[GCOMP]);
> texel[BCOMP] = UBYTE_TO_FLOAT(tex[BCOMP]);
> @@ -380,13 +378,12 @@ fetch_rgba_dxt1(const GLubyte *map, const GLuint imageOffsets[],
> }
>
> static void
> -fetch_rgba_dxt3(const GLubyte *map, const GLuint imageOffsets[],
> - GLint rowStride, GLint i, GLint j, GLint k, GLfloat *texel)
> +fetch_rgba_dxt3(const GLubyte *map,
> + GLint rowStride, GLint i, GLint j, GLfloat *texel)
> {
> if (fetch_ext_rgba_dxt3) {
> - GLuint sliceOffset = k ? imageOffsets[k] : 0;
> GLubyte tex[4];
> - fetch_ext_rgba_dxt3(rowStride, map + sliceOffset, i, j, tex);
> + fetch_ext_rgba_dxt3(rowStride, map, i, j, tex);
> texel[RCOMP] = UBYTE_TO_FLOAT(tex[RCOMP]);
> texel[GCOMP] = UBYTE_TO_FLOAT(tex[GCOMP]);
> texel[BCOMP] = UBYTE_TO_FLOAT(tex[BCOMP]);
> @@ -398,13 +395,12 @@ fetch_rgba_dxt3(const GLubyte *map, const GLuint imageOffsets[],
> }
>
> static void
> -fetch_rgba_dxt5(const GLubyte *map, const GLuint imageOffsets[],
> - GLint rowStride, GLint i, GLint j, GLint k, GLfloat *texel)
> +fetch_rgba_dxt5(const GLubyte *map,
> + GLint rowStride, GLint i, GLint j, GLfloat *texel)
> {
> if (fetch_ext_rgba_dxt5) {
> - GLuint sliceOffset = k ? imageOffsets[k] : 0;
> GLubyte tex[4];
> - fetch_ext_rgba_dxt5(rowStride, map + sliceOffset, i, j, tex);
> + fetch_ext_rgba_dxt5(rowStride, map, i, j, tex);
> texel[RCOMP] = UBYTE_TO_FLOAT(tex[RCOMP]);
> texel[GCOMP] = UBYTE_TO_FLOAT(tex[GCOMP]);
> texel[BCOMP] = UBYTE_TO_FLOAT(tex[BCOMP]);
> @@ -417,13 +413,12 @@ fetch_rgba_dxt5(const GLubyte *map, const GLuint imageOffsets[],
>
>
> static void
> -fetch_srgb_dxt1(const GLubyte *map, const GLuint imageOffsets[],
> - GLint rowStride, GLint i, GLint j, GLint k, GLfloat *texel)
> +fetch_srgb_dxt1(const GLubyte *map,
> + GLint rowStride, GLint i, GLint j, GLfloat *texel)
> {
> if (fetch_ext_rgb_dxt1) {
> - GLuint sliceOffset = k ? imageOffsets[k] / 2 : 0;
> GLubyte tex[4];
> - fetch_ext_rgb_dxt1(rowStride, map + sliceOffset, i, j, tex);
> + fetch_ext_rgb_dxt1(rowStride, map, i, j, tex);
> texel[RCOMP] = _mesa_nonlinear_to_linear(tex[RCOMP]);
> texel[GCOMP] = _mesa_nonlinear_to_linear(tex[GCOMP]);
> texel[BCOMP] = _mesa_nonlinear_to_linear(tex[BCOMP]);
> @@ -435,13 +430,12 @@ fetch_srgb_dxt1(const GLubyte *map, const GLuint imageOffsets[],
> }
>
> static void
> -fetch_srgba_dxt1(const GLubyte *map, const GLuint imageOffsets[],
> - GLint rowStride, GLint i, GLint j, GLint k, GLfloat *texel)
> +fetch_srgba_dxt1(const GLubyte *map,
> + GLint rowStride, GLint i, GLint j, GLfloat *texel)
> {
> if (fetch_ext_rgba_dxt1) {
> - GLuint sliceOffset = k ? imageOffsets[k] / 2 : 0;
> GLubyte tex[4];
> - fetch_ext_rgba_dxt1(rowStride, map + sliceOffset, i, j, tex);
> + fetch_ext_rgba_dxt1(rowStride, map, i, j, tex);
> texel[RCOMP] = _mesa_nonlinear_to_linear(tex[RCOMP]);
> texel[GCOMP] = _mesa_nonlinear_to_linear(tex[GCOMP]);
> texel[BCOMP] = _mesa_nonlinear_to_linear(tex[BCOMP]);
> @@ -453,13 +447,12 @@ fetch_srgba_dxt1(const GLubyte *map, const GLuint imageOffsets[],
> }
>
> static void
> -fetch_srgba_dxt3(const GLubyte *map, const GLuint imageOffsets[],
> - GLint rowStride, GLint i, GLint j, GLint k, GLfloat *texel)
> +fetch_srgba_dxt3(const GLubyte *map,
> + GLint rowStride, GLint i, GLint j, GLfloat *texel)
> {
> if (fetch_ext_rgba_dxt3) {
> - GLuint sliceOffset = k ? imageOffsets[k] : 0;
> GLubyte tex[4];
> - fetch_ext_rgba_dxt3(rowStride, map + sliceOffset, i, j, tex);
> + fetch_ext_rgba_dxt3(rowStride, map, i, j, tex);
> texel[RCOMP] = _mesa_nonlinear_to_linear(tex[RCOMP]);
> texel[GCOMP] = _mesa_nonlinear_to_linear(tex[GCOMP]);
> texel[BCOMP] = _mesa_nonlinear_to_linear(tex[BCOMP]);
> @@ -471,13 +464,12 @@ fetch_srgba_dxt3(const GLubyte *map, const GLuint imageOffsets[],
> }
>
> static void
> -fetch_srgba_dxt5(const GLubyte *map, const GLuint imageOffsets[],
> - GLint rowStride, GLint i, GLint j, GLint k, GLfloat *texel)
> +fetch_srgba_dxt5(const GLubyte *map,
> + GLint rowStride, GLint i, GLint j, GLfloat *texel)
> {
> if (fetch_ext_rgba_dxt5) {
> - GLuint sliceOffset = k ? imageOffsets[k] : 0;
> GLubyte tex[4];
> - fetch_ext_rgba_dxt5(rowStride, map + sliceOffset, i, j, tex);
> + fetch_ext_rgba_dxt5(rowStride, map, i, j, tex);
> texel[RCOMP] = _mesa_nonlinear_to_linear(tex[RCOMP]);
> texel[GCOMP] = _mesa_nonlinear_to_linear(tex[GCOMP]);
> texel[BCOMP] = _mesa_nonlinear_to_linear(tex[BCOMP]);
> diff --git a/src/mesa/swrast/s_context.h b/src/mesa/swrast/s_context.h
> index 2f7a2b5..c9a8ee5 100644
> --- a/src/mesa/swrast/s_context.h
> +++ b/src/mesa/swrast/s_context.h
> @@ -139,7 +139,7 @@ struct swrast_texture_image
>
> /** These fields only valid when texture memory is mapped */
> GLint RowStride; /**< Padded width in units of texels */
> - GLuint *ImageOffsets; /**< if 3D texture: array [Depth] of offsets to
> + void **ImageSlices; /**< if 3D texture: array [Depth] of offsets to
"of pointers", right?
> each 2D slice in 'Data', in texels */
rm "in texels"
> GLubyte *Map; /**< Pointer to mapped image memory */
>
> diff --git a/src/mesa/swrast/s_texfetch.c b/src/mesa/swrast/s_texfetch.c
> index 5e1a9f7..fd9a93e 100644
> --- a/src/mesa/swrast/s_texfetch.c
> +++ b/src/mesa/swrast/s_texfetch.c
> @@ -97,10 +97,9 @@ static void
> fetch_compressed(const struct swrast_texture_image *swImage,
> GLint i, GLint j, GLint k, GLfloat *texel)
> {
> - swImage->FetchCompressedTexel(swImage->Map,
> - swImage->ImageOffsets,
> + swImage->FetchCompressedTexel(swImage->ImageSlices[k],
> swImage->RowStride,
> - i, j, k, texel);
> + i, j, texel);
> }
>
>
> diff --git a/src/mesa/swrast/s_texfetch_tmp.h b/src/mesa/swrast/s_texfetch_tmp.h
> index 2de1f1a..e66de2d 100644
> --- a/src/mesa/swrast/s_texfetch_tmp.h
> +++ b/src/mesa/swrast/s_texfetch_tmp.h
> @@ -58,8 +58,8 @@
> #elif DIM == 3
>
> #define TEXEL_ADDR( type, image, i, j, k, size ) \
> - ((type *)(image)->Map + ((image)->ImageOffsets[k] \
> - + (image)->RowStride * (j) + (i)) * (size))
> + ((type *)(image)->ImageSlices[k] + \
> + ((image)->RowStride * (j) + (i)) * (size))
>
> #define FETCH(x) fetch_texel_3d_##x
>
> diff --git a/src/mesa/swrast/s_texrender.c b/src/mesa/swrast/s_texrender.c
> index 7b25a7b..92d4edc 100644
> --- a/src/mesa/swrast/s_texrender.c
> +++ b/src/mesa/swrast/s_texrender.c
> @@ -88,18 +88,8 @@ update_wrapper(struct gl_context *ctx, struct gl_renderbuffer_attachment *att)
>
> /* Want to store linear values, not sRGB */
> rb->Format = _mesa_get_srgb_format_linear(format);
> -
> - /* Set the gl_renderbuffer::Buffer field so that mapping the buffer
> - * succeeds.
> - */
> - if (att->Texture->Target == GL_TEXTURE_3D ||
> - att->Texture->Target == GL_TEXTURE_2D_ARRAY_EXT) {
> - srb->Buffer = swImage->Buffer +
> - swImage->ImageOffsets[zOffset] * _mesa_get_format_bytes(format);
> - }
> - else {
> - srb->Buffer = swImage->Buffer;
> - }
> +
> + srb->Buffer = swImage->ImageSlices[zOffset];
> }
>
>
> diff --git a/src/mesa/swrast/s_texture.c b/src/mesa/swrast/s_texture.c
> index c60fe2d..f6e0aa4 100644
> --- a/src/mesa/swrast/s_texture.c
> +++ b/src/mesa/swrast/s_texture.c
> @@ -75,23 +75,30 @@ _swrast_alloc_texture_image_buffer(struct gl_context *ctx,
> struct gl_texture_image *texImage)
> {
> struct swrast_texture_image *swImg = swrast_texture_image(texImage);
> - GLuint bytes = _mesa_format_image_size(texImage->TexFormat, texImage->Width,
> - texImage->Height, texImage->Depth);
> + GLuint bytesPerSlice;
> + GLuint sliceHeight = texImage->Height;
> + GLuint slices = texture_slices(texImage);
> GLuint i;
>
> + if (texImage->TexObject->Target == GL_TEXTURE_1D_ARRAY)
> + sliceHeight = 1;
The previously mentioned slice_height() helper function could be used
here too.
More information about the mesa-dev
mailing list