r300g: let the driver determine the GEM domain for buffer_create
authorMarek Olšák <maraeo@gmail.com>
Wed, 2 Jun 2010 03:50:58 +0000 (05:50 +0200)
committerMarek Olšák <maraeo@gmail.com>
Wed, 2 Jun 2010 04:01:22 +0000 (06:01 +0200)
src/gallium/drivers/r300/r300_defines.h
src/gallium/drivers/r300/r300_screen_buffer.c
src/gallium/drivers/r300/r300_texture.c
src/gallium/drivers/r300/r300_winsys.h
src/gallium/winsys/radeon/drm/radeon_buffer.h
src/gallium/winsys/radeon/drm/radeon_drm_buffer.c
src/gallium/winsys/radeon/drm/radeon_r300.c

index 4b1c37072688e0981360fb77fe1b8a6eeac2ea34..83c9ec7e399f0def33ebe2ca39d1e80764310ae1 100644 (file)
@@ -45,4 +45,9 @@ enum r300_buffer_tiling {
     R300_BUFFER_SQUARETILED
 };
 
+enum r300_buffer_domain { /* bitfield */
+    R300_DOMAIN_GTT  = 1,
+    R300_DOMAIN_VRAM = 2
+};
+
 #endif
index 3e2b5afe6f439da74b512f62ffc6a63fd6abcc08..de89f51f3eb59198fbd754ac0b6f28892333e2a6 100644 (file)
@@ -125,7 +125,7 @@ r300_winsys_buffer_create(struct r300_screen *r300screen,
     struct r300_winsys_screen *rws = r300screen->rws;
     struct r300_winsys_buffer *buf;
 
-    buf = rws->buffer_create(rws, alignment, usage, size);
+    buf = rws->buffer_create(rws, alignment, usage, R300_DOMAIN_GTT, size);
     return buf;
 }
 
index a4b5d34ce1f8765b2ba8511a24e254b168b18e9c..8572334f912e661d98c7bf93394fb8e61c60afcf 100644 (file)
@@ -959,9 +959,9 @@ struct pipe_resource* r300_texture_create(struct pipe_screen* screen,
                base->width0, base->height0, base->depth0, base->last_level,
                util_format_short_name(base->format));
 
-    tex->buffer = rws->buffer_create(rws, 2048,
-                                     base->bind,
+    tex->buffer = rws->buffer_create(rws, 2048, base->bind, R300_DOMAIN_VRAM,
                                     tex->size);
+
     rws->buffer_set_tiling(rws, tex->buffer,
             tex->pitch[0] * util_format_get_blocksize(tex->b.b.format),
             tex->microtile,
index f7cbbde410a0402efd826ead4c0672fc5255fbd9..d59a45a00a9d94c041ab3df14bc9fa379617e589 100644 (file)
@@ -74,8 +74,9 @@ struct r300_winsys_screen {
     struct r300_winsys_buffer *(*buffer_create)(struct r300_winsys_screen *ws,
                                                unsigned alignment,
                                                unsigned usage,
+                                                enum r300_buffer_domain domain,
                                                unsigned size);
-    
+
     /**
      * Map the entire data store of a buffer object into the client's address.
      * flags is bitmask of R300_WINSYS_BUFFER_USAGE_CPU_READ/WRITE flags.
index b9ecf9ded071e9c80265f2ad93e16cb701297642..da13e4d36a4b3d7a4d6b8b71a3c760ddc25a470a 100644 (file)
@@ -43,6 +43,8 @@
 
 #include "radeon_winsys.h"
 
+#define RADEON_USAGE_DOMAIN_GTT  (1 << 29)
+#define RADEON_USAGE_DOMAIN_VRAM (1 << 30)
 
 #define RADEON_MAX_BOS 24
 
index a05205da8861fc4e76290e5ebcae62cbdac8be18..efe82026b431e8d3539dc41d21e5f5d5275c7d14 100644 (file)
@@ -145,31 +145,6 @@ const struct pb_vtbl radeon_drm_buffer_vtbl = {
     radeon_drm_buffer_get_base_buffer,
 };
 
-
-static uint32_t radeon_domain_from_usage(unsigned usage)
-{
-    uint32_t domain = 0;
-
-    if (usage & PIPE_BIND_RENDER_TARGET) {
-        domain |= RADEON_GEM_DOMAIN_VRAM;
-    }
-    if (usage & PIPE_BIND_DEPTH_STENCIL) {
-        domain |= RADEON_GEM_DOMAIN_VRAM;
-    }
-    if (usage & PIPE_BIND_SAMPLER_VIEW) {
-        domain |= RADEON_GEM_DOMAIN_VRAM;
-    }
-    /* also need BIND_BLIT_SOURCE/DESTINATION ? */
-    if (usage & PIPE_BIND_VERTEX_BUFFER) {
-        domain |= RADEON_GEM_DOMAIN_GTT;
-    }
-    if (usage & PIPE_BIND_INDEX_BUFFER) {
-        domain |= RADEON_GEM_DOMAIN_GTT;
-    }
-
-    return domain;
-}
-
 struct pb_buffer *radeon_drm_bufmgr_create_buffer_from_handle(struct pb_manager *_mgr,
                                                              uint32_t handle)
 {
@@ -225,7 +200,11 @@ radeon_drm_bufmgr_create_buffer(struct pb_manager *_mgr,
     buf->mgr = mgr;
 
     make_empty_list(buf);
-    domain = radeon_domain_from_usage(desc->usage);
+
+    domain =
+        (desc->usage & RADEON_USAGE_DOMAIN_GTT  ? RADEON_GEM_DOMAIN_GTT  : 0) |
+        (desc->usage & RADEON_USAGE_DOMAIN_VRAM ? RADEON_GEM_DOMAIN_VRAM : 0);
+
     buf->bo = radeon_bo_open(rws->bom, 0, size,
                             desc->alignment, domain, 0);
     if (buf->bo == NULL)
index ecee1ee73db046ed536bccc9cdfb0d02d2fcd455..4cf21ff72bfe9c2a1cf08d86e389485b0609f156 100644 (file)
@@ -31,6 +31,7 @@ static struct r300_winsys_buffer *
 radeon_r300_winsys_buffer_create(struct r300_winsys_screen *rws,
                                 unsigned alignment,
                                 unsigned usage,
+                                 enum r300_buffer_domain domain,
                                 unsigned size)
 {
     struct radeon_libdrm_winsys *ws = radeon_winsys_screen(rws);
@@ -38,6 +39,14 @@ radeon_r300_winsys_buffer_create(struct r300_winsys_screen *rws,
     struct pb_manager *provider;
     struct pb_buffer *buffer;
 
+    /* XXX this is hackish, but it's the only way to pass these flags
+     * to the real create function. */
+    usage &= ~(RADEON_USAGE_DOMAIN_GTT | RADEON_USAGE_DOMAIN_VRAM);
+    if (domain & R300_DOMAIN_GTT)
+        usage |= RADEON_USAGE_DOMAIN_GTT;
+    if (domain & R300_DOMAIN_VRAM)
+        usage |= RADEON_USAGE_DOMAIN_VRAM;
+
     memset(&desc, 0, sizeof(desc));
     desc.alignment = alignment;
     desc.usage = usage;