graphics: make minLod, buffer int64 atomics and cull distance optional on macOS #1082
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!1082
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1082/head"
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?
@overlordxrz-source on GitHub · 2026-10-05 21:56 UTC · original
overlordxrz-source:mac/optional-minlod-int64-cull→main· +93 −5 · 3 files · 2 commits · closed without mergingFixes device-selection failure on Apple Silicon reported in #1068.
MoltenVK v1.4.2 (bundled release) never exposes:
Previously all three were hard requirements on every platform, so VulkanFindPhysicalDevice rejected every Mac GPU with exit 65 before any game loaded.
This change, Apple-only:
Complementary to #959 (barycentrics); does not yet add shader fallbacks for CullDistance outputs / 64-bit buffer atomics, nor the vertex-stage subgroup guard (supportedStages=0) noted as the next blocker in #1068.
Testing performed:
AI disclosure (per repo AI Use policy): AI tooling assisted with code exploration and patch drafting. Human reviewed the full diff, built kyty_emulator (x86_64) and ran ctest before submitting, and remains responsible for correctness.
@coderabbitai[bot] on GitHub · 2026-10-05 22:03 UTC · original · edited 2026-10-05 22:53 UTC
📝 Walkthrough
Walkthrough
Vulkan device setup now records support for image-view minimum LOD, shader-buffer int64 atomics, and shader cull distance. On macOS, missing support for these features no longer rejects device selection, and feature enablement follows reported availability. When the minimum-LOD extension is unavailable, image-view creation trims whole mip levels from the requested range and drops the fractional remainder.
Suggested reviewers:
nmzikPriority: ➖ Normal
Change: Bug fix
Merge Risk: 🟡 Moderate · up to
e709eSome Apple devices may still fail to start, and affected graphics pipelines may fail on devices lacking the optional shader features. Resolve these paths before merging unless their limitations are explicitly accepted.
Security Architecture Review
Security architecture risk: 🟡 Moderate · up to
e709eThe new minimum-LOD fallback breaks image-view reuse: repeated valid texture bindings can accumulate host GPU resources until the image is destroyed. The demonstrated scope is the emulator and its rendering resources, not privilege escalation or remote access. Unsupported shader features also remain a compatibility limitation on newly accepted devices.
Retained concerns
Security review details
Security Blast Radius
Security Findings and Attack Paths
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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
Comment
@coderabbitai helpto get the list of available commands.@ -363,2 +374,3 @@}vk::ImageViewMinLodCreateInfoEXT min_lod {};if (normalized.min_lod != 0) {if (normalized.min_lod != 0 && m_graphics.image_view_min_lod_enabled) {@coderabbitai[bot] on GitHub · 2026-10-05 22:03 UTC · original · edited 2026-10-05 22:54 UTC
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Apply the base-level approximation when min-LOD is unavailable.
If a texture descriptor requests
MinLodaboveBaseLevel,TextureViewInforecords the difference innormalized.min_lod. This branch then omits the clamp without changingnormalized.base_level, so the view still exposes mip levels below the requested minimum. Adjust the base level and level count to a valid integer-mip approximation, or provide another fallback. The min-LOD structure is what otherwise clamps sampling to the requested level. (docs.vulkan.org)✅ Addressed in commit
e709e9e@ -493,0 +550,4 @@#if defined(__APPLE__)// MoltenVK hardcodes shaderBufferInt64Atomics=false; request only what is supported.features12.shaderBufferInt64Atomics = supported_features12.shaderBufferInt64Atomics;#endif@coderabbitai[bot] on GitHub · 2026-10-05 22:03 UTC · original · edited 2026-10-05 22:54 UTC
🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 42855
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 23752
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 12360
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 3642
🌐 Web query:
site:docs.vulkan.org/spec/latest/appendices/spirvenv.html Int64Atomics StorageBuffer shaderBufferInt64Atomics requirement💡 Result:
Gate 64-bit buffer-atomic shaders when the device feature is disabled.
On Apple, a device can be accepted with
shaderBufferInt64Atomicsunsupported, and device creation then disables the feature. GuestBUFFER_ATOMIC_SWAP_X2,BUFFER_ATOMIC_AND_X2, andBUFFER_ATOMIC_OR_X2instructions lower to native 64-bit storage-buffer atomics without checkingshader_buffer_int64_atomics_enabled. Vulkan requires this feature for those operations, so the resulting pipeline may be rejected. Reject these shaders when the feature is disabled, or add a legal fallback. Update the log so it does not claim a fallback exists before one is implemented.@ -574,1 +635,4 @@device_features.shaderClipDistance = VK_TRUE;#if defined(__APPLE__)device_features.shaderCullDistance =graphics.shader_cull_distance_enabled ? VK_TRUE : VK_FALSE;@coderabbitai[bot] on GitHub · 2026-10-05 22:03 UTC · original · edited 2026-10-05 22:58 UTC
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 40066
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 14251
Require
shaderCullDistanceon Apple until the shader fallback exists.When translated shader metadata includes a cull-distance export, the SPIR-V backend emits
BuiltInCullDistanceand declaresCapabilityCullDistance. Apple device selection can accept a device withoutshaderCullDistance, then create the device with that feature disabled. The backend does not checkgraphics.shader_cull_distance_enabled, so it can still generate a shader that requires the disabled feature. The log claiming that cull-distance outputs “will be dropped” does not describe an implemented fallback.🐛 Suggested fix
@ -949,6 +1014,7 @@ void WindowContext::CreateVulkan() {device_extensions.push_back(VK_EXT_DEPTH_CLIP_ENABLE_EXTENSION_NAME);device_extensions.push_back(VK_EXT_COLOR_WRITE_ENABLE_EXTENSION_NAME);device_extensions.push_back(VK_KHR_FRAGMENT_SHADER_BARYCENTRIC_EXTENSION_NAME);device_extensions.push_back(VK_EXT_IMAGE_VIEW_MIN_LOD_EXTENSION_NAME);@coderabbitai[bot] on GitHub · 2026-10-05 22:03 UTC · original · edited 2026-10-05 22:55 UTC
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Request min-LOD as an optional extension on Apple.
If an Apple device advertises
VK_EXT_image_view_min_lod, this extension list still omits it. The later optional-extension scan also omits it, somin_lod_extensionstays false and the application never uses the available feature. Add it when the selected Apple device advertises it; keep the existing requirement on other platforms. The Vulkan specification defines it as a device extension. (docs.vulkan.org)✅ Addressed in commit
e709e9e@coderabbitai[bot] on GitHub · 2026-10-05 22:03 UTC · original · reviewed
Actionable comments posted: 4
ℹ️ Review info
⚙️ Run configuration
5c042136-6287-40a1-bf96-a0310ddf1a7d📥 Commits
Reviewing files that changed from the base of the PR and between
cdb64bfd4fandaf7c92d861.📒 Files selected for processing (3)
src/graphics/host_gpu/graphicContext.hsrc/graphics/host_gpu/renderer/image/imageView.cppsrc/graphics/presentation/window/vulkanWindow.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
@ -363,2 +374,3 @@}vk::ImageViewMinLodCreateInfoEXT min_lod {};if (normalized.min_lod != 0) {if (normalized.min_lod != 0 && m_graphics.image_view_min_lod_enabled) {@overlordxrz-source on GitHub · 2026-10-05 22:44 UTC · original
Taken - when min-LOD is unavailable the view now trims whole mip levels (integer part of the U4.8 clamp) instead of exposing mips below the requested minimum. Fractional remainder still dropped; exact clamp needs the extension. In
e709e9e, emulator + shader_cfg/memory_tracker/texture_cache_depth_readback green.@ -574,1 +635,4 @@device_features.shaderClipDistance = VK_TRUE;#if defined(__APPLE__)device_features.shaderCullDistance =graphics.shader_cull_distance_enabled ? VK_TRUE : VK_FALSE;@overlordxrz-source on GitHub · 2026-10-05 22:44 UTC · original
Same treatment as the int64-atomics note: log is now honest that cull-distance-exporting shaders may fail without the feature, fallback marked as follow-up. Keeping device creation permissive on Apple is intentional - requiring the feature would re-reject every Mac (the bug being fixed). In
e709e9e.@ -493,0 +550,4 @@#if defined(__APPLE__)// MoltenVK hardcodes shaderBufferInt64Atomics=false; request only what is supported.features12.shaderBufferInt64Atomics = supported_features12.shaderBufferInt64Atomics;#endif@overlordxrz-source on GitHub · 2026-10-05 22:44 UTC · original
Fair - the log claimed a fallback that doesn't exist. Fixed to warn that shaders using 64-bit storage-buffer atomics may fail pipeline creation without the feature (citing the same VUID), with a comment marking drop/emulation fallbacks as follow-up work. Deliberately not gating device creation: the PR's purpose is letting MoltenVK devices boot at all. In
e709e9e.@ -949,6 +1014,7 @@ void WindowContext::CreateVulkan() {device_extensions.push_back(VK_EXT_DEPTH_CLIP_ENABLE_EXTENSION_NAME);device_extensions.push_back(VK_EXT_COLOR_WRITE_ENABLE_EXTENSION_NAME);device_extensions.push_back(VK_KHR_FRAGMENT_SHADER_BARYCENTRIC_EXTENSION_NAME);device_extensions.push_back(VK_EXT_IMAGE_VIEW_MIN_LOD_EXTENSION_NAME);@overlordxrz-source on GitHub · 2026-10-05 22:44 UTC · original
Good spot - fixed. The Apple optional-extension scan now picks up VK_EXT_image_view_min_lod when advertised, so a newer MoltenVK with the extension gets it requested and used instead of always falling back. In
e709e9e.@ -1014,0 +1081,4 @@// VK_EXT_image_view_min_lod is required on other platforms but optional here;// enable it when a (newer) MoltenVK advertises it so the feature gets used.if (HasExtension(available_extensions, VK_EXT_IMAGE_VIEW_MIN_LOD_EXTENSION_NAME)) {device_extensions.push_back(VK_EXT_IMAGE_VIEW_MIN_LOD_EXTENSION_NAME);@coderabbitai[bot] on GitHub · 2026-10-05 22:48 UTC · original
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Enable min-LOD only when its feature is supported.
On Apple, a device can advertise
VK_EXT_image_view_min_lodbut reportminLod = VK_FALSE. This branch adds the extension, andVulkanCreateDevicethen requestsminLod = VK_TRUE.vkCreateDevicemust fail for an unsupported requested feature, so the device cannot reach the image-view fallback. QueryminLodbefore setting the creation feature; leave it disabled when support is false. (docs.vulkan.org)As per the retrieved learning, optional runtime capabilities must be requested with the capabilities they depend on.
Source: Learnings
@coderabbitai[bot] on GitHub · 2026-10-05 22:48 UTC · original · reviewed
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
39f0a946-af2a-4256-aa98-f11647165216📥 Commits
Reviewing files that changed from the base of the PR and between
af7c92d861ande709e9edd2.📒 Files selected for processing (2)
src/graphics/host_gpu/renderer/image/imageView.cppsrc/graphics/presentation/window/vulkanWindow.cpp🚧 Files skipped from review as they are similar to previous changes (1)
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 4 remain after this review.
@ -363,2 +374,3 @@}vk::ImageViewMinLodCreateInfoEXT min_lod {};if (normalized.min_lod != 0) {if (normalized.min_lod != 0 && m_graphics.image_view_min_lod_enabled) {@coderabbitai[bot] on GitHub · 2026-10-05 22:54 UTC · original
@overlordxrz-sourceThanks for the fix. The supplied code now trims whole mip levels and keeps at least one mip level in the view. This addresses the requested integer-mip approximation. Exact fractional clamping still requiresVK_EXT_image_view_min_lod.If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!
✅ Review thread resolved.
You are interacting with an AI system.
@ -493,0 +550,4 @@#if defined(__APPLE__)// MoltenVK hardcodes shaderBufferInt64Atomics=false; request only what is supported.features12.shaderBufferInt64Atomics = supported_features12.shaderBufferInt64Atomics;#endif@coderabbitai[bot] on GitHub · 2026-10-05 22:54 UTC · original
@overlordxrz-sourceThanks for the clarification. The updated warning ine709e9ecorrectly states that no fallback exists.Keeping device creation permissive matches this PR’s boot objective. My original request concerned gating affected shaders, not rejecting the device. The warning fixes the misleading log, but the unsupported shader path remains follow-up work.
Would you like me to open a follow-up issue for shader-level handling of unsupported 64-bit buffer atomics?
✏️ Learnings added
If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!
You are interacting with an AI system.
@ -949,6 +1014,7 @@ void WindowContext::CreateVulkan() {device_extensions.push_back(VK_EXT_DEPTH_CLIP_ENABLE_EXTENSION_NAME);device_extensions.push_back(VK_EXT_COLOR_WRITE_ENABLE_EXTENSION_NAME);device_extensions.push_back(VK_KHR_FRAGMENT_SHADER_BARYCENTRIC_EXTENSION_NAME);device_extensions.push_back(VK_EXT_IMAGE_VIEW_MIN_LOD_EXTENSION_NAME);@coderabbitai[bot] on GitHub · 2026-10-05 22:55 UTC · original
@overlordxrz-sourceThanks for the fix. The Apple optional-extension scan now requestsVK_EXT_image_view_min_lodwhen advertised. Non-Apple platforms still require the extension. This addresses the finding.If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!
✅ Review thread resolved.
You are interacting with an AI system.
@ -574,1 +635,4 @@device_features.shaderClipDistance = VK_TRUE;#if defined(__APPLE__)device_features.shaderCullDistance =graphics.shader_cull_distance_enabled ? VK_TRUE : VK_FALSE;@coderabbitai[bot] on GitHub · 2026-10-05 22:58 UTC · original
@overlordxrz-sourceThanks for the clarification. I withdraw the recommendation to requireshaderCullDistanceon Apple. That requirement would defeat the device-selection fix.The supplied code now warns that shaders exporting cull distance may fail pipeline creation. It also identifies the missing fallback as follow-up work. Device acceptance and support for those shaders are separate concerns.
Would you like me to open a follow-up issue for the cull-distance shader fallback?
✏️ Learnings added
🧠 Learnings used
✅ Review thread resolved.
You are interacting with an AI system.
@juanfariasdev on GitHub · 2026-10-05 23:10 UTC · original
Hey @overlordxrz-source, here's my full review of #1082 as of
e709e9e, as promised. Your follow-up already fixed the log wording, so I left that out.imageView.cpp): the trim runs after thecached.info == normalizedlookup, butviews.push_back({normalized, view})stores the trimmed info (min_lod = 0, shiftedbase_level). The next call with the same untrimmed info never matches, so everyFindViewwith a non-zeromin_lodcreates a newVkImageView, and the cache grows without bound.OpImageQuerySizeLod,OpImageQueryLevelsandOpImageFetchreturn in the recompiled shaders, whileVK_EXT_image_view_min_lodonly clamps sampling LOD selection. Dropping the clamp seems safer than shifting the view.FindViewchecks also run on Windows and Linux. They should behave the same there, but I'd keep this behind__APPLE__.shader_buffer_int64_atomics_enabledis only read by the log line right after it's set.shader_cull_distance_enabledis only read for device creation, a few lines later.VulkanFindPhysicalDevice, theelse { check_feature(...) }on__APPLE__only runs when the feature is supported, so the check always passes.Subgroup builtins are not available in this type of function(the same next blocker #1068 reports for GRIS), and on MoltenVK 1.4.1+ push descriptors corrupt rendering. #1083 handles both, so I'd suggest closing this one in favor of #1083 to avoid conflicting changes invulkanWindow.cpp.@overlordxrz-source on GitHub · 2026-10-06 00:32 UTC · original
Replying to @juanfariasdev's review: all seven points taken - point 1 is a genuine cache-coherence bug I introduced (lookup-before-trim, store-after-trim), and point 2 settles it semantically (dropping beats shifting for query/fetch correctness). Rather than rework this PR into a worse #1083, I'm closing it in favor of yours: yours is behind APPLE throughout, honestly states the atomics/cull limitations, covers the next two real blockers (push descriptors, vertex subgroups), and is tested against actual games. Thanks for the thorough review - it made the right call obvious.
@overlordxrz-source on GitHub · 2026-10-06 00:32 UTC · original
Superseded by #1083, which covers this PR's device-selection fix plus the next two macOS blockers (push descriptors, vertex subgroup builtins), all behind APPLE and tested against real games. See discussion above for the review points that decided it.
Pull request closed