graphics: accept Metal-backed Vulkan devices on macOS #2269
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!2269
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2269"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@bengidev on GitHub · 2026-11-14 07:08 UTC · original
bengidev:macos-metal-device→main· +86 −17 · 5 files · 1 commits · openWhy
On Apple Silicon, device selection rejects every device with
(issue #1068). All four are optional Vulkan features that Metal-backed drivers do not
implement, and the renderer only relies on them for shaders that ask for the matching
SPIR-V capability. Two more platform gaps sit right behind that one:
agcrequires itsdriver memory to land on the fixed
0x0fe0000000base, which Rosetta reserves, and aKosmicKrisp device does not advertise
VK_KHR_portability_subset, which Kyty requestedunconditionally.
What
Device selection (
vulkanWindow.cpp) — the five features above become optional onmacOS (selection warns, other platforms still reject), and
vkCreateDevicenever asks adevice for a feature it reports as unsupported:
VK_EXT_image_view_min_lodmoves from the required extension list to the optional set.The device is queried anyway, so the capability is known even where the extension is
absent, and
Image::FindViewonly attachesminLodwhen the device has it (views thenstart at their base level, as before).
shaderBufferInt64Atomics,shaderCullDistanceandfillModeNonSolidare taken fromthe device instead of being forced on, and their
pNextentries are unlinked whenunavailable.
VK_POLYGON_MODE_FILLwhenfillModeNonSolidis missing —Metal cannot rasterize point or line fill, so a wireframe request renders filled rather
than failing.
VK_KHR_portability_subsetis requested inVulkanCreateDevice(where the extensionlist is built from what the driver reports) instead of being pushed unconditionally.
GraphicContextrecords the resulting capabilities(
image_view_min_lod_enabled,fill_mode_non_solid_enabled,shader_buffer_int64_atomics_enabled,graphics_subgroups_enabled) so the renderer andthe shader emitter can pick a fallback instead of assuming the feature.
AGC (
agc.cpp) — the direct-memory mapping keeps asking for the fixed base first, andif the kernel refuses it retries without the fixed address and derives every address from
the base that comes back (
Graphics5Driver: driver DMEM mapped at 0x0000007000000000 instead of 0x0000000fe0000000). The previousEXIT_IF(address != DriverDmemBase)iswhat aborted every macOS run, and the same fixed-address assumption is already documented
in #1454.
Testing
Apple M1 Max, macOS 26.7, x86_64 build running under Rosetta, MoltenVK 1.4.2 bundled
with the KytyPS5 app. Before:
exit 65at device selection. After: device selected,swapchain created (1280x720), graphics and compute pipelines created, and Madden NFL 26
(PPSA26127) reaches its main menu — see the follow-up PR for the shader changes this
depends on.
Not verified: any other title, and the KosmicKrisp path beyond device creation (it needs
the shader changes too). Nothing here changes behaviour on Windows/Linux: the relaxed
checks and the
pNextunlinks only trigger for features a device actually lacks.Follow-up
shader: ...PR stacked on this branch covers the three translation problems Metalexposes next: descriptor aliasing, subgroup builtins in graphics stages, and 64-bit
atomics.
@coderabbitai[bot] on GitHub · 2026-11-14 07:14 UTC · original
Walkthrough
Vulkan device creation now treats selected features as optional on Apple and enables them only when supported. Image-view and pipeline creation use recorded capability flags.
Gen5Driver::Initializeretries DMEM mapping without fixed placement after a fixed-address mapping failure and derives the binding-table base from the returned address.Suggested reviewers:
nmzikChange: Bug fix
Merge Risk:
Moderate · up to
50123This makes Metal-backed Vulkan devices selectable on macOS, but some devices could be accepted and then fail at pipeline or shader creation, or when binding missing textures. The fallback memory mapping can also fail again at the same address. Address these before merging, or explicitly accept them pending the follow-up shader PR.
Pre-merge checks:
4
Full details: Title check
Explanation
The title names the main change: making Metal-backed Vulkan devices on macOS pass device selection. The changeset makes optional device features optional on macOS, adds fallbacks, and changes AGC memory mapping. The title does not mention the AGC change, but it is a secondary part of the change.
Full details: Description check
Explanation
The description explains the problem (device selection rejects Apple M1 Max devices), the changes to device selection, pipeline fallback, portability subset handling, GraphicContext capability fields, and the AGC memory mapping retry. It also gives testing details and a follow-up note, all of which match the changeset.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Share
@ -251,3 +265,3 @@"descriptorBindingPartiallyBound");check_feature(features13.robustImageAccess, "robustImageAccess");check_feature(robustness2.nullDescriptor, "nullDescriptor");check_optional_feature(robustness2.nullDescriptor, "nullDescriptor");@coderabbitai[bot] on GitHub · 2026-11-14 07:14 UTC · original
Keep
nullDescriptorrequired, or substitute a valid view for missing textures.On Apple,
nullDescriptoris no longer required for device selection (vulkanWindow.cpp:221-229,:267). Device creation then leaves the feature disabled. When a texture has no image,MakeImageInforeturns a nullimageView(descriptors.cpp:70-74). Its image entries are built atdescriptors.cpp:1079and submitted with the descriptor writes atdescriptors.cpp:1095-1107. WithoutnullDescriptor, descriptor writes cannot contain null resource handles. With validation enabled, the debug callback exits on that error (vulkanWindow.cpp:858-861). Without validation, the write is undefined.The PR objectives list four optional features and do not include
nullDescriptor. Restoring the required check keeps the existing requirement for this feature.Suggested fix
If the target device lacks
nullDescriptor, this change keeps the device unselected. To keep the device selectable,MakeImageInfomust return a valid placeholder view instead of a null handle. That change is outside the inspected code. Update the comment atvulkanWindow.cpp:670to match the final decision.Committable suggestion
@ -484,0 +512,4 @@// request the feature from a device that does not report it (MoltenVK reports false).features12.shaderBufferInt64Atomics = supported12.shaderBufferInt64Atomics;graphics.shader_buffer_int64_atomics_enabled =supported12.shaderBufferInt64Atomics == VK_TRUE;@coderabbitai[bot] on GitHub · 2026-11-14 07:14 UTC · original
Reject or lower 64-bit buffer atomics when
shaderBufferInt64Atomicsis unavailable.With
shaderBufferInt64Atomicsfalse, the device is accepted andshader_buffer_int64_atomics_enabledis set to false (vulkanWindow.cpp:513-515). No code reads that flag.spirvEmitterModule.cpp:773-776still requiresCapabilityInt64Atomicsfor any shader whereinfo.buffer_int64_atomicsis set.ShaderInfoCollection.cpp:289-290sets that flag for every 64-bit buffer atomic.The Vulkan environment appendix permits a SPIR-V capability only when a corresponding feature is enabled. On a device where no other feature backing
Int64Atomicsis enabled, such a shader requests an unsupported capability. Shader module creation can then fail or lead to undefined behavior.The header comment in
graphicContext.h:33-34describes a lowering for Metal. The inspected code does not show it. Its scope covers only atomic 64-bit loads, so it would not cover read-modify-write operations such asBufferAtomicIAdd64.When the flag is false, either lower these operations in the emitter or reject the shader before module creation. Use the same approach as
ResolveTexture, which exits on 64-bit image atomics whenshader_image_int64_atomics_enabledis false (descriptors.cpp:485-486).@ -577,3 +613,3 @@device_features.depthBiasClamp = VK_TRUE;device_features.shaderClipDistance = VK_TRUE;device_features.shaderCullDistance = VK_TRUE;device_features.shaderCullDistance = supported2.features.shaderCullDistance;@coderabbitai[bot] on GitHub · 2026-11-14 07:14 UTC · original
Gate
CullDistanceshader output onshaderCullDistance.vulkanWindow.cppnow accepts devices withoutshaderCullDistanceand passesVK_FALSEfor it at line 615. The shader recompiler still declaresCullDistancewhen a shader exports cull-distance data. The Vulkan specification states that shader modules must not useCullDistancewhen this feature is not enabled. A module that does so can fail pipeline creation on these devices.No shader-side check gates this declaration. The export and declaration path runs as follows:
ShaderIR.h:316setscull_distancefrom the export control bits.ShaderInfoCollection.cpp:233-235adds aCullDistanceoutput.spirvEmitterModule.cpp:786-788requiresCapabilityCullDistancewhencull_distance_variableis set.Handle the unsupported case explicitly before it reaches the emitter. Either skip the
CullDistanceoutput and capability, or reject shaders that need them on devices without the feature. Skipping the output changes culling results, so define that behavior before choosing this option.@ -4079,0 +4083,4 @@if (result != OK) {address = reinterpret_cast<void*>(DriverDmemBase);result = LibKernel::Memory::KernelMapNamedDirectMemory(&address, DriverDmemSize, 0x33, 0, physical_offset, DriverDmemSize, "SceAgcDriver");@coderabbitai[bot] on GitHub · 2026-11-14 07:14 UTC · original
The retry can request the address that the fixed attempt just failed to map.
When the fixed attempt reserves the target span and then
MapBackingfails, the span staysReserved.MapDirectMemorythen returnsENOMEM. The retry atDriverDmemBasewith flags0seesIsReservedSpansucceed. It keeps the same target and skipsFindGuestFreeRange. If the backing failure repeats at that address,Gen5Driver::Initializefails. The fallback does not reach a different address on this path.The retry should request placement without a hint. The code already derives the binding-table base from the returned address, so this does not change the consumer.
Suggested fix
Committable suggestion
@coderabbitai[bot] on GitHub · 2026-11-14 07:14 UTC · original · reviewed
Actionable comments posted: 4
a2eb2050-7ae5-4468-8084-8d5de967adf5Reviewing files that changed from the base of the PR and between
11d834dd82and501231ece1.src/graphics/host_gpu/graphicContext.hsrc/graphics/host_gpu/renderer/image/imageView.cppsrc/graphics/host_gpu/renderer/pipeline/shaders.cppsrc/graphics/presentation/window/vulkanWindow.cppsrc/libs/agc.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
@Fr0gzilla on GitHub · 2026-11-21 13:26 UTC · original
Tested on Apple M5, macOS 26.6 (25G72), MoltenVK 1.4.2, x86_64 build under Rosetta 2.
On current main (
39936ff), device selection still fails, and nullDescriptor is now missing too (required since892e70c8):#2402 and #1547 don't handle nullDescriptor. This PR does. It cherry-picks cleanly onto
39936ff, andshader_recompiler_compute_tests --device-creation-onlypasses:I don't have PS5 games, so this only covers device selection, not in-game rendering.
AI disclosure: I used an AI assistant to build, run the tests and read the logs; I checked the results myself on my Mac.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.