Realtime Compositor: Support canceling evaluation #117725

Merged
Omar Emara merged 5 commits from OmarEmaraDev/blender:realtime-compositor-cancel into main 2024-02-16 08:32:12 +01:00
Member

This patch adds support for canceling compositor evaluations for the
realtime compositor. Inter-operation canceling is supported, while
intra-operation canceling is only supported for the denoise node.

This patch adds support for canceling compositor evaluations for the realtime compositor. Inter-operation canceling is supported, while intra-operation canceling is only supported for the denoise node.
Omar Emara added the
Interest
Compositing
Module
VFX & Video
labels 2024-02-01 14:53:20 +01:00
Omar Emara added 1 commit 2024-02-01 14:53:28 +01:00
2fe14044b8 Realtime Compositor: Support canceling evaluation
This patch adds support for canceling compositor evaluations for the
realtime compositor. Inter-operation canceling is supported, while
intra-operation canceling is only supported for the denoise node.
Author
Member

@Sergey This has no effect yet for the GPU compositor. I am still investigating why, but it seems to me that the only way to cancel the compositor is through the UI/keyboard events, which are blocked until the GPU compositor finishes, making cancelation handling have no effect. This seems to be the same issue you have been looking into with the DST? Except I am not sure why keyboard events are blocked as well.

@Sergey This has no effect yet for the GPU compositor. I am still investigating why, but it seems to me that the only way to cancel the compositor is through the UI/keyboard events, which are blocked until the GPU compositor finishes, making cancelation handling have no effect. This seems to be the same issue you have been looking into with the DST? Except I am not sure why keyboard events are blocked as well.

@OmarEmaraDev There is indeed the global lock, which prevents the entire event queue from being handled. It was on my list to look into. We should be able to avoid that lock for compositor, and you can probably prototype by commenting out mutex lock/unlock in DRW_system_gpu_render_context_enable/DRW_system_gpu_render_context_disable.

@OmarEmaraDev There is indeed the global lock, which prevents the entire event queue from being handled. It was on my list to look into. We should be able to avoid that lock for compositor, and you can probably prototype by commenting out mutex lock/unlock in `DRW_system_gpu_render_context_enable`/`DRW_system_gpu_render_context_disable`.
Author
Member

It seems to work for the denoise node, but not for other setups, so still needs further investigation, will get back to this patch later.

It seems to work for the denoise node, but not for other setups, so still needs further investigation, will get back to this patch later.
Omar Emara added 2 commits 2024-02-15 09:31:44 +01:00
Omar Emara added 1 commit 2024-02-15 10:28:59 +01:00
Omar Emara changed title from WIP: Realtime Compositor: Support canceling evaluation to Realtime Compositor: Support canceling evaluation 2024-02-15 10:33:58 +01:00
Author
Member

@Sergey So it appears we can't really cancel in the middle of evaluating the operations stream. That's because CPU side, we are just submitting work to the command stream, and practically all work will be submitted before the user is able cancel anything. And it doesn't seem like we have the ability to cancel dispatches that were already submitted.

So it seems to me that the only way to be able to cancel work is to call GPU_finish() and stall the CPU on each operation. Maybe we can only do it every few operation, only before operations that we expect to take a long time, or some other smarter way.

But in any case, I don't think it is something that we can do or investigate quickly in this pull request, so I have reverted inter-operation canceling for now, as this needs to be better thought out.

@Sergey So it appears we can't really cancel in the middle of evaluating the operations stream. That's because CPU side, we are just submitting work to the command stream, and practically all work will be submitted before the user is able cancel anything. And it doesn't seem like we have the ability to cancel dispatches that were already submitted. So it seems to me that the only way to be able to cancel work is to call `GPU_finish()` and stall the CPU on each operation. Maybe we can only do it every few operation, only before operations that we expect to take a long time, or some other smarter way. But in any case, I don't think it is something that we can do or investigate quickly in this pull request, so I have reverted inter-operation canceling for now, as this needs to be better thought out.
Sergey Sharybin approved these changes 2024-02-15 15:57:33 +01:00
Sergey Sharybin left a comment
Owner

Even if we start with just denoiser node, I think it is a great step. Denoiser is used quite often.

There is some minor points. The callback one I don't even immediatelly sure if we can use something else at this time. If no, we should go ahead with this change, and do bigger refactor outside if this improvement.

Even if we start with just denoiser node, I think it is a great step. Denoiser is used quite often. There is some minor points. The callback one I don't even immediatelly sure if we can use something else at this time. If no, we should go ahead with this change, and do bigger refactor outside if this improvement.
@ -25,1 +28,4 @@
bool Context::is_canceled() const
{
if (!get_node_tree().runtime->test_break) {

The new style guide says methods should use this->: https://developer.blender.org/docs/handbook/guidelines/c_cpp/#using-this-

So, this->get_node_tree().

P.S. Can't say I don't miss adding the explicit this->, but, you know, style guide... :)

The new style guide says methods should use `this->`: https://developer.blender.org/docs/handbook/guidelines/c_cpp/#using-this- So, `this->get_node_tree()`. P.S. Can't say I don't miss adding the explicit `this->`, but, you know, style guide... :)
OmarEmaraDev marked this conversation as resolved
@ -26,0 +31,4 @@
if (!get_node_tree().runtime->test_break) {
return false;
}
return get_node_tree().runtime->test_break(get_node_tree().runtime->tbh);

The test_break callback is considered legacy, and something to be moved out of the node tree (as the tree should be considered as instructions, not evaluation), but for the scope of this change I don't think we have anything more "modern". It is also something the CPU side of the compositor is using.

The `test_break` callback is considered legacy, and something to be moved out of the node tree (as the tree should be considered as instructions, not evaluation), but for the scope of this change I don't think we have anything more "modern". It is also something the CPU side of the compositor is using.
OmarEmaraDev marked this conversation as resolved
Omar Emara added 1 commit 2024-02-16 08:26:45 +01:00
Omar Emara merged commit e7ffe74920 into main 2024-02-16 08:32:12 +01:00
Omar Emara deleted branch realtime-compositor-cancel 2024-02-16 08:32:15 +01:00
Sign in to join this conversation.
No reviewers
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
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#117725
No description provided.