mirror of
https://github.com/charles-lunarg/vk-bootstrap.git
synced 2024-11-22 07:24:34 +00:00
Loading looks good, but requires passing Device still;
This commit is contained in:
parent
d8c6fe42b8
commit
2445eb0b28
@ -8,38 +8,6 @@ exclusions = [
|
||||
'vkDestroyDevice'
|
||||
]
|
||||
|
||||
#formatting functions
|
||||
def format_header_top(header: str):
|
||||
header += '\n#pragma once\n\n#include <vulkan/vulkan.h>\n\n'
|
||||
header += 'namespace vkb {\n\n'
|
||||
header += 'struct DispatchTable {\n'
|
||||
header += '\tDispatchTable() = default;\n'
|
||||
header += '\tDispatchTable(VkDevice const& device, PFN_vkGetDeviceProcAddr const& procAddr) {\n'
|
||||
return header;
|
||||
|
||||
def format_header_mid(header: str):
|
||||
header += '\t}\n'
|
||||
return header;
|
||||
|
||||
def format_header_bottom(header: str):
|
||||
header += '}\n\n'
|
||||
header += '} // namespace vkb'
|
||||
return header;
|
||||
|
||||
def format_declaration(header: str, name):
|
||||
fptr_name = 'PFN_' + name
|
||||
member_name = name[2].lower() + name[3:]
|
||||
header += '\t' + fptr_name + ' ' + member_name + ' = nullptr;\n'
|
||||
if name in device_aliases:
|
||||
header = format_declaration(header, device_aliases[name])
|
||||
return header;
|
||||
|
||||
def format_load(header: str, name):
|
||||
fptr_name = 'PFN_' + name
|
||||
member_name = name[2].lower() + name[3:]
|
||||
header += '\t\t' + member_name + ' = (' + fptr_name + ')procAddr(device, "' + name + '");\n'
|
||||
return header;
|
||||
|
||||
#install xmltodict
|
||||
import sys
|
||||
import subprocess
|
||||
@ -56,34 +24,143 @@ with urllib.request.urlopen('https://raw.githubusercontent.com/KhronosGroup/Vulk
|
||||
|
||||
vk_xml = xmltodict.parse(vk_xml_raw,process_namespaces=True)
|
||||
|
||||
device_commands = []
|
||||
core_commands = {}
|
||||
extension_commands = {}
|
||||
|
||||
#Gather all device functions/aliases for filtering core/extension function fetching
|
||||
commands = vk_xml['registry']['commands']['command']
|
||||
aliases = {}
|
||||
for command in commands:
|
||||
#Not worrying about aliases as all extension functions are fetched regardless
|
||||
if 'proto' in command:
|
||||
#print(command['proto']['name'])
|
||||
name = command['proto']['name']
|
||||
if type(command['param']) is list:
|
||||
t = command['param'][0]['type']
|
||||
else:
|
||||
t = command['param']['type']
|
||||
if not name in exclusions:
|
||||
if t == 'VkDevice' or t == 'VkCommandBuffer' or t == 'VkQueue':
|
||||
device_commands += [name]
|
||||
elif '@alias' in command:
|
||||
aliases[command['@alias']] = command['@name'];
|
||||
|
||||
#Push the alias name as a device function if the alias exists in device commands
|
||||
for alias in aliases:
|
||||
if alias in device_commands:
|
||||
device_commands += [aliases[alias]]
|
||||
|
||||
#Gather all core feature levels and functions
|
||||
levels = vk_xml['registry']['feature']
|
||||
for level in levels:
|
||||
core_commands[level['@name']] = []
|
||||
for require in level['require']:
|
||||
params = require.keys()
|
||||
for param in params:
|
||||
if param == 'command':
|
||||
if type(require[param]) is list:
|
||||
for n_param in require[param]:
|
||||
if n_param['@name'] in device_commands:
|
||||
core_commands[level['@name']] += [n_param['@name']]
|
||||
else:
|
||||
if require[param]['@name'] in device_commands:
|
||||
core_commands[level['@name']] += [require[param]['@name']]
|
||||
|
||||
#Gather extension functions
|
||||
extensions = vk_xml['registry']['extensions']['extension']
|
||||
|
||||
device_commands = {};
|
||||
|
||||
extension_commands = {};
|
||||
|
||||
for extension in extensions:
|
||||
extension_name = extension['@name']
|
||||
extension_commands[(extension_name, 'VK_VERSION_1_0')] = []
|
||||
for key in extension.keys():
|
||||
if key == 'require':
|
||||
requires = [extension[key]]
|
||||
for required in requires:
|
||||
if type(required) is list:
|
||||
for nested_required in required:
|
||||
if '@feature' in nested_required and 'command' in nested_required:
|
||||
extension_commands[(extension_name, nested_required['@feature'])] = []
|
||||
commands = [nested_required['command']]
|
||||
for n_required in required:
|
||||
if '@feature' in n_required and 'command' in n_required:
|
||||
extension_commands[(extension_name, n_required['@feature'])] = []
|
||||
commands = [n_required['command']]
|
||||
for command in commands:
|
||||
if type(command) is list:
|
||||
for nested_command in command:
|
||||
extension_commands[(extension_name, nested_required['@feature'])] += [nested_command['@name']]
|
||||
else:
|
||||
extension_commands[(extension_name, nested_required['@feature'])] += [command['@name']]
|
||||
for n_command in command:
|
||||
if n_command['@name'] in device_commands:
|
||||
extension_commands[(extension_name, n_required['@feature'])] += [n_command['@name']]
|
||||
elif command['@name'] in device_commands:
|
||||
extension_commands[(extension_name, n_required['@feature'])] += [command['@name']]
|
||||
elif 'command' in n_required:
|
||||
commands = [n_required['command']]
|
||||
for command in commands:
|
||||
if type(command) is list:
|
||||
for n_command in command:
|
||||
if n_command['@name'] in device_commands:
|
||||
extension_commands[(extension_name, 'VK_VERSION_1_0')] += [n_command['@name']]
|
||||
elif command['@name'] in device_commands:
|
||||
extension_commands[(extension_name, 'VK_VERSION_1_0')] += [command['@name']]
|
||||
elif 'command' in required:
|
||||
commands = [required['command']]
|
||||
for command in commands:
|
||||
if type(command) is list:
|
||||
for n_command in command:
|
||||
if n_command['@name'] in device_commands:
|
||||
extension_commands[(extension_name, 'VK_VERSION_1_0')] += [n_command['@name']]
|
||||
elif command['@name'] in device_commands:
|
||||
extension_commands[(extension_name, 'VK_VERSION_1_0')] += [command['@name']]
|
||||
|
||||
print(extension_commands)
|
||||
header = '\n#pragma once\n\n#include <vulkan/vulkan.h>\n\n'
|
||||
header += 'namespace vkb {\n\n'
|
||||
header += 'struct DispatchTable {\n'
|
||||
header += '\tDispatchTable() = default;\n'
|
||||
header += '\tDispatchTable(VkDevice const& device, PFN_vkGetDeviceProcAddr const& procAddr) {\n'
|
||||
|
||||
declaration = ''
|
||||
loading = ''
|
||||
|
||||
for level in core_commands:
|
||||
declaration += '#ifdef ' + level + '\n';
|
||||
loading += '#ifdef ' + level + '\n';
|
||||
for command in core_commands[level]:
|
||||
fptr_name = 'PFN_' + command
|
||||
member_name = command[2].lower() + command[3:]
|
||||
declaration += '\t' + fptr_name + ' ' + member_name + ' = nullptr;\n'
|
||||
loading += '\t\t' + member_name + ' = (' + fptr_name + ')procAddr(device, "' + command + '");\n'
|
||||
declaration += '#endif\n'
|
||||
loading += '#endif\n'
|
||||
|
||||
for extension in extension_commands:
|
||||
if len(extension_commands[extension]) > 0:
|
||||
declaration += '#if defined(' + extension[0] + ') && defined(' + extension[1] + ')\n';
|
||||
loading += '#if defined(' + extension[0] + ') && defined(' + extension[1] + ')\n';
|
||||
for command in extension_commands[extension]:
|
||||
fptr_name = 'PFN_' + command
|
||||
member_name = command[2].lower() + command[3:]
|
||||
#Duplication guards
|
||||
declaration += '#ifndef ' + fptr_name + '_DECLARE\n'
|
||||
declaration += '#define ' + fptr_name + '_DECLARE\n'
|
||||
declaration += '\t' + fptr_name + ' ' + member_name + ' = nullptr;\n'
|
||||
declaration += '#endif\n'
|
||||
#Duplication guards
|
||||
loading += '#ifndef ' + fptr_name + '_LOAD\n'
|
||||
loading += '#define ' + fptr_name + '_LOAD\n'
|
||||
loading += '\t\t' + member_name + ' = (' + fptr_name + ')procAddr(device, "' + command + '");\n'
|
||||
loading += '#endif\n'
|
||||
declaration += '#endif\n'
|
||||
loading += '#endif\n'
|
||||
|
||||
header += loading
|
||||
header += '\t}\n'
|
||||
header += declaration
|
||||
header += '};\n\n'
|
||||
header += '} // namespace vkb'
|
||||
|
||||
header_file = open("../src/VkDispatchTable.h", "w")
|
||||
header_file.write(header)
|
||||
header_file.close();
|
||||
|
||||
#print(core_commands)
|
||||
#print(core_feature_levels)
|
||||
#print(extension_commands)
|
||||
#print(device_commands)
|
||||
|
||||
#header = ''
|
||||
#header = format_header_top(header)
|
||||
|
@ -1483,7 +1483,7 @@ detail::Result<Device> DeviceBuilder::build() const {
|
||||
device.surface = physical_device.surface;
|
||||
device.queue_families = physical_device.queue_families;
|
||||
device.allocation_callbacks = info.allocation_callbacks;
|
||||
device.fp_vkGetDeviceProcAddr =
|
||||
device.fp_vkGetDeviceProcAddr = detail::vulkan_functions().fp_vkGetDeviceProcAddr;
|
||||
return device;
|
||||
}
|
||||
DeviceBuilder& DeviceBuilder::custom_queue_setup(std::vector<CustomQueueDescription> queue_descriptions) {
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -187,6 +187,29 @@ TEST_CASE("Device Configuration", "[VkBootstrap.bootstrap]") {
|
||||
vkb::destroy_instance(instance_ret.value());
|
||||
}
|
||||
|
||||
TEST_CASE("Loading Dispatch Table", "[VkBootstrap.bootstrap]") {
|
||||
vkb::InstanceBuilder builder;
|
||||
|
||||
auto instance_ret =
|
||||
builder.request_validation_layers().require_api_version(1, 0).set_headless().use_default_debug_messenger().build();
|
||||
REQUIRE(instance_ret.has_value());
|
||||
{
|
||||
|
||||
vkb::PhysicalDeviceSelector selector(instance_ret.value());
|
||||
auto phys_dev_ret = selector.select_first_device_unconditionally().select();
|
||||
REQUIRE(phys_dev_ret.has_value());
|
||||
|
||||
vkb::DeviceBuilder device_builder(phys_dev_ret.value());
|
||||
auto device_ret = device_builder.build();
|
||||
REQUIRE(device_ret.has_value());
|
||||
|
||||
vkb::DispatchTable table = device_ret->get_dispatch_table();
|
||||
|
||||
vkb::destroy_device(device_ret.value());
|
||||
}
|
||||
vkb::destroy_instance(instance_ret.value());
|
||||
}
|
||||
|
||||
TEST_CASE("Swapchain", "[VkBootstrap.bootstrap]") {
|
||||
GIVEN("A working instance, window, surface, and device") {
|
||||
auto window = create_window_glfw("Swapchain");
|
||||
|
Loading…
Reference in New Issue
Block a user