summaryrefslogtreecommitdiffstats
path: root/src/gallium/auxiliary/util
diff options
context:
space:
mode:
authorMarek Olšák <[email protected]>2016-05-31 19:06:45 +0200
committerMarek Olšák <[email protected]>2016-06-04 15:42:33 +0200
commitada3d8f31ef3aeeb73d6d365738a2d1968ced596 (patch)
treeb697854ee678eee668cc14c3a88baac544d1c51f /src/gallium/auxiliary/util
parent441194edd91c2ca9d2b219f7e16ba2c7783396df (diff)
gallium/u_suballoc: allow different alignment for each allocation
Just move the alignment parameter from u_suballocator_create to u_suballocator_alloc. Reviewed-by: Alex Deucher <[email protected]> Tested-by: Grazvydas Ignotas <[email protected]> Tested-by: Dieter Nützel <[email protected]>
Diffstat (limited to 'src/gallium/auxiliary/util')
-rw-r--r--src/gallium/auxiliary/util/u_suballoc.c22
-rw-r--r--src/gallium/auxiliary/util/u_suballoc.h6
2 files changed, 13 insertions, 15 deletions
diff --git a/src/gallium/auxiliary/util/u_suballoc.c b/src/gallium/auxiliary/util/u_suballoc.c
index 3f9ede075f2..5aaddbcb55c 100644
--- a/src/gallium/auxiliary/util/u_suballoc.c
+++ b/src/gallium/auxiliary/util/u_suballoc.c
@@ -41,7 +41,6 @@ struct u_suballocator {
struct pipe_context *pipe;
unsigned size; /* Size of the whole buffer, in bytes. */
- unsigned alignment; /* Alignment of each sub-allocation. */
unsigned bind; /* Bitmask of PIPE_BIND_* flags. */
enum pipe_resource_usage usage;
boolean zero_buffer_memory; /* If the buffer contents should be zeroed. */
@@ -58,8 +57,7 @@ struct u_suballocator {
* cleared to 0 after the allocation.
*/
struct u_suballocator *
-u_suballocator_create(struct pipe_context *pipe, unsigned size,
- unsigned alignment, unsigned bind,
+u_suballocator_create(struct pipe_context *pipe, unsigned size, unsigned bind,
enum pipe_resource_usage usage,
boolean zero_buffer_memory)
{
@@ -68,8 +66,7 @@ u_suballocator_create(struct pipe_context *pipe, unsigned size,
return NULL;
allocator->pipe = pipe;
- allocator->size = align(size, alignment);
- allocator->alignment = alignment;
+ allocator->size = size;
allocator->bind = bind;
allocator->usage = usage;
allocator->zero_buffer_memory = zero_buffer_memory;
@@ -85,17 +82,18 @@ u_suballocator_destroy(struct u_suballocator *allocator)
void
u_suballocator_alloc(struct u_suballocator *allocator, unsigned size,
- unsigned *out_offset, struct pipe_resource **outbuf)
+ unsigned alignment, unsigned *out_offset,
+ struct pipe_resource **outbuf)
{
- unsigned alloc_size = align(size, allocator->alignment);
+ allocator->offset = align(allocator->offset, alignment);
/* Don't allow allocations larger than the buffer size. */
- if (alloc_size > allocator->size)
+ if (size > allocator->size)
goto fail;
/* Make sure we have enough space in the buffer. */
if (!allocator->buffer ||
- allocator->offset + alloc_size > allocator->size) {
+ allocator->offset + size > allocator->size) {
/* Allocate a new buffer. */
pipe_resource_reference(&allocator->buffer, NULL);
allocator->offset = 0;
@@ -117,15 +115,15 @@ u_suballocator_alloc(struct u_suballocator *allocator, unsigned size,
}
}
- assert(allocator->offset % allocator->alignment == 0);
+ assert(allocator->offset % alignment == 0);
assert(allocator->offset < allocator->buffer->width0);
- assert(allocator->offset + alloc_size <= allocator->buffer->width0);
+ assert(allocator->offset + size <= allocator->buffer->width0);
/* Return the buffer. */
*out_offset = allocator->offset;
pipe_resource_reference(outbuf, allocator->buffer);
- allocator->offset += alloc_size;
+ allocator->offset += size;
return;
fail:
diff --git a/src/gallium/auxiliary/util/u_suballoc.h b/src/gallium/auxiliary/util/u_suballoc.h
index 5f9ccde7980..fb08f16fe40 100644
--- a/src/gallium/auxiliary/util/u_suballoc.h
+++ b/src/gallium/auxiliary/util/u_suballoc.h
@@ -34,8 +34,7 @@
struct u_suballocator;
struct u_suballocator *
-u_suballocator_create(struct pipe_context *pipe, unsigned size,
- unsigned alignment, unsigned bind,
+u_suballocator_create(struct pipe_context *pipe, unsigned size, unsigned bind,
enum pipe_resource_usage usage,
boolean zero_buffer_memory);
@@ -44,6 +43,7 @@ u_suballocator_destroy(struct u_suballocator *allocator);
void
u_suballocator_alloc(struct u_suballocator *allocator, unsigned size,
- unsigned *out_offset, struct pipe_resource **outbuf);
+ unsigned alignment, unsigned *out_offset,
+ struct pipe_resource **outbuf);
#endif