From becef43315cbe00db13a7c518542529dd2e77cf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20S=C3=BC=C3=9Fenbach?= Date: Thu, 26 Sep 2019 09:55:15 +0200 Subject: [PATCH] Change (most of) the samples to use the DispatchLoaderDynamic by default. (#392) --- VulkanHppGenerator.cpp | 90 ++++++++++--------- samples/01_InitInstance/CMakeLists.txt | 2 + samples/16_Vulkan_1_1/16_Vulkan_1_1.cpp | 7 ++ samples/CMakeLists.txt | 2 + .../CreateDebugUtilsMessenger/CMakeLists.txt | 2 + .../CMakeLists.txt | 2 + .../EnableValidationWithCallback.cpp | 31 +++---- .../CMakeLists.txt | 2 + .../CMakeLists.txt | 2 + .../InstanceLayerProperties/CMakeLists.txt | 2 + samples/PushDescriptors/PushDescriptors.cpp | 7 ++ samples/RayTracing/RayTracing.cpp | 38 ++++---- samples/utils/utils.cpp | 17 +++- vulkan/vulkan.hpp | 7 +- 14 files changed, 127 insertions(+), 84 deletions(-) diff --git a/VulkanHppGenerator.cpp b/VulkanHppGenerator.cpp index 025a661..6939b06 100644 --- a/VulkanHppGenerator.cpp +++ b/VulkanHppGenerator.cpp @@ -1093,6 +1093,49 @@ void VulkanHppGenerator::appendDispatchLoaderDynamic(std::string & str) } } + std::string emptyFunctions; + std::string strDeviceFunctions; + std::string strDeviceFunctionsInstance; + std::string strInstanceFunctions; + for (auto const& handle : m_handles) + { + for (auto const& command : handle.second.commands) + { + if ((command.first != "vkGetInstanceProcAddr")) + { + std::string enter, leave; + appendPlatformEnter(enter, command.second.platform); + appendPlatformLeave(leave, command.second.platform); + + if (handle.first.empty()) + { + emptyFunctions += enter; + emptyFunctions += " " + command.first + " = PFN_" + command.first + "( vkGetInstanceProcAddr( NULL, \"" + command.first + "\" ) );\n"; + emptyFunctions += leave; + } + else if (!command.second.params.empty() + && m_handles.find(command.second.params[0].type.type) != m_handles.end() + && command.second.params[0].type.type != "VkInstance" + && command.second.params[0].type.type != "VkPhysicalDevice") + { + strDeviceFunctions += enter; + strDeviceFunctions += " " + command.first + " = PFN_" + command.first + "( vkGetDeviceProcAddr( device, \"" + command.first + "\" ) );\n"; + strDeviceFunctions += leave; + + strDeviceFunctionsInstance += enter; + strDeviceFunctionsInstance += " " + command.first + " = PFN_" + command.first + "( vkGetInstanceProcAddr( instance, \"" + command.first + "\" ) );\n"; + strDeviceFunctionsInstance += leave; + } + else + { + strInstanceFunctions += enter; + strInstanceFunctions += " " + command.first + " = PFN_" + command.first + "( vkGetInstanceProcAddr( instance, \"" + command.first + "\" ) );\n"; + strInstanceFunctions += leave; + } + } + } + } + // append initialization function to fetch function pointers str += R"( public: @@ -1122,10 +1165,11 @@ void VulkanHppGenerator::appendDispatchLoaderDynamic(std::string & str) VULKAN_HPP_ASSERT(getInstanceProcAddr); vkGetInstanceProcAddr = getInstanceProcAddr; - vkEnumerateInstanceExtensionProperties = PFN_vkEnumerateInstanceExtensionProperties( vkGetInstanceProcAddr( NULL, "vkEnumerateInstanceExtensionProperties" ) ); - vkEnumerateInstanceLayerProperties = PFN_vkEnumerateInstanceLayerProperties( vkGetInstanceProcAddr( NULL, "vkEnumerateInstanceLayerProperties" ) ); - vkCreateInstance = PFN_vkCreateInstance( vkGetInstanceProcAddr( NULL, "vkCreateInstance" ) ); - } +)"; + + str += emptyFunctions; + + str += R"( } // This interface does not require a linked vulkan library. DispatchLoaderDynamic( VkInstance instance, PFN_vkGetInstanceProcAddr getInstanceProcAddr, VkDevice device = VK_NULL_HANDLE, PFN_vkGetDeviceProcAddr getDeviceProcAddr = nullptr ) @@ -1148,44 +1192,6 @@ void VulkanHppGenerator::appendDispatchLoaderDynamic(std::string & str) { )"; - std::string strDeviceFunctions; - std::string strDeviceFunctionsInstance; - std::string strInstanceFunctions; - for (auto const& handle : m_handles) - { - for (auto const& command : handle.second.commands) - { - if ((command.first != "vkGetInstanceProcAddr")) - { - std::string enter, leave; - appendPlatformEnter(enter, command.second.platform); - appendPlatformLeave(leave, command.second.platform); - - if (!command.second.params.empty() - && m_handles.find(command.second.params[0].type.type) != m_handles.end() - && command.second.params[0].type.type != "VkInstance" - && command.second.params[0].type.type != "VkPhysicalDevice") - { - strDeviceFunctions += enter; - strDeviceFunctions += " " + command.first + " = PFN_" + command.first - + "( vkGetDeviceProcAddr( device, \"" + command.first + "\" ) );\n"; - strDeviceFunctions += leave; - - strDeviceFunctionsInstance += enter; - strDeviceFunctionsInstance += " " + command.first + " = PFN_" + command.first - + "( vkGetInstanceProcAddr( instance, \"" + command.first + "\" ) );\n"; - strDeviceFunctionsInstance += leave; - } - else - { - strInstanceFunctions += enter; - strInstanceFunctions += " " + command.first + " = PFN_" + command.first + "( vkGetInstanceProcAddr( instance, \"" + command.first + "\" ) );\n"; - strInstanceFunctions += leave; - } - } - } - } - str += strInstanceFunctions; str += strDeviceFunctionsInstance; str += " }\n\n"; diff --git a/samples/01_InitInstance/CMakeLists.txt b/samples/01_InitInstance/CMakeLists.txt index d623e5c..61dd871 100644 --- a/samples/01_InitInstance/CMakeLists.txt +++ b/samples/01_InitInstance/CMakeLists.txt @@ -26,6 +26,8 @@ set(SOURCES source_group(headers FILES ${HEADERS}) source_group(sources FILES ${SOURCES}) +add_definitions(-DVULKAN_HPP_DISPATCH_LOADER_DYNAMIC=0) + add_executable(01_InitInstance ${HEADERS} ${SOURCES} diff --git a/samples/16_Vulkan_1_1/16_Vulkan_1_1.cpp b/samples/16_Vulkan_1_1/16_Vulkan_1_1.cpp index ca18d5a..56ac00e 100644 --- a/samples/16_Vulkan_1_1/16_Vulkan_1_1.cpp +++ b/samples/16_Vulkan_1_1/16_Vulkan_1_1.cpp @@ -41,6 +41,13 @@ int main(int /*argc*/, char ** /*argv*/) desiredVersionString += "."; desiredVersionString += std::to_string(desiredMinorVersion); +#if (VULKAN_HPP_DISPATCH_LOADER_DYNAMIC == 1) + // initialize the DipatchLoaderDynamic to use + static vk::DynamicLoader dl; + PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = dl.getProcAddress("vkGetInstanceProcAddr"); + VULKAN_HPP_DEFAULT_DISPATCHER.init(vkGetInstanceProcAddr); +#endif + // Determine what API version is available uint32_t apiVersion = vk::enumerateInstanceVersion(); diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt index 8b5e53f..69b4e5e 100644 --- a/samples/CMakeLists.txt +++ b/samples/CMakeLists.txt @@ -26,6 +26,8 @@ else() error("unhandled platform !") endif() +add_definitions(-DVULKAN_HPP_DISPATCH_LOADER_DYNAMIC=1) + FILE (GLOB linkunits ${CMAKE_CURRENT_SOURCE_DIR}/*) if (SAMPLES_BUILD_WITH_LOCAL_VULKAN_HPP) diff --git a/samples/CreateDebugUtilsMessenger/CMakeLists.txt b/samples/CreateDebugUtilsMessenger/CMakeLists.txt index e6a202f..8a2500a 100644 --- a/samples/CreateDebugUtilsMessenger/CMakeLists.txt +++ b/samples/CreateDebugUtilsMessenger/CMakeLists.txt @@ -26,6 +26,8 @@ set(SOURCES source_group(headers FILES ${HEADERS}) source_group(sources FILES ${SOURCES}) +add_definitions(-DVULKAN_HPP_DISPATCH_LOADER_DYNAMIC=0) + add_executable(CreateDebugUtilsMessenger ${HEADERS} ${SOURCES} diff --git a/samples/EnableValidationWithCallback/CMakeLists.txt b/samples/EnableValidationWithCallback/CMakeLists.txt index 1415ebf..1951ccd 100644 --- a/samples/EnableValidationWithCallback/CMakeLists.txt +++ b/samples/EnableValidationWithCallback/CMakeLists.txt @@ -26,6 +26,8 @@ set(SOURCES source_group(headers FILES ${HEADERS}) source_group(sources FILES ${SOURCES}) +add_definitions(-DVULKAN_HPP_DISPATCH_LOADER_DYNAMIC=0) + add_executable(EnableValidationWithCallback ${HEADERS} ${SOURCES} diff --git a/samples/EnableValidationWithCallback/EnableValidationWithCallback.cpp b/samples/EnableValidationWithCallback/EnableValidationWithCallback.cpp index f78d8e0..4440059 100644 --- a/samples/EnableValidationWithCallback/EnableValidationWithCallback.cpp +++ b/samples/EnableValidationWithCallback/EnableValidationWithCallback.cpp @@ -21,6 +21,8 @@ #include #include +using namespace std::string_literals; + static char const* AppName = "EnableValidationWithCallback"; static char const* EngineName = "Vulkan.hpp"; @@ -41,45 +43,44 @@ VKAPI_ATTR void VKAPI_CALL vkDestroyDebugUtilsMessengerEXT(VkInstance instance, VkBool32 debugMessageFunc(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, VkDebugUtilsMessageTypeFlagsEXT messageTypes, VkDebugUtilsMessengerCallbackDataEXT const * pCallbackData, void * /*pUserData*/) { - std::ostringstream message; + std::string message; - message << vk::to_string(static_cast(messageSeverity)) << ": " << vk::to_string(static_cast(messageTypes)) << ":\n"; - message << "\t" << "messageIDName = <" << pCallbackData->pMessageIdName << ">\n"; - message << "\t" << "messageIdNumber = " << pCallbackData->messageIdNumber << "\n"; - message << "\t" << "message = <" << pCallbackData->pMessage << ">\n"; + message += vk::to_string(static_cast(messageSeverity)) + ": " + vk::to_string(static_cast(messageTypes)) + ":\n"; + message += "\t"s + "messageIDName = <" + pCallbackData->pMessageIdName + ">\n"; + message += "\t"s + "messageIdNumber = " + std::to_string(pCallbackData->messageIdNumber) + "\n"; + message += "\t"s + "message = <" + pCallbackData->pMessage + ">\n"; if (0 < pCallbackData->queueLabelCount) { - message << "\t" << "Queue Labels:\n"; + message += "\t"s + "Queue Labels:\n"; for (uint8_t i = 0; i < pCallbackData->queueLabelCount; i++) { - message << "\t\t" << "lableName = <" << pCallbackData->pQueueLabels[i].pLabelName << ">\n"; + message += "\t\t"s + "lableName = <" + pCallbackData->pQueueLabels[i].pLabelName + ">\n"; } } if (0 < pCallbackData->cmdBufLabelCount) { - message << "\t" << "CommandBuffer Labels:\n"; + message += "\t"s + "CommandBuffer Labels:\n"; for (uint8_t i = 0; i < pCallbackData->cmdBufLabelCount; i++) { - message << "\t\t" << "labelName = <" << pCallbackData->pCmdBufLabels[i].pLabelName << ">\n"; + message += "\t\t"s + "labelName = <" + pCallbackData->pCmdBufLabels[i].pLabelName + ">\n"; } } if (0 < pCallbackData->objectCount) { - message << "\t" << "Objects:\n"; for (uint8_t i = 0; i < pCallbackData->objectCount; i++) { - message << "\t\t" << "Object " << i << "\n"; - message << "\t\t\t" << "objectType = " << vk::to_string(static_cast(pCallbackData->pObjects[i].objectType)) << "\n"; - message << "\t\t\t" << "objectHandle = " << pCallbackData->pObjects[i].objectHandle << "\n"; + message += "\t"s + "Object " + std::to_string(i) + "\n"; + message += "\t\t"s + "objectType = " + vk::to_string(static_cast(pCallbackData->pObjects[i].objectType)) + "\n"; + message += "\t\t"s + "objectHandle = " + std::to_string(pCallbackData->pObjects[i].objectHandle) + "\n"; if (pCallbackData->pObjects[i].pObjectName) { - message << "\t\t\t" << "objectName = <" << pCallbackData->pObjects[i].pObjectName << ">\n"; + message += "\t\t"s + "objectName = <" + pCallbackData->pObjects[i].pObjectName + ">\n"; } } } #ifdef _WIN32 - MessageBox(NULL, message.str().c_str(), "Alert", MB_OK); + MessageBox(NULL, message.c_str(), "Alert", MB_OK); #else std::cout << message.str() << std::endl; #endif diff --git a/samples/InstanceExtensionProperties/CMakeLists.txt b/samples/InstanceExtensionProperties/CMakeLists.txt index 474703f..7559c3d 100644 --- a/samples/InstanceExtensionProperties/CMakeLists.txt +++ b/samples/InstanceExtensionProperties/CMakeLists.txt @@ -26,6 +26,8 @@ set(SOURCES source_group(headers FILES ${HEADERS}) source_group(sources FILES ${SOURCES}) +add_definitions(-DVULKAN_HPP_DISPATCH_LOADER_DYNAMIC=0) + add_executable(InstanceExtensionProperties ${HEADERS} ${SOURCES} diff --git a/samples/InstanceLayerExtensionProperties/CMakeLists.txt b/samples/InstanceLayerExtensionProperties/CMakeLists.txt index 12990cf..e2ab9c2 100644 --- a/samples/InstanceLayerExtensionProperties/CMakeLists.txt +++ b/samples/InstanceLayerExtensionProperties/CMakeLists.txt @@ -26,6 +26,8 @@ set(SOURCES source_group(headers FILES ${HEADERS}) source_group(sources FILES ${SOURCES}) +add_definitions(-DVULKAN_HPP_DISPATCH_LOADER_DYNAMIC=0) + add_executable(InstanceLayerExtensionProperties ${HEADERS} ${SOURCES} diff --git a/samples/InstanceLayerProperties/CMakeLists.txt b/samples/InstanceLayerProperties/CMakeLists.txt index 6a3205f..ee605d9 100644 --- a/samples/InstanceLayerProperties/CMakeLists.txt +++ b/samples/InstanceLayerProperties/CMakeLists.txt @@ -26,6 +26,8 @@ set(SOURCES source_group(headers FILES ${HEADERS}) source_group(sources FILES ${SOURCES}) +add_definitions(-DVULKAN_HPP_DISPATCH_LOADER_DYNAMIC=0) + add_executable(InstanceLayerProperties ${HEADERS} ${SOURCES} diff --git a/samples/PushDescriptors/PushDescriptors.cpp b/samples/PushDescriptors/PushDescriptors.cpp index f7fd5af..ff092b1 100644 --- a/samples/PushDescriptors/PushDescriptors.cpp +++ b/samples/PushDescriptors/PushDescriptors.cpp @@ -30,6 +30,13 @@ int main(int /*argc*/, char ** /*argv*/) { try { +#if (VULKAN_HPP_DISPATCH_LOADER_DYNAMIC == 1) + // initialize the DipatchLoaderDynamic to use + static vk::DynamicLoader dl; + PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = dl.getProcAddress("vkGetInstanceProcAddr"); + VULKAN_HPP_DEFAULT_DISPATCHER.init(vkGetInstanceProcAddr); +#endif + /* VULKAN_KEY_START */ // To use PUSH_DESCRIPTOR, you must also specify GET_PHYSICAL_DEVICE_PROPERTIES_2 diff --git a/samples/RayTracing/RayTracing.cpp b/samples/RayTracing/RayTracing.cpp index 43e67c2..a13a6ea 100644 --- a/samples/RayTracing/RayTracing.cpp +++ b/samples/RayTracing/RayTracing.cpp @@ -62,15 +62,14 @@ static_assert(sizeof(GeometryInstanceData) == 64, "GeometryInstanceData structur struct AccelerationStructureData { - vk::UniqueHandle acclerationStructure; - std::unique_ptr scratchBufferData; - std::unique_ptr resultBufferData; - std::unique_ptr instanceBufferData; + vk::UniqueAccelerationStructureNV acclerationStructure; + std::unique_ptr scratchBufferData; + std::unique_ptr resultBufferData; + std::unique_ptr instanceBufferData; }; AccelerationStructureData createAccelerationStructureData(vk::PhysicalDevice const& physicalDevice, vk::UniqueDevice const& device, vk::UniqueCommandBuffer const& commandBuffer, - std::vector> const& instances, std::vector const& geometries, - vk::DispatchLoaderDynamic const& dispatchLoader) + std::vector> const& instances, std::vector const& geometries) { assert(instances.empty() ^ geometries.empty()); @@ -79,10 +78,10 @@ AccelerationStructureData createAccelerationStructureData(vk::PhysicalDevice con vk::AccelerationStructureTypeNV accelerationStructureType = instances.empty() ? vk::AccelerationStructureTypeNV::eBottomLevel : vk::AccelerationStructureTypeNV::eTopLevel; vk::AccelerationStructureInfoNV accelerationStructureInfo(accelerationStructureType, {}, vk::su::checked_cast(instances.size()), vk::su::checked_cast(geometries.size()), geometries.data()); - accelerationStructureData.acclerationStructure = device->createAccelerationStructureNVUnique(vk::AccelerationStructureCreateInfoNV(0, accelerationStructureInfo), nullptr, dispatchLoader); + accelerationStructureData.acclerationStructure = device->createAccelerationStructureNVUnique(vk::AccelerationStructureCreateInfoNV(0, accelerationStructureInfo)); vk::AccelerationStructureMemoryRequirementsInfoNV objectRequirements(vk::AccelerationStructureMemoryRequirementsTypeNV::eObject, *accelerationStructureData.acclerationStructure); - vk::DeviceSize resultSizeInBytes = device->getAccelerationStructureMemoryRequirementsNV(objectRequirements, dispatchLoader).memoryRequirements.size; + vk::DeviceSize resultSizeInBytes = device->getAccelerationStructureMemoryRequirementsNV(objectRequirements).memoryRequirements.size; assert(0 < resultSizeInBytes); accelerationStructureData.resultBufferData = std::make_unique(physicalDevice, device, resultSizeInBytes, vk::BufferUsageFlagBits::eRayTracingNV, vk::MemoryPropertyFlagBits::eDeviceLocal); @@ -92,8 +91,8 @@ AccelerationStructureData createAccelerationStructureData(vk::PhysicalDevice con vk::AccelerationStructureMemoryRequirementsInfoNV updateScratchRequirements(vk::AccelerationStructureMemoryRequirementsTypeNV::eUpdateScratch, *accelerationStructureData.acclerationStructure); vk::DeviceSize scratchSizeInBytes = - std::max(device->getAccelerationStructureMemoryRequirementsNV(buildScratchRequirements, dispatchLoader).memoryRequirements.size, - device->getAccelerationStructureMemoryRequirementsNV(updateScratchRequirements, dispatchLoader).memoryRequirements.size); + std::max(device->getAccelerationStructureMemoryRequirementsNV(buildScratchRequirements).memoryRequirements.size, + device->getAccelerationStructureMemoryRequirementsNV(updateScratchRequirements).memoryRequirements.size); assert(0 < scratchSizeInBytes); accelerationStructureData.scratchBufferData = std::make_unique(physicalDevice, device, scratchSizeInBytes, vk::BufferUsageFlagBits::eRayTracingNV, @@ -108,7 +107,7 @@ AccelerationStructureData createAccelerationStructureData(vk::PhysicalDevice con for(size_t i = 0; i < instances.size(); i++) { uint64_t accelerationStructureHandle = 0; - device->getAccelerationStructureHandleNV(instances[i].first, sizeof(uint64_t), &accelerationStructureHandle, dispatchLoader); + device->getAccelerationStructureHandleNV(instances[i].first, sizeof(uint64_t), &accelerationStructureHandle); // For each instance we set its instance index to its index i in the instance vector, and set // its hit group index to 2*i. The hit group index defines which entry of the shader binding @@ -122,12 +121,12 @@ AccelerationStructureData createAccelerationStructureData(vk::PhysicalDevice con } device->bindAccelerationStructureMemoryNV(vk::BindAccelerationStructureMemoryInfoNV(*accelerationStructureData.acclerationStructure, - *accelerationStructureData.resultBufferData->deviceMemory), dispatchLoader); + *accelerationStructureData.resultBufferData->deviceMemory)); commandBuffer->buildAccelerationStructureNV(vk::AccelerationStructureInfoNV(accelerationStructureType, {}, vk::su::checked_cast(instances.size()), vk::su::checked_cast(geometries.size()), geometries.data()), accelerationStructureData.instanceBufferData ? *accelerationStructureData.instanceBufferData->buffer : nullptr, 0, false, - *accelerationStructureData.acclerationStructure, nullptr, *accelerationStructureData.scratchBufferData->buffer, 0, dispatchLoader); + *accelerationStructureData.acclerationStructure, nullptr, *accelerationStructureData.scratchBufferData->buffer, 0); commandBuffer->pipelineBarrier(vk::PipelineStageFlagBits::eAccelerationStructureBuildNV, vk::PipelineStageFlagBits::eAccelerationStructureBuildNV, {}, vk::MemoryBarrier(vk::AccessFlagBits::eAccelerationStructureWriteNV | vk::AccessFlagBits::eAccelerationStructureReadNV, @@ -804,8 +803,6 @@ int main(int /*argc*/, char** /*argv*/) { vk::DescriptorType::eStorageBuffer, materialBufferData.buffer, vk::UniqueBufferView() } }, textures); // RayTracing specific stuff - // we need a dynamic DispatchLoader for the extension functions - vk::DispatchLoaderDynamic dispatchLoader(*instance, *device); // create acceleration structures: one top-level, and just one bottom-level AccelerationStructureData topLevelAS, bottomLevelAS; @@ -815,11 +812,10 @@ int main(int /*argc*/, char** /*argv*/) vk::GeometryDataNV geometryDataNV(vk::GeometryTrianglesNV(*vertexBufferData.buffer, 0, vk::su::checked_cast(vertices.size()), VertexStride, vk::Format::eR32G32B32Sfloat, *indexBufferData.buffer, 0, vk::su::checked_cast(indices.size()), vk::IndexType::eUint32), {}); - bottomLevelAS = createAccelerationStructureData(physicalDevice, device, commandBuffer, {}, {vk::GeometryNV(vk::GeometryTypeNV::eTriangles, geometryDataNV)}, - dispatchLoader); + bottomLevelAS = createAccelerationStructureData(physicalDevice, device, commandBuffer, {}, {vk::GeometryNV(vk::GeometryTypeNV::eTriangles, geometryDataNV)}); topLevelAS = createAccelerationStructureData(physicalDevice, device, commandBuffer, {std::make_pair(*bottomLevelAS.acclerationStructure, transform)}, - std::vector(), dispatchLoader); + std::vector()); }); // create raytracing descriptor set @@ -916,7 +912,7 @@ int main(int /*argc*/, char** /*argv*/) uint32_t maxRecursionDepth = 2; vk::RayTracingPipelineCreateInfoNV rayTracingPipelineCreateInfo({}, static_cast(shaderStages.size()), shaderStages.data(), static_cast(shaderGroups.size()), shaderGroups.data(), maxRecursionDepth, *rayTracingPipelineLayout); - vk::UniqueHandle rayTracingPipeline = device->createRayTracingPipelineNVUnique(nullptr, rayTracingPipelineCreateInfo, nullptr, dispatchLoader); + vk::UniquePipeline rayTracingPipeline = device->createRayTracingPipelineNVUnique(nullptr, rayTracingPipelineCreateInfo); uint32_t shaderGroupHandleSize = physicalDevice.getProperties2().get().shaderGroupHandleSize; assert(!(shaderGroupHandleSize % 16)); @@ -924,7 +920,7 @@ int main(int /*argc*/, char** /*argv*/) // with 5 shaders, we need a buffer to hold 5 shaderGroupHandles std::vector shaderHandleStorage(shaderBindingTableSize); - device->getRayTracingShaderGroupHandlesNV(*rayTracingPipeline, 0, 5, shaderHandleStorage, dispatchLoader); + device->getRayTracingShaderGroupHandlesNV(*rayTracingPipeline, 0, 5, shaderHandleStorage); vk::su::BufferData shaderBindingTableBufferData(physicalDevice, device, shaderBindingTableSize, vk::BufferUsageFlagBits::eTransferDst, vk::MemoryPropertyFlagBits::eHostVisible); shaderBindingTableBufferData.upload(device, shaderHandleStorage); @@ -1024,7 +1020,7 @@ int main(int /*argc*/, char** /*argv*/) VkDeviceSize hitGroupStride = shaderGroupHandleSize; commandBuffer->traceRaysNV(*shaderBindingTableBufferData.buffer, rayGenOffset, *shaderBindingTableBufferData.buffer, missOffset, missStride, *shaderBindingTableBufferData.buffer, - hitGroupOffset, hitGroupStride, nullptr, 0, 0, windowExtent.width, windowExtent.height, 1, dispatchLoader); + hitGroupOffset, hitGroupStride, nullptr, 0, 0, windowExtent.width, windowExtent.height, 1); } commandBuffer->endRenderPass(); diff --git a/samples/utils/utils.cpp b/samples/utils/utils.cpp index 59c0828..9ba843b 100644 --- a/samples/utils/utils.cpp +++ b/samples/utils/utils.cpp @@ -18,6 +18,9 @@ #include #include +#if (VULKAN_HPP_DISPATCH_LOADER_DYNAMIC == 1) +VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE +#elif !defined(NDEBUG) PFN_vkCreateDebugUtilsMessengerEXT pfnVkCreateDebugUtilsMessengerEXT; PFN_vkDestroyDebugUtilsMessengerEXT pfnVkDestroyDebugUtilsMessengerEXT; @@ -30,6 +33,7 @@ VKAPI_ATTR void VKAPI_CALL vkDestroyDebugUtilsMessengerEXT(VkInstance instance, { return pfnVkDestroyDebugUtilsMessengerEXT(instance, messenger, pAllocator); } +#endif namespace vk { @@ -173,6 +177,12 @@ namespace vk vk::UniqueInstance createInstance(std::string const& appName, std::string const& engineName, std::vector const& layers, std::vector const& extensions, uint32_t apiVersion) { +#if (VULKAN_HPP_DISPATCH_LOADER_DYNAMIC == 1) + static vk::DynamicLoader dl; + PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = dl.getProcAddress("vkGetInstanceProcAddr"); + VULKAN_HPP_DEFAULT_DISPATCHER.init(vkGetInstanceProcAddr); +#endif + std::vector enabledLayers; enabledLayers.reserve(layers.size()); for (auto const& layer : layers) @@ -205,7 +215,11 @@ namespace vk vk::UniqueInstance instance = vk::createInstanceUnique(vk::InstanceCreateInfo({}, &applicationInfo, checked_cast(enabledLayers.size()), enabledLayers.data(), checked_cast(enabledExtensions.size()), enabledExtensions.data())); -#if !defined(NDEBUG) +#if (VULKAN_HPP_DISPATCH_LOADER_DYNAMIC == 1) + // initialize function pointers for instance + VULKAN_HPP_DEFAULT_DISPATCHER.init(*instance); +#else +# if !defined(NDEBUG) static bool initialized = false; if (!initialized) { @@ -214,6 +228,7 @@ namespace vk assert(pfnVkCreateDebugUtilsMessengerEXT && pfnVkDestroyDebugUtilsMessengerEXT); initialized = true; } +# endif #endif return instance; diff --git a/vulkan/vulkan.hpp b/vulkan/vulkan.hpp index cea62d2..5d66ee5 100644 --- a/vulkan/vulkan.hpp +++ b/vulkan/vulkan.hpp @@ -72072,9 +72072,10 @@ namespace VULKAN_HPP_NAMESPACE VULKAN_HPP_ASSERT(getInstanceProcAddr); vkGetInstanceProcAddr = getInstanceProcAddr; + vkCreateInstance = PFN_vkCreateInstance( vkGetInstanceProcAddr( NULL, "vkCreateInstance" ) ); vkEnumerateInstanceExtensionProperties = PFN_vkEnumerateInstanceExtensionProperties( vkGetInstanceProcAddr( NULL, "vkEnumerateInstanceExtensionProperties" ) ); vkEnumerateInstanceLayerProperties = PFN_vkEnumerateInstanceLayerProperties( vkGetInstanceProcAddr( NULL, "vkEnumerateInstanceLayerProperties" ) ); - vkCreateInstance = PFN_vkCreateInstance( vkGetInstanceProcAddr( NULL, "vkCreateInstance" ) ); + vkEnumerateInstanceVersion = PFN_vkEnumerateInstanceVersion( vkGetInstanceProcAddr( NULL, "vkEnumerateInstanceVersion" ) ); } // This interface does not require a linked vulkan library. @@ -72096,10 +72097,6 @@ namespace VULKAN_HPP_NAMESPACE void init( vk::Instance instance ) { - vkCreateInstance = PFN_vkCreateInstance( vkGetInstanceProcAddr( instance, "vkCreateInstance" ) ); - vkEnumerateInstanceExtensionProperties = PFN_vkEnumerateInstanceExtensionProperties( vkGetInstanceProcAddr( instance, "vkEnumerateInstanceExtensionProperties" ) ); - vkEnumerateInstanceLayerProperties = PFN_vkEnumerateInstanceLayerProperties( vkGetInstanceProcAddr( instance, "vkEnumerateInstanceLayerProperties" ) ); - vkEnumerateInstanceVersion = PFN_vkEnumerateInstanceVersion( vkGetInstanceProcAddr( instance, "vkEnumerateInstanceVersion" ) ); #ifdef VK_USE_PLATFORM_ANDROID_KHR vkCreateAndroidSurfaceKHR = PFN_vkCreateAndroidSurfaceKHR( vkGetInstanceProcAddr( instance, "vkCreateAndroidSurfaceKHR" ) ); #endif /*VK_USE_PLATFORM_ANDROID_KHR*/