Reverted back to dispatch table creation function in device type

- Added noexcept modifier to proxys
- Change name of header to VkBoostrapDispatch.h
This commit is contained in:
Cody Goodson 2021-06-06 14:41:03 -05:00 committed by Charles Giessen
parent 2c0fe72ad9
commit 10d88ae840
5 changed files with 402 additions and 403 deletions

View File

@ -19,13 +19,13 @@
# This file is a part of VkBootstrap # This file is a part of VkBootstrap
# https://github.com/charles-lunarg/vk-bootstrap # https://github.com/charles-lunarg/vk-bootstrap
# On run, vk.xml is pulled from the master of Khronos's Vulkan-Headers repo and a VkDispatchTable type # On run, vk.xml is pulled from the master of Khronos's Vulkan-Headers repo and a VkBoostrapDispatch header
# is generated and placed in VkBoostrap's source directory # is generated and placed in VkBoostrap's source directory
# https://raw.githubusercontent.com/KhronosGroup/Vulkan-Headers/master/registry/vk.xml # https://raw.githubusercontent.com/KhronosGroup/Vulkan-Headers/master/registry/vk.xml
# This script makes use of xmltodict # This script makes use of xmltodict
# https://github.com/martinblech/xmltodict # https://github.com/martinblech/xmltodict
# The module will be auto-installed if not detected # User will be prompted to install if not detected
# Exclusions # Exclusions
exclusions = [ exclusions = [
@ -44,6 +44,7 @@ from string import Template
installed = {pkg.key for pkg in pkg_resources.working_set} installed = {pkg.key for pkg in pkg_resources.working_set}
xmltodict_missing = {'xmltodict'} - installed xmltodict_missing = {'xmltodict'} - installed
# Install xmltodict
if xmltodict_missing: if xmltodict_missing:
val = input("xmltodict is required to run this script. Would you like to install? (y/n): "); val = input("xmltodict is required to run this script. Would you like to install? (y/n): ");
if(val.lower() == "y"): if(val.lower() == "y"):
@ -199,7 +200,7 @@ proxy_section = ''
fp_decl_section = '' fp_decl_section = ''
pfn_load_section = '' pfn_load_section = ''
proxy_template = Template('\t$return_type $proxy_name($args_full) const {\n\t\t$opt_return$fp_name($args_names);\n\t}\n') proxy_template = Template('\t$return_type $proxy_name($args_full) const noexcept {\n\t\t$opt_return$fp_name($args_names);\n\t}\n')
fp_decl_template = Template('\t$pfn_name $fp_name = nullptr;\n') fp_decl_template = Template('\t$pfn_name $fp_name = nullptr;\n')
pfn_load_template = Template('\t\t$fp_name = ($pfn_name)procAddr(device, "$command_name");\n') pfn_load_template = Template('\t\t$fp_name = ($pfn_name)procAddr(device, "$command_name");\n')
@ -286,7 +287,7 @@ body += '} // namespace vkb'
header = license + info + body header = license + info + body
header_file = open("../src/VkDispatchTable.h", "w") header_file = open("../src/VkBootstrapDispatch.h", "w")
header_file.write(header) header_file.write(header)
header_file.close(); header_file.close();

View File

@ -1374,6 +1374,12 @@ detail::Result<VkQueue> Device::get_dedicated_queue(QueueType type) const {
return detail::get_queue(device, index.value()); return detail::get_queue(device, index.value());
} }
// ---- Dispatch ---- //
DispatchTable Device::make_table() const {
return {device, fp_vkGetDeviceProcAddr};
}
// ---- Device ---- // // ---- Device ---- //
CustomQueueDescription::CustomQueueDescription(uint32_t index, uint32_t count, std::vector<float> priorities) CustomQueueDescription::CustomQueueDescription(uint32_t index, uint32_t count, std::vector<float> priorities)
@ -1478,9 +1484,6 @@ detail::Result<Device> DeviceBuilder::build() const {
device.queue_families = physical_device.queue_families; device.queue_families = physical_device.queue_families;
device.allocation_callbacks = info.allocation_callbacks; device.allocation_callbacks = info.allocation_callbacks;
device.fp_vkGetDeviceProcAddr = detail::vulkan_functions().fp_vkGetDeviceProcAddr; device.fp_vkGetDeviceProcAddr = detail::vulkan_functions().fp_vkGetDeviceProcAddr;
if(info.load_dispatch) {
device.dispatch = DispatchTable(device.device, device.fp_vkGetDeviceProcAddr);
}
return device; return device;
} }
DeviceBuilder& DeviceBuilder::custom_queue_setup(std::vector<CustomQueueDescription> queue_descriptions) { DeviceBuilder& DeviceBuilder::custom_queue_setup(std::vector<CustomQueueDescription> queue_descriptions) {
@ -1491,10 +1494,6 @@ DeviceBuilder& DeviceBuilder::set_allocation_callbacks(VkAllocationCallbacks* ca
info.allocation_callbacks = callbacks; info.allocation_callbacks = callbacks;
return *this; return *this;
} }
DeviceBuilder& DeviceBuilder::populate_dispatch_table() {
info.load_dispatch = true;
return *this;
}
// ---- Swapchain ---- // // ---- Swapchain ---- //

View File

@ -23,7 +23,7 @@
#include <vulkan/vulkan.h> #include <vulkan/vulkan.h>
#include "VkDispatchTable.h" #include "VkBootstrapDispatch.h"
namespace vkb { namespace vkb {
@ -543,7 +543,6 @@ struct Device {
std::vector<VkQueueFamilyProperties> queue_families; std::vector<VkQueueFamilyProperties> queue_families;
VkAllocationCallbacks* allocation_callbacks = VK_NULL_HANDLE; VkAllocationCallbacks* allocation_callbacks = VK_NULL_HANDLE;
PFN_vkGetDeviceProcAddr fp_vkGetDeviceProcAddr = nullptr; PFN_vkGetDeviceProcAddr fp_vkGetDeviceProcAddr = nullptr;
DispatchTable dispatch;
detail::Result<uint32_t> get_queue_index(QueueType type) const; detail::Result<uint32_t> get_queue_index(QueueType type) const;
// Only a compute or transfer queue type is valid. All other queue types do not support a 'dedicated' queue index // Only a compute or transfer queue type is valid. All other queue types do not support a 'dedicated' queue index
@ -552,6 +551,9 @@ struct Device {
detail::Result<VkQueue> get_queue(QueueType type) const; detail::Result<VkQueue> get_queue(QueueType type) const;
// Only a compute or transfer queue type is valid. All other queue types do not support a 'dedicated' queue // Only a compute or transfer queue type is valid. All other queue types do not support a 'dedicated' queue
detail::Result<VkQueue> get_dedicated_queue(QueueType type) const; detail::Result<VkQueue> get_dedicated_queue(QueueType type) const;
// Return a loaded dispatch table
DispatchTable make_table() const;
}; };
// For advanced device queue setup // For advanced device queue setup
@ -585,8 +587,6 @@ class DeviceBuilder {
// Provide custom allocation callbacks. // Provide custom allocation callbacks.
DeviceBuilder& set_allocation_callbacks(VkAllocationCallbacks* callbacks); DeviceBuilder& set_allocation_callbacks(VkAllocationCallbacks* callbacks);
// Populate dispatch table for the device
DeviceBuilder& populate_dispatch_table();
private: private:
PhysicalDevice physical_device; PhysicalDevice physical_device;
struct DeviceInfo { struct DeviceInfo {
@ -594,7 +594,6 @@ class DeviceBuilder {
std::vector<VkBaseOutStructure*> pNext_chain; std::vector<VkBaseOutStructure*> pNext_chain;
std::vector<CustomQueueDescription> queue_descriptions; std::vector<CustomQueueDescription> queue_descriptions;
VkAllocationCallbacks* allocation_callbacks = VK_NULL_HANDLE; VkAllocationCallbacks* allocation_callbacks = VK_NULL_HANDLE;
bool load_dispatch = false;
} info; } info;
}; };

File diff suppressed because it is too large Load Diff

View File

@ -200,19 +200,19 @@ TEST_CASE("Loading Dispatch Table", "[VkBootstrap.bootstrap]") {
REQUIRE(phys_dev_ret.has_value()); REQUIRE(phys_dev_ret.has_value());
vkb::DeviceBuilder device_builder(phys_dev_ret.value()); vkb::DeviceBuilder device_builder(phys_dev_ret.value());
auto device_ret = device_builder.populate_dispatch_table().build(); auto device_ret = device_builder.build();
REQUIRE(device_ret.has_value()); REQUIRE(device_ret.has_value());
auto device = device_ret.value(); auto dispatch_table = device_ret.value().make_table();
// Create a basic Device specific type to test with // Create a basic Device specific type to test with
VkFenceCreateInfo info{}; VkFenceCreateInfo info{};
info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
VkFence fence = VK_NULL_HANDLE; VkFence fence = VK_NULL_HANDLE;
device.dispatch.createFence(&info, nullptr, &fence); dispatch_table.createFence(&info, nullptr, &fence);
REQUIRE(fence != VK_NULL_HANDLE); REQUIRE(fence != VK_NULL_HANDLE);
device.dispatch.destroyFence(fence, nullptr); dispatch_table.destroyFence(fence, nullptr);
vkb::destroy_device(device_ret.value()); vkb::destroy_device(device_ret.value());
} }
vkb::destroy_instance(instance_ret.value()); vkb::destroy_instance(instance_ret.value());