Cycles: MetalRT optimisations (scene_intersect_shadow + random_walk) #121397

Merged
Michael Jones (Apple) merged 4 commits from Michael-Jones/blender:mjones/MetalRTOptimisation into main 2024-05-10 16:38:17 +02:00

This PR contains optimisations and a general tidy-up of the MetalRT backend.

  • Currently scene_intersect is used for both normal and (opaque) shadow rays, however the usage patterns are different enough to warrant specialisation. Shadow intersection tests (flagged with PATH_RAY_SHADOW_OPAQUE) only need a bool result, but need a larger "self" payload in order to exclude hits against target lights. By specialising we can minimise the payload size in each case (which is helps performance) and avoid some dynamic branching. This PR introduces a new scene_intersect_shadow function which is specialised in Metal, and currently redirects to scene_intersect in the other backends.

  • Currently scene_intersect_local is implemented for worst-case payload requirements as demanded by subsurface_disk (where max_hits is 4). The random_walk case only demands 1 hit result which we can retrieve directly from the intersector object (rather than stashing it in the payload). By specialising, we significantly reduce the payload size for random_walk queries, which has a big impact on performance. Additionally, we only need to use a custom intersection function for the first ray test in a random walk (for self-primitive filtering), so this PR forces faster opaque intersection testing for all but the first random walk test.

  • Currently scene_intersect_volume has a lot of redundant code to handle non-triangle primitives despite volumes only being enclosed by trimeshes. This PR removes this code.

Additionally, this PR tidies up the convoluted intersection function linking code, removes some redundant intersection handlers, and uses more consistent naming of intersection functions.

On a M3 MacBook Pro, these changes give 2-3% performance increase on typical scenes with opaque trimesh materials (e.g. barbershop, classroom junkshop), but can give over 15% performance increase for certain scenes using random walk SSS (e.g. monster).

This PR contains optimisations and a general tidy-up of the MetalRT backend. - Currently `scene_intersect` is used for both normal and (opaque) shadow rays, however the usage patterns are different enough to warrant specialisation. Shadow intersection tests (flagged with `PATH_RAY_SHADOW_OPAQUE`) only need a bool result, but need a larger "self" payload in order to exclude hits against target lights. By specialising we can minimise the payload size in each case (which is helps performance) and avoid some dynamic branching. This PR introduces a new `scene_intersect_shadow` function which is specialised in Metal, and currently redirects to `scene_intersect` in the other backends. - Currently `scene_intersect_local` is implemented for worst-case payload requirements as demanded by `subsurface_disk` (where `max_hits` is 4). The random_walk case only demands 1 hit result which we can retrieve directly from the intersector object (rather than stashing it in the payload). By specialising, we significantly reduce the payload size for random_walk queries, which has a big impact on performance. Additionally, we only need to use a custom intersection function for the first ray test in a random walk (for self-primitive filtering), so this PR forces faster `opaque` intersection testing for all but the first random walk test. - Currently `scene_intersect_volume` has a lot of redundant code to handle non-triangle primitives despite volumes only being enclosed by trimeshes. This PR removes this code. Additionally, this PR tidies up the convoluted intersection function linking code, removes some redundant intersection handlers, and uses more consistent naming of intersection functions. On a M3 MacBook Pro, these changes give 2-3% performance increase on typical scenes with opaque trimesh materials (e.g. barbershop, classroom junkshop), but can give over 15% performance increase for certain scenes using random walk SSS (e.g. monster).
Michael Jones (Apple) added 1 commit 2024-05-03 15:54:49 +02:00
Cycles: MetalRT optimisations (scene_intersect_shadow + random_walk)
Some checks failed
buildbot/vexp-code-patch-lint Build done.
buildbot/vexp-code-patch-linux-x86_64 Build done.
buildbot/vexp-code-patch-darwin-x86_64 Build done.
buildbot/vexp-code-patch-windows-amd64 Build done.
buildbot/vexp-code-patch-darwin-arm64 Build done.
buildbot/vexp-code-patch-coordinator Build done.
1438b6da6f
This PR contains optimisations and a general tidy-up of the MetalRT backend.

- Currently `scene_intersect` is used for both normal and opaque shadow rays, however the usage patterns are different enough to warrant specialisation. Shadow intersection tests (flagged with `PATH_RAY_SHADOW_OPAQUE`) only need a bool result, but need a larger "self" payload in order to exclude hits against target lights. By specialising we can minimise the payload size in each case and avoid some dynamic branching. This PR introduces a new `scene_intersect_shadow` function which is specialised in Metal, and currently redirects to `scene_intersect` in the other backends.

- Currently `scene_intersect_local` is implemented for worst-case payload requirements as demanded by `subsurface_disk` (where `max_hits` is 4). The random_walk case only demands 1 hit result which this update retrieves directly from the intersector object (rather than stashing it in the payload). By specialising, we can significantly reduce the payload size for random_walk queries, which has a big impact on performance. Additionally, we only need to use a custom intersection function for the first ray test in a random walk (for self-primitive filtering), so this PR forces faster `opaque` intersection testing for all but the first random_walk test.

- Currently 'scene_intersect_volume' has a lot of redundant code to handle non-triangle primitives despite volumes only being enclosed by trimeshes. This PR removes this code.

Additionally, this PR tidies up the convoluted intersection function linking code, removes some redundant intersection handlers, and uses more consistent naming of intersection functions.

On a M3 MacBook Pro, these changes give 2-3% performance increase on typical scenes with opaque trimesh materials (e.g. barbershop, classroom junkshop), but can give over 15% performance increase for certain scenes using random walk SSS (e.g. monster).
Michael Jones (Apple) requested review from Brecht Van Lommel 2024-05-03 15:55:04 +02:00
Author
Member

@blender-bot build +gpu

@blender-bot build +gpu

We currently have issues with the GPU tests with EEVEE timing out. However there do appear to be some Cycles Metal test failures before that happened.

We currently have issues with the GPU tests with EEVEE timing out. However there do appear to be some Cycles Metal test failures before that happened.
Brecht Van Lommel requested changes 2024-05-06 14:02:51 +02:00
Dismissed
Brecht Van Lommel left a comment
Owner

Overall this looks like a nice improvement, but there are some test failures to be looked at.

Overall this looks like a nice improvement, but there are some test failures to be looked at.
@ -148,6 +156,7 @@ ccl_device_intersect bool scene_intersect(KernelGlobals kg,
# include "kernel/bvh/local.h"
# endif
template <bool random_walk = false>

Can we call this single_hit to keep it generic?

Can we call this `single_hit` to keep it generic?
Michael-Jones marked this conversation as resolved

@blender-bot build

@blender-bot build
Author
Member

Thanks @brecht . I'm looking into these test failures (specifically why both MetalRT on/off paths seem okay on my machine but not the buildbot!)

Thanks @brecht . I'm looking into these test failures (specifically why both MetalRT on/off paths seem okay on my machine but not the buildbot!)
Michael Jones (Apple) added 2 commits 2024-05-07 23:06:51 +02:00
Michael Jones (Apple) added 1 commit 2024-05-07 23:08:54 +02:00
make format
Some checks failed
buildbot/vexp-code-patch-lint Build done.
buildbot/vexp-code-patch-darwin-x86_64 Build done.
buildbot/vexp-code-patch-linux-x86_64 Build done.
buildbot/vexp-code-patch-darwin-arm64 Build done.
buildbot/vexp-code-patch-windows-amd64 Build done.
buildbot/vexp-code-patch-coordinator Build done.
91ada3d320
Author
Member

@blender-bot build +gpu

@blender-bot build +gpu
Author
Member

@brecht , I pushed a fix for those unit test failures (a simple repro so strange that I didn't see it sooner) and renamed random_walk to single_hit. The latest buildbot run looks better - the errors seem to be unrelated.

@brecht , I pushed a fix for those unit test failures (a simple repro so strange that I didn't see it sooner) and renamed random_walk to single_hit. The latest buildbot run looks better - the errors seem to be unrelated.
Brecht Van Lommel approved these changes 2024-05-10 14:44:01 +02:00
Michael Jones (Apple) merged commit 5508b41a40 into main 2024-05-10 16:38:17 +02:00
Michael Jones (Apple) deleted branch mjones/MetalRTOptimisation 2024-05-10 16:38:20 +02:00
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
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#121397
No description provided.