mirror of
https://github.com/KhronosGroup/Vulkan-Utility-Libraries.git
synced 2025-05-15 01:08:39 +00:00
util: Fixup and add Dispatch Table header
Fixes the vk_layer_dispatch_table.h header file so that they can be used in other projects. The contents of this header and vk_dispatch_table_helper.h have been moved into a new header vul_dispatch_table.h. The structs VulDeviceDispatchTable and VulInstanceDispatchTable struct contain function pointers for the device and instance, respectively. The functions vul_init_device_dispatch_table and vul_init_instance_dispatch_table fill out the aforementioned structs, making the task of setting up the disptach table in a layer much simpler.
This commit is contained in:
parent
8ea7803544
commit
2bd0e0d438
15 changed files with 2006 additions and 212 deletions
93
scripts/generators/dispatch_table_generator.py
Normal file
93
scripts/generators/dispatch_table_generator.py
Normal file
|
@ -0,0 +1,93 @@
|
|||
#!/usr/bin/python3 -i
|
||||
#
|
||||
# Copyright 2023 The Khronos Group Inc.
|
||||
# Copyright 2023 Valve Corporation
|
||||
# Copyright 2023 LunarG, Inc.
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import os
|
||||
from generators.base_generator import BaseGenerator
|
||||
|
||||
class DispatchTableOutputGenerator(BaseGenerator):
|
||||
def __init__(self):
|
||||
BaseGenerator.__init__(self)
|
||||
|
||||
def generate(self):
|
||||
out = []
|
||||
out.append(f'''// *** THIS FILE IS GENERATED - DO NOT EDIT ***
|
||||
// See {os.path.basename(__file__)} for modifications
|
||||
// Copyright 2023 The Khronos Group Inc.
|
||||
// Copyright 2023 Valve Corporation
|
||||
// Copyright 2023 LunarG, Inc.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
\n''')
|
||||
|
||||
out.append('''
|
||||
#pragma once
|
||||
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
typedef PFN_vkVoidFunction (VKAPI_PTR *PFN_GetPhysicalDeviceProcAddr)(VkInstance instance, const char* pName);
|
||||
''')
|
||||
out.append('''
|
||||
// Instance function pointer dispatch table
|
||||
typedef struct VulInstanceDispatchTable_ {
|
||||
PFN_GetPhysicalDeviceProcAddr GetPhysicalDeviceProcAddr;
|
||||
|
||||
''')
|
||||
for command in [x for x in self.vk.commands.values() if x.instance]:
|
||||
out.extend([f'#ifdef {command.protect}\n'] if command.protect else [])
|
||||
out.append(f' PFN_{command.name} {command.name[2:]};\n')
|
||||
out.extend([f'#endif //{command.protect}\n'] if command.protect else [])
|
||||
out.append('} VulInstanceDispatchTable;\n')
|
||||
|
||||
out.append('''
|
||||
// Device function pointer dispatch table
|
||||
typedef struct VulDeviceDispatchTable_ {
|
||||
''')
|
||||
for command in [x for x in self.vk.commands.values() if x.device]:
|
||||
out.extend([f'#ifdef {command.protect}\n'] if command.protect else [])
|
||||
out.append(f' PFN_{command.name} {command.name[2:]};\n')
|
||||
out.extend([f'#endif //{command.protect}\n'] if command.protect else [])
|
||||
out.append('} VulDeviceDispatchTable;\n')
|
||||
|
||||
out.append('''
|
||||
static inline void vulInitDeviceDispatchTable(VkDevice device, VulDeviceDispatchTable *table, PFN_vkGetDeviceProcAddr gdpa) {
|
||||
memset(table, 0, sizeof(*table));
|
||||
// Device function pointers
|
||||
table->GetDeviceProcAddr = gdpa;
|
||||
''')
|
||||
|
||||
for command in [x for x in self.vk.commands.values() if x.device and x.name != 'vkGetDeviceProcAddr']:
|
||||
out.extend([f'#ifdef {command.protect}\n'] if command.protect else [])
|
||||
out.append(f' table->{command.name[2:]} = (PFN_{command.name}) gdpa(device, "{command.name}");\n')
|
||||
out.extend([f'#endif // {command.protect}\n'] if command.protect else [])
|
||||
out.append('}\n')
|
||||
|
||||
out.append('''
|
||||
static inline void vulInitInstanceDispatchTable(VkInstance instance, VulInstanceDispatchTable *table, PFN_vkGetInstanceProcAddr gipa) {
|
||||
memset(table, 0, sizeof(*table));
|
||||
// Instance function pointers
|
||||
table->GetInstanceProcAddr = gipa;
|
||||
table->GetPhysicalDeviceProcAddr = (PFN_GetPhysicalDeviceProcAddr) gipa(instance, "vk_layerGetPhysicalDeviceProcAddr");
|
||||
''')
|
||||
|
||||
for command in [x for x in self.vk.commands.values() if x.instance and x.name not in [
|
||||
'vkCreateInstance',
|
||||
'vkCreateDevice',
|
||||
'vkGetPhysicalDeviceProcAddr',
|
||||
'vkEnumerateInstanceExtensionProperties',
|
||||
'vkEnumerateInstanceLayerProperties',
|
||||
'vkEnumerateInstanceVersion',
|
||||
'vkGetInstanceProcAddr',
|
||||
]]:
|
||||
out.extend([f'#ifdef {command.protect}\n'] if command.protect else [])
|
||||
out.append(f' table->{command.name[2:]} = (PFN_{command.name}) gipa(instance, "{command.name}");\n')
|
||||
out.extend([f'#endif // {command.protect}\n'] if command.protect else [])
|
||||
out.append('}\n')
|
||||
|
||||
self.write("".join(out))
|
Loading…
Add table
Add a link
Reference in a new issue