From b963aeb94b5be5ae1c776d64089587bfc689c5c8 Mon Sep 17 00:00:00 2001 From: Cody Goodson Date: Thu, 3 Jun 2021 18:15:10 -0500 Subject: [PATCH] Added populated function to gen and exception handling to vk.xml fetch. --- script/generate_dispatch.py | 16 +++++++++++++--- src/VkDispatchTable.h | 4 ++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/script/generate_dispatch.py b/script/generate_dispatch.py index ee2493a..8008022 100644 --- a/script/generate_dispatch.py +++ b/script/generate_dispatch.py @@ -50,7 +50,7 @@ if xmltodict_missing: try: subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'xmltodict']) except subprocess.CalledProcessError as error: - print("Unable to install xmltodict due to error:"); + print("Failed to install xmltodict due to error:"); print(error); input("Press Enter to continue..."); sys.exit(); @@ -61,8 +61,14 @@ if xmltodict_missing: import urllib.request import xmltodict -with urllib.request.urlopen('https://raw.githubusercontent.com/KhronosGroup/Vulkan-Headers/master/registry/vk.xml') as response: - vk_xml_raw = response.read() +try: + response = urllib.request.urlopen('https://raw.githubusercontent.com/KhronosGroup/Vulkan-Headers/master/registry/vk.xml') +except urllib.error.URLError as error: + print("Failed to download vk.xml due to error:"); + print(error.reason) + input("Press Enter to continue..."); + sys.exit(); +vk_xml_raw = response.read() vk_xml = xmltodict.parse(vk_xml_raw,process_namespaces=True) @@ -188,6 +194,7 @@ body += 'namespace vkb {\n\n' body += 'struct DispatchTable {\n' body += '\tDispatchTable() = default;\n' body += '\tDispatchTable(VkDevice device, PFN_vkGetDeviceProcAddr procAddr) : device(device) {\n' +body += '\t\tpopulated = true;\n' proxy_section = '' fp_decl_section = '' @@ -271,7 +278,10 @@ body += pfn_load_section body += '\t}\n' body += proxy_section body += fp_decl_section +body += '\tbool is_populated() const { return populated; }\n' body += '\tVkDevice device = VK_NULL_HANDLE;\n' +body += 'private:\n' +body += '\t bool populated = false;\n' body += '};\n\n' body += '} // namespace vkb' diff --git a/src/VkDispatchTable.h b/src/VkDispatchTable.h index ae4a818..df3c04b 100644 --- a/src/VkDispatchTable.h +++ b/src/VkDispatchTable.h @@ -28,6 +28,7 @@ namespace vkb { struct DispatchTable { DispatchTable() = default; DispatchTable(VkDevice device, PFN_vkGetDeviceProcAddr procAddr) : device(device) { + populated = true; fp_vkGetDeviceQueue = (PFN_vkGetDeviceQueue)procAddr(device, "vkGetDeviceQueue"); fp_vkQueueSubmit = (PFN_vkQueueSubmit)procAddr(device, "vkQueueSubmit"); fp_vkQueueWaitIdle = (PFN_vkQueueWaitIdle)procAddr(device, "vkQueueWaitIdle"); @@ -3528,7 +3529,10 @@ struct DispatchTable { #if (defined(VK_VERSION_1_2)) || (defined(VK_KHR_buffer_device_address)) PFN_vkGetDeviceMemoryOpaqueCaptureAddressKHR fp_vkGetDeviceMemoryOpaqueCaptureAddressKHR = nullptr; #endif + bool is_populated() const { return populated; } VkDevice device = VK_NULL_HANDLE; +private: + bool populated = false; }; } // namespace vkb \ No newline at end of file