summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJosé Fonseca <jfonseca@vmware.com>2010-02-10 11:01:26 +0000
committerJosé Fonseca <jfonseca@vmware.com>2010-02-10 11:01:26 +0000
commit5e6a9005100ec2636ce9734a5e4535216494cf60 (patch)
treee6be5e6ee6a48b8ef0122a4ac3ebe1697a5dc24e /src
parent7a593afa1741bfb0abd31422ecbd551628508711 (diff)
llvmpipe: Leave depth buffer in swizzled format.
This fixes several assertion failures due to only Z32 being supported.
Diffstat (limited to 'src')
-rw-r--r--src/gallium/drivers/llvmpipe/lp_rast.c157
-rw-r--r--src/gallium/drivers/llvmpipe/lp_rast.h4
-rw-r--r--src/gallium/drivers/llvmpipe/lp_rast_priv.h31
-rw-r--r--src/gallium/drivers/llvmpipe/lp_setup.c4
4 files changed, 78 insertions, 118 deletions
diff --git a/src/gallium/drivers/llvmpipe/lp_rast.c b/src/gallium/drivers/llvmpipe/lp_rast.c
index 5ae323fd96..6dbcb3c9b3 100644
--- a/src/gallium/drivers/llvmpipe/lp_rast.c
+++ b/src/gallium/drivers/llvmpipe/lp_rast.c
@@ -229,13 +229,58 @@ void lp_rast_clear_zstencil( struct lp_rasterizer *rast,
unsigned thread_index,
const union lp_rast_cmd_arg arg)
{
- unsigned i;
- uint32_t *depth_tile = rast->tasks[thread_index].tile.depth;
-
+ struct lp_rasterizer_task *task = &rast->tasks[thread_index];
+ const unsigned tile_x = task->x;
+ const unsigned tile_y = task->y;
+ const unsigned height = TILE_SIZE/TILE_VECTOR_HEIGHT;
+ const unsigned width = TILE_SIZE*TILE_VECTOR_HEIGHT;
+ unsigned block_size = util_format_get_blocksize(rast->zsbuf_transfer->texture->format);
+ uint8_t *dst;
+ unsigned dst_stride = rast->zsbuf_transfer->stride*TILE_VECTOR_HEIGHT;
+ unsigned i, j;
+
LP_DBG(DEBUG_RAST, "%s 0x%x\n", __FUNCTION__, arg.clear_zstencil);
- for (i = 0; i < TILE_SIZE * TILE_SIZE; i++)
- depth_tile[i] = arg.clear_zstencil;
+ assert(rast->zsbuf_map);
+ if (!rast->zsbuf_map)
+ return;
+
+ LP_DBG(DEBUG_RAST, "%s\n", __FUNCTION__);
+
+ /*
+ * Clear the aera of the swizzled depth/depth buffer matching this tile, in
+ * stripes of TILE_VECTOR_HEIGHT x TILE_SIZE at a time.
+ *
+ * The swizzled depth format is such that the depths for
+ * TILE_VECTOR_HEIGHT x TILE_VECTOR_WIDTH pixels have consecutive offsets.
+ */
+
+ dst = lp_rast_depth_pointer(rast, tile_x, tile_y);
+
+ switch (block_size) {
+ case 1:
+ memset(dst, (uint8_t) arg.clear_zstencil, height * width);
+ break;
+ case 2:
+ for (i = 0; i < height; i++) {
+ uint16_t *row = (uint16_t *)dst;
+ for (j = 0; j < width; j++)
+ *row++ = (uint16_t) arg.clear_zstencil;
+ dst += dst_stride;
+ }
+ break;
+ case 4:
+ for (i = 0; i < height; i++) {
+ uint32_t *row = (uint32_t *)dst;
+ for (j = 0; j < width; j++)
+ *row++ = arg.clear_zstencil;
+ dst += dst_stride;
+ }
+ break;
+ default:
+ assert(0);
+ break;
+ }
}
@@ -282,53 +327,6 @@ void lp_rast_load_color( struct lp_rasterizer *rast,
}
-static void
-lp_tile_read_z32(uint32_t *tile,
- const uint8_t *map,
- unsigned map_stride,
- unsigned x0, unsigned y0, unsigned w, unsigned h)
-{
- unsigned x, y;
- const uint8_t *map_row = map + y0*map_stride;
- for (y = 0; y < h; ++y) {
- const uint32_t *map_pixel = (uint32_t *)(map_row + x0*4);
- for (x = 0; x < w; ++x) {
- *tile++ = *map_pixel++;
- }
- map_row += map_stride;
- }
-}
-
-/**
- * Load tile z/stencil from the framebuffer surface.
- * This is a bin command called during bin processing.
- */
-void lp_rast_load_zstencil( struct lp_rasterizer *rast,
- unsigned thread_index,
- const union lp_rast_cmd_arg arg )
-{
- struct lp_rasterizer_task *task = &rast->tasks[thread_index];
- const unsigned x = task->x;
- const unsigned y = task->y;
- unsigned w = TILE_SIZE;
- unsigned h = TILE_SIZE;
-
- if (x + w > rast->state.fb.width)
- w -= x + w - rast->state.fb.width;
-
- if (y + h > rast->state.fb.height)
- h -= y + h - rast->state.fb.height;
-
- LP_DBG(DEBUG_RAST, "%s %d,%d %dx%d\n", __FUNCTION__, x, y, w, h);
-
- assert(rast->zsbuf_transfer->texture->format == PIPE_FORMAT_Z32_UNORM);
- lp_tile_read_z32(task->tile.depth,
- rast->zsbuf_map,
- rast->zsbuf_transfer->stride,
- x, y, w, h);
-}
-
-
void lp_rast_set_state( struct lp_rasterizer *rast,
unsigned thread_index,
const union lp_rast_cmd_arg arg )
@@ -377,7 +375,7 @@ void lp_rast_shade_tile( struct lp_rasterizer *rast,
color[i] = tile->color[i] + 4 * block_offset;
/* depth buffer */
- depth = tile->depth + block_offset;
+ depth = lp_rast_depth_pointer(rast, tile_x + x, tile_y + y);
/* run shader */
state->jit_function[0]( &state->jit_context,
@@ -435,12 +433,11 @@ void lp_rast_shade_quads( struct lp_rasterizer *rast,
color[i] = tile->color[i] + 4 * block_offset;
/* depth buffer */
- depth = tile->depth + block_offset;
+ depth = lp_rast_depth_pointer(rast, x, y);
#ifdef DEBUG
- assert(lp_check_alignment(tile->depth, 16));
assert(lp_check_alignment(tile->color[0], 16));
assert(lp_check_alignment(state->jit_context.blend_color, 16));
@@ -557,49 +554,6 @@ static void lp_rast_store_color( struct lp_rasterizer *rast,
}
-static void
-lp_tile_write_z32(const uint32_t *src, uint8_t *dst, unsigned dst_stride,
- unsigned x0, unsigned y0, unsigned w, unsigned h)
-{
- unsigned x, y;
- uint8_t *dst_row = dst + y0*dst_stride;
- for (y = 0; y < h; ++y) {
- uint32_t *dst_pixel = (uint32_t *)(dst_row + x0*4);
- for (x = 0; x < w; ++x) {
- *dst_pixel++ = *src++;
- }
- dst_row += dst_stride;
- }
-}
-
-/**
- * Write the rasterizer's z/stencil tile to the framebuffer.
- */
-static void lp_rast_store_zstencil( struct lp_rasterizer *rast,
- unsigned thread_index )
-{
- struct lp_rasterizer_task *task = &rast->tasks[thread_index];
- const unsigned x = task->x;
- const unsigned y = task->y;
- unsigned w = TILE_SIZE;
- unsigned h = TILE_SIZE;
-
- if (x + w > rast->state.fb.width)
- w -= x + w - rast->state.fb.width;
-
- if (y + h > rast->state.fb.height)
- h -= y + h - rast->state.fb.height;
-
- LP_DBG(DEBUG_RAST, "%s %d,%d %dx%d\n", __FUNCTION__, x, y, w, h);
-
- assert(rast->zsbuf_transfer->texture->format == PIPE_FORMAT_Z32_UNORM);
- lp_tile_write_z32(task->tile.depth,
- rast->zsbuf_map,
- rast->zsbuf_transfer->stride,
- x, y, w, h);
-}
-
-
/**
* Write the rasterizer's tiles to the framebuffer.
*/
@@ -611,9 +565,6 @@ lp_rast_end_tile( struct lp_rasterizer *rast,
if (rast->state.write_color)
lp_rast_store_color(rast, thread_index);
-
- if (rast->state.write_zstencil)
- lp_rast_store_zstencil(rast, thread_index);
}
@@ -694,7 +645,6 @@ static struct {
} cmd_names[] =
{
RAST(load_color),
- RAST(load_zstencil),
RAST(clear_color),
RAST(clear_zstencil),
RAST(triangle),
@@ -753,7 +703,6 @@ is_empty_bin( const struct cmd_bin *bin )
for (i = 0; i < head->count; i++)
if (head->cmd[i] != lp_rast_load_color &&
- head->cmd[i] != lp_rast_load_zstencil &&
head->cmd[i] != lp_rast_set_state) {
return FALSE;
}
@@ -993,7 +942,6 @@ lp_rast_create( struct pipe_screen *screen, struct lp_scene_queue *empty )
for (cbuf = 0; cbuf < PIPE_MAX_COLOR_BUFS; cbuf++ )
task->tile.color[cbuf] = align_malloc(TILE_SIZE * TILE_SIZE * 4, 16);
- task->tile.depth = align_malloc(TILE_SIZE * TILE_SIZE * 4, 16);
task->rast = rast;
task->thread_index = i;
}
@@ -1016,7 +964,6 @@ void lp_rast_destroy( struct lp_rasterizer *rast )
util_unreference_framebuffer_state(&rast->state.fb);
for (i = 0; i < Elements(rast->tasks); i++) {
- align_free(rast->tasks[i].tile.depth);
for (cbuf = 0; cbuf < PIPE_MAX_COLOR_BUFS; cbuf++ )
align_free(rast->tasks[i].tile.color[cbuf]);
}
diff --git a/src/gallium/drivers/llvmpipe/lp_rast.h b/src/gallium/drivers/llvmpipe/lp_rast.h
index 34da73eb50..875f18e0c0 100644
--- a/src/gallium/drivers/llvmpipe/lp_rast.h
+++ b/src/gallium/drivers/llvmpipe/lp_rast.h
@@ -213,10 +213,6 @@ void lp_rast_load_color( struct lp_rasterizer *,
unsigned thread_index,
const union lp_rast_cmd_arg );
-void lp_rast_load_zstencil( struct lp_rasterizer *,
- unsigned thread_index,
- const union lp_rast_cmd_arg );
-
void lp_rast_set_state( struct lp_rasterizer *,
unsigned thread_index,
const union lp_rast_cmd_arg );
diff --git a/src/gallium/drivers/llvmpipe/lp_rast_priv.h b/src/gallium/drivers/llvmpipe/lp_rast_priv.h
index 71e3a301e6..4760d337c6 100644
--- a/src/gallium/drivers/llvmpipe/lp_rast_priv.h
+++ b/src/gallium/drivers/llvmpipe/lp_rast_priv.h
@@ -29,6 +29,8 @@
#define LP_RAST_PRIV_H
#include "os/os_thread.h"
+#include "util/u_format.h"
+#include "gallivm/lp_bld_debug.h"
#include "lp_rast.h"
#include "lp_tile_soa.h"
@@ -48,8 +50,6 @@ struct lp_rasterizer;
struct lp_rast_tile
{
uint8_t *color[PIPE_MAX_COLOR_BUFS];
-
- uint32_t *depth;
};
@@ -91,7 +91,7 @@ struct lp_rasterizer
struct pipe_transfer *cbuf_transfer[PIPE_MAX_COLOR_BUFS];
struct pipe_transfer *zsbuf_transfer;
void *cbuf_map[PIPE_MAX_COLOR_BUFS];
- void *zsbuf_map;
+ uint8_t *zsbuf_map;
struct {
struct pipe_framebuffer_state fb;
@@ -129,6 +129,28 @@ void lp_rast_shade_quads( struct lp_rasterizer *rast,
/**
+ * Get the pointer to the depth buffer for a block.
+ * \param x, y location of 4x4 block in window coords
+ */
+static INLINE void *
+lp_rast_depth_pointer( struct lp_rasterizer *rast,
+ unsigned x, unsigned y )
+{
+ void * depth;
+ assert((x % TILE_VECTOR_WIDTH) == 0);
+ assert((y % TILE_VECTOR_HEIGHT) == 0);
+ depth = rast->zsbuf_map +
+ y*rast->zsbuf_transfer->stride +
+ TILE_VECTOR_HEIGHT*x*util_format_get_blocksize(rast->zsbuf_transfer->texture->format);
+#ifdef DEBUG
+ assert(lp_check_alignment(depth, 16));
+#endif
+ return depth;
+}
+
+
+
+/**
* Shade all pixels in a 4x4 block. The fragment code omits the
* triangle in/out tests.
* \param x, y location of 4x4 block in window coords
@@ -153,8 +175,7 @@ lp_rast_shade_quads_all( struct lp_rasterizer *rast,
for (i = 0; i < rast->state.fb.nr_cbufs; i++)
color[i] = tile->color[i] + 4 * block_offset;
- /* depth buffer */
- depth = tile->depth + block_offset;
+ depth = lp_rast_depth_pointer(rast, x, y);
/* run shader */
state->jit_function[0]( &state->jit_context,
diff --git a/src/gallium/drivers/llvmpipe/lp_setup.c b/src/gallium/drivers/llvmpipe/lp_setup.c
index 3186069899..6601fa61b9 100644
--- a/src/gallium/drivers/llvmpipe/lp_setup.c
+++ b/src/gallium/drivers/llvmpipe/lp_setup.c
@@ -172,10 +172,6 @@ begin_binning( struct setup_context *setup )
lp_scene_bin_everywhere( scene,
lp_rast_clear_zstencil,
setup->clear.zstencil );
- else
- lp_scene_bin_everywhere( scene,
- lp_rast_load_zstencil,
- lp_rast_arg_null() );
}
LP_DBG(DEBUG_SETUP, "%s done\n", __FUNCTION__);