diff options
| author | Ash Hopkins <ashleighhopkins87@gmail.com> | 2026-11-22 11:25:05 +0000 |
|---|---|---|
| committer | Ash Hopkins <ashleighhopkins87@gmail.com> | 2026-11-22 12:54:04 +0000 |
| commit | 6eb5bce3920b68006e6058a48aab5938f3f59a8b (patch) | |
| tree | c819d8c6155e98c5db25569c3f899621a37353a4 /runtime/src | |
| parent | 41f448261e1de8a410b4d760e69a7e5656cef858 (diff) | |
runtime: accept a Vulkan 1.2 device with the dynamic rendering and synchronization2 extensions
The D3D12 layer and its GPU tests took only Vulkan 1.3 devices, for dynamicRendering and synchronization2.
CrossOver's MoltenVK on macOS (1.2.10, the driver its Wine uses) is Vulkan 1.2 with VK_KHR_dynamic_rendering
and VK_KHR_synchronization2, the same features under their extension names, so every Vulkan-backed test
skipped there. src/vulkan13_features.h picks the core features on 1.3 and the two extensions on 1.2, and
device_proc_or_khr falls back to the ...KHR entry points (vkCmdPipelineBarrier2KHR, vkCmdBeginRenderingKHR),
which a 1.2 device serves instead of the core names. The translated shaders are SPIR-V 1.5 validated for
Vulkan 1.2 already. On a 1.3 device the feature chain is the one it was.
Tested in a CrossOver Preview arm64 bottle (FEX) on an Apple M2 Max, cross-built with clang-cl 22.1.8 and
xwin: against main at the same commit, no test that passed fails, and d3d12_com, d3d12_multithread,
d3d12_method_variants, d3d12_uav_clear, d3d12_debug_markers, d3d12_fence_timing, d3d12_sampler2,
d3d12_typeless_rtv, d3d12_predicated_copy and depth24_convert now run and pass. Ten more now run and
fail: comparisons with Wine's host D3D12, and MoltenVK 1.2.10 limits (vk_binary_occlusion and
vk_overlapping_occlusion fail the same way natively on that driver and pass on MoltenVK 1.4.2). The
1.3 path of create_vulkan_device_standalone was not run on a 1.3 device here.
AI-assisted. No game files.
Diffstat (limited to 'runtime/src')
| -rw-r--r-- | runtime/src/vulkan13_features.h | 118 | ||||
| -rw-r--r-- | runtime/src/vulkan_backend.h | 6 |
2 files changed, 122 insertions, 2 deletions
diff --git a/runtime/src/vulkan13_features.h b/runtime/src/vulkan13_features.h new file mode 100644 index 000000000..111d81df3 --- /dev/null +++ b/runtime/src/vulkan13_features.h | |||
| @@ -0,0 +1,118 @@ | |||
| 1 | #pragma once | ||
| 2 | |||
| 3 | // dynamicRendering and synchronization2, the two Vulkan 1.3 features the D3D12 layer needs, on a Vulkan 1.3 device | ||
| 4 | // or on a Vulkan 1.2 device through VK_KHR_dynamic_rendering and VK_KHR_synchronization2. CrossOver's MoltenVK on | ||
| 5 | // macOS is such a 1.2 device (1.2.10: Vulkan 1.2 with both extensions); the extension structs, functions and | ||
| 6 | // behaviour are the core ones under another name, so the rest of the layer does not see the difference. | ||
| 7 | // | ||
| 8 | // leonida::Vulkan13Features v13; | ||
| 9 | // v13.query(physical, props.apiVersion, get_features2, enumerate_extensions); // per candidate | ||
| 10 | // if (!v13.usable()) continue; | ||
| 11 | // enable12.pNext = v13.enable(chain); // chain: what came after VkPhysicalDeviceVulkan13Features | ||
| 12 | // ... v13.next() is where later feature structs go (it used to be enable13.pNext) | ||
| 13 | // v13.add_extensions(device_extensions); | ||
| 14 | // fn = leonida::device_proc_or_khr(get_device_proc, device, "vkCmdPipelineBarrier2"); | ||
| 15 | |||
| 16 | #include <vulkan/vulkan.h> | ||
| 17 | |||
| 18 | #include <cstdint> | ||
| 19 | #include <cstring> | ||
| 20 | #include <string> | ||
| 21 | #include <vector> | ||
| 22 | |||
| 23 | namespace leonida { | ||
| 24 | |||
| 25 | class Vulkan13Features { | ||
| 26 | public: | ||
| 27 | Vulkan13Features() = default; | ||
| 28 | Vulkan13Features(const Vulkan13Features&) = delete; // enable() links pointers into this object | ||
| 29 | Vulkan13Features& operator=(const Vulkan13Features&) = delete; | ||
| 30 | |||
| 31 | bool core = false; // a Vulkan 1.3 device: the features are core | ||
| 32 | bool dynamic_rendering = false; // supported, as a core feature or through VK_KHR_dynamic_rendering | ||
| 33 | bool synchronization2 = false; // supported, as a core feature or through VK_KHR_synchronization2 | ||
| 34 | |||
| 35 | bool usable() const { return dynamic_rendering && synchronization2; } | ||
| 36 | |||
| 37 | // Fills the flags above for one physical device. A device older than 1.2 never qualifies. | ||
| 38 | void query(VkPhysicalDevice physical, std::uint32_t api_version, PFN_vkGetPhysicalDeviceFeatures2 features2, | ||
| 39 | PFN_vkEnumerateDeviceExtensionProperties enumerate_extensions) { | ||
| 40 | core = api_version >= VK_API_VERSION_1_3; | ||
| 41 | dynamic_rendering = synchronization2 = false; | ||
| 42 | if (!features2) return; | ||
| 43 | if (core) { | ||
| 44 | VkPhysicalDeviceVulkan13Features f13{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES}; | ||
| 45 | VkPhysicalDeviceFeatures2 query{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2, &f13}; | ||
| 46 | features2(physical, &query); | ||
| 47 | dynamic_rendering = f13.dynamicRendering == VK_TRUE; | ||
| 48 | synchronization2 = f13.synchronization2 == VK_TRUE; | ||
| 49 | return; | ||
| 50 | } | ||
| 51 | if (api_version < VK_API_VERSION_1_2 || !enumerate_extensions) return; | ||
| 52 | std::uint32_t count = 0; | ||
| 53 | enumerate_extensions(physical, nullptr, &count, nullptr); | ||
| 54 | std::vector<VkExtensionProperties> extensions(count); | ||
| 55 | enumerate_extensions(physical, nullptr, &count, extensions.data()); | ||
| 56 | bool has_dynamic_rendering = false, has_synchronization2 = false; | ||
| 57 | for (const auto& e : extensions) { | ||
| 58 | has_dynamic_rendering |= std::strcmp(e.extensionName, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME) == 0; | ||
| 59 | has_synchronization2 |= std::strcmp(e.extensionName, VK_KHR_SYNCHRONIZATION_2_EXTENSION_NAME) == 0; | ||
| 60 | } | ||
| 61 | if (!has_dynamic_rendering || !has_synchronization2) return; | ||
| 62 | VkPhysicalDeviceSynchronization2FeaturesKHR sync2{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SYNCHRONIZATION_2_FEATURES_KHR}; | ||
| 63 | VkPhysicalDeviceDynamicRenderingFeaturesKHR rendering{ | ||
| 64 | VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DYNAMIC_RENDERING_FEATURES_KHR, &sync2}; | ||
| 65 | VkPhysicalDeviceFeatures2 query{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2, &rendering}; | ||
| 66 | features2(physical, &query); | ||
| 67 | dynamic_rendering = rendering.dynamicRendering == VK_TRUE; | ||
| 68 | synchronization2 = sync2.synchronization2 == VK_TRUE; | ||
| 69 | } | ||
| 70 | |||
| 71 | // Copies the flags of the device query() chose (a later query() for another candidate overwrites them). | ||
| 72 | void choose(const Vulkan13Features& from) { | ||
| 73 | core = from.core; | ||
| 74 | dynamic_rendering = from.dynamic_rendering; | ||
| 75 | synchronization2 = from.synchronization2; | ||
| 76 | } | ||
| 77 | |||
| 78 | // The structs that enable both features, ahead of `chain`; returns their head for VkPhysicalDeviceVulkan12Features' | ||
| 79 | // pNext. Call once, after query() or choose(). | ||
| 80 | void* enable(void* chain) { | ||
| 81 | if (core) { | ||
| 82 | enable13_.pNext = chain; | ||
| 83 | enable13_.dynamicRendering = VK_TRUE; | ||
| 84 | enable13_.synchronization2 = VK_TRUE; | ||
| 85 | return &enable13_; | ||
| 86 | } | ||
| 87 | sync2_.pNext = chain; | ||
| 88 | sync2_.synchronization2 = VK_TRUE; | ||
| 89 | rendering_.pNext = &sync2_; | ||
| 90 | rendering_.dynamicRendering = VK_TRUE; | ||
| 91 | return &rendering_; | ||
| 92 | } | ||
| 93 | |||
| 94 | // Where a feature struct goes to follow these: insert with `s.pNext = *next(); *next() = &s;`. | ||
| 95 | void** next() { return core ? &enable13_.pNext : &sync2_.pNext; } | ||
| 96 | |||
| 97 | // The device extensions a 1.2 device needs for both features; none on 1.3. | ||
| 98 | void add_extensions(std::vector<const char*>& extensions) const { | ||
| 99 | if (core) return; | ||
| 100 | extensions.push_back(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME); | ||
| 101 | extensions.push_back(VK_KHR_SYNCHRONIZATION_2_EXTENSION_NAME); | ||
| 102 | } | ||
| 103 | |||
| 104 | private: | ||
| 105 | VkPhysicalDeviceVulkan13Features enable13_{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES}; | ||
| 106 | VkPhysicalDeviceDynamicRenderingFeaturesKHR rendering_{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DYNAMIC_RENDERING_FEATURES_KHR}; | ||
| 107 | VkPhysicalDeviceSynchronization2FeaturesKHR sync2_{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SYNCHRONIZATION_2_FEATURES_KHR}; | ||
| 108 | }; | ||
| 109 | |||
| 110 | // A device function by its core name, or by its KHR name where the core one is null: a Vulkan 1.2 device returns | ||
| 111 | // null for Vulkan 1.3 core names (vkCmdPipelineBarrier2, vkCmdBeginRendering, ...) and serves the enabled | ||
| 112 | // extension's vkCmdPipelineBarrier2KHR and the like, which have the same signatures. | ||
| 113 | inline PFN_vkVoidFunction device_proc_or_khr(PFN_vkGetDeviceProcAddr get, VkDevice device, const char* name) { | ||
| 114 | if (const PFN_vkVoidFunction function = get(device, name)) return function; | ||
| 115 | return get(device, (std::string(name) + "KHR").c_str()); | ||
| 116 | } | ||
| 117 | |||
| 118 | } // namespace leonida | ||
diff --git a/runtime/src/vulkan_backend.h b/runtime/src/vulkan_backend.h index 7006911c2..245aad6bb 100644 --- a/runtime/src/vulkan_backend.h +++ b/runtime/src/vulkan_backend.h | |||
| @@ -3,7 +3,8 @@ | |||
| 3 | // The execution side of the D3D12 layer, without COM: the per-device Vulkan context (resources, layout tracker, | 3 | // The execution side of the D3D12 layer, without COM: the per-device Vulkan context (resources, layout tracker, |
| 4 | // image views), queues that execute command lists, and timeline-semaphore fences. The COM objects in | 4 | // image views), queues that execute command lists, and timeline-semaphore fences. The COM objects in |
| 5 | // shims/d3d12_com.cpp are thin wrappers over these. Needs Vulkan 1.2 timeline semaphores; rectangle clears and | 5 | // shims/d3d12_com.cpp are thin wrappers over these. Needs Vulkan 1.2 timeline semaphores; rectangle clears and |
| 6 | // enhanced barriers need the Vulkan 1.3 functions (dynamicRendering, synchronization2) to be enabled. | 6 | // enhanced barriers need the Vulkan 1.3 functions (dynamicRendering, synchronization2) to be enabled, as core |
| 7 | // features or through their KHR extensions on a 1.2 device (vulkan13_features.h). | ||
| 7 | 8 | ||
| 8 | #ifndef VK_NO_PROTOTYPES | 9 | #ifndef VK_NO_PROTOTYPES |
| 9 | #define VK_NO_PROTOTYPES | 10 | #define VK_NO_PROTOTYPES |
| @@ -11,6 +12,7 @@ | |||
| 11 | #include "binary_occlusion_spirv.h" | 12 | #include "binary_occlusion_spirv.h" |
| 12 | #include "occlusion_sum_spirv.h" | 13 | #include "occlusion_sum_spirv.h" |
| 13 | #include "statistics_sum_spirv.h" | 14 | #include "statistics_sum_spirv.h" |
| 15 | #include "vulkan13_features.h" | ||
| 14 | #include "vulkan_depth24.h" | 16 | #include "vulkan_depth24.h" |
| 15 | #include "vulkan_scratch.h" | 17 | #include "vulkan_scratch.h" |
| 16 | #include "vulkan_replay.h" | 18 | #include "vulkan_replay.h" |
| @@ -81,7 +83,7 @@ struct VulkanDeviceFunctions { | |||
| 81 | // extension is not enabled, and the query functions are optional (a list that uses queries without them is | 83 | // extension is not enabled, and the query functions are optional (a list that uses queries without them is |
| 82 | // unsupported). The compute and descriptor functions are needed for normalized or summed occlusion results. | 84 | // unsupported). The compute and descriptor functions are needed for normalized or summed occlusion results. |
| 83 | bool load(PFN_vkGetDeviceProcAddr get, VkDevice device) { | 85 | bool load(PFN_vkGetDeviceProcAddr get, VkDevice device) { |
| 84 | #define LEONIDA_VK_LOAD(name) name = reinterpret_cast<PFN_##name>(get(device, #name)); | 86 | #define LEONIDA_VK_LOAD(name) name = reinterpret_cast<PFN_##name>(leonida::device_proc_or_khr(get, device, #name)); |
| 85 | LEONIDA_VK_DEVICE_FUNCTIONS(LEONIDA_VK_LOAD) | 87 | LEONIDA_VK_DEVICE_FUNCTIONS(LEONIDA_VK_LOAD) |
| 86 | #undef LEONIDA_VK_LOAD | 88 | #undef LEONIDA_VK_LOAD |
| 87 | return vkCreateCommandPool && vkDestroyCommandPool && vkAllocateCommandBuffers && vkResetCommandBuffer && | 89 | return vkCreateCommandPool && vkDestroyCommandPool && vkAllocateCommandBuffers && vkResetCommandBuffer && |