gallium/u_suballoc: allow different alignment for each allocation
authorMarek Olšák <marek.olsak@amd.com>
Tue, 31 May 2016 17:06:45 +0000 (19:06 +0200)
committerMarek Olšák <marek.olsak@amd.com>
Sat, 4 Jun 2016 13:42:33 +0000 (15:42 +0200)
Just move the alignment parameter from u_suballocator_create
to u_suballocator_alloc.

Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Tested-by: Grazvydas Ignotas <notasas@gmail.com>
Tested-by: Dieter Nützel <Dieter@nuetzel-hh.de>
src/gallium/auxiliary/util/u_suballoc.c
src/gallium/auxiliary/util/u_suballoc.h
src/gallium/drivers/r600/r600_asm.c
src/gallium/drivers/r600/r600_pipe.c
src/gallium/drivers/radeon/r600_pipe_common.c
src/gallium/drivers/radeon/r600_streamout.c
src/gallium/drivers/radeonsi/si_descriptors.c
src/gallium/drivers/radeonsi/si_pipe.c

index 3f9ede075f22c7dbf08cd6c26d3635a3365e2947..5aaddbcb55c686a92c1ec1475c828317af10e7ef 100644 (file)
@@ -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:
index 5f9ccde798063f8c2664dc014bd47cac3faeb010..fb08f16fe40717695a8d827e3fb1b250595e072e 100644 (file)
@@ -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
index c48d7586cbb8503a758e1754b5e9b991ba13fd10..2141cf200505768055de29ccee1181df415d0003 100644 (file)
@@ -2615,7 +2615,8 @@ void *r600_create_vertex_fetch_shader(struct pipe_context *ctx,
                return NULL;
        }
 
-       u_suballocator_alloc(rctx->allocator_fetch_shader, fs_size, &shader->offset,
+       u_suballocator_alloc(rctx->allocator_fetch_shader, fs_size, 256,
+                            &shader->offset,
                             (struct pipe_resource**)&shader->buffer);
        if (!shader->buffer) {
                r600_bytecode_clear(&bc);
index 846513b8199f3a4d55436ddc1731f1374574e997..ddf880e990a50da7337da3a8c7a819b12f4131d5 100644 (file)
@@ -187,7 +187,7 @@ static struct pipe_context *r600_create_context(struct pipe_screen *screen,
                                       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, 256,
+       rctx->allocator_fetch_shader = u_suballocator_create(&rctx->b.b, 64 * 1024,
                                                             0, PIPE_USAGE_DEFAULT, FALSE);
        if (!rctx->allocator_fetch_shader)
                goto fail;
index 7ace34b8772496a0330831444bd8043984fee165..870d5b8e5c8592b949768bb3cbcd6804134c3ef7 100644 (file)
@@ -371,7 +371,7 @@ bool r600_common_context_init(struct r600_common_context *rctx,
 
        rctx->allocator_so_filled_size =
                u_suballocator_create(&rctx->b, rscreen->info.gart_page_size,
-                                     4, 0, PIPE_USAGE_DEFAULT, TRUE);
+                                     0, PIPE_USAGE_DEFAULT, TRUE);
        if (!rctx->allocator_so_filled_size)
                return false;
 
index a001700ea1935355f2fb19532b15a29be65d30f1..24216dee5eb40711228d43c32175e97659e17187 100644 (file)
@@ -46,7 +46,7 @@ r600_create_so_target(struct pipe_context *ctx,
                return NULL;
        }
 
-       u_suballocator_alloc(rctx->allocator_so_filled_size, 4,
+       u_suballocator_alloc(rctx->allocator_so_filled_size, 4, 4,
                             &t->buf_filled_size_offset,
                             (struct pipe_resource**)&t->buf_filled_size);
        if (!t->buf_filled_size) {
index d66996aa657c4f28d7c7d49f5f66283eb1e2d187..7aaac3950b8c31e3b82ef53d7027964cf67f7490 100644 (file)
@@ -140,7 +140,7 @@ static bool si_ce_upload(struct si_context *sctx, unsigned ce_offset, unsigned s
                         unsigned *out_offset, struct r600_resource **out_buf) {
        uint64_t va;
 
-       u_suballocator_alloc(sctx->ce_suballocator, size, out_offset,
+       u_suballocator_alloc(sctx->ce_suballocator, size, 64, out_offset,
                             (struct pipe_resource**)out_buf);
        if (!out_buf)
                        return false;
index 0987baf86c54695ab077b28145f81bb85fe5f1b9..7bb3dc24e52109f12bb8dfb24ed8f4cb6e087ec7 100644 (file)
@@ -164,7 +164,7 @@ static struct pipe_context *si_create_context(struct pipe_screen *screen,
 
                sctx->ce_suballocator =
                                u_suballocator_create(&sctx->b.b, 1024 * 1024,
-                                                     64, PIPE_BIND_CUSTOM,
+                                                     PIPE_BIND_CUSTOM,
                                                      PIPE_USAGE_DEFAULT, FALSE);
                if (!sctx->ce_suballocator)
                        goto fail;