summaryrefslogtreecommitdiff
path: root/src/mesa/pipe/softpipe
diff options
context:
space:
mode:
Diffstat (limited to 'src/mesa/pipe/softpipe')
-rw-r--r--src/mesa/pipe/softpipe/sp_context.c26
-rw-r--r--src/mesa/pipe/softpipe/sp_state_surface.c42
-rw-r--r--src/mesa/pipe/softpipe/sp_surface.c16
-rw-r--r--src/mesa/pipe/softpipe/sp_tile_cache.c45
-rw-r--r--src/mesa/pipe/softpipe/sp_tile_cache.h6
5 files changed, 64 insertions, 71 deletions
diff --git a/src/mesa/pipe/softpipe/sp_context.c b/src/mesa/pipe/softpipe/sp_context.c
index 4f22539629..68c18e2d05 100644
--- a/src/mesa/pipe/softpipe/sp_context.c
+++ b/src/mesa/pipe/softpipe/sp_context.c
@@ -75,22 +75,15 @@ softpipe_is_format_supported( struct pipe_context *pipe,
void
softpipe_map_surfaces(struct softpipe_context *sp)
{
- struct pipe_surface *ps;
unsigned i;
for (i = 0; i < sp->framebuffer.num_cbufs; i++) {
- ps = sp->framebuffer.cbufs[i];
- if (ps->buffer && !ps->map)
- pipe_surface_map(ps);
+ sp_tile_cache_map_surfaces(sp->cbuf_cache[i]);
}
- ps = sp->framebuffer.zbuf;
- if (ps && ps->buffer && !ps->map)
- pipe_surface_map(ps);
+ sp_tile_cache_map_surfaces(sp->zbuf_cache);
- ps = sp->framebuffer.sbuf;
- if (ps && ps->buffer && !ps->map)
- pipe_surface_map(ps);
+ sp_tile_cache_map_surfaces(sp->sbuf_cache);
}
@@ -100,7 +93,6 @@ softpipe_map_surfaces(struct softpipe_context *sp)
void
softpipe_unmap_surfaces(struct softpipe_context *sp)
{
- struct pipe_surface *ps;
uint i;
for (i = 0; i < sp->framebuffer.num_cbufs; i++)
@@ -109,18 +101,12 @@ softpipe_unmap_surfaces(struct softpipe_context *sp)
sp_flush_tile_cache(sp, sp->sbuf_cache);
for (i = 0; i < sp->framebuffer.num_cbufs; i++) {
- ps = sp->framebuffer.cbufs[i];
- if (ps->map)
- pipe_surface_unmap(ps);
+ sp_tile_cache_unmap_surfaces(sp->cbuf_cache[i]);
}
- ps = sp->framebuffer.zbuf;
- if (ps && ps->map)
- pipe_surface_unmap(ps);
+ sp_tile_cache_unmap_surfaces(sp->zbuf_cache);
- ps = sp->framebuffer.sbuf;
- if (ps && ps->map)
- pipe_surface_unmap(ps);
+ sp_tile_cache_unmap_surfaces(sp->sbuf_cache);
}
diff --git a/src/mesa/pipe/softpipe/sp_state_surface.c b/src/mesa/pipe/softpipe/sp_state_surface.c
index ee72aaf4c5..4a9a28cc4d 100644
--- a/src/mesa/pipe/softpipe/sp_state_surface.c
+++ b/src/mesa/pipe/softpipe/sp_state_surface.c
@@ -38,7 +38,7 @@
/**
* XXX this might get moved someday
* Set the framebuffer surface info: color buffers, zbuffer, stencil buffer.
- * Here, we map the surfaces and update the tile cache to point to the new
+ * Here, we flush the old surfaces and update the tile cache to point to the new
* surfaces.
*/
void
@@ -46,7 +46,6 @@ softpipe_set_framebuffer_state(struct pipe_context *pipe,
const struct pipe_framebuffer_state *fb)
{
struct softpipe_context *sp = softpipe_context(pipe);
- struct pipe_surface *ps;
uint i;
for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) {
@@ -54,19 +53,12 @@ softpipe_set_framebuffer_state(struct pipe_context *pipe,
if (sp->framebuffer.cbufs[i] != fb->cbufs[i]) {
/* flush old */
sp_flush_tile_cache(sp, sp->cbuf_cache[i]);
- /* unmap old */
- ps = sp->framebuffer.cbufs[i];
- if (ps && ps->map)
- pipe_surface_unmap(ps);
- /* map new */
- ps = fb->cbufs[i];
- if (ps)
- pipe_surface_map(ps);
+
/* assign new */
sp->framebuffer.cbufs[i] = fb->cbufs[i];
/* update cache */
- sp_tile_cache_set_surface(sp->cbuf_cache[i], ps);
+ sp_tile_cache_set_surface(sp->cbuf_cache[i], fb->cbufs[i]);
}
}
@@ -76,23 +68,12 @@ softpipe_set_framebuffer_state(struct pipe_context *pipe,
if (sp->framebuffer.zbuf != fb->zbuf) {
/* flush old */
sp_flush_tile_cache(sp, sp->zbuf_cache);
- /* unmap old */
- ps = sp->framebuffer.zbuf;
- if (ps && ps->map)
- pipe_surface_unmap(ps);
- if (sp->framebuffer.sbuf == sp->framebuffer.zbuf) {
- /* combined z/stencil */
- sp->framebuffer.sbuf = NULL;
- }
- /* map new */
- ps = fb->zbuf;
- if (ps)
- pipe_surface_map(ps);
+
/* assign new */
sp->framebuffer.zbuf = fb->zbuf;
/* update cache */
- sp_tile_cache_set_surface(sp->zbuf_cache, ps);
+ sp_tile_cache_set_surface(sp->zbuf_cache, fb->zbuf);
}
/* XXX combined depth/stencil here */
@@ -101,14 +82,7 @@ softpipe_set_framebuffer_state(struct pipe_context *pipe,
if (sp->framebuffer.sbuf != fb->sbuf) {
/* flush old */
sp_flush_tile_cache(sp, sp->sbuf_cache_sep);
- /* unmap old */
- ps = sp->framebuffer.sbuf;
- if (ps && ps->map)
- pipe_surface_unmap(ps);
- /* map new */
- ps = fb->sbuf;
- if (ps && fb->sbuf != fb->zbuf)
- pipe_surface_map(ps);
+
/* assign new */
sp->framebuffer.sbuf = fb->sbuf;
@@ -116,12 +90,12 @@ softpipe_set_framebuffer_state(struct pipe_context *pipe,
if (fb->sbuf != fb->zbuf) {
/* separate stencil buf */
sp->sbuf_cache = sp->sbuf_cache_sep;
- sp_tile_cache_set_surface(sp->sbuf_cache, ps);
+ sp_tile_cache_set_surface(sp->sbuf_cache, fb->sbuf);
}
else {
/* combined depth/stencil */
sp->sbuf_cache = sp->zbuf_cache;
- sp_tile_cache_set_surface(sp->sbuf_cache, ps);
+ sp_tile_cache_set_surface(sp->sbuf_cache, fb->sbuf);
}
}
diff --git a/src/mesa/pipe/softpipe/sp_surface.c b/src/mesa/pipe/softpipe/sp_surface.c
index ece30e36ec..b44ba3e957 100644
--- a/src/mesa/pipe/softpipe/sp_surface.c
+++ b/src/mesa/pipe/softpipe/sp_surface.c
@@ -158,10 +158,10 @@ sp_surface_copy(struct pipe_context *pipe,
}
-static ubyte *
-get_pointer(struct pipe_surface *dst, unsigned x, unsigned y)
+static void *
+get_pointer(struct pipe_surface *dst, void *dst_map, unsigned x, unsigned y)
{
- return dst->map + (y * dst->pitch + x) * dst->cpp;
+ return (char *)dst_map + (y * dst->pitch + x) * dst->cpp;
}
@@ -179,16 +179,16 @@ sp_surface_fill(struct pipe_context *pipe,
unsigned width, unsigned height, unsigned value)
{
unsigned i, j;
+ void *dst_map = pipe_surface_map(dst);
assert(dst->pitch > 0);
assert(width <= dst->pitch);
- (void)pipe_surface_map(dst);
switch (dst->cpp) {
case 1:
{
- ubyte *row = get_pointer(dst, dstx, dsty);
+ ubyte *row = get_pointer(dst, dst_map, dstx, dsty);
for (i = 0; i < height; i++) {
memset(row, value, width);
row += dst->pitch;
@@ -197,7 +197,7 @@ sp_surface_fill(struct pipe_context *pipe,
break;
case 2:
{
- ushort *row = (ushort *) get_pointer(dst, dstx, dsty);
+ ushort *row = get_pointer(dst, dst_map, dstx, dsty);
for (i = 0; i < height; i++) {
for (j = 0; j < width; j++)
row[j] = (ushort) value;
@@ -207,7 +207,7 @@ sp_surface_fill(struct pipe_context *pipe,
break;
case 4:
{
- unsigned *row = (unsigned *) get_pointer(dst, dstx, dsty);
+ unsigned *row = get_pointer(dst, dst_map, dstx, dsty);
for (i = 0; i < height; i++) {
for (j = 0; j < width; j++)
row[j] = value;
@@ -218,7 +218,7 @@ sp_surface_fill(struct pipe_context *pipe,
case 8:
{
/* expand the 4-byte clear value to an 8-byte value */
- ushort *row = (ushort *) get_pointer(dst, dstx, dsty);
+ ushort *row = (ushort *) get_pointer(dst, dst_map, dstx, dsty);
ushort val0 = UBYTE_TO_USHORT((value >> 0) & 0xff);
ushort val1 = UBYTE_TO_USHORT((value >> 8) & 0xff);
ushort val2 = UBYTE_TO_USHORT((value >> 16) & 0xff);
diff --git a/src/mesa/pipe/softpipe/sp_tile_cache.c b/src/mesa/pipe/softpipe/sp_tile_cache.c
index 1dbcc5aadd..d6f60807e6 100644
--- a/src/mesa/pipe/softpipe/sp_tile_cache.c
+++ b/src/mesa/pipe/softpipe/sp_tile_cache.c
@@ -49,6 +49,7 @@
struct softpipe_tile_cache
{
struct pipe_surface *surface; /**< the surface we're caching */
+ void *surface_map;
struct pipe_texture *texture; /**< if caching a texture */
struct softpipe_cached_tile entries[NUM_ENTRIES];
uint clear_flags[(MAX_WIDTH / TILE_SIZE) * (MAX_HEIGHT / TILE_SIZE) / 32];
@@ -57,6 +58,7 @@ struct softpipe_tile_cache
boolean depth_stencil; /** Is the surface a depth/stencil format? */
struct pipe_surface *tex_surf;
+ void *tex_surf_map;
int tex_face, tex_level, tex_z;
struct softpipe_cached_tile tile; /**< scratch tile for clears */
@@ -150,7 +152,7 @@ sp_tile_cache_set_surface(struct softpipe_tile_cache *tc,
{
assert(!tc->texture);
- if (tc->surface && tc->surface->map) {
+ if (tc->surface_map) {
/*assert(tc->surface != ps);*/
pipe_surface_unmap(tc->surface);
}
@@ -158,8 +160,8 @@ sp_tile_cache_set_surface(struct softpipe_tile_cache *tc,
pipe_surface_reference(&tc->surface, ps);
if (ps) {
- if (!ps->map)
- pipe_surface_map(ps);
+ if (tc->surface_map)
+ tc->surface_map = pipe_surface_map(ps);
tc->depth_stencil = (ps->format == PIPE_FORMAT_S8Z24_UNORM ||
ps->format == PIPE_FORMAT_Z16_UNORM ||
@@ -179,6 +181,32 @@ sp_tile_cache_get_surface(struct softpipe_tile_cache *tc)
}
+void
+sp_tile_cache_map_surfaces(struct softpipe_tile_cache *tc)
+{
+ if (tc->surface && !tc->surface_map)
+ tc->surface_map = pipe_surface_map(tc->surface);
+
+ if (tc->tex_surf && !tc->tex_surf_map)
+ tc->tex_surf_map = pipe_surface_map(tc->tex_surf);
+}
+
+
+void
+sp_tile_cache_unmap_surfaces(struct softpipe_tile_cache *tc)
+{
+ if (tc->surface_map) {
+ pipe_surface_unmap(tc->surface);
+ tc->surface_map = NULL;
+ }
+
+ if (tc->tex_surf_map) {
+ pipe_surface_unmap(tc->tex_surf);
+ tc->tex_surf_map = NULL;
+ }
+}
+
+
/**
* Specify the texture to cache.
*/
@@ -192,8 +220,10 @@ sp_tile_cache_set_texture(struct softpipe_tile_cache *tc,
tc->texture = texture;
- if (tc->tex_surf && tc->tex_surf->map)
+ if (tc->tex_surf_map) {
pipe_surface_unmap(tc->tex_surf);
+ tc->tex_surf_map = NULL;
+ }
pipe_surface_reference(&tc->tex_surf, NULL);
/* mark as entries as invalid/empty */
@@ -330,9 +360,6 @@ sp_flush_tile_cache(struct softpipe_context *softpipe,
if (!ps || !ps->buffer)
return;
- if (!ps->map)
- pipe_surface_map(ps);
-
for (pos = 0; pos < NUM_ENTRIES; pos++) {
struct softpipe_cached_tile *tile = tc->entries + pos;
if (tile->x >= 0) {
@@ -475,11 +502,11 @@ sp_get_cached_tile_tex(struct pipe_context *pipe,
tc->tex_z != z) {
/* get new surface (view into texture) */
- if (tc->tex_surf && tc->tex_surf->map)
+ if (tc->tex_surf_map)
pipe_surface_unmap(tc->tex_surf);
tc->tex_surf = pipe->get_tex_surface(pipe, tc->texture, face, level, z);
- pipe_surface_map(tc->tex_surf);
+ tc->tex_surf_map = pipe_surface_map(tc->tex_surf);
tc->tex_face = face;
tc->tex_level = level;
diff --git a/src/mesa/pipe/softpipe/sp_tile_cache.h b/src/mesa/pipe/softpipe/sp_tile_cache.h
index 91fb2795a2..7fd1081286 100644
--- a/src/mesa/pipe/softpipe/sp_tile_cache.h
+++ b/src/mesa/pipe/softpipe/sp_tile_cache.h
@@ -74,6 +74,12 @@ extern struct pipe_surface *
sp_tile_cache_get_surface(struct softpipe_tile_cache *tc);
extern void
+sp_tile_cache_map_surfaces(struct softpipe_tile_cache *tc);
+
+extern void
+sp_tile_cache_unmap_surfaces(struct softpipe_tile_cache *tc);
+
+extern void
sp_tile_cache_set_texture(struct softpipe_tile_cache *tc,
struct pipe_texture *texture);