Skip to content

macOS: through the Vulkan loader, the test tools opt in to portability enumeration; validation runs on MoltenVK (TEST-MAC-LOADER-PORTABILITY) - #2178

Draft
Tauwni wants to merge 6 commits into
ProjectLeonida:mainfrom
Tauwni:fix/mac-loader-portability-enumeration
Draft

Tauwni wants to merge 6 commits into
ProjectLeonida:mainfrom
Tauwni:fix/mac-loader-portability-enumeration

Conversation

@Tauwni

@Tauwni Tauwni commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: TEST-MAC-LOADER-PORTABILITY (#1608 (comment))

What and why

On a Mac, the test tools open MoltenVK directly, which can't load layers. The way to run with LEONIDA_VK_VALIDATION=1 is LEONIDA_VULKAN_LOADER, the standard loader. But behind the loader, MoltenVK is a portability driver:

  • the loader lists it only for an instance created with VK_KHR_portability_enumeration and VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR;
  • a device it exposes must enable VK_KHR_portability_subset.

None of the tools asked for either, so through the loader they found no device:

vkCreateInstance: Found drivers that contain devices which support the portability subset, but the instance does not enumerate portability drivers!

tools/vk_subgroup_info.py returned vkCreateInstance failed (-9) instead, so run_gpu_tests.py lost the probes it reads (per_vertex_inputs, among others). In practice, validation couldn't run on MoltenVK.

  • runtime/test/vulkan_loader.h: when LEONIDA_VULKAN_LOADER is set on macOS, load_vulkan() returns a vkGetInstanceProcAddr wrapper. It wraps vkCreateInstance, adding the extension and its flag where the loader offers them, and vkCreateDevice, adding VK_KHR_portability_subset where the device offers it. Everything else goes to the loader unchanged. Every tool gets this from load_vulkan(), so no tool changes.
  • tools/vk_subgroup_info.py: the same instance opt-in, plus 2 unit tests.
  • Direct MoltenVK, the default, is unchanged, and so are other platforms.
  • docs/testing.md: how to run with validation on a Mac.

Tested

Apple M3, macOS 26.5.1, main ad41fd517 + this commit, Vulkan loader 1.4.363 and validation layers from Homebrew:

What validation reports on MoltenVK, now that it can run (the runtime is unchanged; docs/testing.md now lists these and the filter, see the update below):

  • Nearly every translated shader: VUID-RuntimeSpirv-shaderDenormPreserveFloat16-06296. That is the documented DenormPreserve 16 trade-off (design.md, "Float controls (f16 denormals)"): MoltenVK reports shaderDenormPreserveFloat16 false.
  • vk_bindless_grow, vk_null_descriptor, vk_bindless_test: VUID-vkCreateDescriptorSetLayout-support-09582. The bindless set layout has 11777 descriptors, against MoltenVK's maxPerSetDescriptors of 1212, and vkGetDescriptorSetLayoutSupport answers false for it. size_bindings keeps the default counts above that limit on purpose ("it never shrinks step 1"). The draws pass, but the layout is outside the spec on MoltenVK.

Update (de37175f5, 000258e00, then main merged): docs/testing.md lists the three validation messages MoltenVK 1.4.2 reports that are not test failures, plus the VK_LAYER_MESSAGE_ID_FILTER that hides them:

  • 06296 and VUID-VkShaderModuleCreateInfo-pCode-08740: the DenormPreserve 16 trade-off;
  • 09582: MoltenVK's own count, 4 × (31 + 256 + 16) = 1212, which ignores argument buffers (KhronosGroup/MoltenVK#2573).

With the filter, vk_bindless_test, vk_bindless_grow_test and vk_null_descriptor_test pass under validation. So does the whole run_gpu_tests.py suite at main a73a57e13 (195/268, the same three failures as without validation).

GPUs tested: Apple M3 (10-core GPU), MoltenVK 1.4.2 and KosmicKrisp (Mesa 26.3.1), macOS 26.5.1 (25F80); llvmpipe (Mesa 26.3.1)

AI-assisted: yes (Claude Code)

Checklist

  • Based on current main and merges cleanly.
  • One topic.
  • No game data, keys or decryption.

🤖 Generated with Claude Code

…y enumeration, so MoltenVK is found

With LEONIDA_VULKAN_LOADER (the only way to reach VK_LAYER_KHRONOS_validation on a Mac) the loader lists MoltenVK
only for an instance created with VK_KHR_portability_enumeration and its flag, and a device it exposes must enable
VK_KHR_portability_subset. runtime/test/vulkan_loader.h now wraps vkCreateInstance / vkCreateDevice to add both
where offered; tools/vk_subgroup_info.py opts in the same way. Direct MoltenVK is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… that are not failures, and the filter

VUID-09582 is MoltenVK's own conservative count: vkGetDescriptorSetLayoutSupport
compares the set with maxPerSetDescriptors = 4 x (31 + 256 + 16) = 1212, its
per-stage counts without argument buffers. With the filter, vk_bindless_test
(ps_tex), vk_bindless_grow_test and vk_null_descriptor_test pass under
validation on an Apple M3.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Tauwni

Tauwni commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Update at de37175f5, docs only: docs/testing.md now lists the three validation messages MoltenVK 1.4.2 reports that are not test failures, plus the VK_LAYER_MESSAGE_ID_FILTER that hides them.

  • VUID-RuntimeSpirv-shaderDenormPreserveFloat16-06296 and VUID-VkShaderModuleCreateInfo-pCode-08740: the documented DenormPreserve 16 trade-off.
  • VUID-vkCreateDescriptorSetLayout-support-09582: in MoltenVK 1.4.2's source, vkGetDescriptorSetLayoutSupport just compares the set's descriptor count with maxPerSetDescriptors. MoltenVK computes that limit in getMaxPerSetDescriptorCount() as max(4 × (buffers + textures + samplers per stage), 1024) = 4 × (31 + 256 + 16) = 1212, which ignores the argument buffers it uses on this GPU. So nothing in the runtime is shrunk for it.

With the filter on an Apple M3, under LEONIDA_VK_VALIDATION=1 through the loader:

  • vk_bindless_test (ps_tex): 15 draws read back, 0 bad pixels, 0 validation errors.
  • vk_bindless_grow_test and vk_null_descriptor_test: ok, 0 validation errors.

AI-assisted (Claude Code).

…youtSupport count

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Tauwni

Tauwni commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

I ran the whole GPU suite under validation, using this branch merged onto main a73a57e13 (Apple M3, macOS 26.5.1, MoltenVK 1.4.2 through the loader). Settings: LEONIDA_VK_VALIDATION=1 with the VK_LAYER_MESSAGE_ID_FILTER from docs/testing.md.

Result: 195/268 passed, 70 skipped. The three failures are the ones the suite also has without validation: cs_fma_fused (#1724), cs_imgatomic_ext (#1518) and ps_ssharp (#1774). So apart from the three filtered messages, the layer reports nothing on any of the 268 fixtures on MoltenVK.

AI-assisted (Claude Code). No game data.

@wavehs wavehs left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

macOS arm64 check of #2178 (TEST-MAC-LOADER-PORTABILITY). This one is squarely on my platform: portability enumeration through libvulkan with both Mac drivers, on the C++ tools and on tools/vk_subgroup_info.py.

Tested head 5b835b636 merged onto main bdbc7e923 as merge 50a9c7f5b (clean, no conflicts).

Environment: Apple M3 Pro arm64, macOS 27.2.1, Apple clang 21.0.0, CMake 4.5.0, CPython 3.15.2, Vulkan-Headers 1.4.363.0, MoltenVK 1.4.0 (ICD at /opt/homebrew/etc/vulkan/icd.d/MoltenVK_icd.json), KosmicKrisp = Mesa 26.3.0, loader /opt/homebrew/lib/libvulkan.1.dylib.

The fix does what it says on both paths

  • C++ tool through the loader, MoltenVK ICD: vk_compute_test cs_bounds.spv 1 dump prints device: Apple M3 Pro (subgroup 4..32) and 1 groups x 64: 0 mismatches with the expected eight words. Before the change the same command cannot even create the instance (see NC 1).
  • Same tool through the loader with the KosmicKrisp ICD (VK_ICD_FILENAMES=.../kosmickrisp_mesa_icd.aarch64.json): still runs and reports 0 mismatches, so the new wrapper does not disturb the non-portability Mac driver.
  • Through the loader with no VK_DRIVER_FILES at all, MoltenVK is still found (the loader's default ICD directory), so the documented VK_DRIVER_FILES is a way to pin the driver, not a requirement.
  • tools/vk_subgroup_info.py through the loader now prints the MoltenVK device JSON ("device": "Apple M3 Pro", per_vertex_inputs: false, ...) instead of failing.
  • python -I tests/test_vk_subgroup_info.py: 57 tests OK, including the two new PortabilityEnumerationTest cases (extension offered + loader env, and neither/no Darwin/platform guard).

Negative controls

  1. C++: revert only runtime/test/vulkan_loader.h, rebuild vk_compute_test, same command through the loader with MoltenVK: FAILED vkCreateInstance(&ici, nullptr, &inst) -> -9 (line 232) - VK_ERROR_INCOMPATIBLE_DRIVER, the loader refusing to hand out a portability-only ICD to an instance that did not opt in.
  2. Python: revert only tools/vk_subgroup_info.py, same env: {"error": "RuntimeError: vkCreateInstance failed (-9)"}. Restored.

What I could not verify: the validation-layer half of the docs change
docs/testing.md also documents LEONIDA_VK_VALIDATION=1 on MoltenVK, the VK_LAYER_PATH/DYLD_FALLBACK_LIBRARY_PATH setup, and three VUIDs to filter. vulkan-validationlayers is not installed here (/opt/homebrew/opt/vulkan-validationlayers does not exist), so none of that is tested in this review: the layer messages, their IDs and the per-test effects are taken from the PR, not reproduced. The portability-enumeration mechanism that the layer needs in order to see MoltenVK at all is verified above.

Nits

  • std::vector<const char*> names(info->ppEnabledExtensionNames, info->ppEnabledExtensionNames + info->enabledExtensionCount) (runtime/test/vulkan_loader.h, both create_instance and create_device) forms an iterator pair from a null pointer when the count is 0, which is technically undefined behaviour even though libc++/libstdc++ produce an empty vector. The tools here pass at least one extension in practice, but a count ? ... : nullptr guard (or assigning only when non-zero) costs nothing and keeps UBSan quiet on a future tool.
  • last_instance() is a single global written by every create_instance and read by create_device. All the test tools create one instance, so this is fine today; if one ever creates two and then a device on the first, the wrapper fetches vkCreateDevice/vkEnumerateDeviceExtensionProperties through the wrong instance handle. The function pointers are the same across instances in the loader, so it would still work, but a comment saying "one instance per tool" would record the assumption.
  • The instance wrapper turns portability enumeration on whenever the loader offers the extension, even if the tool's own VkInstanceCreateInfo did not ask for it - that is the point of the change, and the extension is only added when offered, so a non-portability loader/driver sees no difference.

Not run: the validation layer (above), Windows/Linux loader paths (the wrapper is #ifdef __APPLE__), and the full GPU suite (only cs_bounds and the subgroup-info probe were run through the loader; the direct-MoltenVK path every earlier run used is untouched by this PR).

python -I scripts/check_no_game_data.py on the four changed files: clean.

No game files. AI-assisted.

… one-instance assumption written down

From wavehs's review: copy ppEnabledExtensionNames only when the count is not
0, and say why last_instance() is enough for the test tools.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Tauwni

Tauwni commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

@wavehs thanks for the thorough review and the negative controls. Both nits are in 2663850d3:

  • Null extension list: create_instance and create_device now copy ppEnabledExtensionNames only when enabledExtensionCount is not 0, so no iterator pair is formed from a null pointer.
  • last_instance(): a comment now records the assumption: each test tool makes one instance, and the loader's device entry points are the same across instances anyway.

Rerun on the Apple M3 (macOS 26.5.1) with test programs rebuilt from this head. run_gpu_tests.py gives 195/268 directly on MoltenVK 1.4.2, 195/268 through the loader on MoltenVK, and 190/268 through the loader on KosmicKrisp, the same counts as before. vk_bindless_grow_test under LEONIDA_VK_VALIDATION=1 with the documented filter: ok.

On the validation half you couldn't check: I ran the whole suite under the layer on this machine (195/268, the same three failures as without it; my comment above has the details).

AI-assisted (Claude Code).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants