Fix 107322: MacOS/ATI Crash When Starting Eevee #109358

Merged
Jeroen Bakker merged 2 commits from Jeroen-Bakker/blender:macos-raytrace-infinitive-loop into blender-v3.6-release 2023-06-26 14:12:51 +02:00
Member

When using ATI GPU on MacOS/Metal compilation of Eevee shaders crashed due to an infinitive
loop in the compiler backend. This change fixes this by using a more reliable loop that
ensures that the loop will be finite.

Thanks for the Apple developers working on finding the root cause and Michael Parking White
for the initial fix.

Fixes #107322
Fixes #107451

When using ATI GPU on MacOS/Metal compilation of Eevee shaders crashed due to an infinitive loop in the compiler backend. This change fixes this by using a more reliable loop that ensures that the loop will be finite. Thanks for the Apple developers working on finding the root cause and Michael Parking White for the initial fix. Fixes #107322 Fixes #107451
Jeroen Bakker added this to the 3.6 LTS milestone 2023-06-26 08:32:51 +02:00
Jeroen Bakker added the
Interest
Metal
label 2023-06-26 08:32:51 +02:00
Jeroen Bakker added 1 commit 2023-06-26 08:33:00 +02:00
buildbot/vexp-code-patch-coordinator Build done. Details
5b6867816d
Fix 107322: MacOS/ATI Crash When Starting Eevee
When using ATI GPU on MacOS/Metal compilation of Eevee shaders crashed due to an infinitive
loop in the compiler backend. This change fixes this by using a more reliable loop that
ensures that the loop will be finite.

Thanks for the Apple developers working on finding the root cause and Michael Parking White
for the initial fix.

Fixes #107322
Fixes #107451
Jeroen Bakker requested review from Clément Foucault 2023-06-26 08:33:07 +02:00
Jeroen Bakker added this to the EEVEE & Viewport project 2023-06-26 08:33:12 +02:00
Jeroen Bakker self-assigned this 2023-06-26 08:33:17 +02:00
Author
Member

@blender-bot build

@blender-bot build
Clément Foucault requested changes 2023-06-26 09:56:52 +02:00
Clément Foucault left a comment
Member

Some more explicit casts are needed.

Some more explicit casts are needed.
@ -119,3 +119,3 @@
float prev_time, time = 0.0;
for (float iter = 0.0; time < ssray.max_time && iter < sample_count; iter++) {
for (int iter = 0; time < ssray.max_time && iter < sample_count; iter++) {

sample_count needs to be declared as int. Better do the conversion out of the loop const int i_sample_count = int(sample_count)

`sample_count` needs to be declared as int. Better do the conversion out of the loop `const int i_sample_count = int(sample_count)`
Jeroen-Bakker marked this conversation as resolved
@ -122,3 +121,4 @@
for (int iter = 0; time < ssray.max_time && iter < sample_count; iter++) {
prev_time = time;
/* Gives us good precision at center and ensure we cross at least one pixel per iteration. */
time = 1.0 + iter + sqr((iter + noise) / sample_count) * ssray.max_time;

iter needs to be explicitly converted to float here.

`iter` needs to be explicitly converted to float here.
Jeroen-Bakker marked this conversation as resolved
@ -141,2 +140,3 @@
for (float iter = 1.0; !hit && (time < ssray.max_time) && (iter < max_steps); iter++) {
const int max_steps = 255;
for (int iter = 1; !hit && (time < ssray.max_time) && (iter < max_steps); iter++) {
float stride = 1.0 + iter * params.trace_quality;

iter needs to be explicitly converted to float here.

`iter` needs to be explicitly converted to float here.
Jeroen-Bakker marked this conversation as resolved
@ -214,2 +213,3 @@
for (float iter = 1.0; !hit && (time < ssray.max_time) && (iter < max_steps); iter++) {
const int max_steps = 255;
for (int iter = 1; !hit && (time < ssray.max_time) && (iter < max_steps); iter++) {
float stride = 1.0 + iter * params.trace_quality;

iter needs to be explicitly converted to float here.

`iter` needs to be explicitly converted to float here.
Jeroen-Bakker marked this conversation as resolved
Michael Parkin-White reviewed 2023-06-26 11:45:08 +02:00
@ -118,7 +118,7 @@ float search_horizon(vec3 vI,
}
float prev_time, time = 0.0;
for (float iter = 0.0; time < ssray.max_time && iter < sample_count; iter++) {
First-time contributor

My apologies @Jeroen-Bakker , after testing the patch locally, one omission was that we also need to tag the function with no inline, though this should only be done for AMD platforms on Metal. Without this, the crash can still occur for certain material variants it appears.

I hope this is okay to include.

raytrace_lib.glsl

#ifdef METAL_AMD_RAYTRACE_WORKAROUND
__attribute__((noinline))
#endif
bool raytrace(Ray ray,
              RayTraceParameters params,
              const bool discard_backface,
              const bool allow_self_intersection,
              out vec3 hit_position)
{

and

#if (defined(GPU_METAL) && defined(GPU_ATI))
__attribute__((noinline))
#endif
float search_horizon(vec3 vI,
                     vec3 vP,
                     float noise,
                     ScreenSpaceRay ssray,
                     sampler2D depth_tx,
                     const float inverted,
                     float radius,
                     const float sample_count)
{
My apologies @Jeroen-Bakker , after testing the patch locally, one omission was that we also need to tag the function with no inline, though this should only be done for AMD platforms on Metal. Without this, the crash can still occur for certain material variants it appears. I hope this is okay to include. raytrace_lib.glsl ``` #ifdef METAL_AMD_RAYTRACE_WORKAROUND __attribute__((noinline)) #endif bool raytrace(Ray ray, RayTraceParameters params, const bool discard_backface, const bool allow_self_intersection, out vec3 hit_position) { ``` and ``` #if (defined(GPU_METAL) && defined(GPU_ATI)) __attribute__((noinline)) #endif float search_horizon(vec3 vI, vec3 vP, float noise, ScreenSpaceRay ssray, sampler2D depth_tx, const float inverted, float radius, const float sample_count) { ```
Jeroen-Bakker marked this conversation as resolved
Jeroen Bakker added 1 commit 2023-06-26 11:59:35 +02:00
buildbot/vexp-code-patch-coordinator Build done. Details
dcbfc3cba9
Resolved review comments.
Author
Member

@blender-bot build

@blender-bot build
Thomas Dinges approved these changes 2023-06-26 14:08:32 +02:00
Thomas Dinges left a comment
Owner

Fine to land this during Bcon4.

Fine to land this during Bcon4.
Author
Member

This PR has been tested, feedback has been addressed. We want to land this in 3.6.0 as Clement isn't available ATM we checked internally if this was ok.

This PR has been tested, feedback has been addressed. We want to land this in 3.6.0 as Clement isn't available ATM we checked internally if this was ok.
First-time contributor

Suggested comment:

Metal: Resolve AMD GPU timeout caused by infinite loop

Resolves GPU hang caused by backend shader compiler
generating code resulting in infinite loop while using 
floating point counter. 

Patch adds noinline intrinsics for AMD
path on Metal to ensure the bad compiler path is avoided
while also using an integer counter ensuring the loop 
counter is deterministic at compile time.

Fixes #107322
Fixes #107451

Suggested comment: ``` Metal: Resolve AMD GPU timeout caused by infinite loop Resolves GPU hang caused by backend shader compiler generating code resulting in infinite loop while using floating point counter. Patch adds noinline intrinsics for AMD path on Metal to ensure the bad compiler path is avoided while also using an integer counter ensuring the loop counter is deterministic at compile time. Fixes #107322 Fixes #107451 ```
Jeroen Bakker merged commit f7d46d0644 into blender-v3.6-release 2023-06-26 14:12:51 +02:00
Jeroen Bakker deleted branch macos-raytrace-infinitive-loop 2023-06-26 14:12:59 +02:00
Clément Foucault approved these changes 2023-06-26 16:15:49 +02:00
Sign in to join this conversation.
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 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#109358
No description provided.