summaryrefslogtreecommitdiffstats
path: root/src/mesa/swrast
diff options
context:
space:
mode:
authorEric Anholt <[email protected]>2013-04-19 11:44:53 -0700
committerEric Anholt <[email protected]>2013-04-30 10:40:43 -0700
commit0c883e46d871797cd1141498850d51cde6e54b76 (patch)
tree54019d9f77240229e7da69de95be45eb47de4984 /src/mesa/swrast
parente7ecc11311d142a8ac919627011372a265224bcd (diff)
swrast: Replace ImageOffsets with an ImageSlices pointer.
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. v2: Use slice height helper function. Reviewed-by: Kenneth Graunke <[email protected]> Reviewed-by: Brian Paul <[email protected]>
Diffstat (limited to 'src/mesa/swrast')
-rw-r--r--src/mesa/swrast/s_context.h2
-rw-r--r--src/mesa/swrast/s_texfetch.c5
-rw-r--r--src/mesa/swrast/s_texfetch_tmp.h4
-rw-r--r--src/mesa/swrast/s_texrender.c14
-rw-r--r--src/mesa/swrast/s_texture.c43
5 files changed, 29 insertions, 39 deletions
diff --git a/src/mesa/swrast/s_context.h b/src/mesa/swrast/s_context.h
index 5d9354d7cf1..7b3c740c1ca 100644
--- a/src/mesa/swrast/s_context.h
+++ b/src/mesa/swrast/s_context.h
@@ -140,7 +140,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
each 2D slice in 'Data', 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 7c76f18ceba..a9bc3fad0a2 100644
--- a/src/mesa/swrast/s_texfetch.c
+++ b/src/mesa/swrast/s_texfetch.c
@@ -98,10 +98,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 7f09683630c..cf8f61fefdc 100644
--- a/src/mesa/swrast/s_texfetch_tmp.h
+++ b/src/mesa/swrast/s_texfetch_tmp.h
@@ -59,8 +59,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 7b25a7b7d81..92d4edcd835 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 4d3cd0f8ce1..b0990a8cc30 100644
--- a/src/mesa/swrast/s_texture.c
+++ b/src/mesa/swrast/s_texture.c
@@ -88,23 +88,26 @@ _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 slices = texture_slices(texImage);
GLuint i;
if (!_swrast_init_texture_image(texImage))
return GL_FALSE;
+ bytesPerSlice = _mesa_format_image_size(texImage->TexFormat, texImage->Width,
+ _swrast_teximage_slice_height(texImage), 1);
+
assert(!swImg->Buffer);
- swImg->Buffer = _mesa_align_malloc(bytes, 512);
+ swImg->Buffer = _mesa_align_malloc(bytesPerSlice * slices, 512);
if (!swImg->Buffer)
return GL_FALSE;
- /* RowStride and ImageOffsets[] describe how to address texels in 'Data' */
+ /* RowStride and ImageSlices[] describe how to address texels in 'Data' */
swImg->RowStride = texImage->Width;
- for (i = 0; i < texture_slices(texImage); i++) {
- swImg->ImageOffsets[i] = i * texImage->Width * texImage->Height;
+ for (i = 0; i < slices; i++) {
+ swImg->ImageSlices[i] = swImg->Buffer + bytesPerSlice * i;
}
return GL_TRUE;
@@ -114,7 +117,7 @@ _swrast_alloc_texture_image_buffer(struct gl_context *ctx,
/**
* Code that overrides ctx->Driver.AllocTextureImageBuffer may use this to
* initialize the fields of swrast_texture_image without allocating the image
- * buffer or initializing RowStride or the contents of ImageOffsets.
+ * buffer or initializing RowStride or the contents of ImageSlices.
*
* Returns GL_TRUE on success, GL_FALSE on memory allocation failure.
*/
@@ -143,9 +146,9 @@ _swrast_init_texture_image(struct gl_texture_image *texImage)
swImg->DepthScale = (GLfloat) texImage->Depth;
}
- assert(!swImg->ImageOffsets);
- swImg->ImageOffsets = malloc(texture_slices(texImage) * sizeof(GLuint));
- if (!swImg->ImageOffsets)
+ assert(!swImg->ImageSlices);
+ swImg->ImageSlices = calloc(texture_slices(texImage), sizeof(void *));
+ if (!swImg->ImageSlices)
return GL_FALSE;
return GL_TRUE;
@@ -165,8 +168,8 @@ _swrast_free_texture_image_buffer(struct gl_context *ctx,
swImage->Buffer = NULL;
}
- free(swImage->ImageOffsets);
- swImage->ImageOffsets = NULL;
+ free(swImage->ImageSlices);
+ swImage->ImageSlices = NULL;
}
@@ -227,17 +230,15 @@ _swrast_map_teximage(struct gl_context *ctx,
*mapOut = NULL;
return;
}
-
- map = swImage->Buffer;
+
+ /* This function can only be used with a swrast-allocated buffer, in which
+ * case ImageSlices is populated with pointers into Buffer.
+ */
+ assert(swImage->Buffer);
+ assert(swImage->Buffer == swImage->ImageSlices[0]);
assert(slice < texture_slices(texImage));
- if (slice != 0) {
- GLuint sliceSize = _mesa_format_image_size(texImage->TexFormat,
- texImage->Width,
- _swrast_teximage_slice_height(texImage),
- 1);
- map += slice * sliceSize;
- }
+ map = swImage->ImageSlices[slice];
/* apply x/y offset to map address */
map += stride * (y / bh) + texelSize * (x / bw);