u_upload_mgr: pass alignment to u_upload_alloc manually
authorMarek Olšák <marek.olsak@amd.com>
Sat, 19 Dec 2015 16:15:02 +0000 (17:15 +0100)
committerMarek Olšák <marek.olsak@amd.com>
Sat, 2 Jan 2016 14:15:44 +0000 (15:15 +0100)
The fixed alignment of u_upload_mgr will go away.
This is the first step.

The motivation is that one u_upload_mgr can have multiple users,
each allocating from the same buffer, but requiring a different alignment.

Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
25 files changed:
src/gallium/auxiliary/hud/hud_context.c
src/gallium/auxiliary/indices/u_primconvert.c
src/gallium/auxiliary/util/u_upload_mgr.c
src/gallium/auxiliary/util/u_upload_mgr.h
src/gallium/auxiliary/util/u_vbuf.c
src/gallium/auxiliary/vl/vl_compositor.c
src/gallium/drivers/freedreno/a3xx/fd3_context.c
src/gallium/drivers/freedreno/a3xx/fd3_emit.c
src/gallium/drivers/freedreno/a4xx/fd4_context.c
src/gallium/drivers/freedreno/a4xx/fd4_emit.c
src/gallium/drivers/freedreno/freedreno_context.h
src/gallium/drivers/r300/r300_render_translate.c
src/gallium/drivers/r600/r600_state_common.c
src/gallium/drivers/radeon/r600_buffer_common.c
src/gallium/drivers/radeon/r600_pipe_common.c
src/gallium/drivers/radeonsi/si_descriptors.c
src/gallium/drivers/radeonsi/si_state_draw.c
src/gallium/drivers/svga/svga_context.c
src/gallium/drivers/svga/svga_context.h
src/gallium/drivers/svga/svga_state_constants.c
src/gallium/drivers/vc4/vc4_resource.c
src/mesa/state_tracker/st_cb_bitmap.c
src/mesa/state_tracker/st_cb_clear.c
src/mesa/state_tracker/st_cb_drawpixels.c
src/mesa/state_tracker/st_cb_drawtex.c

index c5c333277021b27e490abe348de53df8871ab95b..691de81f20aba99ca5d75e3316a5dfef2535a252 100644 (file)
@@ -431,7 +431,7 @@ hud_alloc_vertices(struct hud_context *hud, struct vertex_queue *v,
    v->max_num_vertices = num_vertices;
    v->vbuf.stride = stride;
    u_upload_alloc(hud->uploader, 0, v->vbuf.stride * v->max_num_vertices,
-                  &v->vbuf.buffer_offset, &v->vbuf.buffer,
+                  16, &v->vbuf.buffer_offset, &v->vbuf.buffer,
                   (void**)&v->vertices);
 }
 
index 70d3e8530b8811f53f93ba6bbd15d179a8775688..c0a31548433140f86d885667f951ca89c3a458fa 100644 (file)
@@ -156,7 +156,7 @@ util_primconvert_draw_vbo(struct primconvert_context *pc,
       pc->upload = u_upload_create(pc->pipe, 4096, 4, PIPE_BIND_INDEX_BUFFER);
    }
 
-   u_upload_alloc(pc->upload, 0, new_ib.index_size * new_info.count,
+   u_upload_alloc(pc->upload, 0, new_ib.index_size * new_info.count, 4,
                   &new_ib.offset, &new_ib.buffer, &dst);
 
    if (info->indexed) {
index 4148bae5ab5046849ae64011364126e7c0666f93..3f790400e4067e3933a890712d241bc4abfe2316 100644 (file)
@@ -181,11 +181,11 @@ void
 u_upload_alloc(struct u_upload_mgr *upload,
                unsigned min_out_offset,
                unsigned size,
+               unsigned alignment,
                unsigned *out_offset,
                struct pipe_resource **outbuf,
                void **ptr)
 {
-   unsigned alignment = upload->alignment;
    unsigned buffer_size = upload->buffer ? upload->buffer->width0 : 0;
    unsigned offset;
 
@@ -249,7 +249,7 @@ void u_upload_data(struct u_upload_mgr *upload,
 {
    uint8_t *ptr;
 
-   u_upload_alloc(upload, min_out_offset, size,
+   u_upload_alloc(upload, min_out_offset, size, upload->alignment,
                   out_offset, outbuf,
                   (void**)&ptr);
    if (ptr)
index 67c6daa4e7f86b99cb6ffa4a738c7e9873033311..ad7135fc8da13f4fe89e180afea3a5d8656e4759 100644 (file)
@@ -74,6 +74,7 @@ void u_upload_unmap( struct u_upload_mgr *upload );
  * \param upload           Upload manager
  * \param min_out_offset   Minimum offset that should be returned in out_offset.
  * \param size             Size of the allocation.
+ * \param alignment        Alignment of the suballocation within the buffer
  * \param out_offset       Pointer to where the new buffer offset will be returned.
  * \param outbuf           Pointer to where the upload buffer will be returned.
  * \param ptr              Pointer to the allocated memory that is returned.
@@ -81,6 +82,7 @@ void u_upload_unmap( struct u_upload_mgr *upload );
 void u_upload_alloc(struct u_upload_mgr *upload,
                     unsigned min_out_offset,
                     unsigned size,
+                    unsigned alignment,
                     unsigned *out_offset,
                     struct pipe_resource **outbuf,
                     void **ptr);
index 54e9e71710496965bbe6d918b747a5296ce167ed..dd64e2d7949c4badc6184937b1dc2edf3971f89e 100644 (file)
@@ -454,7 +454,7 @@ u_vbuf_translate_buffers(struct u_vbuf *mgr, struct translate_key *key,
 
       /* Create and map the output buffer. */
       u_upload_alloc(mgr->uploader, 0,
-                     key->output_stride * num_indices,
+                     key->output_stride * num_indices, 4,
                      &out_offset, &out_buffer,
                      (void**)&out_map);
       if (!out_buffer)
@@ -487,7 +487,7 @@ u_vbuf_translate_buffers(struct u_vbuf *mgr, struct translate_key *key,
       /* Create and map the output buffer. */
       u_upload_alloc(mgr->uploader,
                      key->output_stride * start_vertex,
-                     key->output_stride * num_vertices,
+                     key->output_stride * num_vertices, 4,
                      &out_offset, &out_buffer,
                      (void**)&out_map);
       if (!out_buffer)
index afe53063b48bf0ff9c0857907e56a1e8826bc3c1..f160df63aa535a10dbd5487d70c30798992f61d8 100644 (file)
@@ -716,6 +716,7 @@ gen_vertex_data(struct vl_compositor *c, struct vl_compositor_state *s, struct u
    /* Allocate new memory for vertices. */
    u_upload_alloc(c->upload, 0,
                   c->vertex_buf.stride * VL_COMPOSITOR_MAX_LAYERS * 4, /* size */
+                  4, /* alignment */
                   &c->vertex_buf.buffer_offset, &c->vertex_buf.buffer,
                   (void**)&vb);
 
index 74cbbf2edd8c468aaff863b0ea18ef6c8093aa53..2413f152f940f2f3e90a485dc433a6b89d2c7388 100644 (file)
@@ -172,7 +172,7 @@ fd3_context_create(struct pipe_screen *pscreen, void *priv, unsigned flags)
        fd3_query_context_init(pctx);
 
        fd3_ctx->border_color_uploader = u_upload_create(pctx, 4096,
-                       2 * PIPE_MAX_SAMPLERS * BORDERCOLOR_SIZE, 0);
+                       BORDER_COLOR_UPLOAD_SIZE, 0);
 
        return pctx;
 }
index 24afbc9e956b459154ed8d9321f8fbd1ac1b5da2..e65a352e7f60d597fd2ba94d1b11d53feaaa339b 100644 (file)
@@ -145,7 +145,8 @@ emit_textures(struct fd_context *ctx, struct fd_ringbuffer *ring,
        void *ptr;
 
        u_upload_alloc(fd3_ctx->border_color_uploader,
-                       0, 2 * PIPE_MAX_SAMPLERS * BORDERCOLOR_SIZE, &off,
+                       0, BORDER_COLOR_UPLOAD_SIZE,
+                      BORDER_COLOR_UPLOAD_SIZE, &off,
                        &fd3_ctx->border_color_buf,
                        &ptr);
 
index e53e0c56c9ab8767041f51d85bdd1d4cd9bfa596..1037adfebf899c938e88cde7dcee94ec94b21503 100644 (file)
@@ -172,7 +172,7 @@ fd4_context_create(struct pipe_screen *pscreen, void *priv, unsigned flags)
        fd4_query_context_init(pctx);
 
        fd4_ctx->border_color_uploader = u_upload_create(pctx, 4096,
-                       2 * PIPE_MAX_SAMPLERS * BORDERCOLOR_SIZE, 0);
+                       BORDER_COLOR_UPLOAD_SIZE, 0);
 
        return pctx;
 }
index b9a281497222174bf7f72f8398ca93ae8c5fa285..bc62a5d9a4b02f21f8149bfdc489764fbdf1b4fa 100644 (file)
@@ -133,7 +133,8 @@ emit_textures(struct fd_context *ctx, struct fd_ringbuffer *ring,
        void *ptr;
 
        u_upload_alloc(fd4_ctx->border_color_uploader,
-                       0, 2 * PIPE_MAX_SAMPLERS * BORDERCOLOR_SIZE, &off,
+                       0, BORDER_COLOR_UPLOAD_SIZE,
+                      BORDER_COLOR_UPLOAD_SIZE, &off,
                        &fd4_ctx->border_color_buf,
                        &ptr);
 
index 571c8142bf7730b866f0f2edb5c1776d029c2c45..418b71b95de2ab4e609c8cf3ac03cb06de3d0fe3 100644 (file)
@@ -40,6 +40,8 @@
 #include "freedreno_gmem.h"
 #include "freedreno_util.h"
 
+#define BORDER_COLOR_UPLOAD_SIZE (2 * PIPE_MAX_SAMPLERS * BORDERCOLOR_SIZE)
+
 struct fd_vertex_stateobj;
 
 struct fd_texture_stateobj {
index caeeec059090aa26a46f737a2bc0e59677539a88..7221211deea4ed9671b7730f94e81a713ef30412 100644 (file)
@@ -37,7 +37,7 @@ void r300_translate_index_buffer(struct r300_context *r300,
     switch (*index_size) {
     case 1:
         *out_buffer = NULL;
-        u_upload_alloc(r300->uploader, 0, count * 2,
+        u_upload_alloc(r300->uploader, 0, count * 2, 4,
                        &out_offset, out_buffer, &ptr);
 
         util_shorten_ubyte_elts_to_userptr(
@@ -51,7 +51,7 @@ void r300_translate_index_buffer(struct r300_context *r300,
     case 2:
         if (index_offset) {
             *out_buffer = NULL;
-            u_upload_alloc(r300->uploader, 0, count * 2,
+            u_upload_alloc(r300->uploader, 0, count * 2, 4,
                            &out_offset, out_buffer, &ptr);
 
             util_rebuild_ushort_elts_to_userptr(&r300->context, ib,
@@ -65,7 +65,7 @@ void r300_translate_index_buffer(struct r300_context *r300,
     case 4:
         if (index_offset) {
             *out_buffer = NULL;
-            u_upload_alloc(r300->uploader, 0, count * 4,
+            u_upload_alloc(r300->uploader, 0, count * 4, 4,
                            &out_offset, out_buffer, &ptr);
 
             util_rebuild_uint_elts_to_userptr(&r300->context, ib,
index ca589fa7759c248e69a952fd98435afcc3017b20..3051c9af09cffbea7391a0fe0f8c11de1bcba8d9 100644 (file)
@@ -1732,7 +1732,7 @@ static void r600_draw_vbo(struct pipe_context *ctx, const struct pipe_draw_info
                                }
                        }
 
-                       u_upload_alloc(rctx->b.uploader, start, count * 2,
+                       u_upload_alloc(rctx->b.uploader, start, count * 2, 256,
                                       &out_offset, &out_buffer, &ptr);
 
                        util_shorten_ubyte_elts_to_userptr(
index 18925277d2d3131c293cbf52a76c460cc7ba3440..484f5c8d5b72d004df989261245542f5167c4e97 100644 (file)
@@ -298,7 +298,7 @@ static void *r600_buffer_transfer_map(struct pipe_context *ctx,
                        struct r600_resource *staging = NULL;
 
                        u_upload_alloc(rctx->uploader, 0, box->width + (box->x % R600_MAP_BUFFER_ALIGNMENT),
-                                      &offset, (struct pipe_resource**)&staging, (void**)&data);
+                                      256, &offset, (struct pipe_resource**)&staging, (void**)&data);
 
                        if (staging) {
                                data += box->x % R600_MAP_BUFFER_ALIGNMENT;
index 9a5e98781767b5dfe423a27052ead4cfd0fa7e0b..c044b6130a241e087acd816c2d977d84bf1f9841 100644 (file)
@@ -85,7 +85,7 @@ void r600_draw_rectangle(struct blitter_context *blitter,
        /* Upload vertices. The hw rectangle has only 3 vertices,
         * I guess the 4th one is derived from the first 3.
         * The vertex specification should match u_blitter's vertex element state. */
-       u_upload_alloc(rctx->uploader, 0, sizeof(float) * 24, &offset, &buf, (void**)&vb);
+       u_upload_alloc(rctx->uploader, 0, sizeof(float) * 24, 256, &offset, &buf, (void**)&vb);
        if (!buf)
                return;
 
index b3719dea25255b4ca33408912b7284633a5b3e06..5b0ad8f562211ebaf3e018d6b6ca0d6d2e77f4ba 100644 (file)
@@ -109,7 +109,7 @@ static bool si_upload_descriptors(struct si_context *sctx,
        if (!desc->list_dirty)
                return true;
 
-       u_upload_alloc(sctx->b.uploader, 0, list_size,
+       u_upload_alloc(sctx->b.uploader, 0, list_size, 256,
                       &desc->buffer_offset,
                       (struct pipe_resource**)&desc->buffer, &ptr);
        if (!desc->buffer)
@@ -391,7 +391,7 @@ static bool si_upload_vertex_buffer_descriptors(struct si_context *sctx)
         * directly through a staging buffer and don't go through
         * the fine-grained upload path.
         */
-       u_upload_alloc(sctx->b.uploader, 0, count * 16, &desc->buffer_offset,
+       u_upload_alloc(sctx->b.uploader, 0, count * 16, 256, &desc->buffer_offset,
                       (struct pipe_resource**)&desc->buffer, (void**)&ptr);
        if (!desc->buffer)
                return false;
@@ -465,7 +465,7 @@ void si_upload_const_buffer(struct si_context *sctx, struct r600_resource **rbuf
 {
        void *tmp;
 
-       u_upload_alloc(sctx->b.uploader, 0, size, const_offset,
+       u_upload_alloc(sctx->b.uploader, 0, size, 256, const_offset,
                       (struct pipe_resource**)rbuffer, &tmp);
        if (rbuffer)
                util_memcpy_cpu_to_le32(tmp, ptr, size);
index e5500111f43b3ad0e2f81a656e9ae38bc3a07db5..d5540bec71d1b07158f2291573e6f6d814995650 100644 (file)
@@ -818,7 +818,7 @@ void si_draw_vbo(struct pipe_context *ctx, const struct pipe_draw_info *info)
                        si_get_draw_start_count(sctx, info, &start, &count);
                        start_offset = start * ib.index_size;
 
-                       u_upload_alloc(sctx->b.uploader, start_offset, count * 2,
+                       u_upload_alloc(sctx->b.uploader, start_offset, count * 2, 256,
                                       &out_offset, &out_buffer, &ptr);
                        if (!out_buffer) {
                                pipe_resource_reference(&ib.buffer, NULL);
index d407785ddd9afa77e201f6266bddfbcd20921759..97e649e38ba83b75e9e8ea60c79d82d02590cf4d 100644 (file)
@@ -46,7 +46,6 @@
 #include "svga_winsys.h"
 
 #define CONST0_UPLOAD_DEFAULT_SIZE 65536
-#define CONST0_UPLOAD_ALIGNMENT 256
 
 DEBUG_GET_ONCE_BOOL_OPTION(no_swtnl, "SVGA_NO_SWTNL", FALSE)
 DEBUG_GET_ONCE_BOOL_OPTION(force_swtnl, "SVGA_FORCE_SWTNL", FALSE);
index 78e346a92b970cd3825074adebf122f7ed07b928..c282932cb18460b558725111126287975675dcc1 100644 (file)
@@ -74,6 +74,8 @@
  */
 #define SVGA_MAX_CONST_BUF_SIZE (4096 * 4 * sizeof(int))
 
+#define CONST0_UPLOAD_ALIGNMENT 256
+
 struct draw_vertex_shader;
 struct draw_fragment_shader;
 struct svga_shader_variant;
index 2cf41134bd6c328f3b7699891db1ac9c7057a751..8ab1693088acc3d12645d1263397cfb3808d922f 100644 (file)
@@ -613,7 +613,8 @@ emit_constbuf_vgpu10(struct svga_context *svga, unsigned shader)
     */
    new_buf_size = align(new_buf_size, 16);
 
-   u_upload_alloc(svga->const0_upload, 0, new_buf_size, &offset,
+   u_upload_alloc(svga->const0_upload, 0, new_buf_size,
+                  CONST0_UPLOAD_ALIGNMENT, &offset,
                   &dst_buffer, &dst_map);
    if (!dst_map) {
       if (src_map)
index 9e6678a0625be2b8bfbfb32b479afb735cd51bf2..308fb9fc77bd00481226e8e7335431b16b14554e 100644 (file)
@@ -921,7 +921,7 @@ vc4_get_shadow_index_buffer(struct pipe_context *pctx,
 
         void *data;
         struct pipe_resource *shadow_rsc = NULL;
-        u_upload_alloc(vc4->uploader, 0, count * 2,
+        u_upload_alloc(vc4->uploader, 0, count * 2, 4,;
                        shadow_offset, &shadow_rsc, &data);
         uint16_t *dst = data;
 
index a4a48a616fdb53780eb030647d774a3f975ab609..14e8354d4801ba9e2172792a2708fdb77cf3f8e8 100644 (file)
@@ -204,7 +204,7 @@ setup_bitmap_vertex_data(struct st_context *st, bool normalized,
       tBot = (GLfloat) height;
    }
 
-   u_upload_alloc(st->uploader, 0, 4 * sizeof(vertices[0]),
+   u_upload_alloc(st->uploader, 0, 4 * sizeof(vertices[0]), 4,
                   vbuf_offset, vbuf, (void **) &vertices);
    if (!*vbuf) {
       return;
index 18efd14a57cdb70c8711e746c1e036c2842ab550..e09f5ec6a0bc7cdce5bff02e011118650912e7c4 100644 (file)
@@ -184,7 +184,7 @@ draw_quad(struct st_context *st,
 
    vb.stride = 8 * sizeof(float);
 
-   u_upload_alloc(st->uploader, 0, 4 * sizeof(vertices[0]),
+   u_upload_alloc(st->uploader, 0, 4 * sizeof(vertices[0]), 4,
                   &vb.buffer_offset, &vb.buffer,
                   (void **) &vertices);
    if (!vb.buffer) {
index a125d1f149e5217168e67feb74c6e0f0b21f9191..86e8a55e25e7dd233fb12f00a838da731b595b80 100644 (file)
@@ -457,7 +457,7 @@ draw_quad(struct gl_context *ctx, GLfloat x0, GLfloat y0, GLfloat z,
    struct pipe_resource *buf = NULL;
    unsigned offset;
 
-   u_upload_alloc(st->uploader, 0, 4 * sizeof(verts[0]), &offset,
+   u_upload_alloc(st->uploader, 0, 4 * sizeof(verts[0]), 4, &offset,
                   &buf, (void **) &verts);
    if (!buf) {
       return;
index 2634b09d777971e815007256d9f10f1f0b85e38d..b3e4b5bb70cd86d34083ef5c678a6d61d2661c96 100644 (file)
@@ -150,7 +150,7 @@ st_DrawTex(struct gl_context *ctx, GLfloat x, GLfloat y, GLfloat z,
       GLuint attr;
 
       u_upload_alloc(st->uploader, 0,
-                     numAttribs * 4 * 4 * sizeof(GLfloat),
+                     numAttribs * 4 * 4 * sizeof(GLfloat), 4,
                      &offset, &vbuffer, (void **) &vbuf);
       if (!vbuffer) {
          return;