r600g: remove radeon_bo::handle
[mesa.git] / src / gallium / winsys / r600 / drm / r600_hw_context.c
index 5dd079f62acb84f9a1b86cd7bf3f8a2210d1b069..b2da3eb0458381842f96c9ef4f0b7e237b3730ee 100644 (file)
@@ -41,7 +41,7 @@ void r600_get_backend_mask(struct r600_context *ctx)
        unsigned i, mask = 0;
 
        /* if backend_map query is supported by the kernel */
-       if (ctx->radeon->backend_map_valid) {
+       if (ctx->radeon->info.r600_backend_map_valid) {
                unsigned num_tile_pipes = r600_get_num_tile_pipes(ctx->radeon);
                unsigned backend_map = r600_get_backend_map(ctx->radeon);
                unsigned item_width, item_mask;
@@ -74,7 +74,7 @@ void r600_get_backend_mask(struct r600_context *ctx)
                goto err;
 
        /* initialize buffer with zeroes */
-       results = r600_bo_map(ctx->radeon, buffer, PB_USAGE_CPU_WRITE, NULL);
+       results = r600_bo_map(ctx->radeon, buffer, ctx->cs, PIPE_TRANSFER_WRITE);
        if (results) {
                memset(results, 0, ctx->max_db * 4 * 4);
                r600_bo_unmap(ctx->radeon, buffer);
@@ -89,10 +89,10 @@ void r600_get_backend_mask(struct r600_context *ctx)
                ctx->pm4[ctx->pm4_cdwords++] = r600_context_bo_reloc(ctx, buffer);
 
                /* execute */
-               r600_context_flush(ctx);
+               r600_context_flush(ctx, 0);
 
                /* analyze results */
-               results = r600_bo_map(ctx->radeon, buffer, PB_USAGE_CPU_READ, NULL);
+               results = r600_bo_map(ctx->radeon, buffer, ctx->cs, PIPE_TRANSFER_READ);
                if (results) {
                        for(i = 0; i < ctx->max_db; i++) {
                                /* at least highest bit will be set if backend is used */
@@ -776,7 +776,6 @@ void r600_context_fini(struct r600_context *ctx)
        free(ctx->range);
        free(ctx->blocks);
        free(ctx->bo);
-       free(ctx->pm4);
        ctx->radeon->ws->cs_destroy(ctx->cs);
 
        memset(ctx, 0, sizeof(struct r600_context));
@@ -920,11 +919,7 @@ int r600_context_init(struct r600_context *ctx, struct radeon *radeon)
                goto out_err;
        }
        ctx->pm4_ndwords = RADEON_CTX_MAX_PM4;
-       ctx->pm4 = calloc(ctx->pm4_ndwords, 4);
-       if (ctx->pm4 == NULL) {
-               r = -ENOMEM;
-               goto out_err;
-       }
+       ctx->pm4 = ctx->cs->buf;
 
        r600_init_cs(ctx);
        /* save 16dwords space for fence mecanism */
@@ -945,7 +940,7 @@ void r600_context_flush_all(struct r600_context *ctx, unsigned flush_flags)
 
        if ((ctx->pm4_dirty_cdwords + ndwords + ctx->pm4_cdwords) > ctx->pm4_ndwords) {
                /* need to flush */
-               r600_context_flush(ctx);
+               r600_context_flush(ctx, 0);
        }
 
        ctx->pm4[ctx->pm4_cdwords++] = PKT3(PKT3_SURFACE_SYNC, 3, ctx->predicate_drawing);
@@ -1135,11 +1130,11 @@ void r600_context_pipe_state_set_resource(struct r600_context *ctx, struct r600_
 
        if (!dirty) {
                if (is_vertex) {
-                       if (block->reloc[1].bo->bo->handle != state->bo[0]->bo->handle)
+                       if (block->reloc[1].bo->bo->buf != state->bo[0]->bo->buf)
                                dirty |= R600_BLOCK_STATUS_RESOURCE_DIRTY;
                } else {
-                       if ((block->reloc[1].bo->bo->handle != state->bo[0]->bo->handle) ||
-                           (block->reloc[2].bo->bo->handle != state->bo[1]->bo->handle))
+                       if ((block->reloc[1].bo->bo->buf != state->bo[0]->bo->buf) ||
+                           (block->reloc[2].bo->bo->buf != state->bo[1]->bo->buf))
                                dirty |= R600_BLOCK_STATUS_RESOURCE_DIRTY;
                }
        }
@@ -1446,7 +1441,7 @@ void r600_context_draw(struct r600_context *ctx, const struct r600_draw *draw)
 
        if ((ctx->pm4_dirty_cdwords + ndwords + ctx->pm4_cdwords) > ctx->pm4_ndwords) {
                /* need to flush */
-               r600_context_flush(ctx);
+               r600_context_flush(ctx, 0);
        }
        /* at that point everythings is flushed and ctx->pm4_cdwords = 0 */
        if ((ctx->pm4_dirty_cdwords + ndwords) > ctx->pm4_ndwords) {
@@ -1490,12 +1485,8 @@ void r600_context_draw(struct r600_context *ctx, const struct r600_draw *draw)
        ctx->pm4_dirty_cdwords = 0;
 }
 
-void r600_context_flush(struct r600_context *ctx)
+void r600_context_flush(struct r600_context *ctx, unsigned flags)
 {
-       struct drm_radeon_cs drmib = {};
-       struct drm_radeon_cs_chunk chunks[2];
-       uint64_t chunk_array[2];
-       int r;
        struct r600_block *enable_block = NULL;
 
        if (ctx->pm4_cdwords == ctx->init_dwords)
@@ -1513,27 +1504,13 @@ void r600_context_flush(struct r600_context *ctx)
        ctx->pm4[ctx->pm4_cdwords++] = PKT3(PKT3_EVENT_WRITE, 0, 0);
        ctx->pm4[ctx->pm4_cdwords++] = EVENT_TYPE(EVENT_TYPE_PS_PARTIAL_FLUSH) | EVENT_INDEX(4);
 
-#if 1
-       /* emit cs */
-       drmib.num_chunks = 2;
-       drmib.chunks = (uint64_t)(uintptr_t)chunk_array;
-       chunks[0].chunk_id = RADEON_CHUNK_ID_IB;
-       chunks[0].length_dw = ctx->pm4_cdwords;
-       chunks[0].chunk_data = (uint64_t)(uintptr_t)ctx->pm4;
-       chunks[1].chunk_id = RADEON_CHUNK_ID_RELOCS;
-       chunks[1].length_dw = ctx->creloc * sizeof(struct r600_reloc) / 4;
-       chunks[1].chunk_data = (uint64_t)(uintptr_t)ctx->reloc;
-       chunk_array[0] = (uint64_t)(uintptr_t)&chunks[0];
-       chunk_array[1] = (uint64_t)(uintptr_t)&chunks[1];
-       r = drmCommandWriteRead(ctx->radeon->info.fd, DRM_RADEON_CS, &drmib,
-                               sizeof(struct drm_radeon_cs));
-       if (r) {
-               fprintf(stderr, "radeon: The kernel rejected CS, "
-                       "see dmesg for more information.\n");
-       }
-#else
-       *ctx->radeon->cfence = ctx->radeon->fence;
-#endif
+       /* Flush the CS. */
+       ctx->cs->cdw = ctx->pm4_cdwords;
+       ctx->radeon->ws->cs_flush(ctx->cs, flags);
+
+       /* We need to get the pointer to the other CS,
+        * the command streams are double-buffered. */
+       ctx->pm4 = ctx->cs->buf;
 
        /* restart */
        for (int i = 0; i < ctx->creloc; i++) {
@@ -1544,7 +1521,6 @@ void r600_context_flush(struct r600_context *ctx)
        ctx->pm4_dirty_cdwords = 0;
        ctx->pm4_cdwords = 0;
        ctx->flags = 0;
-       ctx->radeon->ws->cs_flush(ctx->cs, 0);
 
        r600_init_cs(ctx);
 
@@ -1578,7 +1554,7 @@ void r600_context_emit_fence(struct r600_context *ctx, struct r600_bo *fence_bo,
 
        if ((ctx->pm4_dirty_cdwords + ndwords + ctx->pm4_cdwords) > ctx->pm4_ndwords) {
                /* need to flush */
-               r600_context_flush(ctx);
+               r600_context_flush(ctx, 0);
        }
 
        ctx->pm4[ctx->pm4_cdwords++] = PKT3(PKT3_EVENT_WRITE, 0, 0);
@@ -1600,9 +1576,9 @@ static boolean r600_query_result(struct r600_context *ctx, struct r600_query *qu
        u32 *results, *current_result;
 
        if (wait)
-               results = r600_bo_map(ctx->radeon, query->buffer, PIPE_TRANSFER_READ, NULL);
+               results = r600_bo_map(ctx->radeon, query->buffer, ctx->cs, PIPE_TRANSFER_READ);
        else
-               results = r600_bo_map(ctx->radeon, query->buffer, PIPE_TRANSFER_DONTBLOCK | PIPE_TRANSFER_READ, NULL);
+               results = r600_bo_map(ctx->radeon, query->buffer, ctx->cs, PIPE_TRANSFER_DONTBLOCK | PIPE_TRANSFER_READ);
        if (!results)
                return FALSE;
 
@@ -1640,7 +1616,7 @@ void r600_query_begin(struct r600_context *ctx, struct r600_query *query)
 
        if ((required_space + ctx->pm4_cdwords) > ctx->pm4_ndwords) {
                /* need to flush */
-               r600_context_flush(ctx);
+               r600_context_flush(ctx, 0);
        }
 
        if (query->type == PIPE_QUERY_OCCLUSION_COUNTER) {
@@ -1651,7 +1627,7 @@ void r600_query_begin(struct r600_context *ctx, struct r600_query *query)
                        query->queries_emitted = 1;
                } else {
                        if (++query->queries_emitted > query->buffer_size / query->result_size / 2)
-                               r600_context_flush(ctx);
+                               r600_context_flush(ctx, 0);
                }
        }
 
@@ -1662,7 +1638,7 @@ void r600_query_begin(struct r600_context *ctx, struct r600_query *query)
        /* collect current results if query buffer is full */
        if (new_results_end == query->results_start) {
                if (!(query->state & R600_QUERY_STATE_FLUSHED))
-                       r600_context_flush(ctx);
+                       r600_context_flush(ctx, 0);
                r600_query_result(ctx, query, TRUE);
        }
 
@@ -1670,7 +1646,7 @@ void r600_query_begin(struct r600_context *ctx, struct r600_query *query)
                u32 *results;
                int i;
 
-               results = r600_bo_map(ctx->radeon, query->buffer, PIPE_TRANSFER_WRITE, NULL);
+               results = r600_bo_map(ctx->radeon, query->buffer, ctx->cs, PIPE_TRANSFER_WRITE);
                if (results) {
                        results = (u32*)((char*)results + query->results_end);
                        memset(results, 0, query->result_size);
@@ -1743,7 +1719,7 @@ void r600_query_predication(struct r600_context *ctx, struct r600_query *query,
 {
        if (operation == PREDICATION_OP_CLEAR) {
                if (ctx->pm4_cdwords + 3 > ctx->pm4_ndwords)
-                       r600_context_flush(ctx);
+                       r600_context_flush(ctx, 0);
 
                ctx->pm4[ctx->pm4_cdwords++] = PKT3(PKT3_SET_PREDICATION, 1, 0);
                ctx->pm4[ctx->pm4_cdwords++] = 0;
@@ -1759,7 +1735,7 @@ void r600_query_predication(struct r600_context *ctx, struct r600_query *query,
                count /= query->result_size;
 
                if (ctx->pm4_cdwords + 5 * count > ctx->pm4_ndwords)
-                       r600_context_flush(ctx);
+                       r600_context_flush(ctx, 0);
 
                op = PRED_OP(operation) | PREDICATION_DRAW_VISIBLE |
                                (flag_wait ? PREDICATION_HINT_WAIT : PREDICATION_HINT_NOWAIT_DRAW);
@@ -1832,7 +1808,7 @@ boolean r600_context_query_result(struct r600_context *ctx,
        uint64_t *result = (uint64_t*)vresult;
 
        if (!(query->state & R600_QUERY_STATE_FLUSHED)) {
-               r600_context_flush(ctx);
+               r600_context_flush(ctx, 0);
        }
        if (!r600_query_result(ctx, query, wait))
                return FALSE;