[Mesa-dev] [PATCH 7/8] gallium/u_upload_mgr: allow drivers to specify pipe_resource::flags
Nicolai Hähnle
nhaehnle at gmail.com
Mon Dec 4 12:02:07 UTC 2017
Patches 1 and 3-7:
Reviewed-by: Nicolai Hähnle <nicolai.haehnle at amd.com>
On 01.12.2017 21:19, Marek Olšák wrote:
> From: Marek Olšák <marek.olsak at amd.com>
>
> ---
> src/gallium/auxiliary/util/u_upload_mgr.c | 9 ++++++---
> src/gallium/auxiliary/util/u_upload_mgr.h | 2 +-
> src/gallium/drivers/freedreno/a3xx/fd3_context.c | 2 +-
> src/gallium/drivers/freedreno/a4xx/fd4_context.c | 2 +-
> src/gallium/drivers/freedreno/a5xx/fd5_context.c | 2 +-
> src/gallium/drivers/r300/r300_context.c | 2 +-
> src/gallium/drivers/r600/r600_pipe_common.c | 4 ++--
> src/gallium/drivers/radeon/r600_pipe_common.c | 4 ++--
> src/gallium/drivers/svga/svga_context.c | 6 +++---
> src/gallium/drivers/svga/svga_resource_texture.c | 2 +-
> src/gallium/drivers/virgl/virgl_context.c | 2 +-
> 11 files changed, 20 insertions(+), 17 deletions(-)
>
> diff --git a/src/gallium/auxiliary/util/u_upload_mgr.c b/src/gallium/auxiliary/util/u_upload_mgr.c
> index 4bb14d6..e3b0fb3 100644
> --- a/src/gallium/auxiliary/util/u_upload_mgr.c
> +++ b/src/gallium/auxiliary/util/u_upload_mgr.c
> @@ -37,43 +37,45 @@
>
> #include "u_upload_mgr.h"
>
>
> struct u_upload_mgr {
> struct pipe_context *pipe;
>
> unsigned default_size; /* Minimum size of the upload buffer, in bytes. */
> unsigned bind; /* Bitmask of PIPE_BIND_* flags. */
> enum pipe_resource_usage usage;
> + unsigned flags;
> unsigned map_flags; /* Bitmask of PIPE_TRANSFER_* flags. */
> boolean map_persistent; /* If persistent mappings are supported. */
>
> struct pipe_resource *buffer; /* Upload buffer. */
> struct pipe_transfer *transfer; /* Transfer object for the upload buffer. */
> uint8_t *map; /* Pointer to the mapped upload buffer. */
> unsigned offset; /* Aligned offset to the upload buffer, pointing
> * at the first unused byte. */
> };
>
>
> struct u_upload_mgr *
> u_upload_create(struct pipe_context *pipe, unsigned default_size,
> - unsigned bind, enum pipe_resource_usage usage)
> + unsigned bind, enum pipe_resource_usage usage, unsigned flags)
> {
> struct u_upload_mgr *upload = CALLOC_STRUCT(u_upload_mgr);
> if (!upload)
> return NULL;
>
> upload->pipe = pipe;
> upload->default_size = default_size;
> upload->bind = bind;
> upload->usage = usage;
> + upload->flags = flags;
>
> upload->map_persistent =
> pipe->screen->get_param(pipe->screen,
> PIPE_CAP_BUFFER_MAP_PERSISTENT_COHERENT);
>
> if (upload->map_persistent) {
> upload->map_flags = PIPE_TRANSFER_WRITE |
> PIPE_TRANSFER_UNSYNCHRONIZED |
> PIPE_TRANSFER_PERSISTENT |
> PIPE_TRANSFER_COHERENT;
> @@ -87,28 +89,28 @@ u_upload_create(struct pipe_context *pipe, unsigned default_size,
> return upload;
> }
>
> struct u_upload_mgr *
> u_upload_create_default(struct pipe_context *pipe)
> {
> return u_upload_create(pipe, 1024 * 1024,
> PIPE_BIND_VERTEX_BUFFER |
> PIPE_BIND_INDEX_BUFFER |
> PIPE_BIND_CONSTANT_BUFFER,
> - PIPE_USAGE_STREAM);
> + PIPE_USAGE_STREAM, 0);
> }
>
> struct u_upload_mgr *
> u_upload_clone(struct pipe_context *pipe, struct u_upload_mgr *upload)
> {
> return u_upload_create(pipe, upload->default_size, upload->bind,
> - upload->usage);
> + upload->usage, upload->flags);
> }
>
> static void
> upload_unmap_internal(struct u_upload_mgr *upload, boolean destroying)
> {
> if (!destroying && upload->map_persistent)
> return;
>
> if (upload->transfer) {
> struct pipe_box *box = &upload->transfer->box;
> @@ -162,20 +164,21 @@ u_upload_alloc_buffer(struct u_upload_mgr *upload, unsigned min_size)
>
> /* Allocate a new one:
> */
> size = align(MAX2(upload->default_size, min_size), 4096);
>
> memset(&buffer, 0, sizeof buffer);
> buffer.target = PIPE_BUFFER;
> buffer.format = PIPE_FORMAT_R8_UNORM; /* want TYPELESS or similar */
> buffer.bind = upload->bind;
> buffer.usage = upload->usage;
> + buffer.flags = upload->flags;
> buffer.width0 = size;
> buffer.height0 = 1;
> buffer.depth0 = 1;
> buffer.array_size = 1;
>
> if (upload->map_persistent) {
> buffer.flags = PIPE_RESOURCE_FLAG_MAP_PERSISTENT |
> PIPE_RESOURCE_FLAG_MAP_COHERENT;
> }
>
> diff --git a/src/gallium/auxiliary/util/u_upload_mgr.h b/src/gallium/auxiliary/util/u_upload_mgr.h
> index 536467e..875fd9a 100644
> --- a/src/gallium/auxiliary/util/u_upload_mgr.h
> +++ b/src/gallium/auxiliary/util/u_upload_mgr.h
> @@ -45,21 +45,21 @@ extern "C" {
> /**
> * Create the upload manager.
> *
> * \param pipe Pipe driver.
> * \param default_size Minimum size of the upload buffer, in bytes.
> * \param bind Bitmask of PIPE_BIND_* flags.
> * \param usage PIPE_USAGE_*
> */
> struct u_upload_mgr *
> u_upload_create(struct pipe_context *pipe, unsigned default_size,
> - unsigned bind, enum pipe_resource_usage usage);
> + unsigned bind, enum pipe_resource_usage usage, unsigned flags);
>
> /**
> * Create the default uploader for pipe_context. Only pipe_context::screen
> * needs to be set for this to succeed.
> */
> struct u_upload_mgr *
> u_upload_create_default(struct pipe_context *pipe);
>
> /**
> * Create an uploader with identical parameters as another one, but using
> diff --git a/src/gallium/drivers/freedreno/a3xx/fd3_context.c b/src/gallium/drivers/freedreno/a3xx/fd3_context.c
> index 476d06d..3623b9c 100644
> --- a/src/gallium/drivers/freedreno/a3xx/fd3_context.c
> +++ b/src/gallium/drivers/freedreno/a3xx/fd3_context.c
> @@ -107,14 +107,14 @@ fd3_context_create(struct pipe_screen *pscreen, void *priv, unsigned flags)
> DRM_FREEDRENO_GEM_TYPE_KMEM);
>
> fd3_ctx->vsc_size_mem = fd_bo_new(screen->dev, 0x1000,
> DRM_FREEDRENO_GEM_TYPE_KMEM);
>
> fd_context_setup_common_vbos(&fd3_ctx->base);
>
> fd3_query_context_init(pctx);
>
> fd3_ctx->border_color_uploader = u_upload_create(pctx, 4096, 0,
> - PIPE_USAGE_STREAM);
> + PIPE_USAGE_STREAM, 0);
>
> return pctx;
> }
> diff --git a/src/gallium/drivers/freedreno/a4xx/fd4_context.c b/src/gallium/drivers/freedreno/a4xx/fd4_context.c
> index 82ba94a..1f5546d 100644
> --- a/src/gallium/drivers/freedreno/a4xx/fd4_context.c
> +++ b/src/gallium/drivers/freedreno/a4xx/fd4_context.c
> @@ -107,14 +107,14 @@ fd4_context_create(struct pipe_screen *pscreen, void *priv, unsigned flags)
> DRM_FREEDRENO_GEM_TYPE_KMEM);
>
> fd4_ctx->vsc_size_mem = fd_bo_new(screen->dev, 0x1000,
> DRM_FREEDRENO_GEM_TYPE_KMEM);
>
> fd_context_setup_common_vbos(&fd4_ctx->base);
>
> fd4_query_context_init(pctx);
>
> fd4_ctx->border_color_uploader = u_upload_create(pctx, 4096, 0,
> - PIPE_USAGE_STREAM);
> + PIPE_USAGE_STREAM, 0);
>
> return pctx;
> }
> diff --git a/src/gallium/drivers/freedreno/a5xx/fd5_context.c b/src/gallium/drivers/freedreno/a5xx/fd5_context.c
> index 1d08633..4ebbb97 100644
> --- a/src/gallium/drivers/freedreno/a5xx/fd5_context.c
> +++ b/src/gallium/drivers/freedreno/a5xx/fd5_context.c
> @@ -107,14 +107,14 @@ fd5_context_create(struct pipe_screen *pscreen, void *priv, unsigned flags)
> DRM_FREEDRENO_GEM_TYPE_KMEM);
>
> fd5_ctx->blit_mem = fd_bo_new(screen->dev, 0x1000,
> DRM_FREEDRENO_GEM_TYPE_KMEM);
>
> fd_context_setup_common_vbos(&fd5_ctx->base);
>
> fd5_query_context_init(pctx);
>
> fd5_ctx->border_color_uploader = u_upload_create(pctx, 4096, 0,
> - PIPE_USAGE_STREAM);
> + PIPE_USAGE_STREAM, 0);
>
> return pctx;
> }
> diff --git a/src/gallium/drivers/r300/r300_context.c b/src/gallium/drivers/r300/r300_context.c
> index b55fb63..627ba0c 100644
> --- a/src/gallium/drivers/r300/r300_context.c
> +++ b/src/gallium/drivers/r300/r300_context.c
> @@ -418,21 +418,21 @@ struct pipe_context* r300_create_context(struct pipe_screen* screen,
> r300_init_query_functions(r300);
> r300_init_state_functions(r300);
> r300_init_resource_functions(r300);
> r300_init_render_functions(r300);
> r300_init_states(&r300->context);
>
> r300->context.create_video_codec = vl_create_decoder;
> r300->context.create_video_buffer = vl_video_buffer_create;
>
> r300->uploader = u_upload_create(&r300->context, 1024 * 1024,
> - PIPE_BIND_CUSTOM, PIPE_USAGE_STREAM);
> + PIPE_BIND_CUSTOM, PIPE_USAGE_STREAM, 0);
> r300->context.stream_uploader = r300->uploader;
> r300->context.const_uploader = r300->uploader;
>
> r300->blitter = util_blitter_create(&r300->context);
> if (r300->blitter == NULL)
> goto fail;
> r300->blitter->draw_rectangle = r300_blitter_draw_rectangle;
>
> /* The KIL opcode needs the first texture unit to be enabled
> * on r3xx-r4xx. In order to calm down the CS checker, we bind this
> diff --git a/src/gallium/drivers/r600/r600_pipe_common.c b/src/gallium/drivers/r600/r600_pipe_common.c
> index d44860a..d20d2f4 100644
> --- a/src/gallium/drivers/r600/r600_pipe_common.c
> +++ b/src/gallium/drivers/r600/r600_pipe_common.c
> @@ -689,26 +689,26 @@ bool r600_common_context_init(struct r600_common_context *rctx,
> r600_query_init(rctx);
> cayman_init_msaa(&rctx->b);
>
> rctx->allocator_zeroed_memory =
> u_suballocator_create(&rctx->b, rscreen->info.gart_page_size,
> 0, PIPE_USAGE_DEFAULT, 0, true);
> if (!rctx->allocator_zeroed_memory)
> return false;
>
> rctx->b.stream_uploader = u_upload_create(&rctx->b, 1024 * 1024,
> - 0, PIPE_USAGE_STREAM);
> + 0, PIPE_USAGE_STREAM, 0);
> if (!rctx->b.stream_uploader)
> return false;
>
> rctx->b.const_uploader = u_upload_create(&rctx->b, 128 * 1024,
> - 0, PIPE_USAGE_DEFAULT);
> + 0, PIPE_USAGE_DEFAULT, 0);
> if (!rctx->b.const_uploader)
> return false;
>
> rctx->ctx = rctx->ws->ctx_create(rctx->ws);
> if (!rctx->ctx)
> return false;
>
> if (rscreen->info.num_sdma_rings && !(rscreen->debug_flags & DBG_NO_ASYNC_DMA)) {
> rctx->dma.cs = rctx->ws->cs_create(rctx->ctx, RING_DMA,
> r600_flush_dma_ring,
> diff --git a/src/gallium/drivers/radeon/r600_pipe_common.c b/src/gallium/drivers/radeon/r600_pipe_common.c
> index 7e7e42f..d85f9f0 100644
> --- a/src/gallium/drivers/radeon/r600_pipe_common.c
> +++ b/src/gallium/drivers/radeon/r600_pipe_common.c
> @@ -438,26 +438,26 @@ bool si_common_context_init(struct r600_common_context *rctx,
> return false;
> }
>
> rctx->allocator_zeroed_memory =
> u_suballocator_create(&rctx->b, sscreen->info.gart_page_size,
> 0, PIPE_USAGE_DEFAULT, 0, true);
> if (!rctx->allocator_zeroed_memory)
> return false;
>
> rctx->b.stream_uploader = u_upload_create(&rctx->b, 1024 * 1024,
> - 0, PIPE_USAGE_STREAM);
> + 0, PIPE_USAGE_STREAM, 0);
> if (!rctx->b.stream_uploader)
> return false;
>
> rctx->b.const_uploader = u_upload_create(&rctx->b, 128 * 1024,
> - 0, PIPE_USAGE_DEFAULT);
> + 0, PIPE_USAGE_DEFAULT, 0);
> if (!rctx->b.const_uploader)
> return false;
>
> rctx->ctx = rctx->ws->ctx_create(rctx->ws);
> if (!rctx->ctx)
> return false;
>
> if (sscreen->info.num_sdma_rings && !(sscreen->debug_flags & DBG(NO_ASYNC_DMA))) {
> rctx->dma.cs = rctx->ws->cs_create(rctx->ctx, RING_DMA,
> r600_flush_dma_ring,
> diff --git a/src/gallium/drivers/svga/svga_context.c b/src/gallium/drivers/svga/svga_context.c
> index 8640da9..546b9f4 100644
> --- a/src/gallium/drivers/svga/svga_context.c
> +++ b/src/gallium/drivers/svga/svga_context.c
> @@ -137,27 +137,27 @@ svga_context_create(struct pipe_screen *screen, void *priv, unsigned flags)
> goto cleanup;
>
> LIST_INITHEAD(&svga->dirty_buffers);
>
> svga->pipe.screen = screen;
> svga->pipe.priv = priv;
> svga->pipe.destroy = svga_destroy;
> svga->pipe.stream_uploader = u_upload_create(&svga->pipe, 1024 * 1024,
> PIPE_BIND_VERTEX_BUFFER |
> PIPE_BIND_INDEX_BUFFER,
> - PIPE_USAGE_STREAM);
> + PIPE_USAGE_STREAM, 0);
> if (!svga->pipe.stream_uploader)
> goto cleanup;
>
> svga->pipe.const_uploader = u_upload_create(&svga->pipe, 128 * 1024,
> PIPE_BIND_CONSTANT_BUFFER,
> - PIPE_USAGE_STREAM);
> + PIPE_USAGE_STREAM, 0);
> if (!svga->pipe.const_uploader)
> goto cleanup;
>
> svga->swc = svgascreen->sws->context_create(svgascreen->sws);
> if (!svga->swc)
> goto cleanup;
>
> svga_init_resource_functions(svga);
> svga_init_blend_functions(svga);
> svga_init_blit_functions(svga);
> @@ -224,21 +224,21 @@ svga_context_create(struct pipe_screen *screen, void *priv, unsigned flags)
> if (!svga_init_swtnl(svga))
> goto cleanup;
>
> ret = svga_emit_initial_state(svga);
> if (ret != PIPE_OK)
> goto cleanup;
>
> svga->const0_upload = u_upload_create(&svga->pipe,
> CONST0_UPLOAD_DEFAULT_SIZE,
> PIPE_BIND_CONSTANT_BUFFER,
> - PIPE_USAGE_STREAM);
> + PIPE_USAGE_STREAM, 0);
> if (!svga->const0_upload)
> goto cleanup;
>
> if (!svga_texture_transfer_map_upload_create(svga))
> goto cleanup;
>
> /* Avoid shortcircuiting state with initial value of zero.
> */
> memset(&svga->state.hw_clear, 0xcd, sizeof(svga->state.hw_clear));
> memset(&svga->state.hw_clear.framebuffer, 0x0,
> diff --git a/src/gallium/drivers/svga/svga_resource_texture.c b/src/gallium/drivers/svga/svga_resource_texture.c
> index 9e4d6c9..71b8ebe 100644
> --- a/src/gallium/drivers/svga/svga_resource_texture.c
> +++ b/src/gallium/drivers/svga/svga_resource_texture.c
> @@ -1325,21 +1325,21 @@ svga_texture_generate_mipmap(struct pipe_context *pipe,
> /* texture upload buffer default size in bytes */
> #define TEX_UPLOAD_DEFAULT_SIZE (1024 * 1024)
>
> /**
> * Create a texture upload buffer
> */
> boolean
> svga_texture_transfer_map_upload_create(struct svga_context *svga)
> {
> svga->tex_upload = u_upload_create(&svga->pipe, TEX_UPLOAD_DEFAULT_SIZE,
> - 0, PIPE_USAGE_STAGING);
> + 0, PIPE_USAGE_STAGING, 0);
> return svga->tex_upload != NULL;
> }
>
>
> /**
> * Destroy the texture upload buffer
> */
> void
> svga_texture_transfer_map_upload_destroy(struct svga_context *svga)
> {
> diff --git a/src/gallium/drivers/virgl/virgl_context.c b/src/gallium/drivers/virgl/virgl_context.c
> index 232d295..f1b6ef4 100644
> --- a/src/gallium/drivers/virgl/virgl_context.c
> +++ b/src/gallium/drivers/virgl/virgl_context.c
> @@ -931,21 +931,21 @@ struct pipe_context *virgl_context_create(struct pipe_screen *pscreen,
>
> virgl_init_context_resource_functions(&vctx->base);
> virgl_init_query_functions(vctx);
> virgl_init_so_functions(vctx);
>
> list_inithead(&vctx->to_flush_bufs);
> slab_create_child(&vctx->texture_transfer_pool, &rs->texture_transfer_pool);
>
> vctx->primconvert = util_primconvert_create(&vctx->base, rs->caps.caps.v1.prim_mask);
> vctx->uploader = u_upload_create(&vctx->base, 1024 * 1024,
> - PIPE_BIND_INDEX_BUFFER, PIPE_USAGE_STREAM);
> + PIPE_BIND_INDEX_BUFFER, PIPE_USAGE_STREAM, 0);
> if (!vctx->uploader)
> goto fail;
> vctx->base.stream_uploader = vctx->uploader;
> vctx->base.const_uploader = vctx->uploader;
>
> vctx->hw_sub_ctx_id = rs->sub_ctx_id++;
> virgl_encoder_create_sub_ctx(vctx, vctx->hw_sub_ctx_id);
>
> virgl_encoder_set_sub_ctx(vctx, vctx->hw_sub_ctx_id);
> return &vctx->base;
>
--
Lerne, wie die Welt wirklich ist,
Aber vergiss niemals, wie sie sein sollte.
More information about the mesa-dev
mailing list