r300g: convert query to a state for emitting.
authorDave Airlie <airlied@redhat.com>
Wed, 14 Oct 2009 07:14:43 +0000 (17:14 +1000)
committerDave Airlie <airlied@redhat.com>
Wed, 14 Oct 2009 07:14:43 +0000 (17:14 +1000)
This means we don't emit in the begin query but when we have
to flush. Similiar to classic.

TODO:
make query object actually work.

src/gallium/drivers/r300/r300_context.h
src/gallium/drivers/r300/r300_emit.c
src/gallium/drivers/r300/r300_query.c

index 9b0094b63caac6331050e76712960edc1c27fadd..3a01869ba10d35128dff1c59a51825b0847aeec7 100644 (file)
@@ -141,6 +141,7 @@ struct r300_viewport_state {
 #define R300_NEW_VERTEX_FORMAT   0x04000000
 #define R300_NEW_VERTEX_SHADER   0x08000000
 #define R300_NEW_VIEWPORT        0x10000000
+#define R300_NEW_QUERY           0x20000000
 #define R300_NEW_KITCHEN_SINK    0x1fffffff
 
 /* The next several objects are not pure Radeon state; they inherit from
@@ -239,6 +240,7 @@ struct r300_context {
     /* Occlusion query buffer. */
     struct pipe_buffer* oqbo;
     /* Query list. */
+    struct r300_query *query_current;
     struct r300_query query_list;
 
     /* Various CSO state objects. */
index 3d28249c164e442352b7bff1d22b9e9a5b6dfd1c..babbe0dd74a8706a30e9f308c6b0dbdb4cb1b64c 100644 (file)
@@ -320,12 +320,16 @@ void r300_emit_fb_state(struct r300_context* r300,
     END_CS;
 }
 
-void r300_emit_query_begin(struct r300_context* r300,
-                           struct r300_query* query)
+void r300_emit_query_start(struct r300_context *r300)
+
 {
-    struct r300_capabilities* caps = r300_screen(r300->context.screen)->caps;
+    struct r300_capabilities *caps = r300_screen(r300->context.screen)->caps;
+    struct r300_query *query = r300->query_current;
     CS_LOCALS(r300);
 
+    if (!query)
+       return;
+
     /* XXX This will almost certainly not return good results
      * for overlapping queries. */
     BEGIN_CS(4);
@@ -772,6 +776,11 @@ validate:
         goto validate;
     }
 
+    if (r300->dirty_state & R300_NEW_QUERY) {
+        r300_emit_query_start(r300);
+        r300->dirty_state &= ~R300_NEW_QUERY;
+    }
+
     if (r300->dirty_state & R300_NEW_BLEND) {
         r300_emit_blend_state(r300, r300->blend_state);
         r300->dirty_state &= ~R300_NEW_BLEND;
index b01313648bf336457f3567a48b4010e94ac0ac5a..fb4340ff3d1fe0b73d2eb44ca703915f3980fb3e 100644 (file)
@@ -74,6 +74,8 @@ static void r300_begin_query(struct pipe_context* pipe,
     struct r300_context* r300 = r300_context(pipe);
     struct r300_query* q = (struct r300_query*)query;
 
+    assert(r300->query_current == NULL);
+
     map = pipe->screen->buffer_map(pipe->screen, r300->oqbo,
             PIPE_BUFFER_USAGE_CPU_WRITE);
     map += q->offset / 4;
@@ -81,8 +83,8 @@ static void r300_begin_query(struct pipe_context* pipe,
     pipe->screen->buffer_unmap(pipe->screen, r300->oqbo);
 
     q->flushed = FALSE;
-    r300_emit_dirty_state(r300);
-    r300_emit_query_begin(r300, q);
+    r300->query_current = q;
+    r300->dirty_state |= R300_NEW_QUERY;
 }
 
 static void r300_end_query(struct pipe_context* pipe,
@@ -93,6 +95,8 @@ static void r300_end_query(struct pipe_context* pipe,
 
     r300_emit_dirty_state(r300);
     r300_emit_query_end(r300, q);
+
+    r300->query_current = NULL;
 }
 
 static boolean r300_get_query_result(struct pipe_context* pipe,