Mesa (lp-surface-tiling): llvmpipe: do all render target surface mapping/ unmapping in the rast code
Brian Paul
brianp at kemper.freedesktop.org
Thu Mar 25 22:09:46 UTC 2010
Module: Mesa
Branch: lp-surface-tiling
Commit: df4329edbaf204ed501f1eac0698b8198178f9af
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=df4329edbaf204ed501f1eac0698b8198178f9af
Author: Brian Paul <brianp at vmware.com>
Date: Thu Mar 25 15:20:15 2010 -0600
llvmpipe: do all render target surface mapping/unmapping in the rast code
---
src/gallium/drivers/llvmpipe/lp_rast.c | 36 ++++++++++++++--
src/gallium/drivers/llvmpipe/lp_rast_priv.h | 36 +++++++++++++----
src/gallium/drivers/llvmpipe/lp_scene.c | 57 +--------------------------
src/gallium/drivers/llvmpipe/lp_scene.h | 20 ---------
4 files changed, 61 insertions(+), 88 deletions(-)
diff --git a/src/gallium/drivers/llvmpipe/lp_rast.c b/src/gallium/drivers/llvmpipe/lp_rast.c
index 0544eb8..b024e27 100644
--- a/src/gallium/drivers/llvmpipe/lp_rast.c
+++ b/src/gallium/drivers/llvmpipe/lp_rast.c
@@ -89,17 +89,38 @@ lp_rast_begin( struct lp_rasterizer *rast,
static void
lp_rast_end( struct lp_rasterizer *rast )
{
- int i;
+ struct lp_scene *scene = rast->curr_scene;
+ unsigned i;
- lp_scene_reset( rast->curr_scene );
+ /* Unmap color buffers */
+ for (i = 0; i < rast->state.nr_cbufs; i++) {
+ if (rast->cbuf[i].map) {
+ struct pipe_surface *cbuf = scene->fb.cbufs[i];
+ llvmpipe_texture_unmap(cbuf->texture,
+ cbuf->face,
+ cbuf->level,
+ cbuf->zslice);
+ rast->cbuf[i].map = NULL;
+ }
+ }
+
+ /* Unmap z/stencil buffer */
+ if (rast->zsbuf.map) {
+ struct pipe_surface *zsbuf = scene->fb.zsbuf;
+ llvmpipe_texture_unmap(zsbuf->texture,
+ zsbuf->face,
+ zsbuf->level,
+ zsbuf->zslice);
+ rast->zsbuf.map = NULL;
+ }
- for (i = 0; i < rast->state.nr_cbufs; i++)
- rast->cbuf[i].map = NULL;
+ lp_scene_reset( rast->curr_scene );
- rast->zsbuf.map = NULL;
rast->curr_scene = NULL;
}
+
+
/**
* Begining rasterization of a tile.
* \param x window X position of the tile, in pixels
@@ -774,6 +795,9 @@ lp_rast_create( void )
/* for synchronizing rasterization threads */
pipe_barrier_init( &rast->barrier, rast->num_threads );
+ /* for buffer mapping */
+ pipe_mutex_init(rast->map_mutex);
+
return rast;
}
@@ -807,6 +831,8 @@ void lp_rast_destroy( struct lp_rasterizer *rast )
/* for synchronizing rasterization threads */
pipe_barrier_destroy( &rast->barrier );
+ pipe_mutex_destroy(rast->map_mutex);
+
FREE(rast);
}
diff --git a/src/gallium/drivers/llvmpipe/lp_rast_priv.h b/src/gallium/drivers/llvmpipe/lp_rast_priv.h
index b6990b0..62bd3e5 100644
--- a/src/gallium/drivers/llvmpipe/lp_rast_priv.h
+++ b/src/gallium/drivers/llvmpipe/lp_rast_priv.h
@@ -117,6 +117,8 @@ struct lp_rasterizer
/** For synchronizing the rasterization threads */
pipe_barrier barrier;
+
+ pipe_mutex map_mutex;
};
@@ -128,6 +130,7 @@ void lp_rast_shade_quads( struct lp_rasterizer_task *task,
/**
* Get the pointer to a depth tile.
+ * We'll map the z/stencil buffer on demand here.
* \param x, y location of 4x4 block in window coords
*/
static INLINE void *
@@ -141,14 +144,22 @@ lp_rast_get_depth_tile_pointer( struct lp_rasterizer *rast,
assert((y % TILE_VECTOR_HEIGHT) == 0);
if (!rast->zsbuf.map) {
- struct lp_scene *scene = rast->curr_scene;
- rast->zsbuf.map = lp_scene_map_zstencil_buffer(scene, usage,
- LP_TEXTURE_TILED);
+ pipe_mutex_lock(rast->map_mutex);
if (!rast->zsbuf.map) {
- return NULL;
+ struct lp_scene *scene = rast->curr_scene;
+ struct pipe_surface *zsbuf = scene->fb.zsbuf;
+ rast->zsbuf.map = llvmpipe_texture_map(zsbuf->texture,
+ zsbuf->face,
+ zsbuf->level,
+ zsbuf->zslice,
+ usage,
+ LP_TEXTURE_TILED);
}
+ pipe_mutex_unlock(rast->map_mutex);
}
+ assert(rast->zsbuf.map);
+
depth = (rast->zsbuf.map +
rast->zsbuf.stride * y +
rast->zsbuf.blocksize * x * TILE_VECTOR_HEIGHT);
@@ -160,6 +171,7 @@ lp_rast_get_depth_tile_pointer( struct lp_rasterizer *rast,
/**
* Get the pointer to a color tile.
+ * We'll map the color buffer on demand here.
* \param x, y location of 4x4 block in window coords
*/
static INLINE void *
@@ -175,14 +187,22 @@ lp_rast_get_color_tile_pointer( struct lp_rasterizer *rast,
assert((y % TILE_VECTOR_HEIGHT) == 0);
if (!rast->cbuf[buf].map) {
- struct lp_scene *scene = rast->curr_scene;
- rast->cbuf[buf].map = lp_scene_map_color_buffer(scene, buf, usage,
- LP_TEXTURE_TILED);
+ pipe_mutex_lock(rast->map_mutex);
if (!rast->cbuf[buf].map) {
- return NULL;
+ struct lp_scene *scene = rast->curr_scene;
+ struct pipe_surface *cbuf = scene->fb.cbufs[buf];
+ rast->cbuf[buf].map = llvmpipe_texture_map(cbuf->texture,
+ cbuf->face,
+ cbuf->level,
+ cbuf->zslice,
+ usage,
+ LP_TEXTURE_TILED);
}
+ pipe_mutex_unlock(rast->map_mutex);
}
+ assert(rast->cbuf[buf].map);
+
tx = x / TILE_SIZE;
ty = y / TILE_SIZE;
tile_offset = ty * rast->cbuf[buf].tiles_per_row + tx;
diff --git a/src/gallium/drivers/llvmpipe/lp_scene.c b/src/gallium/drivers/llvmpipe/lp_scene.c
index b9f4955..a8854b8 100644
--- a/src/gallium/drivers/llvmpipe/lp_scene.c
+++ b/src/gallium/drivers/llvmpipe/lp_scene.c
@@ -60,7 +60,6 @@ lp_scene_create( struct pipe_context *pipe,
make_empty_list(&scene->textures);
pipe_mutex_init(scene->mutex);
- pipe_mutex_init(scene->map_mutex);
return scene;
}
@@ -89,7 +88,6 @@ lp_scene_destroy(struct lp_scene *scene)
scene->data.head = NULL;
pipe_mutex_destroy(scene->mutex);
- pipe_mutex_destroy(scene->map_mutex);
FREE(scene);
}
@@ -394,59 +392,6 @@ end:
/**
- * Map a color buffer for rendering.
- */
-void *
-lp_scene_map_color_buffer(struct lp_scene *scene, unsigned buf,
- enum lp_texture_usage usage,
- enum lp_texture_layout layout)
-{
- pipe_mutex_lock(scene->map_mutex);
-
- if (!scene->cbuf_map[buf]) {
- struct pipe_surface *cbuf = scene->fb.cbufs[buf];
-
- scene->cbuf_map[buf] = llvmpipe_texture_map(cbuf->texture,
- cbuf->face,
- cbuf->level,
- cbuf->zslice,
- usage,
- layout);
- }
-
- pipe_mutex_unlock(scene->map_mutex);
-
- return scene->cbuf_map[buf];
-}
-
-
-/**
- * Map the z/stencil buffer for rendering.
- */
-void *
-lp_scene_map_zstencil_buffer(struct lp_scene *scene,
- enum lp_texture_usage usage,
- enum lp_texture_layout layout)
-{
- pipe_mutex_lock(scene->map_mutex);
-
- if (!scene->zsbuf_map && scene->fb.zsbuf) {
- struct pipe_surface *zsbuf = scene->fb.zsbuf;
- scene->zsbuf_map = llvmpipe_texture_map(zsbuf->texture,
- zsbuf->face,
- zsbuf->level,
- zsbuf->zslice,
- usage,
- layout);
- }
-
- pipe_mutex_unlock(scene->map_mutex);
-
- return scene->zsbuf_map;
-}
-
-
-/**
* Prepare this scene for the rasterizer.
* Map the framebuffer surfaces. Initialize the 'rast' state.
*/
@@ -472,6 +417,7 @@ lp_scene_map_buffers( struct lp_scene *scene )
static void
lp_scene_unmap_buffers( struct lp_scene *scene )
{
+#if 0
unsigned i;
for (i = 0; i < scene->fb.nr_cbufs; i++) {
@@ -493,6 +439,7 @@ lp_scene_unmap_buffers( struct lp_scene *scene )
zsbuf->zslice);
scene->zsbuf_map = NULL;
}
+#endif
util_unreference_framebuffer_state( &scene->fb );
}
diff --git a/src/gallium/drivers/llvmpipe/lp_scene.h b/src/gallium/drivers/llvmpipe/lp_scene.h
index cdd0fdc..f67b4c4 100644
--- a/src/gallium/drivers/llvmpipe/lp_scene.h
+++ b/src/gallium/drivers/llvmpipe/lp_scene.h
@@ -115,11 +115,6 @@ struct texture_ref {
struct lp_scene {
struct pipe_context *pipe;
- /* Scene's buffers are mapped at the time the scene is enqueued:
- */
- void *cbuf_map[PIPE_MAX_COLOR_BUFS];
- uint8_t *zsbuf_map;
-
/** the framebuffer to render the scene into */
struct pipe_framebuffer_state fb;
@@ -137,9 +132,6 @@ struct lp_scene {
int curr_x, curr_y; /**< for iterating over bins */
pipe_mutex mutex;
- /** Used when mapping/unmapping color/z/stencil buffers */
- pipe_mutex map_mutex;
-
/* Where to place this scene once it has been rasterized:
*/
struct lp_scene_queue *empty_queue;
@@ -308,18 +300,6 @@ struct cmd_bin *
lp_scene_bin_iter_next( struct lp_scene *scene, int *bin_x, int *bin_y );
-void *
-lp_scene_map_color_buffer(struct lp_scene *scene, unsigned buf,
- enum lp_texture_usage usage,
- enum lp_texture_layout layout);
-
-
-void *
-lp_scene_map_zstencil_buffer(struct lp_scene *scene,
- enum lp_texture_usage usage,
- enum lp_texture_layout layout);
-
-
void
lp_scene_rasterize( struct lp_scene *scene,
struct lp_rasterizer *rast,
More information about the mesa-commit
mailing list