Fix #114742: Draw: Buffers never shrink #114857
No reviewers
Labels
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#114857
Loading…
Reference in New Issue
No description provided.
Delete Branch "pragma37/blender:pull-draw-memory-housekeeping"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The buffers from the new Draw Manager increase their size as needed, but they never shrink.
This adds a new
optimize_size
function toStorageArrayBuffer
that can downsize the buffer following the same heuristic asget_or_resize
. And applies it automatically onStorageVectorBuffer::clear()
.Notes:
It may be best to use
StorageVectorBuffer
where possible, so this can be handled in a more automatic and error-proof way.The way this is handled may cause a performance loss if the number of objects is always changing in the scene in a way that causes resizes every frame. It may be best to leave more room for
max_size
even if that means increasing memory use?For example:
size_t max_size = power_of_2_max_u(required_size * 2);
Also, in the case of
StorageVectorBuffer::push_update()
we should only push up toitem_len_
. But that may be best left for 4.1.2c856692d1
to4b1defa78d
@blender-bot package
Package build started. Download here when ready.
I think the heuristic would be to use a hysteresis threshold in the draw manager itself since the counts are stored there.
Usually, try following what the BLI Vector API does in terms of convention.
We cannot use
StorageVectorBuffer
since it would mean all items in it are stored contiguously which might not the case of most of the draw manager buffers (some buffers have holes IIRC).@ -367,2 +367,4 @@
}
/* Downsize the buffer if current size is much larger than the required size. */
void optimize_size(int64_t required_size)
Rename to
resize_to_next_power_of_2(int64_t new_size)
.Don't forget to remove the check. There is already a check in
resize()
if size doesn't change.But that could actually grow the buffer if it was resized manually.
Also, I think we may want to eventually use a different heuristic.
At some point, twice the size can be just too much.
If the user set the size directly then it there's no incentive to use
optimize_size
. Theresize_to_next_power_of_2
is just to use the same heuristic asget_or_resize
.I think we could make it linear after a certain point, but that would require more testing in order to judge what are the best values.
@ -404,0 +412,4 @@
* Set item count to zero.
* If do_optimize_size is true, it may resize the buffer,
* but never to a capacity less than the current count.
* Otherwise it wont not free memory or resize the buffer.
Double negation.
@ -404,2 +415,3 @@
* Otherwise it wont not free memory or resize the buffer.
*/
void clear()
void clear(bool do_optimize_size = true)
Use
clear_and_trim()
for function name. Split to another function for better semantic and to avoid bugs caused by the change of behavior (but does not free memory or resize the buffer
is vastly different fromit may resize the buffer
).Change the usage on a per case basis (in separate commits to allow bisecting) and validate it works fine.
@ -543,2 +546,4 @@
void clear()
{
group_buf_.optimize_size(group_count_);
command_buf_.optimize_size(group_count_ * 2);
This
group_count_ * 2
is not explained and not obvious.Fix #114742: Draw: Buffers never shrinkto Fix #114742: Draw: Buffers never shrink90b9c45e58
to1a775040a8