r600g: allocate/destroy buffers using radeon_winsys
authorMarek Olšák <maraeo@gmail.com>
Tue, 2 Aug 2011 23:03:13 +0000 (01:03 +0200)
committerMarek Olšák <maraeo@gmail.com>
Tue, 16 Aug 2011 07:15:10 +0000 (09:15 +0200)
We use the cache buffer manager from radeon_winsys now, but we don't use
anything else yet.

Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
src/gallium/winsys/r600/drm/r600_bo.c
src/gallium/winsys/r600/drm/r600_drm.c
src/gallium/winsys/r600/drm/r600_priv.h
src/gallium/winsys/r600/drm/radeon_bo.c
src/gallium/winsys/radeon/drm/radeon_drm_bo.c
src/gallium/winsys/radeon/drm/radeon_winsys.h

index 9e6c7cc7639417aab9001de0f67491795fbe9b02..8cf1d809235181ead1d9e2aa1902af7425017fd9 100644 (file)
@@ -68,7 +68,7 @@ struct r600_bo *r600_bo(struct radeon *radeon,
                initial_domain = RADEON_GEM_DOMAIN_VRAM;
                break;
        }
-       rbo = radeon_bo(radeon, 0, size, alignment, initial_domain);
+       rbo = radeon_bo(radeon, 0, size, alignment, binding, initial_domain);
        if (rbo == NULL) {
                return NULL;
        }
@@ -93,7 +93,7 @@ struct r600_bo *r600_bo_handle(struct radeon *radeon, struct winsys_handle *whan
        struct radeon_bo *rbo;
        unsigned tiling_flags;
 
-       rbo = bo->bo = radeon_bo(radeon, whandle->handle, 0, 0, 0);
+       rbo = bo->bo = radeon_bo(radeon, whandle->handle, 0, 0, 0, 0);
        if (rbo == NULL) {
                free(bo);
                return NULL;
index 1cf905f2575f333d1cd04d13732121d2b4adbae2..f2e46d3d0d91f33369df51965ac29c945a61c2d4 100644 (file)
@@ -233,18 +233,6 @@ static int radeon_init_fence(struct radeon *radeon)
        return 0;
 }
 
-#define PTR_TO_UINT(x) ((unsigned)((intptr_t)(x)))
-
-static unsigned handle_hash(void *key)
-{
-    return PTR_TO_UINT(key);
-}
-
-static int handle_compare(void *key1, void *key2)
-{
-    return PTR_TO_UINT(key1) != PTR_TO_UINT(key2);
-}
-
 struct radeon *radeon_create(struct radeon_winsys *ws)
 {
        int r;
@@ -327,8 +315,6 @@ struct radeon *radeon_create(struct radeon_winsys *ws)
                return NULL;
        }
 
-       radeon->bo_handles = util_hash_table_create(handle_hash, handle_compare);
-       pipe_mutex_init(radeon->bo_handles_mutex);
        return radeon;
 }
 
@@ -337,8 +323,6 @@ struct radeon *radeon_destroy(struct radeon *radeon)
        if (radeon == NULL)
                return NULL;
 
-       util_hash_table_destroy(radeon->bo_handles);
-       pipe_mutex_destroy(radeon->bo_handles_mutex);
        if (radeon->fence_bo) {
                r600_bo_reference(radeon, &radeon->fence_bo, NULL);
        }
index ee3df9c93f9a20293a5b4075b373946b19433b46..621c7eb2158b8a707e11347e723ba57a337a98e0 100644 (file)
@@ -50,10 +50,6 @@ struct radeon {
        unsigned                        num_tile_pipes;
        unsigned                        backend_map;
        boolean                         backend_map_valid;
-
-        /* List of buffer handles and its mutex. */
-       struct util_hash_table          *bo_handles;
-       pipe_mutex bo_handles_mutex;
 };
 
 /* these flags are used in register flags and added into block flags */
@@ -75,9 +71,10 @@ struct r600_reg {
 #define BO_BOUND_TEXTURE 1
 struct radeon_bo {
        struct pipe_reference           reference;
+       struct pb_buffer                *buf;
+
        unsigned                        handle;
        unsigned                        size;
-       unsigned                        alignment;
        int                             map_count;
        void                            *data;
        struct list_head                fencedlist;
@@ -87,7 +84,6 @@ struct radeon_bo {
        struct r600_reloc               *reloc;
        unsigned                        reloc_id;
        unsigned                        last_flush;
-       unsigned                        name;
        unsigned                        binding;
 };
 
@@ -124,7 +120,7 @@ unsigned radeon_family_from_device(unsigned device);
  * radeon_bo.c
  */
 struct radeon_bo *radeon_bo(struct radeon *radeon, unsigned handle,
-                           unsigned size, unsigned alignment, unsigned initial_domain);
+                           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);
index 4e61c942a2697e0c0439ec26c61a413a997fe738..7ff4806c056aedfce0e82b405510f0f199c2dfec 100644 (file)
@@ -26,6 +26,7 @@
 #define _FILE_OFFSET_BITS 64
 #include "r600_priv.h"
 #include "util/u_hash_table.h"
+#include "util/u_memory.h"
 #include "radeon_drm.h"
 #include "xf86drm.h"
 #include <sys/mman.h>
@@ -68,22 +69,16 @@ static void radeon_bo_fixed_unmap(struct radeon *radeon, struct radeon_bo *bo)
        }
 }
 
+#include "state_tracker/drm_driver.h"
+
 struct radeon_bo *radeon_bo(struct radeon *radeon, unsigned handle,
-                           unsigned size, unsigned alignment, unsigned initial_domain)
+                           unsigned size, unsigned alignment, unsigned bind,
+                           unsigned initial_domain)
 {
        struct radeon_bo *bo;
-       int r;
+       struct winsys_handle whandle = {};
+       whandle.handle = handle;
 
-       if (handle) {
-               pipe_mutex_lock(radeon->bo_handles_mutex);
-               bo = util_hash_table_get(radeon->bo_handles,
-                                        (void *)(uintptr_t)handle);
-               if (bo) {
-                       struct radeon_bo *b = NULL;
-                       radeon_bo_reference(radeon, &b, bo);
-                       goto done;
-               }
-       }
        bo = calloc(1, sizeof(*bo));
        if (bo == NULL) {
                return NULL;
@@ -91,69 +86,35 @@ struct radeon_bo *radeon_bo(struct radeon *radeon, unsigned handle,
        bo->size = size;
        bo->handle = handle;
        pipe_reference_init(&bo->reference, 1);
-       bo->alignment = alignment;
        LIST_INITHEAD(&bo->fencedlist);
 
        if (handle) {
-               struct drm_gem_open open_arg;
-
-               memset(&open_arg, 0, sizeof(open_arg));
-               open_arg.name = handle;
-               r = drmIoctl(radeon->info.fd, DRM_IOCTL_GEM_OPEN, &open_arg);
-               if (r != 0) {
-                       free(bo);
+               unsigned size;
+               bo->buf = radeon->ws->buffer_from_handle(radeon->ws, &whandle, NULL, &size);
+               if (!bo->buf) {
+                       FREE(bo);
                        return NULL;
                }
-               bo->name = handle;
-               bo->handle = open_arg.handle;
-               bo->size = open_arg.size;
+               bo->handle = radeon->ws->trans_get_buffer_handle(bo->buf);
+               bo->size = size;
                bo->shared = TRUE;
        } else {
-               struct drm_radeon_gem_create args = {};
-
-               args.size = size;
-               args.alignment = alignment;
-               args.initial_domain = initial_domain;
-               args.flags = 0;
-               args.handle = 0;
-               r = drmCommandWriteRead(radeon->info.fd, DRM_RADEON_GEM_CREATE,
-                                       &args, sizeof(args));
-               bo->handle = args.handle;
-               if (r) {
-                       fprintf(stderr, "Failed to allocate :\n");
-                       fprintf(stderr, "   size      : %d bytes\n", size);
-                       fprintf(stderr, "   alignment : %d bytes\n", alignment);
-                       free(bo);
+               bo->buf = radeon->ws->buffer_create(radeon->ws, size, alignment, bind, initial_domain);
+               if (!bo->buf) {
+                       FREE(bo);
                        return NULL;
                }
+               bo->handle = radeon->ws->trans_get_buffer_handle(bo->buf);
        }
-
-       if (handle)
-               util_hash_table_set(radeon->bo_handles, (void *)(uintptr_t)handle, bo);
-done:
-       if (handle)
-               pipe_mutex_unlock(radeon->bo_handles_mutex);
-
        return bo;
 }
 
 static void radeon_bo_destroy(struct radeon *radeon, struct radeon_bo *bo)
 {
-       struct drm_gem_close args;
-
-       if (bo->name) {
-               pipe_mutex_lock(radeon->bo_handles_mutex);
-               util_hash_table_remove(radeon->bo_handles,
-                                      (void *)(uintptr_t)bo->name);
-               pipe_mutex_unlock(radeon->bo_handles_mutex);
-       }
        LIST_DEL(&bo->fencedlist);
        radeon_bo_fixed_unmap(radeon, bo);
-       memset(&args, 0, sizeof(args));
-       args.handle = bo->handle;
-       drmIoctl(radeon->info.fd, DRM_IOCTL_GEM_CLOSE, &args);
-       memset(bo, 0, sizeof(struct radeon_bo));
-       free(bo);
+       pb_reference(&bo->buf, NULL);
+       FREE(bo);
 }
 
 void radeon_bo_reference(struct radeon *radeon,
index 609a9065db8decaf01502b800a6a7536acc57c63..58898d3423ed425f51a79b527f4e3e05ac96a937 100644 (file)
@@ -617,6 +617,11 @@ static boolean radeon_winsys_bo_get_handle(struct pb_buffer *buffer,
     return TRUE;
 }
 
+static unsigned trans_get_buffer_handle(struct pb_buffer *buf)
+{
+       return get_radeon_bo(buf)->handle;
+}
+
 void radeon_bomgr_init_functions(struct radeon_drm_winsys *ws)
 {
     ws->base.buffer_get_cs_handle = radeon_drm_get_cs_handle;
@@ -629,4 +634,6 @@ void radeon_bomgr_init_functions(struct radeon_drm_winsys *ws)
     ws->base.buffer_create = radeon_winsys_bo_create;
     ws->base.buffer_from_handle = radeon_winsys_bo_from_handle;
     ws->base.buffer_get_handle = radeon_winsys_bo_get_handle;
+
+    ws->base.trans_get_buffer_handle = trans_get_buffer_handle;
 }
index 2948ea78c18a1d0bd6d5cfbf168111a006bfbcbe..2e5000702e032fef72abb051cb8a3b6ed2a9c59d 100644 (file)
@@ -325,6 +325,10 @@ struct radeon_winsys {
     boolean (*cs_request_feature)(struct radeon_winsys_cs *cs,
                                   enum radeon_feature_id fid,
                                   boolean enable);
+
+
+    /* Transitional functions for r600g when moving to winsys/radeon */
+    unsigned (*trans_get_buffer_handle)(struct pb_buffer *buf);
 };
 
 #endif