r600g: put radeon_winsys in screen::winsys, don't include drm_driver in the pipe
authorMarek Olšák <maraeo@gmail.com>
Tue, 2 Aug 2011 18:25:13 +0000 (20:25 +0200)
committerMarek Olšák <maraeo@gmail.com>
Tue, 16 Aug 2011 07:15:10 +0000 (09:15 +0200)
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
12 files changed:
src/gallium/drivers/r600/r600.h
src/gallium/drivers/r600/r600_buffer.c
src/gallium/drivers/r600/r600_pipe.c
src/gallium/drivers/r600/r600_pipe.h
src/gallium/drivers/r600/r600_public.h
src/gallium/drivers/r600/r600_texture.c
src/gallium/winsys/r600/drm/evergreen_hw_context.c
src/gallium/winsys/r600/drm/r600_bo.c
src/gallium/winsys/r600/drm/r600_drm.c
src/gallium/winsys/r600/drm/r600_drm_public.h
src/gallium/winsys/r600/drm/r600_hw_context.c
src/gallium/winsys/r600/drm/r600_priv.h

index 714af0c112da244401c7dc0c655b022c1dfaa851..7e7047301225b8d8b82f504b820b900ebe6e191b 100644 (file)
@@ -95,11 +95,12 @@ unsigned r600_get_backend_map(struct radeon *radeon);
 
 /* r600_bo.c */
 struct r600_bo;
+
 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,
-                               unsigned handle, unsigned *array_mode);
+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_unmap(struct radeon *radeon, struct r600_bo *bo);
 boolean r600_bo_get_winsys_handle(struct radeon *radeon, struct r600_bo *pb_bo,
@@ -315,7 +316,7 @@ void evergreen_context_pipe_state_set_fs_resource(struct r600_context *ctx, stru
 void evergreen_context_pipe_state_set_ps_sampler(struct r600_context *ctx, struct r600_pipe_state *state, unsigned id);
 void evergreen_context_pipe_state_set_vs_sampler(struct r600_context *ctx, struct r600_pipe_state *state, unsigned id);
 
-struct radeon *radeon_decref(struct radeon *radeon);
+struct radeon *radeon_destroy(struct radeon *radeon);
 
 void _r600_pipe_state_add_reg(struct r600_context *ctx,
                              struct r600_pipe_state *state,
index 72f352df3c34f82f6b11cecc5c1bd93c82d22df3..28d8c6af1cb75c01084e75821867b41a63785215 100644 (file)
@@ -33,8 +33,6 @@
 #include <util/u_memory.h>
 #include "util/u_upload_mgr.h"
 
-#include "state_tracker/drm_driver.h"
-
 #include <xf86drm.h>
 #include "radeon_drm.h"
 
@@ -48,7 +46,7 @@ static void r600_buffer_destroy(struct pipe_screen *screen,
        struct r600_resource_buffer *rbuffer = r600_buffer(buf);
 
        if (rbuffer->r.bo) {
-               r600_bo_reference((struct radeon*)screen->winsys, &rbuffer->r.bo, NULL);
+               r600_bo_reference(rscreen->radeon, &rbuffer->r.bo, NULL);
        }
        rbuffer->r.bo = NULL;
        util_slab_free(&rscreen->pool_buffers, rbuffer);
@@ -81,12 +79,13 @@ static void *r600_buffer_transfer_map(struct pipe_context *pipe,
                                      struct pipe_transfer *transfer)
 {
        struct r600_resource_buffer *rbuffer = r600_buffer(transfer->resource);
+       struct r600_pipe_context *rctx = (struct r600_pipe_context*)pipe;
        uint8_t *data;
 
        if (rbuffer->r.b.user_ptr)
                return (uint8_t*)rbuffer->r.b.user_ptr + transfer->box.x;
 
-       data = r600_bo_map((struct radeon*)pipe->winsys, rbuffer->r.bo, transfer->usage, pipe);
+       data = r600_bo_map(rctx->screen->radeon, rbuffer->r.bo, transfer->usage, pipe);
        if (!data)
                return NULL;
 
@@ -97,12 +96,13 @@ static void r600_buffer_transfer_unmap(struct pipe_context *pipe,
                                        struct pipe_transfer *transfer)
 {
        struct r600_resource_buffer *rbuffer = r600_buffer(transfer->resource);
+       struct r600_pipe_context *rctx = (struct r600_pipe_context*)pipe;
 
        if (rbuffer->r.b.user_ptr)
                return;
 
        if (rbuffer->r.bo)
-               r600_bo_unmap((struct radeon*)pipe->winsys, rbuffer->r.bo);
+               r600_bo_unmap(rctx->screen->radeon, rbuffer->r.bo);
 }
 
 static void r600_buffer_transfer_flush_region(struct pipe_context *pipe,
@@ -127,20 +127,21 @@ static void r600_buffer_transfer_inline_write(struct pipe_context *pipe,
                                                unsigned stride,
                                                unsigned layer_stride)
 {
-       struct radeon *ws = (struct radeon*)pipe->winsys;
+       struct r600_pipe_context *rctx = (struct r600_pipe_context*)pipe;
+       struct radeon *radeon = rctx->screen->radeon;
        struct r600_resource_buffer *rbuffer = r600_buffer(resource);
        uint8_t *map = NULL;
 
        assert(rbuffer->r.b.user_ptr == NULL);
 
-       map = r600_bo_map(ws, rbuffer->r.bo,
+       map = r600_bo_map(radeon, rbuffer->r.bo,
                          PIPE_TRANSFER_WRITE | PIPE_TRANSFER_DISCARD | usage,
                          pipe);
 
        memcpy(map + box->x, data, box->width);
 
        if (rbuffer->r.bo)
-               r600_bo_unmap(ws, rbuffer->r.bo);
+               r600_bo_unmap(radeon, rbuffer->r.bo);
 }
 
 static const struct u_resource_vtbl r600_buffer_vtbl =
@@ -175,7 +176,7 @@ struct pipe_resource *r600_buffer_create(struct pipe_screen *screen,
        rbuffer->r.size = rbuffer->r.b.b.b.width0;
        rbuffer->r.bo_size = rbuffer->r.size;
 
-       bo = r600_bo((struct radeon*)screen->winsys,
+       bo = r600_bo(rscreen->radeon,
                     rbuffer->r.b.b.b.width0,
                     alignment, rbuffer->r.b.b.b.bind,
                     rbuffer->r.b.b.b.usage);
@@ -219,11 +220,11 @@ struct pipe_resource *r600_user_buffer_create(struct pipe_screen *screen,
 struct pipe_resource *r600_buffer_from_handle(struct pipe_screen *screen,
                                              struct winsys_handle *whandle)
 {
-       struct radeon *rw = (struct radeon*)screen->winsys;
+       struct radeon *rw = ((struct r600_screen*)screen)->radeon;
        struct r600_resource *rbuffer;
        struct r600_bo *bo = NULL;
 
-       bo = r600_bo_handle(rw, whandle->handle, NULL);
+       bo = r600_bo_handle(rw, whandle, NULL, NULL);
        if (bo == NULL) {
                return NULL;
        }
index 6181e8b32021c7b9600effce22df279240b3ec89..8a18207d1ea66a61f31de1db2a0416ff830abf55 100644 (file)
@@ -500,7 +500,8 @@ static void r600_destroy_screen(struct pipe_screen* pscreen)
        if (rscreen == NULL)
                return;
 
-       radeon_decref(rscreen->radeon);
+       radeon_destroy(rscreen->radeon);
+       rscreen->ws->destroy(rscreen->ws);
 
        util_slab_destroy(&rscreen->pool_buffers);
        pipe_mutex_destroy(rscreen->mutex_num_contexts);
@@ -564,18 +565,19 @@ static boolean r600_fence_finish(struct pipe_screen *pscreen,
        return TRUE;
 }
 
-struct pipe_screen *r600_screen_create(struct radeon_winsys *rw)
+struct pipe_screen *r600_screen_create(struct radeon_winsys *ws)
 {
        struct r600_screen *rscreen;
-       struct radeon *radeon = r600_drm_winsys_create(rw);
+       struct radeon *radeon = radeon_create(ws);
 
        rscreen = CALLOC_STRUCT(r600_screen);
        if (rscreen == NULL) {
                return NULL;
        }
 
+       rscreen->ws = ws;
        rscreen->radeon = radeon;
-       rscreen->screen.winsys = (struct pipe_winsys*)radeon;
+       rscreen->screen.winsys = (struct pipe_winsys*)ws;
        rscreen->screen.destroy = r600_destroy_screen;
        rscreen->screen.get_name = r600_get_name;
        rscreen->screen.get_vendor = r600_get_vendor;
index c53a191594bd8b6a331a364bedb5d228fe7e5415..3ca003aa2442dd65475d8db0aedeed7a3a4e27fd 100644 (file)
@@ -74,6 +74,7 @@ enum r600_pipe_state_id {
 
 struct r600_screen {
        struct pipe_screen              screen;
+       struct radeon_winsys            *ws;
        struct radeon                   *radeon;
        struct r600_tiling_info         *tiling_info;
        struct util_slab_mempool        pool_buffers;
index 1c82a7af68fac99c6f51f12baa86cd077b870286..e4fe23a87b7a4b5269dbdb391dea9a24d6d072f4 100644 (file)
@@ -25,6 +25,6 @@
 
 struct radeon_winsys;
 
-struct pipe_screen *r600_screen_create(struct radeon_winsys *rw);
+struct pipe_screen *r600_screen_create(struct radeon_winsys *ws);
 
 #endif
index 927eb5dafc9a6502672583749776a47f0326f23d..386d8f3501564746beb1bd3d50791547b511d1c8 100644 (file)
@@ -31,7 +31,6 @@
 #include <util/u_math.h>
 #include <util/u_inlines.h>
 #include <util/u_memory.h>
-#include "state_tracker/drm_driver.h"
 #include "pipebuffer/pb_buffer.h"
 #include "r600_pipe.h"
 #include "r600_resource.h"
@@ -239,7 +238,7 @@ static void r600_setup_miptree(struct pipe_screen *screen,
                               unsigned array_mode)
 {
        struct pipe_resource *ptex = &rtex->resource.b.b.b;
-       struct radeon *radeon = (struct radeon *)screen->winsys;
+       struct radeon *radeon = ((struct r600_screen*)screen)->radeon;
        enum chip_class chipc = r600_get_family_class(radeon);
        unsigned size, layer_size, i, offset;
        unsigned nblocksx, nblocksy, extra_size = 0;
@@ -329,7 +328,7 @@ static boolean r600_texture_get_handle(struct pipe_screen* screen,
 {
        struct r600_resource_texture *rtex = (struct r600_resource_texture*)ptex;
        struct r600_resource *resource = &rtex->resource;
-       struct radeon *radeon = (struct radeon *)screen->winsys;
+       struct radeon *radeon = ((struct r600_screen*)screen)->radeon;
 
        return r600_bo_get_winsys_handle(radeon, resource->bo,
                        rtex->pitch_in_bytes[0], whandle);
@@ -340,7 +339,7 @@ static void r600_texture_destroy(struct pipe_screen *screen,
 {
        struct r600_resource_texture *rtex = (struct r600_resource_texture*)ptex;
        struct r600_resource *resource = &rtex->resource;
-       struct radeon *radeon = (struct radeon *)screen->winsys;
+       struct radeon *radeon = ((struct r600_screen*)screen)->radeon;
 
        if (rtex->flushed_depth_texture)
                pipe_resource_reference((struct pipe_resource **)&rtex->flushed_depth_texture, NULL);
@@ -373,7 +372,7 @@ r600_texture_create_object(struct pipe_screen *screen,
 {
        struct r600_resource_texture *rtex;
        struct r600_resource *resource;
-       struct radeon *radeon = (struct radeon *)screen->winsys;
+       struct radeon *radeon = ((struct r600_screen*)screen)->radeon;
 
        rtex = CALLOC_STRUCT(r600_resource_texture);
        if (rtex == NULL)
@@ -483,8 +482,9 @@ struct pipe_resource *r600_texture_from_handle(struct pipe_screen *screen,
                                               const struct pipe_resource *templ,
                                               struct winsys_handle *whandle)
 {
-       struct radeon *rw = (struct radeon*)screen->winsys;
+       struct radeon *rw = ((struct r600_screen*)screen)->radeon;
        struct r600_bo *bo = NULL;
+       unsigned stride = 0;
        unsigned array_mode = 0;
 
        /* Support only 2D textures without mipmaps */
@@ -492,15 +492,13 @@ struct pipe_resource *r600_texture_from_handle(struct pipe_screen *screen,
              templ->depth0 != 1 || templ->last_level != 0)
                return NULL;
 
-       bo = r600_bo_handle(rw, whandle->handle, &array_mode);
+       bo = r600_bo_handle(rw, whandle, &stride, &array_mode);
        if (bo == NULL) {
                return NULL;
        }
 
        return (struct pipe_resource *)r600_texture_create_object(screen, templ, array_mode,
-                                                                 whandle->stride,
-                                                                 0,
-                                                                 bo);
+                                                                 stride, 0, bo);
 }
 
 int r600_texture_depth_flush(struct pipe_context *ctx,
@@ -687,7 +685,7 @@ void* r600_texture_transfer_map(struct 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 radeon *)ctx->screen->winsys;
+       struct radeon *radeon = ((struct r600_screen*)ctx->screen)->radeon;
        unsigned offset = 0;
        char *map;
 
@@ -717,7 +715,7 @@ void r600_texture_transfer_unmap(struct pipe_context *ctx,
                                 struct pipe_transfer* transfer)
 {
        struct r600_transfer *rtransfer = (struct r600_transfer*)transfer;
-       struct radeon *radeon = (struct radeon *)ctx->screen->winsys;
+       struct radeon *radeon = ((struct r600_screen*)ctx->screen)->radeon;
        struct r600_bo *bo;
 
        if (rtransfer->staging_texture) {
index 412533e44bc97e4afbc3685177e031302951c247..94206d5568bde1057205c1cf06f61ed3e714d5ea 100644 (file)
@@ -902,6 +902,7 @@ int evergreen_context_init(struct r600_context *ctx, struct radeon *radeon)
 
        memset(ctx, 0, sizeof(struct r600_context));
        ctx->radeon = radeon;
+
        LIST_INITHEAD(&ctx->query_list);
 
        /* init dirty list */
index f6e15630d7156df7d3f6180dfc475555813f7be8..bbd52a1fddecbe95c8c8d87e7a270dccdc8bbe57 100644 (file)
@@ -86,23 +86,26 @@ struct r600_bo *r600_bo(struct radeon *radeon,
        return bo;
 }
 
-struct r600_bo *r600_bo_handle(struct radeon *radeon,
-                              unsigned handle, unsigned *array_mode)
+struct r600_bo *r600_bo_handle(struct radeon *radeon, struct winsys_handle *whandle,
+                              unsigned *stride, unsigned *array_mode)
 {
        struct r600_bo *bo = calloc(1, sizeof(struct r600_bo));
        struct radeon_bo *rbo;
 
-       rbo = bo->bo = radeon_bo(radeon, handle, 0, 0, 0);
+       rbo = bo->bo = radeon_bo(radeon, whandle->handle, 0, 0, 0);
        if (rbo == NULL) {
                free(bo);
                return NULL;
        }
+
+       pipe_reference_init(&bo->reference, 1);
        bo->size = rbo->size;
        bo->domains = (RADEON_GEM_DOMAIN_CPU |
                        RADEON_GEM_DOMAIN_GTT |
                        RADEON_GEM_DOMAIN_VRAM);
 
-       pipe_reference_init(&bo->reference, 1);
+       if (stride)
+               *stride = whandle->stride;
 
        radeon_bo_get_tiling_flags(radeon, rbo, &bo->tiling_flags, &bo->kernel_pitch);
        if (array_mode) {
index 3a2186c6f4a452f9458a50df9642ac53bf74e0ce..1cf905f2575f333d1cd04d13732121d2b4adbae2 100644 (file)
@@ -28,6 +28,7 @@
 
 #include "r600_priv.h"
 #include "r600_drm_public.h"
+#include "util/u_memory.h"
 #include <radeon_drm.h>
 #include <xf86drm.h>
 #include <errno.h>
@@ -244,22 +245,21 @@ static int handle_compare(void *key1, void *key2)
     return PTR_TO_UINT(key1) != PTR_TO_UINT(key2);
 }
 
-struct radeon *r600_drm_winsys_create(struct radeon_winsys *rw)
+struct radeon *radeon_create(struct radeon_winsys *ws)
 {
-       struct radeon *radeon;
        int r;
-
-       radeon = calloc(1, sizeof(*radeon));
+       struct radeon *radeon = CALLOC_STRUCT(radeon);
        if (radeon == NULL) {
                return NULL;
        }
 
-       rw->query_info(rw, &radeon->info);
+       radeon->ws = ws;
+       ws->query_info(ws, &radeon->info);
 
        radeon->family = radeon_family_from_device(radeon->info.pci_id);
        if (radeon->family == CHIP_UNKNOWN) {
                fprintf(stderr, "Unknown chipset 0x%04X\n", radeon->info.pci_id);
-               return radeon_decref(radeon);
+               return radeon_destroy(radeon);
        }
        /* setup class */
        switch (radeon->family) {
@@ -323,7 +323,7 @@ struct radeon *r600_drm_winsys_create(struct radeon_winsys *rw)
        }
        r = radeon_init_fence(radeon);
        if (r) {
-               radeon_decref(radeon);
+               radeon_destroy(radeon);
                return NULL;
        }
 
@@ -332,7 +332,7 @@ struct radeon *r600_drm_winsys_create(struct radeon_winsys *rw)
        return radeon;
 }
 
-struct radeon *radeon_decref(struct radeon *radeon)
+struct radeon *radeon_destroy(struct radeon *radeon)
 {
        if (radeon == NULL)
                return NULL;
@@ -346,6 +346,6 @@ struct radeon *radeon_decref(struct radeon *radeon)
        if (radeon->bomgr)
                r600_bomgr_destroy(radeon->bomgr);
 
-       free(radeon);
+       FREE(radeon);
        return NULL;
 }
index 1d990f91013fd0f9b1f2622cb13e2beed7cb9b54..b8a37c7574f1cdf96da1f414db2cdd37480fa2dc 100644 (file)
@@ -28,6 +28,6 @@
 
 struct radeon_winsys;
 
-struct radeon *r600_drm_winsys_create(struct radeon_winsys *rw);
+struct radeon *radeon_create(struct radeon_winsys *ws);
 
 #endif
index 60de24fa67ffaf4215a47bacb8594b8ca1abce4b..8ab4d94a6ee255556901e51dd63014525263a9f6 100644 (file)
@@ -874,6 +874,7 @@ int r600_context_init(struct r600_context *ctx, struct radeon *radeon)
 
        memset(ctx, 0, sizeof(struct r600_context));
        ctx->radeon = radeon;
+
        LIST_INITHEAD(&ctx->query_list);
 
        /* init dirty list */
index 08a3552803c94c0cbe9281f856c253875d11a245..8296aa1bdd1d3b2c8c6a441b0e39df7e170dc6a0 100644 (file)
@@ -38,6 +38,7 @@ struct r600_bomgr;
 struct r600_bo;
 
 struct radeon {
+       struct radeon_winsys            *ws;
        struct radeon_info              info;
        unsigned                        family;
        enum chip_class                 chip_class;