nv50: remove vtxbuf stateobject after a referenced vtxbuf is mapped
authorMaarten Maathuis <madman2003@gmail.com>
Sun, 20 Dec 2009 11:19:19 +0000 (12:19 +0100)
committerMaarten Maathuis <madman2003@gmail.com>
Tue, 5 Jan 2010 18:13:34 +0000 (19:13 +0100)
- This avoids problematic "reloc'ed while mapped" messages and
some associated corruption as well.

Signed-off-by: Maarten Maathuis <madman2003@gmail.com>
src/gallium/drivers/nouveau/nouveau_screen.c
src/gallium/drivers/nouveau/nouveau_screen.h
src/gallium/drivers/nouveau/nouveau_stateobj.h
src/gallium/drivers/nv50/nv50_screen.c
src/gallium/drivers/nv50/nv50_screen.h
src/gallium/drivers/nv50/nv50_state_validate.c

index 0437af3725c152b92cab09f5727c020cbd340fc4..7ebc94ed6c7f2b37d6f4d6fa230295581a88fdab 100644 (file)
@@ -127,8 +127,18 @@ nouveau_screen_bo_map(struct pipe_screen *pscreen, struct pipe_buffer *pb,
                      unsigned usage)
 {
        struct nouveau_bo *bo = nouveau_bo(pb);
+       struct nouveau_screen *nscreen = nouveau_screen(pscreen);
        int ret;
 
+       if (nscreen->pre_pipebuffer_map_callback) {
+               ret = nscreen->pre_pipebuffer_map_callback(pscreen, pb, usage);
+               if (ret) {
+                       debug_printf("pre_pipebuffer_map_callback failed %d\n",
+                               ret);
+                       return NULL;
+               }
+       }
+
        ret = nouveau_bo_map(bo, nouveau_screen_map_flags(usage));
        if (ret) {
                debug_printf("map failed: %d\n", ret);
@@ -143,11 +153,22 @@ nouveau_screen_bo_map_range(struct pipe_screen *pscreen, struct pipe_buffer *pb,
                            unsigned offset, unsigned length, unsigned usage)
 {
        struct nouveau_bo *bo = nouveau_bo(pb);
+       struct nouveau_screen *nscreen = nouveau_screen(pscreen);
        uint32_t flags = nouveau_screen_map_flags(usage);
        int ret;
 
+       if (nscreen->pre_pipebuffer_map_callback) {
+               ret = nscreen->pre_pipebuffer_map_callback(pscreen, pb, usage);
+               if (ret) {
+                       debug_printf("pre_pipebuffer_map_callback failed %d\n",
+                               ret);
+                       return NULL;
+               }
+       }
+
        ret = nouveau_bo_map_range(bo, offset, length, flags);
        if (ret) {
+               nouveau_bo_unmap(bo);
                if (!(flags & NOUVEAU_BO_NOWAIT) || ret != -EBUSY)
                        debug_printf("map_range failed: %d\n", ret);
                return NULL;
index ebfc67ad1c171dda2ba601260b663a47a53b2a06..a7927d88dfc832fec9011e52e95fa7a5481b0762 100644 (file)
@@ -5,6 +5,9 @@ struct nouveau_screen {
        struct pipe_screen base;
        struct nouveau_device *device;
        struct nouveau_channel *channel;
+
+       int (*pre_pipebuffer_map_callback) (struct pipe_screen *pscreen,
+               struct pipe_buffer *pb, unsigned usage);
 };
 
 static inline struct nouveau_screen *
index 9aee9e495664e3c8b3caf97669106e2b729ff256..77ff7dcf20967a9b8bf20ebc228ce97aa4b7a50a 100644 (file)
@@ -98,6 +98,19 @@ so_reloc(struct nouveau_stateobj *so, struct nouveau_bo *bo,
        so_data(so, data);
 }
 
+/* Determine if this buffer object is referenced by this state object. */
+static INLINE boolean
+so_bo_is_reloc(struct nouveau_stateobj *so, struct nouveau_bo *bo)
+{
+       int i;
+
+       for (i = 0; i < so->cur_reloc; i++)
+               if (so->reloc[i].bo == bo)
+                       return true;
+
+       return false;
+}
+
 static INLINE void
 so_dump(struct nouveau_stateobj *so)
 {
index 7e039ea82ecafe4df6c88723e9310bd21856130c..1778a74517940613ee4fab613eedd04c65fa8e4e 100644 (file)
@@ -189,6 +189,28 @@ nv50_screen_destroy(struct pipe_screen *pscreen)
        FREE(screen);
 }
 
+static int
+nv50_pre_pipebuffer_map(struct pipe_screen *pscreen, struct pipe_buffer *pb,
+       unsigned usage)
+{
+       struct nv50_screen *screen = nv50_screen(pscreen);
+       struct nv50_context *ctx = screen->cur_ctx;
+
+       if (!(pb->usage & PIPE_BUFFER_USAGE_VERTEX))
+               return 0;
+
+       /* Our vtxbuf got mapped, it can no longer be considered part of current
+        * state, remove it to avoid emitting reloc markers.
+        */
+       if (ctx && ctx->state.vtxbuf && so_bo_is_reloc(ctx->state.vtxbuf,
+                       nouveau_bo(pb))) {
+               so_ref(NULL, &ctx->state.vtxbuf);
+               ctx->dirty |= NV50_NEW_ARRAYS;
+       }
+
+       return 0;
+}
+
 struct pipe_screen *
 nv50_screen_create(struct pipe_winsys *ws, struct nouveau_device *dev)
 {
@@ -216,6 +238,7 @@ nv50_screen_create(struct pipe_winsys *ws, struct nouveau_device *dev)
        pscreen->get_param = nv50_screen_get_param;
        pscreen->get_paramf = nv50_screen_get_paramf;
        pscreen->is_format_supported = nv50_screen_is_format_supported;
+       screen->base.pre_pipebuffer_map_callback = nv50_pre_pipebuffer_map;
 
        nv50_screen_init_miptree_functions(pscreen);
        nv50_transfer_init_screen_functions(pscreen);
index 61e24a5b571746e3b5b9c2af0fb76ff4398b2a2e..a038a4e3c2adee79addfa0a57229c6022699ab23 100644 (file)
@@ -2,6 +2,7 @@
 #define __NV50_SCREEN_H__
 
 #include "nouveau/nouveau_screen.h"
+#include "nv50_context.h"
 
 struct nv50_screen {
        struct nouveau_screen base;
@@ -9,6 +10,7 @@ struct nv50_screen {
        struct nouveau_winsys *nvws;
 
        unsigned cur_pctx;
+       struct nv50_context *cur_ctx;
 
        struct nouveau_grobj *tesla;
        struct nouveau_grobj *eng2d;
index c8bdf9dc2761944d35c086166df6420124ca0fbb..682786345ef8ddc20ed0b9565803e17dad8d1d23 100644 (file)
@@ -185,6 +185,9 @@ nv50_state_emit(struct nv50_context *nv50)
        struct nv50_screen *screen = nv50->screen;
        struct nouveau_channel *chan = screen->base.channel;
 
+       /* I don't want to copy headers from the winsys. */
+       screen->cur_ctx = nv50;
+
        if (nv50->pctx_id != screen->cur_pctx) {
                if (nv50->state.fb)
                        nv50->state.dirty |= NV50_NEW_FRAMEBUFFER;