Skip to content

Commit 342da33

Browse files
Cleanup command extension checking of device functions
Remove some TODO's about needing the detailed dependency info of a command. Commands from extensions are available if any of the extensions they come from are enabled. The extensions themselves have complex requirements for enabling, but because the loader tries to do basic validation, it should only check that the primary extensions are available. This is so that the loader doesn't replicate all of the complicated dependency checking logic that already present in the Validation Layer.
1 parent c8a2c8c commit 342da33

File tree

2 files changed

+13
-28
lines changed

2 files changed

+13
-28
lines changed

loader/generated/vk_loader_extensions.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1627,7 +1627,7 @@ void init_extension_device_proc_terminator_dispatch(struct loader_device *dev) {
16271627
// ---- VK_KHR_swapchain extension commands
16281628
if (dev->driver_extensions.khr_swapchain_enabled)
16291629
dispatch->CreateSwapchainKHR = (PFN_vkCreateSwapchainKHR)gpda(dev->icd_device, "vkCreateSwapchainKHR");
1630-
if (dev->driver_extensions.khr_swapchain_enabled)
1630+
if (dev->driver_extensions.khr_swapchain_enabled || dev->driver_extensions.khr_device_group_enabled)
16311631
dispatch->GetDeviceGroupSurfacePresentModesKHR = (PFN_vkGetDeviceGroupSurfacePresentModesKHR)gpda(dev->icd_device, "vkGetDeviceGroupSurfacePresentModesKHR");
16321632

16331633
// ---- VK_KHR_display_swapchain extension commands
@@ -1660,7 +1660,7 @@ void init_extension_device_proc_terminator_dispatch(struct loader_device *dev) {
16601660
#if defined(VK_USE_PLATFORM_WIN32_KHR)
16611661

16621662
// ---- VK_EXT_full_screen_exclusive extension commands
1663-
if (dev->driver_extensions.ext_full_screen_exclusive_enabled && (dev->driver_extensions.khr_device_group_enabled || dev->driver_extensions.version_1_1_enabled))
1663+
if (dev->driver_extensions.ext_full_screen_exclusive_enabled)
16641664
dispatch->GetDeviceGroupSurfacePresentModes2EXT = (PFN_vkGetDeviceGroupSurfacePresentModes2EXT)gpda(dev->icd_device, "vkGetDeviceGroupSurfacePresentModes2EXT");
16651665
#endif // VK_USE_PLATFORM_WIN32_KHR
16661666
}
@@ -13648,7 +13648,7 @@ PFN_vkVoidFunction get_extension_device_proc_terminator(struct loader_device *de
1364813648
}
1364913649
if (!strcmp(name, "GetDeviceGroupSurfacePresentModesKHR")) {
1365013650
*found_name = true;
13651-
return dev->driver_extensions.khr_swapchain_enabled ?
13651+
return dev->driver_extensions.khr_swapchain_enabled || dev->driver_extensions.khr_device_group_enabled ?
1365213652
(PFN_vkVoidFunction)terminator_GetDeviceGroupSurfacePresentModesKHR : NULL;
1365313653
}
1365413654
// ---- VK_KHR_display_swapchain extension commands
@@ -13713,7 +13713,7 @@ PFN_vkVoidFunction get_extension_device_proc_terminator(struct loader_device *de
1371313713
// ---- VK_EXT_full_screen_exclusive extension commands
1371413714
if (!strcmp(name, "GetDeviceGroupSurfacePresentModes2EXT")) {
1371513715
*found_name = true;
13716-
return (dev->driver_extensions.ext_full_screen_exclusive_enabled && (dev->driver_extensions.khr_device_group_enabled || dev->driver_extensions.version_1_1_enabled)) ?
13716+
return dev->driver_extensions.ext_full_screen_exclusive_enabled ?
1371713717
(PFN_vkVoidFunction)terminator_GetDeviceGroupSurfacePresentModes2EXT : NULL;
1371813718
}
1371913719
#endif // VK_USE_PLATFORM_WIN32_KHR

scripts/generators/loader_extension_generator.py

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -249,16 +249,6 @@ def print_vk_layer_dispatch_table(self, out):
249249
self.OutputLayerInstanceDispatchTable(out)
250250
self.OutputLayerDeviceDispatchTable(out)
251251

252-
# Convert an XML dependency expression to a C expression, taking a callback to replace extension names
253-
# See https://registry.khronos.org/vulkan/specs/1.4/registry.html#depends-expressions
254-
@staticmethod
255-
def ConvertDependencyExpression(expr, replace_func):
256-
# '(' and ')' can pass through unchanged
257-
expr = re.sub(',', ' || ', expr)
258-
expr = re.sub(r'\+', ' && ', expr)
259-
expr = re.sub(r'\w+', lambda match: replace_func(match.group()), expr)
260-
return expr
261-
262252
def DescribeBlock(self, command, current_block, out, custom_commands_string = ' commands', indent = ' '):
263253
effective_version_name = APISpecific.getEffectiveVersionName(self.targetApiName, command.version)
264254
if command.extensions != current_block and effective_version_name != current_block:
@@ -664,14 +654,11 @@ def InitDeviceFunctionTerminatorDispatchTable(self, out):
664654
out.append(f'#if defined({command.protect})\n')
665655

666656
current_block = self.DescribeBlock(command, current_block, out)
667-
if command.name == 'vkGetDeviceGroupSurfacePresentModes2EXT': # command.extensions[0].depends in [x for x in self.vk.commands.values() if x.device]:
668-
# Hardcode the dependency expression as vulkan_object.py doesn't expose this information
669-
dep_expr = self.ConvertDependencyExpression('VK_KHR_device_group,VK_VERSION_1_1', lambda ext_name: f'dev->driver_extensions.{ext_name[3:].lower()}_enabled')
670-
out.append(f' if (dev->driver_extensions.{command.extensions[0][3:].lower()}_enabled && ({dep_expr}))\n')
671-
out.append(f' dispatch->{command.name[2:]} = (PFN_{(command.name)})gpda(dev->icd_device, "{(command.name)}");\n')
672-
else:
673-
out.append(f' if (dev->driver_extensions.{command.extensions[0][3:].lower()}_enabled)\n')
674-
out.append(f' dispatch->{command.name[2:]} = (PFN_{(command.name)})gpda(dev->icd_device, "{(command.name)}");\n')
657+
enable_extension_expressions = []
658+
for ext in command.extensions:
659+
enable_extension_expressions.append(f'dev->driver_extensions.{ext[3:].lower()}_enabled')
660+
out.append(f' if ({" || ".join(enable_extension_expressions)})\n')
661+
out.append(f' dispatch->{command.name[2:]} = (PFN_{(command.name)})gpda(dev->icd_device, "{(command.name)}");\n')
675662

676663
if command.protect is not None:
677664
out.append(f'#endif // {command.protect}\n')
@@ -1304,12 +1291,10 @@ def DeviceExtensionGetTerminator(self, out):
13041291

13051292
out.append(f' if (!strcmp(name, "{command.name[2:]}")) {{\n')
13061293
out.append(' *found_name = true;\n')
1307-
if command.name == 'vkGetDeviceGroupSurfacePresentModes2EXT': # command.extensions[0].depends in [x for x in self.vk.commands.values() if x.device]:
1308-
# Hardcode the dependency expression as vulkan_object.py doesn't expose this information
1309-
dep_expr = self.ConvertDependencyExpression('VK_KHR_device_group,VK_VERSION_1_1', lambda ext_name: f'dev->driver_extensions.{ext_name[3:].lower()}_enabled')
1310-
out.append(f' return (dev->driver_extensions.{command.extensions[0][3:].lower()}_enabled && ({dep_expr})) ?\n')
1311-
else:
1312-
out.append(f' return dev->driver_extensions.{command.extensions[0][3:].lower()}_enabled ?\n')
1294+
enable_extension_expressions = []
1295+
for ext in command.extensions:
1296+
enable_extension_expressions.append(f'dev->driver_extensions.{ext[3:].lower()}_enabled')
1297+
out.append(f' return {" || ".join(enable_extension_expressions)} ?\n')
13131298
out.append(f' (PFN_vkVoidFunction)terminator_{(command.name[2:])} : NULL;\n')
13141299
out.append(' }\n')
13151300

0 commit comments

Comments
 (0)