summaryrefslogtreecommitdiff
path: root/src/mesa/state_tracker
diff options
context:
space:
mode:
Diffstat (limited to 'src/mesa/state_tracker')
-rw-r--r--src/mesa/state_tracker/st_cb_accum.c36
-rw-r--r--src/mesa/state_tracker/st_cb_bufferobjects.c16
-rw-r--r--src/mesa/state_tracker/st_cb_drawpixels.c8
-rw-r--r--src/mesa/state_tracker/st_cb_readpixels.c10
-rw-r--r--src/mesa/state_tracker/st_cb_texture.c283
-rw-r--r--src/mesa/state_tracker/st_format.c20
-rw-r--r--src/mesa/state_tracker/st_format.h4
-rw-r--r--src/mesa/state_tracker/st_gen_mipmap.c7
-rw-r--r--src/mesa/state_tracker/st_program.c6
-rw-r--r--src/mesa/state_tracker/st_texture.c22
-rw-r--r--src/mesa/state_tracker/st_texture.h7
11 files changed, 399 insertions, 20 deletions
diff --git a/src/mesa/state_tracker/st_cb_accum.c b/src/mesa/state_tracker/st_cb_accum.c
index 3f9a825a15..1510a1e236 100644
--- a/src/mesa/state_tracker/st_cb_accum.c
+++ b/src/mesa/state_tracker/st_cb_accum.c
@@ -40,6 +40,7 @@
#include "st_draw.h"
#include "st_public.h"
#include "st_format.h"
+#include "st_texture.h"
#include "pipe/p_context.h"
#include "pipe/p_defines.h"
#include "pipe/p_inlines.h"
@@ -118,6 +119,9 @@ st_clear_accum_buffer(GLcontext *ctx, struct gl_renderbuffer *rb)
const GLint height = ctx->DrawBuffer->_Ymax - ypos;
GLubyte *map;
+ st_teximage_flush_before_map(ctx->st, acc_strb->texture, 0, 0,
+ PIPE_TRANSFER_WRITE);
+
acc_pt = screen->get_tex_transfer(screen, acc_strb->texture, 0, 0, 0,
PIPE_TRANSFER_WRITE, xpos, ypos,
width, height);
@@ -163,6 +167,9 @@ accum_mad(GLcontext *ctx, GLfloat scale, GLfloat bias,
struct pipe_transfer *acc_pt;
GLubyte *map;
+ st_teximage_flush_before_map(ctx->st, acc_strb->texture, 0, 0,
+ PIPE_TRANSFER_READ_WRITE);
+
acc_pt = screen->get_tex_transfer(screen, acc_strb->texture, 0, 0, 0,
PIPE_TRANSFER_READ_WRITE, xpos, ypos,
width, height);
@@ -192,20 +199,27 @@ accum_mad(GLcontext *ctx, GLfloat scale, GLfloat bias,
static void
-accum_accum(struct pipe_context *pipe, GLfloat value,
+accum_accum(struct st_context *st, GLfloat value,
GLint xpos, GLint ypos, GLint width, GLint height,
struct st_renderbuffer *acc_strb,
struct st_renderbuffer *color_strb)
{
+ struct pipe_context *pipe = st->pipe;
struct pipe_screen *screen = pipe->screen;
struct pipe_transfer *acc_trans, *color_trans;
GLfloat *colorBuf, *accBuf;
GLint i;
+ st_teximage_flush_before_map(st, acc_strb->texture, 0, 0,
+ PIPE_TRANSFER_READ);
+
acc_trans = screen->get_tex_transfer(screen, acc_strb->texture, 0, 0, 0,
PIPE_TRANSFER_READ, xpos, ypos,
width, height);
+ st_teximage_flush_before_map(st, color_strb->texture, 0, 0,
+ PIPE_TRANSFER_READ);
+
color_trans = screen->get_tex_transfer(screen, color_strb->texture, 0, 0, 0,
PIPE_TRANSFER_READ, xpos, ypos,
width, height);
@@ -235,20 +249,27 @@ accum_accum(struct pipe_context *pipe, GLfloat value,
static void
-accum_load(struct pipe_context *pipe, GLfloat value,
+accum_load(struct st_context *st, GLfloat value,
GLint xpos, GLint ypos, GLint width, GLint height,
struct st_renderbuffer *acc_strb,
struct st_renderbuffer *color_strb)
{
+ struct pipe_context *pipe = st->pipe;
struct pipe_screen *screen = pipe->screen;
struct pipe_transfer *acc_trans, *color_trans;
GLfloat *buf;
GLint i;
+ st_teximage_flush_before_map(st, acc_strb->texture, 0, 0,
+ PIPE_TRANSFER_WRITE);
+
acc_trans = screen->get_tex_transfer(screen, acc_strb->texture, 0, 0, 0,
PIPE_TRANSFER_WRITE, xpos, ypos,
width, height);
+ st_teximage_flush_before_map(st, color_strb->texture, 0, 0,
+ PIPE_TRANSFER_READ);
+
color_trans = screen->get_tex_transfer(screen, color_strb->texture, 0, 0, 0,
PIPE_TRANSFER_READ, xpos, ypos,
width, height);
@@ -284,10 +305,16 @@ accum_return(GLcontext *ctx, GLfloat value,
abuf = (GLfloat *) _mesa_malloc(width * height * 4 * sizeof(GLfloat));
+ st_teximage_flush_before_map(ctx->st, acc_strb->texture, 0, 0,
+ PIPE_TRANSFER_READ);
+
acc_trans = screen->get_tex_transfer(screen, acc_strb->texture, 0, 0, 0,
PIPE_TRANSFER_READ, xpos, ypos,
width, height);
+ st_teximage_flush_before_map(ctx->st, color_strb->texture, 0, 0,
+ PIPE_TRANSFER_READ_WRITE);
+
color_trans = screen->get_tex_transfer(screen, color_strb->texture, 0, 0, 0,
PIPE_TRANSFER_READ_WRITE, xpos, ypos,
width, height);
@@ -325,7 +352,6 @@ static void
st_Accum(GLcontext *ctx, GLenum op, GLfloat value)
{
struct st_context *st = ctx->st;
- struct pipe_context *pipe = st->pipe;
struct st_renderbuffer *acc_strb
= st_renderbuffer(ctx->DrawBuffer->Attachment[BUFFER_ACCUM].Renderbuffer);
struct st_renderbuffer *color_strb
@@ -352,11 +378,11 @@ st_Accum(GLcontext *ctx, GLenum op, GLfloat value)
break;
case GL_ACCUM:
if (value != 0.0F) {
- accum_accum(pipe, value, xpos, ypos, width, height, acc_strb, color_strb);
+ accum_accum(st, value, xpos, ypos, width, height, acc_strb, color_strb);
}
break;
case GL_LOAD:
- accum_load(pipe, value, xpos, ypos, width, height, acc_strb, color_strb);
+ accum_load(st, value, xpos, ypos, width, height, acc_strb, color_strb);
break;
case GL_RETURN:
accum_return(ctx, value, xpos, ypos, width, height, acc_strb, color_strb);
diff --git a/src/mesa/state_tracker/st_cb_bufferobjects.c b/src/mesa/state_tracker/st_cb_bufferobjects.c
index 3651e4ae7d..fdb800fbd0 100644
--- a/src/mesa/state_tracker/st_cb_bufferobjects.c
+++ b/src/mesa/state_tracker/st_cb_bufferobjects.c
@@ -32,6 +32,7 @@
#include "st_context.h"
#include "st_cb_bufferobjects.h"
+#include "st_public.h"
#include "pipe/p_context.h"
#include "pipe/p_defines.h"
@@ -103,6 +104,9 @@ st_bufferobj_subdata(GLcontext *ctx,
if (offset >= st_obj->size || size > (st_obj->size - offset))
return;
+ if (pipe->is_buffer_referenced(pipe, st_obj->buffer))
+ st_flush(st_context(ctx), PIPE_FLUSH_RENDER_CACHE, NULL);
+
pipe_buffer_write(pipe->screen, st_obj->buffer, offset, size, data);
}
@@ -123,6 +127,10 @@ st_bufferobj_get_subdata(GLcontext *ctx,
if (offset >= st_obj->size || size > (st_obj->size - offset))
return;
+ if (pipe->is_buffer_referenced(pipe, st_obj->buffer) &
+ PIPE_REFERENCED_FOR_WRITE)
+ st_flush(st_context(ctx), PIPE_FLUSH_RENDER_CACHE, NULL);
+
pipe_buffer_read(pipe->screen, st_obj->buffer, offset, size, data);
}
@@ -171,7 +179,7 @@ st_bufferobj_data(GLcontext *ctx,
st_obj->size = size;
if (data)
- st_bufferobj_subdata(ctx, target, 0, size, data, obj);
+ pipe_buffer_write(pipe->screen, st_obj->buffer, 0, size, data);
}
@@ -185,6 +193,7 @@ st_bufferobj_map(GLcontext *ctx, GLenum target, GLenum access,
struct pipe_context *pipe = st_context(ctx)->pipe;
struct st_buffer_object *st_obj = st_buffer_object(obj);
GLuint flags;
+ unsigned referenced;
switch (access) {
case GL_WRITE_ONLY:
@@ -200,6 +209,11 @@ st_bufferobj_map(GLcontext *ctx, GLenum target, GLenum access,
break;
}
+ referenced = pipe->is_buffer_referenced(pipe, st_obj->buffer);
+ if (referenced && ((referenced & PIPE_REFERENCED_FOR_WRITE) ||
+ (flags & PIPE_BUFFER_USAGE_CPU_WRITE)))
+ st_flush(st_context(ctx), PIPE_FLUSH_RENDER_CACHE, NULL);
+
obj->Pointer = pipe_buffer_map(pipe->screen, st_obj->buffer, flags);
if(obj->Pointer) {
obj->Offset = 0;
diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c
index 0a4430501f..c67b026413 100644
--- a/src/mesa/state_tracker/st_cb_drawpixels.c
+++ b/src/mesa/state_tracker/st_cb_drawpixels.c
@@ -631,8 +631,6 @@ draw_stencil_pixels(GLcontext *ctx, GLint x, GLint y,
GLint skipPixels;
ubyte *stmap;
- pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL);
-
strb = st_renderbuffer(ctx->DrawBuffer->
Attachment[BUFFER_STENCIL].Renderbuffer);
@@ -640,6 +638,9 @@ draw_stencil_pixels(GLcontext *ctx, GLint x, GLint y,
y = ctx->DrawBuffer->Height - y - height;
}
+ st_teximage_flush_before_map(ctx->st, strb->texture, 0, 0,
+ PIPE_TRANSFER_WRITE);
+
pt = screen->get_tex_transfer(screen, strb->texture, 0, 0, 0,
PIPE_TRANSFER_WRITE, x, y,
width, height);
@@ -825,6 +826,9 @@ copy_stencil_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
GL_STENCIL_INDEX, GL_UNSIGNED_BYTE,
&ctx->DefaultPacking, buffer);
+ st_teximage_flush_before_map(ctx->st, rbDraw->texture, 0, 0,
+ PIPE_TRANSFER_WRITE);
+
ptDraw = screen->get_tex_transfer(screen, rbDraw->texture, 0, 0, 0,
PIPE_TRANSFER_WRITE, dstx, dsty,
width, height);
diff --git a/src/mesa/state_tracker/st_cb_readpixels.c b/src/mesa/state_tracker/st_cb_readpixels.c
index 9ce5f3fe84..519ad6660f 100644
--- a/src/mesa/state_tracker/st_cb_readpixels.c
+++ b/src/mesa/state_tracker/st_cb_readpixels.c
@@ -42,13 +42,14 @@
#include "pipe/p_defines.h"
#include "pipe/p_inlines.h"
#include "util/u_tile.h"
+
#include "st_context.h"
#include "st_cb_bitmap.h"
#include "st_cb_readpixels.h"
#include "st_cb_fbo.h"
#include "st_format.h"
#include "st_public.h"
-
+#include "st_texture.h"
/**
* Special case for reading stencil buffer.
@@ -73,6 +74,10 @@ st_read_stencil_pixels(GLcontext *ctx, GLint x, GLint y,
}
/* Create a read transfer from the renderbuffer's texture */
+
+ st_teximage_flush_before_map(ctx->st, strb->texture, 0, 0,
+ PIPE_TRANSFER_READ);
+
pt = screen->get_tex_transfer(screen, strb->texture, 0, 0, 0,
PIPE_TRANSFER_READ, x, y, width, height);
@@ -240,6 +245,9 @@ st_fast_readpixels(GLcontext *ctx, struct st_renderbuffer *strb,
y = strb->texture->height[0] - y - height;
}
+ st_teximage_flush_before_map(ctx->st, strb->texture, 0, 0,
+ PIPE_TRANSFER_READ);
+
trans = screen->get_tex_transfer(screen, strb->texture, 0, 0, 0,
PIPE_TRANSFER_READ, x, y, width, height);
if (!trans) {
diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c
index 1f14b3705d..98dc6ec74d 100644
--- a/src/mesa/state_tracker/st_cb_texture.c
+++ b/src/mesa/state_tracker/st_cb_texture.c
@@ -26,6 +26,7 @@
**************************************************************************/
#include "main/mfeatures.h"
+#include "main/bufferobj.h"
#if FEATURE_convolve
#include "main/convolve.h"
#endif
@@ -55,6 +56,7 @@
#include "pipe/p_inlines.h"
#include "util/u_tile.h"
#include "util/u_blit.h"
+#include "util/u_surface.h"
#define DBG if (0) printf
@@ -110,6 +112,25 @@ compressed_num_bytes(GLuint mesaFormat)
}
+static GLboolean
+is_compressed_mesa_format(const struct gl_texture_format *format)
+{
+ switch (format->MesaFormat) {
+ case MESA_FORMAT_RGB_DXT1:
+ case MESA_FORMAT_RGBA_DXT1:
+ case MESA_FORMAT_RGBA_DXT3:
+ case MESA_FORMAT_RGBA_DXT5:
+ case MESA_FORMAT_SRGB_DXT1:
+ case MESA_FORMAT_SRGBA_DXT1:
+ case MESA_FORMAT_SRGBA_DXT3:
+ case MESA_FORMAT_SRGBA_DXT5:
+ return GL_TRUE;
+ default:
+ return GL_FALSE;
+ }
+}
+
+
/** called via ctx->Driver.NewTextureImage() */
static struct gl_texture_image *
st_NewTextureImage(GLcontext * ctx)
@@ -379,6 +400,110 @@ strip_texture_border(GLint border,
/**
+ * Try to do texture compression via rendering. If the Gallium driver
+ * can render into a compressed surface this will allow us to do texture
+ * compression.
+ * \return GL_TRUE for success, GL_FALSE for failure
+ */
+static GLboolean
+compress_with_blit(GLcontext * ctx,
+ 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 *unpack,
+ struct gl_texture_image *texImage)
+{
+ const GLuint dstImageOffsets[1] = {0};
+ struct st_texture_image *stImage = st_texture_image(texImage);
+ struct pipe_screen *screen = ctx->st->pipe->screen;
+ const GLuint face = _mesa_tex_target_to_face(target);
+ const struct gl_texture_format *mesa_format;
+ struct pipe_texture templ;
+ struct pipe_texture *src_tex;
+ struct pipe_surface *dst_surface;
+ struct pipe_transfer *tex_xfer;
+ void *map;
+
+
+ if (!stImage->pt) {
+ /* XXX: Can this happen? Should we assert? */
+ return GL_FALSE;
+ }
+
+ /* get destination surface (in the compressed texture) */
+ dst_surface = screen->get_tex_surface(screen, stImage->pt,
+ stImage->face, stImage->level, 0,
+ PIPE_BUFFER_USAGE_GPU_WRITE);
+ if (!dst_surface) {
+ /* can't render into this format (or other problem) */
+ return GL_FALSE;
+ }
+
+ /* Choose format for the temporary RGBA texture image.
+ */
+ mesa_format = st_ChooseTextureFormat(ctx, GL_RGBA, format, type);
+ assert(mesa_format);
+ if (!mesa_format)
+ return GL_FALSE;
+
+ /* Create the temporary source texture
+ */
+ memset(&templ, 0, sizeof(templ));
+ templ.target = PIPE_TEXTURE_2D;
+ templ.format = st_mesa_format_to_pipe_format(mesa_format->MesaFormat);
+ pf_get_block(templ.format, &templ.block);
+ templ.width[0] = width;
+ templ.height[0] = height;
+ templ.depth[0] = 1;
+ templ.last_level = 0;
+ templ.tex_usage = PIPE_TEXTURE_USAGE_SAMPLER;
+ src_tex = screen->texture_create(screen, &templ);
+
+ if (!src_tex)
+ return GL_FALSE;
+
+ /* Put user's tex data into the temporary texture
+ */
+ tex_xfer = screen->get_tex_transfer(screen, src_tex,
+ face, level, 0,
+ PIPE_TRANSFER_WRITE,
+ 0, 0, width, height); /* x, y, w, h */
+ map = screen->transfer_map(screen, tex_xfer);
+
+ mesa_format->StoreImage(ctx, 2, GL_RGBA, mesa_format,
+ map, /* dest ptr */
+ 0, 0, 0, /* dest x/y/z offset */
+ tex_xfer->stride, /* dest row stride (bytes) */
+ dstImageOffsets, /* image offsets (for 3D only) */
+ width, height, 1, /* size */
+ format, type, /* source format/type */
+ pixels, /* source data */
+ unpack); /* source data packing */
+
+ screen->transfer_unmap(screen, tex_xfer);
+ screen->tex_transfer_destroy(tex_xfer);
+
+ /* copy / compress image */
+ util_blit_pixels_tex(ctx->st->blit,
+ src_tex, /* pipe_texture (src) */
+ 0, 0, /* src x0, y0 */
+ width, height, /* src x1, y1 */
+ dst_surface, /* pipe_surface (dst) */
+ xoffset, yoffset, /* dst x0, y0 */
+ xoffset + width, /* dst x1 */
+ yoffset + height, /* dst y1 */
+ 0.0, /* z */
+ PIPE_TEX_MIPFILTER_NEAREST);
+
+ pipe_surface_reference(&dst_surface, NULL);
+ pipe_texture_reference(&src_tex, NULL);
+
+ return GL_TRUE;
+}
+
+
+/**
* Do glTexImage1/2/3D().
*/
static void
@@ -392,8 +517,9 @@ st_TexImage(GLcontext * ctx,
const struct gl_pixelstore_attrib *unpack,
struct gl_texture_object *texObj,
struct gl_texture_image *texImage,
- GLsizei imageSize, GLboolean compressed)
+ GLsizei imageSize, GLboolean compressed_src)
{
+ struct pipe_screen *screen = ctx->st->pipe->screen;
struct st_texture_object *stObj = st_texture_object(texObj);
struct st_texture_image *stImage = st_texture_image(texImage);
GLint postConvWidth, postConvHeight;
@@ -522,7 +648,7 @@ st_TexImage(GLcontext * ctx,
* the expectation that the texture will be set up but nothing
* more will be done. This is where those calls return:
*/
- if (compressed) {
+ if (compressed_src) {
pixels = _mesa_validate_pbo_compressed_teximage(ctx, imageSize, pixels,
unpack,
"glCompressedTexImage");
@@ -535,6 +661,21 @@ st_TexImage(GLcontext * ctx,
if (!pixels)
return;
+ /* See if we can do texture compression with a blit/render.
+ */
+ if (!compressed_src &&
+ !ctx->Mesa_DXTn &&
+ is_compressed_mesa_format(texImage->TexFormat) &&
+ screen->is_format_supported(screen,
+ stImage->pt->format,
+ stImage->pt->target,
+ PIPE_TEXTURE_USAGE_RENDER_TARGET, 0)) {
+ if (compress_with_blit(ctx, target, level, 0, 0, 0, width, height, depth,
+ format, type, pixels, unpack, texImage)) {
+ return;
+ }
+ }
+
if (stImage->pt) {
texImage->Data = st_texture_image_map(ctx->st, stImage, 0,
PIPE_TRANSFER_WRITE, 0, 0,
@@ -570,7 +711,7 @@ st_TexImage(GLcontext * ctx,
* the blitter to copy. Or, use the hardware to do the format
* conversion and copy:
*/
- if (compressed) {
+ if (compressed_src) {
memcpy(texImage->Data, pixels, imageSize);
}
else {
@@ -607,7 +748,7 @@ st_TexImage(GLcontext * ctx,
_mesa_unmap_teximage_pbo(ctx, unpack);
- if (stImage->pt) {
+ if (stImage->pt && texImage->Data) {
st_texture_image_unmap(ctx->st, stImage);
texImage->Data = NULL;
}
@@ -678,6 +819,90 @@ st_CompressedTexImage2D(GLcontext *ctx, GLenum target, GLint level,
}
+
+/**
+ * glGetTexImage() helper: decompress a compressed texture by rendering
+ * a textured quad. Store the results in the user's buffer.
+ */
+static void
+decompress_with_blit(GLcontext * ctx, GLenum target, GLint level,
+ GLenum format, GLenum type, GLvoid *pixels,
+ struct gl_texture_object *texObj,
+ struct gl_texture_image *texImage)
+{
+ struct pipe_screen *screen = ctx->st->pipe->screen;
+ struct st_texture_image *stImage = st_texture_image(texImage);
+ const GLuint width = texImage->Width;
+ const GLuint height = texImage->Height;
+ struct pipe_surface *dst_surface;
+ struct pipe_texture *dst_texture;
+ struct pipe_transfer *tex_xfer;
+
+ /* create temp / dest surface */
+ if (!util_create_rgba_surface(screen, width, height,
+ &dst_texture, &dst_surface)) {
+ _mesa_problem(ctx, "util_create_rgba_surface() failed "
+ "in decompress_with_blit()");
+ return;
+ }
+
+ /* blit/render/decompress */
+ util_blit_pixels_tex(ctx->st->blit,
+ stImage->pt, /* pipe_texture (src) */
+ 0, 0, /* src x0, y0 */
+ width, height, /* src x1, y1 */
+ dst_surface, /* pipe_surface (dst) */
+ 0, 0, /* dst x0, y0 */
+ width, height, /* dst x1, y1 */
+ 0.0, /* z */
+ PIPE_TEX_MIPFILTER_NEAREST);
+
+ /* map the dst_surface so we can read from it */
+ tex_xfer = screen->get_tex_transfer(screen, dst_texture, 0, 0, 0,
+ PIPE_TRANSFER_READ,
+ 0, 0, width, height);
+
+ pixels = _mesa_map_readpix_pbo(ctx, &ctx->Pack, pixels);
+
+ /* copy/pack data into user buffer */
+ if (st_equal_formats(stImage->pt->format, format, type)) {
+ /* memcpy */
+ const uint bytesPerRow = width * pf_get_size(stImage->pt->format);
+ ubyte *map = screen->transfer_map(screen, tex_xfer);
+ GLuint row;
+ for (row = 0; row < height; row++) {
+ GLvoid *dest = _mesa_image_address2d(&ctx->Pack, pixels, width,
+ height, format, type, row, 0);
+ memcpy(dest, map, bytesPerRow);
+ map += tex_xfer->stride;
+ }
+ screen->transfer_unmap(screen, tex_xfer);
+ }
+ else {
+ /* format translation via floats */
+ GLuint row;
+ for (row = 0; row < height; row++) {
+ const GLbitfield transferOps = 0x0; /* bypassed for glGetTexImage() */
+ GLfloat rgba[4 * MAX_WIDTH];
+ GLvoid *dest = _mesa_image_address2d(&ctx->Pack, pixels, width,
+ height, format, type, row, 0);
+
+ /* get float[4] rgba row from surface */
+ pipe_get_tile_rgba(tex_xfer, 0, row, width, 1, rgba);
+
+ _mesa_pack_rgba_span_float(ctx, width, (GLfloat (*)[4]) rgba, format,
+ type, dest, &ctx->Pack, transferOps);
+ }
+ }
+
+ _mesa_unmap_readpix_pbo(ctx, &ctx->Pack);
+
+ /* destroy the temp / dest surface */
+ util_destroy_rgba_surface(dst_texture, dst_surface);
+}
+
+
+
/**
* Need to map texture image into memory before copying image data,
* then unmap it.
@@ -686,7 +911,7 @@ static void
st_get_tex_image(GLcontext * ctx, GLenum target, GLint level,
GLenum format, GLenum type, GLvoid * pixels,
struct gl_texture_object *texObj,
- struct gl_texture_image *texImage, GLboolean compressed)
+ struct gl_texture_image *texImage, GLboolean compressed_dst)
{
struct st_texture_image *stImage = st_texture_image(texImage);
const GLuint dstImageStride =
@@ -695,11 +920,27 @@ st_get_tex_image(GLcontext * ctx, GLenum target, GLint level,
GLuint depth, i;
GLubyte *dest;
+ if (stImage->pt &&
+ pf_is_compressed(stImage->pt->format) &&
+ !compressed_dst) {
+ /* Need to decompress the texture.
+ * We'll do this by rendering a textured quad.
+ * Note that we only expect RGBA formats (no Z/depth formats).
+ */
+ decompress_with_blit(ctx, target, level, format, type, pixels,
+ texObj, texImage);
+ return;
+ }
+
/* Map */
if (stImage->pt) {
/* Image is stored in hardware format in a buffer managed by the
* kernel. Need to explicitly map and unmap it.
*/
+
+ st_teximage_flush_before_map(ctx->st, stImage->pt, 0, level,
+ PIPE_TRANSFER_READ);
+
texImage->Data = st_texture_image_map(ctx->st, stImage, 0,
PIPE_TRANSFER_READ, 0, 0,
stImage->base.Width,
@@ -724,7 +965,7 @@ st_get_tex_image(GLcontext * ctx, GLenum target, GLint level,
dest = (GLubyte *) pixels;
for (i = 0; i < depth; i++) {
- if (compressed) {
+ if (compressed_dst) {
_mesa_get_compressed_teximage(ctx, target, level, dest,
texObj, texImage);
}
@@ -787,6 +1028,7 @@ st_TexSubimage(GLcontext *ctx, GLint dims, GLenum target, GLint level,
struct gl_texture_object *texObj,
struct gl_texture_image *texImage)
{
+ struct pipe_screen *screen = ctx->st->pipe->screen;
struct st_texture_image *stImage = st_texture_image(texImage);
GLuint dstRowStride;
const GLuint srcImageStride =
@@ -804,10 +1046,28 @@ st_TexSubimage(GLcontext *ctx, GLint dims, GLenum target, GLint level,
if (!pixels)
return;
+ /* See if we can do texture compression with a blit/render.
+ */
+ if (!ctx->Mesa_DXTn &&
+ is_compressed_mesa_format(texImage->TexFormat) &&
+ screen->is_format_supported(screen,
+ stImage->pt->format,
+ stImage->pt->target,
+ PIPE_TEXTURE_USAGE_RENDER_TARGET, 0)) {
+ if (compress_with_blit(ctx, target, level,
+ xoffset, yoffset, zoffset,
+ width, height, depth,
+ format, type, pixels, packing, texImage)) {
+ return;
+ }
+ }
+
/* Map buffer if necessary. Need to lock to prevent other contexts
* from uploading the buffer under us.
*/
if (stImage->pt) {
+ st_teximage_flush_before_map(ctx->st, stImage->pt, 0, level,
+ PIPE_TRANSFER_WRITE);
texImage->Data = st_texture_image_map(ctx->st, stImage, zoffset,
PIPE_TRANSFER_WRITE,
xoffset, yoffset,
@@ -932,6 +1192,9 @@ fallback_copy_texsubimage(GLcontext *ctx, GLenum target, GLint level,
srcY = strb->Base.Height - srcY - height;
}
+ st_teximage_flush_before_map(ctx->st, strb->texture, 0, 0,
+ PIPE_TRANSFER_READ);
+
src_trans = screen->get_tex_transfer( screen,
strb->texture,
0, 0, 0,
@@ -939,6 +1202,9 @@ fallback_copy_texsubimage(GLcontext *ctx, GLenum target, GLint level,
srcX, srcY,
width, height);
+ st_teximage_flush_before_map(ctx->st, stImage->pt, 0, 0,
+ PIPE_TRANSFER_WRITE);
+
texDest = st_texture_image_map(ctx->st, stImage, 0, PIPE_TRANSFER_WRITE,
destX, destY, width, height);
@@ -1318,6 +1584,11 @@ copy_image_data_to_texture(struct st_context *st,
/* More straightforward upload.
*/
+
+ st_teximage_flush_before_map(st, stObj->pt, stImage->face, dstLevel,
+ PIPE_TRANSFER_WRITE);
+
+
st_texture_image_data(st->pipe,
stObj->pt,
stImage->face,
diff --git a/src/mesa/state_tracker/st_format.c b/src/mesa/state_tracker/st_format.c
index 9e2d60c926..d507e3e58d 100644
--- a/src/mesa/state_tracker/st_format.c
+++ b/src/mesa/state_tracker/st_format.c
@@ -716,3 +716,23 @@ st_ChooseTextureFormat(GLcontext *ctx, GLint internalFormat,
return translate_gallium_format_to_mesa_format(pFormat);
}
+
+
+/**
+ * Test if a gallium format is equivalent to a GL format/type.
+ */
+GLboolean
+st_equal_formats(enum pipe_format pFormat, GLenum format, GLenum type)
+{
+ switch (pFormat) {
+ case PIPE_FORMAT_R8G8B8A8_UNORM:
+ return format == GL_RGBA && type == GL_UNSIGNED_BYTE;
+ case PIPE_FORMAT_B8G8R8A8_UNORM:
+ return format == GL_BGRA && type == GL_UNSIGNED_BYTE;
+ case PIPE_FORMAT_R5G6B5_UNORM:
+ return format == GL_RGB && type == GL_UNSIGNED_SHORT_5_6_5;
+ /* XXX more combos... */
+ default:
+ return GL_FALSE;
+ }
+}
diff --git a/src/mesa/state_tracker/st_format.h b/src/mesa/state_tracker/st_format.h
index 3f5ac3201b..7bbbe2d570 100644
--- a/src/mesa/state_tracker/st_format.h
+++ b/src/mesa/state_tracker/st_format.h
@@ -76,4 +76,8 @@ st_ChooseTextureFormat(GLcontext * ctx, GLint internalFormat,
GLenum format, GLenum type);
+extern GLboolean
+st_equal_formats(enum pipe_format pFormat, GLenum format, GLenum type);
+
+
#endif /* ST_CB_TEXIMAGE_H */
diff --git a/src/mesa/state_tracker/st_gen_mipmap.c b/src/mesa/state_tracker/st_gen_mipmap.c
index 9cc2176d5e..6e9aa5245e 100644
--- a/src/mesa/state_tracker/st_gen_mipmap.c
+++ b/src/mesa/state_tracker/st_gen_mipmap.c
@@ -123,10 +123,17 @@ fallback_generate_mipmap(GLcontext *ctx, GLenum target,
const ubyte *srcData;
ubyte *dstData;
+ st_teximage_flush_before_map(ctx->st, pt, face, srcLevel,
+ PIPE_TRANSFER_READ);
+
srcTrans = screen->get_tex_transfer(screen, pt, face, srcLevel, zslice,
PIPE_TRANSFER_READ, 0, 0,
pt->width[srcLevel],
pt->height[srcLevel]);
+
+ st_teximage_flush_before_map(ctx->st, pt, face, dstLevel,
+ PIPE_TRANSFER_WRITE);
+
dstTrans = screen->get_tex_transfer(screen, pt, face, dstLevel, zslice,
PIPE_TRANSFER_WRITE, 0, 0,
pt->width[dstLevel],
diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c
index 6348e83d8a..2795570cf1 100644
--- a/src/mesa/state_tracker/st_program.c
+++ b/src/mesa/state_tracker/st_program.c
@@ -484,14 +484,14 @@ st_translate_fragment_program(struct st_context *st,
/* handled above */
assert(0);
break;
- case FRAG_RESULT_COLOR:
+ default:
+ assert(attr == FRAG_RESULT_COLOR ||
+ (FRAG_RESULT_DATA0 <= attr && attr < FRAG_RESULT_MAX));
fs_output_semantic_name[fs_num_outputs] = TGSI_SEMANTIC_COLOR;
fs_output_semantic_index[fs_num_outputs] = numColors;
outputMapping[attr] = fs_num_outputs;
numColors++;
break;
- default:
- assert(0);
}
output_flags[fs_num_outputs] = stfp->Base.Base.OutputFlags[attr];
diff --git a/src/mesa/state_tracker/st_texture.c b/src/mesa/state_tracker/st_texture.c
index 19eb7e2f69..fcbaeb6989 100644
--- a/src/mesa/state_tracker/st_texture.c
+++ b/src/mesa/state_tracker/st_texture.c
@@ -188,8 +188,10 @@ st_texture_image_map(struct st_context *st, struct st_texture_image *stImage,
GLuint zoffset, enum pipe_transfer_usage usage,
GLuint x, GLuint y, GLuint w, GLuint h)
{
- struct pipe_screen *screen = st->pipe->screen;
+ struct pipe_context *pipe = st->pipe;
+ struct pipe_screen *screen = pipe->screen;
struct pipe_texture *pt = stImage->pt;
+
DBG("%s \n", __FUNCTION__);
stImage->transfer = screen->get_tex_transfer(screen, pt, stImage->face,
@@ -265,6 +267,7 @@ st_texture_image_data(struct pipe_context *pipe,
struct pipe_transfer *dst_transfer;
DBG("%s\n", __FUNCTION__);
+
for (i = 0; i < depth; i++) {
dst_transfer = screen->get_tex_transfer(screen, dst, face, level, i,
PIPE_TRANSFER_WRITE, 0, 0,
@@ -481,3 +484,20 @@ st_release_teximage(struct st_framebuffer *stfb, uint surfIndex,
return 1;
}
+
+void
+st_teximage_flush_before_map(struct st_context *st,
+ struct pipe_texture *pt,
+ unsigned int face,
+ unsigned int level,
+ enum pipe_transfer_usage usage)
+{
+ struct pipe_context *pipe = st->pipe;
+ unsigned referenced =
+ pipe->is_texture_referenced(pipe, pt, face, level);
+
+ if (referenced && ((referenced & PIPE_REFERENCED_FOR_WRITE) ||
+ usage == PIPE_TRANSFER_WRITE ||
+ usage == PIPE_TRANSFER_READ_WRITE))
+ st_flush(st, PIPE_FLUSH_RENDER_CACHE, NULL);
+}
diff --git a/src/mesa/state_tracker/st_texture.h b/src/mesa/state_tracker/st_texture.h
index 60c000115e..a392e3d57c 100644
--- a/src/mesa/state_tracker/st_texture.h
+++ b/src/mesa/state_tracker/st_texture.h
@@ -170,5 +170,10 @@ st_texture_image_copy(struct pipe_context *pipe,
struct pipe_texture *src,
GLuint face);
-
+extern void
+st_teximage_flush_before_map(struct st_context *st,
+ struct pipe_texture *pt,
+ unsigned int face,
+ unsigned int level,
+ enum pipe_transfer_usage usage);
#endif