Eevee: Race condition in ShaderCreateInfo::finalize() #128164

Closed
opened 2024-09-26 10:08:40 +02:00 by Sergey Sharybin · 2 comments

System Information
Operating system: macOS-14.6.1-arm64-arm-64bit 64 Bits
Graphics card: Apple M2 Ultra Apple 4.1 Metal - 88.1

Blender Version
Broken: Recent 4.3 main (8dcd51ddc3)
Worked: 4.2

Short description of error
It appears that ShaderCreateInfo::finalize can be called from multiple threads for the same ShaderCreateInfo, resulting in the wrong shader: the second thread will return early since the system believes the finalization is done.

This seems to be the root cause of Eevee benchmarks failing on the buildbot: https://builder.blender.org/admin/#/builders/243/builds/223

The error there is coming from the shader compilation error: # error Missing draw_view additional create info on shader create info. This appears to be due to incomplete shader info used to compile some shaders.

Exact steps for others to reproduce the error

  • For the simplicity of reproducing the error apply the patch attached
  • Open tests/benchmarks/eevee/reports/T98989.blend
  • Observe: ShaderCreateInfo::finalize name:eevee_surf_deferred called while other thread is finalizing it

P.S. This is more of a write-up and coordination with Clément (and the PoC code to help triggering the issue) after a pair debugging session.

**System Information** Operating system: macOS-14.6.1-arm64-arm-64bit 64 Bits Graphics card: Apple M2 Ultra Apple 4.1 Metal - 88.1 **Blender Version** Broken: Recent 4.3 main (8dcd51ddc3e24fed803aed06f9e63dfeee821545) Worked: 4.2 **Short description of error** It appears that `ShaderCreateInfo::finalize` can be called from multiple threads for the same `ShaderCreateInfo`, resulting in the wrong shader: the second thread will return early since the system believes the finalization is done. This seems to be the root cause of Eevee benchmarks failing on the buildbot: https://builder.blender.org/admin/#/builders/243/builds/223 The error there is coming from the shader compilation error: `# error Missing draw_view additional create info on shader create info`. This appears to be due to incomplete shader info used to compile some shaders. **Exact steps for others to reproduce the error** - For the simplicity of reproducing the error apply the patch attached - Open `tests/benchmarks/eevee/reports/T98989.blend` - Observe: `ShaderCreateInfo::finalize name:eevee_surf_deferred called while other thread is finalizing it` P.S. This is more of a write-up and coordination with Clément (and the PoC code to help triggering the issue) after a pair debugging session.
Sergey Sharybin added the
Severity
Normal
Type
Bug
Status
Confirmed
labels 2024-09-26 10:09:01 +02:00
Clément Foucault self-assigned this 2024-09-26 12:08:27 +02:00
Jesse Yurkovich added the
Module
Viewport & EEVEE
label 2024-09-27 08:49:59 +02:00
Clément Foucault removed their assignment 2024-09-27 17:25:26 +02:00

Leaving @pragma37 to take a look

Leaving @pragma37 to take a look
Miguel Pozo self-assigned this 2024-09-27 17:26:56 +02:00
Member

I assumed this would have been caused by the recent draw_manager_shader refactors, but doesn't seem to be the case.

The issue here seems that we are compiling, at the same time, deferred and non-deferred shaders (so, different threads) with the same additonal_info dependencies.
(No idea why this didn't surface earlier)

So, we either ensure that all additional_info dependencies are finalized from the main thread (maybe we can finalize directly at the additional_info call ?), or add mutexes to every ShaderCreateInfo (and ensure there are no cyclic dependencies).

Using mutexes seems to do the trick, although I'm running into weird issues because the ShaderCreateInfo constructor doesn't seem to be called in all cases.
Nope, it was lack of copy constructor.

I assumed this would have been caused by the recent `draw_manager_shader` refactors, but doesn't seem to be the case. The issue here seems that we are compiling, at the same time, deferred and non-deferred shaders (so, different threads) with the same `additonal_info` dependencies. (No idea why this didn't surface earlier) So, we either ensure that all `additional_info` dependencies are finalized from the main thread (maybe we can finalize directly at the `additional_info` call ?), or add mutexes to every `ShaderCreateInfo` (and ensure there are no cyclic dependencies). ~~Using mutexes seems to do the trick, although I'm running into weird issues because the `ShaderCreateInfo` constructor doesn't seem to be called in all cases.~~ Nope, it was lack of copy constructor.
Blender Bot added
Status
Resolved
and removed
Status
Confirmed
labels 2024-10-01 15:36:19 +02:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Code Documentation
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 & 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
Asset System
Module
Core
Module
Development Management
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline & 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
3 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#128164
No description provided.