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. */
/* Unmap and unreference the upload buffer. */
upload_unmap_internal(upload, TRUE);
pipe_resource_reference(&upload->buffer, NULL);
+ upload->buffer_size = 0;
}
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;
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,
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
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);
/* 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;
}
offset = min_out_offset;
- buffer_size = upload->buffer->width0;
}
if (unlikely(!upload->map)) {