swr/rasterizer: improvements in simdlib
[mesa.git] / src / gallium / drivers / swr / swr_query.cpp
index a95e0d8d81605889ce9ca15dce512217ca8d32ba..8c49a2ebb2952bb19f1b130449766e7d111b4c81 100644 (file)
 
 #include "pipe/p_defines.h"
 #include "util/u_memory.h"
-#include "os/os_time.h"
+#include "util/os_time.h"
 #include "swr_context.h"
 #include "swr_fence.h"
 #include "swr_query.h"
 #include "swr_screen.h"
 #include "swr_state.h"
-
+#include "common/os.h"
 
 static struct swr_query *
 swr_query(struct pipe_query *p)
@@ -45,7 +45,8 @@ swr_create_query(struct pipe_context *pipe, unsigned type, unsigned index)
    assert(type < PIPE_QUERY_TYPES);
    assert(index < MAX_SO_STREAMS);
 
-   pq = CALLOC_STRUCT(swr_query);
+   pq = (struct swr_query *) AlignedMalloc(sizeof(struct swr_query), 64);
+   memset(pq, 0, sizeof(*pq));
 
    if (pq) {
       pq->type = type;
@@ -67,14 +68,14 @@ swr_destroy_query(struct pipe_context *pipe, struct pipe_query *q)
       swr_fence_reference(pipe->screen, &pq->fence, NULL);
    }
 
-   FREE(pq);
+   AlignedFree(pq);
 }
 
 
-static boolean
+static bool
 swr_get_query_result(struct pipe_context *pipe,
                      struct pipe_query *q,
-                     boolean wait,
+                     bool wait,
                      union pipe_query_result *result)
 {
    struct swr_query *pq = swr_query(q);
@@ -82,7 +83,7 @@ swr_get_query_result(struct pipe_context *pipe,
 
    if (pq->fence) {
       if (!wait && !swr_is_fence_done(pq->fence))
-         return FALSE;
+         return false;
 
       swr_fence_finish(pipe->screen, NULL, pq->fence, 0);
       swr_fence_reference(pipe->screen, &pq->fence, NULL);
@@ -93,10 +94,11 @@ swr_get_query_result(struct pipe_context *pipe,
    switch (pq->type) {
    /* Booleans */
    case PIPE_QUERY_OCCLUSION_PREDICATE:
+   case PIPE_QUERY_OCCLUSION_PREDICATE_CONSERVATIVE:
       result->b = pq->result.core.DepthPassCount != 0;
       break;
    case PIPE_QUERY_GPU_FINISHED:
-      result->b = TRUE;
+      result->b = true;
       break;
    /* Counters */
    case PIPE_QUERY_OCCLUSION_COUNTER:
@@ -153,10 +155,10 @@ swr_get_query_result(struct pipe_context *pipe,
       break;
    }
 
-   return TRUE;
+   return true;
 }
 
-static boolean
+static bool
 swr_begin_query(struct pipe_context *pipe, struct pipe_query *q)
 {
    struct swr_context *ctx = swr_context(pipe);
@@ -165,8 +167,9 @@ swr_begin_query(struct pipe_context *pipe, struct pipe_query *q)
    /* Initialize Results */
    memset(&pq->result, 0, sizeof(pq->result));
    switch (pq->type) {
+   case PIPE_QUERY_GPU_FINISHED:
    case PIPE_QUERY_TIMESTAMP:
-      /* nothing to do */
+      /* nothing to do, but don't want the default */
       break;
    case PIPE_QUERY_TIME_ELAPSED:
       pq->result.timestamp_start = swr_get_timestamp(pipe->screen);
@@ -178,13 +181,13 @@ swr_begin_query(struct pipe_context *pipe, struct pipe_query *q)
 
       /* Only change stat collection if there are no active queries */
       if (ctx->active_queries == 0) {
-         SwrEnableStatsFE(ctx->swrContext, TRUE);
-         SwrEnableStatsBE(ctx->swrContext, TRUE);
+         ctx->api.pfnSwrEnableStatsFE(ctx->swrContext, TRUE);
+         ctx->api.pfnSwrEnableStatsBE(ctx->swrContext, TRUE);
       }
+      ctx->active_queries++;
       break;
    }
 
-   ctx->active_queries++;
 
    return true;
 }
@@ -195,11 +198,10 @@ swr_end_query(struct pipe_context *pipe, struct pipe_query *q)
    struct swr_context *ctx = swr_context(pipe);
    struct swr_query *pq = swr_query(q);
 
-   assert(ctx->active_queries
-          && "swr_end_query, there are no active queries!");
-   ctx->active_queries--;
-
    switch (pq->type) {
+   case PIPE_QUERY_GPU_FINISHED:
+      /* nothing to do, but don't want the default */
+      break;
    case PIPE_QUERY_TIMESTAMP:
    case PIPE_QUERY_TIME_ELAPSED:
       pq->result.timestamp_end = swr_get_timestamp(pipe->screen);
@@ -214,9 +216,10 @@ swr_end_query(struct pipe_context *pipe, struct pipe_query *q)
       swr_fence_submit(ctx, pq->fence);
 
       /* Only change stat collection if there are no active queries */
+      ctx->active_queries--;
       if (ctx->active_queries == 0) {
-         SwrEnableStatsFE(ctx->swrContext, FALSE);
-         SwrEnableStatsBE(ctx->swrContext, FALSE);
+         ctx->api.pfnSwrEnableStatsFE(ctx->swrContext, FALSE);
+         ctx->api.pfnSwrEnableStatsBE(ctx->swrContext, FALSE);
       }
 
       break;
@@ -226,15 +229,15 @@ swr_end_query(struct pipe_context *pipe, struct pipe_query *q)
 }
 
 
-boolean
+bool
 swr_check_render_cond(struct pipe_context *pipe)
 {
    struct swr_context *ctx = swr_context(pipe);
-   boolean b, wait;
+   bool b, wait;
    uint64_t result;
 
    if (!ctx->render_cond_query)
-      return TRUE; /* no query predicate, draw normally */
+      return true; /* no query predicate, draw normally */
 
    wait = (ctx->render_cond_mode == PIPE_RENDER_COND_WAIT
            || ctx->render_cond_mode == PIPE_RENDER_COND_BY_REGION_WAIT);
@@ -244,12 +247,12 @@ swr_check_render_cond(struct pipe_context *pipe)
    if (b)
       return ((!result) == ctx->render_cond_cond);
    else
-      return TRUE;
+      return true;
 }
 
 
 static void
-swr_set_active_query_state(struct pipe_context *pipe, boolean enable)
+swr_set_active_query_state(struct pipe_context *pipe, bool enable)
 {
 }