JDK-8261714 : Lanai : Crash on graphics card switch when Metal API validation is enabled
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: internal
  • Priority: P2
  • Status: Closed
  • Resolution: Duplicate
  • OS: os_x
  • CPU: x86_64
  • Submitted: 2021-02-14
  • Updated: 2021-03-03
  • Resolved: 2021-03-03
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
internalResolved
Related Reports
Duplicate :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
System to test should have a dual graphics card.

1) Enable Metal API validation (export METAL_DEVICE_WRAPPER_TYPE=1) 
2) Launch SwingSet2 demo or any other application with Metal rendering pipeline (-Dsun.java2d.metal=true)
3) toggle "Automatic graphics switching" setting

Application launched in step 2 crashes with following error.

-[MTLDebugRenderCommandEncoder setFragmentSamplerState:atIndex:]:1950: failed assertion `sampler is associated with a different device'


Note : the crash is observed both ways -  a switch from integrated GPU to discrete GPU and the other way round.
Comments
Since we have JDK-8262254 and JDK-8262882 for the similar reports, closing this now.
03-03-2021

Tested on 16" macBook - 2019 - macOS 11.1 I tested with latest sources. The crash is not reproducible with SwingSet2, J2DDemo and Netbeans. Looks like this bug is fixed by JDK-8262496. I could test only with default retina screen - by toggling GPU multiple times (using "Automatic Graphics Switching" setting) while macBook is on battery. Need to test by plugging in/plugging out external monitor.
01-03-2021

Recently (JDK-8262496) I've fixed all the card-switch cases that I was able to reproduce. Could you check with the latest sources? Withing the fix I've added several validation checks to ensure that we're going to work with the valid for the actual device resources. Also, I've made stencil and samplers structures attached to particular MTLContext, so now they belong to the MTLDevice where they were created. There still may be cases of improper resource usage and we can use the same checks that I did to resolve them.
28-02-2021

I got a crash with the latest build just by 1) Starting SwingSet on the built in retina 2) Plugging in the external monitor. Error is the same as originally reported java -Dsun.java2d.metal=True -jar SwingSet2.jar 2021-02-24 16:14:47.199 system_profiler[40057:19042184] Metal API Validation Enabled 2021-02-24 16:14:47.357 java[40055:19042076] Metal API Validation Enabled Metal pipeline enabled on screen 2077748985 Metal pipeline enabled on screen 69734662 -[MTLDebugRenderCommandEncoder setFragmentTexture:atIndex:]:1890: failed assertion `texture is associated with a different device' zsh: abort java -Dsun.java2d.metal=True -jar SwingSet2.jar I did not have to do *anything* in SwingSet, Just start it and plugin the external monitor IIt did not reproduce in this simple a way the next two times .. more plugging and unplugging was needed but this crash is definitely there. 2019 16" MacBook Pro, macOS 11.1
25-02-2021

I filed a new bug as well, JDK-8262254. You may or may not want to add that case to this bug and close that bug as a duplicate. * App with an open dialog sees a crash if GPU switch occurs
23-02-2021

First 3 errors that were uncovered are fixed as part of JDK-8262115. Now, a non animating UI does not crash on first GPU switch Remaining work - If metal API validation is enabled, 1. Animating UI sees a crash if GPU switch occurs 2. Non animating UI sees a crash if GPU switched twice
22-02-2021

I have fixed 3 errors that were uncovered one after the other in my local repo on GPU switch. There is no crash on switching graphics card now. There is still a crash if we switch graphics card for second time again. This indicates, our state maintenance needs to be more robust. Work in progress..
18-02-2021

I have fixed the reported error locally. It uncovers another error - -[MTLDebugRenderCommandEncoder setFragmentTexture:atIndex:]:1890: failed assertion `texture is associated with a different device' Working on it now..
15-02-2021