VSE: Add anim manager #118670
No reviewers
Labels
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
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
Asset Browser Project
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
6 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#118670
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "iss/blender:anim-sharing-2"
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?
When playing back composition in VSE consisting of multiple movie
strips, there is noticable delay when first frame of movie strip is
displayed. This happens, because anim(
ImBufAnim
) is being loaded.Anims consume quite a bit of memory - about 100MB per strip, so they are
freed as soon as they are not needed for drawing preview.
This patch implements cache for anims, so that multiple strips can reuse
this resource and anim prefetching, which loads anims in background.
Delays during playback are mainly reduced by prefetching. Cache is used
for resource sharing and minimizing of memory usage (about 5x in test
file based on Gold edit).
There are 2 classes that implements this functionality:
AnimManager
is interfacing with VSE code. It provides access to stripanims. This is done with functions
strip_anims_acquire()
, whichcauses, that anims will be locked, so they have to be unlocked by
strip_anims_release()
. It implements prefetching and freeing of"unused" anims -
manage_anims()
. And finally it owns the anim cache.ShareableAnim
is wrapper ofImBufAnim
. It implements loading andfreeing of anims, on lower level. To facilitate sharing, it does user
counting. It supports multiview setups by storing vector of anims.
These are stored in order of how they are assigned to the strip. So
setups where one of strips which use same input file can be set up as
multiview while another is single view.
DNA
Sequence::anims
field is marked as deprecated.On user level, Prefetching does load anims of all strips that are closer
than 512 frames to current frame. Anims of all other strips are freed.
Prefetching and freeing does not happen when user is scrubbing.
WIP: VSE: share ImBufAnim resource between stripsto VSE: share ImBufAnim resource between stripsVSE: share ImBufAnim resource between stripsto [WIP] VSE: share ImBufAnim resource between stripsNote to self: The manager has to only prefetch anims. Strips need to acquire anim in main thread, because they are freed by depshraph.
[WIP] VSE: share ImBufAnim resource between stripsto WIP: VSE: share ImBufAnim resource between stripsstrip_anims_acquire()
2368a1381frna_MovieSequence_metadata_get()
8c2c431b3aWIP: VSE: share ImBufAnim resource between stripsto VSE: share ImBufAnim resource between stripsgit mv
apparently does not stage new file 68ab8cbc4cVSE: share ImBufAnim resource between stripsto VSE: Add anim managerDoes all of this effectively resolve issue #118155?
@ -31,10 +31,13 @@ struct bSound;
#ifdef __cplusplus
namespace blender::seq {
struct MediaPresence;
struct AnimManager;
Visual Studio emits a bunch of warnings about this, the issue being that there it is
struct AnimManager
but in the actual file it isclass AnimManager
@ -0,0 +308,4 @@
for (int i : range) {
Sequence *seq = strips[i];
ShareableAnim &sh_anim = this->cache_entry_get(scene, seq);
sh_anim.mutex->lock();
While trying to test this out, I get a hang here. My test file contained two video tracks on top of each other, both referencing the same file. The hang happens when starting preview playback.
I'm on Windows, what seems to happen is that the ShareableAnim mutex that is tried to get locked here, is actually held by some thread that is already gone. I.e. some thread was apparently spawned, locked the mutex and finished without unlocking it.
@ -0,0 +1,74 @@
/* SPDX-FileCopyrightText: 2024 Blender Authors
Not related to this particular place, just wanted to raise as an issue: I consistenly get a crash when trying to drag and drop any video file into the VSE timeline, in a default empty video project.
What seems to happen is some sort of memory corruption when cleaning up some thread (not sure which one, as it already finished executing any user code and is about to wrap up at CRT/OS level). Another Blender related thread is doing
sequencer_drag_drop.cc
prefetch_data_fn
, this bit:@ -0,0 +21,4 @@
public:
blender::Vector<ImBufAnim *> anims; /* Ordered by view_id. */
blender::Set<Sequence *> users;
std::unique_ptr<std::mutex> mutex = std::make_unique<std::mutex>();
Wondering why this mutex is
std::unique_ptr<std::mutex>
and not just a mutex member, i.e.std::mutex
?As far as you don't overwhelm prefetching thread, then yes. 100% solution would be to load all data in advance and never free them. So technically this is compromise, that should cover reasonable scenarios.
Thanks for review, I see there are issues still, will have to look at these after next week, as next week I will have time off.
@blender-bot package
Package build started. Download here when ready.
I don't see a macOS build. Should it build again?
@blender-bot package
Package build started. Download here when ready.
@ -0,0 +24,4 @@
std::unique_ptr<std::mutex> mutex = std::make_unique<std::mutex>();
void release_from_strip(Sequence *seq);
void release_from_all_strips(void);
release_from_all_strips(void)
->release_from_all_strips()
@ -0,0 +42,4 @@
/**
* Load anims used by strips and lock them so they won't be freed.
*/
void strip_anims_acquire(const Scene *scene, blender::Vector<Sequence *> strips);
blender::Vector<Sequence *> &r_strips
@ -0,0 +52,4 @@
/**
* Get anims used by `seq`.
*/
blender::Vector<ImBufAnim *> &strip_anims_get(const Scene *scene, const Sequence *seq);
Result should be by value.
@ -0,0 +173,4 @@
}
if (is_multiview(scene, seq)) {
blender::Vector<ImBufAnim *> new_anims = multiview_anims_get(
Should be const
@ -0,0 +187,4 @@
}
}
for (int i = 0; i < this->anims.size(); i++) {
for (const int i : this->anims.index_range())
@ -0,0 +222,4 @@
return false;
});
blender::Vector<Sequence *> strips_sorted = strips.as_span();
strips_sorted = strips;
@ -0,0 +305,4 @@
strips = remove_duplicates_for_parallel_load(scene, strips);
threading::parallel_for(strips.index_range(), 1, [&](const IndexRange range) {
for (int i : range) {
const int i : range
@ -0,0 +310,4 @@
ShareableAnim &sh_anim = this->cache_entry_get(scene, seq);
sh_anim.mutex->lock();
sh_anim.acquire_anims(scene, seq);
Just for record, its much better to just use
EnumerableThreadSpecific
to accumulate elements from different threads and in result just move all of them into class fields instead of have mutex just for that.@ -372,0 +378,4 @@
AnimManager *manager = seq_anim_manager_ensure(SEQ_editing_get(scene));
manager->strip_anims_acquire(scene, seq);
blender::Vector<ImBufAnim *> anims = manager->strip_anims_get(scene, seq);
int count = anims.size();
const int count
@ -1239,1 +1248,3 @@
BLI_listbase_count_at_most(&seq->anims, totfiles + 1) == totfiles;
std::min(anim_count, totfiles + 1) == totfiles;
if (anims.size() == 0) {
is_empty()
Checkout
From your project repository, check out a new branch and test the changes.