diff options
author | Jonathan Gray <jsg@cvs.openbsd.org> | 2020-08-26 06:03:18 +0000 |
---|---|---|
committer | Jonathan Gray <jsg@cvs.openbsd.org> | 2020-08-26 06:03:18 +0000 |
commit | af5e8f5366b05c3d4f8521f318c143a5c5dc3ea9 (patch) | |
tree | c5691445908b1beca9facf0e5e3c5d7f35f74228 /lib/mesa/src/gallium/auxiliary/util/u_upload_mgr.c | |
parent | 27c93456b58343162f7c4ad20ca6bea0c9a91646 (diff) |
Merge Mesa 20.1.6
Diffstat (limited to 'lib/mesa/src/gallium/auxiliary/util/u_upload_mgr.c')
-rw-r--r-- | lib/mesa/src/gallium/auxiliary/util/u_upload_mgr.c | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/lib/mesa/src/gallium/auxiliary/util/u_upload_mgr.c b/lib/mesa/src/gallium/auxiliary/util/u_upload_mgr.c index 73f6cae0b..375fad005 100644 --- a/lib/mesa/src/gallium/auxiliary/util/u_upload_mgr.c +++ b/lib/mesa/src/gallium/auxiliary/util/u_upload_mgr.c @@ -51,6 +51,7 @@ struct u_upload_mgr { struct pipe_resource *buffer; /* Upload buffer. */ struct pipe_transfer *transfer; /* Transfer object for the upload buffer. */ uint8_t *map; /* Pointer to the mapped upload buffer. */ + unsigned buffer_size; /* Same as buffer->width0. */ unsigned offset; /* Aligned offset to the upload buffer, pointing * at the first unused byte. */ unsigned flushed_size; /* Size we have flushed by transfer_flush_region. */ @@ -171,6 +172,7 @@ u_upload_release_buffer(struct u_upload_mgr *upload) /* Unmap and unreference the upload buffer. */ upload_unmap_internal(upload, TRUE); pipe_resource_reference(&upload->buffer, NULL); + upload->buffer_size = 0; } @@ -181,8 +183,8 @@ u_upload_destroy(struct u_upload_mgr *upload) FREE(upload); } - -static void +/* Return the allocated buffer size or 0 if it failed. */ +static unsigned u_upload_alloc_buffer(struct u_upload_mgr *upload, unsigned min_size) { struct pipe_screen *screen = upload->pipe->screen; @@ -202,7 +204,7 @@ u_upload_alloc_buffer(struct u_upload_mgr *upload, unsigned min_size) buffer.format = PIPE_FORMAT_R8_UNORM; /* want TYPELESS or similar */ buffer.bind = upload->bind; buffer.usage = upload->usage; - buffer.flags = upload->flags; + buffer.flags = upload->flags | PIPE_RESOURCE_FLAG_SINGLE_THREAD_USE; buffer.width0 = size; buffer.height0 = 1; buffer.depth0 = 1; @@ -215,7 +217,7 @@ u_upload_alloc_buffer(struct u_upload_mgr *upload, unsigned min_size) upload->buffer = screen->resource_create(screen, &buffer); if (upload->buffer == NULL) - return; + return 0; /* Map the new buffer. */ upload->map = pipe_buffer_map_range(upload->pipe, upload->buffer, @@ -224,10 +226,12 @@ u_upload_alloc_buffer(struct u_upload_mgr *upload, unsigned min_size) if (upload->map == NULL) { upload->transfer = NULL; pipe_resource_reference(&upload->buffer, NULL); - return; + return 0; } + upload->buffer_size = size; upload->offset = 0; + return size; } void @@ -239,29 +243,25 @@ u_upload_alloc(struct u_upload_mgr *upload, struct pipe_resource **outbuf, void **ptr) { - unsigned buffer_size = upload->buffer ? upload->buffer->width0 : 0; - unsigned offset; - - min_out_offset = align(min_out_offset, alignment); + unsigned buffer_size = upload->buffer_size; + unsigned offset = MAX2(min_out_offset, upload->offset); - offset = align(upload->offset, alignment); - offset = MAX2(offset, min_out_offset); + offset = align(offset, alignment); /* Make sure we have enough space in the upload buffer * for the sub-allocation. */ - if (unlikely(!upload->buffer || offset + size > buffer_size)) { - u_upload_alloc_buffer(upload, min_out_offset + size); + if (unlikely(offset + size > buffer_size)) { + /* Allocate a new buffer and set the offset to the smallest one. */ + offset = align(min_out_offset, alignment); + buffer_size = u_upload_alloc_buffer(upload, offset + size); - if (unlikely(!upload->buffer)) { + if (unlikely(!buffer_size)) { *out_offset = ~0; pipe_resource_reference(outbuf, NULL); *ptr = NULL; return; } - - offset = min_out_offset; - buffer_size = upload->buffer->width0; } if (unlikely(!upload->map)) { |