mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-06 02:58:05 +02:00
gallium/u_upload_mgr: lower risk of hitting an assert
The assert(size < INT32_MAX / 2) can be triggered by large uploads.
Since we know that the caller of u_upload_alloc_buffer will consume
min_size bytes, we can init buffer_private_refcount to a much smaller
value.
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Fixes: ccf9ef3628 ("gallium/u_upload_mgr: eliminate all atomics for the upload buffer")
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/4235
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8880>
This commit is contained in:
parent
d81087a700
commit
c7725ad4aa
1 changed files with 8 additions and 3 deletions
|
|
@ -227,10 +227,14 @@ u_upload_alloc_buffer(struct u_upload_mgr *upload, unsigned min_size)
|
|||
* before the buffer is unreferenced.
|
||||
*
|
||||
* This technique can increase CPU performance by 10%.
|
||||
*
|
||||
* The caller of u_upload_alloc_buffer will consume min_size bytes,
|
||||
* so init the buffer_private_refcount to 1 + size - min_size, instead
|
||||
* of size to avoid overflowing reference.count when size is huge.
|
||||
*/
|
||||
assert(size < INT32_MAX / 2); /* prevent overflows of reference.count */
|
||||
p_atomic_add(&upload->buffer->reference.count, size);
|
||||
upload->buffer_private_refcount = size;
|
||||
upload->buffer_private_refcount = 1 + (size - min_size);
|
||||
assert(upload->buffer_private_refcount < INT32_MAX / 2);
|
||||
p_atomic_add(&upload->buffer->reference.count, upload->buffer_private_refcount);
|
||||
|
||||
/* Map the new buffer. */
|
||||
upload->map = pipe_buffer_map_range(upload->pipe, upload->buffer,
|
||||
|
|
@ -304,6 +308,7 @@ u_upload_alloc(struct u_upload_mgr *upload,
|
|||
if (*outbuf != upload->buffer) {
|
||||
pipe_resource_reference(outbuf, NULL);
|
||||
*outbuf = upload->buffer;
|
||||
assert (upload->buffer_private_refcount > 0);
|
||||
upload->buffer_private_refcount--;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue