u_upload_mgr: rework the application of alignment
The function only aligned the size, but not the offset. The offset was aligned only when the previous suballocation was aligned. That yielded the correct offset alignment if the alignment was constant for all suballocations. Instead, directly align the offset, but allow an unaligned size. There is no change in behavior, because the alignment is constant at the moment. This a prerequisite for allowing a variable alignment for suballocations. Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
This commit is contained in:
parent
36c93a6fae
commit
ffc4716e97
|
@ -185,15 +185,20 @@ u_upload_alloc(struct u_upload_mgr *upload,
|
||||||
struct pipe_resource **outbuf,
|
struct pipe_resource **outbuf,
|
||||||
void **ptr)
|
void **ptr)
|
||||||
{
|
{
|
||||||
unsigned alloc_size = align(size, upload->alignment);
|
unsigned alignment = upload->alignment;
|
||||||
unsigned alloc_offset = align(min_out_offset, upload->alignment);
|
|
||||||
unsigned buffer_size = upload->buffer ? upload->buffer->width0 : 0;
|
unsigned buffer_size = upload->buffer ? upload->buffer->width0 : 0;
|
||||||
unsigned offset;
|
unsigned offset;
|
||||||
|
|
||||||
|
min_out_offset = align(min_out_offset, alignment);
|
||||||
|
|
||||||
|
offset = align(upload->offset, alignment);
|
||||||
|
offset = MAX2(offset, min_out_offset);
|
||||||
|
|
||||||
/* Make sure we have enough space in the upload buffer
|
/* Make sure we have enough space in the upload buffer
|
||||||
* for the sub-allocation. */
|
* for the sub-allocation.
|
||||||
if (unlikely(MAX2(upload->offset, alloc_offset) + alloc_size > buffer_size)) {
|
*/
|
||||||
u_upload_alloc_buffer(upload, alloc_offset + alloc_size);
|
if (unlikely(!upload->buffer || offset + size > buffer_size)) {
|
||||||
|
u_upload_alloc_buffer(upload, min_out_offset + size);
|
||||||
|
|
||||||
if (unlikely(!upload->buffer)) {
|
if (unlikely(!upload->buffer)) {
|
||||||
*out_offset = ~0;
|
*out_offset = ~0;
|
||||||
|
@ -202,11 +207,10 @@ u_upload_alloc(struct u_upload_mgr *upload,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
offset = min_out_offset;
|
||||||
buffer_size = upload->buffer->width0;
|
buffer_size = upload->buffer->width0;
|
||||||
}
|
}
|
||||||
|
|
||||||
offset = MAX2(upload->offset, alloc_offset);
|
|
||||||
|
|
||||||
if (unlikely(!upload->map)) {
|
if (unlikely(!upload->map)) {
|
||||||
upload->map = pipe_buffer_map_range(upload->pipe, upload->buffer,
|
upload->map = pipe_buffer_map_range(upload->pipe, upload->buffer,
|
||||||
offset,
|
offset,
|
||||||
|
@ -224,8 +228,8 @@ u_upload_alloc(struct u_upload_mgr *upload,
|
||||||
upload->map -= offset;
|
upload->map -= offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(offset < upload->buffer->width0);
|
assert(offset < buffer_size);
|
||||||
assert(offset + size <= upload->buffer->width0);
|
assert(offset + size <= buffer_size);
|
||||||
assert(size);
|
assert(size);
|
||||||
|
|
||||||
/* Emit the return values: */
|
/* Emit the return values: */
|
||||||
|
@ -233,7 +237,7 @@ u_upload_alloc(struct u_upload_mgr *upload,
|
||||||
pipe_resource_reference(outbuf, upload->buffer);
|
pipe_resource_reference(outbuf, upload->buffer);
|
||||||
*out_offset = offset;
|
*out_offset = offset;
|
||||||
|
|
||||||
upload->offset = offset + alloc_size;
|
upload->offset = offset + size;
|
||||||
}
|
}
|
||||||
|
|
||||||
void u_upload_data(struct u_upload_mgr *upload,
|
void u_upload_data(struct u_upload_mgr *upload,
|
||||||
|
|
Loading…
Reference in New Issue