summaryrefslogtreecommitdiffstats
path: root/src/gallium/auxiliary/util
diff options
context:
space:
mode:
authorMarek Olšák <[email protected]>2015-09-02 14:57:55 +0200
committerMarek Olšák <[email protected]>2015-09-03 18:09:13 +0200
commit6c1e368cf38e02174a8c88218ae711ab0b27954f (patch)
tree7e068f4b24ff81de19063bb36a541ece0ae7f2f0 /src/gallium/auxiliary/util
parent722ce747436f5b9c79d1fa4a8c59eed2f9cb611b (diff)
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 <[email protected]>
Diffstat (limited to 'src/gallium/auxiliary/util')
-rw-r--r--src/gallium/auxiliary/util/u_upload_mgr.c32
1 files changed, 17 insertions, 15 deletions
diff --git a/src/gallium/auxiliary/util/u_upload_mgr.c b/src/gallium/auxiliary/util/u_upload_mgr.c
index 744ea2e5e0c..4c560848e87 100644
--- a/src/gallium/auxiliary/util/u_upload_mgr.c
+++ b/src/gallium/auxiliary/util/u_upload_mgr.c
@@ -186,37 +186,39 @@ enum pipe_error u_upload_alloc( struct u_upload_mgr *upload,
struct pipe_resource **outbuf,
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 buffer_size = upload->buffer ? upload->buffer->width0 : 0;
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
* for the sub-allocation. */
- if (!upload->buffer ||
- MAX2(upload->offset, alloc_offset) + alloc_size > upload->buffer->width0) {
+ if (unlikely(MAX2(upload->offset, alloc_offset) + alloc_size > buffer_size)) {
enum pipe_error ret = u_upload_alloc_buffer(upload,
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;
+ }
+
+ buffer_size = upload->buffer->width0;
}
offset = MAX2(upload->offset, alloc_offset);
- if (!upload->map) {
+ if (unlikely(!upload->map)) {
upload->map = pipe_buffer_map_range(upload->pipe, upload->buffer,
offset,
- upload->buffer->width0 - offset,
+ buffer_size - offset,
upload->map_flags,
&upload->transfer);
- if (!upload->map) {
+ if (unlikely(!upload->map)) {
upload->transfer = NULL;
+ *out_offset = ~0;
+ pipe_resource_reference(outbuf, NULL);
+ *ptr = NULL;
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: */
*ptr = upload->map + offset;
- pipe_resource_reference( outbuf, upload->buffer );
+ pipe_resource_reference(outbuf, upload->buffer);
*out_offset = offset;
upload->offset = offset + alloc_size;