From: Keith Whitwell Date: Sat, 13 Mar 2010 15:06:35 +0000 (+0000) Subject: Merge commit 'origin/master' into gallium-sampler-view X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=47bfbd452c93e6a8db013fb90d9f42210cf24889;p=mesa.git Merge commit 'origin/master' into gallium-sampler-view Conflicts: src/gallium/auxiliary/util/u_tile.c src/gallium/auxiliary/util/u_tile.h src/gallium/drivers/identity/id_context.c src/gallium/drivers/llvmpipe/lp_setup.c src/gallium/drivers/llvmpipe/lp_setup.h src/gallium/drivers/softpipe/sp_tex_tile_cache.c src/gallium/include/pipe/p_context.h src/mesa/state_tracker/st_cb_bitmap.c src/mesa/state_tracker/st_cb_drawpixels.c --- 47bfbd452c93e6a8db013fb90d9f42210cf24889 diff --cc src/gallium/auxiliary/util/u_tile.c index 8a36d4d9d18,e445895efc5..82e44192aaf --- a/src/gallium/auxiliary/util/u_tile.c +++ b/src/gallium/auxiliary/util/u_tile.c @@@ -1273,70 -1274,9 +1274,72 @@@ pipe_get_tile_rgba(struct pipe_context } +void - pipe_get_tile_swizzle(struct pipe_transfer *pt, ++pipe_get_tile_swizzle(struct pipe_context *pipe, ++ struct pipe_transfer *pt, + uint x, + uint y, + uint w, + uint h, + uint swizzle_r, + uint swizzle_g, + uint swizzle_b, + uint swizzle_a, + enum pipe_format format, + float *p) +{ + unsigned dst_stride = w * 4; + void *packed; + uint i; + float rgba01[6]; + + if (pipe_clip_tile(x, y, &w, &h, pt)) { + return; + } + + packed = MALLOC(util_format_get_nblocks(format, w, h) * util_format_get_blocksize(format)); + if (!packed) { + return; + } + + if (format == PIPE_FORMAT_UYVY || format == PIPE_FORMAT_YUYV) { + assert((x & 1) == 0); + } + - pipe_get_tile_raw(pt, x, y, w, h, packed, 0); ++ pipe_get_tile_raw(pipe, pt, x, y, w, h, packed, 0); + + pipe_tile_raw_to_rgba(format, packed, w, h, p, dst_stride); + + FREE(packed); + + if (swizzle_r == PIPE_SWIZZLE_RED && + swizzle_g == PIPE_SWIZZLE_GREEN && + swizzle_b == PIPE_SWIZZLE_BLUE && + swizzle_a == PIPE_SWIZZLE_ALPHA) { + /* no-op, skip */ + return; + } + + rgba01[PIPE_SWIZZLE_ZERO] = 0.0f; + rgba01[PIPE_SWIZZLE_ONE] = 1.0f; + + for (i = 0; i < w * h; i++) { + rgba01[PIPE_SWIZZLE_RED] = p[0]; + rgba01[PIPE_SWIZZLE_GREEN] = p[1]; + rgba01[PIPE_SWIZZLE_BLUE] = p[2]; + rgba01[PIPE_SWIZZLE_ALPHA] = p[3]; + + *p++ = rgba01[swizzle_r]; + *p++ = rgba01[swizzle_g]; + *p++ = rgba01[swizzle_b]; + *p++ = rgba01[swizzle_a]; + } +} + + void - pipe_put_tile_rgba(struct pipe_transfer *pt, + pipe_put_tile_rgba(struct pipe_context *pipe, + struct pipe_transfer *pt, uint x, uint y, uint w, uint h, const float *p) { diff --cc src/gallium/auxiliary/util/u_tile.h index d665fdb1bb1,8329087cfa6..1d8ce7d8cbc --- a/src/gallium/auxiliary/util/u_tile.h +++ b/src/gallium/auxiliary/util/u_tile.h @@@ -71,21 -74,9 +74,23 @@@ pipe_get_tile_rgba(struct pipe_context uint x, uint y, uint w, uint h, float *p); +void - pipe_get_tile_swizzle(struct pipe_transfer *pt, ++pipe_get_tile_swizzle(struct pipe_context *pipe, ++ struct pipe_transfer *pt, + uint x, + uint y, + uint w, + uint h, + uint swizzle_r, + uint swizzle_g, + uint swizzle_b, + uint swizzle_a, + enum pipe_format format, + float *p); + void - pipe_put_tile_rgba(struct pipe_transfer *pt, + pipe_put_tile_rgba(struct pipe_context *pipe, + struct pipe_transfer *pt, uint x, uint y, uint w, uint h, const float *p); diff --cc src/gallium/drivers/identity/id_context.c index ef5b428161c,26770d6b1e9..00a542215ad --- a/src/gallium/drivers/identity/id_context.c +++ b/src/gallium/drivers/identity/id_context.c @@@ -707,46 -711,76 +707,115 @@@ identity_is_buffer_referenced(struct pi buffer); } +static struct pipe_sampler_view * +identity_create_sampler_view(struct pipe_context *pipe, + struct pipe_texture *texture, + const struct pipe_sampler_view *templ) +{ + struct identity_context *id_pipe = identity_context(pipe); + struct identity_texture *id_texture = identity_texture(texture); + struct pipe_context *pipe_unwrapped = id_pipe->pipe; + struct pipe_texture *texture_unwrapped = id_texture->texture; + struct identity_sampler_view *view = malloc(sizeof(struct identity_sampler_view)); + + view->sampler_view = pipe_unwrapped->create_sampler_view(pipe_unwrapped, + texture_unwrapped, + templ); + + view->base = *templ; + view->base.reference.count = 1; + view->base.texture = NULL; + pipe_texture_reference(&view->base.texture, texture); + view->base.context = pipe; + + return &view->base; +} + +static void +identity_sampler_view_destroy(struct pipe_context *pipe, + struct pipe_sampler_view *view) +{ + struct identity_context *id_pipe = identity_context(pipe); + struct identity_sampler_view *id_view = identity_sampler_view(view); + struct pipe_context *pipe_unwrapped = id_pipe->pipe; + struct pipe_sampler_view *view_unwrapped = id_view->sampler_view; + + pipe_unwrapped->sampler_view_destroy(pipe_unwrapped, + view_unwrapped); + + pipe_texture_reference(&view->texture, NULL); + free(view); +} + + static struct pipe_transfer * + identity_context_get_tex_transfer(struct pipe_context *_context, + struct pipe_texture *_texture, + unsigned face, + unsigned level, + unsigned zslice, + enum pipe_transfer_usage usage, + unsigned x, + unsigned y, + unsigned w, + unsigned h) + { + struct identity_context *id_context = identity_context(_context); + struct identity_texture *id_texture = identity_texture(_texture); + struct pipe_context *context = id_context->pipe; + struct pipe_texture *texture = id_texture->texture; + struct pipe_transfer *result; + + result = context->get_tex_transfer(context, + texture, + face, + level, + zslice, + usage, + x, + y, + w, + h); + + if (result) + return identity_transfer_create(id_context, id_texture, result); + return NULL; + } + + static void + identity_context_tex_transfer_destroy(struct pipe_context *_pipe, + struct pipe_transfer *_transfer) + { + identity_transfer_destroy(identity_context(_pipe), + identity_transfer(_transfer)); + } + + static void * + identity_context_transfer_map(struct pipe_context *_context, + struct pipe_transfer *_transfer) + { + struct identity_context *id_context = identity_context(_context); + struct identity_transfer *id_transfer = identity_transfer(_transfer); + struct pipe_context *context = id_context->pipe; + struct pipe_transfer *transfer = id_transfer->transfer; + + return context->transfer_map(context, + transfer); + } + + static void + identity_context_transfer_unmap(struct pipe_context *_context, + struct pipe_transfer *_transfer) + { + struct identity_context *id_context = identity_context(_context); + struct identity_transfer *id_transfer = identity_transfer(_transfer); + struct pipe_context *context = id_context->pipe; + struct pipe_transfer *transfer = id_transfer->transfer; + + context->transfer_unmap(context, + transfer); + } + struct pipe_context * identity_context_create(struct pipe_screen *_screen, struct pipe_context *pipe) { @@@ -811,8 -845,10 +880,12 @@@ id_pipe->base.flush = identity_flush; id_pipe->base.is_texture_referenced = identity_is_texture_referenced; id_pipe->base.is_buffer_referenced = identity_is_buffer_referenced; + id_pipe->base.create_sampler_view = identity_create_sampler_view; + id_pipe->base.sampler_view_destroy = identity_sampler_view_destroy; + id_pipe->base.get_tex_transfer = identity_context_get_tex_transfer; + id_pipe->base.tex_transfer_destroy = identity_context_tex_transfer_destroy; + id_pipe->base.transfer_map = identity_context_transfer_map; + id_pipe->base.transfer_unmap = identity_context_transfer_unmap; id_pipe->pipe = pipe; diff --cc src/gallium/drivers/llvmpipe/lp_setup.c index 059584f2a77,16128c34c80..cd16b6b2d38 --- a/src/gallium/drivers/llvmpipe/lp_setup.c +++ b/src/gallium/drivers/llvmpipe/lp_setup.c @@@ -448,12 -450,11 +450,12 @@@ lp_setup_set_vertex_info( struct lp_set /** - * Called during state validation when LP_NEW_TEXTURE is set. + * Called during state validation when LP_NEW_SAMPLER_VIEW is set. */ void - lp_setup_set_fragment_sampler_views(struct setup_context *setup, -lp_setup_set_sampler_textures( struct lp_setup_context *setup, - unsigned num, struct pipe_texture **texture) ++lp_setup_set_fragment_sampler_views(struct lp_setup_context *setup, + unsigned num, + struct pipe_sampler_view **views) { unsigned i; diff --cc src/gallium/drivers/llvmpipe/lp_setup.h index 72116b8c6c4,be1bf96f12d..414eaec98d1 --- a/src/gallium/drivers/llvmpipe/lp_setup.h +++ b/src/gallium/drivers/llvmpipe/lp_setup.h @@@ -120,12 -121,11 +121,12 @@@ lp_setup_set_scissor( struct lp_setup_c const struct pipe_scissor_state *scissor ); void - lp_setup_set_fragment_sampler_views(struct setup_context *setup, -lp_setup_set_sampler_textures( struct lp_setup_context *setup, - unsigned num, struct pipe_texture **texture); ++lp_setup_set_fragment_sampler_views(struct lp_setup_context *setup, + unsigned num, + struct pipe_sampler_view **views); unsigned - lp_setup_is_texture_referenced( const struct setup_context *setup, + lp_setup_is_texture_referenced( const struct lp_setup_context *setup, const struct pipe_texture *texture ); void diff --cc src/gallium/drivers/softpipe/sp_tex_tile_cache.c index dfa002a79b4,e3a5e37ce44..6594514c38f --- a/src/gallium/drivers/softpipe/sp_tex_tile_cache.c +++ b/src/gallium/drivers/softpipe/sp_tex_tile_cache.c @@@ -266,17 -251,12 +260,18 @@@ sp_find_cached_tile_tex(struct softpipe } /* get tile from the transfer (view into texture) */ - pipe_get_tile_swizzle(tc->tex_trans, - pipe_get_tile_rgba(tc->pipe, - tc->tex_trans, - addr.bits.x * TILE_SIZE, - addr.bits.y * TILE_SIZE, - TILE_SIZE, TILE_SIZE, - (float *) tile->data.color); ++ pipe_get_tile_swizzle(tc->pipe, ++ tc->tex_trans, + addr.bits.x * TILE_SIZE, + addr.bits.y * TILE_SIZE, + TILE_SIZE, + TILE_SIZE, + tc->swizzle_r, + tc->swizzle_g, + tc->swizzle_b, + tc->swizzle_a, + tc->format, + (float *) tile->data.color); tile->addr = addr; } diff --cc src/gallium/drivers/trace/tr_context.c index f9555fb922c,b7e6bbac68e..5c24bd1f7df --- a/src/gallium/drivers/trace/tr_context.c +++ b/src/gallium/drivers/trace/tr_context.c @@@ -25,10 -25,11 +25,12 @@@ * **************************************************************************/ +#include "util/u_inlines.h" #include "util/u_memory.h" #include "util/u_simple_list.h" + #include "util/u_format.h" + #include "pipe/p_format.h" #include "pipe/p_screen.h" #include "tr_dump.h" diff --cc src/gallium/include/pipe/p_context.h index 17fad1fa243,a7f12fb81e1..d1b734a9f9a --- a/src/gallium/include/pipe/p_context.h +++ b/src/gallium/include/pipe/p_context.h @@@ -307,15 -307,32 +307,41 @@@ struct pipe_context unsigned int (*is_buffer_referenced)(struct pipe_context *pipe, struct pipe_buffer *buf); + /** + * Create a view on a texture to be used by a shader stage. + */ + struct pipe_sampler_view * (*create_sampler_view)(struct pipe_context *ctx, + struct pipe_texture *texture, + const struct pipe_sampler_view *templat); + + void (*sampler_view_destroy)(struct pipe_context *ctx, + struct pipe_sampler_view *view); + + + /** + * Get a transfer object for transferring data to/from a texture. + * + * Transfers are (by default) context-private and allow uploads to be + * interleaved with + */ + struct pipe_transfer *(*get_tex_transfer)(struct pipe_context *, + struct pipe_texture *texture, + unsigned face, unsigned level, + unsigned zslice, + enum pipe_transfer_usage usage, + unsigned x, unsigned y, + unsigned w, unsigned h); + + void (*tex_transfer_destroy)(struct pipe_context *, + struct pipe_transfer *); + + void *(*transfer_map)( struct pipe_context *, + struct pipe_transfer *transfer ); + + void (*transfer_unmap)( struct pipe_context *, + struct pipe_transfer *transfer ); + + }; diff --cc src/mesa/state_tracker/st_cb_bitmap.c index 25d33b933e3,dfd8925edf4..9a0446bb710 --- a/src/mesa/state_tracker/st_cb_bitmap.c +++ b/src/mesa/state_tracker/st_cb_bitmap.c @@@ -601,8 -598,6 +598,7 @@@ st_flush_bitmap_cache(struct st_contex if (st->ctx->DrawBuffer) { struct pipe_context *pipe = st->pipe; - struct pipe_screen *screen = pipe->screen; + struct pipe_sampler_view *sv; assert(cache->xmin <= cache->xmax); diff --cc src/mesa/state_tracker/st_cb_drawpixels.c index 236010c5b5d,c44d0fc3e86..75be79fd4b0 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@@ -586,16 -608,16 +608,16 @@@ draw_textured_quad(GLcontext *ctx, GLin /* texture state: */ if (st->pixel_xfer.pixelmap_enabled) { - struct pipe_texture *textures[2]; - textures[0] = pt; - textures[1] = st->pixel_xfer.pixelmap_texture; - pipe->set_fragment_sampler_textures(pipe, 2, textures); + struct pipe_sampler_view *sampler_views[2]; + sampler_views[0] = sv; + sampler_views[1] = st->pixel_xfer.pixelmap_sampler_view; + cso_set_fragment_sampler_views(cso, 2, sampler_views); } else { - pipe->set_fragment_sampler_textures(pipe, 1, &pt); + cso_set_fragment_sampler_views(cso, 1, &sv); } - /* Compute window coords (y=0=bottom) with pixel zoom. + /* Compute Gallium window coords (y=0=top) with pixel zoom. * Recall that these coords are transformed by the current * vertex shader and viewport transformation. */ @@@ -938,10 -959,9 +964,10 @@@ st_CopyPixels(GLcontext *ctx, GLint src struct st_renderbuffer *rbRead; void *driver_vp, *driver_fp; struct pipe_texture *pt; + struct pipe_sampler_view *sv; GLfloat *color; enum pipe_format srcFormat, texFormat; - int ptw, pth; + GLboolean invertTex = GL_FALSE; pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL); @@@ -1056,12 -1056,9 +1062,15 @@@ if (!pt) return; + sv = st_sampler_view_from_texture(st->pipe, pt); + if (!sv) { + pipe_texture_reference(&pt, NULL); + return; + } + + /* Make temporary texture which is a copy of the src region. + * We'll draw a quad with this texture to draw the dest image. + */ if (srcFormat == texFormat) { /* copy source framebuffer surface into mipmap/texture */ struct pipe_surface *psRead = screen->get_tex_surface(screen, @@@ -1129,13 -1133,12 +1145,13 @@@ /* draw textured quad */ draw_textured_quad(ctx, dstx, dsty, ctx->Current.RasterPos[2], width, height, ctx->Pixel.ZoomX, ctx->Pixel.ZoomY, - pt, + sv, driver_vp, driver_fp, - color, GL_TRUE); + color, invertTex); pipe_texture_reference(&pt, NULL); + pipe_sampler_view_reference(&sv, NULL); }