From 5a6017d496ccce94d7e3cf9a6cfe1db886dcc767 Mon Sep 17 00:00:00 2001 From: Brian Date: Tue, 20 Nov 2007 08:36:06 -0700 Subject: add PIPE_FORMAT_Z24_S8 support to softpipe patsh --- src/mesa/pipe/softpipe/sp_quad_depth_test.c | 24 +++++++++++++++++ src/mesa/pipe/softpipe/sp_quad_stencil.c | 16 ++++++++++++ src/mesa/pipe/softpipe/sp_surface.c | 40 +++++++++++++++++++++++++++++ src/mesa/pipe/softpipe/sp_tile_cache.c | 13 ++++++++++ 4 files changed, 93 insertions(+) (limited to 'src/mesa/pipe/softpipe') diff --git a/src/mesa/pipe/softpipe/sp_quad_depth_test.c b/src/mesa/pipe/softpipe/sp_quad_depth_test.c index f7e93af784..3318189621 100644 --- a/src/mesa/pipe/softpipe/sp_quad_depth_test.c +++ b/src/mesa/pipe/softpipe/sp_quad_depth_test.c @@ -119,6 +119,21 @@ sp_depth_test_quad(struct quad_stage *qs, struct quad_header *quad) } } break; + case PIPE_FORMAT_Z24_S8: + { + float scale = (float) ((1 << 24) - 1); + + for (j = 0; j < QUAD_SIZE; j++) { + qzzzz[j] = (unsigned) (quad->outputs.depth[j] * scale); + } + + for (j = 0; j < QUAD_SIZE; j++) { + int x = quad->x0 % TILE_SIZE + (j & 1); + int y = quad->y0 % TILE_SIZE + (j >> 1); + bzzzz[j] = tile->data.depth32[y][x] >> 8; + } + } + break; default: assert(0); } @@ -210,6 +225,15 @@ sp_depth_test_quad(struct quad_stage *qs, struct quad_header *quad) tile->data.depth32[y][x] = s8z24; } break; + case PIPE_FORMAT_Z24_S8: + for (j = 0; j < QUAD_SIZE; j++) { + int x = quad->x0 % TILE_SIZE + (j & 1); + int y = quad->y0 % TILE_SIZE + (j >> 1); + uint z24s8 = tile->data.depth32[y][x]; + z24s8 = (z24s8 & 0xff) | (bzzzz[j] << 24); + tile->data.depth32[y][x] = z24s8; + } + break; default: assert(0); } diff --git a/src/mesa/pipe/softpipe/sp_quad_stencil.c b/src/mesa/pipe/softpipe/sp_quad_stencil.c index 831ad8bad0..0149b20f48 100644 --- a/src/mesa/pipe/softpipe/sp_quad_stencil.c +++ b/src/mesa/pipe/softpipe/sp_quad_stencil.c @@ -241,6 +241,13 @@ stencil_test_quad(struct quad_stage *qs, struct quad_header *quad) stencilVals[j] = tile->data.depth32[y][x] >> 24; } break; + case PIPE_FORMAT_Z24_S8: + for (j = 0; j < QUAD_SIZE; j++) { + int x = quad->x0 % TILE_SIZE + (j & 1); + int y = quad->y0 % TILE_SIZE + (j >> 1); + stencilVals[j] = tile->data.depth32[y][x] & 0xff; + } + break; case PIPE_FORMAT_U_S8: for (j = 0; j < QUAD_SIZE; j++) { int x = quad->x0 % TILE_SIZE + (j & 1); @@ -300,6 +307,15 @@ stencil_test_quad(struct quad_stage *qs, struct quad_header *quad) tile->data.depth32[y][x] = s8z24; } break; + case PIPE_FORMAT_Z24_S8: + for (j = 0; j < QUAD_SIZE; j++) { + int x = quad->x0 % TILE_SIZE + (j & 1); + int y = quad->y0 % TILE_SIZE + (j >> 1); + uint z24s8 = tile->data.depth32[y][x]; + z24s8 = (z24s8 & 0xffffff00) | stencilVals[j]; + tile->data.depth32[y][x] = z24s8; + } + break; case PIPE_FORMAT_U_S8: for (j = 0; j < QUAD_SIZE; j++) { int x = quad->x0 % TILE_SIZE + (j & 1); diff --git a/src/mesa/pipe/softpipe/sp_surface.c b/src/mesa/pipe/softpipe/sp_surface.c index ccaf38de3e..b7c9d4f004 100644 --- a/src/mesa/pipe/softpipe/sp_surface.c +++ b/src/mesa/pipe/softpipe/sp_surface.c @@ -461,6 +461,40 @@ s8z24_get_tile(struct pipe_surface *ps, } +/*** PIPE_FORMAT_Z24_S8 ***/ + +/** + * Return Z component as four float in [0,1]. Stencil part ignored. + */ +static void +z24s8_get_tile(struct pipe_surface *ps, + unsigned x, unsigned y, unsigned w, unsigned h, float *p) +{ + const uint *src + = ((const uint *) (ps->region->map + ps->offset)) + + y * ps->region->pitch + x; + const double scale = 1.0 / ((1 << 24) - 1); + unsigned i, j; + unsigned w0 = w; + + assert(ps->format == PIPE_FORMAT_Z24_S8); + + CLIP_TILE; + + for (i = 0; i < h; i++) { + float *pRow = p; + for (j = 0; j < w; j++) { + pRow[j * 4 + 0] = + pRow[j * 4 + 1] = + pRow[j * 4 + 2] = + pRow[j * 4 + 3] = (float) (scale * (src[j] >> 8)); + } + src += ps->region->pitch; + p += 4 * w0; + } +} + + /** * Called via pipe->get_tex_surface() * XXX is this in the right place? @@ -601,6 +635,9 @@ softpipe_get_tile_rgba(struct pipe_context *pipe, case PIPE_FORMAT_S8_Z24: s8z24_get_tile(ps, x, y, w, h, p); break; + case PIPE_FORMAT_Z24_S8: + z24s8_get_tile(ps, x, y, w, h, p); + break; default: assert(0); } @@ -645,6 +682,9 @@ softpipe_put_tile_rgba(struct pipe_context *pipe, case PIPE_FORMAT_S8_Z24: /*s8z24_put_tile(ps, x, y, w, h, p);*/ break; + case PIPE_FORMAT_Z24_S8: + /*z24s8_put_tile(ps, x, y, w, h, p);*/ + break; default: assert(0); } diff --git a/src/mesa/pipe/softpipe/sp_tile_cache.c b/src/mesa/pipe/softpipe/sp_tile_cache.c index 19c06323e1..ea0c8b8f91 100644 --- a/src/mesa/pipe/softpipe/sp_tile_cache.c +++ b/src/mesa/pipe/softpipe/sp_tile_cache.c @@ -166,6 +166,7 @@ sp_flush_tile_cache(struct softpipe_context *softpipe, return; is_depth_stencil = (ps->format == PIPE_FORMAT_S8_Z24 || + ps->format == PIPE_FORMAT_Z24_S8 || ps->format == PIPE_FORMAT_U_Z16 || ps->format == PIPE_FORMAT_U_Z32 || ps->format == PIPE_FORMAT_U_S8); @@ -203,6 +204,7 @@ sp_get_cached_tile(struct softpipe_context *softpipe, struct pipe_surface *ps = tc->surface; boolean is_depth_stencil = (ps->format == PIPE_FORMAT_S8_Z24 || + ps->format == PIPE_FORMAT_Z24_S8 || ps->format == PIPE_FORMAT_U_Z16 || ps->format == PIPE_FORMAT_U_Z32 || ps->format == PIPE_FORMAT_U_S8); @@ -268,6 +270,17 @@ sp_get_cached_tile(struct softpipe_context *softpipe, } } break; + case PIPE_FORMAT_Z24_S8: + { + uint clear_val = ((uint) (tc->clear_value[0] * 0xffffff)) << 8; + clear_val |= ((uint) tc->clear_value[1]) & 0xff; + for (i = 0; i < TILE_SIZE; i++) { + for (j = 0; j < TILE_SIZE; j++) { + tile->data.depth32[i][j] = clear_val; + } + } + } + break; case PIPE_FORMAT_U_S8: { ubyte clear_val = (uint) tc->clear_value[0]; -- cgit v1.2.3