mirror of
https://github.com/KhronosGroup/Vulkan-Hpp.git
synced 2024-10-14 16:32:17 +00:00
Change (most of) the samples to use the DispatchLoaderDynamic by default. (#392)
This commit is contained in:
parent
5ceb4d2801
commit
becef43315
@ -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";
|
||||
|
@ -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}
|
||||
|
@ -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<PFN_vkGetInstanceProcAddr>("vkGetInstanceProcAddr");
|
||||
VULKAN_HPP_DEFAULT_DISPATCHER.init(vkGetInstanceProcAddr);
|
||||
#endif
|
||||
|
||||
// Determine what API version is available
|
||||
uint32_t apiVersion = vk::enumerateInstanceVersion();
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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}
|
||||
|
@ -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}
|
||||
|
@ -21,6 +21,8 @@
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
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<vk::DebugUtilsMessageSeverityFlagBitsEXT>(messageSeverity)) << ": " << vk::to_string(static_cast<vk::DebugUtilsMessageTypeFlagsEXT>(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<vk::DebugUtilsMessageSeverityFlagBitsEXT>(messageSeverity)) + ": " + vk::to_string(static_cast<vk::DebugUtilsMessageTypeFlagsEXT>(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<vk::ObjectType>(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<vk::ObjectType>(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
|
||||
|
@ -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}
|
||||
|
@ -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}
|
||||
|
@ -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}
|
||||
|
@ -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<PFN_vkGetInstanceProcAddr>("vkGetInstanceProcAddr");
|
||||
VULKAN_HPP_DEFAULT_DISPATCHER.init(vkGetInstanceProcAddr);
|
||||
#endif
|
||||
|
||||
/* VULKAN_KEY_START */
|
||||
|
||||
// To use PUSH_DESCRIPTOR, you must also specify GET_PHYSICAL_DEVICE_PROPERTIES_2
|
||||
|
@ -62,15 +62,14 @@ static_assert(sizeof(GeometryInstanceData) == 64, "GeometryInstanceData structur
|
||||
|
||||
struct AccelerationStructureData
|
||||
{
|
||||
vk::UniqueHandle<vk::AccelerationStructureNV, vk::DispatchLoaderDynamic> acclerationStructure;
|
||||
std::unique_ptr<vk::su::BufferData> scratchBufferData;
|
||||
std::unique_ptr<vk::su::BufferData> resultBufferData;
|
||||
std::unique_ptr<vk::su::BufferData> instanceBufferData;
|
||||
vk::UniqueAccelerationStructureNV acclerationStructure;
|
||||
std::unique_ptr<vk::su::BufferData> scratchBufferData;
|
||||
std::unique_ptr<vk::su::BufferData> resultBufferData;
|
||||
std::unique_ptr<vk::su::BufferData> instanceBufferData;
|
||||
};
|
||||
|
||||
AccelerationStructureData createAccelerationStructureData(vk::PhysicalDevice const& physicalDevice, vk::UniqueDevice const& device, vk::UniqueCommandBuffer const& commandBuffer,
|
||||
std::vector<std::pair<vk::AccelerationStructureNV, glm::mat4x4>> const& instances, std::vector<vk::GeometryNV> const& geometries,
|
||||
vk::DispatchLoaderDynamic const& dispatchLoader)
|
||||
std::vector<std::pair<vk::AccelerationStructureNV, glm::mat4x4>> const& instances, std::vector<vk::GeometryNV> 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<uint32_t>(instances.size()),
|
||||
vk::su::checked_cast<uint32_t>(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<vk::su::BufferData>(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<vk::su::BufferData>(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<uint32_t>(instances.size()),
|
||||
vk::su::checked_cast<uint32_t>(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<uint32_t>(vertices.size()), VertexStride,
|
||||
vk::Format::eR32G32B32Sfloat, *indexBufferData.buffer, 0,
|
||||
vk::su::checked_cast<uint32_t>(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<vk::GeometryNV>(), dispatchLoader);
|
||||
std::vector<vk::GeometryNV>());
|
||||
});
|
||||
|
||||
// create raytracing descriptor set
|
||||
@ -916,7 +912,7 @@ int main(int /*argc*/, char** /*argv*/)
|
||||
uint32_t maxRecursionDepth = 2;
|
||||
vk::RayTracingPipelineCreateInfoNV rayTracingPipelineCreateInfo({}, static_cast<uint32_t>(shaderStages.size()), shaderStages.data(), static_cast<uint32_t>(shaderGroups.size()),
|
||||
shaderGroups.data(), maxRecursionDepth, *rayTracingPipelineLayout);
|
||||
vk::UniqueHandle<vk::Pipeline, vk::DispatchLoaderDynamic> rayTracingPipeline = device->createRayTracingPipelineNVUnique(nullptr, rayTracingPipelineCreateInfo, nullptr, dispatchLoader);
|
||||
vk::UniquePipeline rayTracingPipeline = device->createRayTracingPipelineNVUnique(nullptr, rayTracingPipelineCreateInfo);
|
||||
|
||||
uint32_t shaderGroupHandleSize = physicalDevice.getProperties2<vk::PhysicalDeviceProperties2, vk::PhysicalDeviceRayTracingPropertiesNV>().get<vk::PhysicalDeviceRayTracingPropertiesNV>().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<uint8_t> shaderHandleStorage(shaderBindingTableSize);
|
||||
device->getRayTracingShaderGroupHandlesNV<uint8_t>(*rayTracingPipeline, 0, 5, shaderHandleStorage, dispatchLoader);
|
||||
device->getRayTracingShaderGroupHandlesNV<uint8_t>(*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();
|
||||
|
@ -18,6 +18,9 @@
|
||||
#include <iomanip>
|
||||
#include <numeric>
|
||||
|
||||
#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<std::string> const& layers, std::vector<std::string> const& extensions,
|
||||
uint32_t apiVersion)
|
||||
{
|
||||
#if (VULKAN_HPP_DISPATCH_LOADER_DYNAMIC == 1)
|
||||
static vk::DynamicLoader dl;
|
||||
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = dl.getProcAddress<PFN_vkGetInstanceProcAddr>("vkGetInstanceProcAddr");
|
||||
VULKAN_HPP_DEFAULT_DISPATCHER.init(vkGetInstanceProcAddr);
|
||||
#endif
|
||||
|
||||
std::vector<char const*> 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<uint32_t>(enabledLayers.size()), enabledLayers.data(),
|
||||
checked_cast<uint32_t>(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;
|
||||
|
@ -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*/
|
||||
|
Loading…
Reference in New Issue
Block a user