r600g: move constant buffer creation behind winsys abstraction.
authorDave Airlie <airlied@redhat.com>
Fri, 17 Sep 2010 02:47:49 +0000 (12:47 +1000)
committerDave Airlie <airlied@redhat.com>
Fri, 17 Sep 2010 05:29:31 +0000 (15:29 +1000)
this paves the way for moving to pb bufmgrs now.

12 files changed:
src/gallium/drivers/r600/r600_blit.c
src/gallium/drivers/r600/r600_buffer.c
src/gallium/drivers/r600/r600_query.c
src/gallium/drivers/r600/r600_resource.h
src/gallium/drivers/r600/r600_screen.c
src/gallium/drivers/r600/r600_shader.c
src/gallium/drivers/r600/r600_texture.c
src/gallium/drivers/r600/radeon.h
src/gallium/winsys/r600/drm/radeon.c
src/gallium/winsys/r600/drm/radeon_ctx.c
src/gallium/winsys/r600/drm/radeon_priv.h
src/gallium/winsys/r600/drm/radeon_ws_bo.c

index 0e061c25f779d32d840abdfc3c0683a8ae433dc8..54fbc50bbc4fe0e680f870d410f82c5d98a50e4a 100644 (file)
@@ -179,11 +179,11 @@ static int r600_blit_state_vs_resources(struct r600_screen *rscreen, struct r600
        };
 
        /* simple shader */
-       bo = radeon_ws_bo(rscreen->rw, 128, 4096);
+       bo = radeon_ws_bo(rscreen->rw, 128, 4096, 0);
        if (bo == NULL) {
                return -ENOMEM;
        }
-       data = radeon_ws_bo_map(rscreen->rw, bo);
+       data = radeon_ws_bo_map(rscreen->rw, bo, 0, NULL);
        if (!data) {
                radeon_ws_bo_reference(rscreen->rw, &bo, NULL);
                return -ENOMEM;
@@ -274,11 +274,11 @@ static void r600_blit_state_vs_shader(struct r600_screen *rscreen, struct radeon
        };
 
        /* simple shader */
-       bo = radeon_ws_bo(rscreen->rw, 128, 4096);
+       bo = radeon_ws_bo(rscreen->rw, 128, 4096, 0);
        if (bo == NULL) {
                return;
        }
-       data = radeon_ws_bo_map(rscreen->rw, bo);
+       data = radeon_ws_bo_map(rscreen->rw, bo, 0, NULL);
        if (!data) {
                radeon_ws_bo_reference(rscreen->rw, &bo, NULL);
                return;
@@ -338,11 +338,11 @@ static void r600_blit_state_ps_shader(struct r600_screen *rscreen, struct radeon
        };
 
        /* simple shader */
-       bo = radeon_ws_bo(rscreen->rw, 128, 4096);
+       bo = radeon_ws_bo(rscreen->rw, 128, 4096, 0);
        if (bo == NULL) {
                return;
        }
-       data = radeon_ws_bo_map(rscreen->rw, bo);
+       data = radeon_ws_bo_map(rscreen->rw, bo, 0, NULL);
        if (!data) {
                radeon_ws_bo_reference(rscreen->rw, &bo, NULL);
                return;
index 37abf42d34f13f3f73ca7e07e9249839ec19af73..a38c013e1674b8d5caa5b2f042f587405ec3fcd8 100644 (file)
@@ -69,7 +69,6 @@ struct pipe_resource *r600_buffer_create(struct pipe_screen *screen,
        struct r600_screen *rscreen = r600_screen(screen);
        struct r600_resource *rbuffer;
        struct radeon_ws_bo *bo;
-       struct pb_desc desc;
        /* XXX We probably want a different alignment for buffers and textures. */
        unsigned alignment = 4096;
 
@@ -82,19 +81,8 @@ struct pipe_resource *r600_buffer_create(struct pipe_screen *screen,
        rbuffer->base.b.screen = screen;
        rbuffer->base.vtbl = &r600_buffer_vtbl;
        rbuffer->size = rbuffer->base.b.width0;
-       if ((rscreen->use_mem_constant == FALSE) && (rbuffer->base.b.bind & PIPE_BIND_CONSTANT_BUFFER)) {
-               desc.alignment = alignment;
-               desc.usage = rbuffer->base.b.bind;
-               rbuffer->pb = pb_malloc_buffer_create(rbuffer->base.b.width0,
-                                                     &desc);
-               if (rbuffer->pb == NULL) {
-                       free(rbuffer);
-                       return NULL;
-               }
-               return &rbuffer->base.b;
-       }
        rbuffer->domain = r600_domain_from_usage(rbuffer->base.b.bind);
-       bo = radeon_ws_bo(rscreen->rw, rbuffer->base.b.width0, alignment);
+       bo = radeon_ws_bo(rscreen->rw, rbuffer->base.b.width0, alignment, rbuffer->base.b.bind);
        if (bo == NULL) {
                FREE(rbuffer);
                return NULL;
@@ -125,7 +113,7 @@ struct pipe_resource *r600_user_buffer_create(struct pipe_screen *screen,
        if (rbuffer == NULL) {
                return NULL;
        }
-       data = radeon_ws_bo_map(rscreen->rw, rbuffer->bo);
+       data = radeon_ws_bo_map(rscreen->rw, rbuffer->bo, 0, NULL);
        memcpy(data, ptr, bytes);
        radeon_ws_bo_unmap(rscreen->rw, rbuffer->bo);
        return &rbuffer->base.b;
@@ -137,15 +125,9 @@ static void r600_buffer_destroy(struct pipe_screen *screen,
        struct r600_resource *rbuffer = (struct r600_resource*)buf;
        struct r600_screen *rscreen = r600_screen(screen);
 
-       if (rbuffer->pb) {
-               pipe_reference_init(&rbuffer->pb->base.reference, 0);
-               pb_destroy(rbuffer->pb);
-               rbuffer->pb = NULL;
-       }
        if (rbuffer->bo) {
                radeon_ws_bo_reference(rscreen->rw, &rbuffer->bo, NULL);
        }
-       memset(rbuffer, 0, sizeof(struct r600_resource));
        FREE(rbuffer);
 }
 
@@ -157,16 +139,13 @@ static void *r600_buffer_transfer_map(struct pipe_context *pipe,
        int write = 0;
        uint8_t *data;
 
-       if (rbuffer->pb) {
-               return (uint8_t*)pb_map(rbuffer->pb, transfer->usage, NULL) + transfer->box.x;
-       }
        if (transfer->usage & PIPE_TRANSFER_DONTBLOCK) {
                /* FIXME */
        }
        if (transfer->usage & PIPE_TRANSFER_WRITE) {
                write = 1;
        }
-       data = radeon_ws_bo_map(rscreen->rw, rbuffer->bo);
+       data = radeon_ws_bo_map(rscreen->rw, rbuffer->bo, transfer->usage, r600_context(pipe));
        if (!data)
                return NULL;
 
@@ -179,11 +158,7 @@ static void r600_buffer_transfer_unmap(struct pipe_context *pipe,
        struct r600_resource *rbuffer = (struct r600_resource*)transfer->resource;
        struct r600_screen *rscreen = r600_screen(pipe->screen);
 
-       if (rbuffer->pb) {
-               pb_unmap(rbuffer->pb);
-       } else {
-               radeon_ws_bo_unmap(rscreen->rw, rbuffer->bo);
-       }
+       radeon_ws_bo_unmap(rscreen->rw, rbuffer->bo);
 }
 
 static void r600_buffer_transfer_flush_region(struct pipe_context *pipe,
index 922d7ace1307550fa2e71734378b7db158de1722..12900cce1145c9455b17ac91c30d47c90b6e5481 100644 (file)
@@ -79,7 +79,7 @@ static struct pipe_query *r600_create_query(struct pipe_context *ctx, unsigned q
        q->type = query_type;
        q->buffer_size = 4096;
 
-       q->buffer = radeon_ws_bo(rscreen->rw, q->buffer_size, 1);
+       q->buffer = radeon_ws_bo(rscreen->rw, q->buffer_size, 1, 0);
        if (!q->buffer) {
                FREE(q);
                return NULL;
@@ -109,7 +109,7 @@ static void r600_query_result(struct pipe_context *ctx, struct r600_query *rquer
        int i;
 
        radeon_ws_bo_wait(rscreen->rw, rquery->buffer);
-       results = radeon_ws_bo_map(rscreen->rw, rquery->buffer);
+       results = radeon_ws_bo_map(rscreen->rw, rquery->buffer, 0, r600_context(ctx));
        for (i = 0; i < rquery->num_results; i += 4) {
                start = (u64)results[i] | (u64)results[i + 1] << 32;
                end = (u64)results[i + 2] | (u64)results[i + 3] << 32;
index 8a110b1b72a1d8c3f8a44854ff536552752d957e..ff05afbc30217b081569c2511305920dc585a724 100644 (file)
@@ -37,7 +37,6 @@ struct r600_resource {
        struct radeon_ws_bo             *bo;
        u32                             domain;
        u32                             flink;
-       struct pb_buffer                *pb;
        u32                             size;
 };
 
index 19d1005e77183d9371d55482588acd607ae25602..1d8612c21d45c2f12476f9af8fd4e24b20e578cf 100644 (file)
@@ -277,6 +277,7 @@ struct pipe_screen *r600_screen_create(struct radeon *rw)
                FREE(rscreen);
                return NULL;
        }
+       radeon_set_mem_constant(rw, rscreen->use_mem_constant);
        rscreen->rw = rw;
        rscreen->screen.winsys = (struct pipe_winsys*)rw;
        rscreen->screen.destroy = r600_destroy_screen;
index 10f6d016a388c3bb44fc38010e2b8289b205d707..4da6850b0a943f4a9d7670c7aa2d0b22bd131ace 100644 (file)
@@ -163,11 +163,11 @@ static int r600_pipe_shader(struct pipe_context *ctx, struct r600_context_state
        radeon_ws_bo_reference(rscreen->rw, &rpshader->bo, NULL);
        rpshader->bo = NULL;
        rpshader->bo = radeon_ws_bo(rscreen->rw, rshader->bc.ndw * 4,
-                                   4096);
+                                   4096, 0);
        if (rpshader->bo == NULL) {
                return -ENOMEM;
        }
-       data = radeon_ws_bo_map(rscreen->rw, rpshader->bo);
+       data = radeon_ws_bo_map(rscreen->rw, rpshader->bo, 0, rctx);
        memcpy(data, rshader->bc.bytecode, rshader->bc.ndw * 4);
        radeon_ws_bo_unmap(rscreen->rw, rpshader->bo);
        /* build state */
index 4fa8cf4709950dfe9cedb2b9c748b1d3aa372b4a..efc5f820659e628ab8549092ef21a846e870c567 100644 (file)
@@ -121,7 +121,7 @@ struct pipe_resource *r600_texture_create(struct pipe_screen *screen,
        /* FIXME alignment 4096 enought ? too much ? */
        resource->domain = r600_domain_from_usage(resource->base.b.bind);
        resource->size = rtex->size;
-       resource->bo = radeon_ws_bo(radeon, rtex->size, 4096);
+       resource->bo = radeon_ws_bo(radeon, rtex->size, 4096, 0);
        if (resource->bo == NULL) {
                FREE(rtex);
                return NULL;
@@ -344,7 +344,7 @@ void* r600_texture_transfer_map(struct pipe_context *ctx,
                        transfer->box.y / util_format_get_blockheight(format) * transfer->stride +
                        transfer->box.x / util_format_get_blockwidth(format) * util_format_get_blocksize(format);
        }
-       map = radeon_ws_bo_map(radeon, bo);
+       map = radeon_ws_bo_map(radeon, bo, 0, r600_context(ctx));
        if (!map) {
                return NULL;
        }
@@ -655,7 +655,7 @@ int r600_texture_from_depth(struct pipe_context *ctx, struct r600_resource_textu
 
        /* allocate uncompressed texture */
        if (rtexture->uncompressed == NULL) {
-               rtexture->uncompressed = radeon_ws_bo(rscreen->rw, rtexture->size, 4096);
+               rtexture->uncompressed = radeon_ws_bo(rscreen->rw, rtexture->size, 4096, 0);
                if (rtexture->uncompressed == NULL) {
                        return -ENOMEM;
                }
index be28ad19ff6aad5e64f62fbcf9d57ff15fa1c268..36bfb747b5124ec2aeef06a1fc48157a9699b298 100644 (file)
@@ -21,6 +21,8 @@
 
 #include <stdint.h>
 
+#include <pipe/p_compiler.h>
+
 typedef uint64_t               u64;
 typedef uint32_t               u32;
 typedef uint16_t               u16;
@@ -86,14 +88,15 @@ enum {
 };
 
 enum radeon_family radeon_get_family(struct radeon *rw);
+void radeon_set_mem_constant(struct radeon *radeon, boolean state);
 
 /* lowlevel WS bo */
 struct radeon_ws_bo;
 struct radeon_ws_bo *radeon_ws_bo(struct radeon *radeon,
-                                 unsigned size, unsigned alignment);
+                                 unsigned size, unsigned alignment, unsigned usage);
 struct radeon_ws_bo *radeon_ws_bo_handle(struct radeon *radeon,
                                         unsigned handle);
-void *radeon_ws_bo_map(struct radeon *radeon, struct radeon_ws_bo *bo);
+void *radeon_ws_bo_map(struct radeon *radeon, struct radeon_ws_bo *bo, unsigned usage, void *ctx);
 void radeon_ws_bo_unmap(struct radeon *radeon, struct radeon_ws_bo *bo);
 void radeon_ws_bo_reference(struct radeon *radeon, struct radeon_ws_bo **dst,
                            struct radeon_ws_bo *src);
index ccf60605ed85754ad497b165e5db87d84431d0d4..2135b07ab639f781b3c44709726b22f90c6b992f 100644 (file)
@@ -29,6 +29,11 @@ enum radeon_family radeon_get_family(struct radeon *radeon)
        return radeon->family;
 }
 
+void radeon_set_mem_constant(struct radeon *radeon, boolean state)
+{
+       radeon->use_mem_constant = state;
+}
+
 static int radeon_get_device(struct radeon *radeon)
 {
        struct drm_radeon_info info;
index d6e58451b85fd5c7a1c025cd9fcafb6d7e0212a7..a57163be03e0d3e8bbfc99e7c5af16f5e0ff50f8 100644 (file)
@@ -360,7 +360,7 @@ void radeon_ctx_dump_bof(struct radeon_ctx *ctx, const char *file)
                        goto out_err;
                bof_decref(handle);
                handle = NULL;
-               data = radeon_ws_bo_map(ctx->radeon, ctx->bo[i]);
+               data = radeon_ws_bo_map(ctx->radeon, ctx->bo[i], 0, NULL);
                blob = bof_blob(ctx->bo[i]->bo->size, data);
                radeon_ws_bo_unmap(ctx->radeon, ctx->bo[i]);
                if (blob == NULL)
index 6bd8d9850f50e05ce7f13b2cd50e301e09f30bb2..49fe1a6ead1fcb04acfd409440a5dfd4a735bf9b 100644 (file)
@@ -86,11 +86,13 @@ struct radeon {
        unsigned                        nstype;
        struct radeon_stype_info        *stype;
        unsigned max_states;
+       boolean use_mem_constant; /* true for evergreen */
 };
 
 struct radeon_ws_bo {
        struct pipe_reference reference;
        struct radeon_bo *bo;
+       struct pb_buffer *pb;
 };
 
 extern struct radeon *radeon_new(int fd, unsigned device);
index c789f8780f9652131ed4def289eb423ba2e538ff..422e298a8dba5ebd7b53873d28268df889f48c84 100644 (file)
@@ -1,15 +1,28 @@
 #include <malloc.h>
+#include <pipe/p_screen.h>
+#include <pipebuffer/pb_bufmgr.h>
 #include "radeon_priv.h"
 
 struct radeon_ws_bo *radeon_ws_bo(struct radeon *radeon,
-                                 unsigned size, unsigned alignment)
+                                 unsigned size, unsigned alignment, unsigned usage)
 {
        struct radeon_ws_bo *ws_bo = calloc(1, sizeof(struct radeon_ws_bo));
+       struct pb_desc desc;
 
-       ws_bo->bo = radeon_bo(radeon, 0, size, alignment, NULL);
-       if (!ws_bo->bo) {
-               free(ws_bo);
-               return NULL;
+       if (radeon->use_mem_constant && (usage & PIPE_BIND_CONSTANT_BUFFER)) {
+               desc.alignment = alignment;
+               desc.usage = usage;
+               ws_bo->pb = pb_malloc_buffer_create(size, &desc);
+               if (ws_bo->pb == NULL) {
+                       free(ws_bo);
+                       return NULL;
+               }
+       } else {
+               ws_bo->bo = radeon_bo(radeon, 0, size, alignment, NULL);
+               if (!ws_bo->bo) {
+                       free(ws_bo);
+                       return NULL;
+               }
        }
 
        pipe_reference_init(&ws_bo->reference, 1);
@@ -30,20 +43,28 @@ struct radeon_ws_bo *radeon_ws_bo_handle(struct radeon *radeon,
        return ws_bo;
 }
 
-void *radeon_ws_bo_map(struct radeon *radeon, struct radeon_ws_bo *bo)
+void *radeon_ws_bo_map(struct radeon *radeon, struct radeon_ws_bo *bo, unsigned usage, void *ctx)
 {
+       if (bo->pb)
+               return pb_map(bo->pb, usage, ctx);
        radeon_bo_map(radeon, bo->bo);
        return bo->bo->data;
 }
 
 void radeon_ws_bo_unmap(struct radeon *radeon, struct radeon_ws_bo *bo)
 {
-       radeon_bo_unmap(radeon, bo->bo);
+       if (bo->pb)
+               pb_unmap(bo->pb);
+       else
+               radeon_bo_unmap(radeon, bo->bo);
 }
 
 static void radeon_ws_bo_destroy(struct radeon *radeon, struct radeon_ws_bo *bo)
 {
-       radeon_bo_reference(radeon, &bo->bo, NULL);
+       if (bo->pb)
+               pb_reference(&bo->pb, NULL);
+       else
+               radeon_bo_reference(radeon, &bo->bo, NULL);
        free(bo);
 }
 
@@ -51,6 +72,7 @@ void radeon_ws_bo_reference(struct radeon *radeon, struct radeon_ws_bo **dst,
                            struct radeon_ws_bo *src)
 {
        struct radeon_ws_bo *old = *dst;
+               
        if (pipe_reference(&(*dst)->reference, &src->reference)) {
                radeon_ws_bo_destroy(radeon, old);
        }
@@ -59,5 +81,8 @@ void radeon_ws_bo_reference(struct radeon *radeon, struct radeon_ws_bo **dst,
 
 int radeon_ws_bo_wait(struct radeon *radeon, struct radeon_ws_bo *bo)
 {
-       return radeon_bo_wait(radeon, bo->bo);
+       if (bo->pb)
+               return 0;
+       else
+               return radeon_bo_wait(radeon, bo->bo);
 }