upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/src
diff options
context:
space:
mode:
authorAsh Hopkins <ashleighhopkins87@gmail.com>2026-11-22 14:20:33 +0000
committerAsh Hopkins <ashleighhopkins87@gmail.com>2026-11-22 14:42:14 +0000
commit3db08607276b2b7b8e7bb0a87156560ee3ac093d (patch)
tree85f254f46c96c59de856dbd5e44760e2ab4bb3e1 /runtime/src
parenteebf85b60f021ce567427ce766f4ec1c88b0f13a (diff)
runtime: graphics pipelines on a Vulkan 1.2 device through VK_EXT_extended_dynamic_state(2)
The graphics pipelines use the Vulkan 1.3 core dynamic states (primitive topology, primitive restart, vertex binding stride) and their commands (vkCmdBindVertexBuffers2, vkCmdSetPrimitiveTopology, vkCmdSetPrimitiveRestartEnable). On a Vulkan 1.2 device these come from VK_EXT_extended_dynamic_state and VK_EXT_extended_dynamic_state2, with the same values and signatures. Vulkan13Features now enables both where the device has them, and device_proc_or_khr also tries the EXT name. Without them a 1.2 device still works for compute, and graphics pipelines are refused as before. AI-assisted. No game files.
Diffstat (limited to 'runtime/src')
-rw-r--r--runtime/src/vulkan13_features.h44
1 files changed, 37 insertions, 7 deletions
diff --git a/runtime/src/vulkan13_features.h b/runtime/src/vulkan13_features.h
index 2057d953b..e86ec02a2 100644
--- a/runtime/src/vulkan13_features.h
+++ b/runtime/src/vulkan13_features.h
@@ -4,6 +4,9 @@
4// or on a Vulkan 1.2 device through VK_KHR_dynamic_rendering and VK_KHR_synchronization2. CrossOver's MoltenVK on 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 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. 6// behaviour are the core ones under another name, so the rest of the layer does not see the difference.
7// Graphics pipelines also use the 1.3 core dynamic states (primitive topology, primitive restart, vertex binding
8// stride); a 1.2 device gives them through VK_EXT_extended_dynamic_state and VK_EXT_extended_dynamic_state2, enabled
9// where the device has both (extended_dynamic_state). Without them the device still works for compute.
7// 10//
8// leonida::Vulkan13Features v13; 11// leonida::Vulkan13Features v13;
9// v13.query(physical, props.apiVersion, get_features2, enumerate_extensions); // per candidate 12// v13.query(physical, props.apiVersion, get_features2, enumerate_extensions); // per candidate
@@ -34,6 +37,7 @@ public:
34 // Optional 1.3 core features, enabled where supported; on a 1.2 device they stay off (no required subgroup size). 37 // Optional 1.3 core features, enabled where supported; on a 1.2 device they stay off (no required subgroup size).
35 bool subgroup_size_control = false; 38 bool subgroup_size_control = false;
36 bool compute_full_subgroups = false; 39 bool compute_full_subgroups = false;
40 bool extended_dynamic_state = false; // core on 1.3; on 1.2 both VK_EXT_extended_dynamic_state(2) extensions
37 41
38 bool usable() const { return dynamic_rendering && synchronization2; } 42 bool usable() const { return dynamic_rendering && synchronization2; }
39 43
@@ -42,6 +46,7 @@ public:
42 PFN_vkEnumerateDeviceExtensionProperties enumerate_extensions) { 46 PFN_vkEnumerateDeviceExtensionProperties enumerate_extensions) {
43 core = api_version >= VK_API_VERSION_1_3; 47 core = api_version >= VK_API_VERSION_1_3;
44 dynamic_rendering = synchronization2 = subgroup_size_control = compute_full_subgroups = false; 48 dynamic_rendering = synchronization2 = subgroup_size_control = compute_full_subgroups = false;
49 extended_dynamic_state = false;
45 if (!features2) return; 50 if (!features2) return;
46 if (core) { 51 if (core) {
47 VkPhysicalDeviceVulkan13Features f13{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES}; 52 VkPhysicalDeviceVulkan13Features f13{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES};
@@ -51,6 +56,7 @@ public:
51 synchronization2 = f13.synchronization2 == VK_TRUE; 56 synchronization2 = f13.synchronization2 == VK_TRUE;
52 subgroup_size_control = f13.subgroupSizeControl == VK_TRUE; 57 subgroup_size_control = f13.subgroupSizeControl == VK_TRUE;
53 compute_full_subgroups = f13.computeFullSubgroups == VK_TRUE; 58 compute_full_subgroups = f13.computeFullSubgroups == VK_TRUE;
59 extended_dynamic_state = true; // core in 1.3, no feature bit
54 return; 60 return;
55 } 61 }
56 if (api_version < VK_API_VERSION_1_2 || !enumerate_extensions) return; 62 if (api_version < VK_API_VERSION_1_2 || !enumerate_extensions) return;
@@ -58,19 +64,28 @@ public:
58 enumerate_extensions(physical, nullptr, &count, nullptr); 64 enumerate_extensions(physical, nullptr, &count, nullptr);
59 std::vector<VkExtensionProperties> extensions(count); 65 std::vector<VkExtensionProperties> extensions(count);
60 enumerate_extensions(physical, nullptr, &count, extensions.data()); 66 enumerate_extensions(physical, nullptr, &count, extensions.data());
61 bool has_dynamic_rendering = false, has_synchronization2 = false; 67 bool has_dynamic_rendering = false, has_synchronization2 = false, has_eds = false, has_eds2 = false;
62 for (const auto& e : extensions) { 68 for (const auto& e : extensions) {
63 has_dynamic_rendering |= std::strcmp(e.extensionName, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME) == 0; 69 has_dynamic_rendering |= std::strcmp(e.extensionName, VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME) == 0;
64 has_synchronization2 |= std::strcmp(e.extensionName, VK_KHR_SYNCHRONIZATION_2_EXTENSION_NAME) == 0; 70 has_synchronization2 |= std::strcmp(e.extensionName, VK_KHR_SYNCHRONIZATION_2_EXTENSION_NAME) == 0;
71 has_eds |= std::strcmp(e.extensionName, VK_EXT_EXTENDED_DYNAMIC_STATE_EXTENSION_NAME) == 0;
72 has_eds2 |= std::strcmp(e.extensionName, VK_EXT_EXTENDED_DYNAMIC_STATE_2_EXTENSION_NAME) == 0;
65 } 73 }
66 if (!has_dynamic_rendering || !has_synchronization2) return; 74 if (!has_dynamic_rendering || !has_synchronization2) return;
67 VkPhysicalDeviceSynchronization2FeaturesKHR sync2{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SYNCHRONIZATION_2_FEATURES_KHR}; 75 VkPhysicalDeviceExtendedDynamicState2FeaturesEXT eds2{
76 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTENDED_DYNAMIC_STATE_2_FEATURES_EXT};
77 VkPhysicalDeviceExtendedDynamicStateFeaturesEXT eds{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTENDED_DYNAMIC_STATE_FEATURES_EXT,
78 has_eds2 ? &eds2 : nullptr};
79 VkPhysicalDeviceSynchronization2FeaturesKHR sync2{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SYNCHRONIZATION_2_FEATURES_KHR,
80 has_eds ? &eds : nullptr};
68 VkPhysicalDeviceDynamicRenderingFeaturesKHR rendering{ 81 VkPhysicalDeviceDynamicRenderingFeaturesKHR rendering{
69 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DYNAMIC_RENDERING_FEATURES_KHR, &sync2}; 82 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DYNAMIC_RENDERING_FEATURES_KHR, &sync2};
70 VkPhysicalDeviceFeatures2 query{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2, &rendering}; 83 VkPhysicalDeviceFeatures2 query{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2, &rendering};
71 features2(physical, &query); 84 features2(physical, &query);
72 dynamic_rendering = rendering.dynamicRendering == VK_TRUE; 85 dynamic_rendering = rendering.dynamicRendering == VK_TRUE;
73 synchronization2 = sync2.synchronization2 == VK_TRUE; 86 synchronization2 = sync2.synchronization2 == VK_TRUE;
87 extended_dynamic_state = has_eds && has_eds2 && eds.extendedDynamicState == VK_TRUE &&
88 eds2.extendedDynamicState2 == VK_TRUE;
74 } 89 }
75 90
76 // Copies the flags of the device query() chose (a later query() for another candidate overwrites them). 91 // Copies the flags of the device query() chose (a later query() for another candidate overwrites them).
@@ -80,6 +95,7 @@ public:
80 synchronization2 = from.synchronization2; 95 synchronization2 = from.synchronization2;
81 subgroup_size_control = from.subgroup_size_control; 96 subgroup_size_control = from.subgroup_size_control;
82 compute_full_subgroups = from.compute_full_subgroups; 97 compute_full_subgroups = from.compute_full_subgroups;
98 extended_dynamic_state = from.extended_dynamic_state;
83 } 99 }
84 100
85 // The structs that enable both features, ahead of `chain`; returns their head for VkPhysicalDeviceVulkan12Features' 101 // The structs that enable both features, ahead of `chain`; returns their head for VkPhysicalDeviceVulkan12Features'
@@ -95,33 +111,47 @@ public:
95 } 111 }
96 sync2_.pNext = chain; 112 sync2_.pNext = chain;
97 sync2_.synchronization2 = VK_TRUE; 113 sync2_.synchronization2 = VK_TRUE;
114 if (extended_dynamic_state) {
115 eds2_.pNext = chain;
116 eds2_.extendedDynamicState2 = VK_TRUE;
117 eds_.pNext = &eds2_;
118 eds_.extendedDynamicState = VK_TRUE;
119 sync2_.pNext = &eds_;
120 }
98 rendering_.pNext = &sync2_; 121 rendering_.pNext = &sync2_;
99 rendering_.dynamicRendering = VK_TRUE; 122 rendering_.dynamicRendering = VK_TRUE;
100 return &rendering_; 123 return &rendering_;
101 } 124 }
102 125
103 // Where a feature struct goes to follow these: insert with `s.pNext = *next(); *next() = &s;`. 126 // Where a feature struct goes to follow these: insert with `s.pNext = *next(); *next() = &s;`.
104 void** next() { return core ? &enable13_.pNext : &sync2_.pNext; } 127 void** next() { return core ? &enable13_.pNext : extended_dynamic_state ? &eds2_.pNext : &sync2_.pNext; }
105 128
106 // The device extensions a 1.2 device needs for both features; none on 1.3. 129 // The device extensions a 1.2 device needs for both features; none on 1.3.
107 void add_extensions(std::vector<const char*>& extensions) const { 130 void add_extensions(std::vector<const char*>& extensions) const {
108 if (core) return; 131 if (core) return;
109 extensions.push_back(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME); 132 extensions.push_back(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
110 extensions.push_back(VK_KHR_SYNCHRONIZATION_2_EXTENSION_NAME); 133 extensions.push_back(VK_KHR_SYNCHRONIZATION_2_EXTENSION_NAME);
134 if (!extended_dynamic_state) return;
135 extensions.push_back(VK_EXT_EXTENDED_DYNAMIC_STATE_EXTENSION_NAME);
136 extensions.push_back(VK_EXT_EXTENDED_DYNAMIC_STATE_2_EXTENSION_NAME);
111 } 137 }
112 138
113private: 139private:
114 VkPhysicalDeviceVulkan13Features enable13_{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES}; 140 VkPhysicalDeviceVulkan13Features enable13_{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES};
115 VkPhysicalDeviceDynamicRenderingFeaturesKHR rendering_{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DYNAMIC_RENDERING_FEATURES_KHR}; 141 VkPhysicalDeviceDynamicRenderingFeaturesKHR rendering_{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DYNAMIC_RENDERING_FEATURES_KHR};
116 VkPhysicalDeviceSynchronization2FeaturesKHR sync2_{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SYNCHRONIZATION_2_FEATURES_KHR}; 142 VkPhysicalDeviceSynchronization2FeaturesKHR sync2_{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SYNCHRONIZATION_2_FEATURES_KHR};
143 VkPhysicalDeviceExtendedDynamicStateFeaturesEXT eds_{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTENDED_DYNAMIC_STATE_FEATURES_EXT};
144 VkPhysicalDeviceExtendedDynamicState2FeaturesEXT eds2_{
145 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTENDED_DYNAMIC_STATE_2_FEATURES_EXT};
117}; 146};
118 147
119// A device function by its core name, or by its KHR name where the core one is null: a Vulkan 1.2 device returns 148// A device function by its core name, or else by its KHR or EXT name: a Vulkan 1.2 device returns null for Vulkan
120// null for Vulkan 1.3 core names (vkCmdPipelineBarrier2, vkCmdBeginRendering, ...) and serves the enabled 149// 1.3 core names (vkCmdPipelineBarrier2, vkCmdBeginRendering, vkCmdSetPrimitiveTopology, ...) and serves the enabled
121// extension's vkCmdPipelineBarrier2KHR and the like, which have the same signatures. 150// extension's vkCmdPipelineBarrier2KHR, vkCmdSetPrimitiveTopologyEXT and the like, which have the same signatures.
122inline PFN_vkVoidFunction device_proc_or_khr(PFN_vkGetDeviceProcAddr get, VkDevice device, const char* name) { 151inline PFN_vkVoidFunction device_proc_or_khr(PFN_vkGetDeviceProcAddr get, VkDevice device, const char* name) {
123 if (const PFN_vkVoidFunction function = get(device, name)) return function; 152 if (const PFN_vkVoidFunction function = get(device, name)) return function;
124 return get(device, (std::string(name) + "KHR").c_str()); 153 if (const PFN_vkVoidFunction function = get(device, (std::string(name) + "KHR").c_str())) return function;
154 return get(device, (std::string(name) + "EXT").c_str());
125} 155}
126 156
127} // namespace leonida 157} // namespace leonida