summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mesa/state_tracker/st_cb_texture.c330
1 files changed, 89 insertions, 241 deletions
diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c
index d8d2d2aaea..202b69f59d 100644
--- a/src/mesa/state_tracker/st_cb_texture.c
+++ b/src/mesa/state_tracker/st_cb_texture.c
@@ -115,22 +115,7 @@ compressed_num_bytes(GLuint mesaFormat)
}
-static GLboolean
-st_IsTextureResident(GLcontext * ctx, struct gl_texture_object *texObj)
-{
-#if 0
- struct intel_context *intel = intel_context(ctx);
- struct st_texture_object *stObj = st_texture_object(texObj);
-
- return
- stObj->pt &&
- stObj->pt->region &&
- intel_is_region_resident(intel, stObj->pt->region);
-#endif
- return 1;
-}
-
-
+/** called via ctx->Driver.NewTextureImage() */
static struct gl_texture_image *
st_NewTextureImage(GLcontext * ctx)
{
@@ -140,6 +125,7 @@ st_NewTextureImage(GLcontext * ctx)
}
+/** called via ctx->Driver.NewTextureObject() */
static struct gl_texture_object *
st_NewTextureObject(GLcontext * ctx, GLuint name, GLenum target)
{
@@ -151,6 +137,7 @@ st_NewTextureObject(GLcontext * ctx, GLuint name, GLenum target)
return &obj->base;
}
+/** called via ctx->Driver.DeleteTextureImage() */
static void
st_DeleteTextureObject(GLcontext *ctx,
struct gl_texture_object *texObj)
@@ -163,6 +150,7 @@ st_DeleteTextureObject(GLcontext *ctx,
}
+/** called via ctx->Driver.FreeTexImageData() */
static void
st_FreeTextureImageData(GLcontext * ctx, struct gl_texture_image *texImage)
{
@@ -181,7 +169,7 @@ st_FreeTextureImageData(GLcontext * ctx, struct gl_texture_image *texImage)
}
-/* ================================================================
+/**
* From linux kernel i386 header files, copes with odd sizes better
* than COPY_DWORDS would:
* XXX Put this in src/mesa/main/imports.h ???
@@ -207,7 +195,8 @@ __memcpy(void *to, const void *from, size_t n)
#endif
-/* The system memcpy (at least on ubuntu 5.10) has problems copying
+/**
+ * The system memcpy (at least on ubuntu 5.10) has problems copying
* to agp (writecombined) memory from a source which isn't 64-byte
* aligned - there is a 4x performance falloff.
*
@@ -230,25 +219,14 @@ do_memcpy(void *dest, const void *src, size_t n)
}
-/* Functions to store texture images. Where possible, textures
- * will be created or further instantiated with image data, otherwise
- * images will be stored in malloc'd memory. A validation step is
- * required to pull those images into a texture, or otherwise
- * decide a fallback is required.
- */
-
-
static int
logbase2(int n)
{
- GLint i = 1;
- GLint log2 = 0;
-
+ GLint i = 1, log2 = 0;
while (n > i) {
i *= 2;
log2++;
}
-
return log2;
}
@@ -356,94 +334,6 @@ guess_and_alloc_texture(struct st_context *st,
}
-/* There are actually quite a few combinations this will work for,
- * more than what I've listed here.
- */
-static GLboolean
-check_pbo_format(GLint internalFormat,
- GLenum format, GLenum type,
- const struct gl_texture_format *mesa_format)
-{
- switch (internalFormat) {
- case 4:
- case GL_RGBA:
- return (format == GL_BGRA &&
- (type == GL_UNSIGNED_BYTE ||
- type == GL_UNSIGNED_INT_8_8_8_8_REV) &&
- mesa_format == &_mesa_texformat_argb8888);
- case 3:
- case GL_RGB:
- return (format == GL_RGB &&
- type == GL_UNSIGNED_SHORT_5_6_5 &&
- mesa_format == &_mesa_texformat_rgb565);
- case GL_YCBCR_MESA:
- return (type == GL_UNSIGNED_SHORT_8_8_MESA || type == GL_UNSIGNED_BYTE);
- default:
- return GL_FALSE;
- }
-}
-
-
-/* XXX: Do this for TexSubImage also:
- */
-static GLboolean
-try_pbo_upload(GLcontext *ctx,
- struct st_texture_image *stImage,
- const struct gl_pixelstore_attrib *unpack,
- GLint internalFormat,
- GLint width, GLint height,
- GLenum format, GLenum type, const void *pixels)
-{
- return GL_FALSE; /* XXX fix flushing/locking/blitting below */
-#if 000
- struct intel_context *intel = intel_context(ctx);
- struct intel_buffer_object *pbo = intel_buffer_object(unpack->BufferObj);
- GLuint src_offset, src_stride;
- GLuint dst_offset, dst_stride;
-
- if (!pbo ||
- ctx._ImageTransferState ||
- unpack->SkipPixels || unpack->SkipRows) {
- _mesa_printf("%s: failure 1\n", __FUNCTION__);
- return GL_FALSE;
- }
-
- src_offset = (GLuint) pixels;
-
- if (unpack->RowLength > 0)
- src_stride = unpack->RowLength;
- else
- src_stride = width;
-
- dst_offset = st_texture_image_offset(stImage->pt,
- stImage->face,
- stImage->level);
-
- dst_stride = stImage->pt->pitch;
-
- {
- struct _DriBufferObject *src_buffer =
- intel_bufferobj_buffer(intel, pbo, INTEL_READ);
-
- /* Temporary hack: cast to _DriBufferObject:
- */
- struct _DriBufferObject *dst_buffer =
- (struct _DriBufferObject *)stImage->pt->region->buffer;
-
-
- intelEmitCopyBlit(intel,
- stImage->pt->cpp,
- src_stride, src_buffer, src_offset,
- dst_stride, dst_buffer, dst_offset,
- 0, 0, 0, 0, width, height,
- GL_COPY);
- }
-
- return GL_TRUE;
-#endif
-}
-
-
/**
* Adjust pixel unpack params and image dimensions to strip off the
* texture border.
@@ -482,6 +372,9 @@ strip_texture_border(GLint border,
}
+/**
+ * Do glTexImage1/2/3D().
+ */
static void
st_TexImage(GLcontext * ctx,
GLint dims,
@@ -608,36 +501,6 @@ st_TexImage(GLcontext * ctx,
if (!stImage->pt)
DBG("XXX: Image did not fit into texture - storing in local memory!\n");
-#if 0 /* XXX FIX when st_buffer_objects are in place */
- /* PBO fastpaths:
- */
- if (dims <= 2 &&
- stImage->pt &&
- intel_buffer_object(unpack->BufferObj) &&
- check_pbo_format(internalFormat, format,
- type, texImage->TexFormat)) {
-
- DBG("trying pbo upload\n");
-
-
-
- /* Otherwise, attempt to use the blitter for PBO image uploads.
- */
- if (try_pbo_upload(intel, stImage, unpack,
- internalFormat,
- width, height, format, type, pixels)) {
- DBG("pbo upload succeeded\n");
- return;
- }
-
- DBG("pbo upload failed\n");
- }
-#else
- (void) try_pbo_upload;
- (void) check_pbo_format;
-#endif
-
-
/* st_CopyTexImage calls this function with pixels == NULL, with
* the expectation that the texture will be set up but nothing
* more will be done. This is where those calls return:
@@ -734,14 +597,14 @@ st_TexImage(GLcontext * ctx,
static void
st_TexImage3D(GLcontext * ctx,
- GLenum target, GLint level,
- GLint internalFormat,
- GLint width, GLint height, GLint depth,
- GLint border,
- GLenum format, GLenum type, const void *pixels,
- const struct gl_pixelstore_attrib *unpack,
- struct gl_texture_object *texObj,
- struct gl_texture_image *texImage)
+ GLenum target, GLint level,
+ GLint internalFormat,
+ GLint width, GLint height, GLint depth,
+ GLint border,
+ GLenum format, GLenum type, const void *pixels,
+ const struct gl_pixelstore_attrib *unpack,
+ struct gl_texture_object *texObj,
+ struct gl_texture_image *texImage)
{
st_TexImage(ctx, 3, target, level,
internalFormat, width, height, depth, border,
@@ -751,13 +614,13 @@ st_TexImage3D(GLcontext * ctx,
static void
st_TexImage2D(GLcontext * ctx,
- GLenum target, GLint level,
- GLint internalFormat,
- GLint width, GLint height, GLint border,
- GLenum format, GLenum type, const void *pixels,
- const struct gl_pixelstore_attrib *unpack,
- struct gl_texture_object *texObj,
- struct gl_texture_image *texImage)
+ GLenum target, GLint level,
+ GLint internalFormat,
+ GLint width, GLint height, GLint border,
+ GLenum format, GLenum type, const void *pixels,
+ const struct gl_pixelstore_attrib *unpack,
+ struct gl_texture_object *texObj,
+ struct gl_texture_image *texImage)
{
st_TexImage(ctx, 2, target, level,
internalFormat, width, height, 1, border,
@@ -767,13 +630,13 @@ st_TexImage2D(GLcontext * ctx,
static void
st_TexImage1D(GLcontext * ctx,
- GLenum target, GLint level,
- GLint internalFormat,
- GLint width, GLint border,
- GLenum format, GLenum type, const void *pixels,
- const struct gl_pixelstore_attrib *unpack,
- struct gl_texture_object *texObj,
- struct gl_texture_image *texImage)
+ GLenum target, GLint level,
+ GLint internalFormat,
+ GLint width, GLint border,
+ GLenum format, GLenum type, const void *pixels,
+ const struct gl_pixelstore_attrib *unpack,
+ struct gl_texture_object *texObj,
+ struct gl_texture_image *texImage)
{
st_TexImage(ctx, 1, target, level,
internalFormat, width, 1, 1, border,
@@ -782,12 +645,12 @@ st_TexImage1D(GLcontext * ctx,
static void
-st_CompressedTexImage2D( GLcontext *ctx, GLenum target, GLint level,
- GLint internalFormat,
- GLint width, GLint height, GLint border,
- GLsizei imageSize, const GLvoid *data,
- struct gl_texture_object *texObj,
- struct gl_texture_image *texImage )
+st_CompressedTexImage2D(GLcontext *ctx, GLenum target, GLint level,
+ GLint internalFormat,
+ GLint width, GLint height, GLint border,
+ GLsizei imageSize, const GLvoid *data,
+ struct gl_texture_object *texObj,
+ struct gl_texture_image *texImage)
{
st_TexImage(ctx, 2, target, level,
internalFormat, width, height, 1, border,
@@ -806,9 +669,10 @@ st_get_tex_image(GLcontext * ctx, GLenum target, GLint level,
struct gl_texture_image *texImage, int compressed)
{
struct st_texture_image *stImage = st_texture_image(texImage);
- GLuint dstImageStride = _mesa_image_image_stride(&ctx->Pack, texImage->Width,
- texImage->Height, format,
- type);
+ GLuint dstImageStride = _mesa_image_image_stride(&ctx->Pack,
+ texImage->Width,
+ texImage->Height,
+ format, type);
GLuint depth;
GLuint i;
GLubyte *dest;
@@ -868,9 +732,9 @@ st_get_tex_image(GLcontext * ctx, GLenum target, GLint level,
static void
st_GetTexImage(GLcontext * ctx, GLenum target, GLint level,
- GLenum format, GLenum type, GLvoid * pixels,
- struct gl_texture_object *texObj,
- struct gl_texture_image *texImage)
+ GLenum format, GLenum type, GLvoid * pixels,
+ struct gl_texture_object *texObj,
+ struct gl_texture_image *texImage)
{
st_get_tex_image(ctx, target, level, format, type, pixels,
texObj, texImage, 0);
@@ -879,9 +743,9 @@ st_GetTexImage(GLcontext * ctx, GLenum target, GLint level,
static void
st_GetCompressedTexImage(GLcontext *ctx, GLenum target, GLint level,
- GLvoid *pixels,
- const struct gl_texture_object *texObj,
- const struct gl_texture_image *texImage)
+ GLvoid *pixels,
+ const struct gl_texture_object *texObj,
+ const struct gl_texture_image *texImage)
{
st_get_tex_image(ctx, target, level, 0, 0, pixels,
(struct gl_texture_object *) texObj,
@@ -892,14 +756,14 @@ st_GetCompressedTexImage(GLcontext *ctx, GLenum target, GLint level,
static void
st_TexSubimage(GLcontext * ctx,
- GLint dims,
- GLenum target, GLint level,
- GLint xoffset, GLint yoffset, GLint zoffset,
- GLint width, GLint height, GLint depth,
- GLenum format, GLenum type, const void *pixels,
- const struct gl_pixelstore_attrib *packing,
- struct gl_texture_object *texObj,
- struct gl_texture_image *texImage)
+ GLint dims,
+ GLenum target, GLint level,
+ GLint xoffset, GLint yoffset, GLint zoffset,
+ GLint width, GLint height, GLint depth,
+ GLenum format, GLenum type, const void *pixels,
+ const struct gl_pixelstore_attrib *packing,
+ struct gl_texture_object *texObj,
+ struct gl_texture_image *texImage)
{
struct st_texture_image *stImage = st_texture_image(texImage);
GLuint dstRowStride;
@@ -989,7 +853,6 @@ st_TexSubImage3D(GLcontext * ctx,
}
-
static void
st_TexSubImage2D(GLcontext * ctx,
GLenum target,
@@ -1071,8 +934,6 @@ fallback_copy_texsubimage(GLcontext *ctx,
struct pipe_surface *src_surf, *dest_surf;
GLint row, yStep;
- st_flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL);
-
/* determine bottom-to-top vs. top-to-bottom order for src renderbuffer */
if (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP) {
srcY = strb->Base.Height - 1 - srcY;
@@ -1123,18 +984,15 @@ fallback_copy_texsubimage(GLcontext *ctx,
}
-
-
/**
- * Do a CopyTex[Sub]Image using an optimized hardware (blit) path.
- * Note that the region to copy has already been clip tested.
- *
- * Note: srcY=0=Bottom of renderbuffer
+ * Do a CopyTex[Sub]Image1/2/3D() using a hardware (blit) path if possible.
+ * Note that the region to copy has already been clipped so we know we
+ * won't read from outside the source renderbuffer's bounds.
*
- * \return GL_TRUE if success, GL_FALSE if failure (use a fallback)
+ * Note: srcY=0=Bottom of renderbuffer (GL convention)
*/
static void
-do_copy_texsubimage(GLcontext *ctx,
+st_copy_texsubimage(GLcontext *ctx,
GLenum target, GLint level,
GLint destX, GLint destY, GLint destZ,
GLint srcX, GLint srcY,
@@ -1147,7 +1005,7 @@ do_copy_texsubimage(GLcontext *ctx,
struct gl_texture_image *texImage =
_mesa_select_tex_image(ctx, texObj, target, level);
struct st_texture_image *stImage = st_texture_image(texImage);
- GLenum baseFormat = texImage->InternalFormat;
+ const GLenum texBaseFormat = texImage->InternalFormat;
struct gl_framebuffer *fb = ctx->ReadBuffer;
struct st_renderbuffer *strb;
struct pipe_context *pipe = ctx->st->pipe;
@@ -1155,20 +1013,17 @@ do_copy_texsubimage(GLcontext *ctx,
uint dest_format, src_format;
GLboolean use_fallback = GL_TRUE;
- (void) texImage;
-
- /* XX need this?*/
st_flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL);
/* determine if copying depth or color data */
- if (baseFormat == GL_DEPTH_COMPONENT) {
+ if (texBaseFormat == GL_DEPTH_COMPONENT) {
strb = st_renderbuffer(fb->_DepthBuffer);
}
- else if (baseFormat == GL_DEPTH_STENCIL_EXT) {
+ else if (texBaseFormat == GL_DEPTH_STENCIL_EXT) {
strb = st_renderbuffer(fb->_StencilBuffer);
}
else {
- /* baseFormat == GL_RGB, GL_RGBA, GL_ALPHA, etc */
+ /* texBaseFormat == GL_RGB, GL_RGBA, GL_ALPHA, etc */
strb = st_renderbuffer(fb->_ColorReadBuffer);
}
@@ -1192,6 +1047,7 @@ do_copy_texsubimage(GLcontext *ctx,
assert(dest_surface->buffer);
if (src_format == dest_format) {
+ /* use surface_copy() / blit */
boolean do_flip = (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP);
pipe->surface_copy(pipe,
do_flip,
@@ -1205,14 +1061,15 @@ do_copy_texsubimage(GLcontext *ctx,
width, height);
use_fallback = GL_FALSE;
}
- else if (screen->is_format_supported(screen, strb->surface->format,
+ else if (screen->is_format_supported(screen, src_format,
PIPE_TEXTURE_2D,
PIPE_TEXTURE_USAGE_SAMPLER,
0) &&
- screen->is_format_supported(screen, dest_surface->format,
+ screen->is_format_supported(screen, dest_format,
PIPE_TEXTURE_2D,
PIPE_TEXTURE_USAGE_RENDER_TARGET,
0)) {
+ /* draw textured quad to do the copy */
boolean do_flip = (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP);
int srcY0, srcY1;
if (do_flip) {
@@ -1238,8 +1095,9 @@ do_copy_texsubimage(GLcontext *ctx,
}
if (use_fallback) {
+ /* software fallback */
fallback_copy_texsubimage(ctx, target, level,
- strb, stImage, baseFormat,
+ strb, stImage, texBaseFormat,
destX, destY, destZ,
srcX, srcY, width, height);
}
@@ -1276,9 +1134,9 @@ st_CopyTexImage1D(GLcontext * ctx, GLenum target, GLint level,
GL_RGBA, CHAN_TYPE, NULL,
&ctx->DefaultPacking, texObj, texImage);
- do_copy_texsubimage(ctx, target, level,
- 0, 0, 0,
- x, y, width, 1);
+ st_copy_texsubimage(ctx, target, level,
+ 0, 0, 0, /* destX,Y,Z */
+ x, y, width, 1); /* src X, Y, size */
}
@@ -1295,11 +1153,6 @@ st_CopyTexImage2D(GLcontext * ctx, GLenum target, GLint level,
struct gl_texture_image *texImage =
_mesa_select_tex_image(ctx, texObj, target, level);
-#if 0
- if (border)
- goto fail;
-#endif
-
/* Setup or redefine the texture object, texture and texture
* image. Don't populate yet.
*/
@@ -1308,10 +1161,9 @@ st_CopyTexImage2D(GLcontext * ctx, GLenum target, GLint level,
GL_RGBA, CHAN_TYPE, NULL,
&ctx->DefaultPacking, texObj, texImage);
-
- do_copy_texsubimage(ctx, target, level,
- 0, 0, 0,
- x, y, width, height);
+ st_copy_texsubimage(ctx, target, level,
+ 0, 0, 0, /* destX,Y,Z */
+ x, y, width, height); /* src X, Y, size */
}
@@ -1321,9 +1173,9 @@ st_CopyTexSubImage1D(GLcontext * ctx, GLenum target, GLint level,
{
const GLint yoffset = 0, zoffset = 0;
const GLsizei height = 1;
- do_copy_texsubimage(ctx, target, level,
- xoffset, yoffset, zoffset,
- x, y, width, height);
+ st_copy_texsubimage(ctx, target, level,
+ xoffset, yoffset, zoffset, /* destX,Y,Z */
+ x, y, width, height); /* src X, Y, size */
}
@@ -1333,9 +1185,9 @@ st_CopyTexSubImage2D(GLcontext * ctx, GLenum target, GLint level,
GLint x, GLint y, GLsizei width, GLsizei height)
{
const GLint zoffset = 0;
- do_copy_texsubimage(ctx, target, level,
- xoffset, yoffset, zoffset,
- x, y, width, height);
+ st_copy_texsubimage(ctx, target, level,
+ xoffset, yoffset, zoffset, /* destX,Y,Z */
+ x, y, width, height); /* src X, Y, size */
}
@@ -1344,14 +1196,12 @@ st_CopyTexSubImage3D(GLcontext * ctx, GLenum target, GLint level,
GLint xoffset, GLint yoffset, GLint zoffset,
GLint x, GLint y, GLsizei width, GLsizei height)
{
- do_copy_texsubimage(ctx, target, level,
- xoffset, yoffset, zoffset,
- x, y, width, height);
+ st_copy_texsubimage(ctx, target, level,
+ xoffset, yoffset, zoffset, /* destX,Y,Z */
+ x, y, width, height); /* src X, Y, size */
}
-
-
/**
* Compute which mipmap levels that really need to be sent to the hardware.
* This depends on the base image size, GL_TEXTURE_MIN_LOD,
@@ -1383,7 +1233,8 @@ calculate_first_last_level(struct st_texture_object *stObj)
}
else {
firstLevel = 0;
- lastLevel = MIN2(tObj->MaxLevel, (int) tObj->Image[0][tObj->BaseLevel]->WidthLog2);
+ lastLevel = MIN2(tObj->MaxLevel,
+ (int) tObj->Image[0][tObj->BaseLevel]->WidthLog2);
}
break;
case GL_TEXTURE_RECTANGLE_NV:
@@ -1554,8 +1405,6 @@ st_finalize_texture(GLcontext *ctx,
}
-
-
void
st_init_texture_functions(struct dd_function_table *functions)
{
@@ -1585,7 +1434,6 @@ st_init_texture_functions(struct dd_function_table *functions)
functions->DeleteTexture = st_DeleteTextureObject;
functions->FreeTexImageData = st_FreeTextureImageData;
functions->UpdateTexturePalette = 0;
- functions->IsTextureResident = st_IsTextureResident;
functions->TextureMemCpy = do_memcpy;