r600g: remove redundant variable r600_query::buffer_size
authorMarek Olšák <maraeo@gmail.com>
Fri, 28 Oct 2011 10:34:57 +0000 (12:34 +0200)
committerMarek Olšák <maraeo@gmail.com>
Fri, 28 Oct 2011 17:29:05 +0000 (19:29 +0200)
src/gallium/drivers/r600/r600.h
src/gallium/drivers/r600/r600_hw_context.c

index 37b6e967c10348e2110c45bd2981716fc59e35aa..ea9a2d658c2443af63eb5667b744db93c1db2b29 100644 (file)
@@ -184,7 +184,6 @@ struct r600_query {
         * data blocks for current query are stored sequentially from
         * results_start to results_end, with wrapping on the buffer end */
        struct r600_resource                    *buffer;
-       unsigned                                buffer_size;
        /* linked list of queries */
        struct list_head                        list;
 };
index 9d6b0534c98220bac966b864fdcf810f796e9f61..d6dce2c1fd7dd3bf2d3acfcac2dd540c6f8ab312 100644 (file)
@@ -1594,7 +1594,7 @@ static boolean r600_query_result(struct r600_context *ctx, struct r600_query *qu
                }
 
                results_base += 4 * 4;
-               if (results_base >= query->buffer_size)
+               if (results_base >= query->buffer->b.b.b.width0)
                        results_base = 0;
        }
 
@@ -1632,13 +1632,13 @@ void r600_query_begin(struct r600_context *ctx, struct r600_query *query)
                if (query->state & R600_QUERY_STATE_FLUSHED) {
                        query->queries_emitted = 1;
                } else {
-                       if (++query->queries_emitted > query->buffer_size / query->result_size / 2)
+                       if (++query->queries_emitted > query->buffer->b.b.b.width0 / query->result_size / 2)
                                r600_context_flush(ctx, RADEON_FLUSH_ASYNC);
                }
        }
 
        new_results_end = query->results_end + query->result_size;
-       if (new_results_end >= query->buffer_size)
+       if (new_results_end >= query->buffer->b.b.b.width0)
                new_results_end = 0;
 
        /* collect current results if query buffer is full */
@@ -1720,7 +1720,7 @@ void r600_query_end(struct r600_context *ctx, struct r600_query *query)
        ctx->pm4[ctx->pm4_cdwords++] = r600_context_bo_reloc(ctx, query->buffer, RADEON_USAGE_WRITE);
 
        query->results_end += query->result_size;
-       if (query->results_end >= query->buffer_size)
+       if (query->results_end >= query->buffer->b.b.b.width0)
                query->results_end = 0;
 
        query->state ^= R600_QUERY_STATE_STARTED;
@@ -1746,8 +1746,10 @@ void r600_query_predication(struct r600_context *ctx, struct r600_query *query,
                u32 op;
 
                /* find count of the query data blocks */
-               count = query->buffer_size + query->results_end - query->results_start;
-               if (count >= query->buffer_size) count-=query->buffer_size;
+               count = query->buffer->b.b.b.width0 + query->results_end - query->results_start;
+               if (count >= query->buffer->b.b.b.width0) {
+                       count -= query->buffer->b.b.b.width0;
+               }
                count /= query->result_size;
 
                if (ctx->pm4_cdwords + 5 * count > ctx->pm4_ndwords)
@@ -1765,7 +1767,7 @@ void r600_query_predication(struct r600_context *ctx, struct r600_query *query,
                        ctx->pm4[ctx->pm4_cdwords++] = r600_context_bo_reloc(ctx, query->buffer,
                                                                             RADEON_USAGE_READ);
                        results_base += query->result_size;
-                       if (results_base >= query->buffer_size)
+                       if (results_base >= query->buffer->b.b.b.width0)
                                results_base = 0;
                        /* set CONTINUE bit for all packets except the first */
                        op |= PREDICATION_CONTINUE;
@@ -1775,12 +1777,14 @@ void r600_query_predication(struct r600_context *ctx, struct r600_query *query,
 
 struct r600_query *r600_context_query_create(struct r600_context *ctx, unsigned query_type)
 {
-       struct r600_query *query = calloc(1, sizeof(struct r600_query));
+       struct r600_query *query;
+       unsigned buffer_size = 4096;
+
+       query = CALLOC_STRUCT(r600_query);
        if (query == NULL)
                return NULL;
 
        query->type = query_type;
-       query->buffer_size = 4096;
 
        switch (query_type) {
        case PIPE_QUERY_OCCLUSION_COUNTER:
@@ -1796,21 +1800,20 @@ struct r600_query *r600_context_query_create(struct r600_context *ctx, unsigned
        }
 
        /* adjust buffer size to simplify offsets wrapping math */
-       query->buffer_size -= query->buffer_size % query->result_size;
+       buffer_size -= buffer_size % query->result_size;
 
-       /* As of GL4, query buffers are normally read by the CPU after
+       /* Queries are normally read by the CPU after
         * being written by the gpu, hence staging is probably a good
         * usage pattern.
         */
        query->buffer = (struct r600_resource*)
-               pipe_buffer_create(&ctx->screen->screen, PIPE_BIND_CUSTOM, PIPE_USAGE_STAGING, query->buffer_size);
+               pipe_buffer_create(&ctx->screen->screen, PIPE_BIND_CUSTOM, PIPE_USAGE_STAGING, buffer_size);
        if (!query->buffer) {
-               free(query);
+               FREE(query);
                return NULL;
        }
 
        LIST_ADDTAIL(&query->list, &ctx->query_list);
-
        return query;
 }