Re: [Mesa-dev] [PATCH 5/7] gallium/u_suballoc: allow setting pipe_resource::flags
On 02/16/2017 05:52 AM, Marek Olšák wrote: From: Marek Olšák--- 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 */ /* bitmask of PIPE_RESOURCE_FLAG_x */ would be more explicit. And maybe even call the field 'resource_flags' instead. 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. Can you add a comment for the new param here? As is, reading "unsigned flags" surely would require digging around to know what flags are expected. \p flags bitmask of PIPE_RESOURCE_FLAG_x bits. I'd like to look at using true enums for some of our bitfield flags. Last time I looked, gdb was able to figure out when an enum represents a bitmask and helpfully printed the flag names. -Brian */ 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(>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(>buffer, NULL); allocator->offset = 0; - allocator->buffer = - pipe_buffer_create(allocator->pipe->screen, allocator->bind, -allocator->usage, allocator->size); + + struct pipe_resource templ; + memset(, 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, ); 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
[Mesa-dev] [PATCH 5/7] gallium/u_suballoc: allow setting pipe_resource::flags
From: Marek Olšák--- 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(>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(>buffer, NULL); allocator->offset = 0; - allocator->buffer = - pipe_buffer_create(allocator->pipe->screen, allocator->bind, -allocator->usage, allocator->size); + + struct pipe_resource templ; + memset(, 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, ); 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,