r300g: inline FLUSH_CS
[mesa.git] / src / gallium / drivers / r300 / r300_query.c
index bc40fcfb5ba3cf6e408ee98ed82eb04354063a82..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;
@@ -78,54 +74,65 @@ static void r300_destroy_query(struct pipe_context* pipe,
 static void r300_begin_query(struct pipe_context* pipe,
                              struct pipe_query* query)
 {
-    uint32_t* map;
+    uint32_t value = ~0U;
     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;
+    }
 
-    map = pipe->screen->buffer_map(pipe->screen, r300->oqbo,
-            PIPE_BUFFER_USAGE_CPU_WRITE);
-    map += q->offset / 4;
-    *map = ~0U;
-    pipe->screen->buffer_unmap(pipe->screen, r300->oqbo);
+    pipe_buffer_write(pipe,
+                     r300->oqbo,
+                     q->offset,
+                     sizeof value,
+                     &value);
 
     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;
     struct r300_query *q = (struct r300_query*)query;
-    unsigned flags = PIPE_BUFFER_USAGE_CPU_READ;
+    struct pipe_transfer *transfer;
+    unsigned flags = PIPE_TRANSFER_READ;
     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);
     if (!wait) {
-        flags |= PIPE_BUFFER_USAGE_DONTBLOCK;
+        flags |= PIPE_TRANSFER_DONTBLOCK;
     }
 
-    map = pipe->screen->buffer_map(pipe->screen, r300->oqbo, flags);
+    map = pipe_buffer_map(pipe, r300->oqbo, flags, &transfer);
     if (!map)
         return FALSE;
     map += q->offset / 4;
@@ -140,15 +147,19 @@ 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;
         map++;
     }
-    pipe->screen->buffer_unmap(pipe->screen, r300->oqbo);
+    pipe_buffer_unmap(pipe, r300->oqbo, transfer);
 
     if (temp == ~0U) {
         /* Our results haven't been written yet... */