Merge pull request #666 from asuessenbach/ArrayProxyNoTemporaries

Introduce structure constructors using ArrayProxyNoTemporaries
This commit is contained in:
Andreas Süßenbach 2020-07-09 14:16:25 +02:00 committed by GitHub
commit 011899d101
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
57 changed files with 2229 additions and 604 deletions

View File

@ -90,6 +90,11 @@ std::string trimEnd( std::string const & input );
std::string trimStars( std::string const & input ); std::string trimStars( std::string const & input );
void warn( bool condition, int line, std::string const & message ); void warn( bool condition, int line, std::string const & message );
const std::set<std::string> ignoreLens = { "null-terminated",
R"(latexmath:[\lceil{\mathit{rasterizationSamples} \over 32}\rceil])",
"2*VK_UUID_SIZE",
"2*ename:VK_UUID_SIZE" };
const std::set<std::string> nonConstSTypeStructs = { "VkBaseInStructure", "VkBaseOutStructure" }; const std::set<std::string> nonConstSTypeStructs = { "VkBaseInStructure", "VkBaseOutStructure" };
void appendArgumentCount( std::string & str, void appendArgumentCount( std::string & str,
@ -3582,6 +3587,21 @@ std::string
: ""; : "";
} }
template <class InputIt, class UnaryPredicate>
std::vector<InputIt> findAll( InputIt first, InputIt last, UnaryPredicate p )
{
std::vector<InputIt> result;
while ( first != last )
{
if ( p( *first ) )
{
result.push_back( first );
}
++first;
}
return result;
}
void VulkanHppGenerator::appendStructConstructors( std::string & str, void VulkanHppGenerator::appendStructConstructors( std::string & str,
std::pair<std::string, StructureData> const & structData, std::pair<std::string, StructureData> const & structData,
std::string const & prefix ) const std::string const & prefix ) const
@ -3605,7 +3625,7 @@ ${prefix}}
for ( auto const & member : structData.second.members ) for ( auto const & member : structData.second.members )
{ {
// gather the arguments // gather the arguments
listedArgument = appendStructConstructorArgument( arguments, listedArgument, member ); listedArgument = appendStructConstructorArgument( arguments, listedArgument, member, true );
// gather the initializers; skip members 'pNext' and 'sType', they are directly set by initializers // gather the initializers; skip members 'pNext' and 'sType', they are directly set by initializers
if ( ( member.name != "pNext" ) && ( member.name != "sType" ) ) if ( ( member.name != "pNext" ) && ( member.name != "sType" ) )
@ -3621,16 +3641,117 @@ ${prefix}}
{ "initializers", initializers }, { "initializers", initializers },
{ "prefix", prefix }, { "prefix", prefix },
{ "structName", stripPrefix( structData.first, "Vk" ) } } ); { "structName", stripPrefix( structData.first, "Vk" ) } } );
appendStructConstructorsEnhanced( str, structData, prefix );
}
void VulkanHppGenerator::appendStructConstructorsEnhanced( std::string & str,
std::pair<std::string, StructureData> const & structData,
std::string const & prefix ) const
{
auto memberIts =
findAll( structData.second.members.begin(), structData.second.members.end(), []( MemberData const & md ) {
return !md.len.empty() && ( ignoreLens.find( md.len.front() ) == ignoreLens.end() );
} );
if ( !memberIts.empty() )
{
// maximal one member to be handled by an ArrayProxyNoTemporaries is of type void
assert( std::count_if( memberIts.begin(), memberIts.end(), []( auto it ) { return it->type.type == "void"; } ) <=
1 );
// map from len-members to all the array members using that len
std::map<std::vector<MemberData>::const_iterator, std::vector<std::vector<MemberData>::const_iterator>> lenIts;
for ( auto const & mit : memberIts )
{
std::string lenName =
( mit->len.front() == R"(latexmath:[\textrm{codeSize} \over 4])" ) ? "codeSize" : mit->len.front();
auto lenIt = std::find_if(
structData.second.members.begin(), mit, [&lenName]( MemberData const & md ) { return md.name == lenName; } );
assert( lenIt != mit );
lenIts[lenIt].push_back( mit );
}
std::string arguments, initializers;
bool listedArgument = false;
bool firstArgument = true;
bool arrayListed = false;
std::string templateHeader, sizeChecks;
for ( auto mit = structData.second.members.begin(); mit != structData.second.members.end(); ++mit )
{
// gather the initializers; skip members 'pNext' and 'sType', they are directly set by initializers
if ( ( mit->name != "pNext" ) && ( mit->name != "sType" ) )
{
auto litit = lenIts.find( mit );
if ( litit != lenIts.end() )
{
// len arguments just have an initalizer, from the ArrayProxyNoTemporaries size
assert( ( litit->second.size() == 1 ) || !litit->second.front()->optional );
initializers +=
( firstArgument ? ": " : ", " ) + mit->name + "( " + generateLenInitializer( mit, litit ) + " )";
sizeChecks += generateSizeCheck( litit->second, stripPrefix(structData.first, "Vk"), prefix );
}
else if ( std::find( memberIts.begin(), memberIts.end(), mit ) != memberIts.end() )
{
assert( beginsWith( mit->name, "p" ) );
std::string argumentName = startLowerCase( stripPrefix( mit->name, "p" ) ) + "_";
assert( endsWith( mit->type.postfix, "*" ) );
std::string argumentType = stripPostfix( mit->type.compose(), "*" );
if ( mit->type.type == "void" )
{
templateHeader = prefix + "template <typename T>\n";
size_t pos = argumentType.find( "void" );
assert( pos != std::string::npos );
argumentType.replace( pos, strlen( "void" ), "T" );
}
arguments += listedArgument ? ", " : "";
arguments += "VULKAN_HPP_NAMESPACE::ArrayProxyNoTemporaries<" + argumentType + "> const & " + argumentName;
if ( arrayListed )
{
arguments += " = {}";
}
listedArgument = true;
arrayListed = true;
initializers += ( firstArgument ? ": " : ", " ) + mit->name + "( " + argumentName + ".data() )";
}
else
{
listedArgument = appendStructConstructorArgument( arguments, listedArgument, *mit, arrayListed );
initializers += ( firstArgument ? ": " : ", " ) + mit->name + "( " + mit->name + "_ )";
}
firstArgument = false;
}
}
static const std::string constructorTemplate = R"(
#if !defined(VULKAN_HPP_DISABLE_ENHANCED_MODE)
${templateHeader}${prefix}${structName}( ${arguments} )
${prefix}${initializers}
${prefix}{${sizeChecks}}
#endif // !defined(VULKAN_HPP_DISABLE_ENHANCED_MODE)
)";
str += replaceWithMap( constructorTemplate,
{ { "arguments", arguments },
{ "initializers", initializers },
{ "prefix", prefix },
{ "sizeChecks", sizeChecks },
{ "structName", stripPrefix( structData.first, "Vk" ) },
{ "templateHeader", templateHeader } } );
}
} }
bool VulkanHppGenerator::appendStructConstructorArgument( std::string & str, bool VulkanHppGenerator::appendStructConstructorArgument( std::string & str,
bool listedArgument, bool listedArgument,
MemberData const & memberData ) const MemberData const & memberData,
bool withDefault ) const
{ {
// skip members 'pNext' and 'sType', as they are never explicitly set // skip members 'pNext' and 'sType', as they are never explicitly set
if ( ( memberData.name != "pNext" ) && ( memberData.name != "sType" ) ) if ( ( memberData.name != "pNext" ) && ( memberData.name != "sType" ) )
{ {
str += ( listedArgument ? ( "," ) : "" ); str += ( listedArgument ? ( ", " ) : "" );
if ( memberData.arraySizes.empty() ) if ( memberData.arraySizes.empty() )
{ {
str += memberData.type.compose() + " "; str += memberData.type.compose() + " ";
@ -3639,18 +3760,23 @@ bool VulkanHppGenerator::appendStructConstructorArgument( std::string & str
{ {
str += constructStandardArray( memberData.type.compose(), memberData.arraySizes ) + " const& "; str += constructStandardArray( memberData.type.compose(), memberData.arraySizes ) + " const& ";
} }
str += memberData.name + "_ = "; str += memberData.name + "_";
auto enumIt = m_enums.find( memberData.type.type ); if ( withDefault )
if ( enumIt != m_enums.end() && memberData.type.postfix.empty() )
{ {
appendEnumInitializer( str, memberData.type, memberData.arraySizes, enumIt->second.values ); str += " = ";
} auto enumIt = m_enums.find( memberData.type.type );
else if ( enumIt != m_enums.end() && memberData.type.postfix.empty() )
{ {
// all the rest can be initialized with just {} appendEnumInitializer( str, memberData.type, memberData.arraySizes, enumIt->second.values );
str += "{}"; }
else
{
// all the rest can be initialized with just {}
str += "{}";
}
} }
listedArgument = true; listedArgument = true;
} }
return listedArgument; return listedArgument;
@ -3785,10 +3911,6 @@ void VulkanHppGenerator::appendStructSetter( std::string & str
: "" }, : "" },
{ "structureName", structureName } } ); { "structureName", structureName } } );
std::set<std::string> ignoreLens = { "null-terminated",
R"(latexmath:[\lceil{\mathit{rasterizationSamples} \over 32}\rceil])",
"2*VK_UUID_SIZE",
"2*ename:VK_UUID_SIZE" };
if ( !member.len.empty() && ( ignoreLens.find( member.len[0] ) == ignoreLens.end() ) ) if ( !member.len.empty() && ( ignoreLens.find( member.len[0] ) == ignoreLens.end() ) )
{ {
assert( member.name.front() == 'p' ); assert( member.name.front() == 'p' );
@ -3878,7 +4000,8 @@ void VulkanHppGenerator::appendStructSubConstructor( std::string &
bool listedArgument = true; bool listedArgument = true;
for ( size_t i = subStruct->second.members.size(); i < structData.second.members.size(); i++ ) for ( size_t i = subStruct->second.members.size(); i < structData.second.members.size(); i++ )
{ {
listedArgument = appendStructConstructorArgument( subArguments, listedArgument, structData.second.members[i] ); listedArgument =
appendStructConstructorArgument( subArguments, listedArgument, structData.second.members[i], true );
assert( structData.second.members[i].arraySizes.empty() ); assert( structData.second.members[i].arraySizes.empty() );
subCopies += subCopies +=
@ -4647,8 +4770,8 @@ std::map<size_t, size_t> VulkanHppGenerator::determineVectorParamIndices( std::v
assert( ( std::count_if( params.begin(), params.end(), findLambda ) == 0 ) || assert( ( std::count_if( params.begin(), params.end(), findLambda ) == 0 ) ||
( findIt < it ) ); // make sure, there is no other parameter like that ( findIt < it ) ); // make sure, there is no other parameter like that
// add this parameter as a vector parameter, using the len-name parameter as the second value (or INVALID_INDEX // add this parameter as a vector parameter, using the len-name parameter as the second value (or
// if there is nothing like that) // INVALID_INDEX if there is nothing like that)
vectorParamIndices.insert( vectorParamIndices.insert(
std::make_pair( std::distance( params.begin(), it ), std::make_pair( std::distance( params.begin(), it ),
( findIt < it ) ? std::distance( params.begin(), findIt ) : INVALID_INDEX ) ); ( findIt < it ) ? std::distance( params.begin(), findIt ) : INVALID_INDEX ) );
@ -4745,6 +4868,56 @@ std::string const & VulkanHppGenerator::getVulkanLicenseHeader() const
return m_vulkanLicenseHeader; return m_vulkanLicenseHeader;
} }
std::string VulkanHppGenerator::generateLenInitializer(
std::vector<MemberData>::const_iterator mit,
std::map<std::vector<MemberData>::const_iterator,
std::vector<std::vector<MemberData>::const_iterator>>::const_iterator litit ) const
{
std::string initializer;
if ( ( 1 < litit->second.size() ) &&
( std::find_if( litit->second.begin(), litit->second.end(), []( std::vector<MemberData>::const_iterator it ) {
return !it->noAutoValidity;
} ) == litit->second.end() ) )
{
// there are multiple arrays related to this len, all marked with noautovalidity
for ( size_t i = 0; i + 1 < litit->second.size(); i++ )
{
auto arrayIt = litit->second[i];
std::string argumentName = startLowerCase( stripPrefix( arrayIt->name, "p" ) ) + "_";
initializer += "!" + argumentName + ".empty() ? " + argumentName + ".size() : ";
}
auto arrayIt = litit->second.back();
std::string argumentName = startLowerCase( stripPrefix( arrayIt->name, "p" ) ) + "_";
initializer += argumentName + ".size()";
}
else
{
auto arrayIt = litit->second.front();
assert( ( arrayIt->len.front() == litit->first->name ) ||
( ( arrayIt->len.front() == R"(latexmath:[\textrm{codeSize} \over 4])" ) &&
( litit->first->name == "codeSize" ) ) );
assert( beginsWith( arrayIt->name, "p" ) );
std::string argumentName = startLowerCase( stripPrefix( arrayIt->name, "p" ) ) + "_";
assert( mit->type.prefix.empty() && mit->type.postfix.empty() );
initializer = argumentName + ".size()";
if ( arrayIt->len.front() == R"(latexmath:[\textrm{codeSize} \over 4])" )
{
initializer += " * 4";
}
if ( arrayIt->type.type == "void" )
{
initializer += " * sizeof(T)";
}
}
if ( mit->type.type != "size_t" )
{
initializer = "static_cast<" + mit->type.type + ">( " + initializer + " )";
}
return initializer;
}
std::pair<std::string, std::string> std::pair<std::string, std::string>
VulkanHppGenerator::generateProtection( std::string const & feature, std::set<std::string> const & extensions ) const VulkanHppGenerator::generateProtection( std::string const & feature, std::set<std::string> const & extensions ) const
{ {
@ -4781,6 +4954,79 @@ std::pair<std::string, std::string> VulkanHppGenerator::generateProtection( std:
} }
} }
std::string
VulkanHppGenerator::generateSizeCheck( std::vector<std::vector<MemberData>::const_iterator> const & arrayIts,
std::string const & structName,
std::string const & prefix ) const
{
std::string sizeCheck;
if ( 1 < arrayIts.size() )
{
std::string assertionText, throwText;
if ( std::find_if( arrayIts.begin(), arrayIts.end(), []( std::vector<MemberData>::const_iterator it ) {
return !it->noAutoValidity;
} ) == arrayIts.end() )
{
// all the arrays are marked with noautovalidity -> exactly one of them has to be non-empty
std::string sum;
for ( size_t first = 0; first + 1 < arrayIts.size(); ++first )
{
sum += "!" + startLowerCase( stripPrefix( arrayIts[first]->name, "p" ) ) + "_.empty() + ";
}
sum += "!" + startLowerCase( stripPrefix( arrayIts.back()->name, "p" ) ) + "_.empty()";
assertionText += prefix + " VULKAN_HPP_ASSERT( ( " + sum + " ) == 1 );\n";
throwText += prefix + " if ( ( " + sum + " ) != 1 )\n";
throwText += prefix + " {\n";
throwText += prefix + " throw LogicError( VULKAN_HPP_NAMESPACE_STRING \"::" + structName + "::" + structName +
": ( " + sum + " ) != 1\" );\n";
throwText += prefix + " }\n";
}
else
{
// none of the arrays should be marked with noautovalidity !
assert( std::find_if( arrayIts.begin(), arrayIts.end(), []( std::vector<MemberData>::const_iterator it ) {
return it->noAutoValidity;
} ) == arrayIts.end() );
for ( size_t first = 0; first + 1 < arrayIts.size(); ++first )
{
assert( beginsWith( arrayIts[first]->name, "p" ) );
std::string firstName = startLowerCase( stripPrefix( arrayIts[first]->name, "p" ) ) + "_";
for ( auto second = first + 1; second < arrayIts.size(); ++second )
{
assert( beginsWith( arrayIts[second]->name, "p" ) );
std::string secondName = startLowerCase( stripPrefix( arrayIts[second]->name, "p" ) ) + "_";
std::string assertionCheck = firstName + ".size() == " + secondName + ".size()";
std::string throwCheck = firstName + ".size() != " + secondName + ".size()";
if ( arrayIts[first]->optional || arrayIts[second]->optional )
{
assertionCheck = "( " + assertionCheck + " )";
throwCheck = "( " + throwCheck + " )";
if ( arrayIts[second]->optional )
{
assertionCheck = secondName + ".empty() || " + assertionCheck;
throwCheck = "!" + secondName + ".empty() && " + throwCheck;
}
if ( arrayIts[first]->optional )
{
assertionCheck = firstName + ".empty() || " + assertionCheck;
throwCheck = "!" + firstName + ".empty() && " + throwCheck;
}
}
assertionText += prefix + " VULKAN_HPP_ASSERT( " + assertionCheck + " );\n";
throwText += prefix + " if ( " + throwCheck + " )\n";
throwText += prefix + " {\n";
throwText += prefix + " throw LogicError( VULKAN_HPP_NAMESPACE_STRING \"::" + structName +
"::" + structName + ": " + throwCheck + "\" );\n";
throwText += prefix + " }\n";
}
}
}
sizeCheck += "\n#ifdef VULKAN_HPP_NO_EXCEPTIONS\n" + assertionText + "#else\n" + throwText +
"#endif /*VULKAN_HPP_NO_EXCEPTIONS*/\n" + prefix;
}
return sizeCheck;
}
std::set<std::string> VulkanHppGenerator::getPlatforms( std::set<std::string> const & extensions ) const std::set<std::string> VulkanHppGenerator::getPlatforms( std::set<std::string> const & extensions ) const
{ {
std::set<std::string> platforms; std::set<std::string> platforms;
@ -6489,9 +6735,8 @@ void VulkanHppGenerator::readStructMember( tinyxml2::XMLElement const * element,
std::string const & len = memberData.len[0]; std::string const & len = memberData.len[0];
auto lenMember = auto lenMember =
std::find_if( members.begin(), members.end(), [&len]( MemberData const & md ) { return ( md.name == len ); } ); std::find_if( members.begin(), members.end(), [&len]( MemberData const & md ) { return ( md.name == len ); } );
check( ( len == "null-terminated" ) || ( len == R"(latexmath:[\textrm{codeSize} \over 4])" ) || check( ( lenMember != members.end() ) || ( ignoreLens.find( len ) != ignoreLens.end() ) ||
( len == R"(latexmath:[\lceil{\mathit{rasterizationSamples} \over 32}\rceil])" ) || ( len == R"(latexmath:[\textrm{codeSize} \over 4])" ),
( len == "2*VK_UUID_SIZE" ) || ( len == "2*ename:VK_UUID_SIZE" ) || ( lenMember != members.end() ),
line, line,
"member attribute <len> holds unknown value <" + len + ">" ); "member attribute <len> holds unknown value <" + len + ">" );
if ( lenMember != members.end() ) if ( lenMember != members.end() )
@ -6507,6 +6752,14 @@ void VulkanHppGenerator::readStructMember( tinyxml2::XMLElement const * element,
"member attribute <len> holds unknown second value <" + memberData.len[1] + ">" ); "member attribute <len> holds unknown second value <" + memberData.len[1] + ">" );
} }
} }
else if ( attribute.first == "noautovalidity" )
{
memberData.noAutoValidity = ( attribute.second == "true" );
}
else if ( attribute.first == "optional" )
{
memberData.optional = ( attribute.second == "true" );
}
else if ( attribute.first == "selection" ) else if ( attribute.first == "selection" )
{ {
check( isUnion, line, "attribute <selection> is used with a non-union structure." ); check( isUnion, line, "attribute <selection> is used with a non-union structure." );

View File

@ -194,6 +194,8 @@ private:
std::vector<std::string> arraySizes; std::vector<std::string> arraySizes;
std::string bitCount; std::string bitCount;
std::vector<std::string> len; std::vector<std::string> len;
bool noAutoValidity = false;
bool optional = false;
std::string selection; std::string selection;
std::string selector; std::string selector;
std::string values; std::string values;
@ -478,7 +480,13 @@ private:
void appendStructConstructors( std::string & str, void appendStructConstructors( std::string & str,
std::pair<std::string, StructureData> const & structData, std::pair<std::string, StructureData> const & structData,
std::string const & prefix ) const; std::string const & prefix ) const;
bool appendStructConstructorArgument( std::string & str, bool listedArgument, MemberData const & memberData ) const; void appendStructConstructorsEnhanced( std::string & str,
std::pair<std::string, StructureData> const & structData,
std::string const & prefix ) const;
bool appendStructConstructorArgument( std::string & str,
bool listedArgument,
MemberData const & memberData,
bool withDefault ) const;
std::string appendStructMembers( std::string & str, std::string appendStructMembers( std::string & str,
std::pair<std::string, StructureData> const & structData, std::pair<std::string, StructureData> const & structData,
std::string const & prefix ) const; std::string const & prefix ) const;
@ -508,15 +516,22 @@ private:
std::string determineSubStruct( std::pair<std::string, StructureData> const & structure ) const; std::string determineSubStruct( std::pair<std::string, StructureData> const & structure ) const;
size_t determineTemplateParamIndex( std::vector<ParamData> const & params, size_t determineTemplateParamIndex( std::vector<ParamData> const & params,
std::map<size_t, size_t> const & vectorParamIndices ) const; std::map<size_t, size_t> const & vectorParamIndices ) const;
std::map<size_t, size_t> determineVectorParamIndices( std::vector<ParamData> const & params ) const; std::map<size_t, size_t> determineVectorParamIndices( std::vector<ParamData> const & params ) const;
std::string generateLenInitializer(
std::vector<MemberData>::const_iterator mit,
std::map<std::vector<MemberData>::const_iterator,
std::vector<std::vector<MemberData>::const_iterator>>::const_iterator litit ) const;
std::pair<std::string, std::string> generateProtection( std::string const & feature, std::pair<std::string, std::string> generateProtection( std::string const & feature,
std::set<std::string> const & extension ) const; std::set<std::string> const & extension ) const;
std::pair<std::string, std::string> generateProtection( std::string const & type, bool isAliased ) const; std::pair<std::string, std::string> generateProtection( std::string const & type, bool isAliased ) const;
std::set<std::string> getPlatforms( std::set<std::string> const & extensions ) const; std::string generateSizeCheck( std::vector<std::vector<MemberData>::const_iterator> const & arrayIts,
bool holdsSType( std::string const & type ) const; std::string const & structName,
bool isParam( std::string const & name, std::vector<ParamData> const & params ) const; std::string const & prefix ) const;
bool isParamIndirect( std::string const & name, std::vector<ParamData> const & params ) const; std::set<std::string> getPlatforms( std::set<std::string> const & extensions ) const;
bool isTwoStepAlgorithm( std::vector<ParamData> const & params ) const; bool holdsSType( std::string const & type ) const;
bool isParam( std::string const & name, std::vector<ParamData> const & params ) const;
bool isParamIndirect( std::string const & name, std::vector<ParamData> const & params ) const;
bool isTwoStepAlgorithm( std::vector<ParamData> const & params ) const;
void readBaseType( tinyxml2::XMLElement const * element, std::map<std::string, std::string> const & attributes ); void readBaseType( tinyxml2::XMLElement const * element, std::map<std::string, std::string> const & attributes );
void readBitmask( tinyxml2::XMLElement const * element, std::map<std::string, std::string> const & attributes ); void readBitmask( tinyxml2::XMLElement const * element, std::map<std::string, std::string> const & attributes );
void readBitmaskAlias( tinyxml2::XMLElement const * element, std::map<std::string, std::string> const & attributes ); void readBitmaskAlias( tinyxml2::XMLElement const * element, std::map<std::string, std::string> const & attributes );

View File

@ -45,6 +45,11 @@ int main( int /*argc*/, char ** /*argv*/ )
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( std::exception & err )
{
std::cout << "std::exception: " << err.what() << std::endl;
exit( -1 );
}
catch ( ... ) catch ( ... )
{ {
std::cout << "unknown error\n"; std::cout << "unknown error\n";

View File

@ -47,6 +47,11 @@ int main( int /*argc*/, char ** /*argv*/ )
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( std::exception & err )
{
std::cout << "std::exception: " << err.what() << std::endl;
exit( -1 );
}
catch ( ... ) catch ( ... )
{ {
std::cout << "unknown error\n"; std::cout << "unknown error\n";

View File

@ -53,7 +53,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::DeviceQueueCreateInfo deviceQueueCreateInfo( vk::DeviceQueueCreateInfo deviceQueueCreateInfo(
vk::DeviceQueueCreateFlags(), static_cast<uint32_t>( graphicsQueueFamilyIndex ), 1, &queuePriority ); vk::DeviceQueueCreateFlags(), static_cast<uint32_t>( graphicsQueueFamilyIndex ), 1, &queuePriority );
vk::UniqueDevice device = vk::UniqueDevice device =
physicalDevice.createDeviceUnique( vk::DeviceCreateInfo( vk::DeviceCreateFlags(), 1, &deviceQueueCreateInfo ) ); physicalDevice.createDeviceUnique( vk::DeviceCreateInfo( vk::DeviceCreateFlags(), deviceQueueCreateInfo ) );
// Note: No need to explicitly destroy the device, as the corresponding destroy function is // Note: No need to explicitly destroy the device, as the corresponding destroy function is
// called by the destructor of the UniqueDevice on leaving this scope. // called by the destructor of the UniqueDevice on leaving this scope.
@ -65,6 +65,11 @@ int main( int /*argc*/, char ** /*argv*/ )
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( std::exception & err )
{
std::cout << "std::exception: " << err.what() << std::endl;
exit( -1 );
}
catch ( ... ) catch ( ... )
{ {
std::cout << "unknown error\n"; std::cout << "unknown error\n";

View File

@ -61,6 +61,11 @@ int main( int /*argc*/, char ** /*argv*/ )
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( std::exception & err )
{
std::cout << "std::exception: " << err.what() << std::endl;
exit( -1 );
}
catch ( ... ) catch ( ... )
{ {
std::cout << "unknown error\n"; std::cout << "unknown error\n";

View File

@ -142,8 +142,7 @@ int main( int /*argc*/, char ** /*argv*/ )
1, 1,
vk::ImageUsageFlagBits::eColorAttachment, vk::ImageUsageFlagBits::eColorAttachment,
vk::SharingMode::eExclusive, vk::SharingMode::eExclusive,
0, {},
nullptr,
preTransform, preTransform,
compositeAlpha, compositeAlpha,
swapchainPresentMode, swapchainPresentMode,
@ -188,9 +187,9 @@ int main( int /*argc*/, char ** /*argv*/ )
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( std::runtime_error & err ) catch ( std::exception & err )
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::exception: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( ... ) catch ( ... )

View File

@ -108,9 +108,9 @@ int main( int /*argc*/, char ** /*argv*/ )
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( std::runtime_error & err ) catch ( std::exception & err )
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::exception: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( ... ) catch ( ... )

View File

@ -94,9 +94,9 @@ int main( int /*argc*/, char ** /*argv*/ )
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( std::runtime_error & err ) catch ( std::exception & err )
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::exception: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( ... ) catch ( ... )

View File

@ -43,11 +43,11 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::DescriptorSetLayoutBinding descriptorSetLayoutBinding( vk::DescriptorSetLayoutBinding descriptorSetLayoutBinding(
0, vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex ); 0, vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex );
vk::UniqueDescriptorSetLayout descriptorSetLayout = device->createDescriptorSetLayoutUnique( vk::UniqueDescriptorSetLayout descriptorSetLayout = device->createDescriptorSetLayoutUnique(
vk::DescriptorSetLayoutCreateInfo( vk::DescriptorSetLayoutCreateFlags(), 1, &descriptorSetLayoutBinding ) ); vk::DescriptorSetLayoutCreateInfo( vk::DescriptorSetLayoutCreateFlags(), descriptorSetLayoutBinding ) );
// create a PipelineLayout using that DescriptorSetLayout // create a PipelineLayout using that DescriptorSetLayout
vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique( vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique(
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), 1, &descriptorSetLayout.get() ) ); vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), *descriptorSetLayout ) );
// Note: No need to explicitly destroy the layouts, as the corresponding destroy function is // Note: No need to explicitly destroy the layouts, as the corresponding destroy function is
// called by the destructor of the UniqueDescriptorSetLayout or UniquePipelineLayout, respectively, on leaving this // called by the destructor of the UniqueDescriptorSetLayout or UniquePipelineLayout, respectively, on leaving this
@ -60,9 +60,9 @@ int main( int /*argc*/, char ** /*argv*/ )
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( std::runtime_error & err ) catch ( std::exception & err )
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::exception: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( ... ) catch ( ... )

View File

@ -56,17 +56,16 @@ int main( int /*argc*/, char ** /*argv*/ )
// create a descriptor pool // create a descriptor pool
vk::DescriptorPoolSize poolSize( vk::DescriptorType::eUniformBuffer, 1 ); vk::DescriptorPoolSize poolSize( vk::DescriptorType::eUniformBuffer, 1 );
vk::UniqueDescriptorPool descriptorPool = device->createDescriptorPoolUnique( vk::UniqueDescriptorPool descriptorPool = device->createDescriptorPoolUnique(
vk::DescriptorPoolCreateInfo( vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 1, 1, &poolSize ) ); vk::DescriptorPoolCreateInfo( vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 1, poolSize ) );
// allocate a descriptor set // allocate a descriptor set
vk::UniqueDescriptorSet descriptorSet = std::move( vk::UniqueDescriptorSet descriptorSet = std::move(
device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, 1, &*descriptorSetLayout ) ) device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, *descriptorSetLayout ) )
.front() ); .front() );
vk::DescriptorBufferInfo descriptorBufferInfo( uniformBufferData.buffer.get(), 0, sizeof( glm::mat4x4 ) ); vk::DescriptorBufferInfo descriptorBufferInfo( uniformBufferData.buffer.get(), 0, sizeof( glm::mat4x4 ) );
device->updateDescriptorSets( device->updateDescriptorSets(
vk::WriteDescriptorSet( vk::WriteDescriptorSet( descriptorSet.get(), 0, 0, vk::DescriptorType::eUniformBuffer, {}, descriptorBufferInfo ),
descriptorSet.get(), 0, 0, 1, vk::DescriptorType::eUniformBuffer, nullptr, &descriptorBufferInfo ),
{} ); {} );
/* VULKAN_HPP_KEY_END */ /* VULKAN_HPP_KEY_END */
@ -76,9 +75,9 @@ int main( int /*argc*/, char ** /*argv*/ )
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( std::runtime_error & err ) catch ( std::exception & err )
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::exception: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( ... ) catch ( ... )

View File

@ -52,7 +52,7 @@ int main( int /*argc*/, char ** /*argv*/ )
/* VULKAN_HPP_KEY_START */ /* VULKAN_HPP_KEY_START */
vk::AttachmentDescription attachmentDescriptions[2]; std::array<vk::AttachmentDescription, 2> attachmentDescriptions;
attachmentDescriptions[0] = vk::AttachmentDescription( vk::AttachmentDescriptionFlags(), attachmentDescriptions[0] = vk::AttachmentDescription( vk::AttachmentDescriptionFlags(),
colorFormat, colorFormat,
vk::SampleCountFlagBits::e1, vk::SampleCountFlagBits::e1,
@ -74,17 +74,11 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::AttachmentReference colorReference( 0, vk::ImageLayout::eColorAttachmentOptimal ); vk::AttachmentReference colorReference( 0, vk::ImageLayout::eColorAttachmentOptimal );
vk::AttachmentReference depthReference( 1, vk::ImageLayout::eDepthStencilAttachmentOptimal ); vk::AttachmentReference depthReference( 1, vk::ImageLayout::eDepthStencilAttachmentOptimal );
vk::SubpassDescription subpass( vk::SubpassDescriptionFlags(), vk::SubpassDescription subpass(
vk::PipelineBindPoint::eGraphics, vk::SubpassDescriptionFlags(), vk::PipelineBindPoint::eGraphics, {}, colorReference, {}, &depthReference );
0,
nullptr,
1,
&colorReference,
nullptr,
&depthReference );
vk::UniqueRenderPass renderPass = device->createRenderPassUnique( vk::UniqueRenderPass renderPass = device->createRenderPassUnique(
vk::RenderPassCreateInfo( vk::RenderPassCreateFlags(), 2, attachmentDescriptions, 1, &subpass ) ); vk::RenderPassCreateInfo( vk::RenderPassCreateFlags(), attachmentDescriptions, subpass ) );
// Note: No need to explicitly destroy the RenderPass or the Semaphore, as the corresponding destroy // Note: No need to explicitly destroy the RenderPass or the Semaphore, as the corresponding destroy
// functions are called by the destructor of the UniqueRenderPass and the UniqueSemaphore on leaving this scope. // functions are called by the destructor of the UniqueRenderPass and the UniqueSemaphore on leaving this scope.
@ -96,9 +90,9 @@ int main( int /*argc*/, char ** /*argv*/ )
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( std::runtime_error & err ) catch ( std::exception & err )
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::exception: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( ... ) catch ( ... )

View File

@ -47,16 +47,14 @@ int main( int /*argc*/, char ** /*argv*/ )
bool ok = vk::su::GLSLtoSPV( vk::ShaderStageFlagBits::eVertex, vertexShaderText_PC_C, vertexShaderSPV ); bool ok = vk::su::GLSLtoSPV( vk::ShaderStageFlagBits::eVertex, vertexShaderText_PC_C, vertexShaderSPV );
assert( ok ); assert( ok );
vk::ShaderModuleCreateInfo vertexShaderModuleCreateInfo( vk::ShaderModuleCreateInfo vertexShaderModuleCreateInfo( vk::ShaderModuleCreateFlags(), vertexShaderSPV );
vk::ShaderModuleCreateFlags(), vertexShaderSPV.size() * sizeof( unsigned int ), vertexShaderSPV.data() ); vk::UniqueShaderModule vertexShaderModule = device->createShaderModuleUnique( vertexShaderModuleCreateInfo );
vk::UniqueShaderModule vertexShaderModule = device->createShaderModuleUnique( vertexShaderModuleCreateInfo );
std::vector<unsigned int> fragmentShaderSPV; std::vector<unsigned int> fragmentShaderSPV;
ok = vk::su::GLSLtoSPV( vk::ShaderStageFlagBits::eFragment, fragmentShaderText_C_C, fragmentShaderSPV ); ok = vk::su::GLSLtoSPV( vk::ShaderStageFlagBits::eFragment, fragmentShaderText_C_C, fragmentShaderSPV );
assert( ok ); assert( ok );
vk::ShaderModuleCreateInfo fragmentShaderModuleCreateInfo( vk::ShaderModuleCreateInfo fragmentShaderModuleCreateInfo( vk::ShaderModuleCreateFlags(), fragmentShaderSPV );
vk::ShaderModuleCreateFlags(), fragmentShaderSPV.size() * sizeof( unsigned int ), fragmentShaderSPV.data() );
vk::UniqueShaderModule fragmentShaderModule = device->createShaderModuleUnique( fragmentShaderModuleCreateInfo ); vk::UniqueShaderModule fragmentShaderModule = device->createShaderModuleUnique( fragmentShaderModuleCreateInfo );
glslang::FinalizeProcess(); glslang::FinalizeProcess();
@ -71,9 +69,9 @@ int main( int /*argc*/, char ** /*argv*/ )
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( std::runtime_error & err ) catch ( std::exception & err )
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::exception: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( ... ) catch ( ... )

View File

@ -58,7 +58,7 @@ int main( int /*argc*/, char ** /*argv*/ )
/* VULKAN_KEY_START */ /* VULKAN_KEY_START */
vk::ImageView attachments[2]; std::array<vk::ImageView, 2> attachments;
attachments[1] = depthBufferData.imageView.get(); attachments[1] = depthBufferData.imageView.get();
std::vector<vk::UniqueFramebuffer> framebuffers; std::vector<vk::UniqueFramebuffer> framebuffers;
@ -68,7 +68,6 @@ int main( int /*argc*/, char ** /*argv*/ )
attachments[0] = view.get(); attachments[0] = view.get();
framebuffers.push_back( device->createFramebufferUnique( vk::FramebufferCreateInfo( vk::FramebufferCreateFlags(), framebuffers.push_back( device->createFramebufferUnique( vk::FramebufferCreateInfo( vk::FramebufferCreateFlags(),
renderPass.get(), renderPass.get(),
2,
attachments, attachments,
surfaceData.extent.width, surfaceData.extent.width,
surfaceData.extent.height, surfaceData.extent.height,
@ -85,9 +84,9 @@ int main( int /*argc*/, char ** /*argv*/ )
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( std::runtime_error & err ) catch ( std::exception & err )
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::exception: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( ... ) catch ( ... )

View File

@ -98,7 +98,7 @@ int main( int /*argc*/, char ** /*argv*/ )
assert( currentBuffer.result == vk::Result::eSuccess ); assert( currentBuffer.result == vk::Result::eSuccess );
assert( currentBuffer.value < framebuffers.size() ); assert( currentBuffer.value < framebuffers.size() );
vk::ClearValue clearValues[2]; std::array<vk::ClearValue, 2> clearValues;
clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) ); clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) );
clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 ); clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
@ -107,7 +107,6 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::RenderPassBeginInfo renderPassBeginInfo( renderPass.get(), vk::RenderPassBeginInfo renderPassBeginInfo( renderPass.get(),
framebuffers[currentBuffer.value].get(), framebuffers[currentBuffer.value].get(),
vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ),
2,
clearValues ); clearValues );
commandBuffer->beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline ); commandBuffer->beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
@ -128,9 +127,9 @@ int main( int /*argc*/, char ** /*argv*/ )
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( std::runtime_error & err ) catch ( std::exception & err )
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::exception: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( ... ) catch ( ... )

View File

@ -53,7 +53,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::UniqueDescriptorSetLayout descriptorSetLayout = vk::su::createDescriptorSetLayout( vk::UniqueDescriptorSetLayout descriptorSetLayout = vk::su::createDescriptorSetLayout(
device, { { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex } } ); device, { { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex } } );
vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique( vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique(
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), 1, &descriptorSetLayout.get() ) ); vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), *descriptorSetLayout ) );
glslang::InitializeProcess(); glslang::InitializeProcess();
vk::UniqueShaderModule vertexShaderModule = vk::UniqueShaderModule vertexShaderModule =
@ -64,24 +64,22 @@ int main( int /*argc*/, char ** /*argv*/ )
/* VULKAN_KEY_START */ /* VULKAN_KEY_START */
vk::PipelineShaderStageCreateInfo pipelineShaderStageCreateInfos[2] = { std::array<vk::PipelineShaderStageCreateInfo, 2> pipelineShaderStageCreateInfos = {
vk::PipelineShaderStageCreateInfo( vk::PipelineShaderStageCreateInfo(
vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eVertex, vertexShaderModule.get(), "main" ), vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eVertex, vertexShaderModule.get(), "main" ),
vk::PipelineShaderStageCreateInfo( vk::PipelineShaderStageCreateInfo(
vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eFragment, fragmentShaderModule.get(), "main" ) vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eFragment, fragmentShaderModule.get(), "main" )
}; };
vk::VertexInputBindingDescription vertexInputBindingDescription( 0, sizeof( coloredCubeData[0] ) ); vk::VertexInputBindingDescription vertexInputBindingDescription( 0, sizeof( coloredCubeData[0] ) );
vk::VertexInputAttributeDescription vertexInputAttributeDescriptions[2] = { std::array<vk::VertexInputAttributeDescription, 2> vertexInputAttributeDescriptions = {
vk::VertexInputAttributeDescription( 0, 0, vk::Format::eR32G32B32A32Sfloat, 0 ), vk::VertexInputAttributeDescription( 0, 0, vk::Format::eR32G32B32A32Sfloat, 0 ),
vk::VertexInputAttributeDescription( 1, 0, vk::Format::eR32G32B32A32Sfloat, 16 ) vk::VertexInputAttributeDescription( 1, 0, vk::Format::eR32G32B32A32Sfloat, 16 )
}; };
vk::PipelineVertexInputStateCreateInfo pipelineVertexInputStateCreateInfo( vk::PipelineVertexInputStateCreateInfo pipelineVertexInputStateCreateInfo(
vk::PipelineVertexInputStateCreateFlags(), // flags vk::PipelineVertexInputStateCreateFlags(), // flags
1, // vertexBindingDescriptionCount vertexInputBindingDescription, // vertexBindingDescriptions
&vertexInputBindingDescription, // pVertexBindingDescription vertexInputAttributeDescriptions // vertexAttributeDescriptions
2, // vertexAttributeDescriptionCount
vertexInputAttributeDescriptions // pVertexAttributeDescriptions
); );
vk::PipelineInputAssemblyStateCreateInfo pipelineInputAssemblyStateCreateInfo( vk::PipelineInputAssemblyStateCreateInfo pipelineInputAssemblyStateCreateInfo(
@ -139,19 +137,17 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::PipelineColorBlendStateCreateFlags(), // flags vk::PipelineColorBlendStateCreateFlags(), // flags
false, // logicOpEnable false, // logicOpEnable
vk::LogicOp::eNoOp, // logicOp vk::LogicOp::eNoOp, // logicOp
1, // attachmentCount pipelineColorBlendAttachmentState, // attachments
&pipelineColorBlendAttachmentState, // pAttachments
{ { 1.0f, 1.0f, 1.0f, 1.0f } } // blendConstants { { 1.0f, 1.0f, 1.0f, 1.0f } } // blendConstants
); );
vk::DynamicState dynamicStates[2] = { vk::DynamicState::eViewport, vk::DynamicState::eScissor }; std::array<vk::DynamicState, 2> dynamicStates = { vk::DynamicState::eViewport, vk::DynamicState::eScissor };
vk::PipelineDynamicStateCreateInfo pipelineDynamicStateCreateInfo( vk::PipelineDynamicStateCreateInfo pipelineDynamicStateCreateInfo( vk::PipelineDynamicStateCreateFlags(),
vk::PipelineDynamicStateCreateFlags(), 2, dynamicStates ); dynamicStates );
vk::GraphicsPipelineCreateInfo graphicsPipelineCreateInfo( vk::GraphicsPipelineCreateInfo graphicsPipelineCreateInfo(
vk::PipelineCreateFlags(), // flags vk::PipelineCreateFlags(), // flags
2, // stageCount pipelineShaderStageCreateInfos, // stages
pipelineShaderStageCreateInfos, // pStages
&pipelineVertexInputStateCreateInfo, // pVertexInputState &pipelineVertexInputStateCreateInfo, // pVertexInputState
&pipelineInputAssemblyStateCreateInfo, // pInputAssemblyState &pipelineInputAssemblyStateCreateInfo, // pInputAssemblyState
nullptr, // pTessellationState nullptr, // pTessellationState
@ -174,9 +170,9 @@ int main( int /*argc*/, char ** /*argv*/ )
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( std::runtime_error & err ) catch ( std::exception & err )
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::exception: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( ... ) catch ( ... )

View File

@ -75,7 +75,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::UniqueDescriptorSetLayout descriptorSetLayout = vk::su::createDescriptorSetLayout( vk::UniqueDescriptorSetLayout descriptorSetLayout = vk::su::createDescriptorSetLayout(
device, { { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex } } ); device, { { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex } } );
vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique( vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique(
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), 1, &descriptorSetLayout.get() ) ); vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), *descriptorSetLayout ) );
vk::UniqueRenderPass renderPass = vk::su::createRenderPass( vk::UniqueRenderPass renderPass = vk::su::createRenderPass(
device, device,
@ -102,14 +102,11 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::UniqueDescriptorPool descriptorPool = vk::UniqueDescriptorPool descriptorPool =
vk::su::createDescriptorPool( device, { { vk::DescriptorType::eUniformBuffer, 1 } } ); vk::su::createDescriptorPool( device, { { vk::DescriptorType::eUniformBuffer, 1 } } );
vk::UniqueDescriptorSet descriptorSet = std::move( vk::UniqueDescriptorSet descriptorSet = std::move(
device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, 1, &*descriptorSetLayout ) ) device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, *descriptorSetLayout ) )
.front() ); .front() );
vk::su::updateDescriptorSets( vk::su::updateDescriptorSets(
device, device, descriptorSet, { { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, {} } }, {} );
descriptorSet,
{ { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, {} } },
{} );
vk::UniquePipelineCache pipelineCache = device->createPipelineCacheUnique( vk::PipelineCacheCreateInfo() ); vk::UniquePipelineCache pipelineCache = device->createPipelineCacheUnique( vk::PipelineCacheCreateInfo() );
vk::UniquePipeline graphicsPipeline = vk::su::createGraphicsPipeline( vk::UniquePipeline graphicsPipeline = vk::su::createGraphicsPipeline(
@ -134,13 +131,12 @@ int main( int /*argc*/, char ** /*argv*/ )
commandBuffer->begin( vk::CommandBufferBeginInfo( vk::CommandBufferUsageFlags() ) ); commandBuffer->begin( vk::CommandBufferBeginInfo( vk::CommandBufferUsageFlags() ) );
vk::ClearValue clearValues[2]; std::array<vk::ClearValue, 2> clearValues;
clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) ); clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) );
clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 ); clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
vk::RenderPassBeginInfo renderPassBeginInfo( renderPass.get(), vk::RenderPassBeginInfo renderPassBeginInfo( renderPass.get(),
framebuffers[currentBuffer.value].get(), framebuffers[currentBuffer.value].get(),
vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ),
2,
clearValues ); clearValues );
commandBuffer->beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline ); commandBuffer->beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
commandBuffer->bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline.get() ); commandBuffer->bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline.get() );
@ -164,14 +160,13 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::UniqueFence drawFence = device->createFenceUnique( vk::FenceCreateInfo() ); vk::UniqueFence drawFence = device->createFenceUnique( vk::FenceCreateInfo() );
vk::PipelineStageFlags waitDestinationStageMask( vk::PipelineStageFlagBits::eColorAttachmentOutput ); vk::PipelineStageFlags waitDestinationStageMask( vk::PipelineStageFlagBits::eColorAttachmentOutput );
vk::SubmitInfo submitInfo( 1, &imageAcquiredSemaphore.get(), &waitDestinationStageMask, 1, &commandBuffer.get() ); vk::SubmitInfo submitInfo( *imageAcquiredSemaphore, waitDestinationStageMask, *commandBuffer );
graphicsQueue.submit( submitInfo, drawFence.get() ); graphicsQueue.submit( submitInfo, drawFence.get() );
while ( vk::Result::eTimeout == device->waitForFences( drawFence.get(), VK_TRUE, vk::su::FenceTimeout ) ) while ( vk::Result::eTimeout == device->waitForFences( drawFence.get(), VK_TRUE, vk::su::FenceTimeout ) )
; ;
presentQueue.presentKHR( presentQueue.presentKHR( vk::PresentInfoKHR( {}, *swapChainData.swapChain, currentBuffer.value ) );
vk::PresentInfoKHR( 0, nullptr, 1, &swapChainData.swapChain.get(), &currentBuffer.value ) );
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) ); std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
/* VULKAN_KEY_END */ /* VULKAN_KEY_END */
@ -183,9 +178,9 @@ int main( int /*argc*/, char ** /*argv*/ )
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( std::runtime_error & err ) catch ( std::exception & err )
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::exception: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( ... ) catch ( ... )

View File

@ -111,9 +111,9 @@ int main( int /*argc*/, char ** /*argv*/ )
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( std::runtime_error & err ) catch ( std::exception & err )
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::exception: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( ... ) catch ( ... )

View File

@ -122,7 +122,7 @@ int main( int /*argc*/, char ** /*argv*/ )
/* Queue the command buffer for execution */ /* Queue the command buffer for execution */
vk::UniqueFence commandFence = device->createFenceUnique( {} ); vk::UniqueFence commandFence = device->createFenceUnique( {} );
vk::PipelineStageFlags pipeStageFlags( vk::PipelineStageFlagBits::eColorAttachmentOutput ); vk::PipelineStageFlags pipeStageFlags( vk::PipelineStageFlagBits::eColorAttachmentOutput );
graphicsQueue.submit( vk::SubmitInfo( 1, &imageAcquiredSemaphore.get(), &pipeStageFlags, 1, &commandBuffer.get() ), graphicsQueue.submit( vk::SubmitInfo( *imageAcquiredSemaphore, pipeStageFlags, *commandBuffer ),
commandFence.get() ); commandFence.get() );
/* Make sure command buffer is finished before mapping */ /* Make sure command buffer is finished before mapping */
@ -222,7 +222,7 @@ int main( int /*argc*/, char ** /*argv*/ )
commandBuffer->end(); commandBuffer->end();
vk::UniqueFence drawFence = device->createFenceUnique( {} ); vk::UniqueFence drawFence = device->createFenceUnique( {} );
graphicsQueue.submit( vk::SubmitInfo( 0, nullptr, nullptr, 1, &commandBuffer.get() ), drawFence.get() ); graphicsQueue.submit( vk::SubmitInfo( {}, {}, *commandBuffer ), drawFence.get() );
graphicsQueue.waitIdle(); graphicsQueue.waitIdle();
/* Make sure command buffer is finished before presenting */ /* Make sure command buffer is finished before presenting */
@ -230,8 +230,7 @@ int main( int /*argc*/, char ** /*argv*/ )
; ;
/* Now present the image in the window */ /* Now present the image in the window */
presentQueue.presentKHR( presentQueue.presentKHR( vk::PresentInfoKHR( {}, *swapChainData.swapChain, currentBuffer, {} ) );
vk::PresentInfoKHR( 0, nullptr, 1, &swapChainData.swapChain.get(), &currentBuffer, nullptr ) );
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) ); std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
/* VULKAN_KEY_END */ /* VULKAN_KEY_END */
@ -241,9 +240,9 @@ int main( int /*argc*/, char ** /*argv*/ )
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( std::runtime_error & err ) catch ( std::exception & err )
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::exception: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( ... ) catch ( ... )

View File

@ -127,7 +127,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::ApplicationInfo applicationInfo( AppName, 1, EngineName, 1, VK_API_VERSION_1_1 ); vk::ApplicationInfo applicationInfo( AppName, 1, EngineName, 1, VK_API_VERSION_1_1 );
const char * extensionName = VK_EXT_DEBUG_UTILS_EXTENSION_NAME; const char * extensionName = VK_EXT_DEBUG_UTILS_EXTENSION_NAME;
vk::UniqueInstance instance = vk::createInstanceUnique( vk::UniqueInstance instance = vk::createInstanceUnique(
vk::InstanceCreateInfo( vk::InstanceCreateFlags(), &applicationInfo, 0, nullptr, 1, &extensionName ) ); vk::InstanceCreateInfo( vk::InstanceCreateFlags(), &applicationInfo, {}, extensionName ) );
pfnVkCreateDebugUtilsMessengerEXT = pfnVkCreateDebugUtilsMessengerEXT =
reinterpret_cast<PFN_vkCreateDebugUtilsMessengerEXT>( instance->getProcAddr( "vkCreateDebugUtilsMessengerEXT" ) ); reinterpret_cast<PFN_vkCreateDebugUtilsMessengerEXT>( instance->getProcAddr( "vkCreateDebugUtilsMessengerEXT" ) );
@ -160,9 +160,9 @@ int main( int /*argc*/, char ** /*argv*/ )
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( std::runtime_error & err ) catch ( std::exception & err )
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::exception: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( ... ) catch ( ... )

View File

@ -68,9 +68,9 @@ int main( int /*argc*/, char ** /*argv*/ )
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( std::runtime_error err ) catch ( std::exception err )
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::exception: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( ... ) catch ( ... )

View File

@ -82,7 +82,7 @@ int main( int /*argc*/, char ** /*argv*/ )
{ { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex }, { { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex },
{ vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment } } ); { vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment } } );
vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique( vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique(
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), 1, &descriptorSetLayout.get() ) ); vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), *descriptorSetLayout ) );
vk::UniqueRenderPass renderPass = vk::su::createRenderPass( vk::UniqueRenderPass renderPass = vk::su::createRenderPass(
device, device,
@ -109,14 +109,11 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::UniqueDescriptorPool descriptorPool = vk::su::createDescriptorPool( vk::UniqueDescriptorPool descriptorPool = vk::su::createDescriptorPool(
device, { { vk::DescriptorType::eUniformBuffer, 1 }, { vk::DescriptorType::eCombinedImageSampler, 1 } } ); device, { { vk::DescriptorType::eUniformBuffer, 1 }, { vk::DescriptorType::eCombinedImageSampler, 1 } } );
vk::UniqueDescriptorSet descriptorSet = std::move( vk::UniqueDescriptorSet descriptorSet = std::move(
device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, 1, &*descriptorSetLayout ) ) device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, *descriptorSetLayout ) )
.front() ); .front() );
vk::su::updateDescriptorSets( vk::su::updateDescriptorSets(
device, device, descriptorSet, { { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, {} } }, textureData );
descriptorSet,
{ { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, {} } },
textureData );
vk::UniquePipelineCache pipelineCache = device->createPipelineCacheUnique( vk::PipelineCacheCreateInfo() ); vk::UniquePipelineCache pipelineCache = device->createPipelineCacheUnique( vk::PipelineCacheCreateInfo() );
vk::UniquePipeline graphicsPipeline = vk::UniquePipeline graphicsPipeline =
@ -141,13 +138,12 @@ int main( int /*argc*/, char ** /*argv*/ )
// commandBuffer->begin() has already been called above! // commandBuffer->begin() has already been called above!
vk::ClearValue clearValues[2]; std::array<vk::ClearValue, 2> clearValues;
clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) ); clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) );
clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 ); clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
vk::RenderPassBeginInfo renderPassBeginInfo( renderPass.get(), vk::RenderPassBeginInfo renderPassBeginInfo( renderPass.get(),
framebuffers[currentBuffer.value].get(), framebuffers[currentBuffer.value].get(),
vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ),
2,
clearValues ); clearValues );
commandBuffer->beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline ); commandBuffer->beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
commandBuffer->bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline.get() ); commandBuffer->bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline.get() );
@ -171,14 +167,13 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::UniqueFence drawFence = device->createFenceUnique( vk::FenceCreateInfo() ); vk::UniqueFence drawFence = device->createFenceUnique( vk::FenceCreateInfo() );
vk::PipelineStageFlags waitDestinationStageMask( vk::PipelineStageFlagBits::eColorAttachmentOutput ); vk::PipelineStageFlags waitDestinationStageMask( vk::PipelineStageFlagBits::eColorAttachmentOutput );
vk::SubmitInfo submitInfo( 1, &imageAcquiredSemaphore.get(), &waitDestinationStageMask, 1, &commandBuffer.get() ); vk::SubmitInfo submitInfo( *imageAcquiredSemaphore, waitDestinationStageMask, *commandBuffer );
graphicsQueue.submit( submitInfo, drawFence.get() ); graphicsQueue.submit( submitInfo, drawFence.get() );
while ( vk::Result::eTimeout == device->waitForFences( drawFence.get(), VK_TRUE, vk::su::FenceTimeout ) ) while ( vk::Result::eTimeout == device->waitForFences( drawFence.get(), VK_TRUE, vk::su::FenceTimeout ) )
; ;
presentQueue.presentKHR( presentQueue.presentKHR( vk::PresentInfoKHR( {}, *swapChainData.swapChain, currentBuffer.value ) );
vk::PresentInfoKHR( 0, nullptr, 1, &swapChainData.swapChain.get(), &currentBuffer.value ) );
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) ); std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
/* VULKAN_KEY_END */ /* VULKAN_KEY_END */
@ -190,9 +185,9 @@ int main( int /*argc*/, char ** /*argv*/ )
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( std::runtime_error & err ) catch ( std::exception & err )
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::exception: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( ... ) catch ( ... )

View File

@ -140,20 +140,17 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::UniqueDescriptorSetLayout descriptorSetLayout = vk::su::createDescriptorSetLayout( vk::UniqueDescriptorSetLayout descriptorSetLayout = vk::su::createDescriptorSetLayout(
device, { { vk::DescriptorType::eUniformBufferDynamic, 1, vk::ShaderStageFlagBits::eVertex } } ); device, { { vk::DescriptorType::eUniformBufferDynamic, 1, vk::ShaderStageFlagBits::eVertex } } );
vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique( vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique(
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), 1, &descriptorSetLayout.get() ) ); vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), *descriptorSetLayout ) );
// create a DescriptorPool with vk::DescriptorType::eUniformBufferDynamic // create a DescriptorPool with vk::DescriptorType::eUniformBufferDynamic
vk::UniqueDescriptorPool descriptorPool = vk::UniqueDescriptorPool descriptorPool =
vk::su::createDescriptorPool( device, { { vk::DescriptorType::eUniformBufferDynamic, 1 } } ); vk::su::createDescriptorPool( device, { { vk::DescriptorType::eUniformBufferDynamic, 1 } } );
vk::UniqueDescriptorSet descriptorSet = std::move( vk::UniqueDescriptorSet descriptorSet = std::move(
device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, 1, &*descriptorSetLayout ) ) device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, *descriptorSetLayout ) )
.front() ); .front() );
vk::su::updateDescriptorSets( vk::su::updateDescriptorSets(
device, device, descriptorSet, { { vk::DescriptorType::eUniformBufferDynamic, uniformBufferData.buffer, {} } }, {} );
descriptorSet,
{ { vk::DescriptorType::eUniformBufferDynamic, uniformBufferData.buffer, {} } },
{} );
vk::UniquePipelineCache pipelineCache = device->createPipelineCacheUnique( vk::PipelineCacheCreateInfo() ); vk::UniquePipelineCache pipelineCache = device->createPipelineCacheUnique( vk::PipelineCacheCreateInfo() );
vk::UniquePipeline graphicsPipeline = vk::su::createGraphicsPipeline( vk::UniquePipeline graphicsPipeline = vk::su::createGraphicsPipeline(
@ -176,13 +173,12 @@ int main( int /*argc*/, char ** /*argv*/ )
commandBuffer->begin( vk::CommandBufferBeginInfo( vk::CommandBufferUsageFlags() ) ); commandBuffer->begin( vk::CommandBufferBeginInfo( vk::CommandBufferUsageFlags() ) );
vk::ClearValue clearValues[2]; std::array<vk::ClearValue, 2> clearValues;
clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) ); clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) );
clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 ); clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
vk::RenderPassBeginInfo renderPassBeginInfo( renderPass.get(), vk::RenderPassBeginInfo renderPassBeginInfo( renderPass.get(),
framebuffers[currentBuffer.value].get(), framebuffers[currentBuffer.value].get(),
vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ),
2,
clearValues ); clearValues );
commandBuffer->beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline ); commandBuffer->beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
commandBuffer->bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline.get() ); commandBuffer->bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline.get() );
@ -216,14 +212,13 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::UniqueFence drawFence = device->createFenceUnique( vk::FenceCreateInfo() ); vk::UniqueFence drawFence = device->createFenceUnique( vk::FenceCreateInfo() );
vk::PipelineStageFlags waitDestinationStageMask( vk::PipelineStageFlagBits::eColorAttachmentOutput ); vk::PipelineStageFlags waitDestinationStageMask( vk::PipelineStageFlagBits::eColorAttachmentOutput );
vk::SubmitInfo submitInfo( 1, &imageAcquiredSemaphore.get(), &waitDestinationStageMask, 1, &commandBuffer.get() ); vk::SubmitInfo submitInfo( *imageAcquiredSemaphore, waitDestinationStageMask, *commandBuffer );
graphicsQueue.submit( submitInfo, drawFence.get() ); graphicsQueue.submit( submitInfo, drawFence.get() );
while ( vk::Result::eTimeout == device->waitForFences( drawFence.get(), VK_TRUE, vk::su::FenceTimeout ) ) while ( vk::Result::eTimeout == device->waitForFences( drawFence.get(), VK_TRUE, vk::su::FenceTimeout ) )
; ;
presentQueue.presentKHR( presentQueue.presentKHR( vk::PresentInfoKHR( {}, *swapChainData.swapChain, currentBuffer.value ) );
vk::PresentInfoKHR( 0, nullptr, 1, &swapChainData.swapChain.get(), &currentBuffer.value ) );
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) ); std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
/* VULKAN_KEY_END */ /* VULKAN_KEY_END */
@ -235,9 +230,9 @@ int main( int /*argc*/, char ** /*argv*/ )
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( std::runtime_error & err ) catch ( std::exception & err )
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::exception: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( ... ) catch ( ... )

View File

@ -136,13 +136,9 @@ int main( int /*argc*/, char ** /*argv*/ )
instanceExtensionNames.push_back( VK_EXT_DEBUG_UTILS_EXTENSION_NAME ); instanceExtensionNames.push_back( VK_EXT_DEBUG_UTILS_EXTENSION_NAME );
vk::ApplicationInfo applicationInfo( AppName, 1, EngineName, 1, VK_API_VERSION_1_1 ); vk::ApplicationInfo applicationInfo( AppName, 1, EngineName, 1, VK_API_VERSION_1_1 );
vk::InstanceCreateInfo instanceCreateInfo( vk::InstanceCreateFlags(), vk::InstanceCreateInfo instanceCreateInfo(
&applicationInfo, vk::InstanceCreateFlags(), &applicationInfo, instanceLayerNames, instanceExtensionNames );
vk::su::checked_cast<uint32_t>( instanceLayerNames.size() ), vk::UniqueInstance instance = vk::createInstanceUnique( instanceCreateInfo );
instanceLayerNames.data(),
vk::su::checked_cast<uint32_t>( instanceExtensionNames.size() ),
instanceExtensionNames.data() );
vk::UniqueInstance instance = vk::createInstanceUnique( instanceCreateInfo );
#if ( VULKAN_HPP_DISPATCH_LOADER_DYNAMIC == 1 ) #if ( VULKAN_HPP_DISPATCH_LOADER_DYNAMIC == 1 )
// initialize function pointers for instance // initialize function pointers for instance
@ -189,7 +185,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::DeviceQueueCreateInfo deviceQueueCreateInfo( vk::DeviceQueueCreateInfo deviceQueueCreateInfo(
vk::DeviceQueueCreateFlags(), queueFamilyIndex, 1, &queuePriority ); vk::DeviceQueueCreateFlags(), queueFamilyIndex, 1, &queuePriority );
vk::UniqueDevice device = vk::UniqueDevice device =
physicalDevice.createDeviceUnique( vk::DeviceCreateInfo( vk::DeviceCreateFlags(), 1, &deviceQueueCreateInfo ) ); physicalDevice.createDeviceUnique( vk::DeviceCreateInfo( vk::DeviceCreateFlags(), deviceQueueCreateInfo ) );
// Create a command pool (not a UniqueCommandPool, for testing purposes! // Create a command pool (not a UniqueCommandPool, for testing purposes!
vk::CommandPool commandPool = vk::CommandPool commandPool =
@ -207,9 +203,9 @@ int main( int /*argc*/, char ** /*argv*/ )
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( std::runtime_error & err ) catch ( std::exception & err )
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::exception: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( ... ) catch ( ... )

View File

@ -69,6 +69,11 @@ int main( int /*argc*/, char ** /*argv*/ )
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( std::exception & err )
{
std::cout << "std::exception: " << err.what() << std::endl;
exit( -1 );
}
catch ( ... ) catch ( ... )
{ {
std::cout << "unknown error\n"; std::cout << "unknown error\n";

View File

@ -55,8 +55,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::UniqueFence fence = device->createFenceUnique( vk::FenceCreateInfo() ); vk::UniqueFence fence = device->createFenceUnique( vk::FenceCreateInfo() );
vk::PipelineStageFlags waitDestinationStageMask( vk::PipelineStageFlagBits::eColorAttachmentOutput ); vk::SubmitInfo submitInfo( {}, {}, *commandBuffer );
vk::SubmitInfo submitInfo( 0, nullptr, &waitDestinationStageMask, 1, &commandBuffer.get() );
graphicsQueue.submit( submitInfo, fence.get() ); graphicsQueue.submit( submitInfo, fence.get() );
// Make sure timeout is long enough for a simple command buffer without waiting for an event // Make sure timeout is long enough for a simple command buffer without waiting for an event
@ -90,7 +89,6 @@ int main( int /*argc*/, char ** /*argv*/ )
// Note that stepping through this code in the debugger is a bad idea because the GPU can TDR waiting for the event. // Note that stepping through this code in the debugger is a bad idea because the GPU can TDR waiting for the event.
// Execute the code from vk::Queue::submit() through vk::Device::setEvent() without breakpoints // Execute the code from vk::Queue::submit() through vk::Device::setEvent() without breakpoints
waitDestinationStageMask = vk::PipelineStageFlagBits::eBottomOfPipe;
graphicsQueue.submit( submitInfo, fence.get() ); graphicsQueue.submit( submitInfo, fence.get() );
// We should timeout waiting for the fence because the GPU should be waiting on the event // We should timeout waiting for the fence because the GPU should be waiting on the event
@ -147,9 +145,9 @@ int main( int /*argc*/, char ** /*argv*/ )
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( std::runtime_error & err ) catch ( std::exception & err )
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::exception: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( ... ) catch ( ... )

View File

@ -101,30 +101,28 @@ int main( int /*argc*/, char ** /*argv*/ )
commandBuffer->begin( vk::CommandBufferBeginInfo() ); commandBuffer->begin( vk::CommandBufferBeginInfo() );
textureData.setImage( device, commandBuffer, vk::su::CheckerboardImageGenerator() ); textureData.setImage( device, commandBuffer, vk::su::CheckerboardImageGenerator() );
vk::DescriptorSetLayoutBinding bindings[2] = { std::array<vk::DescriptorSetLayoutBinding, 2> bindings = {
vk::DescriptorSetLayoutBinding( 0, vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex ), vk::DescriptorSetLayoutBinding( 0, vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex ),
vk::DescriptorSetLayoutBinding( 1, vk::DescriptorSetLayoutBinding(
vk::DescriptorType::eCombinedImageSampler, 1, vk::DescriptorType::eCombinedImageSampler, vk::ShaderStageFlagBits::eFragment, *textureData.textureSampler )
1,
vk::ShaderStageFlagBits::eFragment,
&textureData.textureSampler.get() )
}; };
vk::UniqueDescriptorSetLayout descriptorSetLayout = device->createDescriptorSetLayoutUnique( vk::UniqueDescriptorSetLayout descriptorSetLayout = device->createDescriptorSetLayoutUnique(
vk::DescriptorSetLayoutCreateInfo( vk::DescriptorSetLayoutCreateFlags(), 2, bindings ) ); vk::DescriptorSetLayoutCreateInfo( vk::DescriptorSetLayoutCreateFlags(), bindings ) );
// Create pipeline layout // Create pipeline layout
vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique( vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique(
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), 1, &descriptorSetLayout.get() ) ); vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), *descriptorSetLayout ) );
// Create a single pool to contain data for our descriptor set // Create a single pool to contain data for our descriptor set
vk::DescriptorPoolSize poolSizes[2] = { vk::DescriptorPoolSize( vk::DescriptorType::eUniformBuffer, 1 ), std::array<vk::DescriptorPoolSize, 2> poolSizes = { vk::DescriptorPoolSize( vk::DescriptorType::eUniformBuffer, 1 ),
vk::DescriptorPoolSize( vk::DescriptorType::eCombinedImageSampler, 1 ) }; vk::DescriptorPoolSize(
vk::UniqueDescriptorPool descriptorPool = device->createDescriptorPoolUnique( vk::DescriptorType::eCombinedImageSampler, 1 ) };
vk::DescriptorPoolCreateInfo( vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 1, 2, poolSizes ) ); vk::UniqueDescriptorPool descriptorPool = device->createDescriptorPoolUnique(
vk::DescriptorPoolCreateInfo( vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 1, poolSizes ) );
// Populate descriptor sets // Populate descriptor sets
vk::UniqueDescriptorSet descriptorSet = std::move( vk::UniqueDescriptorSet descriptorSet = std::move(
device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, 1, &*descriptorSetLayout ) ) device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, *descriptorSetLayout ) )
.front() ); .front() );
vk::DescriptorBufferInfo bufferInfo( uniformBufferData.buffer.get(), 0, sizeof( glm::mat4x4 ) ); vk::DescriptorBufferInfo bufferInfo( uniformBufferData.buffer.get(), 0, sizeof( glm::mat4x4 ) );
@ -132,8 +130,8 @@ int main( int /*argc*/, char ** /*argv*/ )
textureData.imageData->imageView.get(), textureData.imageData->imageView.get(),
vk::ImageLayout::eShaderReadOnlyOptimal ); vk::ImageLayout::eShaderReadOnlyOptimal );
vk::WriteDescriptorSet writeDescriptorSets[2] = { vk::WriteDescriptorSet writeDescriptorSets[2] = {
vk::WriteDescriptorSet( descriptorSet.get(), 0, 0, 1, vk::DescriptorType::eUniformBuffer, nullptr, &bufferInfo ), vk::WriteDescriptorSet( descriptorSet.get(), 0, 0, vk::DescriptorType::eUniformBuffer, {}, bufferInfo ),
vk::WriteDescriptorSet( descriptorSet.get(), 1, 0, 1, vk::DescriptorType::eCombinedImageSampler, &imageInfo ) vk::WriteDescriptorSet( descriptorSet.get(), 1, 0, vk::DescriptorType::eCombinedImageSampler, imageInfo )
}; };
device->updateDescriptorSets( vk::ArrayProxy<const vk::WriteDescriptorSet>( 2, writeDescriptorSets ), nullptr ); device->updateDescriptorSets( vk::ArrayProxy<const vk::WriteDescriptorSet>( 2, writeDescriptorSets ), nullptr );
@ -158,13 +156,12 @@ int main( int /*argc*/, char ** /*argv*/ )
assert( currentBuffer.result == vk::Result::eSuccess ); assert( currentBuffer.result == vk::Result::eSuccess );
assert( currentBuffer.value < framebuffers.size() ); assert( currentBuffer.value < framebuffers.size() );
vk::ClearValue clearValues[2]; std::array<vk::ClearValue, 2> clearValues;
clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) ); clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) );
clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 ); clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
vk::RenderPassBeginInfo renderPassBeginInfo( renderPass.get(), vk::RenderPassBeginInfo renderPassBeginInfo( renderPass.get(),
framebuffers[currentBuffer.value].get(), framebuffers[currentBuffer.value].get(),
vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ),
2,
clearValues ); clearValues );
commandBuffer->beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline ); commandBuffer->beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
commandBuffer->bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline.get() ); commandBuffer->bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline.get() );
@ -187,8 +184,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::su::submitAndWait( device, graphicsQueue, commandBuffer ); vk::su::submitAndWait( device, graphicsQueue, commandBuffer );
presentQueue.presentKHR( presentQueue.presentKHR( vk::PresentInfoKHR( {}, *swapChainData.swapChain, currentBuffer.value ) );
vk::PresentInfoKHR( 0, nullptr, 1, &swapChainData.swapChain.get(), &currentBuffer.value ) );
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) ); std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
device->waitIdle(); device->waitIdle();
@ -198,9 +194,9 @@ int main( int /*argc*/, char ** /*argv*/ )
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( std::runtime_error & err ) catch ( std::exception & err )
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::exception: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( ... ) catch ( ... )

View File

@ -74,8 +74,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::ImageUsageFlagBits::eSampled | vk::ImageUsageFlagBits::eSampled |
( needsStaging ? vk::ImageUsageFlagBits::eTransferDst : vk::ImageUsageFlagBits() ), ( needsStaging ? vk::ImageUsageFlagBits::eTransferDst : vk::ImageUsageFlagBits() ),
vk::SharingMode::eExclusive, vk::SharingMode::eExclusive,
0, {},
nullptr,
needsStaging ? vk::ImageLayout::eUndefined : vk::ImageLayout::ePreinitialized ) ); needsStaging ? vk::ImageLayout::eUndefined : vk::ImageLayout::ePreinitialized ) );
vk::MemoryRequirements memoryRequirements = device->getImageMemoryRequirements( image.get() ); vk::MemoryRequirements memoryRequirements = device->getImageMemoryRequirements( image.get() );
@ -207,9 +206,9 @@ int main( int /*argc*/, char ** /*argv*/ )
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( std::runtime_error & err ) catch ( std::exception & err )
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::exception: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( ... ) catch ( ... )

View File

@ -162,12 +162,12 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::DescriptorSetLayoutBinding layoutBinding( vk::DescriptorSetLayoutBinding layoutBinding(
0, vk::DescriptorType::eInputAttachment, 1, vk::ShaderStageFlagBits::eFragment ); 0, vk::DescriptorType::eInputAttachment, 1, vk::ShaderStageFlagBits::eFragment );
vk::UniqueDescriptorSetLayout descriptorSetLayout = device->createDescriptorSetLayoutUnique( vk::UniqueDescriptorSetLayout descriptorSetLayout = device->createDescriptorSetLayoutUnique(
vk::DescriptorSetLayoutCreateInfo( vk::DescriptorSetLayoutCreateFlags(), 1, &layoutBinding ) ); vk::DescriptorSetLayoutCreateInfo( vk::DescriptorSetLayoutCreateFlags(), layoutBinding ) );
vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique( vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique(
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), 1, &descriptorSetLayout.get() ) ); vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), *descriptorSetLayout ) );
vk::AttachmentDescription attachments[2] = { std::array<vk::AttachmentDescription, 2> attachments = {
// First attachment is the color attachment - clear at the beginning of the renderpass and transition layout to // First attachment is the color attachment - clear at the beginning of the renderpass and transition layout to
// PRESENT_SRC_KHR at the end of renderpass // PRESENT_SRC_KHR at the end of renderpass
vk::AttachmentDescription( vk::AttachmentDescriptionFlags(), vk::AttachmentDescription( vk::AttachmentDescriptionFlags(),
@ -195,9 +195,9 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::AttachmentReference colorReference( 0, vk::ImageLayout::eColorAttachmentOptimal ); vk::AttachmentReference colorReference( 0, vk::ImageLayout::eColorAttachmentOptimal );
vk::AttachmentReference inputReference( 1, vk::ImageLayout::eShaderReadOnlyOptimal ); vk::AttachmentReference inputReference( 1, vk::ImageLayout::eShaderReadOnlyOptimal );
vk::SubpassDescription subPass( vk::SubpassDescription subPass(
vk::SubpassDescriptionFlags(), vk::PipelineBindPoint::eGraphics, 1, &inputReference, 1, &colorReference ); vk::SubpassDescriptionFlags(), vk::PipelineBindPoint::eGraphics, inputReference, colorReference );
vk::UniqueRenderPass renderPass = device->createRenderPassUnique( vk::UniqueRenderPass renderPass =
vk::RenderPassCreateInfo( vk::RenderPassCreateFlags(), 2, attachments, 1, &subPass ) ); device->createRenderPassUnique( vk::RenderPassCreateInfo( vk::RenderPassCreateFlags(), attachments, subPass ) );
glslang::InitializeProcess(); glslang::InitializeProcess();
vk::UniqueShaderModule vertexShaderModule = vk::UniqueShaderModule vertexShaderModule =
@ -211,16 +211,16 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::DescriptorPoolSize poolSize( vk::DescriptorType::eInputAttachment, 1 ); vk::DescriptorPoolSize poolSize( vk::DescriptorType::eInputAttachment, 1 );
vk::UniqueDescriptorPool descriptorPool = device->createDescriptorPoolUnique( vk::UniqueDescriptorPool descriptorPool = device->createDescriptorPoolUnique(
vk::DescriptorPoolCreateInfo( vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 1, 1, &poolSize ) ); vk::DescriptorPoolCreateInfo( vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 1, poolSize ) );
vk::UniqueDescriptorSet descriptorSet = std::move( vk::UniqueDescriptorSet descriptorSet = std::move(
device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, 1, &*descriptorSetLayout ) ) device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, *descriptorSetLayout ) )
.front() ); .front() );
vk::DescriptorImageInfo inputImageInfo( vk::DescriptorImageInfo inputImageInfo(
nullptr, inputAttachmentView.get(), vk::ImageLayout::eShaderReadOnlyOptimal ); nullptr, inputAttachmentView.get(), vk::ImageLayout::eShaderReadOnlyOptimal );
vk::WriteDescriptorSet writeDescriptorSet( vk::WriteDescriptorSet writeDescriptorSet(
descriptorSet.get(), 0, 0, 1, vk::DescriptorType::eInputAttachment, &inputImageInfo ); descriptorSet.get(), 0, 0, vk::DescriptorType::eInputAttachment, inputImageInfo );
device->updateDescriptorSets( vk::ArrayProxy<const vk::WriteDescriptorSet>( 1, &writeDescriptorSet ), nullptr ); device->updateDescriptorSets( vk::ArrayProxy<const vk::WriteDescriptorSet>( 1, &writeDescriptorSet ), nullptr );
vk::UniquePipelineCache pipelineCache = device->createPipelineCacheUnique( vk::PipelineCacheCreateInfo() ); vk::UniquePipelineCache pipelineCache = device->createPipelineCacheUnique( vk::PipelineCacheCreateInfo() );
@ -248,8 +248,7 @@ int main( int /*argc*/, char ** /*argv*/ )
commandBuffer->beginRenderPass( vk::RenderPassBeginInfo( renderPass.get(), commandBuffer->beginRenderPass( vk::RenderPassBeginInfo( renderPass.get(),
framebuffers[currentBuffer].get(), framebuffers[currentBuffer].get(),
vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ),
1, clearValue ),
&clearValue ),
vk::SubpassContents::eInline ); vk::SubpassContents::eInline );
commandBuffer->bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline.get() ); commandBuffer->bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline.get() );
commandBuffer->bindDescriptorSets( commandBuffer->bindDescriptorSets(
@ -272,7 +271,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::su::submitAndWait( device, graphicsQueue, commandBuffer ); vk::su::submitAndWait( device, graphicsQueue, commandBuffer );
presentQueue.presentKHR( vk::PresentInfoKHR( 0, nullptr, 1, &swapChainData.swapChain.get(), &currentBuffer ) ); presentQueue.presentKHR( vk::PresentInfoKHR( {}, *swapChainData.swapChain, currentBuffer ) );
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) ); std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
} }
catch ( vk::SystemError & err ) catch ( vk::SystemError & err )
@ -280,9 +279,9 @@ int main( int /*argc*/, char ** /*argv*/ )
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( std::runtime_error & err ) catch ( std::exception & err )
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::exception: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( ... ) catch ( ... )

View File

@ -55,9 +55,9 @@ int main( int /*argc*/, char ** /*argv*/ )
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( std::runtime_error & err ) catch ( std::exception & err )
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::exception: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( ... ) catch ( ... )

View File

@ -90,9 +90,9 @@ int main( int /*argc*/, char ** /*argv*/ )
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( std::runtime_error & err ) catch ( std::exception & err )
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::exception: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( ... ) catch ( ... )

View File

@ -54,9 +54,9 @@ int main( int /*argc*/, char ** /*argv*/ )
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( std::runtime_error & err ) catch ( std::exception & err )
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::runtexceptionime_error: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( ... ) catch ( ... )

View File

@ -45,9 +45,9 @@ int main( int /*argc*/, char ** /*argv*/ )
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( std::runtime_error & err ) catch ( std::exception & err )
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::exception: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( ... ) catch ( ... )

View File

@ -155,40 +155,41 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::DescriptorSetLayoutBinding uniformBinding( vk::DescriptorSetLayoutBinding uniformBinding(
0, vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex ); 0, vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex );
vk::UniqueDescriptorSetLayout uniformLayout = device->createDescriptorSetLayoutUnique( vk::UniqueDescriptorSetLayout uniformLayout = device->createDescriptorSetLayoutUnique(
vk::DescriptorSetLayoutCreateInfo( vk::DescriptorSetLayoutCreateFlags(), 1, &uniformBinding ) ); vk::DescriptorSetLayoutCreateInfo( vk::DescriptorSetLayoutCreateFlags(), uniformBinding ) );
// Create second layout containing combined sampler/image data // Create second layout containing combined sampler/image data
vk::DescriptorSetLayoutBinding sampler2DBinding( vk::DescriptorSetLayoutBinding sampler2DBinding(
0, vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eVertex ); 0, vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eVertex );
vk::UniqueDescriptorSetLayout samplerLayout = device->createDescriptorSetLayoutUnique( vk::UniqueDescriptorSetLayout samplerLayout = device->createDescriptorSetLayoutUnique(
vk::DescriptorSetLayoutCreateInfo( vk::DescriptorSetLayoutCreateFlags(), 1, &sampler2DBinding ) ); vk::DescriptorSetLayoutCreateInfo( vk::DescriptorSetLayoutCreateFlags(), sampler2DBinding ) );
// Create pipeline layout with multiple descriptor sets // Create pipeline layout with multiple descriptor sets
std::array<vk::DescriptorSetLayout, 2> descriptorSetLayouts = { { uniformLayout.get(), samplerLayout.get() } }; std::array<vk::DescriptorSetLayout, 2> descriptorSetLayouts = { { uniformLayout.get(), samplerLayout.get() } };
vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique( vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique(
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), 2, descriptorSetLayouts.data() ) ); vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), descriptorSetLayouts ) );
// Create a single pool to contain data for our two descriptor sets // Create a single pool to contain data for our two descriptor sets
vk::DescriptorPoolSize poolSizes[2] = { vk::DescriptorPoolSize( vk::DescriptorType::eUniformBuffer, 1 ), std::array<vk::DescriptorPoolSize, 2> poolSizes = { vk::DescriptorPoolSize( vk::DescriptorType::eUniformBuffer, 1 ),
vk::DescriptorPoolSize( vk::DescriptorType::eCombinedImageSampler, 1 ) }; vk::DescriptorPoolSize(
vk::UniqueDescriptorPool descriptorPool = device->createDescriptorPoolUnique( vk::DescriptorType::eCombinedImageSampler, 1 ) };
vk::DescriptorPoolCreateInfo( vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 2, 2, poolSizes ) ); vk::UniqueDescriptorPool descriptorPool = device->createDescriptorPoolUnique(
vk::DescriptorPoolCreateInfo( vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 2, poolSizes ) );
// Populate descriptor sets // Populate descriptor sets
std::vector<vk::UniqueDescriptorSet> descriptorSets = device->allocateDescriptorSetsUnique( std::vector<vk::UniqueDescriptorSet> descriptorSets = device->allocateDescriptorSetsUnique(
vk::DescriptorSetAllocateInfo( descriptorPool.get(), 2, descriptorSetLayouts.data() ) ); vk::DescriptorSetAllocateInfo( descriptorPool.get(), descriptorSetLayouts ) );
// Populate with info about our uniform buffer // Populate with info about our uniform buffer
vk::DescriptorBufferInfo uniformBufferInfo( uniformBufferData.buffer.get(), 0, sizeof( glm::mat4x4 ) ); vk::DescriptorBufferInfo uniformBufferInfo( uniformBufferData.buffer.get(), 0, sizeof( glm::mat4x4 ) );
vk::DescriptorImageInfo textureImageInfo( textureData.textureSampler.get(), vk::DescriptorImageInfo textureImageInfo( textureData.textureSampler.get(),
textureData.imageData->imageView.get(), textureData.imageData->imageView.get(),
vk::ImageLayout::eShaderReadOnlyOptimal ); vk::ImageLayout::eShaderReadOnlyOptimal );
std::array<vk::WriteDescriptorSet, 2> writeDescriptorSets = { { std::array<vk::WriteDescriptorSet, 2> writeDescriptorSets = {
vk::WriteDescriptorSet( { vk::WriteDescriptorSet(
descriptorSets[0].get(), 0, 0, 1, vk::DescriptorType::eUniformBuffer, nullptr, &uniformBufferInfo ), descriptorSets[0].get(), 0, 0, vk::DescriptorType::eUniformBuffer, {}, uniformBufferInfo ),
vk::WriteDescriptorSet( vk::WriteDescriptorSet(
descriptorSets[1].get(), 0, 0, 1, vk::DescriptorType::eCombinedImageSampler, &textureImageInfo ) descriptorSets[1].get(), 0, 0, vk::DescriptorType::eCombinedImageSampler, textureImageInfo ) }
} }; };
device->updateDescriptorSets( writeDescriptorSets, nullptr ); device->updateDescriptorSets( writeDescriptorSets, nullptr );
/* VULKAN_KEY_END */ /* VULKAN_KEY_END */
@ -213,13 +214,12 @@ int main( int /*argc*/, char ** /*argv*/ )
assert( currentBuffer.result == vk::Result::eSuccess ); assert( currentBuffer.result == vk::Result::eSuccess );
assert( currentBuffer.value < framebuffers.size() ); assert( currentBuffer.value < framebuffers.size() );
vk::ClearValue clearValues[2]; std::array<vk::ClearValue, 2> clearValues;
clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) ); clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) );
clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 ); clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
vk::RenderPassBeginInfo renderPassBeginInfo( renderPass.get(), vk::RenderPassBeginInfo renderPassBeginInfo( renderPass.get(),
framebuffers[currentBuffer.value].get(), framebuffers[currentBuffer.value].get(),
vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ),
2,
clearValues ); clearValues );
commandBuffer->beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline ); commandBuffer->beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
commandBuffer->bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline.get() ); commandBuffer->bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline.get() );
@ -246,14 +246,13 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::UniqueFence drawFence = device->createFenceUnique( vk::FenceCreateInfo() ); vk::UniqueFence drawFence = device->createFenceUnique( vk::FenceCreateInfo() );
vk::PipelineStageFlags waitDestinationStageMask( vk::PipelineStageFlagBits::eColorAttachmentOutput ); vk::PipelineStageFlags waitDestinationStageMask( vk::PipelineStageFlagBits::eColorAttachmentOutput );
vk::SubmitInfo submitInfo( 1, &imageAcquiredSemaphore.get(), &waitDestinationStageMask, 1, &commandBuffer.get() ); vk::SubmitInfo submitInfo( *imageAcquiredSemaphore, waitDestinationStageMask, *commandBuffer );
graphicsQueue.submit( submitInfo, drawFence.get() ); graphicsQueue.submit( submitInfo, drawFence.get() );
while ( vk::Result::eTimeout == device->waitForFences( drawFence.get(), VK_TRUE, vk::su::FenceTimeout ) ) while ( vk::Result::eTimeout == device->waitForFences( drawFence.get(), VK_TRUE, vk::su::FenceTimeout ) )
; ;
presentQueue.presentKHR( presentQueue.presentKHR( vk::PresentInfoKHR( {}, *swapChainData.swapChain, currentBuffer.value ) );
vk::PresentInfoKHR( 0, nullptr, 1, &swapChainData.swapChain.get(), &currentBuffer.value ) );
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) ); std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
device->waitIdle(); device->waitIdle();
@ -263,9 +262,9 @@ int main( int /*argc*/, char ** /*argv*/ )
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( std::runtime_error & err ) catch ( std::exception & err )
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::exception: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( ... ) catch ( ... )

View File

@ -75,7 +75,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::UniqueDescriptorSetLayout descriptorSetLayout = vk::su::createDescriptorSetLayout( vk::UniqueDescriptorSetLayout descriptorSetLayout = vk::su::createDescriptorSetLayout(
device, { { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex } } ); device, { { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex } } );
vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique( vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique(
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), 1, &descriptorSetLayout.get() ) ); vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), *descriptorSetLayout ) );
vk::UniqueRenderPass renderPass = vk::su::createRenderPass( vk::UniqueRenderPass renderPass = vk::su::createRenderPass(
device, device,
@ -102,14 +102,11 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::UniqueDescriptorPool descriptorPool = vk::UniqueDescriptorPool descriptorPool =
vk::su::createDescriptorPool( device, { { vk::DescriptorType::eUniformBuffer, 1 } } ); vk::su::createDescriptorPool( device, { { vk::DescriptorType::eUniformBuffer, 1 } } );
vk::UniqueDescriptorSet descriptorSet = std::move( vk::UniqueDescriptorSet descriptorSet = std::move(
device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, 1, &*descriptorSetLayout ) ) device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, *descriptorSetLayout ) )
.front() ); .front() );
vk::su::updateDescriptorSets( vk::su::updateDescriptorSets(
device, device, descriptorSet, { { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, {} } }, {} );
descriptorSet,
{ { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, {} } },
{} );
vk::UniquePipelineCache pipelineCache = device->createPipelineCacheUnique( vk::PipelineCacheCreateInfo() ); vk::UniquePipelineCache pipelineCache = device->createPipelineCacheUnique( vk::PipelineCacheCreateInfo() );
vk::UniquePipeline graphicsPipeline = vk::su::createGraphicsPipeline( vk::UniquePipeline graphicsPipeline = vk::su::createGraphicsPipeline(
@ -157,13 +154,12 @@ int main( int /*argc*/, char ** /*argv*/ )
commandBuffer->begin( vk::CommandBufferBeginInfo( vk::CommandBufferUsageFlags() ) ); commandBuffer->begin( vk::CommandBufferBeginInfo( vk::CommandBufferUsageFlags() ) );
commandBuffer->resetQueryPool( queryPool.get(), 0, 2 ); commandBuffer->resetQueryPool( queryPool.get(), 0, 2 );
vk::ClearValue clearValues[2]; std::array<vk::ClearValue, 2> clearValues;
clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) ); clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) );
clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 ); clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
commandBuffer->beginRenderPass( vk::RenderPassBeginInfo( renderPass.get(), commandBuffer->beginRenderPass( vk::RenderPassBeginInfo( renderPass.get(),
framebuffers[currentBuffer.value].get(), framebuffers[currentBuffer.value].get(),
vk::Rect2D( vk::Offset2D(), surfaceData.extent ), vk::Rect2D( vk::Offset2D(), surfaceData.extent ),
2,
clearValues ), clearValues ),
vk::SubpassContents::eInline ); vk::SubpassContents::eInline );
@ -201,7 +197,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::UniqueFence drawFence = device->createFenceUnique( vk::FenceCreateInfo() ); vk::UniqueFence drawFence = device->createFenceUnique( vk::FenceCreateInfo() );
vk::PipelineStageFlags waitDestinationStageMask( vk::PipelineStageFlagBits::eColorAttachmentOutput ); vk::PipelineStageFlags waitDestinationStageMask( vk::PipelineStageFlagBits::eColorAttachmentOutput );
vk::SubmitInfo submitInfo( 1, &imageAcquiredSemaphore.get(), &waitDestinationStageMask, 1, &commandBuffer.get() ); vk::SubmitInfo submitInfo( *imageAcquiredSemaphore, waitDestinationStageMask, *commandBuffer );
graphicsQueue.submit( submitInfo, drawFence.get() ); graphicsQueue.submit( submitInfo, drawFence.get() );
graphicsQueue.waitIdle(); graphicsQueue.waitIdle();
@ -231,8 +227,7 @@ int main( int /*argc*/, char ** /*argv*/ )
while ( vk::Result::eTimeout == device->waitForFences( drawFence.get(), VK_TRUE, vk::su::FenceTimeout ) ) while ( vk::Result::eTimeout == device->waitForFences( drawFence.get(), VK_TRUE, vk::su::FenceTimeout ) )
; ;
presentQueue.presentKHR( presentQueue.presentKHR( vk::PresentInfoKHR( {}, *swapChainData.swapChain, currentBuffer.value ) );
vk::PresentInfoKHR( 0, nullptr, 1, &swapChainData.swapChain.get(), &currentBuffer.value ) );
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) ); std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
/* VULKAN_KEY_END */ /* VULKAN_KEY_END */
@ -242,9 +237,9 @@ int main( int /*argc*/, char ** /*argv*/ )
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( std::runtime_error & err ) catch ( std::exception & err )
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::exception: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( ... ) catch ( ... )

View File

@ -64,9 +64,9 @@ int main( int /*argc*/, char ** /*argv*/ )
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( std::runtime_error & err ) catch ( std::exception & err )
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::exception: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( ... ) catch ( ... )

View File

@ -805,9 +805,9 @@ int main( int /*argc*/, char ** /*argv*/ )
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( std::runtime_error & err ) catch ( std::exception & err )
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::exception: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( ... ) catch ( ... )

View File

@ -72,7 +72,7 @@ int main( int /*argc*/, char ** /*argv*/ )
float queuePriority = 0.0f; float queuePriority = 0.0f;
vk::DeviceQueueCreateInfo deviceQueueCreateInfo( vk::DeviceQueueCreateInfo deviceQueueCreateInfo(
vk::DeviceQueueCreateFlags(), static_cast<uint32_t>( graphicsQueueFamilyIndex ), 1, &queuePriority ); vk::DeviceQueueCreateFlags(), static_cast<uint32_t>( graphicsQueueFamilyIndex ), 1, &queuePriority );
vk::DeviceCreateInfo deviceCreateInfo( vk::DeviceCreateFlags(), 1, &deviceQueueCreateInfo ); vk::DeviceCreateInfo deviceCreateInfo( vk::DeviceCreateFlags(), deviceQueueCreateInfo );
vk::DeviceGroupDeviceCreateInfo deviceGroupDeviceCreateInfo( groupProperties[i].physicalDeviceCount, vk::DeviceGroupDeviceCreateInfo deviceGroupDeviceCreateInfo( groupProperties[i].physicalDeviceCount,
groupProperties[i].physicalDevices ); groupProperties[i].physicalDevices );
@ -89,9 +89,9 @@ int main( int /*argc*/, char ** /*argv*/ )
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( std::runtime_error & err ) catch ( std::exception & err )
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::exception: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( ... ) catch ( ... )

View File

@ -101,9 +101,9 @@ int main( int /*argc*/, char ** /*argv*/ )
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( std::runtime_error & err ) catch ( std::exception & err )
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::exception: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( ... ) catch ( ... )

View File

@ -1273,9 +1273,9 @@ int main( int /*argc*/, char ** /*argv*/ )
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( std::runtime_error & err ) catch ( std::exception & err )
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::exception: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( ... ) catch ( ... )

View File

@ -93,9 +93,9 @@ int main( int /*argc*/, char ** /*argv*/ )
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( std::runtime_error & err ) catch ( std::exception & err )
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::exception: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( ... ) catch ( ... )

View File

@ -113,7 +113,7 @@ int main( int /*argc*/, char ** /*argv*/ )
{ { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex }, { { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex },
{ vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment } } ); { vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment } } );
vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique( vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique(
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), 1, &descriptorSetLayout.get() ) ); vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), *descriptorSetLayout ) );
vk::UniqueRenderPass renderPass = vk::su::createRenderPass( vk::UniqueRenderPass renderPass = vk::su::createRenderPass(
device, device,
@ -140,14 +140,11 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::UniqueDescriptorPool descriptorPool = vk::su::createDescriptorPool( vk::UniqueDescriptorPool descriptorPool = vk::su::createDescriptorPool(
device, { { vk::DescriptorType::eUniformBuffer, 1 }, { vk::DescriptorType::eCombinedImageSampler, 1 } } ); device, { { vk::DescriptorType::eUniformBuffer, 1 }, { vk::DescriptorType::eCombinedImageSampler, 1 } } );
vk::UniqueDescriptorSet descriptorSet = std::move( vk::UniqueDescriptorSet descriptorSet = std::move(
device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, 1, &*descriptorSetLayout ) ) device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, *descriptorSetLayout ) )
.front() ); .front() );
vk::su::updateDescriptorSets( vk::su::updateDescriptorSets(
device, device, descriptorSet, { { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, {} } }, textureData );
descriptorSet,
{ { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, {} } },
textureData );
/* VULKAN_KEY_START */ /* VULKAN_KEY_START */
@ -314,14 +311,13 @@ int main( int /*argc*/, char ** /*argv*/ )
assert( currentBuffer.result == vk::Result::eSuccess ); assert( currentBuffer.result == vk::Result::eSuccess );
assert( currentBuffer.value < framebuffers.size() ); assert( currentBuffer.value < framebuffers.size() );
vk::ClearValue clearValues[2]; std::array<vk::ClearValue, 2> clearValues;
clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) ); clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) );
clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 ); clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
commandBuffer->beginRenderPass( vk::RenderPassBeginInfo( renderPass.get(), commandBuffer->beginRenderPass( vk::RenderPassBeginInfo( renderPass.get(),
framebuffers[currentBuffer.value].get(), framebuffers[currentBuffer.value].get(),
vk::Rect2D( vk::Offset2D(), surfaceData.extent ), vk::Rect2D( vk::Offset2D(), surfaceData.extent ),
2,
clearValues ), clearValues ),
vk::SubpassContents::eInline ); vk::SubpassContents::eInline );
commandBuffer->bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline.get() ); commandBuffer->bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline.get() );
@ -345,14 +341,13 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::UniqueFence drawFence = device->createFenceUnique( vk::FenceCreateInfo() ); vk::UniqueFence drawFence = device->createFenceUnique( vk::FenceCreateInfo() );
vk::PipelineStageFlags waitDestinationStageMask( vk::PipelineStageFlagBits::eColorAttachmentOutput ); vk::PipelineStageFlags waitDestinationStageMask( vk::PipelineStageFlagBits::eColorAttachmentOutput );
vk::SubmitInfo submitInfo( 1, &imageAcquiredSemaphore.get(), &waitDestinationStageMask, 1, &commandBuffer.get() ); vk::SubmitInfo submitInfo( *imageAcquiredSemaphore, waitDestinationStageMask, *commandBuffer );
graphicsQueue.submit( submitInfo, drawFence.get() ); graphicsQueue.submit( submitInfo, drawFence.get() );
while ( vk::Result::eTimeout == device->waitForFences( drawFence.get(), VK_TRUE, vk::su::FenceTimeout ) ) while ( vk::Result::eTimeout == device->waitForFences( drawFence.get(), VK_TRUE, vk::su::FenceTimeout ) )
; ;
presentQueue.presentKHR( presentQueue.presentKHR( vk::PresentInfoKHR( {}, *swapChainData.swapChain, currentBuffer.value ) );
vk::PresentInfoKHR( 0, nullptr, 1, &swapChainData.swapChain.get(), &currentBuffer.value ) );
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) ); std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
// Store away the cache that we've populated. This could conceivably happen // Store away the cache that we've populated. This could conceivably happen
@ -381,9 +376,9 @@ int main( int /*argc*/, char ** /*argv*/ )
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( std::runtime_error & err ) catch ( std::exception & err )
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::exception: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( ... ) catch ( ... )

View File

@ -80,7 +80,7 @@ int main( int /*argc*/, char ** /*argv*/ )
{ { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex }, { { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex },
{ vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment } } ); { vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment } } );
vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique( vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique(
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), 1, &descriptorSetLayout.get() ) ); vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), *descriptorSetLayout ) );
vk::UniqueRenderPass renderPass = vk::su::createRenderPass( vk::UniqueRenderPass renderPass = vk::su::createRenderPass(
device, device,
@ -107,14 +107,11 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::UniqueDescriptorPool descriptorPool = vk::su::createDescriptorPool( vk::UniqueDescriptorPool descriptorPool = vk::su::createDescriptorPool(
device, { { vk::DescriptorType::eUniformBuffer, 1 }, { vk::DescriptorType::eCombinedImageSampler, 1 } } ); device, { { vk::DescriptorType::eUniformBuffer, 1 }, { vk::DescriptorType::eCombinedImageSampler, 1 } } );
vk::UniqueDescriptorSet descriptorSet = std::move( vk::UniqueDescriptorSet descriptorSet = std::move(
device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, 1, &*descriptorSetLayout ) ) device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, *descriptorSetLayout ) )
.front() ); .front() );
vk::su::updateDescriptorSets( vk::su::updateDescriptorSets(
device, device, descriptorSet, { { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, {} } }, textureData );
descriptorSet,
{ { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, {} } },
textureData );
vk::UniquePipelineCache pipelineCache = device->createPipelineCacheUnique( vk::PipelineCacheCreateInfo() ); vk::UniquePipelineCache pipelineCache = device->createPipelineCacheUnique( vk::PipelineCacheCreateInfo() );
@ -125,24 +122,20 @@ int main( int /*argc*/, char ** /*argv*/ )
// First pipeline has VK_PIPELINE_CREATE_ALLOW_DERIVATIVES_BIT set. // First pipeline has VK_PIPELINE_CREATE_ALLOW_DERIVATIVES_BIT set.
// Second pipeline has a modified fragment shader and sets the VK_PIPELINE_CREATE_DERIVATIVE_BIT flag. // Second pipeline has a modified fragment shader and sets the VK_PIPELINE_CREATE_DERIVATIVE_BIT flag.
vk::PipelineShaderStageCreateInfo pipelineShaderStageCreateInfos[2] = { std::array<vk::PipelineShaderStageCreateInfo, 2> pipelineShaderStageCreateInfos = {
vk::PipelineShaderStageCreateInfo( vk::PipelineShaderStageCreateInfo(
vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eVertex, vertexShaderModule.get(), "main" ), vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eVertex, vertexShaderModule.get(), "main" ),
vk::PipelineShaderStageCreateInfo( vk::PipelineShaderStageCreateInfo(
vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eFragment, fragmentShaderModule.get(), "main" ) vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eFragment, fragmentShaderModule.get(), "main" )
}; };
vk::VertexInputBindingDescription vertexInputBindingDescription( 0, sizeof( texturedCubeData[0] ) ); vk::VertexInputBindingDescription vertexInputBindingDescription( 0, sizeof( texturedCubeData[0] ) );
vk::VertexInputAttributeDescription vertexInputAttributeDescriptions[2] = { std::array<vk::VertexInputAttributeDescription, 2> vertexInputAttributeDescriptions = {
vk::VertexInputAttributeDescription( 0, 0, vk::Format::eR32G32B32A32Sfloat, 0 ), vk::VertexInputAttributeDescription( 0, 0, vk::Format::eR32G32B32A32Sfloat, 0 ),
vk::VertexInputAttributeDescription( 1, 0, vk::Format::eR32G32B32A32Sfloat, 16 ) vk::VertexInputAttributeDescription( 1, 0, vk::Format::eR32G32B32A32Sfloat, 16 )
}; };
vk::PipelineVertexInputStateCreateInfo pipelineVertexInputStateCreateInfo( vk::PipelineVertexInputStateCreateInfo pipelineVertexInputStateCreateInfo(
vk::PipelineVertexInputStateCreateFlags(), vk::PipelineVertexInputStateCreateFlags(), vertexInputBindingDescription, vertexInputAttributeDescriptions );
1,
&vertexInputBindingDescription,
2,
vertexInputAttributeDescriptions );
vk::PipelineInputAssemblyStateCreateInfo pipelineInputAssemblyStateCreateInfo( vk::PipelineInputAssemblyStateCreateInfo pipelineInputAssemblyStateCreateInfo(
vk::PipelineInputAssemblyStateCreateFlags(), vk::PrimitiveTopology::eTriangleList ); vk::PipelineInputAssemblyStateCreateFlags(), vk::PrimitiveTopology::eTriangleList );
@ -190,16 +183,14 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::PipelineColorBlendStateCreateInfo pipelineColorBlendStateCreateInfo( vk::PipelineColorBlendStateCreateFlags(), vk::PipelineColorBlendStateCreateInfo pipelineColorBlendStateCreateInfo( vk::PipelineColorBlendStateCreateFlags(),
false, false,
vk::LogicOp::eNoOp, vk::LogicOp::eNoOp,
1, pipelineColorBlendAttachmentState,
&pipelineColorBlendAttachmentState,
{ { 1.0f, 1.0f, 1.0f, 1.0f } } ); { { 1.0f, 1.0f, 1.0f, 1.0f } } );
vk::DynamicState dynamicStates[2] = { vk::DynamicState::eViewport, vk::DynamicState::eScissor }; std::array<vk::DynamicState, 2> dynamicStates = { vk::DynamicState::eViewport, vk::DynamicState::eScissor };
vk::PipelineDynamicStateCreateInfo pipelineDynamicStateCreateInfo( vk::PipelineDynamicStateCreateInfo pipelineDynamicStateCreateInfo( vk::PipelineDynamicStateCreateFlags(),
vk::PipelineDynamicStateCreateFlags(), 2, dynamicStates ); dynamicStates );
vk::GraphicsPipelineCreateInfo graphicsPipelineCreateInfo( vk::PipelineCreateFlagBits::eAllowDerivatives, vk::GraphicsPipelineCreateInfo graphicsPipelineCreateInfo( vk::PipelineCreateFlagBits::eAllowDerivatives,
2,
pipelineShaderStageCreateInfos, pipelineShaderStageCreateInfos,
&pipelineVertexInputStateCreateInfo, &pipelineVertexInputStateCreateInfo,
&pipelineInputAssemblyStateCreateInfo, &pipelineInputAssemblyStateCreateInfo,
@ -259,14 +250,13 @@ void main()
assert( currentBuffer.result == vk::Result::eSuccess ); assert( currentBuffer.result == vk::Result::eSuccess );
assert( currentBuffer.value < framebuffers.size() ); assert( currentBuffer.value < framebuffers.size() );
vk::ClearValue clearValues[2]; std::array<vk::ClearValue, 2> clearValues;
clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) ); clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) );
clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 ); clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
commandBuffer->beginRenderPass( vk::RenderPassBeginInfo( renderPass.get(), commandBuffer->beginRenderPass( vk::RenderPassBeginInfo( renderPass.get(),
framebuffers[currentBuffer.value].get(), framebuffers[currentBuffer.value].get(),
vk::Rect2D( vk::Offset2D(), surfaceData.extent ), vk::Rect2D( vk::Offset2D(), surfaceData.extent ),
2,
clearValues ), clearValues ),
vk::SubpassContents::eInline ); vk::SubpassContents::eInline );
commandBuffer->bindPipeline( vk::PipelineBindPoint::eGraphics, derivedPipeline.get() ); commandBuffer->bindPipeline( vk::PipelineBindPoint::eGraphics, derivedPipeline.get() );
@ -290,14 +280,13 @@ void main()
vk::UniqueFence drawFence = device->createFenceUnique( vk::FenceCreateInfo() ); vk::UniqueFence drawFence = device->createFenceUnique( vk::FenceCreateInfo() );
vk::PipelineStageFlags waitDestinationStageMask( vk::PipelineStageFlagBits::eColorAttachmentOutput ); vk::PipelineStageFlags waitDestinationStageMask( vk::PipelineStageFlagBits::eColorAttachmentOutput );
vk::SubmitInfo submitInfo( 1, &imageAcquiredSemaphore.get(), &waitDestinationStageMask, 1, &commandBuffer.get() ); vk::SubmitInfo submitInfo( *imageAcquiredSemaphore, waitDestinationStageMask, *commandBuffer );
graphicsQueue.submit( submitInfo, drawFence.get() ); graphicsQueue.submit( submitInfo, drawFence.get() );
while ( vk::Result::eTimeout == device->waitForFences( drawFence.get(), VK_TRUE, vk::su::FenceTimeout ) ) while ( vk::Result::eTimeout == device->waitForFences( drawFence.get(), VK_TRUE, vk::su::FenceTimeout ) )
; ;
presentQueue.presentKHR( presentQueue.presentKHR( vk::PresentInfoKHR( {}, *swapChainData.swapChain, currentBuffer.value ) );
vk::PresentInfoKHR( 0, nullptr, 1, &swapChainData.swapChain.get(), &currentBuffer.value ) );
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) ); std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
} }
catch ( vk::SystemError & err ) catch ( vk::SystemError & err )
@ -305,9 +294,9 @@ void main()
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( std::runtime_error & err ) catch ( std::exception & err )
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::exception: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( ... ) catch ( ... )

View File

@ -144,24 +144,25 @@ int main( int /*argc*/, char ** /*argv*/ )
// Set up our push constant range, which mirrors the declaration of // Set up our push constant range, which mirrors the declaration of
vk::PushConstantRange pushConstantRanges( vk::ShaderStageFlagBits::eFragment, 0, 8 ); vk::PushConstantRange pushConstantRanges( vk::ShaderStageFlagBits::eFragment, 0, 8 );
vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique( vk::PipelineLayoutCreateInfo( vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique(
vk::PipelineLayoutCreateFlags(), 1, &descriptorSetLayout.get(), 1, &pushConstantRanges ) ); vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), *descriptorSetLayout, pushConstantRanges ) );
// Create a single pool to contain data for our descriptor set // Create a single pool to contain data for our descriptor set
vk::DescriptorPoolSize poolSizes[2] = { vk::DescriptorPoolSize( vk::DescriptorType::eUniformBuffer, 1 ), std::array<vk::DescriptorPoolSize, 2> poolSizes = { vk::DescriptorPoolSize( vk::DescriptorType::eUniformBuffer, 1 ),
vk::DescriptorPoolSize( vk::DescriptorType::eCombinedImageSampler, 1 ) }; vk::DescriptorPoolSize(
vk::UniqueDescriptorPool descriptorPool = device->createDescriptorPoolUnique( vk::DescriptorType::eCombinedImageSampler, 1 ) };
vk::DescriptorPoolCreateInfo( vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 1, 2, poolSizes ) ); vk::UniqueDescriptorPool descriptorPool = device->createDescriptorPoolUnique(
vk::DescriptorPoolCreateInfo( vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 1, poolSizes ) );
// Populate descriptor sets // Populate descriptor sets
vk::UniqueDescriptorSet descriptorSet = std::move( vk::UniqueDescriptorSet descriptorSet = std::move(
device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, 1, &*descriptorSetLayout ) ) device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, *descriptorSetLayout ) )
.front() ); .front() );
// Populate with info about our uniform buffer for MVP // Populate with info about our uniform buffer for MVP
vk::DescriptorBufferInfo bufferInfo( uniformBufferData.buffer.get(), 0, sizeof( glm::mat4x4 ) ); vk::DescriptorBufferInfo bufferInfo( uniformBufferData.buffer.get(), 0, sizeof( glm::mat4x4 ) );
device->updateDescriptorSets( device->updateDescriptorSets(
vk::WriteDescriptorSet( *descriptorSet, 0, 0, 1, vk::DescriptorType::eUniformBuffer, nullptr, &bufferInfo ), {} ); vk::WriteDescriptorSet( *descriptorSet, 0, 0, vk::DescriptorType::eUniformBuffer, {}, bufferInfo ), {} );
// Create our push constant data, which matches shader expectations // Create our push constant data, which matches shader expectations
std::array<unsigned, 2> pushConstants = { { (unsigned)2, (unsigned)0x3F800000 } }; std::array<unsigned, 2> pushConstants = { { (unsigned)2, (unsigned)0x3F800000 } };
@ -194,14 +195,13 @@ int main( int /*argc*/, char ** /*argv*/ )
assert( currentBuffer.result == vk::Result::eSuccess ); assert( currentBuffer.result == vk::Result::eSuccess );
assert( currentBuffer.value < framebuffers.size() ); assert( currentBuffer.value < framebuffers.size() );
vk::ClearValue clearValues[2]; std::array<vk::ClearValue, 2> clearValues;
clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) ); clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) );
clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 ); clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
vk::RenderPassBeginInfo renderPassBeginInfo( renderPass.get(), vk::RenderPassBeginInfo renderPassBeginInfo( renderPass.get(),
framebuffers[currentBuffer.value].get(), framebuffers[currentBuffer.value].get(),
vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ),
2,
clearValues ); clearValues );
commandBuffer->beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline ); commandBuffer->beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
commandBuffer->bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline.get() ); commandBuffer->bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline.get() );
@ -225,14 +225,13 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::UniqueFence drawFence = device->createFenceUnique( vk::FenceCreateInfo() ); vk::UniqueFence drawFence = device->createFenceUnique( vk::FenceCreateInfo() );
vk::PipelineStageFlags waitDestinationStageMask( vk::PipelineStageFlagBits::eColorAttachmentOutput ); vk::PipelineStageFlags waitDestinationStageMask( vk::PipelineStageFlagBits::eColorAttachmentOutput );
vk::SubmitInfo submitInfo( 1, &imageAcquiredSemaphore.get(), &waitDestinationStageMask, 1, &commandBuffer.get() ); vk::SubmitInfo submitInfo( *imageAcquiredSemaphore, waitDestinationStageMask, *commandBuffer );
graphicsQueue.submit( submitInfo, drawFence.get() ); graphicsQueue.submit( submitInfo, drawFence.get() );
while ( vk::Result::eTimeout == device->waitForFences( drawFence.get(), VK_TRUE, vk::su::FenceTimeout ) ) while ( vk::Result::eTimeout == device->waitForFences( drawFence.get(), VK_TRUE, vk::su::FenceTimeout ) )
; ;
presentQueue.presentKHR( presentQueue.presentKHR( vk::PresentInfoKHR( {}, *swapChainData.swapChain, currentBuffer.value ) );
vk::PresentInfoKHR( 0, nullptr, 1, &swapChainData.swapChain.get(), &currentBuffer.value ) );
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) ); std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
} }
catch ( vk::SystemError & err ) catch ( vk::SystemError & err )
@ -240,9 +239,9 @@ int main( int /*argc*/, char ** /*argv*/ )
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( std::runtime_error & err ) catch ( std::exception & err )
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::exception: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( ... ) catch ( ... )

View File

@ -119,7 +119,7 @@ int main( int /*argc*/, char ** /*argv*/ )
{ vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment } }, { vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment } },
vk::DescriptorSetLayoutCreateFlagBits::ePushDescriptorKHR ); vk::DescriptorSetLayoutCreateFlagBits::ePushDescriptorKHR );
vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique( vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique(
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), 1, &descriptorSetLayout.get() ) ); vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), *descriptorSetLayout ) );
vk::UniqueRenderPass renderPass = vk::su::createRenderPass( vk::UniqueRenderPass renderPass = vk::su::createRenderPass(
device, device,
@ -163,13 +163,12 @@ int main( int /*argc*/, char ** /*argv*/ )
assert( currentBuffer.result == vk::Result::eSuccess ); assert( currentBuffer.result == vk::Result::eSuccess );
assert( currentBuffer.value < framebuffers.size() ); assert( currentBuffer.value < framebuffers.size() );
vk::ClearValue clearValues[2]; std::array<vk::ClearValue, 2> clearValues;
clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) ); clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) );
clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 ); clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
vk::RenderPassBeginInfo renderPassBeginInfo( renderPass.get(), vk::RenderPassBeginInfo renderPassBeginInfo( renderPass.get(),
framebuffers[currentBuffer.value].get(), framebuffers[currentBuffer.value].get(),
vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ),
2,
clearValues ); clearValues );
commandBuffer->beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline ); commandBuffer->beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
commandBuffer->bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline.get() ); commandBuffer->bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline.get() );
@ -179,8 +178,8 @@ int main( int /*argc*/, char ** /*argv*/ )
textureData.imageData->imageView.get(), textureData.imageData->imageView.get(),
vk::ImageLayout::eShaderReadOnlyOptimal ); vk::ImageLayout::eShaderReadOnlyOptimal );
vk::WriteDescriptorSet writeDescriptorSets[2] = { vk::WriteDescriptorSet writeDescriptorSets[2] = {
vk::WriteDescriptorSet( {}, 0, 0, 1, vk::DescriptorType::eUniformBuffer, nullptr, &bufferInfo ), vk::WriteDescriptorSet( {}, 0, 0, vk::DescriptorType::eUniformBuffer, {}, bufferInfo ),
vk::WriteDescriptorSet( {}, 1, 0, 1, vk::DescriptorType::eCombinedImageSampler, &imageInfo ) vk::WriteDescriptorSet( {}, 1, 0, vk::DescriptorType::eCombinedImageSampler, imageInfo )
}; };
// this call is from an extension and needs the dynamic dispatcher !! // this call is from an extension and needs the dynamic dispatcher !!
@ -204,14 +203,13 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::UniqueFence drawFence = device->createFenceUnique( vk::FenceCreateInfo() ); vk::UniqueFence drawFence = device->createFenceUnique( vk::FenceCreateInfo() );
vk::PipelineStageFlags waitDestinationStageMask( vk::PipelineStageFlagBits::eColorAttachmentOutput ); vk::PipelineStageFlags waitDestinationStageMask( vk::PipelineStageFlagBits::eColorAttachmentOutput );
vk::SubmitInfo submitInfo( 1, &imageAcquiredSemaphore.get(), &waitDestinationStageMask, 1, &commandBuffer.get() ); vk::SubmitInfo submitInfo( *imageAcquiredSemaphore, waitDestinationStageMask, *commandBuffer );
graphicsQueue.submit( submitInfo, drawFence.get() ); graphicsQueue.submit( submitInfo, drawFence.get() );
while ( vk::Result::eTimeout == device->waitForFences( drawFence.get(), VK_TRUE, vk::su::FenceTimeout ) ) while ( vk::Result::eTimeout == device->waitForFences( drawFence.get(), VK_TRUE, vk::su::FenceTimeout ) )
; ;
presentQueue.presentKHR( presentQueue.presentKHR( vk::PresentInfoKHR( {}, *swapChainData.swapChain, currentBuffer.value ) );
vk::PresentInfoKHR( 0, nullptr, 1, &swapChainData.swapChain.get(), &currentBuffer.value ) );
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) ); std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
/* VULKAN_KEY_END */ /* VULKAN_KEY_END */
@ -223,9 +221,9 @@ int main( int /*argc*/, char ** /*argv*/ )
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( std::runtime_error & err ) catch ( std::exception & err )
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::exception: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( ... ) catch ( ... )

View File

@ -15,8 +15,11 @@
// VulkanHpp Samples : RayTracing // VulkanHpp Samples : RayTracing
// Simple sample how to ray trace using Vulkan // Simple sample how to ray trace using Vulkan
// clang-format off
// we need to include vulkan.hpp before glfw3.h, so stop clang-format to reorder them
#include <vulkan/vulkan.hpp> #include <vulkan/vulkan.hpp>
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
// clang-format on
#include <numeric> #include <numeric>
#include <random> #include <random>
#include <sstream> #include <sstream>
@ -46,11 +49,11 @@ struct GeometryInstanceData
uint32_t instanceOffset_, uint32_t instanceOffset_,
uint8_t flags_, uint8_t flags_,
uint64_t accelerationStructureHandle_ ) uint64_t accelerationStructureHandle_ )
: instanceId( instanceID_ ), : instanceId( instanceID_ )
mask( mask_ ), , mask( mask_ )
instanceOffset( instanceOffset_ ), , instanceOffset( instanceOffset_ )
flags( flags_ ), , flags( flags_ )
accelerationStructureHandle( accelerationStructureHandle_ ) , accelerationStructureHandle( accelerationStructureHandle_ )
{ {
assert( !( instanceID_ & 0xFF000000 ) && !( instanceOffset_ & 0xFF000000 ) ); assert( !( instanceID_ & 0xFF000000 ) && !( instanceOffset_ & 0xFF000000 ) );
memcpy( transform, &transform_, 12 * sizeof( float ) ); memcpy( transform, &transform_, 12 * sizeof( float ) );
@ -86,11 +89,8 @@ AccelerationStructureData
vk::AccelerationStructureTypeNV accelerationStructureType = vk::AccelerationStructureTypeNV accelerationStructureType =
instances.empty() ? vk::AccelerationStructureTypeNV::eBottomLevel : vk::AccelerationStructureTypeNV::eTopLevel; instances.empty() ? vk::AccelerationStructureTypeNV::eBottomLevel : vk::AccelerationStructureTypeNV::eTopLevel;
vk::AccelerationStructureInfoNV accelerationStructureInfo( accelerationStructureType, vk::AccelerationStructureInfoNV accelerationStructureInfo(
{}, accelerationStructureType, {}, vk::su::checked_cast<uint32_t>( instances.size() ), geometries );
vk::su::checked_cast<uint32_t>( instances.size() ),
vk::su::checked_cast<uint32_t>( geometries.size() ),
geometries.data() );
accelerationStructureData.acclerationStructure = device->createAccelerationStructureNVUnique( accelerationStructureData.acclerationStructure = device->createAccelerationStructureNVUnique(
vk::AccelerationStructureCreateInfoNV( 0, accelerationStructureInfo ) ); vk::AccelerationStructureCreateInfoNV( 0, accelerationStructureInfo ) );
@ -157,11 +157,8 @@ AccelerationStructureData
*accelerationStructureData.acclerationStructure, *accelerationStructureData.resultBufferData->deviceMemory ) ); *accelerationStructureData.acclerationStructure, *accelerationStructureData.resultBufferData->deviceMemory ) );
commandBuffer->buildAccelerationStructureNV( commandBuffer->buildAccelerationStructureNV(
vk::AccelerationStructureInfoNV( accelerationStructureType, vk::AccelerationStructureInfoNV(
{}, accelerationStructureType, {}, vk::su::checked_cast<uint32_t>( instances.size() ), geometries ),
vk::su::checked_cast<uint32_t>( instances.size() ),
vk::su::checked_cast<uint32_t>( geometries.size() ),
geometries.data() ),
accelerationStructureData.instanceBufferData ? *accelerationStructureData.instanceBufferData->buffer : nullptr, accelerationStructureData.instanceBufferData ? *accelerationStructureData.instanceBufferData->buffer : nullptr,
0, 0,
false, false,
@ -871,7 +868,7 @@ int main( int /*argc*/, char ** /*argv*/ )
static_cast<uint32_t>( textures.size() ), static_cast<uint32_t>( textures.size() ),
vk::ShaderStageFlagBits::eFragment } } ); vk::ShaderStageFlagBits::eFragment } } );
vk::UniquePipelineLayout pipelineLayout = vk::UniquePipelineLayout pipelineLayout =
device->createPipelineLayoutUnique( vk::PipelineLayoutCreateInfo( {}, 1, &( *descriptorSetLayout ) ) ); device->createPipelineLayoutUnique( vk::PipelineLayoutCreateInfo( {}, *descriptorSetLayout ) );
glslang::InitializeProcess(); glslang::InitializeProcess();
vk::UniqueShaderModule vertexShaderModule = vk::UniqueShaderModule vertexShaderModule =
@ -899,14 +896,13 @@ int main( int /*argc*/, char ** /*argv*/ )
physicalDevice, device, sizeof( UniformBufferObject ), vk::BufferUsageFlagBits::eUniformBuffer ); physicalDevice, device, sizeof( UniformBufferObject ), vk::BufferUsageFlagBits::eUniformBuffer );
vk::UniqueDescriptorSet descriptorSet = std::move( vk::UniqueDescriptorSet descriptorSet = std::move(
device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, 1, &*descriptorSetLayout ) ) device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, *descriptorSetLayout ) )
.front() ); .front() );
vk::su::updateDescriptorSets( vk::su::updateDescriptorSets( device,
device, descriptorSet,
descriptorSet, { { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, {} },
{ { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, {} }, { vk::DescriptorType::eStorageBuffer, materialBufferData.buffer, {} } },
{ vk::DescriptorType::eStorageBuffer, materialBufferData.buffer, {} } }, textures );
textures );
// RayTracing specific stuff // RayTracing specific stuff
@ -996,18 +992,16 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::DescriptorPoolCreateInfo descriptorPoolCreateInfo( vk::DescriptorPoolCreateInfo descriptorPoolCreateInfo(
vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet,
vk::su::checked_cast<uint32_t>( swapChainData.images.size() ), vk::su::checked_cast<uint32_t>( swapChainData.images.size() ),
vk::su::checked_cast<uint32_t>( descriptorPoolSizes.size() ), descriptorPoolSizes );
descriptorPoolSizes.data() );
vk::UniqueDescriptorPool rayTracingDescriptorPool = device->createDescriptorPoolUnique( descriptorPoolCreateInfo ); vk::UniqueDescriptorPool rayTracingDescriptorPool = device->createDescriptorPoolUnique( descriptorPoolCreateInfo );
vk::UniqueDescriptorSetLayout rayTracingDescriptorSetLayout = device->createDescriptorSetLayoutUnique( vk::UniqueDescriptorSetLayout rayTracingDescriptorSetLayout =
vk::DescriptorSetLayoutCreateInfo( {}, static_cast<uint32_t>( bindings.size() ), bindings.data() ) ); device->createDescriptorSetLayoutUnique( vk::DescriptorSetLayoutCreateInfo( {}, bindings ) );
std::vector<vk::DescriptorSetLayout> layouts; std::vector<vk::DescriptorSetLayout> layouts;
for ( size_t i = 0; i < swapChainData.images.size(); i++ ) for ( size_t i = 0; i < swapChainData.images.size(); i++ )
{ {
layouts.push_back( *rayTracingDescriptorSetLayout ); layouts.push_back( *rayTracingDescriptorSetLayout );
} }
vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo( vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo( *rayTracingDescriptorPool, layouts );
*rayTracingDescriptorPool, vk::su::checked_cast<uint32_t>( layouts.size() ), layouts.data() );
std::vector<vk::UniqueDescriptorSet> rayTracingDescriptorSets = std::vector<vk::UniqueDescriptorSet> rayTracingDescriptorSets =
device->allocateDescriptorSetsUnique( descriptorSetAllocateInfo ); device->allocateDescriptorSetsUnique( descriptorSetAllocateInfo );
@ -1027,15 +1021,14 @@ int main( int /*argc*/, char ** /*argv*/ )
// view) // view)
for ( size_t i = 0; i < rayTracingDescriptorSets.size(); i++ ) for ( size_t i = 0; i < rayTracingDescriptorSets.size(); i++ )
{ {
vk::su::updateDescriptorSets( vk::su::updateDescriptorSets( device,
device, rayTracingDescriptorSets[i],
rayTracingDescriptorSets[i], { { bindings[2].descriptorType, uniformBufferData.buffer, {} },
{ { bindings[2].descriptorType, uniformBufferData.buffer, {} }, { bindings[3].descriptorType, vertexBufferData.buffer, {} },
{ bindings[3].descriptorType, vertexBufferData.buffer, {} }, { bindings[4].descriptorType, indexBufferData.buffer, {} },
{ bindings[4].descriptorType, indexBufferData.buffer, {} }, { bindings[5].descriptorType, materialBufferData.buffer, {} } },
{ bindings[5].descriptorType, materialBufferData.buffer, {} } }, textures,
textures, 2 );
2 );
} }
// create the ray-tracing shader modules // create the ray-tracing shader modules
@ -1094,7 +1087,7 @@ int main( int /*argc*/, char ** /*argv*/ )
// Create the layout of the pipeline following the provided descriptor set layout // Create the layout of the pipeline following the provided descriptor set layout
vk::UniquePipelineLayout rayTracingPipelineLayout = vk::UniquePipelineLayout rayTracingPipelineLayout =
device->createPipelineLayoutUnique( vk::PipelineLayoutCreateInfo( {}, 1, &*rayTracingDescriptorSetLayout ) ); device->createPipelineLayoutUnique( vk::PipelineLayoutCreateInfo( {}, *rayTracingDescriptorSetLayout ) );
// Assemble the shader stages and recursion depth info into the raytracing pipeline // Assemble the shader stages and recursion depth info into the raytracing pipeline
// The ray tracing process can shoot rays from the camera, and a shadow ray can be shot from the // The ray tracing process can shoot rays from the camera, and a shadow ray can be shot from the
@ -1102,14 +1095,9 @@ int main( int /*argc*/, char ** /*argv*/ )
// as possible for performance reasons. Even recursive ray tracing should be flattened into a loop // as possible for performance reasons. Even recursive ray tracing should be flattened into a loop
// in the ray generation to avoid deep recursion. // in the ray generation to avoid deep recursion.
uint32_t maxRecursionDepth = 2; uint32_t maxRecursionDepth = 2;
vk::RayTracingPipelineCreateInfoNV rayTracingPipelineCreateInfo( {}, vk::RayTracingPipelineCreateInfoNV rayTracingPipelineCreateInfo(
static_cast<uint32_t>( shaderStages.size() ), {}, shaderStages, shaderGroups, maxRecursionDepth, *rayTracingPipelineLayout );
shaderStages.data(), vk::UniquePipeline rayTracingPipeline =
static_cast<uint32_t>( shaderGroups.size() ),
shaderGroups.data(),
maxRecursionDepth,
*rayTracingPipelineLayout );
vk::UniquePipeline rayTracingPipeline =
device->createRayTracingPipelineNVUnique( nullptr, rayTracingPipelineCreateInfo ); device->createRayTracingPipelineNVUnique( nullptr, rayTracingPipelineCreateInfo );
uint32_t shaderGroupHandleSize = uint32_t shaderGroupHandleSize =
@ -1208,8 +1196,7 @@ int main( int /*argc*/, char ** /*argv*/ )
commandBuffer->beginRenderPass( vk::RenderPassBeginInfo( *renderPass, commandBuffer->beginRenderPass( vk::RenderPassBeginInfo( *renderPass,
*framebuffers[backBufferIndex], *framebuffers[backBufferIndex],
vk::Rect2D( vk::Offset2D( 0, 0 ), windowExtent ), vk::Rect2D( vk::Offset2D( 0, 0 ), windowExtent ),
static_cast<uint32_t>( clearValues.size() ), clearValues ),
clearValues.data() ),
vk::SubpassContents::eInline ); vk::SubpassContents::eInline );
commandBuffer->bindPipeline( vk::PipelineBindPoint::eGraphics, *graphicsPipeline ); commandBuffer->bindPipeline( vk::PipelineBindPoint::eGraphics, *graphicsPipeline );
@ -1237,7 +1224,7 @@ int main( int /*argc*/, char ** /*argv*/ )
nullptr, *swapChainData.imageViews[backBufferIndex], vk::ImageLayout::eGeneral ); nullptr, *swapChainData.imageViews[backBufferIndex], vk::ImageLayout::eGeneral );
device->updateDescriptorSets( device->updateDescriptorSets(
vk::WriteDescriptorSet( vk::WriteDescriptorSet(
*rayTracingDescriptorSets[backBufferIndex], 1, 0, 1, bindings[1].descriptorType, &imageInfo ), *rayTracingDescriptorSets[backBufferIndex], 1, 0, bindings[1].descriptorType, imageInfo ),
{} ); {} );
vk::su::setImageLayout( commandBuffer, vk::su::setImageLayout( commandBuffer,
@ -1293,11 +1280,8 @@ int main( int /*argc*/, char ** /*argv*/ )
1, 1,
&( *perFrameData[frameIndex].renderCompleteSemaphore ) ), &( *perFrameData[frameIndex].renderCompleteSemaphore ) ),
*perFrameData[frameIndex].fence ); *perFrameData[frameIndex].fence );
presentQueue.presentKHR( vk::PresentInfoKHR( 1, presentQueue.presentKHR( vk::PresentInfoKHR(
&( *perFrameData[frameIndex].renderCompleteSemaphore ), *perFrameData[frameIndex].renderCompleteSemaphore, *swapChainData.swapChain, backBufferIndex ) );
1,
&( *swapChainData.swapChain ),
&backBufferIndex ) );
frameIndex = ( frameIndex + 1 ) % IMGUI_VK_QUEUED_FRAMES; frameIndex = ( frameIndex + 1 ) % IMGUI_VK_QUEUED_FRAMES;
double endTime = glfwGetTime(); double endTime = glfwGetTime();
@ -1330,9 +1314,9 @@ int main( int /*argc*/, char ** /*argv*/ )
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( std::runtime_error & err ) catch ( std::exception & err )
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::exception: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( ... ) catch ( ... )

View File

@ -77,7 +77,7 @@ int main( int /*argc*/, char ** /*argv*/ )
{ { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex }, { { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex },
{ vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment } } ); { vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment } } );
vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique( vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique(
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), 1, &descriptorSetLayout.get() ) ); vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), *descriptorSetLayout ) );
vk::UniqueRenderPass renderPass = vk::su::createRenderPass( vk::UniqueRenderPass renderPass = vk::su::createRenderPass(
device, device,
@ -129,21 +129,19 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::UniqueDescriptorPool descriptorPool = vk::su::createDescriptorPool( vk::UniqueDescriptorPool descriptorPool = vk::su::createDescriptorPool(
device, { { vk::DescriptorType::eUniformBuffer, 2 }, { vk::DescriptorType::eCombinedImageSampler, 2 } } ); device, { { vk::DescriptorType::eUniformBuffer, 2 }, { vk::DescriptorType::eCombinedImageSampler, 2 } } );
vk::DescriptorSetLayout layouts[] = { descriptorSetLayout.get(), descriptorSetLayout.get() }; std::array<vk::DescriptorSetLayout, 2> layouts = { descriptorSetLayout.get(), descriptorSetLayout.get() };
std::vector<vk::UniqueDescriptorSet> descriptorSets = std::vector<vk::UniqueDescriptorSet> descriptorSets =
device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( descriptorPool.get(), 2, layouts ) ); device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( descriptorPool.get(), layouts ) );
assert( descriptorSets.size() == 2 ); assert( descriptorSets.size() == 2 );
vk::su::updateDescriptorSets( vk::su::updateDescriptorSets( device,
device, descriptorSets[0],
descriptorSets[0], { { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, {} } },
{ { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, {} } }, greenTextureData );
greenTextureData ); vk::su::updateDescriptorSets( device,
vk::su::updateDescriptorSets( descriptorSets[1],
device, { { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, {} } },
descriptorSets[1], checkeredTextureData );
{ { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, {} } },
checkeredTextureData );
/* VULKAN_KEY_START */ /* VULKAN_KEY_START */
@ -191,14 +189,13 @@ int main( int /*argc*/, char ** /*argv*/ )
secondaryCommandBuffers[i]->end(); secondaryCommandBuffers[i]->end();
} }
vk::ClearValue clearValues[2]; std::array<vk::ClearValue, 2> clearValues;
clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) ); clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) );
clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 ); clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
vk::RenderPassBeginInfo renderPassBeginInfo( renderPass.get(), vk::RenderPassBeginInfo renderPassBeginInfo( renderPass.get(),
framebuffers[currentBuffer.value].get(), framebuffers[currentBuffer.value].get(),
vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ),
2,
clearValues ); clearValues );
// specifying VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS means this render pass may ONLY call // specifying VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS means this render pass may ONLY call
// vkCmdExecuteCommands // vkCmdExecuteCommands
@ -226,14 +223,13 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::UniqueFence drawFence = device->createFenceUnique( vk::FenceCreateInfo() ); vk::UniqueFence drawFence = device->createFenceUnique( vk::FenceCreateInfo() );
vk::PipelineStageFlags waitDestinationStageMask( vk::PipelineStageFlagBits::eColorAttachmentOutput ); vk::PipelineStageFlags waitDestinationStageMask( vk::PipelineStageFlagBits::eColorAttachmentOutput );
vk::SubmitInfo submitInfo( 1, &imageAcquiredSemaphore.get(), &waitDestinationStageMask, 1, &commandBuffer.get() ); vk::SubmitInfo submitInfo( *imageAcquiredSemaphore, waitDestinationStageMask, *commandBuffer );
graphicsQueue.submit( submitInfo, drawFence.get() ); graphicsQueue.submit( submitInfo, drawFence.get() );
while ( vk::Result::eTimeout == device->waitForFences( drawFence.get(), VK_TRUE, vk::su::FenceTimeout ) ) while ( vk::Result::eTimeout == device->waitForFences( drawFence.get(), VK_TRUE, vk::su::FenceTimeout ) )
; ;
presentQueue.presentKHR( presentQueue.presentKHR( vk::PresentInfoKHR( {}, *swapChainData.swapChain, currentBuffer.value ) );
vk::PresentInfoKHR( 0, nullptr, 1, &swapChainData.swapChain.get(), &currentBuffer.value ) );
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) ); std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
/* VULKAN_KEY_END */ /* VULKAN_KEY_END */
@ -245,9 +241,9 @@ int main( int /*argc*/, char ** /*argv*/ )
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( std::runtime_error & err ) catch ( std::exception & err )
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::exception: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( ... ) catch ( ... )

View File

@ -154,34 +154,30 @@ int main( int /*argc*/, char ** /*argv*/ )
// binding 0 = uniform buffer (MVP) // binding 0 = uniform buffer (MVP)
// binding 1 = texture2D // binding 1 = texture2D
// binding 2 = sampler // binding 2 = sampler
std::array<vk::DescriptorSetLayoutBinding, 3> resourceBindings = { { std::array<vk::DescriptorSetLayoutBinding, 3> resourceBindings = {
vk::DescriptorSetLayoutBinding( 0, vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex ), { vk::DescriptorSetLayoutBinding( 0, vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex ),
vk::DescriptorSetLayoutBinding( 1, vk::DescriptorType::eSampledImage, 1, vk::ShaderStageFlagBits::eFragment ), vk::DescriptorSetLayoutBinding( 1, vk::DescriptorType::eSampledImage, 1, vk::ShaderStageFlagBits::eFragment ),
vk::DescriptorSetLayoutBinding( 2, vk::DescriptorType::eSampler, 1, vk::ShaderStageFlagBits::eFragment ) vk::DescriptorSetLayoutBinding( 2, vk::DescriptorType::eSampler, 1, vk::ShaderStageFlagBits::eFragment ) }
}
}; };
vk::UniqueDescriptorSetLayout descriptorSetLayout = device->createDescriptorSetLayoutUnique( vk::UniqueDescriptorSetLayout descriptorSetLayout = device->createDescriptorSetLayoutUnique(
vk::DescriptorSetLayoutCreateInfo( vk::DescriptorSetLayoutCreateFlags(), vk::DescriptorSetLayoutCreateInfo( vk::DescriptorSetLayoutCreateFlags(), resourceBindings ) );
static_cast<uint32_t>( resourceBindings.size() ),
resourceBindings.data() ) );
// Create pipeline layout // Create pipeline layout
vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique( vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique(
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), 1, &( *descriptorSetLayout ) ) ); vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), *descriptorSetLayout ) );
// Create a single pool to contain data for the descriptor set // Create a single pool to contain data for the descriptor set
std::array<vk::DescriptorPoolSize, 3> poolSizes = { { vk::DescriptorPoolSize( vk::DescriptorType::eUniformBuffer, 1 ), std::array<vk::DescriptorPoolSize, 3> poolSizes = {
vk::DescriptorPoolSize( vk::DescriptorType::eSampledImage, 1 ), { vk::DescriptorPoolSize( vk::DescriptorType::eUniformBuffer, 1 ),
vk::DescriptorPoolSize( vk::DescriptorType::eSampler, 1 ) } }; vk::DescriptorPoolSize( vk::DescriptorType::eSampledImage, 1 ),
vk::UniqueDescriptorPool descriptorPool = device->createDescriptorPoolUnique( vk::DescriptorPoolSize( vk::DescriptorType::eSampler, 1 ) }
vk::DescriptorPoolCreateInfo( vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, };
1, vk::UniqueDescriptorPool descriptorPool = device->createDescriptorPoolUnique(
static_cast<uint32_t>( poolSizes.size() ), vk::DescriptorPoolCreateInfo( vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 1, poolSizes ) );
poolSizes.data() ) );
// Populate descriptor sets // Populate descriptor sets
vk::UniqueDescriptorSet descriptorSet = std::move( vk::UniqueDescriptorSet descriptorSet = std::move(
device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, 1, &*descriptorSetLayout ) ) device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, *descriptorSetLayout ) )
.front() ); .front() );
vk::DescriptorBufferInfo bufferInfo( uniformBufferData.buffer.get(), 0, sizeof( glm::mat4x4 ) ); vk::DescriptorBufferInfo bufferInfo( uniformBufferData.buffer.get(), 0, sizeof( glm::mat4x4 ) );
@ -189,11 +185,11 @@ int main( int /*argc*/, char ** /*argv*/ )
textureData.imageData->imageView.get(), textureData.imageData->imageView.get(),
vk::ImageLayout::eShaderReadOnlyOptimal ); vk::ImageLayout::eShaderReadOnlyOptimal );
vk::DescriptorImageInfo samplerInfo( sampler.get(), {}, {} ); vk::DescriptorImageInfo samplerInfo( sampler.get(), {}, {} );
std::array<vk::WriteDescriptorSet, 3> descriptorWrites = { { std::array<vk::WriteDescriptorSet, 3> descriptorWrites = {
vk::WriteDescriptorSet( *descriptorSet, 0, 0, 1, vk::DescriptorType::eUniformBuffer, nullptr, &bufferInfo ), { vk::WriteDescriptorSet( *descriptorSet, 0, 0, vk::DescriptorType::eUniformBuffer, {}, bufferInfo ),
vk::WriteDescriptorSet( *descriptorSet, 1, 0, 1, vk::DescriptorType::eSampledImage, &imageInfo ), vk::WriteDescriptorSet( *descriptorSet, 1, 0, vk::DescriptorType::eSampledImage, imageInfo ),
vk::WriteDescriptorSet( *descriptorSet, 2, 0, 1, vk::DescriptorType::eSampler, &samplerInfo ) vk::WriteDescriptorSet( *descriptorSet, 2, 0, vk::DescriptorType::eSampler, samplerInfo ) }
} }; };
device->updateDescriptorSets( descriptorWrites, nullptr ); device->updateDescriptorSets( descriptorWrites, nullptr );
/* VULKAN_KEY_END */ /* VULKAN_KEY_END */
@ -219,14 +215,13 @@ int main( int /*argc*/, char ** /*argv*/ )
assert( currentBuffer.result == vk::Result::eSuccess ); assert( currentBuffer.result == vk::Result::eSuccess );
assert( currentBuffer.value < framebuffers.size() ); assert( currentBuffer.value < framebuffers.size() );
vk::ClearValue clearValues[2]; std::array<vk::ClearValue, 2> clearValues;
clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) ); clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) );
clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 ); clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
vk::RenderPassBeginInfo renderPassBeginInfo( renderPass.get(), vk::RenderPassBeginInfo renderPassBeginInfo( renderPass.get(),
framebuffers[currentBuffer.value].get(), framebuffers[currentBuffer.value].get(),
vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ),
2,
clearValues ); clearValues );
commandBuffer->beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline ); commandBuffer->beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
@ -251,14 +246,13 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::UniqueFence drawFence = device->createFenceUnique( vk::FenceCreateInfo() ); vk::UniqueFence drawFence = device->createFenceUnique( vk::FenceCreateInfo() );
vk::PipelineStageFlags waitDestinationStageMask( vk::PipelineStageFlagBits::eColorAttachmentOutput ); vk::PipelineStageFlags waitDestinationStageMask( vk::PipelineStageFlagBits::eColorAttachmentOutput );
vk::SubmitInfo submitInfo( 1, &imageAcquiredSemaphore.get(), &waitDestinationStageMask, 1, &commandBuffer.get() ); vk::SubmitInfo submitInfo( *imageAcquiredSemaphore, waitDestinationStageMask, *commandBuffer );
graphicsQueue.submit( submitInfo, drawFence.get() ); graphicsQueue.submit( submitInfo, drawFence.get() );
while ( vk::Result::eTimeout == device->waitForFences( drawFence.get(), VK_TRUE, vk::su::FenceTimeout ) ) while ( vk::Result::eTimeout == device->waitForFences( drawFence.get(), VK_TRUE, vk::su::FenceTimeout ) )
; ;
presentQueue.presentKHR( presentQueue.presentKHR( vk::PresentInfoKHR( {}, *swapChainData.swapChain, currentBuffer.value ) );
vk::PresentInfoKHR( 0, nullptr, 1, &swapChainData.swapChain.get(), &currentBuffer.value ) );
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) ); std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
device->waitIdle(); device->waitIdle();
@ -268,9 +262,9 @@ int main( int /*argc*/, char ** /*argv*/ )
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( std::runtime_error & err ) catch ( std::exception & err )
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::exception: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( ... ) catch ( ... )

View File

@ -173,9 +173,9 @@ int main( int /*argc*/, char ** /*argv*/ )
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( std::runtime_error & err ) catch ( std::exception & err )
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::exception: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( ... ) catch ( ... )

View File

@ -65,9 +65,9 @@ int main( int /*argc*/, char ** /*argv*/ )
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( std::runtime_error & err ) catch ( std::exception & err )
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::exception: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( ... ) catch ( ... )

View File

@ -82,7 +82,7 @@ int main( int /*argc*/, char ** /*argv*/ )
{ { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex }, { { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex },
{ vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment } } ); { vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment } } );
vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique( vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique(
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), 1, &descriptorSetLayout.get() ) ); vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), *descriptorSetLayout ) );
vk::UniqueRenderPass renderPass = vk::su::createRenderPass( vk::UniqueRenderPass renderPass = vk::su::createRenderPass(
device, device,
@ -109,13 +109,10 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::UniqueDescriptorPool descriptorPool = vk::su::createDescriptorPool( vk::UniqueDescriptorPool descriptorPool = vk::su::createDescriptorPool(
device, { { vk::DescriptorType::eUniformBuffer, 1 }, { vk::DescriptorType::eCombinedImageSampler, 1 } } ); device, { { vk::DescriptorType::eUniformBuffer, 1 }, { vk::DescriptorType::eCombinedImageSampler, 1 } } );
vk::UniqueDescriptorSet descriptorSet = std::move( vk::UniqueDescriptorSet descriptorSet = std::move(
device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, 1, &*descriptorSetLayout ) ) device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, *descriptorSetLayout ) )
.front() ); .front() );
vk::su::updateDescriptorSets( vk::su::updateDescriptorSets(
device, device, descriptorSet, { { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, {} } }, textureData );
descriptorSet,
{ { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, {} } },
textureData );
vk::UniquePipelineCache pipelineCache = device->createPipelineCacheUnique( vk::PipelineCacheCreateInfo() ); vk::UniquePipelineCache pipelineCache = device->createPipelineCacheUnique( vk::PipelineCacheCreateInfo() );
vk::UniquePipeline graphicsPipeline = vk::UniquePipeline graphicsPipeline =
@ -137,13 +134,12 @@ int main( int /*argc*/, char ** /*argv*/ )
assert( currentBuffer.result == vk::Result::eSuccess ); assert( currentBuffer.result == vk::Result::eSuccess );
assert( currentBuffer.value < framebuffers.size() ); assert( currentBuffer.value < framebuffers.size() );
vk::ClearValue clearValues[2]; std::array<vk::ClearValue, 2> clearValues;
clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) ); clearValues[0].color = vk::ClearColorValue( std::array<float, 4>( { { 0.2f, 0.2f, 0.2f, 0.2f } } ) );
clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 ); clearValues[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
vk::RenderPassBeginInfo renderPassBeginInfo( renderPass.get(), vk::RenderPassBeginInfo renderPassBeginInfo( renderPass.get(),
framebuffers[currentBuffer.value].get(), framebuffers[currentBuffer.value].get(),
vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ),
2,
clearValues ); clearValues );
commandBuffer->beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline ); commandBuffer->beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
@ -168,14 +164,13 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::UniqueFence drawFence = device->createFenceUnique( vk::FenceCreateInfo() ); vk::UniqueFence drawFence = device->createFenceUnique( vk::FenceCreateInfo() );
vk::PipelineStageFlags waitDestinationStageMask( vk::PipelineStageFlagBits::eColorAttachmentOutput ); vk::PipelineStageFlags waitDestinationStageMask( vk::PipelineStageFlagBits::eColorAttachmentOutput );
vk::SubmitInfo submitInfo( 1, &imageAcquiredSemaphore.get(), &waitDestinationStageMask, 1, &commandBuffer.get() ); vk::SubmitInfo submitInfo( *imageAcquiredSemaphore, waitDestinationStageMask, *commandBuffer );
graphicsQueue.submit( submitInfo, drawFence.get() ); graphicsQueue.submit( submitInfo, drawFence.get() );
while ( vk::Result::eTimeout == device->waitForFences( drawFence.get(), VK_TRUE, vk::su::FenceTimeout ) ) while ( vk::Result::eTimeout == device->waitForFences( drawFence.get(), VK_TRUE, vk::su::FenceTimeout ) )
; ;
presentQueue.presentKHR( presentQueue.presentKHR( vk::PresentInfoKHR( {}, *swapChainData.swapChain, currentBuffer.value ) );
vk::PresentInfoKHR( 0, nullptr, 1, &swapChainData.swapChain.get(), &currentBuffer.value ) );
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) ); std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
device->waitIdle(); device->waitIdle();
@ -185,9 +180,9 @@ int main( int /*argc*/, char ** /*argv*/ )
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( std::runtime_error & err ) catch ( std::exception & err )
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::exception: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( ... ) catch ( ... )

View File

@ -117,7 +117,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::UniqueDescriptorSetLayout descriptorSetLayout = vk::su::createDescriptorSetLayout( vk::UniqueDescriptorSetLayout descriptorSetLayout = vk::su::createDescriptorSetLayout(
device, { { vk::DescriptorType::eUniformTexelBuffer, 1, vk::ShaderStageFlagBits::eVertex } } ); device, { { vk::DescriptorType::eUniformTexelBuffer, 1, vk::ShaderStageFlagBits::eVertex } } );
vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique( vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique(
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), 1, &descriptorSetLayout.get() ) ); vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), *descriptorSetLayout ) );
vk::UniqueRenderPass renderPass = vk::su::createRenderPass( vk::UniqueRenderPass renderPass = vk::su::createRenderPass(
device, device,
@ -137,7 +137,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::UniqueDescriptorPool descriptorPool = vk::UniqueDescriptorPool descriptorPool =
vk::su::createDescriptorPool( device, { { vk::DescriptorType::eUniformTexelBuffer, 1 } } ); vk::su::createDescriptorPool( device, { { vk::DescriptorType::eUniformTexelBuffer, 1 } } );
vk::UniqueDescriptorSet descriptorSet = std::move( vk::UniqueDescriptorSet descriptorSet = std::move(
device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, 1, &*descriptorSetLayout ) ) device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, *descriptorSetLayout ) )
.front() ); .front() );
vk::su::updateDescriptorSets( vk::su::updateDescriptorSets(
device, device,
@ -174,8 +174,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::RenderPassBeginInfo renderPassBeginInfo( renderPass.get(), vk::RenderPassBeginInfo renderPassBeginInfo( renderPass.get(),
framebuffers[currentBuffer.value].get(), framebuffers[currentBuffer.value].get(),
vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ), vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ),
1, clearValue );
&clearValue );
commandBuffer->beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline ); commandBuffer->beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
commandBuffer->bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline.get() ); commandBuffer->bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline.get() );
@ -198,14 +197,13 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::UniqueFence drawFence = device->createFenceUnique( vk::FenceCreateInfo() ); vk::UniqueFence drawFence = device->createFenceUnique( vk::FenceCreateInfo() );
vk::PipelineStageFlags waitDestinationStageMask( vk::PipelineStageFlagBits::eColorAttachmentOutput ); vk::PipelineStageFlags waitDestinationStageMask( vk::PipelineStageFlagBits::eColorAttachmentOutput );
vk::SubmitInfo submitInfo( 1, &imageAcquiredSemaphore.get(), &waitDestinationStageMask, 1, &commandBuffer.get() ); vk::SubmitInfo submitInfo( *imageAcquiredSemaphore, waitDestinationStageMask, *commandBuffer );
graphicsQueue.submit( submitInfo, drawFence.get() ); graphicsQueue.submit( submitInfo, drawFence.get() );
while ( vk::Result::eTimeout == device->waitForFences( drawFence.get(), VK_TRUE, vk::su::FenceTimeout ) ) while ( vk::Result::eTimeout == device->waitForFences( drawFence.get(), VK_TRUE, vk::su::FenceTimeout ) )
; ;
presentQueue.presentKHR( presentQueue.presentKHR( vk::PresentInfoKHR( {}, *swapChainData.swapChain, currentBuffer.value ) );
vk::PresentInfoKHR( 0, nullptr, 1, &swapChainData.swapChain.get(), &currentBuffer.value ) );
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) ); std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
/* VULKAN_KEY_END */ /* VULKAN_KEY_END */
@ -217,9 +215,9 @@ int main( int /*argc*/, char ** /*argv*/ )
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( std::runtime_error & err ) catch ( std::exception & err )
{ {
std::cout << "std::runtime_error: " << err.what() << std::endl; std::cout << "std::exception: " << err.what() << std::endl;
exit( -1 ); exit( -1 );
} }
catch ( ... ) catch ( ... )

View File

@ -94,8 +94,7 @@ namespace vk
bool ok = GLSLtoSPV( shaderStage, shaderText, shaderSPV ); bool ok = GLSLtoSPV( shaderStage, shaderText, shaderSPV );
assert( ok ); assert( ok );
return device->createShaderModuleUnique( vk::ShaderModuleCreateInfo( return device->createShaderModuleUnique( vk::ShaderModuleCreateInfo( vk::ShaderModuleCreateFlags(), shaderSPV ) );
vk::ShaderModuleCreateFlags(), shaderSPV.size() * sizeof( unsigned int ), shaderSPV.data() ) );
} }
} // namespace su } // namespace su
} // namespace vk } // namespace vk

View File

@ -76,10 +76,8 @@ namespace vk
} ); } );
assert( 0 < maxSets ); assert( 0 < maxSets );
vk::DescriptorPoolCreateInfo descriptorPoolCreateInfo( vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, vk::DescriptorPoolCreateInfo descriptorPoolCreateInfo(
maxSets, vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, maxSets, poolSizes );
checked_cast<uint32_t>( poolSizes.size() ),
poolSizes.data() );
return device->createDescriptorPoolUnique( descriptorPoolCreateInfo ); return device->createDescriptorPoolUnique( descriptorPoolCreateInfo );
} }
@ -96,8 +94,7 @@ namespace vk
std::get<1>( bindingData[i] ), std::get<1>( bindingData[i] ),
std::get<2>( bindingData[i] ) ); std::get<2>( bindingData[i] ) );
} }
return device->createDescriptorSetLayoutUnique( return device->createDescriptorSetLayoutUnique( vk::DescriptorSetLayoutCreateInfo( flags, bindings ) );
vk::DescriptorSetLayoutCreateInfo( flags, checked_cast<uint32_t>( bindings.size() ), bindings.data() ) );
} }
vk::UniqueDevice createDevice( vk::PhysicalDevice physicalDevice, vk::UniqueDevice createDevice( vk::PhysicalDevice physicalDevice,
@ -117,14 +114,8 @@ namespace vk
float queuePriority = 0.0f; float queuePriority = 0.0f;
vk::DeviceQueueCreateInfo deviceQueueCreateInfo( vk::DeviceQueueCreateInfo deviceQueueCreateInfo(
vk::DeviceQueueCreateFlags(), queueFamilyIndex, 1, &queuePriority ); vk::DeviceQueueCreateFlags(), queueFamilyIndex, 1, &queuePriority );
vk::DeviceCreateInfo deviceCreateInfo( vk::DeviceCreateFlags(), vk::DeviceCreateInfo deviceCreateInfo(
1, vk::DeviceCreateFlags(), deviceQueueCreateInfo, {}, enabledExtensions, physicalDeviceFeatures );
&deviceQueueCreateInfo,
0,
nullptr,
checked_cast<uint32_t>( enabledExtensions.size() ),
enabledExtensions.data(),
physicalDeviceFeatures );
deviceCreateInfo.pNext = pNext; deviceCreateInfo.pNext = pNext;
return physicalDevice.createDeviceUnique( deviceCreateInfo ); return physicalDevice.createDeviceUnique( deviceCreateInfo );
} }
@ -168,7 +159,7 @@ namespace vk
vk::UniquePipelineLayout const & pipelineLayout, vk::UniquePipelineLayout const & pipelineLayout,
vk::UniqueRenderPass const & renderPass ) vk::UniqueRenderPass const & renderPass )
{ {
vk::PipelineShaderStageCreateInfo pipelineShaderStageCreateInfos[2] = { std::array<vk::PipelineShaderStageCreateInfo, 2> pipelineShaderStageCreateInfos = {
vk::PipelineShaderStageCreateInfo( vk::PipelineShaderStageCreateFlags(), vk::PipelineShaderStageCreateInfo( vk::PipelineShaderStageCreateFlags(),
vk::ShaderStageFlagBits::eVertex, vk::ShaderStageFlagBits::eVertex,
vertexShaderData.first, vertexShaderData.first,
@ -193,11 +184,8 @@ namespace vk
vertexInputAttributeDescriptions.push_back( vk::VertexInputAttributeDescription( vertexInputAttributeDescriptions.push_back( vk::VertexInputAttributeDescription(
i, 0, vertexInputAttributeFormatOffset[i].first, vertexInputAttributeFormatOffset[i].second ) ); i, 0, vertexInputAttributeFormatOffset[i].first, vertexInputAttributeFormatOffset[i].second ) );
} }
pipelineVertexInputStateCreateInfo.vertexBindingDescriptionCount = 1; pipelineVertexInputStateCreateInfo.setVertexBindingDescriptions( vertexInputBindingDescription );
pipelineVertexInputStateCreateInfo.pVertexBindingDescriptions = &vertexInputBindingDescription; pipelineVertexInputStateCreateInfo.setVertexAttributeDescriptions( vertexInputAttributeDescriptions );
pipelineVertexInputStateCreateInfo.vertexAttributeDescriptionCount =
vk::su::checked_cast<uint32_t>( vertexInputAttributeDescriptions.size() );
pipelineVertexInputStateCreateInfo.pVertexAttributeDescriptions = vertexInputAttributeDescriptions.data();
} }
vk::PipelineInputAssemblyStateCreateInfo pipelineInputAssemblyStateCreateInfo( vk::PipelineInputAssemblyStateCreateInfo pipelineInputAssemblyStateCreateInfo(
@ -246,16 +234,14 @@ namespace vk
vk::PipelineColorBlendStateCreateInfo pipelineColorBlendStateCreateInfo( vk::PipelineColorBlendStateCreateFlags(), vk::PipelineColorBlendStateCreateInfo pipelineColorBlendStateCreateInfo( vk::PipelineColorBlendStateCreateFlags(),
false, false,
vk::LogicOp::eNoOp, vk::LogicOp::eNoOp,
1, pipelineColorBlendAttachmentState,
&pipelineColorBlendAttachmentState,
{ { 1.0f, 1.0f, 1.0f, 1.0f } } ); { { 1.0f, 1.0f, 1.0f, 1.0f } } );
vk::DynamicState dynamicStates[2] = { vk::DynamicState::eViewport, vk::DynamicState::eScissor }; std::array<vk::DynamicState, 2> dynamicStates = { vk::DynamicState::eViewport, vk::DynamicState::eScissor };
vk::PipelineDynamicStateCreateInfo pipelineDynamicStateCreateInfo( vk::PipelineDynamicStateCreateInfo pipelineDynamicStateCreateInfo( vk::PipelineDynamicStateCreateFlags(),
vk::PipelineDynamicStateCreateFlags(), 2, dynamicStates ); dynamicStates );
vk::GraphicsPipelineCreateInfo graphicsPipelineCreateInfo( vk::PipelineCreateFlags(), vk::GraphicsPipelineCreateInfo graphicsPipelineCreateInfo( vk::PipelineCreateFlags(),
2,
pipelineShaderStageCreateInfos, pipelineShaderStageCreateInfos,
&pipelineVertexInputStateCreateInfo, &pipelineVertexInputStateCreateInfo,
&pipelineInputAssemblyStateCreateInfo, &pipelineInputAssemblyStateCreateInfo,
@ -346,12 +332,7 @@ namespace vk
#if defined( NDEBUG ) #if defined( NDEBUG )
// in non-debug mode just use the InstanceCreateInfo for instance creation // in non-debug mode just use the InstanceCreateInfo for instance creation
vk::StructureChain<vk::InstanceCreateInfo> instanceCreateInfo( vk::StructureChain<vk::InstanceCreateInfo> instanceCreateInfo(
{ {}, { {}, &applicationInfo, enabledLayers, enabledExtensions } );
&applicationInfo,
checked_cast<uint32_t>( enabledLayers.size() ),
enabledLayers.data(),
checked_cast<uint32_t>( enabledExtensions.size() ),
enabledExtensions.data() } );
#else #else
// in debug mode, addionally use the debugUtilsMessengerCallback in instance creation! // in debug mode, addionally use the debugUtilsMessengerCallback in instance creation!
vk::DebugUtilsMessageSeverityFlagsEXT severityFlags( vk::DebugUtilsMessageSeverityFlagBitsEXT::eWarning | vk::DebugUtilsMessageSeverityFlagsEXT severityFlags( vk::DebugUtilsMessageSeverityFlagBitsEXT::eWarning |
@ -360,12 +341,7 @@ namespace vk
vk::DebugUtilsMessageTypeFlagBitsEXT::ePerformance | vk::DebugUtilsMessageTypeFlagBitsEXT::ePerformance |
vk::DebugUtilsMessageTypeFlagBitsEXT::eValidation ); vk::DebugUtilsMessageTypeFlagBitsEXT::eValidation );
vk::StructureChain<vk::InstanceCreateInfo, vk::DebugUtilsMessengerCreateInfoEXT> instanceCreateInfo( vk::StructureChain<vk::InstanceCreateInfo, vk::DebugUtilsMessengerCreateInfoEXT> instanceCreateInfo(
{ {}, { {}, &applicationInfo, enabledLayers, enabledExtensions },
&applicationInfo,
checked_cast<uint32_t>( enabledLayers.size() ),
enabledLayers.data(),
checked_cast<uint32_t>( enabledExtensions.size() ),
enabledExtensions.data() },
{ {}, severityFlags, messageTypeFlags, &vk::su::debugUtilsMessengerCallback } ); { {}, severityFlags, messageTypeFlags, &vk::su::debugUtilsMessengerCallback } );
#endif #endif
vk::UniqueInstance instance = vk::createInstanceUnique( instanceCreateInfo.get<vk::InstanceCreateInfo>() ); vk::UniqueInstance instance = vk::createInstanceUnique( instanceCreateInfo.get<vk::InstanceCreateInfo>() );
@ -412,19 +388,13 @@ namespace vk
vk::AttachmentReference depthAttachment( 1, vk::ImageLayout::eDepthStencilAttachmentOptimal ); vk::AttachmentReference depthAttachment( 1, vk::ImageLayout::eDepthStencilAttachmentOptimal );
vk::SubpassDescription subpassDescription( vk::SubpassDescriptionFlags(), vk::SubpassDescription subpassDescription( vk::SubpassDescriptionFlags(),
vk::PipelineBindPoint::eGraphics, vk::PipelineBindPoint::eGraphics,
0, {},
nullptr, colorAttachment,
1, {},
&colorAttachment,
nullptr,
( depthFormat != vk::Format::eUndefined ) ? &depthAttachment ( depthFormat != vk::Format::eUndefined ) ? &depthAttachment
: nullptr ); : nullptr );
return device->createRenderPassUnique( return device->createRenderPassUnique(
vk::RenderPassCreateInfo( vk::RenderPassCreateFlags(), vk::RenderPassCreateInfo( vk::RenderPassCreateFlags(), attachmentDescriptions, subpassDescription ) );
static_cast<uint32_t>( attachmentDescriptions.size() ),
attachmentDescriptions.data(),
1,
&subpassDescription ) );
} }
VKAPI_ATTR VkBool32 VKAPI_CALL VKAPI_ATTR VkBool32 VKAPI_CALL
@ -753,8 +723,7 @@ namespace vk
void submitAndWait( vk::UniqueDevice & device, vk::Queue queue, vk::UniqueCommandBuffer & commandBuffer ) void submitAndWait( vk::UniqueDevice & device, vk::Queue queue, vk::UniqueCommandBuffer & commandBuffer )
{ {
vk::UniqueFence fence = device->createFenceUnique( vk::FenceCreateInfo() ); vk::UniqueFence fence = device->createFenceUnique( vk::FenceCreateInfo() );
vk::PipelineStageFlags pipelineStageFlags = vk::PipelineStageFlagBits::eColorAttachmentOutput; queue.submit( vk::SubmitInfo( {}, {}, *commandBuffer ), fence.get() );
queue.submit( vk::SubmitInfo( 0, nullptr, &pipelineStageFlags, 1, &commandBuffer.get() ), fence.get() );
while ( vk::Result::eTimeout == device->waitForFences( fence.get(), VK_TRUE, vk::su::FenceTimeout ) ) while ( vk::Result::eTimeout == device->waitForFences( fence.get(), VK_TRUE, vk::su::FenceTimeout ) )
; ;
} }
@ -789,7 +758,7 @@ namespace vk
vk::DescriptorImageInfo imageInfo( vk::DescriptorImageInfo imageInfo(
*textureData.textureSampler, *textureData.imageData->imageView, vk::ImageLayout::eShaderReadOnlyOptimal ); *textureData.textureSampler, *textureData.imageData->imageView, vk::ImageLayout::eShaderReadOnlyOptimal );
writeDescriptorSets.push_back( vk::WriteDescriptorSet( writeDescriptorSets.push_back( vk::WriteDescriptorSet(
*descriptorSet, dstBinding, 0, 1, vk::DescriptorType::eCombinedImageSampler, &imageInfo, nullptr, nullptr ) ); *descriptorSet, dstBinding, 0, vk::DescriptorType::eCombinedImageSampler, imageInfo, {}, nullptr ) );
device->updateDescriptorSets( writeDescriptorSets, nullptr ); device->updateDescriptorSets( writeDescriptorSets, nullptr );
} }
@ -896,8 +865,7 @@ namespace vk
tiling, tiling,
usage | vk::ImageUsageFlagBits::eSampled, usage | vk::ImageUsageFlagBits::eSampled,
vk::SharingMode::eExclusive, vk::SharingMode::eExclusive,
0, {},
nullptr,
initialLayout ); initialLayout );
image = device->createImageUnique( imageCreateInfo ); image = device->createImageUnique( imageCreateInfo );
@ -981,8 +949,7 @@ namespace vk
1, 1,
usage, usage,
vk::SharingMode::eExclusive, vk::SharingMode::eExclusive,
0, {},
nullptr,
preTransform, preTransform,
compositeAlpha, compositeAlpha,
presentMode, presentMode,

View File

@ -47,7 +47,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::DeviceQueueCreateInfo deviceQueueCreateInfo( vk::DeviceQueueCreateInfo deviceQueueCreateInfo(
vk::DeviceQueueCreateFlags(), static_cast<uint32_t>( graphicsQueueFamilyIndex ), 1, &queuePriority ); vk::DeviceQueueCreateFlags(), static_cast<uint32_t>( graphicsQueueFamilyIndex ), 1, &queuePriority );
vk::UniqueDevice device = vk::UniqueDevice device =
physicalDevice.createDeviceUnique( vk::DeviceCreateInfo( vk::DeviceCreateFlags(), 1, &deviceQueueCreateInfo ) ); physicalDevice.createDeviceUnique( vk::DeviceCreateInfo( vk::DeviceCreateFlags(), deviceQueueCreateInfo ) );
std::vector<uint8_t> data; std::vector<uint8_t> data;
device->getAccelerationStructureHandleNV<uint8_t>( {}, data, vk::DispatchLoaderDynamic() ); device->getAccelerationStructureHandleNV<uint8_t>( {}, data, vk::DispatchLoaderDynamic() );

View File

@ -60,7 +60,7 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::DeviceQueueCreateFlags(), static_cast<uint32_t>( graphicsQueueFamilyIndex ), 1, &queuePriority ); vk::DeviceQueueCreateFlags(), static_cast<uint32_t>( graphicsQueueFamilyIndex ), 1, &queuePriority );
vk::UniqueDevice device = vk::UniqueDevice device =
physicalDevices[0] physicalDevices[0]
.createDeviceUnique( vk::DeviceCreateInfo( vk::DeviceCreateFlags(), 1, &deviceQueueCreateInfo ) ) .createDeviceUnique( vk::DeviceCreateInfo( vk::DeviceCreateFlags(), deviceQueueCreateInfo ) )
.value; .value;
VULKAN_HPP_DEFAULT_DISPATCHER.init( *device ); VULKAN_HPP_DEFAULT_DISPATCHER.init( *device );

File diff suppressed because it is too large Load Diff