r300g: inline FLUSH_CS
[mesa.git] / src / gallium / drivers / r300 / r300_query.c
index 3348a0ada61c3aa88ab0068c31b59b412931b8d5..7c088063683f81fbcff31742e91adb9b6dcd6c40 100644 (file)
 
 #include "r300_context.h"
 #include "r300_screen.h"
-#include "r300_cs.h"
 #include "r300_emit.h"
-#include "r300_query.h"
-#include "r300_reg.h"
 
 #include <stdio.h>
 
@@ -45,8 +42,6 @@ static struct pipe_query *r300_create_query(struct pipe_context *pipe,
     q->type = query_type;
     assert(q->type == PIPE_QUERY_OCCLUSION_COUNTER);
 
-    q->active = FALSE;
-
     if (r300screen->caps.family == CHIP_FAMILY_RV530)
         query_size = r300screen->caps.num_z_pipes * sizeof(uint32_t);
     else
@@ -61,6 +56,7 @@ static struct pipe_query *r300_create_query(struct pipe_context *pipe,
     /* XXX */
     if (q->offset >= 4096) {
         q->offset = 0;
+        fprintf(stderr, "r300: Rewinding OQBO...\n");
     }
 
     return (struct pipe_query*)q;
@@ -82,7 +78,12 @@ 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);
+    if (r300->query_current != NULL) {
+        fprintf(stderr, "r300: begin_query: "
+                "Some other query has already been started.\n");
+        assert(0);
+        return;
+    }
 
     pipe_buffer_write(pipe,
                      r300->oqbo,
@@ -92,24 +93,28 @@ static void r300_begin_query(struct pipe_context* pipe,
 
     q->flushed = FALSE;
     r300->query_current = q;
-    r300->dirty_state |= R300_NEW_QUERY;
+    r300->query_start.dirty = TRUE;
 }
 
 static void r300_end_query(struct pipe_context* pipe,
                           struct pipe_query* query)
 {
     struct r300_context* r300 = r300_context(pipe);
-    struct r300_query* q = (struct r300_query*)query;
+
+    if ((struct r300_query*)query != r300->query_current) {
+        fprintf(stderr, "r300: end_query: Got invalid query.\n");
+        assert(0);
+        return;
+    }
 
     r300_emit_query_end(r300);
-    q->begin_emitted = false;
     r300->query_current = NULL;
 }
 
 static boolean r300_get_query_result(struct pipe_context* pipe,
                                      struct pipe_query* query,
                                      boolean wait,
-                                     uint64_t* result)
+                                     void* vresult)
 {
     struct r300_context* r300 = r300_context(pipe);
     struct r300_screen* r300screen = r300->screen;
@@ -119,6 +124,7 @@ static boolean r300_get_query_result(struct pipe_context* pipe,
     uint32_t* map;
     uint32_t temp = 0;
     unsigned i, num_results;
+    uint64_t *result = (uint64_t*)vresult;
 
     if (q->flushed == FALSE)
         pipe->flush(pipe, 0, NULL);
@@ -141,9 +147,13 @@ static boolean r300_get_query_result(struct pipe_context* pipe,
             /* Looks like our results aren't ready yet. */
             if (wait) {
                 fprintf(stderr, "r300: Despite waiting, OQ results haven't "
-                                "come in yet.\n");
+                                "come in yet. This is a driver bug.\n"
+                                "r300: Returning bogus results to avoid "
+                                "a possible infinite loop...\n");
+                temp = 987654321;
+            } else {
+                temp = ~0U;
             }
-            temp = ~0U;
             break;
         }
         temp += *map;