From e4f6f0ec02133e9297c3f2db787dee14bf0ae6e1 Mon Sep 17 00:00:00 2001 From: Brian Date: Fri, 26 Oct 2007 10:45:42 -0600 Subject: surface_alloc() is now a winsys function. This allows surfaces to be allocated without a rendering context. A few loose ends to resolve, but in working condition. --- src/mesa/pipe/failover/fo_context.c | 2 + src/mesa/pipe/i915simple/i915_surface.c | 189 +++++++++++++++++++++++++------- src/mesa/pipe/p_context.h | 9 +- src/mesa/pipe/p_winsys.h | 4 + src/mesa/pipe/softpipe/sp_surface.c | 107 ++++++++++++++---- src/mesa/pipe/softpipe/sp_surface.h | 15 ++- 6 files changed, 257 insertions(+), 69 deletions(-) (limited to 'src/mesa/pipe') diff --git a/src/mesa/pipe/failover/fo_context.c b/src/mesa/pipe/failover/fo_context.c index a3a0296598..7e02b751bb 100644 --- a/src/mesa/pipe/failover/fo_context.c +++ b/src/mesa/pipe/failover/fo_context.c @@ -134,7 +134,9 @@ struct pipe_context *failover_create( struct pipe_context *hw, failover_init_state_functions( failover ); +#if 0 failover->pipe.surface_alloc = hw->surface_alloc; +#endif failover->pipe.get_tex_surface = hw->get_tex_surface; failover->pipe.region_map = hw->region_map; diff --git a/src/mesa/pipe/i915simple/i915_surface.c b/src/mesa/pipe/i915simple/i915_surface.c index a07a21c13b..b4b5bd1ce5 100644 --- a/src/mesa/pipe/i915simple/i915_surface.c +++ b/src/mesa/pipe/i915simple/i915_surface.c @@ -29,13 +29,20 @@ #include "i915_state.h" #include "pipe/p_defines.h" #include "pipe/p_util.h" +#include "pipe/p_winsys.h" -struct i915_surface -{ - struct pipe_surface surface; - /* anything else? */ -}; +#define CLIP_TILE \ + do { \ + if (x >= ps->width) \ + return; \ + if (y >= ps->height) \ + return; \ + if (x + w > ps->width) \ + w = ps->width - x; \ + if (y + h > ps->height) \ + h = ps->height -y; \ + } while(0) /** @@ -53,30 +60,44 @@ i915_get_tile_rgba(struct pipe_context *pipe, unsigned i, j; unsigned w0 = w; - assert(ps->format == PIPE_FORMAT_U_A8_R8_G8_B8); - -#if 0 - assert(x + w <= ps->width); - assert(y + h <= ps->height); -#else - /* temp clipping hack */ - if (x + w > ps->width) - w = ps->width - x; - if (y + h > ps->height) - h = ps->height -y; -#endif - for (i = 0; i < h; i++) { - float *pRow = p; - for (j = 0; j < w; j++) { - const unsigned pixel = src[j]; - pRow[0] = UBYTE_TO_FLOAT((pixel >> 16) & 0xff); - pRow[1] = UBYTE_TO_FLOAT((pixel >> 8) & 0xff); - pRow[2] = UBYTE_TO_FLOAT((pixel >> 0) & 0xff); - pRow[3] = UBYTE_TO_FLOAT((pixel >> 24) & 0xff); - pRow += 4; + CLIP_TILE; + + switch (ps->format) { + case PIPE_FORMAT_U_A8_R8_G8_B8: + for (i = 0; i < h; i++) { + float *pRow = p; + for (j = 0; j < w; j++) { + const unsigned pixel = src[j]; + pRow[0] = UBYTE_TO_FLOAT((pixel >> 16) & 0xff); + pRow[1] = UBYTE_TO_FLOAT((pixel >> 8) & 0xff); + pRow[2] = UBYTE_TO_FLOAT((pixel >> 0) & 0xff); + pRow[3] = UBYTE_TO_FLOAT((pixel >> 24) & 0xff); + pRow += 4; + } + src += ps->region->pitch; + p += w0 * 4; + } + break; + case PIPE_FORMAT_S8_Z24: + { + const float scale = 1.0 / (float) 0xffffff; + for (i = 0; i < h; i++) { + float *pRow = p; + for (j = 0; j < w; j++) { + const unsigned pixel = src[j]; + pRow[0] = + pRow[1] = + pRow[2] = + pRow[3] = (pixel & 0xffffff) * scale; + pRow += 4; + } + src += ps->region->pitch; + p += w0 * 4; + } } - src += ps->region->pitch; - p += w0 * 4; + break; + default: + assert(0); } } @@ -86,34 +107,122 @@ i915_put_tile_rgba(struct pipe_context *pipe, struct pipe_surface *ps, uint x, uint y, uint w, uint h, const float *p) { - /* any need to put tiles into i915 surfaces? */ + /* TODO */ assert(0); } +/* + * XXX note: same as code in sp_surface.c + */ +static void +i915_get_tile(struct pipe_context *pipe, + struct pipe_surface *ps, + uint x, uint y, uint w, uint h, + void *p, int dst_stride) +{ + const uint cpp = ps->region->cpp; + const uint w0 = w; + const ubyte *pSrc; + ubyte *pDest; + uint i; -static struct pipe_surface * -i915_surface_alloc(struct pipe_context *pipe, unsigned format) + assert(ps->region->map); + + CLIP_TILE; + + if (dst_stride == 0) { + dst_stride = w0 * cpp; + } + + pSrc = ps->region->map + ps->offset + (y * ps->region->pitch + x) * cpp; + pDest = (ubyte *) p; + + for (i = 0; i < h; i++) { + memcpy(pDest, pSrc, w0 * cpp); + pDest += dst_stride; + pSrc += ps->region->pitch * cpp; + } +} + + +/* + * XXX note: same as code in sp_surface.c + */ +static void +i915_put_tile(struct pipe_context *pipe, + struct pipe_surface *ps, + uint x, uint y, uint w, uint h, + const void *p, int src_stride) { - struct i915_surface *surf = CALLOC_STRUCT(i915_surface); + const uint cpp = ps->region->cpp; + const uint w0 = w; + const ubyte *pSrc; + ubyte *pDest; + uint i; + + assert(ps->region->map); + + CLIP_TILE; + + if (src_stride == 0) { + src_stride = w0 * cpp; + } + + pSrc = (const ubyte *) p; + pDest = ps->region->map + ps->offset + (y * ps->region->pitch + x) * cpp; + + for (i = 0; i < h; i++) { + memcpy(pDest, pSrc, w0 * cpp); + pDest += ps->region->pitch * cpp; + pSrc += src_stride; + } +} - if (!surf) - return NULL; - surf->surface.format = format; - surf->surface.refcount = 1; +/* + * XXX note: same as code in sp_surface.c + */ +static struct pipe_surface * +i915_get_tex_surface(struct pipe_context *pipe, + struct pipe_mipmap_tree *mt, + unsigned face, unsigned level, unsigned zslice) +{ + struct pipe_surface *ps; + unsigned offset; /* in bytes */ - // surf->surface.get_tile = i915_get_tile; - // surf->surface.put_tile = i915_put_tile; + offset = mt->level[level].level_offset; - return &surf->surface; + if (mt->target == PIPE_TEXTURE_CUBE) { + offset += mt->level[level].image_offset[face] * mt->cpp; + } + else if (mt->target == PIPE_TEXTURE_3D) { + offset += mt->level[level].image_offset[zslice] * mt->cpp; + } + else { + assert(face == 0); + assert(zslice == 0); + } + + ps = pipe->winsys->surface_alloc(pipe->winsys, mt->format); + if (ps) { + assert(ps->format); + assert(ps->refcount); + pipe_region_reference(&ps->region, mt->region); + ps->width = mt->level[level].width; + ps->height = mt->level[level].height; + ps->offset = offset; + } + return ps; } void i915_init_surface_functions(struct i915_context *i915) { - i915->pipe.surface_alloc = i915_surface_alloc; + i915->pipe.get_tex_surface = i915_get_tex_surface; + i915->pipe.get_tile = i915_get_tile; + i915->pipe.put_tile = i915_put_tile; i915->pipe.get_tile_rgba = i915_get_tile_rgba; i915->pipe.put_tile_rgba = i915_put_tile_rgba; } diff --git a/src/mesa/pipe/p_context.h b/src/mesa/pipe/p_context.h index b9de3667e5..3a041f158b 100644 --- a/src/mesa/pipe/p_context.h +++ b/src/mesa/pipe/p_context.h @@ -176,13 +176,7 @@ struct pipe_context { unsigned index, const struct pipe_feedback_buffer *); - /* - * Surface functions - * This might go away... - */ - struct pipe_surface *(*surface_alloc)(struct pipe_context *pipe, - unsigned format); - + /** Get a surface which is a "view" into a texture */ struct pipe_surface *(*get_tex_surface)(struct pipe_context *pipe, struct pipe_mipmap_tree *texture, unsigned face, unsigned level, @@ -198,7 +192,6 @@ struct pipe_context { struct pipe_surface *ps, uint x, uint y, uint w, uint h, const void *p, int src_stride); - /* XXX temporary here, move these to softpipe */ void (*get_tile_rgba)(struct pipe_context *pipe, struct pipe_surface *ps, uint x, uint y, uint w, uint h, float *p); diff --git a/src/mesa/pipe/p_winsys.h b/src/mesa/pipe/p_winsys.h index 3b04c44733..10a2caf1a2 100644 --- a/src/mesa/pipe/p_winsys.h +++ b/src/mesa/pipe/p_winsys.h @@ -77,6 +77,10 @@ struct pipe_winsys void (*region_release)(struct pipe_winsys *ws, struct pipe_region **r); + /** allocate a new surface (no context dependency) */ + struct pipe_surface *(*surface_alloc)(struct pipe_winsys *ws, + unsigned format); + /** * The buffer manager is modeled after the dri_bufmgr interface, which * in turn is modeled after the ARB_vertex_buffer_object extension, diff --git a/src/mesa/pipe/softpipe/sp_surface.c b/src/mesa/pipe/softpipe/sp_surface.c index 4accafa384..d1aa2aba97 100644 --- a/src/mesa/pipe/softpipe/sp_surface.c +++ b/src/mesa/pipe/softpipe/sp_surface.c @@ -27,6 +27,7 @@ #include "pipe/p_defines.h" #include "pipe/p_util.h" +#include "pipe/p_winsys.h" #include "sp_context.h" #include "sp_state.h" #include "sp_surface.h" @@ -361,7 +362,7 @@ i8_get_tile(struct pipe_surface *ps, static void a8_l8_get_tile(struct pipe_surface *ps, - unsigned x, unsigned y, unsigned w, unsigned h, float *p) + unsigned x, unsigned y, unsigned w, unsigned h, float *p) { const ushort *src = ((const ushort *) (ps->region->map + ps->offset)) @@ -466,7 +467,7 @@ void softpipe_init_surface_funcs(struct softpipe_surface *sps) { assert(sps->surface.format); - +#if 0 switch (sps->surface.format) { case PIPE_FORMAT_U_A8_R8_G8_B8: sps->get_tile = a8r8g8b8_get_tile; @@ -507,6 +508,7 @@ softpipe_init_surface_funcs(struct softpipe_surface *sps) default: assert(0); } +#endif } @@ -555,7 +557,7 @@ softpipe_get_tex_surface(struct pipe_context *pipe, assert(zslice == 0); } - ps = pipe->surface_alloc(pipe, mt->format); + ps = pipe->winsys->surface_alloc(pipe->winsys, mt->format); if (ps) { assert(ps->format); assert(ps->refcount); @@ -637,26 +639,90 @@ softpipe_put_tile(struct pipe_context *pipe, /* XXX TEMPORARY */ -static void -get_tile_rgba_generic(struct pipe_context *pipe, - struct pipe_surface *ps, - uint x, uint y, uint w, uint h, - float *p) +void +softpipe_get_tile_rgba(struct pipe_context *pipe, + struct pipe_surface *ps, + uint x, uint y, uint w, uint h, + float *p) { - struct softpipe_surface *sps = softpipe_surface(ps); - sps->get_tile(ps, x, y, w, h, p); + switch (ps->format) { + case PIPE_FORMAT_U_A8_R8_G8_B8: + a8r8g8b8_get_tile(ps, x, y, w, h, p); + break; + case PIPE_FORMAT_U_A1_R5_G5_B5: + a1r5g5b5_get_tile(ps, x, y, w, h, p); + break; + case PIPE_FORMAT_U_L8: + l8_get_tile(ps, x, y, w, h, p); + break; + case PIPE_FORMAT_U_A8: + a8_get_tile(ps, x, y, w, h, p); + break; + case PIPE_FORMAT_U_I8: + i8_get_tile(ps, x, y, w, h, p); + break; + case PIPE_FORMAT_U_A8_L8: + a8_l8_get_tile(ps, x, y, w, h, p); + break; + case PIPE_FORMAT_S_R16_G16_B16_A16: + r16g16b16a16_get_tile(ps, x, y, w, h, p); + break; + case PIPE_FORMAT_U_Z16: + z16_get_tile(ps, x, y, w, h, p); + break; + case PIPE_FORMAT_U_Z32: + z32_get_tile(ps, x, y, w, h, p); + break; + case PIPE_FORMAT_S8_Z24: + s8z24_get_tile(ps, x, y, w, h, p); + break; + default: + assert(0); + } } /* XXX TEMPORARY */ -static void -put_tile_rgba_generic(struct pipe_context *pipe, - struct pipe_surface *ps, - uint x, uint y, uint w, uint h, - const float *p) +void +softpipe_put_tile_rgba(struct pipe_context *pipe, + struct pipe_surface *ps, + uint x, uint y, uint w, uint h, + const float *p) { - struct softpipe_surface *sps = softpipe_surface(ps); - sps->put_tile(ps, x, y, w, h, p); + switch (ps->format) { + case PIPE_FORMAT_U_A8_R8_G8_B8: + a8r8g8b8_put_tile(ps, x, y, w, h, p); + break; + case PIPE_FORMAT_U_A1_R5_G5_B5: + /*a1r5g5b5_put_tile(ps, x, y, w, h, p);*/ + break; + case PIPE_FORMAT_U_L8: + /*l8_put_tile(ps, x, y, w, h, p);*/ + break; + case PIPE_FORMAT_U_A8: + /*a8_put_tile(ps, x, y, w, h, p);*/ + break; + case PIPE_FORMAT_U_I8: + /*i8_put_tile(ps, x, y, w, h, p);*/ + break; + case PIPE_FORMAT_U_A8_L8: + /*a8_l8_put_tile(ps, x, y, w, h, p);*/ + break; + case PIPE_FORMAT_S_R16_G16_B16_A16: + r16g16b16a16_put_tile(ps, x, y, w, h, p); + break; + case PIPE_FORMAT_U_Z16: + /*z16_put_tile(ps, x, y, w, h, p);*/ + break; + case PIPE_FORMAT_U_Z32: + /*z32_put_tile(ps, x, y, w, h, p);*/ + break; + case PIPE_FORMAT_S8_Z24: + /*s8z24_put_tile(ps, x, y, w, h, p);*/ + break; + default: + assert(0); + } } @@ -664,11 +730,12 @@ put_tile_rgba_generic(struct pipe_context *pipe, void sp_init_surface_functions(struct softpipe_context *sp) { +#if 0 sp->pipe.surface_alloc = softpipe_surface_alloc; - +#endif sp->pipe.get_tile = softpipe_get_tile; sp->pipe.put_tile = softpipe_put_tile; - sp->pipe.get_tile_rgba = get_tile_rgba_generic; - sp->pipe.put_tile_rgba = put_tile_rgba_generic; + sp->pipe.get_tile_rgba = softpipe_get_tile_rgba; + sp->pipe.put_tile_rgba = softpipe_put_tile_rgba; } diff --git a/src/mesa/pipe/softpipe/sp_surface.h b/src/mesa/pipe/softpipe/sp_surface.h index af6533d4f0..359a438c86 100644 --- a/src/mesa/pipe/softpipe/sp_surface.h +++ b/src/mesa/pipe/softpipe/sp_surface.h @@ -46,20 +46,33 @@ struct softpipe_tile_cache; struct softpipe_surface { struct pipe_surface surface; +#if 0 /* XXX these are temporary here */ void (*get_tile)(struct pipe_surface *ps, uint x, uint y, uint w, uint h, float *p); void (*put_tile)(struct pipe_surface *ps, uint x, uint y, uint w, uint h, const float *p); +#endif }; - extern struct pipe_surface * softpipe_get_tex_surface(struct pipe_context *pipe, struct pipe_mipmap_tree *mt, unsigned face, unsigned level, unsigned zslice); +extern void +softpipe_get_tile_rgba(struct pipe_context *pipe, + struct pipe_surface *ps, + uint x, uint y, uint w, uint h, + float *p); + +extern void +softpipe_put_tile_rgba(struct pipe_context *pipe, + struct pipe_surface *ps, + uint x, uint y, uint w, uint h, + const float *p); + extern void softpipe_init_surface_funcs(struct softpipe_surface *sps); -- cgit v1.2.3