nvfx: pause occlusion queries during blitter usage
authorLuca Barbieri <luca@luca-barbieri.com>
Sun, 5 Sep 2010 06:27:12 +0000 (08:27 +0200)
committerLuca Barbieri <luca@luca-barbieri.com>
Sun, 5 Sep 2010 15:52:26 +0000 (17:52 +0200)
Thanks for Dave Airlie and Jerome Glisse for their code which made
me realize I need this too.

src/gallium/drivers/nouveau/nouveau_class.h
src/gallium/drivers/nvfx/nvfx_context.h
src/gallium/drivers/nvfx/nvfx_query.c
src/gallium/drivers/nvfx/nvfx_surface.c

index 72ddf9bf760c5a049d4252294ff0f63abb699ec1..2c616886a39df57e58957486b56620fd8f5b776e 100644 (file)
@@ -6205,7 +6205,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #define  NV34TCL_COLOR_MATERIAL_BACK_B                                                 0x000017b8
 #define  NV34TCL_COLOR_MATERIAL_BACK_A                                                 0x000017c0
 #define  NV34TCL_QUERY_RESET                                                           0x000017c8
-#define  NV34TCL_QUERY_UNK17CC                                                         0x000017cc
+#define  NV34TCL_QUERY_ENABLE                                                          0x000017cc
 #define  NV34TCL_QUERY_GET                                                             0x00001800
 #define   NV34TCL_QUERY_GET_UNK24_SHIFT                                                        24
 #define   NV34TCL_QUERY_GET_UNK24_MASK                                                 0xff000000
index 369c2163882a7f0947353a225d8626602a6f1838..a164ba6c10b3a57a6fe33dde283e1b3e1b5aef17 100644 (file)
@@ -177,6 +177,7 @@ struct nvfx_context {
        struct nvfx_sampler_state *tex_sampler[PIPE_MAX_SAMPLERS];
        struct pipe_sampler_view *fragment_sampler_views[PIPE_MAX_SAMPLERS];
        struct nvfx_pipe_fragment_program* dummy_fs;
+       struct pipe_query* query;
 
        unsigned nr_samplers;
        unsigned nr_textures;
index 1dab20c41a02ae4019123c117aa06a27cdd01211..eeeb89766104df05eded8d6d1edcf15c317b2136 100644 (file)
@@ -49,9 +49,10 @@ nvfx_query_begin(struct pipe_context *pipe, struct pipe_query *pq)
        struct nvfx_query *q = nvfx_query(pq);
        struct nvfx_screen *screen = nvfx->screen;
        struct nouveau_channel *chan = screen->base.channel;
-       struct nouveau_grobj *eng3d = screen->eng3d;
        uint64_t tmp;
 
+       assert(!nvfx->query);
+
        /* Happens when end_query() is called, then another begin_query()
         * without querying the result in-between.  For now we'll wait for
         * the existing query to notify completion, but it could be better.
@@ -71,27 +72,35 @@ nvfx_query_begin(struct pipe_context *pipe, struct pipe_query *pq)
 
        nouveau_notifier_reset(nvfx->screen->query, q->object->start);
 
-       BEGIN_RING(chan, eng3d, NV34TCL_QUERY_RESET, 1);
-       OUT_RING  (chan, 1);
-       BEGIN_RING(chan, eng3d, NV34TCL_QUERY_UNK17CC, 1);
-       OUT_RING  (chan, 1);
+       WAIT_RING(chan, 4);
+       OUT_RING(chan, RING_3D(NV34TCL_QUERY_RESET, 1));
+       OUT_RING(chan, 1);
+       OUT_RING(chan, RING_3D(NV34TCL_QUERY_ENABLE, 1));
+       OUT_RING(chan, 1);
 
        q->ready = FALSE;
+
+       nvfx->query = pq;
 }
 
 static void
 nvfx_query_end(struct pipe_context *pipe, struct pipe_query *pq)
 {
        struct nvfx_context *nvfx = nvfx_context(pipe);
-       struct nvfx_screen *screen = nvfx->screen;
-       struct nouveau_channel *chan = screen->base.channel;
-       struct nouveau_grobj *eng3d = screen->eng3d;
+       struct nouveau_channel *chan = nvfx->screen->base.channel;
        struct nvfx_query *q = nvfx_query(pq);
 
-       BEGIN_RING(chan, eng3d, NV34TCL_QUERY_GET, 1);
+       assert(nvfx->query == pq);
+
+       WAIT_RING(chan, 4);
+       OUT_RING(chan, RING_3D(NV34TCL_QUERY_GET, 1));
        OUT_RING  (chan, (0x01 << NV34TCL_QUERY_GET_UNK24_SHIFT) |
                   ((q->object->start * 32) << NV34TCL_QUERY_GET_OFFSET_SHIFT));
+       OUT_RING(chan, RING_3D(NV34TCL_QUERY_ENABLE, 1));
+       OUT_RING(chan, 0);
        FIRE_RING(chan);
+
+       nvfx->query = 0;
 }
 
 static boolean
index aff7ac54b7ff744b758f8e245f4492ce2a6919d7..e39f7f15a31f3f354d34a51910717d20451b7733 100644 (file)
@@ -163,6 +163,14 @@ nvfx_get_blitter(struct pipe_context* pipe, int copy)
 
        assert(nvfx->blitters_in_use < Elements(nvfx->blitter));
 
+       if(nvfx->query && !nvfx->blitters_in_use)
+       {
+               struct nouveau_channel* chan = nvfx->screen->base.channel;
+               WAIT_RING(chan, 2);
+               OUT_RING(chan, RING_3D(NV34TCL_QUERY_ENABLE, 1));
+               OUT_RING(chan, 0);
+       }
+
        struct blitter_context** pblitter = &nvfx->blitter[nvfx->blitters_in_use++];
        if(!*pblitter)
                *pblitter = util_blitter_create(pipe);
@@ -195,6 +203,14 @@ nvfx_put_blitter(struct pipe_context* pipe, struct blitter_context* blitter)
        struct nvfx_context* nvfx = nvfx_context(pipe);
        --nvfx->blitters_in_use;
        assert(nvfx->blitters_in_use >= 0);
+
+       if(nvfx->query && !nvfx->blitters_in_use)
+       {
+               struct nouveau_channel* chan = nvfx->screen->base.channel;
+               WAIT_RING(chan, 2);
+               OUT_RING(chan, RING_3D(NV34TCL_QUERY_ENABLE, 1));
+               OUT_RING(chan, 1);
+       }
 }
 
 static unsigned