Add pNext as optional last argument to constructors of structs that hold a pNext.

This commit is contained in:
asuessenbach 2022-03-23 17:08:19 +01:00
parent efcb07a591
commit d90c6cbbfc
7 changed files with 3307 additions and 1744 deletions

View File

@ -65,10 +65,10 @@ struct GeometryInstanceData
} }
float transform[12]; // Transform matrix, containing only the top 3 rows float transform[12]; // Transform matrix, containing only the top 3 rows
uint32_t instanceId : 24; // Instance index uint32_t instanceId : 24; // Instance index
uint32_t mask : 8; // Visibility mask uint32_t mask : 8; // Visibility mask
uint32_t instanceOffset : 24; // Index of the hit group which will be invoked when a ray hits the instance uint32_t instanceOffset : 24; // Index of the hit group which will be invoked when a ray hits the instance
uint32_t flags : 8; // Instance flags, such as culling uint32_t flags : 8; // Instance flags, such as culling
uint64_t accelerationStructureHandle; // Opaque handle of the bottom-level acceleration structure uint64_t accelerationStructureHandle; // Opaque handle of the bottom-level acceleration structure
}; };
static_assert( sizeof( GeometryInstanceData ) == 64, "GeometryInstanceData structure compiles to incorrect size" ); static_assert( sizeof( GeometryInstanceData ) == 64, "GeometryInstanceData structure compiles to incorrect size" );
@ -174,7 +174,8 @@ struct PerFrameData
, fence( device, vk::FenceCreateInfo( vk::FenceCreateFlagBits::eSignaled ) ) , fence( device, vk::FenceCreateInfo( vk::FenceCreateFlagBits::eSignaled ) )
, presentCompleteSemaphore( device, vk::SemaphoreCreateInfo() ) , presentCompleteSemaphore( device, vk::SemaphoreCreateInfo() )
, renderCompleteSemaphore( device, vk::SemaphoreCreateInfo() ) , renderCompleteSemaphore( device, vk::SemaphoreCreateInfo() )
{} {
}
vk::raii::CommandPool commandPool; vk::raii::CommandPool commandPool;
vk::raii::CommandBuffer commandBuffer; vk::raii::CommandBuffer commandBuffer;
@ -962,8 +963,8 @@ int main( int /*argc*/, char ** /*argv*/ )
std::vector<vk::WriteDescriptorSet> accelerationDescriptionSets; std::vector<vk::WriteDescriptorSet> accelerationDescriptionSets;
for ( size_t i = 0; i < rayTracingDescriptorSets.size(); i++ ) for ( size_t i = 0; i < rayTracingDescriptorSets.size(); i++ )
{ {
accelerationDescriptionSets.emplace_back( *rayTracingDescriptorSets[i], 0, 0, 1, bindings[0].descriptorType ); accelerationDescriptionSets.emplace_back(
accelerationDescriptionSets.back().pNext = &writeDescriptorSetAcceleration; *rayTracingDescriptorSets[i], 0, 0, 1, bindings[0].descriptorType, nullptr, nullptr, nullptr, &writeDescriptorSetAcceleration );
} }
device.updateDescriptorSets( accelerationDescriptionSets, nullptr ); device.updateDescriptorSets( accelerationDescriptionSets, nullptr );
@ -1102,7 +1103,7 @@ int main( int /*argc*/, char ** /*argv*/ )
&swapChainData.swapChain, &swapChainData.swapChain,
graphicsAndPresentQueueFamilyIndex.first, graphicsAndPresentQueueFamilyIndex.first,
graphicsAndPresentQueueFamilyIndex.second ); graphicsAndPresentQueueFamilyIndex.second );
depthBufferData = vk::raii::su::DepthBufferData( physicalDevice, device, vk::su::pickDepthFormat( *physicalDevice ), windowExtent ); depthBufferData = vk::raii::su::DepthBufferData( physicalDevice, device, vk::raii::su::pickDepthFormat( physicalDevice ), windowExtent );
vk::raii::su::oneTimeSubmit( vk::raii::su::oneTimeSubmit(
commandBuffer, commandBuffer,

View File

@ -308,7 +308,8 @@ namespace vk
vk::ImageLayout::eUndefined, vk::ImageLayout::eUndefined,
vk::MemoryPropertyFlagBits::eDeviceLocal, vk::MemoryPropertyFlagBits::eDeviceLocal,
vk::ImageAspectFlagBits::eDepth ) vk::ImageAspectFlagBits::eDepth )
{} {
}
}; };
struct SurfaceData struct SurfaceData
@ -356,8 +357,8 @@ namespace vk
swapchainExtent = surfaceCapabilities.currentExtent; swapchainExtent = surfaceCapabilities.currentExtent;
} }
vk::SurfaceTransformFlagBitsKHR preTransform = ( surfaceCapabilities.supportedTransforms & vk::SurfaceTransformFlagBitsKHR::eIdentity ) vk::SurfaceTransformFlagBitsKHR preTransform = ( surfaceCapabilities.supportedTransforms & vk::SurfaceTransformFlagBitsKHR::eIdentity )
? vk::SurfaceTransformFlagBitsKHR::eIdentity ? vk::SurfaceTransformFlagBitsKHR::eIdentity
: surfaceCapabilities.currentTransform; : surfaceCapabilities.currentTransform;
vk::CompositeAlphaFlagBitsKHR compositeAlpha = vk::CompositeAlphaFlagBitsKHR compositeAlpha =
( surfaceCapabilities.supportedCompositeAlpha & vk::CompositeAlphaFlagBitsKHR::ePreMultiplied ) ? vk::CompositeAlphaFlagBitsKHR::ePreMultiplied ( surfaceCapabilities.supportedCompositeAlpha & vk::CompositeAlphaFlagBitsKHR::ePreMultiplied ) ? vk::CompositeAlphaFlagBitsKHR::ePreMultiplied
: ( surfaceCapabilities.supportedCompositeAlpha & vk::CompositeAlphaFlagBitsKHR::ePostMultiplied ) ? vk::CompositeAlphaFlagBitsKHR::ePostMultiplied : ( surfaceCapabilities.supportedCompositeAlpha & vk::CompositeAlphaFlagBitsKHR::ePostMultiplied ) ? vk::CompositeAlphaFlagBitsKHR::ePostMultiplied
@ -591,8 +592,7 @@ namespace vk
float queuePriority = 0.0f; float queuePriority = 0.0f;
vk::DeviceQueueCreateInfo deviceQueueCreateInfo( vk::DeviceQueueCreateFlags(), queueFamilyIndex, 1, &queuePriority ); vk::DeviceQueueCreateInfo deviceQueueCreateInfo( vk::DeviceQueueCreateFlags(), queueFamilyIndex, 1, &queuePriority );
vk::DeviceCreateInfo deviceCreateInfo( vk::DeviceCreateFlags(), deviceQueueCreateInfo, {}, enabledExtensions, physicalDeviceFeatures ); vk::DeviceCreateInfo deviceCreateInfo( vk::DeviceCreateFlags(), deviceQueueCreateInfo, {}, enabledExtensions, physicalDeviceFeatures, pNext );
deviceCreateInfo.pNext = pNext;
return vk::raii::Device( physicalDevice, deviceCreateInfo ); return vk::raii::Device( physicalDevice, deviceCreateInfo );
} }

View File

@ -10278,13 +10278,19 @@ std::string VulkanHppGenerator::generateStructConstructors( std::pair<std::strin
arguments += argument; arguments += argument;
} }
// gather the initializers; skip member 'pNext' and members with exactly one legal value // gather the initializers; skip members with exactly one legal value
if ( ( member.name != "pNext" ) && member.value.empty() ) if ( member.value.empty() )
{ {
initializers += ( firstArgument ? ":" : "," ) + std::string( " " ) + member.name + "( " + member.name + "_ )"; initializers += std::string( firstArgument ? ": " : ", " ) + member.name + "( " + member.name + "_ )";
firstArgument = false; firstArgument = false;
} }
} }
auto pNextIt = std::find_if( structData.second.members.begin(), structData.second.members.end(), []( MemberData const & md ) { return md.name == "pNext"; } );
if ( pNextIt != structData.second.members.end() )
{
// add pNext as a last optional argument to the constructor
arguments += std::string( listedArgument ? ", " : "" ) + pNextIt->type.compose( "VULKAN_HPP_NAMESPACE" ) + " pNext_ = nullptr";
}
std::string str = replaceWithMap( constructors, std::string str = replaceWithMap( constructors,
{ { "arguments", arguments }, { { "arguments", arguments },
@ -10323,8 +10329,13 @@ std::string VulkanHppGenerator::generateStructConstructorsEnhanced( std::pair<st
std::string templateHeader, sizeChecks; std::string templateHeader, sizeChecks;
for ( auto mit = structData.second.members.begin(); mit != structData.second.members.end(); ++mit ) for ( auto mit = structData.second.members.begin(); mit != structData.second.members.end(); ++mit )
{ {
// gather the initializers; skip member 'pNext' and constant members // gather the initializers
if ( ( mit->name != "pNext" ) && mit->value.empty() ) if ( mit->name == "pNext" ) // for pNext, we just get the initializer... the argument is added at the end
{
initializers += std::string( firstArgument ? ":" : "," ) + " pNext( pNext_ )";
firstArgument = false;
}
else if ( mit->value.empty() ) // skip constant members
{ {
auto litit = lenIts.find( mit ); auto litit = lenIts.find( mit );
if ( litit != lenIts.end() ) if ( litit != lenIts.end() )
@ -10376,6 +10387,15 @@ std::string VulkanHppGenerator::generateStructConstructorsEnhanced( std::pair<st
firstArgument = false; firstArgument = false;
} }
} }
auto pNextIt =
std::find_if( structData.second.members.begin(), structData.second.members.end(), []( MemberData const & md ) { return md.name == "pNext"; } );
if ( pNextIt != structData.second.members.end() )
{
// add pNext as a last optional argument to the constructor
arguments += std::string( listedArgument ? ", " : "" ) + pNextIt->type.compose( "VULKAN_HPP_NAMESPACE" ) + " pNext_ = nullptr";
}
static const std::string constructorTemplate = R"( static const std::string constructorTemplate = R"(
#if !defined( VULKAN_HPP_DISABLE_ENHANCED_MODE ) #if !defined( VULKAN_HPP_DISABLE_ENHANCED_MODE )
${templateHeader} ${structName}( ${arguments} ) ${templateHeader} ${structName}( ${arguments} )

View File

@ -52,7 +52,7 @@ int main( int /*argc*/, char ** /*argv*/ )
<< "subsetAllocation = " << !!groupProperties[i].subsetAllocation << "\n"; << "subsetAllocation = " << !!groupProperties[i].subsetAllocation << "\n";
std::cout << "\n"; std::cout << "\n";
if ( 1 < groupProperties[i].physicalDeviceCount ) if ( 0 < groupProperties[i].physicalDeviceCount )
{ {
vk::PhysicalDevice physicalDevice = groupProperties[i].physicalDevices[0]; vk::PhysicalDevice physicalDevice = groupProperties[i].physicalDevices[0];
@ -69,12 +69,10 @@ int main( int /*argc*/, char ** /*argv*/ )
// create a Device // create a Device
float queuePriority = 0.0f; float queuePriority = 0.0f;
vk::DeviceQueueCreateInfo deviceQueueCreateInfo( vk::DeviceQueueCreateFlags(), static_cast<uint32_t>( graphicsQueueFamilyIndex ), 1, &queuePriority ); vk::DeviceQueueCreateInfo deviceQueueCreateInfo( vk::DeviceQueueCreateFlags(), static_cast<uint32_t>( graphicsQueueFamilyIndex ), 1, &queuePriority );
vk::DeviceCreateInfo deviceCreateInfo( vk::DeviceCreateFlags(), deviceQueueCreateInfo ); vk::StructureChain<vk::DeviceCreateInfo, vk::DeviceGroupDeviceCreateInfo> deviceCreateInfoChain(
{ {}, deviceQueueCreateInfo }, { groupProperties[i].physicalDeviceCount, groupProperties[i].physicalDevices } );
vk::DeviceGroupDeviceCreateInfo deviceGroupDeviceCreateInfo( groupProperties[i].physicalDeviceCount, groupProperties[i].physicalDevices ); vk::Device device = physicalDevice.createDevice( deviceCreateInfoChain.get<vk::DeviceCreateInfo>() );
deviceCreateInfo.pNext = &deviceGroupDeviceCreateInfo;
vk::Device device = physicalDevice.createDevice( deviceCreateInfo );
// ... and destroy it again // ... and destroy it again
device.destroy(); device.destroy();

View File

@ -63,10 +63,10 @@ struct GeometryInstanceData
} }
float transform[12]; // Transform matrix, containing only the top 3 rows float transform[12]; // Transform matrix, containing only the top 3 rows
uint32_t instanceId : 24; // Instance index uint32_t instanceId : 24; // Instance index
uint32_t mask : 8; // Visibility mask uint32_t mask : 8; // Visibility mask
uint32_t instanceOffset : 24; // Index of the hit group which will be invoked when a ray hits the instance uint32_t instanceOffset : 24; // Index of the hit group which will be invoked when a ray hits the instance
uint32_t flags : 8; // Instance flags, such as culling uint32_t flags : 8; // Instance flags, such as culling
uint64_t accelerationStructureHandle; // Opaque handle of the bottom-level acceleration structure uint64_t accelerationStructureHandle; // Opaque handle of the bottom-level acceleration structure
}; };
static_assert( sizeof( GeometryInstanceData ) == 64, "GeometryInstanceData structure compiles to incorrect size" ); static_assert( sizeof( GeometryInstanceData ) == 64, "GeometryInstanceData structure compiles to incorrect size" );
@ -961,8 +961,8 @@ int main( int /*argc*/, char ** /*argv*/ )
std::vector<vk::WriteDescriptorSet> accelerationDescriptionSets; std::vector<vk::WriteDescriptorSet> accelerationDescriptionSets;
for ( size_t i = 0; i < rayTracingDescriptorSets.size(); i++ ) for ( size_t i = 0; i < rayTracingDescriptorSets.size(); i++ )
{ {
accelerationDescriptionSets.emplace_back( rayTracingDescriptorSets[i], 0, 0, 1, bindings[0].descriptorType ); accelerationDescriptionSets.emplace_back(
accelerationDescriptionSets.back().pNext = &writeDescriptorSetAcceleration; rayTracingDescriptorSets[i], 0, 0, 1, bindings[0].descriptorType, nullptr, nullptr, nullptr, &writeDescriptorSetAcceleration );
} }
device.updateDescriptorSets( accelerationDescriptionSets, nullptr ); device.updateDescriptorSets( accelerationDescriptionSets, nullptr );

View File

@ -106,8 +106,7 @@ namespace vk
float queuePriority = 0.0f; float queuePriority = 0.0f;
vk::DeviceQueueCreateInfo deviceQueueCreateInfo( {}, queueFamilyIndex, 1, &queuePriority ); vk::DeviceQueueCreateInfo deviceQueueCreateInfo( {}, queueFamilyIndex, 1, &queuePriority );
vk::DeviceCreateInfo deviceCreateInfo( {}, deviceQueueCreateInfo, {}, enabledExtensions, physicalDeviceFeatures ); vk::DeviceCreateInfo deviceCreateInfo( {}, deviceQueueCreateInfo, {}, enabledExtensions, physicalDeviceFeatures, pNext );
deviceCreateInfo.pNext = pNext;
vk::Device device = physicalDevice.createDevice( deviceCreateInfo ); vk::Device device = physicalDevice.createDevice( deviceCreateInfo );
#if ( VULKAN_HPP_DISPATCH_LOADER_DYNAMIC == 1 ) #if ( VULKAN_HPP_DISPATCH_LOADER_DYNAMIC == 1 )
@ -768,7 +767,8 @@ namespace vk
vk::ImageLayout::eUndefined, vk::ImageLayout::eUndefined,
vk::MemoryPropertyFlagBits::eDeviceLocal, vk::MemoryPropertyFlagBits::eDeviceLocal,
vk::ImageAspectFlagBits::eDepth ) vk::ImageAspectFlagBits::eDepth )
{} {
}
ImageData::ImageData( vk::PhysicalDevice const & physicalDevice, ImageData::ImageData( vk::PhysicalDevice const & physicalDevice,
vk::Device const & device, vk::Device const & device,
@ -839,8 +839,8 @@ namespace vk
swapchainExtent = surfaceCapabilities.currentExtent; swapchainExtent = surfaceCapabilities.currentExtent;
} }
vk::SurfaceTransformFlagBitsKHR preTransform = ( surfaceCapabilities.supportedTransforms & vk::SurfaceTransformFlagBitsKHR::eIdentity ) vk::SurfaceTransformFlagBitsKHR preTransform = ( surfaceCapabilities.supportedTransforms & vk::SurfaceTransformFlagBitsKHR::eIdentity )
? vk::SurfaceTransformFlagBitsKHR::eIdentity ? vk::SurfaceTransformFlagBitsKHR::eIdentity
: surfaceCapabilities.currentTransform; : surfaceCapabilities.currentTransform;
vk::CompositeAlphaFlagBitsKHR compositeAlpha = vk::CompositeAlphaFlagBitsKHR compositeAlpha =
( surfaceCapabilities.supportedCompositeAlpha & vk::CompositeAlphaFlagBitsKHR::ePreMultiplied ) ? vk::CompositeAlphaFlagBitsKHR::ePreMultiplied ( surfaceCapabilities.supportedCompositeAlpha & vk::CompositeAlphaFlagBitsKHR::ePreMultiplied ) ? vk::CompositeAlphaFlagBitsKHR::ePreMultiplied
: ( surfaceCapabilities.supportedCompositeAlpha & vk::CompositeAlphaFlagBitsKHR::ePostMultiplied ) ? vk::CompositeAlphaFlagBitsKHR::ePostMultiplied : ( surfaceCapabilities.supportedCompositeAlpha & vk::CompositeAlphaFlagBitsKHR::ePostMultiplied ) ? vk::CompositeAlphaFlagBitsKHR::ePostMultiplied
@ -887,7 +887,8 @@ namespace vk
CheckerboardImageGenerator::CheckerboardImageGenerator( std::array<uint8_t, 3> const & rgb0, std::array<uint8_t, 3> const & rgb1 ) CheckerboardImageGenerator::CheckerboardImageGenerator( std::array<uint8_t, 3> const & rgb0, std::array<uint8_t, 3> const & rgb1 )
: m_rgb0( rgb0 ), m_rgb1( rgb1 ) : m_rgb0( rgb0 ), m_rgb1( rgb1 )
{} {
}
void CheckerboardImageGenerator::operator()( void * data, vk::Extent2D & extent ) const void CheckerboardImageGenerator::operator()( void * data, vk::Extent2D & extent ) const
{ {

File diff suppressed because it is too large Load Diff