mesa: move gl_texture_image::Data, RowStride, ImageOffsets to swrast

Only swrast and the drivers that fall back to swrast need these fields now.
This removes the last of the fields related to software rendering from
gl_texture_image.
This commit is contained in:
Brian Paul
2011-10-23 10:44:47 -06:00
parent 33abbd4fbd
commit 6e0f9001fe
27 changed files with 206 additions and 177 deletions

View File

@@ -417,8 +417,8 @@ intel_miptree_copy_teximage(struct intel_context *intel,
dst_mt, dst_x, dst_y, dst_mt->region->pitch * dst_mt->region->cpp, dst_mt, dst_x, dst_y, dst_mt->region->pitch * dst_mt->region->cpp,
width, height); width, height);
src = intelImage->base.Base.Data; src = intelImage->base.Data;
src += (intelImage->base.Base.RowStride * src += (intelImage->base.RowStride *
intelImage->base.Base.Height * intelImage->base.Base.Height *
dst_mt->region->cpp * dst_mt->region->cpp *
slice); slice);
@@ -429,7 +429,7 @@ intel_miptree_copy_teximage(struct intel_context *intel,
dst_x, dst_y, dst_x, dst_y,
width, height, width, height,
src, src,
intelImage->base.Base.RowStride, intelImage->base.RowStride,
0, 0); 0, 0);
intel_region_unmap(intel, dst_mt->region); intel_region_unmap(intel, dst_mt->region);
@@ -437,8 +437,8 @@ intel_miptree_copy_teximage(struct intel_context *intel,
} }
if (!src_mt) { if (!src_mt) {
_mesa_free_texmemory(intelImage->base.Base.Data); _mesa_free_texmemory(intelImage->base.Data);
intelImage->base.Base.Data = NULL; intelImage->base.Data = NULL;
} }
intel_miptree_reference(&intelImage->mt, dst_mt); intel_miptree_reference(&intelImage->mt, dst_mt);

View File

@@ -59,6 +59,7 @@ intel_alloc_texture_image_buffer(struct gl_context *ctx,
struct intel_texture_image *intel_image = intel_texture_image(image); struct intel_texture_image *intel_image = intel_texture_image(image);
struct gl_texture_object *texobj = image->TexObject; struct gl_texture_object *texobj = image->TexObject;
struct intel_texture_object *intel_texobj = intel_texture_object(texobj); struct intel_texture_object *intel_texobj = intel_texture_object(texobj);
GLuint slices;
/* Because the driver uses AllocTextureImageBuffer() internally, it may end /* Because the driver uses AllocTextureImageBuffer() internally, it may end
* up mismatched with FreeTextureImageBuffer(), but that is safe to call * up mismatched with FreeTextureImageBuffer(), but that is safe to call
@@ -66,6 +67,26 @@ intel_alloc_texture_image_buffer(struct gl_context *ctx,
*/ */
ctx->Driver.FreeTextureImageBuffer(ctx, image); ctx->Driver.FreeTextureImageBuffer(ctx, image);
if (intel->must_use_separate_stencil
&& image->TexFormat == MESA_FORMAT_S8_Z24) {
intel_tex_image_s8z24_create_renderbuffers(intel, intel_image);
}
/* Allocate the swrast_texture_image::ImageOffsets array now */
switch (texobj->Target) {
case GL_TEXTURE_3D:
case GL_TEXTURE_2D_ARRAY:
slices = image->Depth;
break;
case GL_TEXTURE_1D_ARRAY:
slices = image->Height;
break;
default:
slices = 1;
}
assert(!intel_image->base.ImageOffsets);
intel_image->base.ImageOffsets = malloc(slices * sizeof(GLuint));
if (intel_texobj->mt && if (intel_texobj->mt &&
intel_miptree_match_image(intel_texobj->mt, image)) { intel_miptree_match_image(intel_texobj->mt, image)) {
intel_miptree_reference(&intel_image->mt, intel_texobj->mt); intel_miptree_reference(&intel_image->mt, intel_texobj->mt);
@@ -113,9 +134,14 @@ intel_free_texture_image_buffer(struct gl_context * ctx,
intel_miptree_release(&intelImage->mt); intel_miptree_release(&intelImage->mt);
if (texImage->Data) { if (intelImage->base.Data) {
_mesa_free_texmemory(texImage->Data); _mesa_free_texmemory(intelImage->base.Data);
texImage->Data = NULL; intelImage->base.Data = NULL;
}
if (intelImage->base.ImageOffsets) {
free(intelImage->base.ImageOffsets);
intelImage->base.ImageOffsets = NULL;
} }
_mesa_reference_renderbuffer(&intelImage->depth_rb, NULL); _mesa_reference_renderbuffer(&intelImage->depth_rb, NULL);
@@ -188,11 +214,11 @@ intel_map_texture_image(struct gl_context *ctx,
assert(map); assert(map);
*stride = _mesa_format_row_stride(tex_image->TexFormat, width); *stride = _mesa_format_row_stride(tex_image->TexFormat, width);
*map = tex_image->Data + (slice * height + y) * *stride + x * texelSize; *map = intel_image->base.Data + (slice * height + y) * *stride + x * texelSize;
DBG("%s: %d,%d %dx%d from data %p = %p/%d\n", __FUNCTION__, DBG("%s: %d,%d %dx%d from data %p = %p/%d\n", __FUNCTION__,
x, y, w, h, x, y, w, h,
tex_image->Data, *map, *stride); intel_image->base.Data, *map, *stride);
} }
} }

View File

@@ -454,7 +454,7 @@ intel_set_texture_image_region(struct gl_context *ctx,
if (intel_image->mt == NULL) if (intel_image->mt == NULL)
return; return;
image->RowStride = region->pitch; intel_image->base.RowStride = region->pitch;
} }
void void

View File

@@ -147,40 +147,29 @@ intel_tex_map_image_for_swrast(struct intel_context *intel,
mt->target == GL_TEXTURE_1D_ARRAY) { mt->target == GL_TEXTURE_1D_ARRAY) {
int i; int i;
if (mt->target == GL_TEXTURE_2D_ARRAY ||
mt->target == GL_TEXTURE_1D_ARRAY) {
/* Mesa only allocates one entry for these, but we really do have an
* offset per depth.
*/
free(intel_image->base.Base.ImageOffsets);
intel_image->base.Base.ImageOffsets = malloc(mt->level[level].depth *
sizeof(GLuint));
}
/* ImageOffsets[] is only used for swrast's fetch_texel_3d, so we can't /* ImageOffsets[] is only used for swrast's fetch_texel_3d, so we can't
* share code with the normal path. * share code with the normal path.
*/ */
for (i = 0; i < mt->level[level].depth; i++) { for (i = 0; i < mt->level[level].depth; i++) {
intel_miptree_get_image_offset(mt, level, face, i, &x, &y); intel_miptree_get_image_offset(mt, level, face, i, &x, &y);
intel_image->base.Base.ImageOffsets[i] = x + y * mt->region->pitch; intel_image->base.ImageOffsets[i] = x + y * mt->region->pitch;
} }
DBG("%s \n", __FUNCTION__); DBG("%s \n", __FUNCTION__);
intel_image->base.Base.Data = intel_region_map(intel, mt->region, mode); intel_image->base.Data = intel_region_map(intel, mt->region, mode);
} else { } else {
assert(mt->level[level].depth == 1); assert(mt->level[level].depth == 1);
intel_miptree_get_image_offset(mt, level, face, 0, &x, &y); intel_miptree_get_image_offset(mt, level, face, 0, &x, &y);
intel_image->base.Base.ImageOffsets[0] = 0;
DBG("%s: (%d,%d) -> (%d, %d)/%d\n", DBG("%s: (%d,%d) -> (%d, %d)/%d\n",
__FUNCTION__, face, level, x, y, mt->region->pitch * mt->cpp); __FUNCTION__, face, level, x, y, mt->region->pitch * mt->cpp);
intel_image->base.Base.Data = intel_region_map(intel, mt->region, mode) + intel_image->base.Data = intel_region_map(intel, mt->region, mode) +
(x + y * mt->region->pitch) * mt->cpp; (x + y * mt->region->pitch) * mt->cpp;
} }
intel_image->base.Base.RowStride = mt->region->pitch; intel_image->base.RowStride = mt->region->pitch;
} }
static void static void
@@ -189,7 +178,7 @@ intel_tex_unmap_image_for_swrast(struct intel_context *intel,
{ {
if (intel_image && intel_image->mt) { if (intel_image && intel_image->mt) {
intel_region_unmap(intel, intel_image->mt->region); intel_region_unmap(intel, intel_image->mt->region);
intel_image->base.Base.Data = NULL; intel_image->base.Data = NULL;
} }
} }

View File

@@ -68,7 +68,7 @@ nouveau_teximage_new(struct gl_context *ctx)
{ {
struct nouveau_teximage *nti = CALLOC_STRUCT(nouveau_teximage); struct nouveau_teximage *nti = CALLOC_STRUCT(nouveau_teximage);
return &nti->base; return &nti->base.Base;
} }
static void static void
@@ -103,7 +103,7 @@ nouveau_teximage_map(struct gl_context *ctx, struct gl_texture_image *ti,
nti->transfer.x = x; nti->transfer.x = x;
nti->transfer.y = y; nti->transfer.y = y;
ti->Data = nouveau_get_scratch(ctx, st->pitch * h, nti->base.Data = nouveau_get_scratch(ctx, st->pitch * h,
&st->bo, &st->offset); &st->bo, &st->offset);
} else { } else {
@@ -119,7 +119,7 @@ nouveau_teximage_map(struct gl_context *ctx, struct gl_texture_image *ti,
assert(!ret); assert(!ret);
} }
ti->Data = s->bo->map + y * s->pitch + x * s->cpp; nti->base.Data = s->bo->map + y * s->pitch + x * s->cpp;
} }
} }
} }
@@ -141,7 +141,7 @@ nouveau_teximage_unmap(struct gl_context *ctx, struct gl_texture_image *ti)
nouveau_bo_unmap(s->bo); nouveau_bo_unmap(s->bo);
} }
ti->Data = NULL; nti->base.Data = NULL;
} }
@@ -197,7 +197,7 @@ nouveau_map_texture_image(struct gl_context *ctx,
*stride = s->pitch; *stride = s->pitch;
} }
} else { } else {
*map = ti->Data + y * s->pitch + x * s->cpp; *map = nti->base.Data + y * s->pitch + x * s->cpp;
*stride = s->pitch; *stride = s->pitch;
} }
} }
@@ -220,7 +220,7 @@ nouveau_unmap_texture_image(struct gl_context *ctx, struct gl_texture_image *ti,
nouveau_bo_unmap(s->bo); nouveau_bo_unmap(s->bo);
} }
ti->Data = NULL; nti->base.Data = NULL;
} }
static gl_format static gl_format
@@ -461,12 +461,13 @@ nouveau_teximage(struct gl_context *ctx, GLint dims, GLenum target, GLint level,
struct gl_texture_image *ti) struct gl_texture_image *ti)
{ {
struct nouveau_surface *s = &to_nouveau_teximage(ti)->surface; struct nouveau_surface *s = &to_nouveau_teximage(ti)->surface;
struct nouveau_teximage *nti = to_nouveau_teximage(ti);
int ret; int ret;
/* Allocate a new bo for the image. */ /* Allocate a new bo for the image. */
nouveau_surface_alloc(ctx, s, LINEAR, get_teximage_placement(ti), nouveau_surface_alloc(ctx, s, LINEAR, get_teximage_placement(ti),
ti->TexFormat, width, height); ti->TexFormat, width, height);
ti->RowStride = s->pitch / s->cpp; nti->base.RowStride = s->pitch / s->cpp;
pixels = _mesa_validate_pbo_teximage(ctx, dims, width, height, depth, pixels = _mesa_validate_pbo_teximage(ctx, dims, width, height, depth,
format, type, pixels, packing, format, type, pixels, packing,
@@ -479,7 +480,7 @@ nouveau_teximage(struct gl_context *ctx, GLint dims, GLenum target, GLint level,
ret = _mesa_texstore(ctx, dims, ti->_BaseFormat, ret = _mesa_texstore(ctx, dims, ti->_BaseFormat,
ti->TexFormat, ti->TexFormat,
0, 0, 0, s->pitch, 0, 0, 0, s->pitch,
(GLubyte **) &ti->Data, &nti->base.Data,
width, height, depth, width, height, depth,
format, type, pixels, packing); format, type, pixels, packing);
assert(ret); assert(ret);
@@ -555,6 +556,7 @@ nouveau_texsubimage(struct gl_context *ctx, GLint dims, GLenum target, GLint lev
struct gl_texture_image *ti) struct gl_texture_image *ti)
{ {
struct nouveau_surface *s = &to_nouveau_teximage(ti)->surface; struct nouveau_surface *s = &to_nouveau_teximage(ti)->surface;
struct nouveau_teximage *nti = to_nouveau_teximage(ti);
int ret; int ret;
pixels = _mesa_validate_pbo_teximage(ctx, dims, width, height, depth, pixels = _mesa_validate_pbo_teximage(ctx, dims, width, height, depth,
@@ -566,7 +568,7 @@ nouveau_texsubimage(struct gl_context *ctx, GLint dims, GLenum target, GLint lev
ret = _mesa_texstore(ctx, 3, ti->_BaseFormat, ti->TexFormat, ret = _mesa_texstore(ctx, 3, ti->_BaseFormat, ti->TexFormat,
0, 0, 0, s->pitch, 0, 0, 0, s->pitch,
(GLubyte **) &ti->Data, &nti->base.Data,
width, height, depth, width, height, depth,
format, type, pixels, packing); format, type, pixels, packing);
assert(ret); assert(ret);
@@ -654,10 +656,12 @@ nouveau_set_texbuffer(__DRIcontext *dri_ctx,
fb->Attachment[BUFFER_FRONT_LEFT].Renderbuffer; fb->Attachment[BUFFER_FRONT_LEFT].Renderbuffer;
struct gl_texture_object *t = _mesa_get_current_tex_object(ctx, target); struct gl_texture_object *t = _mesa_get_current_tex_object(ctx, target);
struct gl_texture_image *ti; struct gl_texture_image *ti;
struct nouveau_teximage *nti;
struct nouveau_surface *s; struct nouveau_surface *s;
_mesa_lock_texture(ctx, t); _mesa_lock_texture(ctx, t);
ti = _mesa_get_tex_image(ctx, t, target, 0); ti = _mesa_get_tex_image(ctx, t, target, 0);
nti = to_nouveau_teximage(ti);
s = &to_nouveau_teximage(ti)->surface; s = &to_nouveau_teximage(ti)->surface;
/* Update the texture surface with the given drawable. */ /* Update the texture surface with the given drawable. */
@@ -669,7 +673,7 @@ nouveau_set_texbuffer(__DRIcontext *dri_ctx,
/* Update the image fields. */ /* Update the image fields. */
_mesa_init_teximage_fields(ctx, target, ti, s->width, s->height, _mesa_init_teximage_fields(ctx, target, ti, s->width, s->height,
1, 0, s->cpp, s->format); 1, 0, s->cpp, s->format);
ti->RowStride = s->pitch / s->cpp; nti->base.RowStride = s->pitch / s->cpp;
/* Try to validate it. */ /* Try to validate it. */
if (!validate_teximage(ctx, t, 0, 0, 0, 0, s->width, s->height, 1)) if (!validate_teximage(ctx, t, 0, 0, 0, 0, s->width, s->height, 1))

View File

@@ -27,8 +27,10 @@
#ifndef __NOUVEAU_TEXTURE_H__ #ifndef __NOUVEAU_TEXTURE_H__
#define __NOUVEAU_TEXTURE_H__ #define __NOUVEAU_TEXTURE_H__
#include "swrast/s_context.h"
struct nouveau_teximage { struct nouveau_teximage {
struct gl_texture_image base; struct swrast_texture_image base;
struct nouveau_surface surface; struct nouveau_surface surface;
struct { struct {
struct nouveau_surface surface; struct nouveau_surface surface;

View File

@@ -846,7 +846,7 @@ void r200SetTexBuffer2(__DRIcontext *pDRICtx, GLint target, GLint texture_format
_mesa_init_teximage_fields(radeon->glCtx, target, texImage, _mesa_init_teximage_fields(radeon->glCtx, target, texImage,
rb->base.Width, rb->base.Height, 1, 0, rb->base.Width, rb->base.Height, 1, 0,
rb->cpp, texFormat); rb->cpp, texFormat);
texImage->RowStride = rb->pitch / rb->cpp; rImage->base.RowStride = rb->pitch / rb->cpp;
t->pp_txsize = ((rb->base.Width - 1) << RADEON_TEX_USIZE_SHIFT) t->pp_txsize = ((rb->base.Width - 1) << RADEON_TEX_USIZE_SHIFT)

View File

@@ -498,7 +498,7 @@ void r300SetTexBuffer2(__DRIcontext *pDRICtx, GLint target, GLint texture_format
_mesa_init_teximage_fields(radeon->glCtx, target, texImage, _mesa_init_teximage_fields(radeon->glCtx, target, texImage,
rb->base.Width, rb->base.Height, 1, 0, rb->base.Width, rb->base.Height, 1, 0,
rb->cpp, texFormat); rb->cpp, texFormat);
texImage->RowStride = rb->pitch / rb->cpp; rImage->base.RowStride = rb->pitch / rb->cpp;
pitch_val--; pitch_val--;

View File

@@ -1404,7 +1404,7 @@ void evergreenSetTexBuffer(__DRIcontext *pDRICtx, GLint target, GLint glx_textur
_mesa_init_teximage_fields(radeon->glCtx, target, texImage, _mesa_init_teximage_fields(radeon->glCtx, target, texImage,
rb->base.Width, rb->base.Height, 1, 0, rb->base.Width, rb->base.Height, 1, 0,
rb->cpp, texFormat); rb->cpp, texFormat);
texImage->RowStride = rb->pitch / rb->cpp; rImage->base.RowStride = rb->pitch / rb->cpp;
pitch_val = (pitch_val + R700_TEXEL_PITCH_ALIGNMENT_MASK) pitch_val = (pitch_val + R700_TEXEL_PITCH_ALIGNMENT_MASK)
& ~R700_TEXEL_PITCH_ALIGNMENT_MASK; & ~R700_TEXEL_PITCH_ALIGNMENT_MASK;

View File

@@ -1257,7 +1257,7 @@ void r600SetTexBuffer2(__DRIcontext *pDRICtx, GLint target, GLint glx_texture_fo
_mesa_init_teximage_fields(radeon->glCtx, target, texImage, _mesa_init_teximage_fields(radeon->glCtx, target, texImage,
rb->base.Width, rb->base.Height, 1, 0, rb->base.Width, rb->base.Height, 1, 0,
rb->cpp, texFormat); rb->cpp, texFormat);
texImage->RowStride = rb->pitch / rb->cpp; rImage->base.RowStride = rb->pitch / rb->cpp;
pitch_val = (pitch_val + R700_TEXEL_PITCH_ALIGNMENT_MASK) pitch_val = (pitch_val + R700_TEXEL_PITCH_ALIGNMENT_MASK)
& ~R700_TEXEL_PITCH_ALIGNMENT_MASK; & ~R700_TEXEL_PITCH_ALIGNMENT_MASK;

View File

@@ -480,7 +480,7 @@ static void migrate_image_to_miptree(radeon_mipmap_tree *mt,
radeon_bo_unmap(image->mt->bo); radeon_bo_unmap(image->mt->bo);
radeon_miptree_unreference(&image->mt); radeon_miptree_unreference(&image->mt);
} else if (image->base.Base.Data) { } else if (image->base.Data) {
/* This condition should be removed, it's here to workaround /* This condition should be removed, it's here to workaround
* a segfault when mapping textures during software fallbacks. * a segfault when mapping textures during software fallbacks.
*/ */
@@ -496,11 +496,11 @@ static void migrate_image_to_miptree(radeon_mipmap_tree *mt,
rows = (rows + blockHeight - 1) / blockHeight; rows = (rows + blockHeight - 1) / blockHeight;
} }
copy_rows(dest, dstlvl->rowstride, image->base.Base.Data, srcrowstride, copy_rows(dest, dstlvl->rowstride, image->base.Data, srcrowstride,
rows, srcrowstride); rows, srcrowstride);
_mesa_free_texmemory(image->base.Base.Data); _mesa_free_texmemory(image->base.Data);
image->base.Base.Data = 0; image->base.Data = 0;
} }
radeon_bo_unmap(mt->bo); radeon_bo_unmap(mt->bo);

View File

@@ -720,7 +720,7 @@ void radeonSetTexBuffer2(__DRIcontext *pDRICtx, GLint target, GLint texture_form
_mesa_init_teximage_fields(radeon->glCtx, target, texImage, _mesa_init_teximage_fields(radeon->glCtx, target, texImage,
rb->base.Width, rb->base.Height, 1, 0, rb->base.Width, rb->base.Height, 1, 0,
rb->cpp, texFormat); rb->cpp, texFormat);
texImage->RowStride = rb->pitch / rb->cpp; rImage->base.RowStride = rb->pitch / rb->cpp;
t->pp_txpitch &= (1 << 13) -1; t->pp_txpitch &= (1 << 13) -1;
pitch_val = rb->pitch; pitch_val = rb->pitch;

View File

@@ -104,7 +104,7 @@ void radeonFreeTextureImageBuffer(struct gl_context *ctx, struct gl_texture_imag
if (image->mt) { if (image->mt) {
radeon_miptree_unreference(&image->mt); radeon_miptree_unreference(&image->mt);
assert(!image->base.Base.Data); assert(!image->base.Data);
} else { } else {
_mesa_free_texture_image_data(ctx, timage); _mesa_free_texture_image_data(ctx, timage);
} }
@@ -112,9 +112,14 @@ void radeonFreeTextureImageBuffer(struct gl_context *ctx, struct gl_texture_imag
radeon_bo_unref(image->bo); radeon_bo_unref(image->bo);
image->bo = NULL; image->bo = NULL;
} }
if (timage->Data) { if (image->base.Data) {
_mesa_free_texmemory(timage->Data); _mesa_free_texmemory(image->base.Data);
timage->Data = NULL; image->base.Data = NULL;
}
if (image->base.ImageOffsets) {
free(image->base.ImageOffsets);
image->base.ImageOffsets = NULL;
} }
} }
@@ -132,8 +137,8 @@ static void teximage_set_map_data(radeon_texture_image *image)
lvl = &image->mt->levels[image->mtlevel]; lvl = &image->mt->levels[image->mtlevel];
image->base.Base.Data = image->mt->bo->ptr + lvl->faces[image->mtface].offset; image->base.Data = image->mt->bo->ptr + lvl->faces[image->mtface].offset;
image->base.Base.RowStride = lvl->rowstride / _mesa_get_format_bytes(image->base.Base.TexFormat); image->base.RowStride = lvl->rowstride / _mesa_get_format_bytes(image->base.Base.TexFormat);
} }
@@ -147,7 +152,7 @@ void radeon_teximage_map(radeon_texture_image *image, GLboolean write_enable)
__func__, image, __func__, image,
write_enable ? "true": "false"); write_enable ? "true": "false");
if (image->mt) { if (image->mt) {
assert(!image->base.Base.Data); assert(!image->base.Data);
radeon_bo_map(image->mt->bo, write_enable); radeon_bo_map(image->mt->bo, write_enable);
teximage_set_map_data(image); teximage_set_map_data(image);
@@ -161,9 +166,9 @@ void radeon_teximage_unmap(radeon_texture_image *image)
"%s(img %p)\n", "%s(img %p)\n",
__func__, image); __func__, image);
if (image->mt) { if (image->mt) {
assert(image->base.Base.Data); assert(image->base.Data);
image->base.Base.Data = 0; image->base.Data = 0;
radeon_bo_unmap(image->mt->bo); radeon_bo_unmap(image->mt->bo);
} }
} }
@@ -174,7 +179,7 @@ static void map_override(struct gl_context *ctx, radeonTexObj *t)
radeon_bo_map(t->bo, GL_FALSE); radeon_bo_map(t->bo, GL_FALSE);
img->base.Base.Data = t->bo->ptr; img->base.Data = t->bo->ptr;
} }
static void unmap_override(struct gl_context *ctx, radeonTexObj *t) static void unmap_override(struct gl_context *ctx, radeonTexObj *t)
@@ -183,7 +188,7 @@ static void unmap_override(struct gl_context *ctx, radeonTexObj *t)
radeon_bo_unmap(t->bo); radeon_bo_unmap(t->bo);
img->base.Base.Data = NULL; img->base.Data = NULL;
} }
/** /**
@@ -243,8 +248,11 @@ void radeonUnmapTexture(struct gl_context *ctx, struct gl_texture_object *texObj
return; return;
for(face = 0; face < t->mt->faces; ++face) { for(face = 0; face < t->mt->faces; ++face) {
for(level = t->minLod; level <= t->maxLod; ++level) for(level = t->minLod; level <= t->maxLod; ++level) {
texObj->Image[face][level]->Data = 0; radeon_texture_image *image =
get_radeon_texture_image(texObj->Image[face][level]);
image->base.Data = NULL;
}
} }
radeon_bo_unmap(t->mt->bo); radeon_bo_unmap(t->mt->bo);
} }
@@ -306,7 +314,7 @@ radeon_map_texture_image(struct gl_context *ctx,
assert(map); assert(map);
*stride = _mesa_format_row_stride(texImage->TexFormat, width); *stride = _mesa_format_row_stride(texImage->TexFormat, width);
*map = texImage->Data + (slice * height) * *stride; *map = image->base.Data + (slice * height) * *stride;
} }
*map += y * *stride + x * texel_size; *map += y * *stride + x * texel_size;
@@ -690,26 +698,6 @@ static void teximage_assign_miptree(radeonContextPtr rmesa,
"%s Failed to allocate miptree.\n", __func__); "%s Failed to allocate miptree.\n", __func__);
} }
static GLuint * allocate_image_offsets(struct gl_context *ctx,
unsigned alignedWidth,
unsigned height,
unsigned depth)
{
int i;
GLuint *offsets;
offsets = malloc(depth * sizeof(GLuint)) ;
if (!offsets) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glTex[Sub]Image");
return NULL;
}
for (i = 0; i < depth; ++i) {
offsets[i] = alignedWidth * height * i;
}
return offsets;
}
/** /**
* Update a subregion of the given texture image. * Update a subregion of the given texture image.
@@ -728,9 +716,11 @@ static void radeon_store_teximage(struct gl_context* ctx, int dims,
radeonContextPtr rmesa = RADEON_CONTEXT(ctx); radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
radeonTexObj *t = radeon_tex_obj(texObj); radeonTexObj *t = radeon_tex_obj(texObj);
radeon_texture_image* image = get_radeon_texture_image(texImage); radeon_texture_image* image = get_radeon_texture_image(texImage);
GLuint texel_size = _mesa_get_format_bytes(texImage->TexFormat);
GLuint dstRowStride; GLuint dstRowStride;
GLuint *dstImageOffsets; GLuint alignedWidth;
GLint i;
radeon_print(RADEON_TEXTURE, RADEON_TRACE, radeon_print(RADEON_TEXTURE, RADEON_TRACE,
"%s(%p, tex %p, image %p) compressed %d\n", "%s(%p, tex %p, image %p) compressed %d\n",
@@ -747,16 +737,13 @@ static void radeon_store_teximage(struct gl_context* ctx, int dims,
assert(dstRowStride); assert(dstRowStride);
if (dims == 3) { /* fill in the ImageOffsets array */
unsigned alignedWidth = dstRowStride/_mesa_get_format_bytes(texImage->TexFormat); alignedWidth = dstRowStride / texel_size;
dstImageOffsets = allocate_image_offsets(ctx, alignedWidth, texImage->Height, texImage->Depth); for (i = 0; i < texImage->Depth; ++i) {
if (!dstImageOffsets) { image->base.ImageOffsets[i] = alignedWidth * texImage->Height * i;
radeon_warning("%s Failed to allocate dstImaeOffset.\n", __func__);
return;
}
} else {
dstImageOffsets = texImage->ImageOffsets;
} }
/* and fill in RowStride (in texels) */
image->base.RowStride = alignedWidth;
radeon_teximage_map(image, GL_TRUE); radeon_teximage_map(image, GL_TRUE);
@@ -770,13 +757,13 @@ static void radeon_store_teximage(struct gl_context* ctx, int dims,
dstRowStride = _mesa_format_row_stride(texImage->TexFormat, texImage->Width); dstRowStride = _mesa_format_row_stride(texImage->TexFormat, texImage->Width);
img_start = _mesa_compressed_image_address(xoffset, yoffset, 0, img_start = _mesa_compressed_image_address(xoffset, yoffset, 0,
texImage->TexFormat, texImage->TexFormat,
texImage->Width, texImage->Data); texImage->Width, image->base.Data);
} }
else { else {
uint32_t offset; uint32_t offset;
offset = dstRowStride / _mesa_get_format_bytes(texImage->TexFormat) * yoffset / block_height + xoffset / block_width; offset = dstRowStride / texel_size * yoffset / block_height + xoffset / block_width;
offset *= _mesa_get_format_bytes(texImage->TexFormat); offset *= texel_size;
img_start = texImage->Data + offset; img_start = image->base.Data + offset;
} }
srcRowStride = _mesa_format_row_stride(texImage->TexFormat, width); srcRowStride = _mesa_format_row_stride(texImage->TexFormat, width);
bytesPerRow = srcRowStride; bytesPerRow = srcRowStride;
@@ -786,12 +773,11 @@ static void radeon_store_teximage(struct gl_context* ctx, int dims,
} }
else { else {
GLubyte *slices[512]; GLubyte *slices[512];
GLuint texelBytes = _mesa_get_format_bytes(texImage->TexFormat);
GLuint i; GLuint i;
assert(depth <= 512); assert(depth <= 512);
for (i = 0; i < depth; i++) { for (i = 0; i < depth; i++) {
slices[i] = (GLubyte *) texImage->Data slices[i] = (GLubyte *) image->base.Data
+ dstImageOffsets[i] * texelBytes; + image->base.ImageOffsets[i] * texel_size;
} }
if (!_mesa_texstore(ctx, dims, texImage->_BaseFormat, if (!_mesa_texstore(ctx, dims, texImage->_BaseFormat,
texImage->TexFormat, texImage->TexFormat,
@@ -804,10 +790,6 @@ static void radeon_store_teximage(struct gl_context* ctx, int dims,
} }
} }
if (dims == 3) {
free(dstImageOffsets);
}
radeon_teximage_unmap(image); radeon_teximage_unmap(image);
} }
@@ -837,7 +819,6 @@ static void radeon_teximage(
t->validated = GL_FALSE; t->validated = GL_FALSE;
/* Mesa core only clears texImage->Data but not image->mt */
radeonFreeTextureImageBuffer(ctx, texImage); radeonFreeTextureImageBuffer(ctx, texImage);
if (!t->bo) { if (!t->bo) {
@@ -847,11 +828,11 @@ static void radeon_teximage(
texImage->Width, texImage->Width,
texImage->Height, texImage->Height,
texImage->Depth); texImage->Depth);
texImage->Data = _mesa_alloc_texmemory(size); image->base.Data = _mesa_alloc_texmemory(size);
radeon_print(RADEON_TEXTURE, RADEON_VERBOSE, radeon_print(RADEON_TEXTURE, RADEON_VERBOSE,
"%s %dd: texObj %p, texImage %p, " "%s %dd: texObj %p, texImage %p, "
" no miptree assigned, using local memory %p\n", " no miptree assigned, using local memory %p\n",
__func__, dims, texObj, texImage, texImage->Data); __func__, dims, texObj, texImage, image->base.Data);
} }
} }
@@ -867,6 +848,10 @@ static void radeon_teximage(
} }
} }
image->base.ImageOffsets =
(GLuint *) malloc(texImage->Depth * sizeof(GLuint));
/* Upload texture image; note that the spec allows pixels to be NULL */ /* Upload texture image; note that the spec allows pixels to be NULL */
if (compressed) { if (compressed) {
pixels = _mesa_validate_pbo_compressed_teximage( pixels = _mesa_validate_pbo_compressed_teximage(
@@ -1090,7 +1075,7 @@ void radeon_image_target_texture_2d(struct gl_context *ctx, GLenum target,
texImage->Depth = 1; texImage->Depth = 1;
texImage->_BaseFormat = GL_RGBA; texImage->_BaseFormat = GL_RGBA;
texImage->TexFormat = image->format; texImage->TexFormat = image->format;
texImage->RowStride = image->pitch; radeonImage->base.RowStride = image->pitch;
texImage->InternalFormat = image->internal_format; texImage->InternalFormat = image->internal_format;
if(t->mt) if(t->mt)

View File

@@ -52,6 +52,7 @@
#include "main/texstate.h" #include "main/texstate.h"
#include "swrast_priv.h" #include "swrast_priv.h"
#include "swrast/s_context.h"
/** /**
@@ -67,6 +68,7 @@ static void swrastSetTexBuffer2(__DRIcontext *pDRICtx, GLint target,
struct gl_texture_unit *texUnit; struct gl_texture_unit *texUnit;
struct gl_texture_object *texObj; struct gl_texture_object *texObj;
struct gl_texture_image *texImage; struct gl_texture_image *texImage;
struct swrast_texture_image *swImage;
uint32_t internalFormat; uint32_t internalFormat;
gl_format texFormat; gl_format texFormat;
@@ -77,6 +79,7 @@ static void swrastSetTexBuffer2(__DRIcontext *pDRICtx, GLint target,
texUnit = _mesa_get_current_tex_unit(&dri_ctx->Base); texUnit = _mesa_get_current_tex_unit(&dri_ctx->Base);
texObj = _mesa_select_tex_object(&dri_ctx->Base, texUnit, target); texObj = _mesa_select_tex_object(&dri_ctx->Base, texUnit, target);
texImage = _mesa_get_tex_image(&dri_ctx->Base, texObj, target, 0); texImage = _mesa_get_tex_image(&dri_ctx->Base, texObj, target, 0);
swImage = swrast_texture_image(texImage);
_mesa_lock_texture(&dri_ctx->Base, texObj); _mesa_lock_texture(&dri_ctx->Base, texObj);
@@ -90,7 +93,7 @@ static void swrastSetTexBuffer2(__DRIcontext *pDRICtx, GLint target,
_mesa_init_teximage_fields(&dri_ctx->Base, target, texImage, _mesa_init_teximage_fields(&dri_ctx->Base, target, texImage,
w, h, 1, 0, internalFormat, texFormat); w, h, 1, 0, internalFormat, texFormat);
sPriv->swrast_loader->getImage(dPriv, x, y, w, h, (char *)texImage->Data, sPriv->swrast_loader->getImage(dPriv, x, y, w, h, (char *)swImage->Data,
dPriv->loaderPrivate); dPriv->loaderPrivate);
_mesa_unlock_texture(&dri_ctx->Base, texObj); _mesa_unlock_texture(&dri_ctx->Base, texObj);

View File

@@ -1261,11 +1261,6 @@ struct gl_texture_image
GLuint Level; /**< Which mipmap level am I? */ GLuint Level; /**< Which mipmap level am I? */
/** Cube map face: index into gl_texture_object::Image[] array */ /** Cube map face: index into gl_texture_object::Image[] array */
GLuint Face; GLuint Face;
GLuint RowStride; /**< Padded width in units of texels */
GLuint *ImageOffsets; /**< if 3D texture: array [Depth] of offsets to
each 2D slice in 'Data', in texels */
GLvoid *Data; /**< Image data, accessed via FetchTexel() */
}; };

View File

@@ -461,8 +461,8 @@ _mesa_decompress_image(gl_format format, GLuint width, GLuint height,
/* setup dummy texture image info */ /* setup dummy texture image info */
memset(&texImage, 0, sizeof(texImage)); memset(&texImage, 0, sizeof(texImage));
texImage.Base.Data = (void *) src; texImage.Data = (void *) src;
texImage.Base.RowStride = srcRowStride; texImage.RowStride = srcRowStride;
switch (format) { switch (format) {
/* DXT formats */ /* DXT formats */

View File

@@ -177,7 +177,7 @@ _mesa_fetch_texel_2d_f_rgba_fxt1( const struct swrast_texture_image *texImage,
/* just sample as GLubyte and convert to float here */ /* just sample as GLubyte and convert to float here */
GLubyte rgba[4]; GLubyte rgba[4];
(void) k; (void) k;
fxt1_decode_1(texImage->Base.Data, texImage->Base.RowStride, i, j, rgba); fxt1_decode_1(texImage->Data, texImage->RowStride, i, j, rgba);
texel[RCOMP] = UBYTE_TO_FLOAT(rgba[RCOMP]); texel[RCOMP] = UBYTE_TO_FLOAT(rgba[RCOMP]);
texel[GCOMP] = UBYTE_TO_FLOAT(rgba[GCOMP]); texel[GCOMP] = UBYTE_TO_FLOAT(rgba[GCOMP]);
texel[BCOMP] = UBYTE_TO_FLOAT(rgba[BCOMP]); texel[BCOMP] = UBYTE_TO_FLOAT(rgba[BCOMP]);
@@ -192,7 +192,7 @@ _mesa_fetch_texel_2d_f_rgb_fxt1( const struct swrast_texture_image *texImage,
/* just sample as GLubyte and convert to float here */ /* just sample as GLubyte and convert to float here */
GLubyte rgba[4]; GLubyte rgba[4];
(void) k; (void) k;
fxt1_decode_1(texImage->Base.Data, texImage->Base.RowStride, i, j, rgba); fxt1_decode_1(texImage->Data, texImage->RowStride, i, j, rgba);
texel[RCOMP] = UBYTE_TO_FLOAT(rgba[RCOMP]); texel[RCOMP] = UBYTE_TO_FLOAT(rgba[RCOMP]);
texel[GCOMP] = UBYTE_TO_FLOAT(rgba[GCOMP]); texel[GCOMP] = UBYTE_TO_FLOAT(rgba[GCOMP]);
texel[BCOMP] = UBYTE_TO_FLOAT(rgba[BCOMP]); texel[BCOMP] = UBYTE_TO_FLOAT(rgba[BCOMP]);

View File

@@ -325,7 +325,7 @@ _mesa_fetch_texel_2d_f_red_rgtc1(const struct swrast_texture_image *texImage,
GLint i, GLint j, GLint k, GLfloat *texel) GLint i, GLint j, GLint k, GLfloat *texel)
{ {
GLubyte red; GLubyte red;
unsigned_fetch_texel_rgtc(texImage->Base.RowStride, (GLubyte *)(texImage->Base.Data), unsigned_fetch_texel_rgtc(texImage->RowStride, texImage->Data,
i, j, &red, 1); i, j, &red, 1);
texel[RCOMP] = UBYTE_TO_FLOAT(red); texel[RCOMP] = UBYTE_TO_FLOAT(red);
texel[GCOMP] = 0.0; texel[GCOMP] = 0.0;
@@ -338,7 +338,7 @@ _mesa_fetch_texel_2d_f_signed_red_rgtc1(const struct swrast_texture_image *texIm
GLint i, GLint j, GLint k, GLfloat *texel) GLint i, GLint j, GLint k, GLfloat *texel)
{ {
GLbyte red; GLbyte red;
signed_fetch_texel_rgtc(texImage->Base.RowStride, (GLbyte *)(texImage->Base.Data), signed_fetch_texel_rgtc(texImage->RowStride, (GLbyte *)(texImage->Data),
i, j, &red, 1); i, j, &red, 1);
texel[RCOMP] = BYTE_TO_FLOAT_TEX(red); texel[RCOMP] = BYTE_TO_FLOAT_TEX(red);
texel[GCOMP] = 0.0; texel[GCOMP] = 0.0;
@@ -351,9 +351,9 @@ _mesa_fetch_texel_2d_f_rg_rgtc2(const struct swrast_texture_image *texImage,
GLint i, GLint j, GLint k, GLfloat *texel) GLint i, GLint j, GLint k, GLfloat *texel)
{ {
GLubyte red, green; GLubyte red, green;
unsigned_fetch_texel_rgtc(texImage->Base.RowStride, (GLubyte *)(texImage->Base.Data), unsigned_fetch_texel_rgtc(texImage->RowStride, texImage->Data,
i, j, &red, 2); i, j, &red, 2);
unsigned_fetch_texel_rgtc(texImage->Base.RowStride, (GLubyte *)(texImage->Base.Data) + 8, unsigned_fetch_texel_rgtc(texImage->RowStride, texImage->Data + 8,
i, j, &green, 2); i, j, &green, 2);
texel[RCOMP] = UBYTE_TO_FLOAT(red); texel[RCOMP] = UBYTE_TO_FLOAT(red);
texel[GCOMP] = UBYTE_TO_FLOAT(green); texel[GCOMP] = UBYTE_TO_FLOAT(green);
@@ -366,9 +366,9 @@ _mesa_fetch_texel_2d_f_signed_rg_rgtc2(const struct swrast_texture_image *texIma
GLint i, GLint j, GLint k, GLfloat *texel) GLint i, GLint j, GLint k, GLfloat *texel)
{ {
GLbyte red, green; GLbyte red, green;
signed_fetch_texel_rgtc(texImage->Base.RowStride, (GLbyte *)(texImage->Base.Data), signed_fetch_texel_rgtc(texImage->RowStride, (GLbyte *)(texImage->Data),
i, j, &red, 2); i, j, &red, 2);
signed_fetch_texel_rgtc(texImage->Base.RowStride, (GLbyte *)(texImage->Base.Data) + 8, signed_fetch_texel_rgtc(texImage->RowStride, (GLbyte *)(texImage->Data) + 8,
i, j, &green, 2); i, j, &green, 2);
texel[RCOMP] = BYTE_TO_FLOAT_TEX(red); texel[RCOMP] = BYTE_TO_FLOAT_TEX(red);
texel[GCOMP] = BYTE_TO_FLOAT_TEX(green); texel[GCOMP] = BYTE_TO_FLOAT_TEX(green);
@@ -381,7 +381,7 @@ _mesa_fetch_texel_2d_f_l_latc1(const struct swrast_texture_image *texImage,
GLint i, GLint j, GLint k, GLfloat *texel) GLint i, GLint j, GLint k, GLfloat *texel)
{ {
GLubyte red; GLubyte red;
unsigned_fetch_texel_rgtc(texImage->Base.RowStride, (GLubyte *)(texImage->Base.Data), unsigned_fetch_texel_rgtc(texImage->RowStride, texImage->Data,
i, j, &red, 1); i, j, &red, 1);
texel[RCOMP] = texel[RCOMP] =
texel[GCOMP] = texel[GCOMP] =
@@ -394,7 +394,7 @@ _mesa_fetch_texel_2d_f_signed_l_latc1(const struct swrast_texture_image *texImag
GLint i, GLint j, GLint k, GLfloat *texel) GLint i, GLint j, GLint k, GLfloat *texel)
{ {
GLbyte red; GLbyte red;
signed_fetch_texel_rgtc(texImage->Base.RowStride, (GLbyte *)(texImage->Base.Data), signed_fetch_texel_rgtc(texImage->RowStride, (GLbyte *)(texImage->Data),
i, j, &red, 1); i, j, &red, 1);
texel[RCOMP] = texel[RCOMP] =
texel[GCOMP] = texel[GCOMP] =
@@ -407,9 +407,9 @@ _mesa_fetch_texel_2d_f_la_latc2(const struct swrast_texture_image *texImage,
GLint i, GLint j, GLint k, GLfloat *texel) GLint i, GLint j, GLint k, GLfloat *texel)
{ {
GLubyte red, green; GLubyte red, green;
unsigned_fetch_texel_rgtc(texImage->Base.RowStride, (GLubyte *)(texImage->Base.Data), unsigned_fetch_texel_rgtc(texImage->RowStride, texImage->Data,
i, j, &red, 2); i, j, &red, 2);
unsigned_fetch_texel_rgtc(texImage->Base.RowStride, (GLubyte *)(texImage->Base.Data) + 8, unsigned_fetch_texel_rgtc(texImage->RowStride, texImage->Data + 8,
i, j, &green, 2); i, j, &green, 2);
texel[RCOMP] = texel[RCOMP] =
texel[GCOMP] = texel[GCOMP] =
@@ -422,9 +422,9 @@ _mesa_fetch_texel_2d_f_signed_la_latc2(const struct swrast_texture_image *texIma
GLint i, GLint j, GLint k, GLfloat *texel) GLint i, GLint j, GLint k, GLfloat *texel)
{ {
GLbyte red, green; GLbyte red, green;
signed_fetch_texel_rgtc(texImage->Base.RowStride, (GLbyte *)(texImage->Base.Data), signed_fetch_texel_rgtc(texImage->RowStride, (GLbyte *)(texImage->Data),
i, j, &red, 2); i, j, &red, 2);
signed_fetch_texel_rgtc(texImage->Base.RowStride, (GLbyte *)(texImage->Base.Data) + 8, signed_fetch_texel_rgtc(texImage->RowStride, (GLbyte *)(texImage->Data) + 8,
i, j, &green, 2); i, j, &green, 2);
texel[RCOMP] = texel[RCOMP] =
texel[GCOMP] = texel[GCOMP] =

View File

@@ -398,8 +398,8 @@ fetch_texel_2d_rgb_dxt1( const struct swrast_texture_image *texImage,
{ {
(void) k; (void) k;
if (fetch_ext_rgb_dxt1) { if (fetch_ext_rgb_dxt1) {
fetch_ext_rgb_dxt1(texImage->Base.RowStride, fetch_ext_rgb_dxt1(texImage->RowStride,
(GLubyte *)(texImage)->Base.Data, i, j, texel); texImage->Data, i, j, texel);
} }
else else
_mesa_debug(NULL, "attempted to decode s3tc texture without library available: fetch_texel_2d_rgb_dxt1"); _mesa_debug(NULL, "attempted to decode s3tc texture without library available: fetch_texel_2d_rgb_dxt1");
@@ -426,8 +426,8 @@ fetch_texel_2d_rgba_dxt1( const struct swrast_texture_image *texImage,
{ {
(void) k; (void) k;
if (fetch_ext_rgba_dxt1) { if (fetch_ext_rgba_dxt1) {
fetch_ext_rgba_dxt1(texImage->Base.RowStride, fetch_ext_rgba_dxt1(texImage->RowStride,
(GLubyte *)(texImage)->Base.Data, i, j, texel); texImage->Data, i, j, texel);
} }
else else
_mesa_debug(NULL, "attempted to decode s3tc texture without library available: fetch_texel_2d_rgba_dxt1\n"); _mesa_debug(NULL, "attempted to decode s3tc texture without library available: fetch_texel_2d_rgba_dxt1\n");
@@ -454,9 +454,8 @@ fetch_texel_2d_rgba_dxt3( const struct swrast_texture_image *texImage,
{ {
(void) k; (void) k;
if (fetch_ext_rgba_dxt3) { if (fetch_ext_rgba_dxt3) {
fetch_ext_rgba_dxt3(texImage->Base.RowStride, fetch_ext_rgba_dxt3(texImage->RowStride,
(GLubyte *)(texImage)->Base.Data, texImage->Data, i, j, texel);
i, j, texel);
} }
else else
_mesa_debug(NULL, "attempted to decode s3tc texture without library available: fetch_texel_2d_rgba_dxt3\n"); _mesa_debug(NULL, "attempted to decode s3tc texture without library available: fetch_texel_2d_rgba_dxt3\n");
@@ -483,9 +482,8 @@ fetch_texel_2d_rgba_dxt5( const struct swrast_texture_image *texImage,
{ {
(void) k; (void) k;
if (fetch_ext_rgba_dxt5) { if (fetch_ext_rgba_dxt5) {
fetch_ext_rgba_dxt5(texImage->Base.RowStride, fetch_ext_rgba_dxt5(texImage->RowStride,
(GLubyte *)(texImage)->Base.Data, texImage->Data, i, j, texel);
i, j, texel);
} }
else else
_mesa_debug(NULL, "attempted to decode s3tc texture without library available: fetch_texel_2d_rgba_dxt5\n"); _mesa_debug(NULL, "attempted to decode s3tc texture without library available: fetch_texel_2d_rgba_dxt5\n");

View File

@@ -612,12 +612,14 @@ _mesa_free_texture_image_data(struct gl_context *ctx,
{ {
(void) ctx; (void) ctx;
#if 0
if (texImage->Data) { if (texImage->Data) {
/* free the old texture data */ /* free the old texture data */
_mesa_free_texmemory(texImage->Data); _mesa_free_texmemory(texImage->Data);
} }
texImage->Data = NULL; texImage->Data = NULL;
#endif
} }
@@ -639,10 +641,12 @@ _mesa_delete_texture_image(struct gl_context *ctx,
ASSERT(ctx->Driver.FreeTextureImageBuffer); ASSERT(ctx->Driver.FreeTextureImageBuffer);
ctx->Driver.FreeTextureImageBuffer( ctx, texImage ); ctx->Driver.FreeTextureImageBuffer( ctx, texImage );
#if 0
ASSERT(texImage->Data == NULL); ASSERT(texImage->Data == NULL);
if (texImage->ImageOffsets) if (texImage->ImageOffsets)
free(texImage->ImageOffsets); free(texImage->ImageOffsets);
free(texImage); free(texImage);
#endif
} }
@@ -1084,18 +1088,19 @@ clear_teximage_fields(struct gl_texture_image *img)
img->Width = 0; img->Width = 0;
img->Height = 0; img->Height = 0;
img->Depth = 0; img->Depth = 0;
#if 0
img->RowStride = 0; img->RowStride = 0;
if (img->ImageOffsets) { if (img->ImageOffsets) {
free(img->ImageOffsets); free(img->ImageOffsets);
img->ImageOffsets = NULL; img->ImageOffsets = NULL;
} }
#endif
img->Width2 = 0; img->Width2 = 0;
img->Height2 = 0; img->Height2 = 0;
img->Depth2 = 0; img->Depth2 = 0;
img->WidthLog2 = 0; img->WidthLog2 = 0;
img->HeightLog2 = 0; img->HeightLog2 = 0;
img->DepthLog2 = 0; img->DepthLog2 = 0;
img->Data = NULL;
img->TexFormat = MESA_FORMAT_NONE; img->TexFormat = MESA_FORMAT_NONE;
} }
@@ -1123,8 +1128,6 @@ _mesa_init_teximage_fields(struct gl_context *ctx, GLenum target,
GLint border, GLenum internalFormat, GLint border, GLenum internalFormat,
gl_format format) gl_format format)
{ {
GLint i;
ASSERT(img); ASSERT(img);
ASSERT(width >= 0); ASSERT(width >= 0);
ASSERT(height >= 0); ASSERT(height >= 0);
@@ -1161,6 +1164,7 @@ _mesa_init_teximage_fields(struct gl_context *ctx, GLenum target,
img->MaxLog2 = MAX2(img->WidthLog2, img->HeightLog2); img->MaxLog2 = MAX2(img->WidthLog2, img->HeightLog2);
#if 0
/* RowStride and ImageOffsets[] describe how to address texels in 'Data' */ /* RowStride and ImageOffsets[] describe how to address texels in 'Data' */
img->RowStride = width; img->RowStride = width;
/* Allocate the ImageOffsets array and initialize to typical values. /* Allocate the ImageOffsets array and initialize to typical values.
@@ -1173,6 +1177,7 @@ _mesa_init_teximage_fields(struct gl_context *ctx, GLenum target,
for (i = 0; i < depth; i++) { for (i = 0; i < depth; i++) {
img->ImageOffsets[i] = i * width * height; img->ImageOffsets[i] = i * width * height;
} }
#endif
img->TexFormat = format; img->TexFormat = format;
} }
@@ -2409,7 +2414,6 @@ teximage(struct gl_context *ctx, GLuint dims,
ctx->Driver.FreeTextureImageBuffer(ctx, texImage); ctx->Driver.FreeTextureImageBuffer(ctx, texImage);
ASSERT(texImage->Data == NULL);
texFormat = _mesa_choose_texture_format(ctx, texObj, target, level, texFormat = _mesa_choose_texture_format(ctx, texObj, target, level,
internalFormat, format, internalFormat, format,
type); type);
@@ -2548,7 +2552,6 @@ _mesa_EGLImageTargetTexture2DOES (GLenum target, GLeglImageOES image)
} else { } else {
ctx->Driver.FreeTextureImageBuffer(ctx, texImage); ctx->Driver.FreeTextureImageBuffer(ctx, texImage);
ASSERT(texImage->Data == NULL);
ctx->Driver.EGLImageTargetTexture2D(ctx, target, ctx->Driver.EGLImageTargetTexture2D(ctx, target,
texObj, texImage, image); texObj, texImage, image);
@@ -3370,7 +3373,6 @@ compressedteximage(struct gl_context *ctx, GLuint dims,
gl_format texFormat; gl_format texFormat;
ctx->Driver.FreeTextureImageBuffer(ctx, texImage); ctx->Driver.FreeTextureImageBuffer(ctx, texImage);
ASSERT(texImage->Data == NULL);
texFormat = _mesa_choose_texture_format(ctx, texObj, target, level, texFormat = _mesa_choose_texture_format(ctx, texObj, target, level,
internalFormat, GL_NONE, internalFormat, GL_NONE,

View File

@@ -4906,7 +4906,6 @@ _mesa_store_compressed_teximage2d(struct gl_context *ctx,
ASSERT(texImage->Width > 0); ASSERT(texImage->Width > 0);
ASSERT(texImage->Height > 0); ASSERT(texImage->Height > 0);
ASSERT(texImage->Depth == 1); ASSERT(texImage->Depth == 1);
ASSERT(texImage->Data == NULL); /* was freed in glCompressedTexImage2DARB */
/* allocate storage for texture data */ /* allocate storage for texture data */
if (!ctx->Driver.AllocTextureImageBuffer(ctx, texImage, texImage->TexFormat, if (!ctx->Driver.AllocTextureImageBuffer(ctx, texImage, texImage->TexFormat,

View File

@@ -138,20 +138,14 @@ struct swrast_texture_image
/** used for mipmap LOD computation */ /** used for mipmap LOD computation */
GLfloat WidthScale, HeightScale, DepthScale; GLfloat WidthScale, HeightScale, DepthScale;
#if 0 /** These fields only valid when texture memory is mapped */
GLubyte *Data; /**< The actual texture data in malloc'd memory */ GLint RowStride; /**< Padded width in units of texels */
GLuint *ImageOffsets; /**< if 3D texture: array [Depth] of offsets to
GLint TexelSize; /**< bytes per texel block */ each 2D slice in 'Data', in texels */
#endif GLubyte *Data; /**< Image data, accessed via FetchTexel() */
FetchTexelFunc FetchTexel; FetchTexelFunc FetchTexel;
StoreTexelFunc Store; StoreTexelFunc Store;
#if 0
/** These fields only valid when texture memory is mapped */
GLubyte **SliceMaps; /**< points to OneMap or a malloc'd array */
GLint RowStride; /**< bytes per row of blocks */
#endif
}; };

View File

@@ -43,7 +43,7 @@
#if DIM == 1 #if DIM == 1
#define TEXEL_ADDR( type, image, i, j, k, size ) \ #define TEXEL_ADDR( type, image, i, j, k, size ) \
((void) (j), (void) (k), ((type *)(image)->Base.Data + (i) * (size))) ((void) (j), (void) (k), ((type *)(image)->Data + (i) * (size)))
#define FETCH(x) fetch_texel_1d_##x #define FETCH(x) fetch_texel_1d_##x
@@ -51,15 +51,15 @@
#define TEXEL_ADDR( type, image, i, j, k, size ) \ #define TEXEL_ADDR( type, image, i, j, k, size ) \
((void) (k), \ ((void) (k), \
((type *)(image)->Base.Data + ((image)->Base.RowStride * (j) + (i)) * (size))) ((type *)(image)->Data + ((image)->RowStride * (j) + (i)) * (size)))
#define FETCH(x) fetch_texel_2d_##x #define FETCH(x) fetch_texel_2d_##x
#elif DIM == 3 #elif DIM == 3
#define TEXEL_ADDR( type, image, i, j, k, size ) \ #define TEXEL_ADDR( type, image, i, j, k, size ) \
((type *)(image)->Base.Data + ((image)->Base.ImageOffsets[k] \ ((type *)(image)->Data + ((image)->ImageOffsets[k] \
+ (image)->Base.RowStride * (j) + (i)) * (size)) + (image)->RowStride * (j) + (i)) * (size))
#define FETCH(x) fetch_texel_3d_##x #define FETCH(x) fetch_texel_3d_##x

View File

@@ -1375,7 +1375,7 @@ opt_sample_rgb_2d(struct gl_context *ctx,
GLint i = IFLOOR(texcoords[k][0] * width) & colMask; GLint i = IFLOOR(texcoords[k][0] * width) & colMask;
GLint j = IFLOOR(texcoords[k][1] * height) & rowMask; GLint j = IFLOOR(texcoords[k][1] * height) & rowMask;
GLint pos = (j << shift) | i; GLint pos = (j << shift) | i;
GLubyte *texel = ((GLubyte *) img->Data) + 3*pos; GLubyte *texel = swImg->Data + 3 * pos;
rgba[k][RCOMP] = UBYTE_TO_FLOAT(texel[2]); rgba[k][RCOMP] = UBYTE_TO_FLOAT(texel[2]);
rgba[k][GCOMP] = UBYTE_TO_FLOAT(texel[1]); rgba[k][GCOMP] = UBYTE_TO_FLOAT(texel[1]);
rgba[k][BCOMP] = UBYTE_TO_FLOAT(texel[0]); rgba[k][BCOMP] = UBYTE_TO_FLOAT(texel[0]);
@@ -1419,7 +1419,7 @@ opt_sample_rgba_2d(struct gl_context *ctx,
const GLint col = IFLOOR(texcoords[i][0] * width) & colMask; const GLint col = IFLOOR(texcoords[i][0] * width) & colMask;
const GLint row = IFLOOR(texcoords[i][1] * height) & rowMask; const GLint row = IFLOOR(texcoords[i][1] * height) & rowMask;
const GLint pos = (row << shift) | col; const GLint pos = (row << shift) | col;
const GLuint texel = *((GLuint *) img->Data + pos); const GLuint texel = *((GLuint *) swImg->Data + pos);
rgba[i][RCOMP] = UBYTE_TO_FLOAT( (texel >> 24) ); rgba[i][RCOMP] = UBYTE_TO_FLOAT( (texel >> 24) );
rgba[i][GCOMP] = UBYTE_TO_FLOAT( (texel >> 16) & 0xff ); rgba[i][GCOMP] = UBYTE_TO_FLOAT( (texel >> 16) & 0xff );
rgba[i][BCOMP] = UBYTE_TO_FLOAT( (texel >> 8) & 0xff ); rgba[i][BCOMP] = UBYTE_TO_FLOAT( (texel >> 8) & 0xff );
@@ -1442,7 +1442,7 @@ sample_lambda_2d(struct gl_context *ctx,
const GLboolean repeatNoBorderPOT = (tObj->Sampler.WrapS == GL_REPEAT) const GLboolean repeatNoBorderPOT = (tObj->Sampler.WrapS == GL_REPEAT)
&& (tObj->Sampler.WrapT == GL_REPEAT) && (tObj->Sampler.WrapT == GL_REPEAT)
&& (tImg->Border == 0 && (tImg->Width == tImg->RowStride)) && (tImg->Border == 0 && (tImg->Width == swImg->RowStride))
&& swImg->_IsPowerOfTwo; && swImg->_IsPowerOfTwo;
ASSERT(lambda != NULL); ASSERT(lambda != NULL);

View File

@@ -610,7 +610,7 @@ update_wrapper(struct gl_context *ctx, struct gl_renderbuffer_attachment *att)
trb->Base.DataType = CHAN_TYPE; trb->Base.DataType = CHAN_TYPE;
trb->Base._BaseFormat = GL_RGBA; trb->Base._BaseFormat = GL_RGBA;
} }
trb->Base.Data = trb->TexImage->Base.Data; trb->Base.Data = trb->TexImage->Data;
} }

View File

@@ -69,14 +69,32 @@ _swrast_alloc_texture_image_buffer(struct gl_context *ctx,
{ {
struct swrast_texture_image *swImg = swrast_texture_image(texImage); struct swrast_texture_image *swImg = swrast_texture_image(texImage);
GLuint bytes = _mesa_format_image_size(format, width, height, depth); GLuint bytes = _mesa_format_image_size(format, width, height, depth);
GLuint i;
/* This _should_ be true (revisit if these ever fail) */ /* This _should_ be true (revisit if these ever fail) */
assert(texImage->Width == width); assert(texImage->Width == width);
assert(texImage->Height == height); assert(texImage->Height == height);
assert(texImage->Depth == depth); assert(texImage->Depth == depth);
assert(!texImage->Data); assert(!swImg->Data);
texImage->Data = _mesa_align_malloc(bytes, 512); swImg->Data = _mesa_align_malloc(bytes, 512);
if (!swImg->Data)
return GL_FALSE;
/* RowStride and ImageOffsets[] describe how to address texels in 'Data' */
swImg->RowStride = width;
/* Allocate the ImageOffsets array and initialize to typical values.
* We allocate the array for 1D/2D textures too in order to avoid special-
* case code in the texstore routines.
*/
swImg->ImageOffsets = (GLuint *) malloc(depth * sizeof(GLuint));
if (!swImg->ImageOffsets)
return GL_FALSE;
for (i = 0; i < depth; i++) {
swImg->ImageOffsets[i] = i * width * height;
}
if ((width == 1 || _mesa_is_pow_two(texImage->Width2)) && if ((width == 1 || _mesa_is_pow_two(texImage->Width2)) &&
(height == 1 || _mesa_is_pow_two(texImage->Height2)) && (height == 1 || _mesa_is_pow_two(texImage->Height2)) &&
@@ -98,7 +116,7 @@ _swrast_alloc_texture_image_buffer(struct gl_context *ctx,
swImg->DepthScale = (GLfloat) texImage->Depth; swImg->DepthScale = (GLfloat) texImage->Depth;
} }
return texImage->Data != NULL; return GL_TRUE;
} }
@@ -109,11 +127,16 @@ void
_swrast_free_texture_image_buffer(struct gl_context *ctx, _swrast_free_texture_image_buffer(struct gl_context *ctx,
struct gl_texture_image *texImage) struct gl_texture_image *texImage)
{ {
if (texImage->Data) { struct swrast_texture_image *swImage = swrast_texture_image(texImage);
_mesa_align_free(texImage->Data); if (swImage->Data) {
_mesa_align_free(swImage->Data);
swImage->Data = NULL;
} }
texImage->Data = NULL; if (swImage->ImageOffsets) {
free(swImage->ImageOffsets);
swImage->ImageOffsets = NULL;
}
} }
@@ -155,6 +178,7 @@ _swrast_map_teximage(struct gl_context *ctx,
GLubyte **mapOut, GLubyte **mapOut,
GLint *rowStrideOut) GLint *rowStrideOut)
{ {
struct swrast_texture_image *swImage = swrast_texture_image(texImage);
GLubyte *map; GLubyte *map;
GLint stride, texelSize; GLint stride, texelSize;
GLuint bw, bh; GLuint bw, bh;
@@ -165,9 +189,9 @@ _swrast_map_teximage(struct gl_context *ctx,
stride = _mesa_format_row_stride(texImage->TexFormat, texImage->Width); stride = _mesa_format_row_stride(texImage->TexFormat, texImage->Width);
_mesa_get_format_block_size(texImage->TexFormat, &bw, &bh); _mesa_get_format_block_size(texImage->TexFormat, &bw, &bh);
assert(texImage->Data); assert(swImage->Data);
map = texImage->Data; map = swImage->Data;
if (texImage->TexObject->Target == GL_TEXTURE_3D || if (texImage->TexObject->Target == GL_TEXTURE_3D ||
texImage->TexObject->Target == GL_TEXTURE_2D_ARRAY) { texImage->TexObject->Target == GL_TEXTURE_2D_ARRAY) {

View File

@@ -127,10 +127,12 @@ _swrast_culltriangle( struct gl_context *ctx,
ctx->Texture.Unit[0].CurrentTex[TEXTURE_2D_INDEX]; \ ctx->Texture.Unit[0].CurrentTex[TEXTURE_2D_INDEX]; \
const struct gl_texture_image *texImg = \ const struct gl_texture_image *texImg = \
obj->Image[0][obj->BaseLevel]; \ obj->Image[0][obj->BaseLevel]; \
const struct swrast_texture_image *swImg = \
swrast_texture_image_const(texImg); \
const GLfloat twidth = (GLfloat) texImg->Width; \ const GLfloat twidth = (GLfloat) texImg->Width; \
const GLfloat theight = (GLfloat) texImg->Height; \ const GLfloat theight = (GLfloat) texImg->Height; \
const GLint twidth_log2 = texImg->WidthLog2; \ const GLint twidth_log2 = texImg->WidthLog2; \
const GLubyte *texture = (const GLubyte *) texImg->Data; \ const GLubyte *texture = (const GLubyte *) swImg->Data; \
const GLint smask = texImg->Width - 1; \ const GLint smask = texImg->Width - 1; \
const GLint tmask = texImg->Height - 1; \ const GLint tmask = texImg->Height - 1; \
ASSERT(texImg->TexFormat == MESA_FORMAT_RGB888); \ ASSERT(texImg->TexFormat == MESA_FORMAT_RGB888); \
@@ -181,10 +183,12 @@ _swrast_culltriangle( struct gl_context *ctx,
ctx->Texture.Unit[0].CurrentTex[TEXTURE_2D_INDEX]; \ ctx->Texture.Unit[0].CurrentTex[TEXTURE_2D_INDEX]; \
const struct gl_texture_image *texImg = \ const struct gl_texture_image *texImg = \
obj->Image[0][obj->BaseLevel]; \ obj->Image[0][obj->BaseLevel]; \
const struct swrast_texture_image *swImg = \
swrast_texture_image_const(texImg); \
const GLfloat twidth = (GLfloat) texImg->Width; \ const GLfloat twidth = (GLfloat) texImg->Width; \
const GLfloat theight = (GLfloat) texImg->Height; \ const GLfloat theight = (GLfloat) texImg->Height; \
const GLint twidth_log2 = texImg->WidthLog2; \ const GLint twidth_log2 = texImg->WidthLog2; \
const GLubyte *texture = (const GLubyte *) texImg->Data; \ const GLubyte *texture = (const GLubyte *) swImg->Data; \
const GLint smask = texImg->Width - 1; \ const GLint smask = texImg->Width - 1; \
const GLint tmask = texImg->Height - 1; \ const GLint tmask = texImg->Height - 1; \
ASSERT(texImg->TexFormat == MESA_FORMAT_RGB888); \ ASSERT(texImg->TexFormat == MESA_FORMAT_RGB888); \
@@ -533,9 +537,11 @@ affine_span(struct gl_context *ctx, SWspan *span,
ctx->Texture.Unit[0].CurrentTex[TEXTURE_2D_INDEX]; \ ctx->Texture.Unit[0].CurrentTex[TEXTURE_2D_INDEX]; \
const struct gl_texture_image *texImg = \ const struct gl_texture_image *texImg = \
obj->Image[0][obj->BaseLevel]; \ obj->Image[0][obj->BaseLevel]; \
const struct swrast_texture_image *swImg = \
swrast_texture_image_const(texImg); \
const GLfloat twidth = (GLfloat) texImg->Width; \ const GLfloat twidth = (GLfloat) texImg->Width; \
const GLfloat theight = (GLfloat) texImg->Height; \ const GLfloat theight = (GLfloat) texImg->Height; \
info.texture = (const GLchan *) texImg->Data; \ info.texture = (const GLchan *) swImg->Data; \
info.twidth_log2 = texImg->WidthLog2; \ info.twidth_log2 = texImg->WidthLog2; \
info.smask = texImg->Width - 1; \ info.smask = texImg->Width - 1; \
info.tmask = texImg->Height - 1; \ info.tmask = texImg->Height - 1; \
@@ -800,7 +806,9 @@ fast_persp_span(struct gl_context *ctx, SWspan *span,
ctx->Texture.Unit[0].CurrentTex[TEXTURE_2D_INDEX]; \ ctx->Texture.Unit[0].CurrentTex[TEXTURE_2D_INDEX]; \
const struct gl_texture_image *texImg = \ const struct gl_texture_image *texImg = \
obj->Image[0][obj->BaseLevel]; \ obj->Image[0][obj->BaseLevel]; \
info.texture = (const GLchan *) texImg->Data; \ const struct swrast_texture_image *swImg = \
swrast_texture_image_const(texImg); \
info.texture = (const GLchan *) swImg->Data; \
info.twidth_log2 = texImg->WidthLog2; \ info.twidth_log2 = texImg->WidthLog2; \
info.smask = texImg->Width - 1; \ info.smask = texImg->Width - 1; \
info.tmask = texImg->Height - 1; \ info.tmask = texImg->Height - 1; \
@@ -1062,7 +1070,7 @@ _swrast_choose_triangle( struct gl_context *ctx )
&& texObj2D->_Swizzle == SWIZZLE_NOOP && texObj2D->_Swizzle == SWIZZLE_NOOP
&& swImg->_IsPowerOfTwo && swImg->_IsPowerOfTwo
&& texImg->Border == 0 && texImg->Border == 0
&& texImg->Width == texImg->RowStride && texImg->Width == swImg->RowStride
&& (format == MESA_FORMAT_RGB888 || format == MESA_FORMAT_RGBA8888) && (format == MESA_FORMAT_RGB888 || format == MESA_FORMAT_RGBA8888)
&& minFilter == magFilter && minFilter == magFilter
&& ctx->Light.Model.ColorControl == GL_SINGLE_COLOR && ctx->Light.Model.ColorControl == GL_SINGLE_COLOR