[Mesa-dev] [PATCH 5/7] gallium/u_suballoc: allow setting pipe_resource::flags
Marek Olšák
maraeo at gmail.com
Thu Feb 16 12:52:34 UTC 2017
From: Marek Olšák <marek.olsak at amd.com>
---
src/gallium/auxiliary/util/u_suballoc.c | 22 ++++++++++++++++++----
src/gallium/auxiliary/util/u_suballoc.h | 2 +-
src/gallium/drivers/r600/r600_pipe.c | 5 +++--
src/gallium/drivers/radeon/r600_pipe_common.c | 2 +-
src/gallium/drivers/radeonsi/si_pipe.c | 2 +-
5 files changed, 24 insertions(+), 9 deletions(-)
diff --git a/src/gallium/auxiliary/util/u_suballoc.c b/src/gallium/auxiliary/util/u_suballoc.c
index 8c463c9..392bba7 100644
--- a/src/gallium/auxiliary/util/u_suballoc.c
+++ b/src/gallium/auxiliary/util/u_suballoc.c
@@ -36,46 +36,48 @@
#include "u_suballoc.h"
struct u_suballocator {
struct pipe_context *pipe;
unsigned size; /* Size of the whole buffer, in bytes. */
unsigned bind; /* Bitmask of PIPE_BIND_* flags. */
enum pipe_resource_usage usage;
+ unsigned flags; /* pipe_resource::flags */
boolean zero_buffer_memory; /* If the buffer contents should be zeroed. */
struct pipe_resource *buffer; /* The buffer we suballocate from. */
unsigned offset; /* Aligned offset pointing at the first unused byte. */
};
/**
* Create a suballocator.
*
* \p zero_buffer_memory determines whether the buffer contents should be
* cleared to 0 after the allocation.
*/
struct u_suballocator *
u_suballocator_create(struct pipe_context *pipe, unsigned size, unsigned bind,
- enum pipe_resource_usage usage,
+ enum pipe_resource_usage usage, unsigned flags,
boolean zero_buffer_memory)
{
struct u_suballocator *allocator = CALLOC_STRUCT(u_suballocator);
if (!allocator)
return NULL;
allocator->pipe = pipe;
allocator->size = size;
allocator->bind = bind;
allocator->usage = usage;
+ allocator->flags = flags;
allocator->zero_buffer_memory = zero_buffer_memory;
return allocator;
}
void
u_suballocator_destroy(struct u_suballocator *allocator)
{
pipe_resource_reference(&allocator->buffer, NULL);
FREE(allocator);
}
@@ -90,23 +92,35 @@ u_suballocator_alloc(struct u_suballocator *allocator, unsigned size,
/* Don't allow allocations larger than the buffer size. */
if (size > allocator->size)
goto fail;
/* Make sure we have enough space in the buffer. */
if (!allocator->buffer ||
allocator->offset + size > allocator->size) {
/* Allocate a new buffer. */
pipe_resource_reference(&allocator->buffer, NULL);
allocator->offset = 0;
- allocator->buffer =
- pipe_buffer_create(allocator->pipe->screen, allocator->bind,
- allocator->usage, allocator->size);
+
+ struct pipe_resource templ;
+ memset(&templ, 0, sizeof(templ));
+ templ.target = PIPE_BUFFER;
+ templ.format = PIPE_FORMAT_R8_UNORM;
+ templ.bind = allocator->bind;
+ templ.usage = allocator->usage;
+ templ.flags = allocator->flags;
+ templ.width0 = allocator->size;
+ templ.height0 = 1;
+ templ.depth0 = 1;
+ templ.array_size = 1;
+
+ struct pipe_screen *screen = allocator->pipe->screen;
+ allocator->buffer = screen->resource_create(screen, &templ);
if (!allocator->buffer)
goto fail;
/* Clear the memory if needed. */
if (allocator->zero_buffer_memory) {
struct pipe_context *pipe = allocator->pipe;
if (pipe->clear_buffer) {
unsigned clear_value = 0;
diff --git a/src/gallium/auxiliary/util/u_suballoc.h b/src/gallium/auxiliary/util/u_suballoc.h
index fb08f16..e35382f 100644
--- a/src/gallium/auxiliary/util/u_suballoc.h
+++ b/src/gallium/auxiliary/util/u_suballoc.h
@@ -28,21 +28,21 @@
/* A simple allocator that suballocates memory from a large buffer. */
#ifndef U_SUBALLOC
#define U_SUBALLOC
struct u_suballocator;
struct u_suballocator *
u_suballocator_create(struct pipe_context *pipe, unsigned size, unsigned bind,
- enum pipe_resource_usage usage,
+ enum pipe_resource_usage usage, unsigned flags,
boolean zero_buffer_memory);
void
u_suballocator_destroy(struct u_suballocator *allocator);
void
u_suballocator_alloc(struct u_suballocator *allocator, unsigned size,
unsigned alignment, unsigned *out_offset,
struct pipe_resource **outbuf);
diff --git a/src/gallium/drivers/r600/r600_pipe.c b/src/gallium/drivers/r600/r600_pipe.c
index 5290f40..1803c26 100644
--- a/src/gallium/drivers/r600/r600_pipe.c
+++ b/src/gallium/drivers/r600/r600_pipe.c
@@ -181,22 +181,23 @@ static struct pipe_context *r600_create_context(struct pipe_screen *screen,
break;
default:
R600_ERR("Unsupported chip class %d.\n", rctx->b.chip_class);
goto fail;
}
rctx->b.gfx.cs = ws->cs_create(rctx->b.ctx, RING_GFX,
r600_context_gfx_flush, rctx);
rctx->b.gfx.flush = r600_context_gfx_flush;
- rctx->allocator_fetch_shader = u_suballocator_create(&rctx->b.b, 64 * 1024,
- 0, PIPE_USAGE_DEFAULT, FALSE);
+ rctx->allocator_fetch_shader =
+ u_suballocator_create(&rctx->b.b, 64 * 1024,
+ 0, PIPE_USAGE_DEFAULT, 0, FALSE);
if (!rctx->allocator_fetch_shader)
goto fail;
rctx->isa = calloc(1, sizeof(struct r600_isa));
if (!rctx->isa || r600_isa_init(rctx, rctx->isa))
goto fail;
if (rscreen->b.debug_flags & DBG_FORCE_DMA)
rctx->b.b.resource_copy_region = rctx->b.dma_copy;
diff --git a/src/gallium/drivers/radeon/r600_pipe_common.c b/src/gallium/drivers/radeon/r600_pipe_common.c
index 53d3dc6..8405c5e 100644
--- a/src/gallium/drivers/radeon/r600_pipe_common.c
+++ b/src/gallium/drivers/radeon/r600_pipe_common.c
@@ -591,21 +591,21 @@ bool r600_common_context_init(struct r600_common_context *rctx,
rctx->b.set_device_reset_callback = r600_set_device_reset_callback;
r600_init_context_texture_functions(rctx);
r600_init_viewport_functions(rctx);
r600_streamout_init(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, true);
+ 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);
if (!rctx->b.stream_uploader)
return false;
rctx->b.const_uploader = rctx->b.stream_uploader;
rctx->ctx = rctx->ws->ctx_create(rctx->ws);
diff --git a/src/gallium/drivers/radeonsi/si_pipe.c b/src/gallium/drivers/radeonsi/si_pipe.c
index 8806027..2dc884a 100644
--- a/src/gallium/drivers/radeonsi/si_pipe.c
+++ b/src/gallium/drivers/radeonsi/si_pipe.c
@@ -198,21 +198,21 @@ static struct pipe_context *si_create_context(struct pipe_screen *screen,
if (ws->cs_add_const_preamble_ib) {
sctx->ce_preamble_ib =
ws->cs_add_const_preamble_ib(sctx->b.gfx.cs);
if (!sctx->ce_preamble_ib)
goto fail;
}
sctx->ce_suballocator =
u_suballocator_create(&sctx->b.b, 1024 * 1024,
- 0, PIPE_USAGE_DEFAULT, false);
+ 0, PIPE_USAGE_DEFAULT, 0, false);
if (!sctx->ce_suballocator)
goto fail;
}
sctx->b.gfx.flush = si_context_gfx_flush;
/* Border colors. */
sctx->border_color_table = malloc(SI_MAX_BORDER_COLORS *
sizeof(*sctx->border_color_table));
if (!sctx->border_color_table)
--
2.7.4
More information about the mesa-dev
mailing list