Cycles: Metal support for OpenImageDenoise #116124

Merged
Brecht Van Lommel merged 10 commits from Stefan_Werner/blender:oidn_metal into main 2024-02-06 21:13:33 +01:00
Member

Enabling the Metal backend In OpenImageDenoise.

Enabling the Metal backend In OpenImageDenoise.
Stefan Werner added 2 commits 2023-12-13 08:07:33 +01:00
Author
Member

WIP label is here because this patch requires a public release of a version of OpenImageDenoise with built-in Metal support. The build_environment CMake script in this PR is still pointing at the 2.1.0 URL and hash and needs to be updated once the release is out.

WIP label is here because this patch requires a public release of a version of OpenImageDenoise with built-in Metal support. The build_environment CMake script in this PR is still pointing at the 2.1.0 URL and hash and needs to be updated once the release is out.
Xavier Hallade reviewed 2023-12-13 13:54:21 +01:00
@ -14,6 +14,7 @@ if(NOT APPLE)
${OIDN_EXTRA_ARGS}
-DOIDN_DEVICE_SYCL=ON
-DOIDN_DEVICE_SYCL_AOT=OFF
-DOIDN_DEVICE_METAL=ON
Member

if(NOT APPLE) block doesn't seem to be the correct location for this setting :)

`if(NOT APPLE)` block doesn't seem to be the correct location for this setting :)
Author
Member

True.

True.
brecht marked this conversation as resolved
Contributor

Since OIDN 2.2 with Metal support is out (9db3b38d50), we should move forward with this PR.

Since OIDN 2.2 with Metal support is out (https://github.com/OpenImageDenoise/oidn/tree/9db3b38d50c86fb4585ac54a6dbf87ef6399ffc2), we should move forward with this PR.
Brecht Van Lommel added 2 commits 2024-02-02 19:42:35 +01:00
Brecht Van Lommel changed title from WIP: Metal support for OIDN to Cycles: Metal support for OpenImageDenoise 2024-02-02 19:43:14 +01:00
Brecht Van Lommel added 1 commit 2024-02-02 19:44:52 +01:00
Brecht Van Lommel requested changes 2024-02-02 19:49:56 +01:00
Brecht Van Lommel left a comment
Owner

I have committed new macOS Arm libraries with OIDN metal support.

I'm getting an error when trying this in the viewport:

image data not accessible by the device, please use OIDNBuffer or device allocator for storage

Also an assert when stopping viewport render:

Assertion failed: (mtlCommandBuffer_ == nil), function ~MetalDeviceQueue, file queue.mm, line 205.
I have committed new macOS Arm libraries with OIDN metal support. I'm getting an error when trying this in the viewport: ``` image data not accessible by the device, please use OIDNBuffer or device allocator for storage ``` Also an assert when stopping viewport render: ``` Assertion failed: (mtlCommandBuffer_ == nil), function ~MetalDeviceQueue, file queue.mm, line 205. ```
Contributor

This PR seems to be incomplete. The Metal backend doesn't support pointers, buffers must be used instead. This logic is missing from the code.

This PR seems to be incomplete. The Metal backend doesn't support pointers, buffers must be used instead. This logic is missing from the code.
Contributor

Here's a fix: bcd2f39a81

The only remaining issue is that I had to disable the following workaround because OIDN doesn't support managed Metal buffers yet:
82942c7f2a/intern/cycles/device/metal/device_impl.mm (L729)

Is this workaround still needed? If it is, I could fix this in OIDN very quickly (today) but we'll then need to create a new release candidate.

Here's a fix: https://projects.blender.org/aafra/blender/commit/bcd2f39a81ad5097cc835e506793e3b5417ac4ea The only remaining issue is that I had to disable the following workaround because OIDN doesn't support managed Metal buffers yet: https://projects.blender.org/aafra/blender/src/commit/82942c7f2a88931d46939b84a212a21793f2a965/intern/cycles/device/metal/device_impl.mm#L729 Is this workaround still needed? If it is, I could fix this in OIDN very quickly (today) but we'll then need to create a new release candidate.
Stefan Werner added 3 commits 2024-02-05 09:54:27 +01:00
buildbot/vexp-code-patch-linux-x86_64 Build done. Details
buildbot/vexp-code-patch-windows-amd64 Build done. Details
buildbot/vexp-code-patch-lint Build done. Details
buildbot/vexp-code-patch-darwin-x86_64 Build done. Details
buildbot/vexp-code-patch-darwin-arm64 Build done. Details
buildbot/vexp-code-patch-coordinator Build done. Details
01078acff6
Merge commit 'bcd2f39a81ad5097cc835e506793e3b5417ac4ea' into oidn_metal
Author
Member

I merged the patch from @aafra into this PR.

I merged the patch from @aafra into this PR.

@aafra I would prefer to keep the workaround if we can, we haven't really raised our macOS version and GPU minimum requirements since that workaround was made, so it could still affect someone.

We can also apply a patch on our side if needed.

@aafra I would prefer to keep the workaround if we can, we haven't really raised our macOS version and GPU minimum requirements since that workaround was made, so it could still affect someone. We can also apply a patch on our side if needed.
Contributor

@brecht Do you know which GPUs or macOS versions actually need this workaround? OIDN supports Metal only on Apple silicon and macOS Ventura and later, so the workaround could be disabled only in these cases. It would be quite strange if M chips with unified memory would require managed memory for anything.

@brecht Do you know which GPUs or macOS versions actually need this workaround? OIDN supports Metal only on Apple silicon and macOS Ventura and later, so the workaround could be disabled only in these cases. It would be quite strange if M chips with unified memory would require managed memory for anything.

I'm not sure, maybe @Michael-Jones remembers. The commit message does not mention it.

The buildbot uses an M1 and macOS Ventura (13.x), so we'll see if the baking tests still fail.

@blender-bot build macos

I'm not sure, maybe @Michael-Jones remembers. The commit message does not mention it. The buildbot uses an M1 and macOS Ventura (13.x), so we'll see if the baking tests still fail. @blender-bot build macos

I'm not sure, maybe @Michael-Jones remembers. The commit message does not mention it.

I did a few test runs with that workaround removed on the 4.0 release branch, and the tests all still passed. It never really made sense why we needed it in the first place, so other than it being a mystery I think it should be safe to remove

> I'm not sure, maybe @Michael-Jones remembers. The commit message does not mention it. I did a few test runs with that workaround removed on the 4.0 release branch, and the tests all still passed. It never really made sense why we needed it in the first place, so other than it being a mystery I think it should be safe to remove
Brecht Van Lommel reopened this pull request 2024-02-05 12:15:23 +01:00

Ok, I've removed that workaround in main now. The baking tests are still passing too.

The denoising tests are failing though:

E0205 12:13:49.306424 256584485 denoiser_oidn_gpu.cpp:411] OIDN error: could not create Metal compute pipeline state
could not create Metal compute pipeline state
E0205 12:13:49.306448 256584485 denoiser_gpu.cpp:377] Error running denoiser.
Assertion failed: (mtlCommandBuffer_ == nil), function ~MetalDeviceQueue, file queue.mm, line 205.
Ok, I've removed that workaround in main now. The baking tests are still passing too. The denoising tests are failing though: ``` E0205 12:13:49.306424 256584485 denoiser_oidn_gpu.cpp:411] OIDN error: could not create Metal compute pipeline state could not create Metal compute pipeline state E0205 12:13:49.306448 256584485 denoiser_gpu.cpp:377] Error running denoiser. Assertion failed: (mtlCommandBuffer_ == nil), function ~MetalDeviceQueue, file queue.mm, line 205. ```
Contributor

Strange. I’ll run the tests locally and report back whether I get these errors too.

Do you think the x86 compositor failures could be related?

Strange. I’ll run the tests locally and report back whether I get these errors too. Do you think the x86 compositor failures could be related?

The compositor tests are just because this branch is slightly behind main, they can be ignored.

The compositor tests are just because this branch is slightly behind main, they can be ignored.
Contributor

I just ran the tests on an M2 Max + Sonoma and only the compositor tests failed. But it seems cycles_denoise_metal didn't run at all. I simply ran make test. Do I need to do anything special to run this test too?

I just ran the tests on an M2 Max + Sonoma and only the compositor tests failed. But it seems `cycles_denoise_metal` didn't run at all. I simply ran `make test`. Do I need to do anything special to run this test too?
Contributor

It seems none of the Metal tests appear in the list of tests when running locally. How is it possible to enable them?

It seems none of the Metal tests appear in the list of tests when running locally. How is it possible to enable them?

In CMakeCache.txt, set CYCLES_TEST_DEVICES:STRING=CPU;METAL

In `CMakeCache.txt`, set `CYCLES_TEST_DEVICES:STRING=CPU;METAL`
Contributor

It worked, thanks!

M2 Max on Sonoma:

       Start  75: cycles_denoise_metal
 75/305 Test  #75: cycles_denoise_metal ............................................   Passed   13.55 sec

I'm now trying a different machine.

It worked, thanks! M2 Max on Sonoma: ``` Start 75: cycles_denoise_metal 75/305 Test #75: cycles_denoise_metal ............................................ Passed 13.55 sec ``` I'm now trying a different machine.
Stefan Werner added 2 commits 2024-02-06 01:01:15 +01:00
buildbot/vexp-code-patch-linux-x86_64 Build done. Details
buildbot/vexp-code-patch-windows-amd64 Build done. Details
buildbot/vexp-code-patch-lint Build done. Details
buildbot/vexp-code-patch-darwin-x86_64 Build done. Details
buildbot/vexp-code-patch-darwin-arm64 Build done. Details
buildbot/vexp-code-patch-coordinator Build done. Details
83bee7fba6
Merge branch 'main' into oidn_metal
Contributor

I finally managed to reproduce the issue. The problem happens when running the OIDN binaries on Ventura, which were compiled with an Xcode targeting the newer Sonoma by default. I think the problem is simply that the deployment target is not set when compiling OIDN's Metal shaders. I will create a new OIDN release candidate with the fix today, after which I think we should be able to merge this. I hope it won't be too late for Blender 4.1.

I finally managed to reproduce the issue. The problem happens when running the OIDN binaries on Ventura, which were compiled with an Xcode targeting the newer Sonoma by default. I think the problem is simply that the deployment target is not set when compiling OIDN's Metal shaders. I will create a new OIDN release candidate with the fix today, after which I think we should be able to merge this. I hope it won't be too late for Blender 4.1.

Thanks for figuring that out. It's fine, this can still make it to 4.1.

Thanks for figuring that out. It's fine, this can still make it to 4.1.
Member

Attila found the fix and released an rc2 with it, here is a PR to adopt it: #117902

Attila found the [fix ](https://github.com/OpenImageDenoise/oidn/commit/1fc394dcaee62be8f53af5178deb7706ae1decd3) and released an rc2 with it, here is a PR to adopt it: https://projects.blender.org/blender/blender/pulls/117902

Let's try this again with the fix in the libraries.

@blender-bot build macos

Let's try this again with the fix in the libraries. @blender-bot build macos
Brecht Van Lommel approved these changes 2024-02-06 20:56:48 +01:00

That worked, thanks all.

That worked, thanks all.
Brecht Van Lommel merged commit 31d55e87f9 into main 2024-02-06 21:13:33 +01:00
Brecht Van Lommel deleted branch oidn_metal 2024-02-06 21:13:38 +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
5 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#116124
No description provided.