Compositor: Enable lock-free GPU context activation on macOS #118920

Merged
Sergey Sharybin merged 1 commits from Sergey/blender:compositor_gpu_metal into main 2024-03-01 14:38:21 +01:00

This required to apply a small fix in the Metal texture uploader.

Without synchronization pixels of a wrong pass can be uploaded to
a wrong texture. This is because this code path is heavily reusing
temporary allocations, and at some point the allocation is not
considered as still in use, unless the command buffer used by the
texture uploader is submitted.

Ref #118919

This required to apply a small fix in the Metal texture uploader. Without synchronization pixels of a wrong pass can be uploaded to a wrong texture. This is because this code path is heavily reusing temporary allocations, and at some point the allocation is not considered as still in use, unless the command buffer used by the texture uploader is submitted. Ref #118919
Sergey Sharybin added 1 commit 2024-02-29 18:25:58 +01:00
This required to apply a small fix in the Metal texture uploader.

Without synchronization pixels of a wrong pass can be uploaded to
a wrong texture. This is because this code path is heavily reusing
temporary allocations, and at some point the allocation is not
considered as still in use, unless the command buffer used by the
texture uploader is submitted.

Ref #118919
Sergey Sharybin requested review from Clément Foucault 2024-02-29 18:26:10 +01:00
Aras Pranckevicius reviewed 2024-03-01 08:18:57 +01:00
@ -1125,2 +1125,4 @@
ctx->main_command_buffer.submit(false);
/* Release temporary staging buffer allocation.
* NOTE: Allocation will be tracked with command submission and released once no longer in use.

The comment wrt command buffer submission is probably outdated now, given that the cmdbuf was just submitted right above?

The comment wrt command buffer submission is probably outdated now, given that the cmdbuf was just submitted right above?
Author
Owner

I do not think it is outdated. You submit command, and it tracks allocation, so it is safe to free memory here. So you need to submit in order to make the allocation tracked.

I do not think it is outdated. You submit command, and it tracks allocation, so it is safe to free memory here. So you need to submit in order to make the allocation tracked.
First-time contributor

FYI on this, texture::update_sub is called quite a lot, and having a command buffer flush here may negatively impact performance. It will also prevent multiple subsequent texture updates being batched together and optimized by the driver/GPU workload scheduler.

However, given the cause of the original issue, if this is fixing a missing GPU_flush, then we should ideally be able to either insert that at the high level in the problem code, or look into why this was happening in the first place. i.e. perhaps a later function requires a flush which is not happening.

Regarding the memory, this should not matter either way as if the buffer is used by any command buffer, the command buffer instance will retain a reference to any used memory. Freeing the buffer reference on host can be done safely in any case.

I can have a look into this however, if this does indeed resolve the issue.

FYI on this, texture::update_sub is called quite a lot, and having a command buffer flush here may negatively impact performance. It will also prevent multiple subsequent texture updates being batched together and optimized by the driver/GPU workload scheduler. However, given the cause of the original issue, if this is fixing a missing GPU_flush, then we should ideally be able to either insert that at the high level in the problem code, or look into why this was happening in the first place. i.e. perhaps a later function requires a flush which is not happening. Regarding the memory, this should not matter either way as if the buffer is used by any command buffer, the command buffer instance will retain a reference to any used memory. Freeing the buffer reference on host can be done safely in any case. I can have a look into this however, if this does indeed resolve the issue.
Clément Foucault approved these changes 2024-03-01 12:38:22 +01:00
Clément Foucault left a comment
Member

I approve but this might backfire at some point. Just tagging @Michael-Parkin-White-Apple

I approve but this might backfire at some point. Just tagging @Michael-Parkin-White-Apple
Sergey Sharybin merged commit 3fcd7ccbc0 into main 2024-03-01 14:38:21 +01:00
Sergey Sharybin deleted branch compositor_gpu_metal 2024-03-01 14:38:24 +01:00
Author
Owner

@Michael-Parkin-White-Apple In case you'd looking into deeper details, the file to reproduce the original issue can be found in #118919. You don't need to modify code anymore to make the GPU compositor lock-free. Just Ctrl-Click on the image input node to plug the viewer and pan the editor to force some ascynhronous GPU use.

@Michael-Parkin-White-Apple In case you'd looking into deeper details, the file to reproduce the original issue can be found in #118919. You don't need to modify code anymore to make the GPU compositor lock-free. Just Ctrl-Click on the image input node to plug the viewer and pan the editor to force some ascynhronous GPU use.
Sign in to join this conversation.
No reviewers
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
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
Viewport & EEVEE
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
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
Module
Viewport & EEVEE
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Severity
High
Severity
Low
Severity
Normal
Severity
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
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#118920
No description provided.