Skip to content

vk_validation: enable VK_KHR_portability_enumeration and VK_KHR_portability_subset on macOS - #6404

Open
TheAirborneCoder wants to merge 1 commit into
ItsNotRexed:mainfrom
TheAirborneCoder:mac-vk-val-portability
Open

TheAirborneCoder wants to merge 1 commit into
ItsNotRexed:mainfrom
TheAirborneCoder:mac-vk-val-portability

Conversation

@TheAirborneCoder

Copy link
Copy Markdown
Contributor

Follow-up to #4005 / #4025 (claimed in #6214): enable macOS Vulkan portability enumeration and portability subset when running standalone Vulkan test tools with LEONIDA_VK_VALIDATION=1 via the Vulkan loader (libvulkan.1.dylib).

Why

On macOS, direct libMoltenVK.dylib exposes no Vulkan layers, so running LEONIDA_VK_VALIDATION=1 requires loading Homebrew's libvulkan.1.dylib with VK_LAYER_PATH pointing at vulkan-validationlayers. Two portability requirements block that path on main (561b65a83):

  1. vkCreateInstance fails with VK_ERROR_INCOMPATIBLE_DRIVER (-9) because MoltenVK is a portability driver and requires VK_KHR_portability_enumeration + VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR.
  2. Once instance creation succeeds, VK_LAYER_KHRONOS_validation emits VUID-VkDeviceCreateInfo-pProperties-04451 unless "VK_KHR_portability_subset" is enabled on VkDeviceCreateInfo when advertised by the physical device.

What changed

  • runtime/test/vk_validation.h:
    • OptInValidation::prepare() queries vkEnumerateInstanceExtensionProperties and, when VK_KHR_portability_enumeration is advertised, deduplicates and appends it while setting VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR (safe no-op on non-portability loaders).
    • Adds OptInValidation::prepare_device() to query vkEnumerateDeviceExtensionProperties and deduplicate/append VK_KHR_portability_subset when advertised.
  • runtime/test/vk_compute_test.cpp & runtime/test/vk_test_device.h: wire prepare_device() / portability subset opt-in.
  • runtime/test/vk_validation_test.cpp & runtime/CMakeLists.txt: unit tests covering portability extension discovery, deduplication, and non-portability no-op behavior (vk_validation registered in ctest).
  • docs/testing.md: document the macOS Homebrew libvulkan.1.dylib + vulkan-validationlayers invocation (VK_LAYER_PATH, DYLD_FALLBACK_LIBRARY_PATH, MoltenVK_icd.json under /opt/homebrew/etc/vulkan/icd.d).

Verification

Tested on Apple M2 Ultra (Mac Studio, 60-core GPU), macOS 27.3 (26C5035r), MoltenVK 1.4.2, KosmicKrisp (Mesa 26.3.1), Homebrew vulkan-loader 1.4.363.0, vulkan-validationlayers 1.4.363.0, AppleClang 21.0.0:

  • Before (main 561b65a83): vk_compute_test with LEONIDA_VULKAN_LOADER=/opt/homebrew/lib/libvulkan.1.dylib, VK_DRIVER_FILES=/opt/homebrew/etc/vulkan/icd.d/MoltenVK_icd.json, LEONIDA_VK_VALIDATION=1 failed with FAILED vkCreateInstance(&ici, nullptr, &inst) -> -9 (line 215).
  • After (7b1fb5783):
    • vk_compute_test with LEONIDA_VK_VALIDATION=1 (using --no-float-controls SPIR-V since Metal reports shaderDenormPreserveFloat16 = false): exit 0, 0 validation errors on both MoltenVK 1.4.2 (2 groups x 64: 0 mismatches) and KosmicKrisp 26.3.1 (2 groups x 64: 0 mismatches).
    • ctest --test-dir runtime/build/macos --output-on-failure: 63/63 passed both on default direct MoltenVK (61 pass, 2 skip) and under LEONIDA_VK_VALIDATION=1 on MoltenVK via libvulkan.1.dylib (62 pass including vk_validation and vk_sync_validation, 1 skip).
    • python3 -m compileall -q make_game.py tools tests, tests/test_docs_*.py, tests/test_ci_registration.py, tests/test_ctest_registration.py, tests/test_text_*.py, and python3 -m unittest discover -s tests/semantic -v (6,150 tests OK).

No game files used. Once #4025 lands, its four harnesses (vk_harness, vk_store_test, vk_texture_test, vk_sampler_test) can call validation.prepare_device() as well.

AI-assisted (Gemini 4 Carbon / Neon).

…set under LEONIDA_VK_VALIDATION

On macOS, direct libMoltenVK.dylib exposes no Vulkan layers, so running test
programs under LEONIDA_VK_VALIDATION=1 requires loading libvulkan.1.dylib via
LEONIDA_VULKAN_LOADER. Because MoltenVK is a portability driver, the Vulkan
loader returns VK_ERROR_INCOMPATIBLE_DRIVER (-9) unless the instance enables
VK_KHR_portability_enumeration with VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR,
and Khronos validation reports VUID-VkDeviceCreateInfo-pProperties-04451 on
vkCreateDevice unless VK_KHR_portability_subset is also enabled when the
physical device advertises it.

- runtime/test/vk_validation.h: add deduplicated enable_portability_enumeration
  in OptInValidation::prepare() when vkEnumerateInstanceExtensionProperties
  lists VK_KHR_portability_enumeration, and add OptInValidation::prepare_device()
  to enable VK_KHR_portability_subset when the device lists it. No-op when
  LEONIDA_VK_VALIDATION is unset or "0", or when the loader/device does not
  advertise the extension.
- runtime/test/vk_compute_test.cpp: call validation.prepare_device() before
  vkCreateDevice.
- runtime/test/vk_test_device.h: reuse the portability enumeration and subset
  helpers under LEONIDA_VK_VALIDATION so standalone CTest targets (including
  vk_sync_validation_selftest) also run under validation on MoltenVK.
- runtime/test/vk_validation_test.cpp, runtime/CMakeLists.txt: add a CPU-only
  unit test (vk_validation) covering disabled, missing-layer, non-portability,
  portability, and duplicate-entry cases.
- docs/testing.md: note the Homebrew vulkan-validationlayers + libvulkan.1.dylib
  setup for LEONIDA_VK_VALIDATION=1 on macOS.

AI-assisted.
@thehollowedone

Copy link
Copy Markdown

Independent Windows check of standalone 7b1fb578. Windows 11 x64, RTX 3080 Ti / 621.35, MSVC 19.44, Vulkan SDK 1.4.363.0.

Stock vk_validation passed. The stock cs_lds shader passed spirv-val and matched all 256 expected words through vk_compute_test. The loader confirmed that Khronos validation was active for both the instance and device. Core and synchronization validation reported zero errors.

The Windows loader advertised portability enumeration. The NVIDIA device did not advertise portability subset, so that branch was exercised by the unit test's mock. Synthetic inputs only. AI-assisted.

@JRamos1993

JRamos1993 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Tested 7b1fb57 merged onto main 1cc6e3c on an RTX 5090 (driver 621.24), Windows 11, MSVC 19.44, Vulkan SDK 1.4.363, RelWithDebInfo:

  • Full ctest: 259/260. The failures main 1cc6e3c also has without this PR: d3d12_indirect_dispatch_count.
  • vk_validation: passes 20 of 20 runs, and passes under LEONIDA_VK_VALIDATION=1 with 0 validation messages.
  • Warnings: none new in the files this PR changes.

AI-assisted (Claude Code).

@trick-ye

Copy link
Copy Markdown

Tested 7b1fb578 on AMD Radeon RX 7800 XT (RDNA3), AMD 26.11.2 (Windows driver 32.0.32029.2010), Windows 11 26200: the new vk_validation passes; no d3d12_ test changes result against main.

  • ctest -R d3d12_ -j 1 plus vk_validation: 94 tests, 86 pass, 5 skipped, 3 fail. The three failures are the ones main 561b65a8 has on this card: d3d12_texture_tiles (D3D-597), d3d12_indirect_dispatch_count (D3D-594) and d3d12_pipeline_library_host (D3D-600). None of the 93 d3d12_ tests in my main run changed result.
  • The new CPU-only vk_validation passes on Windows/MSVC. My runner does not set LEONIDA_VK_VALIDATION, so the portability paths themselves were not exercised on a device; this only shows that no d3d12_ result changed with validation off.
  • Read the diff; nothing to flag.
  • MSVC 14.42 (VS 2022), Windows SDK 10.0.26100, Vulkan SDK 1.4.363.0, llvm-mc 23.1.6, RelWithDebInfo, LEONIDA_VK_DEVICE=7800; all runtime targets built (GameInput shim not built: no SDL3). Synthetic tests only, no game files.

AI-assisted (Claude Code).

@jgrizon

jgrizon commented Nov 23, 2026

Copy link
Copy Markdown

Tested 7b1fb57 on Apple M5 Pro (20-core GPU), MoltenVK 1.4.2, device API 1.4.357, macOS 27.3 (arm64), Homebrew Vulkan loader 1.4.363.0 and validationlayers 1.4.363.0.

  • main (37f2151): 10 of the validation tests skip with SKIP vk_sync_validation_selftest: no Vulkan device; 0.96 s total.
  • 7b1fb57: 63/63 pass, no failures, no validation errors; 36.64 s.

One note: on this driver main does not fail with VK_ERROR_INCOMPATIBLE_DRIVER (-9) as the description says. The loader returns zero physical devices and the tests skip instead. Same cause, gentler symptom.

macOS setup gotcha for anyone reproducing: Homebrew's VkLayer_khronos_validation.json ships a relative library_path (libVkLayer_khronos_validation.dylib), which the loader cannot resolve from explicit_layer.d, so the layer reports VK_ERROR_LAYER_NOT_PRESENT (-6) and vkCreateInstance fails. Rewriting it to /opt/homebrew/lib/libVkLayer_khronos_validation.dylib fixes it.

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.

5 participants