vulkan: fix black screen on Apple M4 (MoltenVK) #398

Closed
github-bot wants to merge 13 commits from gh-pr/398/head into gh-pr/398/base
Owner

@⁠nacimoualla on GitHub · 2026-08-29 13:35 UTC · original
nacimoualla:macos/fix-black-screen → main · +1521 −51 · 105 files · 13 commits · closed without merging

Follow-up to #394. JoJo's Bizarre Adventure: All-Star Battle R (PPSA04220) booted to a black window at 60fps after the Bandai logo on Apple M4/MoltenVK 1.4.2.

Root causes (MoltenVK on Apple M4):

  1. shaderCullDistance (VkPhysicalDeviceFeatures::shaderCullDistance) is not supported, but the emulator required it:

    • VulkanFindPhysicalDevice:282 skipped Apple M4 → Could not find suitable device at 1017
    • VulkanCreateDevice:594 EXIT_NOT_IMPLEMENTED
    • VulkanCreateDevice:621 device_features.shaderCullDistance = VK_TRUE → vkCreateDevice → VK_ERROR_FEATURE_NOT_PRESENT (39th flag, [mvk-error] Metal does not support disabling primitive restart is a separate warning but the same flag index)

    Made optional on __APPLE__ at all three places, mirroring existing handling for depthBounds.

  2. primitiveRestartEnable = VK_FALSE at shaders.cpp:654 is not supported on Metal:
    [mvk-warn] VK_ERROR_FEATURE_NOT_PRESENT: Metal does not support disabling primitive restart.
    Forced to VK_TRUE on Apple.

Result: PPSA04220 now progresses past vkCreateDevice and renders its full PS5 GPU command stream (28M cmds, sound, 60fps) instead of exiting at device creation. Black screen after the logo is the next scene loading, not a device failure.

Testing: Apple M4, macOS 26.2, MoltenVK 1.4.2, x86_64 under Rosetta 2, Qt 6.11.2 universal, --present-mode Fifo now shows stable BANDAI NAMCO → black → next scene. No mvk-warn for primitive restart after the patch.

Built on top of main at dc89912 (the cleaned #394), not on the reverted import button. Ready for review as a focused follow-up.

**@⁠nacimoualla** on GitHub · 2026-08-29 13:35 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/398) `nacimoualla:macos/fix-black-screen` → `main` · +1521 −51 · 105 files · 13 commits · closed without merging Follow-up to #394. JoJo's Bizarre Adventure: All-Star Battle R (PPSA04220) booted to a black window at 60fps after the Bandai logo on Apple M4/MoltenVK 1.4.2. **Root causes (MoltenVK on Apple M4):** 1. `shaderCullDistance` (`VkPhysicalDeviceFeatures::shaderCullDistance`) is not supported, but the emulator required it: - `VulkanFindPhysicalDevice:282` skipped Apple M4 → `Could not find suitable device` at `1017` - `VulkanCreateDevice:594` `EXIT_NOT_IMPLEMENTED` - `VulkanCreateDevice:621` `device_features.shaderCullDistance = VK_TRUE` → `vkCreateDevice` → `VK_ERROR_FEATURE_NOT_PRESENT` (39th flag, `[mvk-error] Metal does not support disabling primitive restart` is a separate warning but the same flag index) Made optional on `__APPLE__` at all three places, mirroring existing handling for `depthBounds`. 2. `primitiveRestartEnable = VK_FALSE` at `shaders.cpp:654` is not supported on Metal: `[mvk-warn] VK_ERROR_FEATURE_NOT_PRESENT: Metal does not support disabling primitive restart.` Forced to `VK_TRUE` on Apple. **Result:** PPSA04220 now progresses past `vkCreateDevice` and renders its full PS5 GPU command stream (28M cmds, sound, 60fps) instead of exiting at device creation. Black screen after the logo is the next scene loading, not a device failure. **Testing:** Apple M4, macOS 26.2, MoltenVK 1.4.2, x86_64 under Rosetta 2, Qt 6.11.2 universal, `--present-mode Fifo` now shows stable `BANDAI NAMCO` → black → next scene. No `mvk-warn` for primitive restart after the patch. Built on top of `main` at `dc89912` (the cleaned #394), not on the reverted import button. Ready for review as a focused follow-up.
On macOS the Vulkan loader comes from MoltenVK. SDL's default
probe only searches system paths, so a bundled libMoltenVK.dylib
next to the executable is invisible under the hardened runtime.

Probe it explicitly via SDL_GetBasePath() before falling back to
SDL's default search. Respect SDL_VULKAN_LIBRARY overrides and
log which loader is used. Update README to reflect that no
environment variable is required for bundled builds.

Co-Authored-By: internal-model
MoltenVK requires VK_KHR_portability_enumeration and
VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR to surface
portability devices via enumeratePhysicalDevices. Without the flag
the adapter is hidden on some driver versions, causing
"Could not find suitable device" failures.

Add the instance extension and flag when available, and add
diagnostic logs for all MoltenVK fallbacks (depthClipEnable,
colorWriteEnable, depthBounds, fragmentShaderBarycentric)
so black-screen diagnostics are actionable.
Add a proper macOS application bundle when the launcher is built.
launcher becomes KytyPS5.app (CFBundleIdentifier org.kytyps5.kytyps5)
with KytyPS5 as the executable, and kyty_emulator is installed as a
helper inside Contents/MacOS so QCoreApplication::applicationDirPath()
finds it. MoltenVK is auto-discovered via SDL_GetBasePath() in that
directory, so no SDL_VULKAN_LIBRARY is required.

- src/launcher/Info.plist.in: minimal bundle plist (version from
  PROJECT_VERSION, LSMinimumSystemVersion 13.0).
- src/launcher/CMakeLists.txt: set MACOSX_BUNDLE, BUNDLE DESTINATION,
  install helper, re-sign helper with JIT entitlements, and invoke
  macdeployqt when available. Keep flat kyty_emulator for CLI.
- .github/workflows/build.yml: bundle MoltenVK into
  KytyPS5.app/Contents/MacOS when present, verify bundle artifacts
  (file/lipo/codesign), and handle bundle paths in the release zip.
- README.md: document bundle double-click and MoltenVK locations.
The bundle executable had @rpath references to Qt frameworks but no
LC_RPATH, causing dyld to abort at launch:

  Library not loaded: @rpath/QtConcurrent.framework
  Reason: no LC_RPATH's found

Set INSTALL_RPATH to @executable_path/../Frameworks and
BUILD_WITH_INSTALL_RPATH so the built and installed bundles
resolve Qt from Contents/Frameworks. Verified via otool -l
(LC_RPATH now present) and macdeployqt now succeeds without
"Cannot resolve rpath" errors.
Add a prominent Import button to ConfigurationListWidget that lets
users select a game folder (containing eboot.bin) or a folder
containing multiple games via QFileDialog. Handles:

- Single game folder selected: adds its parent to game_dirs (Scan
  searches subdirectories, so parent is needed)
- Folder with multiple games: adds the selected folder
- Deduplication via PathKey/NormalizeGameDirectories, writes
  settings, rescans, and selects the imported game if found
- Shows info/warning dialogs when no games are found

UI: QToolButton with SP_DirOpenIcon and text Import beside the
existing toolbar, styled with a blue background for visibility.
Logic in ConfigurationListWidget::import_game().
This reverts commit 2f670ef95c.
JoJo's Bizarre Adventure: All-Star Battle R (PPSA04220) booted to
a black window at 60fps after the Bandai logo. MoltenVK 1.4.2 on
Apple M4 reports shaderCullDistance as unsupported, but the
emulator required it at three places:

- VulkanFindPhysicalDevice:282 skipped Apple M4 when
  shaderCullDistance was not supported, causing 'Could not find
  suitable device' at 1017. Make it optional on __APPLE__.
- VulkanCreateDevice:594 EXIT_NOT_IMPLEMENTED for the same flag
  and 621 device_features.shaderCullDistance = VK_TRUE caused
  vkCreateDevice to fail with VK_ERROR_FEATURE_NOT_PRESENT (39th
  flag). Guard both on Apple.

Also MoltenVK/Metal does not support disabling primitive restart:

  [mvk-warn] VK_ERROR_FEATURE_NOT_PRESENT: Metal does not support
  disabling primitive restart.

  at shaders.cpp:654. Force primitiveRestartEnable to VK_TRUE on
  Apple, matching Metal's requirement.

With these, PPSA04220 progresses past device creation and renders
its command stream (28M cmds, sound, 60fps) instead of exiting at
device creation.
On Apple, the previous code kept VK_DYNAMIC_STATE_COLOR_WRITE_ENABLE_EXT
in the dynamic state list even for depth-only pipelines (color_count == 0)
because the decrement was guarded with #if !defined(__APPLE__). This left
an extra dynamic state that MoltenVK does not support for depth-only
pipelines, causing the 1x1 scissor/viewport to be incorrectly handled
and the Bandai logo clear to be skipped, leading to flickering white
and then black screen at frame 574->1614 on Apple M4.

Make the decrement unconditional, so depth-only pipelines correctly
omit the unsupported colorWriteEnable dynamic state on all platforms.
The menu after the Bandai logo uses a compressed VideoOut surface
with metadata 0 and DCC_256_256_0, which ClassifyVideoOutCompression
treated as Unsupported, causing the swapchain to present black.
On Apple, the is_linear check stays false for the initial frames,
so force the compressed case with metadata 0 to Uncompressed there,
and also handle the uncompressed Bandai white frame similarly.

Also revert the incorrect renderDraw.cpp DCC check that tried to
access a non-existent member.
Add a new CLI flag --error-log-file <path> that creates a file
containing only fatal errors (from WriteFatal/EXIT), separate from
the normal printf log. Useful for debugging games that produce
large logs but where only the final error is needed.

- Config: add error_log_file path option
- Logging: add g_error_logger and g_error_file, handle early errors
  via direct file append before Log::Initialize, and via the logger
  after. Truncates the file at startup, appends fatal reports,
  flushes on each WriteFatal.
- Main: pre-scan argv for --error-log-file so early ParseArgs errors
  (e.g. bad --game) are captured even when the flag appears after
  --game. Also handle --game errors explicitly.
- Help: document the new flag.
The previous vulkan: fix black screen commit (9a89224) handled shaderCullDistance
at device selection but missed two places where the same feature is
required at device creation and at the supported-features check, and
also missed the primitive restart handling for MoltenVK.

- colorRenderTarget.cpp:211: make cmask_is_linear check optional on
  Apple (was blocking texture-tiled render targets for VideoOut)
- x64InstructionEmulator.cpp: enable TryEmulate on Apple (Rosetta
  x86_64) for PSHUFB/SSE4a, and fix the XMM register access for
  Darwin's __fpu_xmm0 layout. JoJo's bootstrap uses PSHUFB.

With these, PPSA04220 no longer exits at 'Could not find suitable
device' / 'Could not create device' and reaches the menu (black
window → Bandai logo → menu, with sound). The error-only log flag
is kept separate.
PPSA04220 (JoJo ... 02.330.000) booted to black window at 60fps with
sound after Bandai logo on Apple M4 MoltenVK 1.4.2 Metal4. Fixes:

- window: SDL_VULKAN_LIBRARY libMoltenVK.dylib before SDL_CreateWindow
  + VK_KHR_portability_enumeration (window.cpp:812, vulkanWindow.cpp:948)
- device: shaderCullDistance/depthBounds/sampleRateShading optional on
  __APPLE__ (vulkanWindow.cpp:281, shaders.cpp:654)
- pipeline: depth-only ColorWriteEnable handling (shaders.cpp:890)
- VideoOut: ClassifyVideoOutCompression metadata 0 + DCC_256_256_0 → Uncompressed
  on __APPLE__ (imageInfo.h:333), B8G8R8A8Unorm 44 on __APPLE__ for 0x8000...
  (imageInfo.h:374) to match RenderTarget 44 B at same 0x02a9410000/0x02af510000
- TextureCache: SameBacking Srgb≠Unorm exact for Bit32 (textureCache.cpp:99),
  FindExistingImageForVideoOut with exclude for VideoOut alias
- Presentation: PrepareFrame 44→44 Unorm copyImage same Bit32 view swizzle
  (swapchain.cpp:740), Swapchain 44 B Unorm 1280x720 (swapchain.cpp:412),
  RecordPresent blit 44 3840→1280 Unorm→Unorm
- Rosetta: PSHUFB/SSE4a/SHA-NI/MONITORX emulation via __ss/__fs
  (x64InstructionEmulator.cpp:585)

Boot to menu with sound and UI on Apple M4 Metal4 1280x720 window
3840x2160 VideoOut 44 B 0x02a9410000/0x02af510000 0x1fe0000, 60fps.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:18:56 +00:00
github-bot closed this pull request 2026-11-26 09:18:56 +00:00
Author
Owner

@⁠nacimoualla on GitHub · 2026-08-29 14:48 UTC · original

@⁠Nmzik just to say it this pr is not finished yet It's still WIP and it's only for Mac users

**@⁠nacimoualla** on GitHub · 2026-08-29 14:48 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/398#issuecomment-5463058899) @⁠Nmzik just to say it this pr is not finished yet It's still WIP and it's only for Mac users
Author
Owner

@⁠Nmzik on GitHub · 2026-08-29 14:55 UTC · original

@⁠nacimoualla Sure. Could you please cleanup your PR first? It has commited changes from old PR

**@⁠Nmzik** on GitHub · 2026-08-29 14:55 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/398#issuecomment-5463094247) @⁠nacimoualla Sure. Could you please cleanup your PR first? It has commited changes from old PR
Author
Owner

@⁠nacimoualla on GitHub · 2026-08-29 14:57 UTC · original

@⁠Nmzik yeah sure

**@⁠nacimoualla** on GitHub · 2026-08-29 14:57 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/398#issuecomment-5463102505) @⁠Nmzik yeah sure
Author
Owner

@⁠nacimoualla on GitHub · 2026-08-29 14:58 UTC · original

@⁠Nmzik hey can you tell me did anyone tried to run jojo game in Mac OS?

**@⁠nacimoualla** on GitHub · 2026-08-29 14:58 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/398#issuecomment-5463107624) @⁠Nmzik hey can you tell me did anyone tried to run jojo game in Mac OS?
Author
Owner

@⁠Nmzik on GitHub · 2026-08-29 15:02 UTC · original

@⁠nacimoualla No idea. Just my 5 cents: it’s better to start with simple 2D games and gradually move to 3D games. That way, it’ll be easier for you. But since the backend is already working on Linux and Windows, it should be pretty easy to get the games running, at least in some half-corrected form. On Windows/Linux jojo is running fine

**@⁠Nmzik** on GitHub · 2026-08-29 15:02 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/398#issuecomment-5463126395) @⁠nacimoualla No idea. Just my 5 cents: it’s better to start with simple 2D games and gradually move to 3D games. That way, it’ll be easier for you. But since the backend is already working on Linux and Windows, it should be pretty easy to get the games running, at least in some half-corrected form. On Windows/Linux jojo is running fine
Author
Owner

@⁠nacimoualla on GitHub · 2026-08-29 15:04 UTC · original

@⁠nacimoualla No idea. Just my 5 cents: it’s better to start with simple 2D games and gradually move to 3D games. That way, it’ll be easier for you. But since the backend is already working on Linux and Windows, it should be pretty easy to get the games running, at least in some half-corrected form. On Windows/Linux jojo is running fine

I got a 3d game to show the bandai company logo now I am trying to make it work

**@⁠nacimoualla** on GitHub · 2026-08-29 15:04 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/398#issuecomment-5463135551) > @⁠nacimoualla No idea. Just my 5 cents: it’s better to start with simple 2D games and gradually move to 3D games. That way, it’ll be easier for you. But since the backend is already working on Linux and Windows, it should be pretty easy to get the games running, at least in some half-corrected form. On Windows/Linux jojo is running fine I got a 3d game to show the bandai company logo now I am trying to make it work
Author
Owner

@⁠nacimoualla on GitHub · 2026-08-29 19:04 UTC · original

@⁠Nmzik I got JoJo's Bizarre Adventure: All-Star Battle R to boot into menu after a lot of work lol

**@⁠nacimoualla** on GitHub · 2026-08-29 19:04 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/398#issuecomment-5464288308) @⁠Nmzik I got JoJo's Bizarre Adventure: All-Star Battle R to boot into menu after a lot of work lol
Author
Owner

@⁠Nmzik on GitHub · 2026-08-30 23:38 UTC · original

@⁠nacimoualla please do full clean up. It is impossible to merge (a lot of AI logs) + redundant code

**@⁠Nmzik** on GitHub · 2026-08-30 23:38 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/398#issuecomment-5471975715) @⁠nacimoualla please do full clean up. It is impossible to merge (a lot of AI logs) + redundant code

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.