diff options
author | Dave Airlie <[email protected]> | 2009-04-22 21:41:57 +1000 |
---|---|---|
committer | Dave Airlie <[email protected]> | 2009-04-22 21:41:57 +1000 |
commit | 466c78c93538f2853449124c06274d538830cd5a (patch) | |
tree | a6bd88060ba328d8bed1ff2ea1a37ee741a90a17 /src/mesa/state_tracker | |
parent | 65fe0c86ffcff99f9f09606d462bf3731ea0c308 (diff) | |
parent | f057f6543da469f231d551cb5728d98df8add4fa (diff) |
Merge remote branch 'origin/master' into radeon-rewrite
Diffstat (limited to 'src/mesa/state_tracker')
20 files changed, 788 insertions, 350 deletions
diff --git a/src/mesa/state_tracker/st_atom.c b/src/mesa/state_tracker/st_atom.c index f79092291b0..ca15ce1b474 100644 --- a/src/mesa/state_tracker/st_atom.c +++ b/src/mesa/state_tracker/st_atom.c @@ -37,11 +37,8 @@ -/* This is used to initialize st->atoms[]. We could use this list - * directly except for a single atom, st_update_constants, which has a - * .dirty value which changes according to the parameters of the - * current fragment and vertex programs, and so cannot be a static - * value. +/** + * This is used to initialize st->atoms[]. */ static const struct st_tracked_state *atoms[] = { @@ -67,34 +64,13 @@ static const struct st_tracked_state *atoms[] = void st_init_atoms( struct st_context *st ) { - GLuint i; - - st->atoms = _mesa_malloc(sizeof(atoms)); - st->nr_atoms = sizeof(atoms)/sizeof(*atoms); - memcpy(st->atoms, atoms, sizeof(atoms)); - - /* Patch in a pointer to the dynamic state atom: - */ - for (i = 0; i < st->nr_atoms; i++) { - if (st->atoms[i] == &st_update_vs_constants) { - st->atoms[i] = &st->constants.tracked_state[PIPE_SHADER_VERTEX]; - st->atoms[i][0] = st_update_vs_constants; - } - - if (st->atoms[i] == &st_update_fs_constants) { - st->atoms[i] = &st->constants.tracked_state[PIPE_SHADER_FRAGMENT]; - st->atoms[i][0] = st_update_fs_constants; - } - } + /* no-op */ } void st_destroy_atoms( struct st_context *st ) { - if (st->atoms) { - _mesa_free(st->atoms); - st->atoms = NULL; - } + /* no-op */ } @@ -172,8 +148,8 @@ void st_validate_state( struct st_context *st ) memset(&examined, 0, sizeof(examined)); prev = *state; - for (i = 0; i < st->nr_atoms; i++) { - const struct st_tracked_state *atom = st->atoms[i]; + for (i = 0; i < Elements(atoms); i++) { + const struct st_tracked_state *atom = atoms[i]; struct st_state_flags generated; // _mesa_printf("atom %s %x/%x\n", atom->name, atom->dirty.mesa, atom->dirty.st); @@ -185,7 +161,7 @@ void st_validate_state( struct st_context *st ) } if (check_state(state, &atom->dirty)) { - st->atoms[i]->update( st ); + atoms[i]->update( st ); // _mesa_printf("after: %x\n", atom->dirty.mesa); } @@ -203,11 +179,9 @@ void st_validate_state( struct st_context *st ) } else { - const GLuint nr = st->nr_atoms; - - for (i = 0; i < nr; i++) { - if (check_state(state, &st->atoms[i]->dirty)) - st->atoms[i]->update( st ); + for (i = 0; i < Elements(atoms); i++) { + if (check_state(state, &atoms[i]->dirty)) + atoms[i]->update( st ); } } diff --git a/src/mesa/state_tracker/st_atom_constbuf.c b/src/mesa/state_tracker/st_atom_constbuf.c index fd81ac36d2c..77ecd0719e6 100644 --- a/src/mesa/state_tracker/st_atom_constbuf.c +++ b/src/mesa/state_tracker/st_atom_constbuf.c @@ -42,7 +42,7 @@ #include "st_atom.h" #include "st_atom_constbuf.h" #include "st_program.h" - +#include "st_inlines.h" /** * Pass the given program parameters to the graphics pipe as a @@ -62,12 +62,6 @@ void st_upload_constants( struct st_context *st, if (params && params->NumParameters) { const uint paramBytes = params->NumParameters * sizeof(GLfloat) * 4; - /* Update our own dependency flags. This works because this - * function will also be called whenever the program changes. - */ - st->constants.tracked_state[id].dirty.mesa = - (params->StateFlags | _NEW_PROGRAM); - _mesa_load_state_parameters(st->ctx, params); /* We always need to get a new buffer, to keep the drivers simple and @@ -86,9 +80,9 @@ void st_upload_constants( struct st_context *st, /* load Mesa constants into the constant buffer */ if (cbuf->buffer) - pipe_buffer_write(pipe->screen, cbuf->buffer, - 0, paramBytes, - params->ParameterValues); + st_no_flush_pipe_buffer_write(st, cbuf->buffer, + 0, paramBytes, + params->ParameterValues); st->pipe->set_constant_buffer(st->pipe, id, 0, cbuf); } @@ -111,7 +105,7 @@ static void update_vs_constants(struct st_context *st ) const struct st_tracked_state st_update_vs_constants = { "st_update_vs_constants", /* name */ { /* dirty */ - 0, /* set dynamically above */ /* mesa */ + _NEW_PROGRAM_CONSTANTS, ST_NEW_VERTEX_PROGRAM, /* st */ }, update_vs_constants /* update */ @@ -130,7 +124,7 @@ static void update_fs_constants(struct st_context *st ) const struct st_tracked_state st_update_fs_constants = { "st_update_fs_constants", /* name */ { /* dirty */ - 0, /* set dynamically above */ /* mesa */ + (_NEW_PROGRAM | _NEW_PROGRAM_CONSTANTS), /* mesa */ ST_NEW_FRAGMENT_PROGRAM, /* st */ }, update_fs_constants /* update */ diff --git a/src/mesa/state_tracker/st_atom_pixeltransfer.c b/src/mesa/state_tracker/st_atom_pixeltransfer.c index 8d0029dde5f..eff3666ca88 100644 --- a/src/mesa/state_tracker/st_atom_pixeltransfer.c +++ b/src/mesa/state_tracker/st_atom_pixeltransfer.c @@ -45,6 +45,7 @@ #include "st_format.h" #include "st_program.h" #include "st_texture.h" +#include "st_inlines.h" #include "pipe/p_screen.h" #include "pipe/p_context.h" @@ -125,8 +126,7 @@ create_color_map_texture(GLcontext *ctx) /* create texture for color map/table */ pt = st_texture_create(ctx->st, PIPE_TEXTURE_2D, format, 0, - texSize, texSize, 1, 0, - PIPE_TEXTURE_USAGE_SAMPLER); + texSize, texSize, 1, PIPE_TEXTURE_USAGE_SAMPLER); return pt; } @@ -148,8 +148,9 @@ load_color_map_texture(GLcontext *ctx, struct pipe_texture *pt) uint *dest; uint i, j; - transfer = screen->get_tex_transfer(screen, pt, 0, 0, 0, PIPE_TRANSFER_WRITE, - 0, 0, texSize, texSize); + transfer = st_cond_flush_get_tex_transfer(st_context(ctx), + pt, 0, 0, 0, PIPE_TRANSFER_WRITE, + 0, 0, texSize, texSize); dest = (uint *) screen->transfer_map(screen, transfer); /* Pack four 1D maps into a 2D texture: diff --git a/src/mesa/state_tracker/st_cb_accum.c b/src/mesa/state_tracker/st_cb_accum.c index 3f9a825a153..7f793cf08db 100644 --- a/src/mesa/state_tracker/st_cb_accum.c +++ b/src/mesa/state_tracker/st_cb_accum.c @@ -40,6 +40,8 @@ #include "st_draw.h" #include "st_public.h" #include "st_format.h" +#include "st_texture.h" +#include "st_inlines.h" #include "pipe/p_context.h" #include "pipe/p_defines.h" #include "pipe/p_inlines.h" @@ -118,9 +120,10 @@ st_clear_accum_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) const GLint height = ctx->DrawBuffer->_Ymax - ypos; GLubyte *map; - acc_pt = screen->get_tex_transfer(screen, acc_strb->texture, 0, 0, 0, - PIPE_TRANSFER_WRITE, xpos, ypos, - width, height); + acc_pt = st_cond_flush_get_tex_transfer(st_context(ctx), acc_strb->texture, + 0, 0, 0, + PIPE_TRANSFER_WRITE, xpos, ypos, + width, height); map = screen->transfer_map(screen, acc_pt); /* note acc_strb->format might not equal acc_pt->format */ @@ -163,9 +166,11 @@ accum_mad(GLcontext *ctx, GLfloat scale, GLfloat bias, struct pipe_transfer *acc_pt; GLubyte *map; - acc_pt = screen->get_tex_transfer(screen, acc_strb->texture, 0, 0, 0, - PIPE_TRANSFER_READ_WRITE, xpos, ypos, - width, height); + acc_pt = st_cond_flush_get_tex_transfer(st_context(ctx), acc_strb->texture, + 0, 0, 0, + PIPE_TRANSFER_READ_WRITE, + xpos, ypos, + width, height); map = screen->transfer_map(screen, acc_pt); /* note acc_strb->format might not equal acc_pt->format */ @@ -192,23 +197,25 @@ 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; - acc_trans = screen->get_tex_transfer(screen, acc_strb->texture, 0, 0, 0, - PIPE_TRANSFER_READ, xpos, ypos, - width, height); + acc_trans = st_cond_flush_get_tex_transfer(st, acc_strb->texture, 0, 0, 0, + PIPE_TRANSFER_READ, xpos, ypos, + width, height); - color_trans = screen->get_tex_transfer(screen, color_strb->texture, 0, 0, 0, - PIPE_TRANSFER_READ, xpos, ypos, - width, height); + color_trans = st_cond_flush_get_tex_transfer(st, color_strb->texture, + 0, 0, 0, + PIPE_TRANSFER_READ, xpos, ypos, + width, height); colorBuf = (GLfloat *) _mesa_malloc(width * height * 4 * sizeof(GLfloat)); accBuf = (GLfloat *) _mesa_malloc(width * height * 4 * sizeof(GLfloat)); @@ -221,9 +228,9 @@ accum_accum(struct pipe_context *pipe, GLfloat value, } screen->tex_transfer_destroy(acc_trans); - acc_trans = screen->get_tex_transfer(screen, acc_strb->texture, 0, 0, 0, - PIPE_TRANSFER_WRITE, xpos, ypos, - width, height); + acc_trans = st_no_flush_get_tex_transfer(st, acc_strb->texture, 0, 0, 0, + PIPE_TRANSFER_WRITE, xpos, ypos, + width, height); acc_put_tile_rgba(pipe, acc_trans, 0, 0, width, height, accBuf); @@ -235,23 +242,25 @@ 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; - acc_trans = screen->get_tex_transfer(screen, acc_strb->texture, 0, 0, 0, - PIPE_TRANSFER_WRITE, xpos, ypos, - width, height); + acc_trans = st_cond_flush_get_tex_transfer(st, acc_strb->texture, 0, 0, 0, + PIPE_TRANSFER_WRITE, xpos, ypos, + width, height); - color_trans = screen->get_tex_transfer(screen, color_strb->texture, 0, 0, 0, - PIPE_TRANSFER_READ, xpos, ypos, - width, height); + color_trans = st_cond_flush_get_tex_transfer(st, color_strb->texture, + 0, 0, 0, + PIPE_TRANSFER_READ, xpos, ypos, + width, height); buf = (GLfloat *) _mesa_malloc(width * height * 4 * sizeof(GLfloat)); @@ -284,13 +293,16 @@ accum_return(GLcontext *ctx, GLfloat value, abuf = (GLfloat *) _mesa_malloc(width * height * 4 * sizeof(GLfloat)); - acc_trans = screen->get_tex_transfer(screen, acc_strb->texture, 0, 0, 0, - PIPE_TRANSFER_READ, xpos, ypos, - width, height); + acc_trans = st_cond_flush_get_tex_transfer(st_context(ctx), + acc_strb->texture, 0, 0, 0, + PIPE_TRANSFER_READ, xpos, ypos, + width, height); - color_trans = screen->get_tex_transfer(screen, color_strb->texture, 0, 0, 0, - PIPE_TRANSFER_READ_WRITE, xpos, ypos, - width, height); + color_trans = st_cond_flush_get_tex_transfer(st_context(ctx), + color_strb->texture, 0, 0, 0, + PIPE_TRANSFER_READ_WRITE, + xpos, ypos, + width, height); acc_get_tile_rgba(pipe, acc_trans, 0, 0, width, height, abuf); @@ -325,7 +337,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 +363,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_bitmap.c b/src/mesa/state_tracker/st_cb_bitmap.c index 2d547dd0722..8709633557c 100644 --- a/src/mesa/state_tracker/st_cb_bitmap.c +++ b/src/mesa/state_tracker/st_cb_bitmap.c @@ -47,6 +47,8 @@ #include "st_cb_program.h" #include "st_mesa_to_tgsi.h" #include "st_texture.h" +#include "st_inlines.h" + #include "pipe/p_context.h" #include "pipe/p_defines.h" #include "pipe/p_inlines.h" @@ -147,7 +149,7 @@ make_bitmap_fragment_program(GLcontext *ctx, GLuint samplerIndex) p->Instructions[ic].SrcReg[0].Swizzle = SWIZZLE_XXXX; p->Instructions[ic].SrcReg[0].Index = 0; - p->Instructions[ic].SrcReg[0].NegateBase = NEGATE_XYZW; + p->Instructions[ic].SrcReg[0].Negate = NEGATE_XYZW; ic++; /* END; */ @@ -330,15 +332,16 @@ make_bitmap_texture(GLcontext *ctx, GLsizei width, GLsizei height, * Create texture to hold bitmap pattern. */ pt = st_texture_create(ctx->st, PIPE_TEXTURE_2D, ctx->st->bitmap.tex_format, - 0, width, height, 1, 0, + 0, width, height, 1, PIPE_TEXTURE_USAGE_SAMPLER); if (!pt) { _mesa_unmap_bitmap_pbo(ctx, unpack); return NULL; } - transfer = screen->get_tex_transfer(screen, pt, 0, 0, 0, PIPE_TRANSFER_WRITE, - 0, 0, width, height); + transfer = st_no_flush_get_tex_transfer(st_context(ctx), pt, 0, 0, 0, + PIPE_TRANSFER_WRITE, + 0, 0, width, height); dest = screen->transfer_map(screen, transfer); @@ -425,11 +428,11 @@ setup_bitmap_vertex_data(struct st_context *st, } /* put vertex data into vbuf */ - pipe_buffer_write(pipe->screen, - st->bitmap.vbuf, - st->bitmap.vbuf_slot * sizeof st->bitmap.vertices, - sizeof st->bitmap.vertices, - st->bitmap.vertices); + st_no_flush_pipe_buffer_write(st, + st->bitmap.vbuf, + st->bitmap.vbuf_slot * sizeof st->bitmap.vertices, + sizeof st->bitmap.vertices, + st->bitmap.vertices); return st->bitmap.vbuf_slot++ * sizeof st->bitmap.vertices; } @@ -570,8 +573,10 @@ reset_cache(struct st_context *st) cache->ymin = 1000000; cache->ymax = -1000000; - if (cache->trans) + if (cache->trans) { screen->tex_transfer_destroy(cache->trans); + cache->trans = NULL; + } assert(!cache->texture); @@ -579,16 +584,27 @@ reset_cache(struct st_context *st) cache->texture = st_texture_create(st, PIPE_TEXTURE_2D, st->bitmap.tex_format, 0, BITMAP_CACHE_WIDTH, BITMAP_CACHE_HEIGHT, - 1, 0, - PIPE_TEXTURE_USAGE_SAMPLER); + 1, PIPE_TEXTURE_USAGE_SAMPLER); + +} + +static void +create_cache_trans(struct st_context *st) +{ + struct pipe_context *pipe = st->pipe; + struct pipe_screen *screen = pipe->screen; + struct bitmap_cache *cache = st->bitmap.cache; + + if (cache->trans) + return; /* Map the texture transfer. * Subsequent glBitmap calls will write into the texture image. */ - cache->trans = screen->get_tex_transfer(screen, cache->texture, 0, 0, 0, - PIPE_TRANSFER_WRITE, 0, 0, - BITMAP_CACHE_WIDTH, - BITMAP_CACHE_HEIGHT); + cache->trans = st_no_flush_get_tex_transfer(st, cache->texture, 0, 0, 0, + PIPE_TRANSFER_WRITE, 0, 0, + BITMAP_CACHE_WIDTH, + BITMAP_CACHE_HEIGHT); cache->buffer = screen->transfer_map(screen, cache->trans); /* init image to all 0xff */ @@ -620,11 +636,13 @@ st_flush_bitmap_cache(struct st_context *st) /* The texture transfer has been mapped until now. * So unmap and release the texture transfer before drawing. */ - screen->transfer_unmap(screen, cache->trans); - cache->buffer = NULL; + if (cache->trans) { + screen->transfer_unmap(screen, cache->trans); + cache->buffer = NULL; - screen->tex_transfer_destroy(cache->trans); - cache->trans = NULL; + screen->tex_transfer_destroy(cache->trans); + cache->trans = NULL; + } draw_bitmap_quad(st->ctx, cache->xpos, @@ -709,6 +727,9 @@ accum_bitmap(struct st_context *st, if (y + height > cache->ymax) cache->ymax = y + height; + /* create the transfer if needed */ + create_cache_trans(st); + unpack_bitmap(st, px, py, width, height, unpack, bitmap, cache->buffer, BITMAP_CACHE_WIDTH); @@ -821,8 +842,7 @@ st_destroy_bitmap(struct st_context *st) struct pipe_screen *screen = pipe->screen; struct bitmap_cache *cache = st->bitmap.cache; - screen->transfer_unmap(screen, cache->trans); - screen->tex_transfer_destroy(cache->trans); + if (st->bitmap.vs) { cso_delete_vertex_shader(st->cso_context, st->bitmap.vs); @@ -834,7 +854,11 @@ st_destroy_bitmap(struct st_context *st) st->bitmap.vbuf = NULL; } - if (st->bitmap.cache) { + if (cache) { + if (cache->trans) { + screen->transfer_unmap(screen, cache->trans); + screen->tex_transfer_destroy(cache->trans); + } pipe_texture_reference(&st->bitmap.cache->texture, NULL); _mesa_free(st->bitmap.cache); st->bitmap.cache = NULL; diff --git a/src/mesa/state_tracker/st_cb_bufferobjects.c b/src/mesa/state_tracker/st_cb_bufferobjects.c index 3651e4ae7dc..a94e11fff12 100644 --- a/src/mesa/state_tracker/st_cb_bufferobjects.c +++ b/src/mesa/state_tracker/st_cb_bufferobjects.c @@ -30,6 +30,7 @@ #include "main/mtypes.h" #include "main/bufferobj.h" +#include "st_inlines.h" #include "st_context.h" #include "st_cb_bufferobjects.h" @@ -97,13 +98,13 @@ st_bufferobj_subdata(GLcontext *ctx, GLsizeiptrARB size, const GLvoid * data, struct gl_buffer_object *obj) { - struct pipe_context *pipe = st_context(ctx)->pipe; struct st_buffer_object *st_obj = st_buffer_object(obj); if (offset >= st_obj->size || size > (st_obj->size - offset)) return; - pipe_buffer_write(pipe->screen, st_obj->buffer, offset, size, data); + st_cond_flush_pipe_buffer_write(st_context(ctx), st_obj->buffer, + offset, size, data); } @@ -117,13 +118,13 @@ st_bufferobj_get_subdata(GLcontext *ctx, GLsizeiptrARB size, GLvoid * data, struct gl_buffer_object *obj) { - struct pipe_context *pipe = st_context(ctx)->pipe; struct st_buffer_object *st_obj = st_buffer_object(obj); if (offset >= st_obj->size || size > (st_obj->size - offset)) return; - pipe_buffer_read(pipe->screen, st_obj->buffer, offset, size, data); + st_cond_flush_pipe_buffer_read(st_context(ctx), st_obj->buffer, + offset, size, data); } @@ -168,10 +169,16 @@ st_bufferobj_data(GLcontext *ctx, st_obj->buffer = pipe_buffer_create( pipe->screen, 32, buffer_usage, size ); + if (!st_obj->buffer) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBufferDataARB"); + return; + } + st_obj->size = size; if (data) - st_bufferobj_subdata(ctx, target, 0, size, data, obj); + st_no_flush_pipe_buffer_write(st_context(ctx), st_obj->buffer, 0, + size, data); } @@ -182,7 +189,6 @@ static void * st_bufferobj_map(GLcontext *ctx, GLenum target, GLenum access, struct gl_buffer_object *obj) { - struct pipe_context *pipe = st_context(ctx)->pipe; struct st_buffer_object *st_obj = st_buffer_object(obj); GLuint flags; @@ -200,7 +206,9 @@ st_bufferobj_map(GLcontext *ctx, GLenum target, GLenum access, break; } - obj->Pointer = pipe_buffer_map(pipe->screen, st_obj->buffer, flags); + obj->Pointer = st_cond_flush_pipe_buffer_map(st_context(ctx), + st_obj->buffer, + flags); if(obj->Pointer) { obj->Offset = 0; obj->Length = obj->Size; diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index 5bdc6a13309..880e83108c1 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -45,6 +45,7 @@ #include "st_program.h" #include "st_public.h" #include "st_mesa_to_tgsi.h" +#include "st_inlines.h" #include "pipe/p_context.h" #include "pipe/p_inlines.h" @@ -166,10 +167,10 @@ draw_quad(GLcontext *ctx, } /* put vertex data into vbuf */ - pipe_buffer_write(pipe->screen, st->clear.vbuf, - st->clear.vbuf_slot * sizeof(st->clear.vertices), - sizeof(st->clear.vertices), - st->clear.vertices); + st_no_flush_pipe_buffer_write(st, st->clear.vbuf, + st->clear.vbuf_slot * sizeof(st->clear.vertices), + sizeof(st->clear.vertices), + st->clear.vertices); /* draw */ util_draw_vertex_buffer(pipe, diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index ebb1d1142aa..08dc7c930e2 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -53,6 +53,8 @@ #include "st_format.h" #include "st_mesa_to_tgsi.h" #include "st_texture.h" +#include "st_inlines.h" + #include "pipe/p_context.h" #include "pipe/p_defines.h" #include "pipe/p_inlines.h" @@ -144,6 +146,8 @@ combined_drawpix_fragment_program(GLcontext *ctx) st->pixel_xfer.xfer_prog_sn = st->pixel_xfer.program->serialNo; st->pixel_xfer.user_prog_sn = st->fp->serialNo; st->pixel_xfer.combined_prog_sn = stfp->serialNo; + /* can't reference new program directly, already have a reference on it */ + st_reference_fragprog(st, &st->pixel_xfer.combined_prog, NULL); st->pixel_xfer.combined_prog = stfp; } @@ -351,8 +355,7 @@ make_texture(struct st_context *st, if (!pixels) return NULL; - pt = st_texture_create(st, PIPE_TEXTURE_2D, pipeFormat, 0, width, height, - 1, 0, + pt = st_texture_create(st, PIPE_TEXTURE_2D, pipeFormat, 0, width, height, 1, PIPE_TEXTURE_USAGE_SAMPLER); if (!pt) { _mesa_unmap_drawpix_pbo(ctx, unpack); @@ -369,9 +372,9 @@ make_texture(struct st_context *st, /* we'll do pixel transfer in a fragment shader */ ctx->_ImageTransferState = 0x0; - transfer = screen->get_tex_transfer(screen, pt, 0, 0, 0, - PIPE_TRANSFER_WRITE, 0, 0, - width, height); + transfer = st_no_flush_get_tex_transfer(st, pt, 0, 0, 0, + PIPE_TRANSFER_WRITE, 0, 0, + width, height); /* map texture transfer */ dest = screen->transfer_map(screen, transfer); @@ -491,7 +494,7 @@ draw_quad(GLcontext *ctx, GLfloat x0, GLfloat y0, GLfloat z, /* allocate/load buffer object with vertex data */ buf = pipe_buffer_create(pipe->screen, 32, PIPE_BUFFER_USAGE_VERTEX, sizeof(verts)); - pipe_buffer_write(pipe->screen, buf, 0, sizeof(verts), verts); + st_no_flush_pipe_buffer_write(st, buf, 0, sizeof(verts), verts); util_draw_vertex_buffer(pipe, buf, 0, PIPE_PRIM_QUADS, @@ -632,8 +635,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); @@ -641,9 +642,9 @@ draw_stencil_pixels(GLcontext *ctx, GLint x, GLint y, y = ctx->DrawBuffer->Height - y - height; } - pt = screen->get_tex_transfer(screen, strb->texture, 0, 0, 0, - PIPE_TRANSFER_WRITE, x, y, - width, height); + pt = st_cond_flush_get_tex_transfer(st_context(ctx), strb->texture, 0, 0, 0, + PIPE_TRANSFER_WRITE, x, y, + width, height); stmap = screen->transfer_map(screen, pt); @@ -826,9 +827,10 @@ copy_stencil_pixels(GLcontext *ctx, GLint srcx, GLint srcy, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, &ctx->DefaultPacking, buffer); - ptDraw = screen->get_tex_transfer(screen, rbDraw->texture, 0, 0, 0, - PIPE_TRANSFER_WRITE, dstx, dsty, - width, height); + ptDraw = st_cond_flush_get_tex_transfer(st_context(ctx), + rbDraw->texture, 0, 0, 0, + PIPE_TRANSFER_WRITE, dstx, dsty, + width, height); assert(ptDraw->block.width == 1); assert(ptDraw->block.height == 1); @@ -904,7 +906,6 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy, GLfloat *color; enum pipe_format srcFormat, texFormat; - /* make sure rendering has completed */ pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL); st_validate_state(st); @@ -951,7 +952,7 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy, } pt = st_texture_create(ctx->st, PIPE_TEXTURE_2D, texFormat, 0, - width, height, 1, 0, + width, height, 1, PIPE_TEXTURE_USAGE_SAMPLER); if (!pt) return; @@ -978,13 +979,13 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy, else { /* CPU-based fallback/conversion */ struct pipe_transfer *ptRead = - screen->get_tex_transfer(screen, rbRead->texture, 0, 0, 0, - PIPE_TRANSFER_READ, srcx, srcy, width, - height); + st_cond_flush_get_tex_transfer(st, rbRead->texture, 0, 0, 0, + PIPE_TRANSFER_READ, srcx, srcy, width, + height); struct pipe_transfer *ptTex = - screen->get_tex_transfer(screen, pt, 0, 0, 0, PIPE_TRANSFER_WRITE, - 0, 0, width, height); + st_cond_flush_get_tex_transfer(st, pt, 0, 0, 0, PIPE_TRANSFER_WRITE, + 0, 0, width, height); if (type == GL_COLOR) { /* alternate path using get/put_tile() */ diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index f74d0d46d01..1590f275e2a 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -96,29 +96,22 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, pipe_surface_reference( &strb->surface, NULL ); pipe_texture_reference( &strb->texture, NULL ); - + /* Setup new texture template. + */ memset(&template, 0, sizeof(template)); - + template.target = PIPE_TEXTURE_2D; if (strb->format != PIPE_FORMAT_NONE) { template.format = strb->format; } else { template.format = st_choose_renderbuffer_format(pipe, internalFormat); } - - strb->Base.Width = width; - strb->Base.Height = height; - init_renderbuffer_bits(strb, template.format); - - template.target = PIPE_TEXTURE_2D; - template.compressed = 0; pf_get_block(template.format, &template.block); template.width[0] = width; template.height[0] = height; template.depth[0] = 1; template.last_level = 0; template.nr_samples = rb->NumSamples; - if (pf_is_depth_stencil(template.format)) { template.tex_usage = PIPE_TEXTURE_USAGE_DEPTH_STENCIL; } @@ -127,6 +120,10 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, PIPE_TEXTURE_USAGE_RENDER_TARGET); } + /* init renderbuffer fields */ + strb->Base.Width = width; + strb->Base.Height = height; + init_renderbuffer_bits(strb, template.format); /* Probably need dedicated flags for surface usage too: */ diff --git a/src/mesa/state_tracker/st_cb_readpixels.c b/src/mesa/state_tracker/st_cb_readpixels.c index 9ce5f3fe84c..7a4bbf5ce3a 100644 --- a/src/mesa/state_tracker/st_cb_readpixels.c +++ b/src/mesa/state_tracker/st_cb_readpixels.c @@ -42,13 +42,15 @@ #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" +#include "st_inlines.h" /** * Special case for reading stencil buffer. @@ -73,8 +75,11 @@ st_read_stencil_pixels(GLcontext *ctx, GLint x, GLint y, } /* Create a read transfer from the renderbuffer's texture */ - pt = screen->get_tex_transfer(screen, strb->texture, 0, 0, 0, - PIPE_TRANSFER_READ, x, y, width, height); + + pt = st_cond_flush_get_tex_transfer(st_context(ctx), strb->texture, + 0, 0, 0, + PIPE_TRANSFER_READ, x, y, + width, height); /* map the stencil buffer */ stmap = screen->transfer_map(screen, pt); @@ -240,8 +245,10 @@ st_fast_readpixels(GLcontext *ctx, struct st_renderbuffer *strb, y = strb->texture->height[0] - y - height; } - trans = screen->get_tex_transfer(screen, strb->texture, 0, 0, 0, - PIPE_TRANSFER_READ, x, y, width, height); + trans = st_cond_flush_get_tex_transfer(st_context(ctx), strb->texture, + 0, 0, 0, + PIPE_TRANSFER_READ, x, y, + width, height); if (!trans) { return GL_FALSE; } @@ -350,7 +357,6 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, if (!dest) return; - /* make sure rendering has completed */ st_flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL); if (format == GL_STENCIL_INDEX || @@ -395,8 +401,10 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, } /* Create a read transfer from the renderbuffer's texture */ - trans = screen->get_tex_transfer(screen, strb->texture, 0, 0, 0, - PIPE_TRANSFER_READ, x, y, width, height); + trans = st_cond_flush_get_tex_transfer(st_context(ctx), strb->texture, + 0, 0, 0, + PIPE_TRANSFER_READ, x, y, + width, height); /* determine bottom-to-top vs. top-to-bottom order */ if (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP) { diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c index 8013e69e8e1..c3e990e0775 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 @@ -49,12 +50,14 @@ #include "state_tracker/st_public.h" #include "state_tracker/st_texture.h" #include "state_tracker/st_gen_mipmap.h" +#include "state_tracker/st_inlines.h" #include "pipe/p_context.h" #include "pipe/p_defines.h" #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 @@ -88,7 +91,7 @@ gl_target_to_pipe(GLenum target) * Return nominal bytes per texel for a compressed format, 0 for non-compressed * format. */ -static int +static GLuint compressed_num_bytes(GLuint mesaFormat) { switch(mesaFormat) { @@ -110,6 +113,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) @@ -169,7 +191,7 @@ st_FreeTextureImageData(GLcontext * ctx, struct gl_texture_image *texImage) * than COPY_DWORDS would: * XXX Put this in src/mesa/main/imports.h ??? */ -#if defined(i386) || defined(__i386__) +#if defined(PIPE_CC_GCC) && defined(PIPE_ARCH_X86) static INLINE void * __memcpy(void *to, const void *from, size_t n) { @@ -227,6 +249,21 @@ logbase2(int n) /** + * Return default texture usage bitmask for the given texture format. + */ +static GLuint +default_usage(enum pipe_format fmt) +{ + GLuint usage = PIPE_TEXTURE_USAGE_SAMPLER; + if (pf_is_depth_stencil(fmt)) + usage |= PIPE_TEXTURE_USAGE_DEPTH_STENCIL; + else + usage |= PIPE_TEXTURE_USAGE_RENDER_TARGET; + return usage; +} + + +/** * Allocate a pipe_texture object for the given st_texture_object using * the given st_texture_image to guess the mipmap size/levels. * @@ -250,7 +287,7 @@ guess_and_alloc_texture(struct st_context *st, GLuint width = stImage->base.Width2; /* size w/out border */ GLuint height = stImage->base.Height2; GLuint depth = stImage->base.Depth2; - GLuint i, comp_byte = 0; + GLuint i, usage; enum pipe_format fmt; DBG("%s\n", __FUNCTION__); @@ -308,10 +345,10 @@ guess_and_alloc_texture(struct st_context *st, lastLevel = firstLevel + MAX2(MAX2(l2width, l2height), l2depth); } - if (stImage->base.IsCompressed) - comp_byte = compressed_num_bytes(stImage->base.TexFormat->MesaFormat); - fmt = st_mesa_format_to_pipe_format(stImage->base.TexFormat->MesaFormat); + + usage = default_usage(fmt); + stObj->pt = st_texture_create(st, gl_target_to_pipe(stObj->base.Target), fmt, @@ -319,11 +356,7 @@ guess_and_alloc_texture(struct st_context *st, width, height, depth, - comp_byte, - ( (pf_is_depth_stencil(fmt) ? - PIPE_TEXTURE_USAGE_DEPTH_STENCIL : - PIPE_TEXTURE_USAGE_RENDER_TARGET) | - PIPE_TEXTURE_USAGE_SAMPLER )); + usage); DBG("%s - success\n", __FUNCTION__); } @@ -368,6 +401,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 = st_cond_flush_get_tex_transfer(st_context(ctx), 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 @@ -381,8 +518,9 @@ st_TexImage(GLcontext * ctx, const struct gl_pixelstore_attrib *unpack, struct gl_texture_object *texObj, struct gl_texture_image *texImage, - GLsizei imageSize, int 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; @@ -395,8 +533,7 @@ st_TexImage(GLcontext * ctx, /* gallium does not support texture borders, strip it off */ if (border) { - strip_texture_border(border, &width, &height, &depth, - unpack, &unpackNB); + strip_texture_border(border, &width, &height, &depth, unpack, &unpackNB); unpack = &unpackNB; texImage->Width = width; texImage->Height = height; @@ -512,11 +649,12 @@ 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"); - } else { + } + else { pixels = _mesa_validate_pbo_teximage(ctx, dims, width, height, 1, format, type, pixels, unpack, "glTexImage"); @@ -524,12 +662,28 @@ 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, stImage->base.Width, stImage->base.Height); - dstRowStride = stImage->transfer->stride; + if(stImage->transfer) + dstRowStride = stImage->transfer->stride; } else { /* Allocate regular memory and store the image there temporarily. */ @@ -559,16 +713,16 @@ 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 { - GLuint srcImageStride = _mesa_image_image_stride(unpack, width, height, - format, type); - int i; + const GLuint srcImageStride = + _mesa_image_image_stride(unpack, width, height, format, type); + GLint i; const GLubyte *src = (const GLubyte *) pixels; - for (i = 0; i++ < depth;) { + for (i = 0; i < depth; i++) { if (!texImage->TexFormat->StoreImage(ctx, dims, texImage->_BaseFormat, texImage->TexFormat, @@ -581,9 +735,11 @@ st_TexImage(GLcontext * ctx, _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage"); } - if (stImage->pt && i < depth) { + if (stImage->pt && i + 1 < depth) { + /* unmap this slice */ st_texture_image_unmap(ctx->st, stImage); - texImage->Data = st_texture_image_map(ctx->st, stImage, i, + /* map next slice of 3D texture */ + texImage->Data = st_texture_image_map(ctx->st, stImage, i + 1, PIPE_TRANSFER_WRITE, 0, 0, stImage->base.Width, stImage->base.Height); @@ -594,7 +750,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; } @@ -616,9 +772,9 @@ st_TexImage3D(GLcontext * ctx, struct gl_texture_object *texObj, struct gl_texture_image *texImage) { - st_TexImage(ctx, 3, target, level, - internalFormat, width, height, depth, border, - format, type, pixels, unpack, texObj, texImage, 0, 0); + st_TexImage(ctx, 3, target, level, internalFormat, width, height, depth, + border, format, type, pixels, unpack, texObj, texImage, + 0, GL_FALSE); } @@ -632,9 +788,8 @@ st_TexImage2D(GLcontext * ctx, struct gl_texture_object *texObj, struct gl_texture_image *texImage) { - st_TexImage(ctx, 2, target, level, - internalFormat, width, height, 1, border, - format, type, pixels, unpack, texObj, texImage, 0, 0); + st_TexImage(ctx, 2, target, level, internalFormat, width, height, 1, border, + format, type, pixels, unpack, texObj, texImage, 0, GL_FALSE); } @@ -648,9 +803,8 @@ st_TexImage1D(GLcontext * ctx, struct gl_texture_object *texObj, struct gl_texture_image *texImage) { - st_TexImage(ctx, 1, target, level, - internalFormat, width, 1, 1, border, - format, type, pixels, unpack, texObj, texImage, 0, 0); + st_TexImage(ctx, 1, target, level, internalFormat, width, 1, 1, border, + format, type, pixels, unpack, texObj, texImage, 0, GL_FALSE); } @@ -662,12 +816,96 @@ st_CompressedTexImage2D(GLcontext *ctx, GLenum target, GLint level, struct gl_texture_object *texObj, struct gl_texture_image *texImage) { - st_TexImage(ctx, 2, target, level, - internalFormat, width, height, 1, border, - 0, 0, data, &ctx->Unpack, texObj, texImage, imageSize, 1); + st_TexImage(ctx, 2, target, level, internalFormat, width, height, 1, border, + 0, 0, data, &ctx->Unpack, texObj, texImage, imageSize, GL_TRUE); } + +/** + * 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 = st_cond_flush_get_tex_transfer(st_context(ctx), + 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. @@ -676,22 +914,36 @@ 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, int compressed) + struct gl_texture_image *texImage, GLboolean compressed_dst) { struct st_texture_image *stImage = st_texture_image(texImage); - GLuint dstImageStride = _mesa_image_image_stride(&ctx->Pack, - texImage->Width, - texImage->Height, - format, type); - GLuint depth; - GLuint i; + const GLuint dstImageStride = + _mesa_image_image_stride(&ctx->Pack, texImage->Width, texImage->Height, + format, type); + 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, @@ -715,18 +967,21 @@ st_get_tex_image(GLcontext * ctx, GLenum target, GLint level, dest = (GLubyte *) pixels; - for (i = 0; i++ < depth;) { - if (compressed) { + for (i = 0; i < depth; i++) { + if (compressed_dst) { _mesa_get_compressed_teximage(ctx, target, level, dest, texObj, texImage); - } else { + } + else { _mesa_get_teximage(ctx, target, level, format, type, dest, texObj, texImage); } - if (stImage->pt && i < depth) { + if (stImage->pt && i + 1 < depth) { + /* unmap this slice */ st_texture_image_unmap(ctx->st, stImage); - texImage->Data = st_texture_image_map(ctx->st, stImage, i, + /* map next slice of 3D texture */ + texImage->Data = st_texture_image_map(ctx->st, stImage, i + 1, PIPE_TRANSFER_READ, 0, 0, stImage->base.Width, stImage->base.Height); @@ -750,8 +1005,8 @@ st_GetTexImage(GLcontext * ctx, GLenum target, GLint level, struct gl_texture_object *texObj, struct gl_texture_image *texImage) { - st_get_tex_image(ctx, target, level, format, type, pixels, - texObj, texImage, 0); + st_get_tex_image(ctx, target, level, format, type, pixels, texObj, texImage, + GL_FALSE); } @@ -761,17 +1016,14 @@ st_GetCompressedTexImage(GLcontext *ctx, GLenum target, GLint level, struct gl_texture_object *texObj, struct gl_texture_image *texImage) { - st_get_tex_image(ctx, target, level, 0, 0, pixels, - (struct gl_texture_object *) texObj, - (struct gl_texture_image *) texImage, 1); + st_get_tex_image(ctx, target, level, 0, 0, pixels, texObj, texImage, + GL_TRUE); } static void -st_TexSubimage(GLcontext * ctx, - GLint dims, - GLenum target, GLint level, +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, @@ -779,11 +1031,12 @@ st_TexSubimage(GLcontext * ctx, 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; - GLuint srcImageStride = _mesa_image_image_stride(packing, width, height, - format, type); - int i; + const GLuint srcImageStride = + _mesa_image_image_stride(packing, width, height, format, type); + GLint i; const GLubyte *src; DBG("%s target %s level %d offset %d,%d %dx%d\n", __FUNCTION__, @@ -796,10 +1049,28 @@ st_TexSubimage(GLcontext * ctx, 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, @@ -814,7 +1085,7 @@ st_TexSubimage(GLcontext * ctx, src = (const GLubyte *) pixels; dstRowStride = stImage->transfer->stride; - for (i = 0; i++ < depth;) { + for (i = 0; i < depth; i++) { if (!texImage->TexFormat->StoreImage(ctx, dims, texImage->_BaseFormat, texImage->TexFormat, texImage->Data, @@ -826,10 +1097,12 @@ st_TexSubimage(GLcontext * ctx, _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexSubImage"); } - if (stImage->pt && i < depth) { - /* map next slice of 3D texture */ + if (stImage->pt && i + 1 < depth) { + /* unmap this slice */ st_texture_image_unmap(ctx->st, stImage); - texImage->Data = st_texture_image_map(ctx->st, stImage, zoffset + i, + /* map next slice of 3D texture */ + texImage->Data = st_texture_image_map(ctx->st, stImage, + zoffset + i + 1, PIPE_TRANSFER_WRITE, xoffset, yoffset, width, height); @@ -852,73 +1125,58 @@ st_TexSubimage(GLcontext * ctx, static void -st_TexSubImage3D(GLcontext * ctx, - GLenum target, - GLint level, - GLint xoffset, GLint yoffset, GLint zoffset, - GLsizei width, GLsizei height, GLsizei depth, - GLenum format, GLenum type, - const GLvoid * pixels, - const struct gl_pixelstore_attrib *packing, - struct gl_texture_object *texObj, - struct gl_texture_image *texImage) +st_TexSubImage3D(GLcontext *ctx, GLenum target, GLint level, + GLint xoffset, GLint yoffset, GLint zoffset, + GLsizei width, GLsizei height, GLsizei depth, + GLenum format, GLenum type, const GLvoid *pixels, + const struct gl_pixelstore_attrib *packing, + struct gl_texture_object *texObj, + struct gl_texture_image *texImage) { - st_TexSubimage(ctx, 3, target, level, - xoffset, yoffset, zoffset, - width, height, depth, - format, type, pixels, packing, texObj, texImage); + st_TexSubimage(ctx, 3, target, level, xoffset, yoffset, zoffset, + width, height, depth, format, type, + pixels, packing, texObj, texImage); } static void -st_TexSubImage2D(GLcontext * ctx, - GLenum target, - GLint level, - GLint xoffset, GLint yoffset, - GLsizei width, GLsizei height, - GLenum format, GLenum type, - const GLvoid * pixels, - const struct gl_pixelstore_attrib *packing, - struct gl_texture_object *texObj, - struct gl_texture_image *texImage) +st_TexSubImage2D(GLcontext *ctx, GLenum target, GLint level, + GLint xoffset, GLint yoffset, + GLsizei width, GLsizei height, + GLenum format, GLenum type, const GLvoid * pixels, + const struct gl_pixelstore_attrib *packing, + struct gl_texture_object *texObj, + struct gl_texture_image *texImage) { - st_TexSubimage(ctx, 2, target, level, - xoffset, yoffset, 0, - width, height, 1, - format, type, pixels, packing, texObj, texImage); + st_TexSubimage(ctx, 2, target, level, xoffset, yoffset, 0, + width, height, 1, format, type, + pixels, packing, texObj, texImage); } static void -st_TexSubImage1D(GLcontext * ctx, - GLenum target, - GLint level, - GLint xoffset, - GLsizei width, - GLenum format, GLenum type, - const GLvoid * pixels, - const struct gl_pixelstore_attrib *packing, - struct gl_texture_object *texObj, - struct gl_texture_image *texImage) +st_TexSubImage1D(GLcontext *ctx, GLenum target, GLint level, + GLint xoffset, GLsizei width, GLenum format, GLenum type, + const GLvoid * pixels, + const struct gl_pixelstore_attrib *packing, + struct gl_texture_object *texObj, + struct gl_texture_image *texImage) { - st_TexSubimage(ctx, 1, target, level, - xoffset, 0, 0, - width, 1, 1, + st_TexSubimage(ctx, 1, target, level, xoffset, 0, 0, width, 1, 1, format, type, pixels, packing, texObj, texImage); } /** - * Do a CopyTexSubImage operation using a read transfer from the source, a write - * transfer to the destination and get_tile()/put_tile() to access the pixels/texels. + * Do a CopyTexSubImage operation using a read transfer from the source, + * a write transfer to the destination and get_tile()/put_tile() to access + * the pixels/texels. * * Note: srcY=0=TOP of renderbuffer */ static void -fallback_copy_texsubimage(GLcontext *ctx, - GLenum target, - GLint level, +fallback_copy_texsubimage(GLcontext *ctx, GLenum target, GLint level, struct st_renderbuffer *strb, struct st_texture_image *stImage, GLenum baseFormat, @@ -937,12 +1195,15 @@ fallback_copy_texsubimage(GLcontext *ctx, srcY = strb->Base.Height - srcY - height; } - src_trans = screen->get_tex_transfer( screen, - strb->texture, - 0, 0, 0, - PIPE_TRANSFER_READ, - srcX, srcY, - width, height); + src_trans = st_cond_flush_get_tex_transfer( st_context(ctx), + strb->texture, + 0, 0, 0, + PIPE_TRANSFER_READ, + 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); @@ -980,8 +1241,8 @@ fallback_copy_texsubimage(GLcontext *ctx, if (tempSrc && texDest) { const GLint dims = 2; + const GLint dstRowStride = stImage->transfer->stride; struct gl_texture_image *texImage = &stImage->base; - GLint dstRowStride = stImage->transfer->stride; struct gl_pixelstore_attrib unpack = ctx->DefaultPacking; if (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP) { @@ -1095,7 +1356,6 @@ st_copy_texsubimage(GLcontext *ctx, if (src_format == dest_format && !do_flip) { /* use surface_copy() / blit */ - dest_surface = screen->get_tex_surface(screen, stImage->pt, stImage->face, stImage->level, destZ, @@ -1122,7 +1382,7 @@ st_copy_texsubimage(GLcontext *ctx, PIPE_TEXTURE_USAGE_RENDER_TARGET, 0)) { /* draw textured quad to do the copy */ - int srcY0, srcY1; + GLint srcY0, srcY1; dest_surface = screen->get_tex_surface(screen, stImage->pt, stImage->face, stImage->level, @@ -1179,11 +1439,6 @@ st_CopyTexImage1D(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. */ @@ -1274,8 +1529,8 @@ calculate_first_last_level(struct st_texture_object *stObj) * and having firstLevel and lastLevel as signed prevents the need for * extra sign checks. */ - int firstLevel; - int lastLevel; + GLint firstLevel; + GLint lastLevel; /* Yes, this looks overly complicated, but it's all needed. */ @@ -1329,16 +1584,21 @@ copy_image_data_to_texture(struct st_context *st, /* More straightforward upload. */ - st_texture_image_data(st->pipe, - stObj->pt, - stImage->face, - dstLevel, - stImage->base.Data, - stImage->base.RowStride * - stObj->pt->block.size, - stImage->base.RowStride * - stImage->base.Height * - stObj->pt->block.size); + + st_teximage_flush_before_map(st, stObj->pt, stImage->face, dstLevel, + PIPE_TRANSFER_WRITE); + + + st_texture_image_data(st, + stObj->pt, + stImage->face, + dstLevel, + stImage->base.Data, + stImage->base.RowStride * + stObj->pt->block.size, + stImage->base.RowStride * + stImage->base.Height * + stObj->pt->block.size); _mesa_align_free(stImage->base.Data); stImage->base.Data = NULL; } @@ -1360,9 +1620,7 @@ st_finalize_texture(GLcontext *ctx, { struct st_texture_object *stObj = st_texture_object(tObj); const GLuint nr_faces = (stObj->base.Target == GL_TEXTURE_CUBE_MAP) ? 6 : 1; - int comp_byte = 0; - int cpp; - GLuint face; + GLuint cpp, face; struct st_texture_image *firstImage; *needFlush = GL_FALSE; @@ -1384,14 +1642,12 @@ st_finalize_texture(GLcontext *ctx, if (firstImage->pt && firstImage->pt != stObj->pt && firstImage->pt->last_level >= stObj->lastLevel) { - pipe_texture_reference(&stObj->pt, firstImage->pt); } /* FIXME: determine format block instead of cpp */ if (firstImage->base.IsCompressed) { - comp_byte = compressed_num_bytes(firstImage->base.TexFormat->MesaFormat); - cpp = comp_byte; + cpp = compressed_num_bytes(firstImage->base.TexFormat->MesaFormat); } else { cpp = firstImage->base.TexFormat->TexelBytes; @@ -1409,8 +1665,9 @@ st_finalize_texture(GLcontext *ctx, stObj->pt->width[0] != firstImage->base.Width2 || stObj->pt->height[0] != firstImage->base.Height2 || stObj->pt->depth[0] != firstImage->base.Depth2 || - stObj->pt->block.size/stObj->pt->block.width != cpp || /* Nominal bytes per pixel */ - stObj->pt->compressed != firstImage->base.IsCompressed) { + /* Nominal bytes per pixel: */ + stObj->pt->block.size / stObj->pt->block.width != cpp) + { pipe_texture_reference(&stObj->pt, NULL); ctx->st->dirty.st |= ST_NEW_FRAMEBUFFER; } @@ -1421,6 +1678,8 @@ st_finalize_texture(GLcontext *ctx, if (!stObj->pt) { const enum pipe_format fmt = st_mesa_format_to_pipe_format(firstImage->base.TexFormat->MesaFormat); + GLuint usage = default_usage(fmt); + stObj->pt = st_texture_create(ctx->st, gl_target_to_pipe(stObj->base.Target), fmt, @@ -1428,11 +1687,7 @@ st_finalize_texture(GLcontext *ctx, firstImage->base.Width2, firstImage->base.Height2, firstImage->base.Depth2, - comp_byte, - ( (pf_is_depth_stencil(fmt) ? - PIPE_TEXTURE_USAGE_DEPTH_STENCIL : - PIPE_TEXTURE_USAGE_RENDER_TARGET) | - PIPE_TEXTURE_USAGE_SAMPLER )); + usage); if (!stObj->pt) { _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage"); diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index ae8c2978bf8..f840579a404 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -116,11 +116,6 @@ struct st_context char vendor[100]; char renderer[100]; - /* State to be validated: - */ - struct st_tracked_state **atoms; - GLuint nr_atoms; - struct st_state_flags dirty; GLboolean missing_textures; diff --git a/src/mesa/state_tracker/st_format.c b/src/mesa/state_tracker/st_format.c index 9e2d60c9269..d507e3e58dd 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 3f5ac3201b1..7bbbe2d5704 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 9cc2176d5e4..e159b4c9db5 100644 --- a/src/mesa/state_tracker/st_gen_mipmap.c +++ b/src/mesa/state_tracker/st_gen_mipmap.c @@ -47,6 +47,7 @@ #include "st_program.h" #include "st_texture.h" #include "st_cb_texture.h" +#include "st_inlines.h" /** @@ -123,14 +124,17 @@ fallback_generate_mipmap(GLcontext *ctx, GLenum target, const ubyte *srcData; ubyte *dstData; - srcTrans = screen->get_tex_transfer(screen, pt, face, srcLevel, zslice, - PIPE_TRANSFER_READ, 0, 0, - pt->width[srcLevel], - pt->height[srcLevel]); - dstTrans = screen->get_tex_transfer(screen, pt, face, dstLevel, zslice, - PIPE_TRANSFER_WRITE, 0, 0, - pt->width[dstLevel], - pt->height[dstLevel]); + srcTrans = st_cond_flush_get_tex_transfer(st_context(ctx), pt, face, + srcLevel, zslice, + PIPE_TRANSFER_READ, 0, 0, + pt->width[srcLevel], + pt->height[srcLevel]); + + dstTrans = st_cond_flush_get_tex_transfer(st_context(ctx), pt, face, + dstLevel, zslice, + PIPE_TRANSFER_WRITE, 0, 0, + pt->width[dstLevel], + pt->height[dstLevel]); srcData = (ubyte *) screen->transfer_map(screen, srcTrans); dstData = (ubyte *) screen->transfer_map(screen, dstTrans); diff --git a/src/mesa/state_tracker/st_inlines.h b/src/mesa/state_tracker/st_inlines.h new file mode 100644 index 00000000000..0322d5dfa6e --- /dev/null +++ b/src/mesa/state_tracker/st_inlines.h @@ -0,0 +1,122 @@ +#ifndef ST_INLINES_H +#define ST_INLINES_H + +#include "pipe/p_context.h" +#include "pipe/p_screen.h" +#include "pipe/p_defines.h" +#include "pipe/p_inlines.h" +#include "pipe/p_state.h" + +#include "st_context.h" +#include "st_texture.h" +#include "st_public.h" + +static INLINE struct pipe_transfer * +st_cond_flush_get_tex_transfer(struct st_context *st, + struct pipe_texture *pt, + unsigned int face, + unsigned int level, + unsigned int zslice, + enum pipe_transfer_usage usage, + unsigned int x, unsigned int y, + unsigned int w, unsigned int h) +{ + struct pipe_screen *screen = st->pipe->screen; + + st_teximage_flush_before_map(st, pt, face, level, usage); + return screen->get_tex_transfer(screen, pt, face, level, zslice, usage, + x, y, w, h); +} + +static INLINE struct pipe_transfer * +st_no_flush_get_tex_transfer(struct st_context *st, + struct pipe_texture *pt, + unsigned int face, + unsigned int level, + unsigned int zslice, + enum pipe_transfer_usage usage, + unsigned int x, unsigned int y, + unsigned int w, unsigned int h) +{ + struct pipe_screen *screen = st->pipe->screen; + + return screen->get_tex_transfer(screen, pt, face, level, + zslice, usage, x, y, w, h); +} + +static INLINE void * +st_cond_flush_pipe_buffer_map(struct st_context *st, + struct pipe_buffer *buf, + unsigned int map_flags) +{ + struct pipe_context *pipe = st->pipe; + unsigned int referenced = pipe->is_buffer_referenced(pipe, buf); + + if (referenced && ((referenced & PIPE_REFERENCED_FOR_WRITE) || + (map_flags & PIPE_BUFFER_USAGE_CPU_WRITE))) + st_flush(st, PIPE_FLUSH_RENDER_CACHE, NULL); + + return pipe_buffer_map(pipe->screen, buf, map_flags); +} + +static INLINE void * +st_no_flush_pipe_buffer_map(struct st_context *st, + struct pipe_buffer *buf, + unsigned int map_flags) +{ + return pipe_buffer_map(st->pipe->screen, buf, map_flags); +} + + +static INLINE void +st_cond_flush_pipe_buffer_write(struct st_context *st, + struct pipe_buffer *buf, + unsigned int offset, + unsigned int size, + const void * data) +{ + struct pipe_context *pipe = st->pipe; + + if (pipe->is_buffer_referenced(pipe, buf)) + st_flush(st, PIPE_FLUSH_RENDER_CACHE, NULL); + + pipe_buffer_write(pipe->screen, buf, offset, size, data); +} + +static INLINE void +st_no_flush_pipe_buffer_write(struct st_context *st, + struct pipe_buffer *buf, + unsigned int offset, + unsigned int size, + const void * data) +{ + pipe_buffer_write(st->pipe->screen, buf, offset, size, data); +} + +static INLINE void +st_cond_flush_pipe_buffer_read(struct st_context *st, + struct pipe_buffer *buf, + unsigned int offset, + unsigned int size, + void * data) +{ + struct pipe_context *pipe = st->pipe; + + if (pipe->is_buffer_referenced(pipe, buf) & PIPE_REFERENCED_FOR_WRITE) + st_flush(st, PIPE_FLUSH_RENDER_CACHE, NULL); + + pipe_buffer_read(pipe->screen, buf, offset, size, data); +} + +static INLINE void +st_no_flush_pipe_buffer_read(struct st_context *st, + struct pipe_buffer *buf, + unsigned int offset, + unsigned int size, + void * data) +{ + pipe_buffer_read(st->pipe->screen, buf, offset, size, data); +} + +#endif + diff --git a/src/mesa/state_tracker/st_mesa_to_tgsi.c b/src/mesa/state_tracker/st_mesa_to_tgsi.c index ffa607dd87c..43c9afccc3b 100644 --- a/src/mesa/state_tracker/st_mesa_to_tgsi.c +++ b/src/mesa/state_tracker/st_mesa_to_tgsi.c @@ -275,8 +275,8 @@ compile_instruction( /* swizzle (ext swizzle also depends on negation) */ { GLuint swz[4]; - GLboolean extended = (inst->SrcReg[i].NegateBase != NEGATE_NONE && - inst->SrcReg[i].NegateBase != NEGATE_XYZW); + GLboolean extended = (inst->SrcReg[i].Negate != NEGATE_NONE && + inst->SrcReg[i].Negate != NEGATE_XYZW); for( j = 0; j < 4; j++ ) { swz[j] = GET_SWZ( inst->SrcReg[i].Swizzle, j ); if (swz[j] > SWIZZLE_W) @@ -296,20 +296,20 @@ compile_instruction( } } - if( inst->SrcReg[i].NegateBase == NEGATE_XYZW ) { + if( inst->SrcReg[i].Negate == NEGATE_XYZW ) { fullsrc->SrcRegister.Negate = 1; } - else if( inst->SrcReg[i].NegateBase != NEGATE_NONE ) { - if( inst->SrcReg[i].NegateBase & NEGATE_X ) { + else if( inst->SrcReg[i].Negate != NEGATE_NONE ) { + if( inst->SrcReg[i].Negate & NEGATE_X ) { fullsrc->SrcRegisterExtSwz.NegateX = 1; } - if( inst->SrcReg[i].NegateBase & NEGATE_Y ) { + if( inst->SrcReg[i].Negate & NEGATE_Y ) { fullsrc->SrcRegisterExtSwz.NegateY = 1; } - if( inst->SrcReg[i].NegateBase & NEGATE_Z ) { + if( inst->SrcReg[i].Negate & NEGATE_Z ) { fullsrc->SrcRegisterExtSwz.NegateZ = 1; } - if( inst->SrcReg[i].NegateBase & NEGATE_W ) { + if( inst->SrcReg[i].Negate & NEGATE_W ) { fullsrc->SrcRegisterExtSwz.NegateW = 1; } } @@ -318,10 +318,6 @@ compile_instruction( fullsrc->SrcRegisterExtMod.Absolute = 1; } - if( inst->SrcReg[i].NegateAbs ) { - fullsrc->SrcRegisterExtMod.Negate = 1; - } - if( inst->SrcReg[i].RelAddr ) { fullsrc->SrcRegister.Indirect = 1; diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c index 6348e83d8ae..2795570cf10 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 3f90ad502c2..10faa633ea8 100644 --- a/src/mesa/state_tracker/st_texture.c +++ b/src/mesa/state_tracker/st_texture.c @@ -30,6 +30,7 @@ #include "st_public.h" #include "st_texture.h" #include "st_cb_fbo.h" +#include "st_inlines.h" #include "main/enums.h" #include "main/teximage.h" #include "main/texstore.h" @@ -78,7 +79,6 @@ st_texture_create(struct st_context *st, GLuint width0, GLuint height0, GLuint depth0, - GLuint compress_byte, GLuint usage ) { struct pipe_texture pt, *newtex; @@ -101,7 +101,6 @@ st_texture_create(struct st_context *st, pt.width[0] = width0; pt.height[0] = height0; pt.depth[0] = depth0; - pt.compressed = compress_byte ? 1 : 0; pf_get_block(format, &pt.block); pt.tex_usage = usage; @@ -128,8 +127,7 @@ st_texture_match_image(const struct pipe_texture *pt, /* Check if this image's format matches the established texture's format. */ - if (st_mesa_format_to_pipe_format(image->TexFormat->MesaFormat) != pt->format || - image->IsCompressed != pt->compressed) + if (st_mesa_format_to_pipe_format(image->TexFormat->MesaFormat) != pt->format) return GL_FALSE; /* Test if this image's size matches what's expected in the @@ -191,13 +189,15 @@ 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, - stImage->level, zoffset, - usage, x, y, w, h); + stImage->transfer = st_no_flush_get_tex_transfer(st, pt, stImage->face, + stImage->level, zoffset, + usage, x, y, w, h); if (stImage->transfer) return screen->transfer_map(screen, stImage->transfer); @@ -254,13 +254,14 @@ st_surface_data(struct pipe_context *pipe, /* Upload data for a particular image. */ void -st_texture_image_data(struct pipe_context *pipe, +st_texture_image_data(struct st_context *st, struct pipe_texture *dst, GLuint face, GLuint level, void *src, GLuint src_row_stride, GLuint src_image_stride) { + struct pipe_context *pipe = st->pipe; struct pipe_screen *screen = pipe->screen; GLuint depth = dst->depth[level]; GLuint i; @@ -268,11 +269,12 @@ 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, - dst->width[level], - dst->height[level]); + dst_transfer = st_no_flush_get_tex_transfer(st, dst, face, level, i, + PIPE_TRANSFER_WRITE, 0, 0, + dst->width[level], + dst->height[level]); st_surface_data(pipe, dst_transfer, 0, 0, /* dstx, dsty */ @@ -484,3 +486,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 28c2f580f68..b9d447cb56e 100644 --- a/src/mesa/state_tracker/st_texture.h +++ b/src/mesa/state_tracker/st_texture.h @@ -108,7 +108,6 @@ st_texture_create(struct st_context *st, GLuint width0, GLuint height0, GLuint depth0, - GLuint compress_byte, GLuint tex_usage ); @@ -157,7 +156,7 @@ st_texture_texel_offset(const struct pipe_texture * pt, /* Upload an image into a texture */ extern void -st_texture_image_data(struct pipe_context *pipe, +st_texture_image_data(struct st_context *st, struct pipe_texture *dst, GLuint face, GLuint level, void *src, GLuint src_row_pitch, GLuint src_image_pitch); @@ -171,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 |