u_upload_mgr: optimize u_upload_alloc
This is probably the most called util function. It does almost nothing, yet it can consume 10% of the CPU on the profile. This drops it down to 5%. Reviewed-by: Brian Paul <brianp@vmware.com>
This commit is contained in:
parent
722ce74743
commit
6c1e368cf3
|
@ -186,37 +186,39 @@ enum pipe_error 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 alloc_size = align(size, upload->alignment);
|
||||||
unsigned alloc_offset = align(min_out_offset, upload->alignment);
|
unsigned alloc_offset = align(min_out_offset, upload->alignment);
|
||||||
|
unsigned buffer_size = upload->buffer ? upload->buffer->width0 : 0;
|
||||||
unsigned offset;
|
unsigned offset;
|
||||||
|
|
||||||
/* Init these return values here in case we fail below to make
|
|
||||||
* sure the caller doesn't get garbage values.
|
|
||||||
*/
|
|
||||||
*out_offset = ~0;
|
|
||||||
pipe_resource_reference(outbuf, NULL);
|
|
||||||
*ptr = NULL;
|
|
||||||
|
|
||||||
/* 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 (!upload->buffer ||
|
if (unlikely(MAX2(upload->offset, alloc_offset) + alloc_size > buffer_size)) {
|
||||||
MAX2(upload->offset, alloc_offset) + alloc_size > upload->buffer->width0) {
|
|
||||||
enum pipe_error ret = u_upload_alloc_buffer(upload,
|
enum pipe_error ret = u_upload_alloc_buffer(upload,
|
||||||
alloc_offset + alloc_size);
|
alloc_offset + alloc_size);
|
||||||
if (ret != PIPE_OK)
|
if (unlikely(ret != PIPE_OK)) {
|
||||||
|
*out_offset = ~0;
|
||||||
|
pipe_resource_reference(outbuf, NULL);
|
||||||
|
*ptr = NULL;
|
||||||
return ret;
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer_size = upload->buffer->width0;
|
||||||
}
|
}
|
||||||
|
|
||||||
offset = MAX2(upload->offset, alloc_offset);
|
offset = MAX2(upload->offset, alloc_offset);
|
||||||
|
|
||||||
if (!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,
|
||||||
upload->buffer->width0 - offset,
|
buffer_size - offset,
|
||||||
upload->map_flags,
|
upload->map_flags,
|
||||||
&upload->transfer);
|
&upload->transfer);
|
||||||
if (!upload->map) {
|
if (unlikely(!upload->map)) {
|
||||||
upload->transfer = NULL;
|
upload->transfer = NULL;
|
||||||
|
*out_offset = ~0;
|
||||||
|
pipe_resource_reference(outbuf, NULL);
|
||||||
|
*ptr = NULL;
|
||||||
return PIPE_ERROR_OUT_OF_MEMORY;
|
return PIPE_ERROR_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -229,7 +231,7 @@ enum pipe_error u_upload_alloc( struct u_upload_mgr *upload,
|
||||||
|
|
||||||
/* Emit the return values: */
|
/* Emit the return values: */
|
||||||
*ptr = upload->map + offset;
|
*ptr = upload->map + offset;
|
||||||
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 + alloc_size;
|
||||||
|
|
Loading…
Reference in New Issue