JDK-8261620 : Running metal with API validation crashes immediately
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: internal
  • Priority: P2
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2021-02-11
  • Updated: 2021-02-14
  • Resolved: 2021-02-12
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
internalFixed
Related Reports
Relates :  
Relates :  
Relates :  
Relates :  
Description
If you use the new Metal pipeline and run J2Demo, or SwingSet2, or likely most apps, with Metal API validation turned on, the validator immediately detects a problem and this causes a crash.

Normally folks do this inside Xcode but you can do it outside with an environment variable

 %  export METAL_DEVICE_WRAPPER_TYPE=1
 %  ~/lanai/build/macosx-x86_64-server-release/jdk/bin/java -Dsun.java2d.metal=True -jar J2Ddemo.jar
2021-02-11 15:01:48.133 system_profiler[29990:11424023] Metal API Validation Enabled
2021-02-11 15:01:48.411 java[29988:11423901] Metal API Validation Enabled
Metal pipeline enabled on screen 188990411
-[MTLDebugBlitCommandEncoder internalValidateCopyFromTexture:sourceSlice:sourceLevel:sourceOrigin:sourceSize:toTexture:destinationSlice:destinationLevel:destinationOrigin:options:]:472: failed assertion `(sourceOrigin.y + sourceSize.height)(228) must be <= height(200).'
zsh: abort      ~/lanai/build/macosx-x86_64-server-release/jdk/bin/java  -jar J2Ddemo.jar

Could be that there are more such issues but since this crash occurs on start up I can't say what else there might be.
But clearly we want to find and fix any others too ..

thanks to Gerard for spotting this.

Comments
This is evident as it is in the common method where we blit from backbuffer to frontbuffer. Adding proper checks before blitting fixes the crash.
12-02-2021