summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/gallium/auxiliary/util/u_upload_mgr.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/src/gallium/auxiliary/util/u_upload_mgr.c b/src/gallium/auxiliary/util/u_upload_mgr.c
index 4ac468524d8..c199ad0edf1 100644
--- a/src/gallium/auxiliary/util/u_upload_mgr.c
+++ b/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;
@@ -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,7 +243,7 @@ u_upload_alloc(struct u_upload_mgr *upload,
struct pipe_resource **outbuf,
void **ptr)
{
- unsigned buffer_size = upload->buffer ? upload->buffer->width0 : 0;
+ unsigned buffer_size = upload->buffer_size;
unsigned offset;
min_out_offset = align(min_out_offset, alignment);
@@ -250,10 +254,10 @@ u_upload_alloc(struct u_upload_mgr *upload,
/* 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)) {
+ buffer_size = u_upload_alloc_buffer(upload, min_out_offset + size);
- if (unlikely(!upload->buffer)) {
+ if (unlikely(!buffer_size)) {
*out_offset = ~0;
pipe_resource_reference(outbuf, NULL);
*ptr = NULL;
@@ -261,7 +265,6 @@ u_upload_alloc(struct u_upload_mgr *upload,
}
offset = min_out_offset;
- buffer_size = upload->buffer->width0;
}
if (unlikely(!upload->map)) {