winsys/radeon: add an interface for contexts
authorMarek Olšák <marek.olsak@amd.com>
Thu, 30 Apr 2015 14:07:12 +0000 (16:07 +0200)
committerMarek Olšák <marek.olsak@amd.com>
Thu, 6 Aug 2015 22:06:52 +0000 (00:06 +0200)
Same idea as in libdrm_amdgpu.

A command stream can only be created for a specific context and it's always
submitted to that context.

This will mainly be used by amdgpu and it's required by the GPU reset status
query too.
(radeon only has a basic version of the query and thus doesn't need this)

Reviewed-by: Christian König <christian.koenig@amd.com>
src/gallium/drivers/r300/r300_context.c
src/gallium/drivers/r300/r300_context.h
src/gallium/drivers/r600/r600_pipe.c
src/gallium/drivers/radeon/r600_pipe_common.c
src/gallium/drivers/radeon/r600_pipe_common.h
src/gallium/drivers/radeon/radeon_uvd.c
src/gallium/drivers/radeon/radeon_vce.c
src/gallium/drivers/radeon/radeon_winsys.h
src/gallium/drivers/radeonsi/si_pipe.c
src/gallium/winsys/radeon/drm/radeon_drm_cs.c

index c35aa3b24aa74d62e1c8e22009e81d6a7e79c034..8c24ad6d98a619a7f817d56c0271f7b2f4430d19 100644 (file)
@@ -94,6 +94,8 @@ static void r300_destroy_context(struct pipe_context* context)
 
     if (r300->cs)
         r300->rws->cs_destroy(r300->cs);
+    if (r300->ctx)
+        r300->rws->ctx_destroy(r300->ctx);
 
     rc_destroy_regalloc_state(&r300->fs_regalloc_state);
 
@@ -382,7 +384,11 @@ struct pipe_context* r300_create_context(struct pipe_screen* screen,
                      sizeof(struct pipe_transfer), 64,
                      UTIL_SLAB_SINGLETHREADED);
 
-    r300->cs = rws->cs_create(rws, RING_GFX, r300_flush_callback, r300, NULL);
+    r300->ctx = rws->ctx_create(rws);
+    if (!r300->ctx)
+        goto fail;
+
+    r300->cs = rws->cs_create(r300->ctx, RING_GFX, r300_flush_callback, r300, NULL);
     if (r300->cs == NULL)
         goto fail;
 
index 5a58500b0744a31e7c896307f16455bdcccd850c..18ae11a3a2410b0ec6cc3e234351af536905481d 100644 (file)
@@ -449,6 +449,8 @@ struct r300_context {
 
     /* The interface to the windowing system, etc. */
     struct radeon_winsys *rws;
+    /* The submission context. */
+    struct radeon_winsys_ctx *ctx;
     /* The command stream. */
     struct radeon_winsys_cs *cs;
     /* Screen. */
index e755784209a524f2c98318a5a26f602b12737af9..f02014e17f0009f313b8b0e5a05ba53e6122f42c 100644 (file)
@@ -176,7 +176,7 @@ static struct pipe_context *r600_create_context(struct pipe_screen *screen, void
                goto fail;
        }
 
-       rctx->b.rings.gfx.cs = ws->cs_create(ws, RING_GFX,
+       rctx->b.rings.gfx.cs = ws->cs_create(rctx->b.ctx, RING_GFX,
                                             r600_context_gfx_flush, rctx,
                                             rscreen->b.trace_bo ?
                                                     rscreen->b.trace_bo->cs_buf : NULL);
index 4c29f5235e18d523f20ab53edad36a0613a6c0e3..3f1c0f0eae97061cf3dc1e51d81b6a7974fa974a 100644 (file)
@@ -262,8 +262,12 @@ bool r600_common_context_init(struct r600_common_context *rctx,
        if (!rctx->uploader)
                return false;
 
+       rctx->ctx = rctx->ws->ctx_create(rctx->ws);
+       if (!rctx->ctx)
+               return false;
+
        if (rscreen->info.r600_has_dma && !(rscreen->debug_flags & DBG_NO_ASYNC_DMA)) {
-               rctx->rings.dma.cs = rctx->ws->cs_create(rctx->ws, RING_DMA,
+               rctx->rings.dma.cs = rctx->ws->cs_create(rctx->ctx, RING_DMA,
                                                         r600_flush_dma_ring,
                                                         rctx, NULL);
                rctx->rings.dma.flush = r600_flush_dma_ring;
@@ -274,12 +278,12 @@ bool r600_common_context_init(struct r600_common_context *rctx,
 
 void r600_common_context_cleanup(struct r600_common_context *rctx)
 {
-       if (rctx->rings.gfx.cs) {
+       if (rctx->rings.gfx.cs)
                rctx->ws->cs_destroy(rctx->rings.gfx.cs);
-       }
-       if (rctx->rings.dma.cs) {
+       if (rctx->rings.dma.cs)
                rctx->ws->cs_destroy(rctx->rings.dma.cs);
-       }
+       if (rctx->ctx)
+               rctx->ws->ctx_destroy(rctx->ctx);
 
        if (rctx->uploader) {
                u_upload_destroy(rctx->uploader);
index dbd828805836a493901654cc13b7cf03d6ef767e..ce3f396011f2fc69ee3505e5b2a49967a59fec96 100644 (file)
@@ -372,6 +372,7 @@ struct r600_common_context {
 
        struct r600_common_screen       *screen;
        struct radeon_winsys            *ws;
+       struct radeon_winsys_ctx        *ctx;
        enum radeon_family              family;
        enum chip_class                 chip_class;
        struct r600_rings               rings;
index be58d0b9ce37f893622256548586a22b1991d974..79fc0c726c4216cefc34d1cacc906bad881a1502 100644 (file)
@@ -761,6 +761,7 @@ struct pipe_video_codec *ruvd_create_decoder(struct pipe_context *context,
 {
        struct radeon_winsys* ws = ((struct r600_common_context *)context)->ws;
        unsigned dpb_size = calc_dpb_size(templ);
+       struct r600_common_context *rctx = (struct r600_common_context*)context;
        unsigned width = templ->width, height = templ->height;
        unsigned bs_buf_size;
        struct radeon_info info;
@@ -807,7 +808,7 @@ struct pipe_video_codec *ruvd_create_decoder(struct pipe_context *context,
        dec->stream_handle = rvid_alloc_stream_handle();
        dec->screen = context->screen;
        dec->ws = ws;
-       dec->cs = ws->cs_create(ws, RING_UVD, NULL, NULL, NULL);
+       dec->cs = ws->cs_create(rctx->ctx, RING_UVD, NULL, NULL, NULL);
        if (!dec->cs) {
                RVID_ERR("Can't get command submission context.\n");
                goto error;
index a6567379fe3501632c5a16b656e6ba46f318fe05..4557ce55556acadfd5c8716b8f49bef4cbfb9eca 100644 (file)
@@ -377,6 +377,7 @@ struct pipe_video_codec *rvce_create_encoder(struct pipe_context *context,
                                             rvce_get_buffer get_buffer)
 {
        struct r600_common_screen *rscreen = (struct r600_common_screen *)context->screen;
+       struct r600_common_context *rctx = (struct r600_common_context*)context;
        struct rvce_encoder *enc;
        struct pipe_video_buffer *tmp_buf, templat = {};
        struct radeon_surf *tmp_surf;
@@ -411,7 +412,7 @@ struct pipe_video_codec *rvce_create_encoder(struct pipe_context *context,
 
        enc->screen = context->screen;
        enc->ws = ws;
-       enc->cs = ws->cs_create(ws, RING_VCE, rvce_cs_flush, enc, NULL);
+       enc->cs = ws->cs_create(rctx->ctx, RING_VCE, rvce_cs_flush, enc, NULL);
        if (!enc->cs) {
                RVID_ERR("Can't get command submission context.\n");
                goto error;
index ea1e197015767e3026be33edbe2c2faf8ecf5637..93618ccbc1a77f26ba5843b24ef3ff1b3f9f0a59 100644 (file)
@@ -191,6 +191,7 @@ enum radeon_bo_priority {
 
 struct winsys_handle;
 struct radeon_winsys_cs_handle;
+struct radeon_winsys_ctx;
 
 struct radeon_winsys_cs {
     unsigned                    cdw;  /* Number of used dwords. */
@@ -505,16 +506,27 @@ struct radeon_winsys {
      * commands independently of other contexts.
      *************************************************************************/
 
+    /**
+     * Create a command submission context.
+     * Various command streams can be submitted to the same context.
+     */
+    struct radeon_winsys_ctx *(*ctx_create)(struct radeon_winsys *ws);
+
+    /**
+     * Destroy a context.
+     */
+    void (*ctx_destroy)(struct radeon_winsys_ctx *ctx);
+
     /**
      * Create a command stream.
      *
-     * \param ws        The winsys this function is called from.
+     * \param ctx       The submission context
      * \param ring_type The ring type (GFX, DMA, UVD)
      * \param flush     Flush callback function associated with the command stream.
      * \param user      User pointer that will be passed to the flush callback.
      * \param trace_buf Trace buffer when tracing is enabled
      */
-    struct radeon_winsys_cs *(*cs_create)(struct radeon_winsys *ws,
+    struct radeon_winsys_cs *(*cs_create)(struct radeon_winsys_ctx *ctx,
                                           enum ring_type ring_type,
                                           void (*flush)(void *ctx, unsigned flags,
                                                        struct pipe_fence_handle **fence),
index 73797976b5b332b2248051512c09c8fc84f12cb3..cacef9f0ae7c3e778cc7615150aadaa2c066ad41 100644 (file)
@@ -118,7 +118,7 @@ static struct pipe_context *si_create_context(struct pipe_screen *screen, void *
                sctx->b.b.create_video_buffer = vl_video_buffer_create;
        }
 
-       sctx->b.rings.gfx.cs = ws->cs_create(ws, RING_GFX, si_context_gfx_flush,
+       sctx->b.rings.gfx.cs = ws->cs_create(sctx->b.ctx, RING_GFX, si_context_gfx_flush,
                                             sctx, sscreen->b.trace_bo ?
                                                sscreen->b.trace_bo->cs_buf : NULL);
        sctx->b.rings.gfx.flush = si_context_gfx_flush;
index 6067bac36b82b9533c64097986acc94dc7b29f42..5fde875c34cad4ce4e9e19d020a608c6398049d3 100644 (file)
@@ -80,6 +80,18 @@ radeon_cs_create_fence(struct radeon_winsys_cs *rcs);
 static void radeon_fence_reference(struct pipe_fence_handle **dst,
                                    struct pipe_fence_handle *src);
 
+static struct radeon_winsys_ctx *radeon_drm_ctx_create(struct radeon_winsys *ws)
+{
+    /* No context support here. Just return the winsys pointer
+     * as the "context". */
+    return (struct radeon_winsys_ctx*)ws;
+}
+
+static void radeon_drm_ctx_destroy(struct radeon_winsys_ctx *ctx)
+{
+    /* No context support here. */
+}
+
 static boolean radeon_init_cs_context(struct radeon_cs_context *csc,
                                       struct radeon_drm_winsys *ws)
 {
@@ -158,14 +170,14 @@ static void radeon_destroy_cs_context(struct radeon_cs_context *csc)
 
 
 static struct radeon_winsys_cs *
-radeon_drm_cs_create(struct radeon_winsys *rws,
+radeon_drm_cs_create(struct radeon_winsys_ctx *ctx,
                      enum ring_type ring_type,
                      void (*flush)(void *ctx, unsigned flags,
                                    struct pipe_fence_handle **fence),
                      void *flush_ctx,
                      struct radeon_winsys_cs_handle *trace_buf)
 {
-    struct radeon_drm_winsys *ws = radeon_drm_winsys(rws);
+    struct radeon_drm_winsys *ws = (struct radeon_drm_winsys*)ctx;
     struct radeon_drm_cs *cs;
 
     cs = CALLOC_STRUCT(radeon_drm_cs);
@@ -667,6 +679,8 @@ static void radeon_fence_reference(struct pipe_fence_handle **dst,
 
 void radeon_drm_cs_init_functions(struct radeon_drm_winsys *ws)
 {
+    ws->base.ctx_create = radeon_drm_ctx_create;
+    ws->base.ctx_destroy = radeon_drm_ctx_destroy;
     ws->base.cs_create = radeon_drm_cs_create;
     ws->base.cs_destroy = radeon_drm_cs_destroy;
     ws->base.cs_add_reloc = radeon_drm_cs_add_reloc;