Image Access in Compositor Backdrop is not thread-safe #118337
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
4 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#118337
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
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?
System Information
Operating system: Windows-10-10.0.19045-SP0 64 Bits
Graphics card: NVIDIA GeForce GTX 1070/PCIe/SSE2 NVIDIA Corporation 4.6.0 NVIDIA 537.58
Blender Version
Broken: version: 4.2.0 Alpha, branch: main, commit date: 2024-02-13 07:22, hash:
9ad127780af9
Worked: (in tiled mode)
Short description of error
Full frame compositor backdrop disappears during playback due to performance issue not present in tiled or GPU execution modes
Exact steps for others to reproduce the error
Blend file link: https://www.dropbox.com/scl/fi/uqt6ghyw6aw16j32ospvz/full-frame-mode-image-update-performance-issue.zip?rlkey=3urj9sbde7pesmpupg5dk0bzm&dl=0
For me the backdrop in Tiled mode is buttery smooth, GPU is strangely very slow, and Full frame is so slow that it can't display anything before the playhead moves to the next frame.
If I call render.render() after updating the image filepath, this will force the compositor to wait until the tree finishes processing before moving to the next frame. Strangely Full Frame mode is the fastest in this case, which suggests the issue isn't full frame being slower, but perhaps it not interacting with the backdrop as quickly? If you try this you'll need to avoid recursion by setting a variable preventing the handler to execute multiple times per frame, because the frame change handler also fires after rendering.
When trying to replicate the problem in the latest daily build, I found that neither Tiled nor Full Frame options are available. It appears that these modes were removed in a previous commit (
a8a05ebba1
). I'm not sure yet why this change was made (cc @Sergey).Regarding the issue you described, it seems that the backdrop not being able to compute the composition at the same time as the playback may not be considered a bug. The backdrop is not intended to be used for video playback.
If your intention is to request an improvement in performance, I'm afraid that potential performance improvements are not handled as bug reports. However, you can be assured that the developers are continuously working on improving performance in general.
Did I misunderstand the issue?
The tiled was removed on Monday, so you'll need to compare your build with a pre-monday build.
It affects addons with caching systems.
I think maybe it's a bug because it works in the old tiled mode and current GPU mode without issue. I don't think it's a performance improvement issue because the full frame is actually faster than tiled mode to process the tree.
oh sorry, I clicked the wrong button.
forgot to mention, it also affects the image editor.
@mano-wii This was done as part of #106533, https://devtalk.blender.org/t/improved-render-compositor-feedback-and-discussion/33377
Compositor is not really meant to be executed during playback, as it will not be able to keep up with the frame-rate. This is how regular animation is handling it: if you have animated property playback does not trigger compositing. Updating image path forces compositor to refresh, but it is more of a side-effect when is done from a frame-update handler. However, ideally I think would be if the preview image is not cleared when compositing is cancelled.
I gave it a dig in the code, and it seems that the
MultilayerBaseOperation::get_im_buf
is not thread-safe: it doesif (BKE_image_multilayer_index()) { /* acquire ibuf */ }
. TheBKE_image_multilayer_index
is not thread-safe, so if the image path is changed from a different thread it the call might access stale or null-ifiedimage_->rr
. Or, the path might be changed in-between of the index check and ibuf acquisition.I am not sure why do we even need the explicit check
BKE_image_multilayer_index
prior to theibuf
acquisition. It is safer to always callget_im_buf
, which will do thread-safeibuf
acquisition. There is still unsafe call toBKE_image_is_multilayer
in theget_im_buf
, which potentially might leads to issues if frame update handler changes image type, but that's a separate story from this report.@OmarEmaraDev Would be nice to have a second pair of eyes. Do you see anything potential issues if we do
?
@Sergey I will check myself. But immediately, just to clarify,
BKE_image_multilayer_index
setup themulti_index
in the image user, which is necessary as far as I can remember. So removing it might not side-effect free. But maybe I don't remember exactly, so I will take another look.@Sergey I took another look, and I don't think we can remove that function call, since it initialized the
multi_index
necessary to acquire the buffer.@OmarEmaraDev Ah, it looked like the
get_im_buf
sets themulti_index
, but it only does it for non-multilayer images.Ok, so we need to find a different way ensuring thread-safety of image access.
Full frame compositor backdrop disappears during playback. Issue not present in tiled or GPU execution modesto Image Access in Compositor Backdrop is not thread-safe@Sergey could this issue also cause the below error when trying to write to the image datablock after rendering completes?
bpy.data.scenes[scene_name].node_tree.nodes[cache_node_name].image.filepath = new_exr_path
Error:
Before attempting to update the image datablock's filepath, I'm ensuring the compositor and render have fully finished, and I'm launching the function from queue.queue() to make sure it's back on the main thread. I'm not sure why it's saying can't write in this context:
@3di It looks to me a separate issue. It might be that you're modifying an image from a non-main thread, while main thread is in a state where modification of IDs is not allowed. I don't fully understand this check for whether ID is allowed to be modified or not, and it probably worth submitting a separate issue about it. It might or might not leat to the same root issue, but it needs a separate investigation.
It would also be nice if you try to reproduce the
AttributeError
with Compositor disabled in the Post-processing settings.@Sergey thanks. I did create this report a while back #114455 (comment) , but at that time I thought it was because
is_job_running
was returning the incorrect result.The python code doesn't run until back in the main thread, because it's executed from queue.queue() which doesn't run until back in the main thread as I understand it. Perhaps Blender is incorrectly raising the error because it thinks it's not back in the main thread when it is?
It must be a difficult one to solve, because even jacques lucke couldn't fix it when he ran into the problem several years ago with his animation nodes addon.