r600g: use buffer_map/unmap from radeon_winsys
authorMarek Olšák <maraeo@gmail.com>
Thu, 4 Aug 2011 02:27:48 +0000 (04:27 +0200)
committerMarek Olšák <maraeo@gmail.com>
Tue, 16 Aug 2011 07:15:11 +0000 (09:15 +0200)
This also drops the unneeded bo_busy/wait functions.

Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
src/gallium/drivers/r600/r600.h
src/gallium/drivers/r600/r600_asm.c
src/gallium/drivers/r600/r600_buffer.c
src/gallium/drivers/r600/r600_pipe.c
src/gallium/drivers/r600/r600_shader.c
src/gallium/drivers/r600/r600_texture.c
src/gallium/winsys/r600/drm/r600_bo.c
src/gallium/winsys/r600/drm/r600_hw_context.c
src/gallium/winsys/r600/drm/r600_priv.h
src/gallium/winsys/r600/drm/radeon_bo.c

index 21b42736c6a3fcbef28b5a39009eed3b6bff3913..0c70fe2bb0ac2814a45fdfd736ddac7f840ca51f 100644 (file)
@@ -95,13 +95,14 @@ unsigned r600_get_backend_map(struct radeon *radeon);
 
 /* r600_bo.c */
 struct r600_bo;
+struct radeon_winsys_cs;
 
 struct r600_bo *r600_bo(struct radeon *radeon,
                        unsigned size, unsigned alignment,
                        unsigned binding, unsigned usage);
 struct r600_bo *r600_bo_handle(struct radeon *radeon, struct winsys_handle *whandle,
                                unsigned *stride, unsigned *array_mode);
-void *r600_bo_map(struct radeon *radeon, struct r600_bo *bo, unsigned usage, void *ctx);
+void *r600_bo_map(struct radeon *radeon, struct r600_bo *bo, struct radeon_winsys_cs *cs, unsigned usage);
 void r600_bo_unmap(struct radeon *radeon, struct r600_bo *bo);
 boolean r600_bo_get_winsys_handle(struct radeon *radeon, struct r600_bo *pb_bo,
                                  unsigned stride, struct winsys_handle *whandle);
index 24af9917a6f7301e40e9471c76533a7f6d8c95e2..f5244a723f4bcf2be897def794cacde419ec98b4 100644 (file)
@@ -2231,7 +2231,7 @@ int r600_vertex_elements_build_fetch_shader(struct r600_pipe_context *rctx, stru
                return -ENOMEM;
        }
 
-       bytecode = r600_bo_map(rctx->radeon, ve->fetch_shader, 0, NULL);
+       bytecode = r600_bo_map(rctx->radeon, ve->fetch_shader, rctx->ctx.cs, PIPE_TRANSFER_WRITE);
        if (bytecode == NULL) {
                r600_bc_clear(&bc);
                r600_bo_reference(rctx->radeon, &ve->fetch_shader, NULL);
index 28d8c6af1cb75c01084e75821867b41a63785215..b8c6a4197486f332150fe9dfa1cff7697aebcd77 100644 (file)
@@ -85,7 +85,7 @@ static void *r600_buffer_transfer_map(struct pipe_context *pipe,
        if (rbuffer->r.b.user_ptr)
                return (uint8_t*)rbuffer->r.b.user_ptr + transfer->box.x;
 
-       data = r600_bo_map(rctx->screen->radeon, rbuffer->r.bo, transfer->usage, pipe);
+       data = r600_bo_map(rctx->screen->radeon, rbuffer->r.bo, rctx->ctx.cs, transfer->usage);
        if (!data)
                return NULL;
 
@@ -134,9 +134,8 @@ static void r600_buffer_transfer_inline_write(struct pipe_context *pipe,
 
        assert(rbuffer->r.b.user_ptr == NULL);
 
-       map = r600_bo_map(radeon, rbuffer->r.bo,
-                         PIPE_TRANSFER_WRITE | PIPE_TRANSFER_DISCARD | usage,
-                         pipe);
+       map = r600_bo_map(radeon, rbuffer->r.bo, rctx->ctx.cs,
+                         PIPE_TRANSFER_WRITE | PIPE_TRANSFER_DISCARD | usage);
 
        memcpy(map + box->x, data, box->width);
 
index e3e31982acd2364745718819770407b737728eac..1072ea0744d69341d8518b5ccd6897f99ee0c782 100644 (file)
@@ -54,6 +54,7 @@
  */
 static struct r600_fence *r600_create_fence(struct r600_pipe_context *ctx)
 {
+       struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx;
        struct r600_fence *fence = NULL;
 
        if (!ctx->fences.bo) {
@@ -63,7 +64,8 @@ static struct r600_fence *r600_create_fence(struct r600_pipe_context *ctx)
                        R600_ERR("r600: failed to create bo for fence objects\n");
                        return NULL;
                }
-               ctx->fences.data = r600_bo_map(ctx->radeon, ctx->fences.bo, PIPE_TRANSFER_UNSYNCHRONIZED, NULL);
+               ctx->fences.data = r600_bo_map(ctx->radeon, ctx->fences.bo, rctx->ctx.cs,
+                                              PIPE_TRANSFER_UNSYNCHRONIZED | PIPE_TRANSFER_WRITE);
        }
 
        if (!LIST_IS_EMPTY(&ctx->fences.pool)) {
index 2551aa26f2adcf974dc5495ddb0c9327ccaaf3b0..0f226ebd52a9a0da7c0993e26c4ed8b5da56cdb3 100644 (file)
@@ -86,7 +86,7 @@ static int r600_pipe_shader(struct pipe_context *ctx, struct r600_pipe_shader *s
                if (shader->bo == NULL) {
                        return -ENOMEM;
                }
-               ptr = (uint32_t*)r600_bo_map(rctx->radeon, shader->bo, 0, NULL);
+               ptr = (uint32_t*)r600_bo_map(rctx->radeon, shader->bo, rctx->ctx.cs, PIPE_TRANSFER_WRITE);
                if (R600_BIG_ENDIAN) {
                        for (i = 0; i < rshader->bc.ndw; ++i) {
                                ptr[i] = bswap_32(rshader->bc.bytecode[i]);
index 386d8f3501564746beb1bd3d50791547b511d1c8..f9f0d70200876dbb97823c54201861ab263320ae 100644 (file)
@@ -682,10 +682,11 @@ void r600_texture_transfer_destroy(struct pipe_context *ctx,
 void* r600_texture_transfer_map(struct pipe_context *ctx,
                                struct pipe_transfer* transfer)
 {
+       struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx;
        struct r600_transfer *rtransfer = (struct r600_transfer*)transfer;
        struct r600_bo *bo;
        enum pipe_format format = transfer->resource->format;
-       struct radeon *radeon = ((struct r600_screen*)ctx->screen)->radeon;
+       struct radeon *radeon = rctx->screen->radeon;
        unsigned offset = 0;
        char *map;
 
@@ -704,7 +705,7 @@ void* r600_texture_transfer_map(struct pipe_context *ctx,
                        transfer->box.x / util_format_get_blockwidth(format) * util_format_get_blocksize(format);
        }
 
-       if (!(map = r600_bo_map(radeon, bo, transfer->usage, ctx))) {
+       if (!(map = r600_bo_map(radeon, bo, rctx->ctx.cs, transfer->usage))) {
                return NULL;
        }
 
index 0b2a9aabac37dd2e9c452983bfb2bf65bf0ab26b..184efcc0e9a6a3d266de53bc6d3c9370e57ea656 100644 (file)
@@ -107,48 +107,14 @@ struct r600_bo *r600_bo_handle(struct radeon *radeon, struct winsys_handle *whan
        return bo;
 }
 
-void *r600_bo_map(struct radeon *radeon, struct r600_bo *bo, unsigned usage, void *ctx)
+void *r600_bo_map(struct radeon *radeon, struct r600_bo *bo, struct radeon_winsys_cs *cs, unsigned usage)
 {
-       struct pipe_context *pctx = ctx;
-
-       if (usage & PIPE_TRANSFER_UNSYNCHRONIZED) {
-               radeon_bo_map(radeon, bo->bo);
-               return (uint8_t *) bo->bo->data;
-       }
-
-       if (p_atomic_read(&bo->bo->reference.count) > 1) {
-               if (usage & PIPE_TRANSFER_DONTBLOCK) {
-                       return NULL;
-               }
-               if (ctx) {
-                        pctx->flush(pctx, NULL);
-               }
-       }
-
-       if (usage & PIPE_TRANSFER_DONTBLOCK) {
-               uint32_t domain;
-
-               if (radeon_bo_busy(radeon, bo->bo, &domain))
-                       return NULL;
-               if (radeon_bo_map(radeon, bo->bo)) {
-                       return NULL;
-               }
-               goto out;
-       }
-
-       radeon_bo_map(radeon, bo->bo);
-       if (radeon_bo_wait(radeon, bo->bo)) {
-               radeon_bo_unmap(radeon, bo->bo);
-               return NULL;
-       }
-
-out:
-       return (uint8_t *) bo->bo->data;
+       return radeon->ws->buffer_map(bo->bo->buf, cs, usage);
 }
 
 void r600_bo_unmap(struct radeon *radeon, struct r600_bo *bo)
 {
-       radeon_bo_unmap(radeon, bo->bo);
+       radeon->ws->buffer_unmap(bo->bo->buf);
 }
 
 void r600_bo_destroy(struct radeon *radeon, struct r600_bo *bo)
index 760bfc591c0bbf43c04856e19aaf7d66794b21b3..0ebb5ed0385d59bf9f72433f3d42ff04e8391128 100644 (file)
@@ -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);
@@ -92,7 +92,7 @@ void r600_get_backend_mask(struct r600_context *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 */
@@ -1576,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;
 
@@ -1646,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);
index 952f91df89a1f62bcf4979686063b918977c217e..90860f4e31bcc2ecf31b1c1a7aff2301b1f806d6 100644 (file)
@@ -66,8 +66,6 @@ struct radeon_bo {
        struct radeon_winsys_cs_handle  *cs_buf;
        unsigned                        handle;
        unsigned                        size;
-       int                             map_count;
-       void                            *data;
 
        unsigned                        last_flush;
        unsigned                        binding;
@@ -92,9 +90,6 @@ struct radeon_bo *radeon_bo(struct radeon *radeon, unsigned handle,
                            unsigned size, unsigned alignment, unsigned bind, unsigned initial_domain);
 void radeon_bo_reference(struct radeon *radeon, struct radeon_bo **dst,
                         struct radeon_bo *src);
-int radeon_bo_wait(struct radeon *radeon, struct radeon_bo *bo);
-int radeon_bo_busy(struct radeon *radeon, struct radeon_bo *bo, uint32_t *domain);
-int radeon_bo_fixed_map(struct radeon *radeon, struct radeon_bo *bo);
 
 /*
  * r600_hw_context.c
@@ -123,8 +118,8 @@ static INLINE unsigned r600_context_bo_reloc(struct r600_context *ctx, struct r6
 
        assert(bo != NULL);
 
-       reloc_index =
-               ctx->radeon->ws->cs_add_reloc(ctx->cs, bo->cs_buf, rbo->domains, rbo->domains);
+       reloc_index = ctx->radeon->ws->cs_add_reloc(ctx->cs, bo->cs_buf,
+                                                   rbo->domains, rbo->domains);
 
        if (reloc_index >= ctx->creloc)
                ctx->creloc = reloc_index+1;
@@ -138,22 +133,4 @@ static INLINE unsigned r600_context_bo_reloc(struct r600_context *ctx, struct r6
  */
 void r600_bo_destroy(struct radeon *radeon, struct r600_bo *bo);
 
-
-/*
- * radeon_bo.c
- */
-static inline int radeon_bo_map(struct radeon *radeon, struct radeon_bo *bo)
-{
-       if (bo->map_count == 0 && !bo->data)
-               return radeon_bo_fixed_map(radeon, bo);
-       bo->map_count++;
-       return 0;
-}
-
-static inline void radeon_bo_unmap(struct radeon *radeon, struct radeon_bo *bo)
-{
-       bo->map_count--;
-       assert(bo->map_count >= 0);
-}
-
 #endif
index f2f53a14a58f7a49628a6ebf4547cce3306cb0e7..14f8d340d67cfe1f5560bb79713531cbd269239b 100644 (file)
 #include <sys/mman.h>
 #include <errno.h>
 
-int radeon_bo_fixed_map(struct radeon *radeon, struct radeon_bo *bo)
-{
-       struct drm_radeon_gem_mmap args;
-       void *ptr;
-       int r;
-
-       /* Zero out args to make valgrind happy */
-       memset(&args, 0, sizeof(args));
-       args.handle = bo->handle;
-       args.offset = 0;
-       args.size = (uint64_t)bo->size;
-       r = drmCommandWriteRead(radeon->info.fd, DRM_RADEON_GEM_MMAP,
-                               &args, sizeof(args));
-       if (r) {
-               fprintf(stderr, "error mapping %p 0x%08X (error = %d)\n",
-                       bo, bo->handle, r);
-               return r;
-       }
-       ptr = mmap(0, args.size, PROT_READ|PROT_WRITE, MAP_SHARED, radeon->info.fd, args.addr_ptr);
-       if (ptr == MAP_FAILED) {
-               fprintf(stderr, "%s failed to map bo\n", __func__);
-               return -errno;
-       }
-       bo->data = ptr;
-
-       bo->map_count++;
-       return 0;
-}
-
-static void radeon_bo_fixed_unmap(struct radeon *radeon, struct radeon_bo *bo)
-{
-       if (bo->data) {
-               munmap(bo->data, bo->size);
-               bo->data = NULL;
-       }
-}
-
 #include "state_tracker/drm_driver.h"
 
 struct radeon_bo *radeon_bo(struct radeon *radeon, unsigned handle,
@@ -102,7 +65,6 @@ struct radeon_bo *radeon_bo(struct radeon *radeon, unsigned handle,
 
 static void radeon_bo_destroy(struct radeon *radeon, struct radeon_bo *bo)
 {
-       radeon_bo_fixed_unmap(radeon, bo);
        pb_reference(&bo->buf, NULL);
        FREE(bo);
 }
@@ -117,34 +79,3 @@ void radeon_bo_reference(struct radeon *radeon,
        }
        *dst = src;
 }
-
-int radeon_bo_wait(struct radeon *radeon, struct radeon_bo *bo)
-{
-       struct drm_radeon_gem_wait_idle args;
-       int ret;
-
-       /* Zero out args to make valgrind happy */
-       memset(&args, 0, sizeof(args));
-       args.handle = bo->handle;
-       do {
-               ret = drmCommandWriteRead(radeon->info.fd, DRM_RADEON_GEM_WAIT_IDLE,
-                                       &args, sizeof(args));
-       } while (ret == -EBUSY);
-       return ret;
-}
-
-int radeon_bo_busy(struct radeon *radeon, struct radeon_bo *bo, uint32_t *domain)
-{
-       struct drm_radeon_gem_busy args;
-       int ret;
-
-       memset(&args, 0, sizeof(args));
-       args.handle = bo->handle;
-       args.domain = 0;
-
-       ret = drmCommandWriteRead(radeon->info.fd, DRM_RADEON_GEM_BUSY,
-                       &args, sizeof(args));
-
-       *domain = args.domain;
-       return ret;
-}