Crash when enabling Open Shading Language with Cycles on macOS and Apple Silicon M1 #86530

Closed
opened 2021-03-12 16:30:09 +01:00 by Phil Hargett · 11 comments

System Information
Operating system: macOS Big Sur 11.2.3
CPU: Apple M1
Graphics card: Apple M1

Blender Version
Broken: 2.93 alpha on master, built locally, currently at commit b1ef55abdb (although older commits also have this issue)
Worked: 2.92 Blender Intel version running on Apple M1 via Rosetta 2 does not crash

Short description of error

Enabling Open Shading Language on the Render Properties panel with Render Engine set to Cycles causes an immediate crash.

First noticed this on my own scenes, but can reproduce by just opening blender and using the default scene.

Exact steps for others to reproduce the error

  1. Open Blender, just use default scene
  2. Set Viewport shading to Rendered Preview (so that Cycles results can be previewed in real-time)
  3. On Render Properties panel, set Render Engine to Cycles (leave CPU selected)
  4. On Render Properties panel, check the "Open Shading Language" checkbox
  5. Crash

Details gathered so far

I've been building and using Blender successfully after progress was made on #78710 and the Building Blender instructions for Mac were known to work again. My current projects don't need OSL, but was just experimenting when I discovered the crash.

After building an Xcode project and attaching Xcode to my locally built Blender app (again, this is all running on the new Apple M1/ARM64 chip, not Intel), I did find that the crashing thread seems to be in OSL library code:

- 0	0x0000000108b53f00 in llvm::CallInst::Create(llvm::FunctionType*, llvm::Value*, llvm::ArrayRef<llvm::Value*>, llvm::ArrayRef<llvm::OperandBundleDefT<llvm::Value*> >, llvm::Twine const&, llvm::Instruction*) ()
- 1	0x0000000108b495d8 in llvm::IRBuilderBase::CreateCall(llvm::FunctionType*, llvm::Value*, llvm::ArrayRef<llvm::Value*>, llvm::Twine const&, llvm::MDNode*) ()
- 2	0x0000000104a2cee0 in OSL_v1_11::pvt::LLVM_Util::call_function(llvm::Value*, OpenImageIO_v2_1::span<llvm::Value* const, -1l>) ()
- 3	0x00000001049ff1bc in OSL_v1_11::pvt::llvm_gen_closure(OSL_v1_11::pvt::BackendLLVM&, int) ()
- 4	0x0000000104a084c4 in OSL_v1_11::pvt::BackendLLVM::build_llvm_code(int, int, llvm::BasicBlock*) ()
- 5	0x0000000104a0a860 in OSL_v1_11::pvt::BackendLLVM::build_llvm_instance(bool) ()
- 6	0x0000000104a20cd4 in OSL_v1_11::pvt::BackendLLVM::run() ()
- 7	0x00000001048cacec in OSL_v1_11::pvt::ShadingSystemImpl::optimize_group(OSL_v1_11::ShaderGroup&, OSL_v1_11::ShadingContext*, bool) ()
- 8	0x00000001048c943c in OSL_v1_11::pvt::ShadingSystemImpl::optimize_all_groups(int, int, int, bool) ()
- 9	0x00000001048dfbac in void* std::__1::__thread_proxy<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct> >, void (*)(OSL_v1_11::pvt::ShadingSystemImpl*, int, int, bool), OSL_v1_11::pvt::ShadingSystemImpl*, int, int, bool> >(void*) ()
#10	0x0000000181f2e06c in _pthread_start ()

After reviewing other threads to see if they were doing anything interesting (as opposed to just looping on semaphores or event loops), there is this thread:

- 0	0x0000000181ef6acc in __ulock_wait ()
- 1	0x0000000181f2fc14 in _pthread_join ()
- 2	0x0000000181ec644c in std::__1::thread::join() ()
- 3	0x00000001048c92f0 in OSL_v1_11::pvt::ShadingSystemImpl::optimize_all_groups(int, int, int, bool) ()
- 4	0x0000000105f4ae8c in ccl::OSLShaderManager::device_update(ccl::Device*, ccl::DeviceScene*, ccl::Scene*, ccl::Progress&) ()
- 5	0x0000000105f54718 in ccl::Scene::device_update(ccl::Device*, ccl::Progress&) ()
- 6	0x0000000105f55e1c in ccl::Scene::update(ccl::Progress&, bool&) ()
- 7	0x0000000105f5bfb0 in ccl::Session::update_scene() ()
- 8	0x0000000105f5d904 in ccl::Session::run_cpu() ()
- 9	0x0000000105f5afe4 in ccl::Session::run() ()
- 10	0x0000000108df87c0 in ccl::thread::run(void*) ()
- 11	0x0000000181f2e06c in _pthread_start ()

This is pretty much the last line of method ccl::OSLShaderManager::device_update.

**System Information** Operating system: macOS Big Sur 11.2.3 CPU: Apple M1 Graphics card: Apple M1 **Blender Version** Broken: 2.93 alpha on master, built locally, currently at commit b1ef55abdbb (although older commits also have this issue) Worked: 2.92 Blender Intel version running on Apple M1 via Rosetta 2 does not crash **Short description of error** Enabling Open Shading Language on the Render Properties panel with Render Engine set to Cycles causes an immediate crash. First noticed this on my own scenes, but can reproduce by just opening blender and using the default scene. **Exact steps for others to reproduce the error** 1. Open Blender, just use default scene 2. Set Viewport shading to Rendered Preview (so that Cycles results can be previewed in real-time) 3. On Render Properties panel, set Render Engine to Cycles (leave CPU selected) 4. On Render Properties panel, check the "Open Shading Language" checkbox 5. Crash **Details gathered so far** I've been building and using Blender successfully after progress was made on #78710 and the Building Blender instructions for Mac were known to work again. My current projects don't need OSL, but was just experimenting when I discovered the crash. After building an Xcode project and attaching Xcode to my locally built Blender app (again, this is all running on the new Apple M1/ARM64 chip, not Intel), I did find that the crashing thread seems to be in OSL library code: ``` - 0 0x0000000108b53f00 in llvm::CallInst::Create(llvm::FunctionType*, llvm::Value*, llvm::ArrayRef<llvm::Value*>, llvm::ArrayRef<llvm::OperandBundleDefT<llvm::Value*> >, llvm::Twine const&, llvm::Instruction*) () - 1 0x0000000108b495d8 in llvm::IRBuilderBase::CreateCall(llvm::FunctionType*, llvm::Value*, llvm::ArrayRef<llvm::Value*>, llvm::Twine const&, llvm::MDNode*) () - 2 0x0000000104a2cee0 in OSL_v1_11::pvt::LLVM_Util::call_function(llvm::Value*, OpenImageIO_v2_1::span<llvm::Value* const, -1l>) () - 3 0x00000001049ff1bc in OSL_v1_11::pvt::llvm_gen_closure(OSL_v1_11::pvt::BackendLLVM&, int) () - 4 0x0000000104a084c4 in OSL_v1_11::pvt::BackendLLVM::build_llvm_code(int, int, llvm::BasicBlock*) () - 5 0x0000000104a0a860 in OSL_v1_11::pvt::BackendLLVM::build_llvm_instance(bool) () - 6 0x0000000104a20cd4 in OSL_v1_11::pvt::BackendLLVM::run() () - 7 0x00000001048cacec in OSL_v1_11::pvt::ShadingSystemImpl::optimize_group(OSL_v1_11::ShaderGroup&, OSL_v1_11::ShadingContext*, bool) () - 8 0x00000001048c943c in OSL_v1_11::pvt::ShadingSystemImpl::optimize_all_groups(int, int, int, bool) () - 9 0x00000001048dfbac in void* std::__1::__thread_proxy<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct> >, void (*)(OSL_v1_11::pvt::ShadingSystemImpl*, int, int, bool), OSL_v1_11::pvt::ShadingSystemImpl*, int, int, bool> >(void*) () #10 0x0000000181f2e06c in _pthread_start () ``` After reviewing other threads to see if they were doing anything interesting (as opposed to just looping on semaphores or event loops), there is this thread: ``` - 0 0x0000000181ef6acc in __ulock_wait () - 1 0x0000000181f2fc14 in _pthread_join () - 2 0x0000000181ec644c in std::__1::thread::join() () - 3 0x00000001048c92f0 in OSL_v1_11::pvt::ShadingSystemImpl::optimize_all_groups(int, int, int, bool) () - 4 0x0000000105f4ae8c in ccl::OSLShaderManager::device_update(ccl::Device*, ccl::DeviceScene*, ccl::Scene*, ccl::Progress&) () - 5 0x0000000105f54718 in ccl::Scene::device_update(ccl::Device*, ccl::Progress&) () - 6 0x0000000105f55e1c in ccl::Scene::update(ccl::Progress&, bool&) () - 7 0x0000000105f5bfb0 in ccl::Session::update_scene() () - 8 0x0000000105f5d904 in ccl::Session::run_cpu() () - 9 0x0000000105f5afe4 in ccl::Session::run() () - 10 0x0000000108df87c0 in ccl::thread::run(void*) () - 11 0x0000000181f2e06c in _pthread_start () ``` This is pretty much the last line of method `ccl::OSLShaderManager::device_update`.
Author

Added subscriber: @hargettp

Added subscriber: @hargettp

Changed status from 'Needs Triage' to: 'Confirmed'

Changed status from 'Needs Triage' to: 'Confirmed'

Added subscriber: @2046411367

Added subscriber: @2046411367
Author

So, for what it's worth, I changed this line: https://git.blender.org/gitweb/gitweb.cgi/blender.git/blob/HEAD:/intern/cycles/render/osl.cpp#l171

from this call:

ss->optimize_all_groups();

to this call:

ss->optimize_all_groups(1, true);

This basically makes the optimize_all_groups synchronous on the calling thread, rather than spread out over multiple threads. Such a change should eliminate thread safety in OSL as a cause.

Repeating the test still caused a crash in OSL. This suggests the bug might be in OSL on M1--although I can't rule out we didn't pass a bad data structure or pointer to OSL before this.

So, for what it's worth, I changed this line: https://git.blender.org/gitweb/gitweb.cgi/blender.git/blob/HEAD:/intern/cycles/render/osl.cpp#l171 from this call: `ss->optimize_all_groups();` to this call: `ss->optimize_all_groups(1, true);` This basically makes the `optimize_all_groups` synchronous on the calling thread, rather than spread out over multiple threads. Such a change should eliminate thread safety in OSL as a cause. Repeating the test still caused a crash in OSL. This suggests the bug might be in OSL on M1--although I can't rule out we didn't pass a bad data structure or pointer to OSL before this.

Added subscriber: @CookItOff

Added subscriber: @CookItOff

I can confirm the crash on M1 with the Arm 64 official build.

I can confirm the crash on M1 with the Arm 64 official build.
Author

FYI, filed this ticket for OSL: Crash in optimize_all_groups running in pre-release Blender on Apple Silicon . Not 100% sure its OSL, but hoping for guidance.

FYI, filed this ticket for OSL: [Crash in optimize_all_groups running in pre-release Blender on Apple Silicon ](https://github.com/AcademySoftwareFoundation/OpenShadingLanguage/issues/1359). Not 100% sure its OSL, but hoping for guidance.

This issue was referenced by 33f218fa3f

This issue was referenced by 33f218fa3f93a3d574d81d65628188921d6f100c

Changed status from 'Confirmed' to: 'Resolved'

Changed status from 'Confirmed' to: 'Resolved'
Brecht Van Lommel self-assigned this 2021-04-19 15:05:21 +02:00

This issue was referenced by None@62619

This issue was referenced by None@62619
Author

Yep, solved--ty @brecht !

Yep, solved--ty @brecht !
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 project
No Assignees
6 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#86530
No description provided.