mirror of
https://github.com/KhronosGroup/Vulkan-Hpp
synced 2024-11-08 13:40:08 +00:00
Introduce structure constructors using ArrayProxyNoTemporaries
This commit is contained in:
parent
d9a88324d8
commit
d86303c0e4
@ -90,6 +90,11 @@ std::string trimEnd( std::string const & input );
|
||||
std::string trimStars( std::string const & input );
|
||||
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" };
|
||||
|
||||
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,
|
||||
std::pair<std::string, StructureData> const & structData,
|
||||
std::string const & prefix ) const
|
||||
@ -3605,7 +3625,7 @@ ${prefix}}
|
||||
for ( auto const & member : structData.second.members )
|
||||
{
|
||||
// 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
|
||||
if ( ( member.name != "pNext" ) && ( member.name != "sType" ) )
|
||||
@ -3621,16 +3641,117 @@ ${prefix}}
|
||||
{ "initializers", initializers },
|
||||
{ "prefix", prefix },
|
||||
{ "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 listedArgument,
|
||||
MemberData const & memberData ) const
|
||||
MemberData const & memberData,
|
||||
bool withDefault ) const
|
||||
{
|
||||
// skip members 'pNext' and 'sType', as they are never explicitly set
|
||||
if ( ( memberData.name != "pNext" ) && ( memberData.name != "sType" ) )
|
||||
{
|
||||
str += ( listedArgument ? ( "," ) : "" );
|
||||
str += ( listedArgument ? ( ", " ) : "" );
|
||||
if ( memberData.arraySizes.empty() )
|
||||
{
|
||||
str += memberData.type.compose() + " ";
|
||||
@ -3639,18 +3760,23 @@ bool VulkanHppGenerator::appendStructConstructorArgument( std::string & str
|
||||
{
|
||||
str += constructStandardArray( memberData.type.compose(), memberData.arraySizes ) + " const& ";
|
||||
}
|
||||
str += memberData.name + "_ = ";
|
||||
str += memberData.name + "_";
|
||||
|
||||
auto enumIt = m_enums.find( memberData.type.type );
|
||||
if ( enumIt != m_enums.end() && memberData.type.postfix.empty() )
|
||||
if ( withDefault )
|
||||
{
|
||||
appendEnumInitializer( str, memberData.type, memberData.arraySizes, enumIt->second.values );
|
||||
}
|
||||
else
|
||||
{
|
||||
// all the rest can be initialized with just {}
|
||||
str += "{}";
|
||||
str += " = ";
|
||||
auto enumIt = m_enums.find( memberData.type.type );
|
||||
if ( enumIt != m_enums.end() && memberData.type.postfix.empty() )
|
||||
{
|
||||
appendEnumInitializer( str, memberData.type, memberData.arraySizes, enumIt->second.values );
|
||||
}
|
||||
else
|
||||
{
|
||||
// all the rest can be initialized with just {}
|
||||
str += "{}";
|
||||
}
|
||||
}
|
||||
|
||||
listedArgument = true;
|
||||
}
|
||||
return listedArgument;
|
||||
@ -3785,10 +3911,6 @@ void VulkanHppGenerator::appendStructSetter( std::string & str
|
||||
: "" },
|
||||
{ "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() ) )
|
||||
{
|
||||
assert( member.name.front() == 'p' );
|
||||
@ -3878,7 +4000,8 @@ void VulkanHppGenerator::appendStructSubConstructor( std::string &
|
||||
bool listedArgument = true;
|
||||
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() );
|
||||
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 ) ||
|
||||
( 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
|
||||
// if there is nothing like that)
|
||||
// add this parameter as a vector parameter, using the len-name parameter as the second value (or
|
||||
// INVALID_INDEX if there is nothing like that)
|
||||
vectorParamIndices.insert(
|
||||
std::make_pair( std::distance( params.begin(), it ),
|
||||
( findIt < it ) ? std::distance( params.begin(), findIt ) : INVALID_INDEX ) );
|
||||
@ -4745,6 +4868,56 @@ std::string const & VulkanHppGenerator::getVulkanLicenseHeader() const
|
||||
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>
|
||||
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> platforms;
|
||||
@ -6489,9 +6735,8 @@ void VulkanHppGenerator::readStructMember( tinyxml2::XMLElement const * element,
|
||||
std::string const & len = memberData.len[0];
|
||||
auto lenMember =
|
||||
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])" ) ||
|
||||
( len == R"(latexmath:[\lceil{\mathit{rasterizationSamples} \over 32}\rceil])" ) ||
|
||||
( len == "2*VK_UUID_SIZE" ) || ( len == "2*ename:VK_UUID_SIZE" ) || ( lenMember != members.end() ),
|
||||
check( ( lenMember != members.end() ) || ( ignoreLens.find( len ) != ignoreLens.end() ) ||
|
||||
( len == R"(latexmath:[\textrm{codeSize} \over 4])" ),
|
||||
line,
|
||||
"member attribute <len> holds unknown value <" + len + ">" );
|
||||
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] + ">" );
|
||||
}
|
||||
}
|
||||
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" )
|
||||
{
|
||||
check( isUnion, line, "attribute <selection> is used with a non-union structure." );
|
||||
|
@ -194,6 +194,8 @@ private:
|
||||
std::vector<std::string> arraySizes;
|
||||
std::string bitCount;
|
||||
std::vector<std::string> len;
|
||||
bool noAutoValidity = false;
|
||||
bool optional = false;
|
||||
std::string selection;
|
||||
std::string selector;
|
||||
std::string values;
|
||||
@ -478,7 +480,13 @@ private:
|
||||
void appendStructConstructors( 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 ) 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::pair<std::string, StructureData> const & structData,
|
||||
std::string const & prefix ) const;
|
||||
@ -508,15 +516,22 @@ private:
|
||||
std::string determineSubStruct( std::pair<std::string, StructureData> const & structure ) const;
|
||||
size_t determineTemplateParamIndex( std::vector<ParamData> const & params,
|
||||
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::set<std::string> const & extension ) 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;
|
||||
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;
|
||||
std::string generateSizeCheck( std::vector<std::vector<MemberData>::const_iterator> const & arrayIts,
|
||||
std::string const & structName,
|
||||
std::string const & prefix ) const;
|
||||
std::set<std::string> getPlatforms( std::set<std::string> const & extensions ) 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 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 );
|
||||
|
@ -45,6 +45,11 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
std::cout << "vk::SystemError: " << err.what() << std::endl;
|
||||
exit( -1 );
|
||||
}
|
||||
catch ( std::exception & err )
|
||||
{
|
||||
std::cout << "std::exception: " << err.what() << std::endl;
|
||||
exit( -1 );
|
||||
}
|
||||
catch ( ... )
|
||||
{
|
||||
std::cout << "unknown error\n";
|
||||
|
@ -47,6 +47,11 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
std::cout << "vk::SystemError: " << err.what() << std::endl;
|
||||
exit( -1 );
|
||||
}
|
||||
catch ( std::exception & err )
|
||||
{
|
||||
std::cout << "std::exception: " << err.what() << std::endl;
|
||||
exit( -1 );
|
||||
}
|
||||
catch ( ... )
|
||||
{
|
||||
std::cout << "unknown error\n";
|
||||
|
@ -53,7 +53,7 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
vk::DeviceQueueCreateInfo deviceQueueCreateInfo(
|
||||
vk::DeviceQueueCreateFlags(), static_cast<uint32_t>( graphicsQueueFamilyIndex ), 1, &queuePriority );
|
||||
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
|
||||
// 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;
|
||||
exit( -1 );
|
||||
}
|
||||
catch ( std::exception & err )
|
||||
{
|
||||
std::cout << "std::exception: " << err.what() << std::endl;
|
||||
exit( -1 );
|
||||
}
|
||||
catch ( ... )
|
||||
{
|
||||
std::cout << "unknown error\n";
|
||||
|
@ -61,6 +61,11 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
std::cout << "vk::SystemError: " << err.what() << std::endl;
|
||||
exit( -1 );
|
||||
}
|
||||
catch ( std::exception & err )
|
||||
{
|
||||
std::cout << "std::exception: " << err.what() << std::endl;
|
||||
exit( -1 );
|
||||
}
|
||||
catch ( ... )
|
||||
{
|
||||
std::cout << "unknown error\n";
|
||||
|
@ -142,8 +142,7 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
1,
|
||||
vk::ImageUsageFlagBits::eColorAttachment,
|
||||
vk::SharingMode::eExclusive,
|
||||
0,
|
||||
nullptr,
|
||||
{},
|
||||
preTransform,
|
||||
compositeAlpha,
|
||||
swapchainPresentMode,
|
||||
@ -188,9 +187,9 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
std::cout << "vk::SystemError: " << err.what() << std::endl;
|
||||
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 );
|
||||
}
|
||||
catch ( ... )
|
||||
|
@ -108,9 +108,9 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
std::cout << "vk::SystemError: " << err.what() << std::endl;
|
||||
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 );
|
||||
}
|
||||
catch ( ... )
|
||||
|
@ -94,9 +94,9 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
std::cout << "vk::SystemError: " << err.what() << std::endl;
|
||||
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 );
|
||||
}
|
||||
catch ( ... )
|
||||
|
@ -43,11 +43,11 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
vk::DescriptorSetLayoutBinding descriptorSetLayoutBinding(
|
||||
0, vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex );
|
||||
vk::UniqueDescriptorSetLayout descriptorSetLayout = device->createDescriptorSetLayoutUnique(
|
||||
vk::DescriptorSetLayoutCreateInfo( vk::DescriptorSetLayoutCreateFlags(), 1, &descriptorSetLayoutBinding ) );
|
||||
vk::DescriptorSetLayoutCreateInfo( vk::DescriptorSetLayoutCreateFlags(), descriptorSetLayoutBinding ) );
|
||||
|
||||
// create a PipelineLayout using that DescriptorSetLayout
|
||||
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
|
||||
// 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;
|
||||
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 );
|
||||
}
|
||||
catch ( ... )
|
||||
|
@ -56,17 +56,16 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
// create a descriptor pool
|
||||
vk::DescriptorPoolSize poolSize( vk::DescriptorType::eUniformBuffer, 1 );
|
||||
vk::UniqueDescriptorPool descriptorPool = device->createDescriptorPoolUnique(
|
||||
vk::DescriptorPoolCreateInfo( vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 1, 1, &poolSize ) );
|
||||
vk::DescriptorPoolCreateInfo( vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 1, poolSize ) );
|
||||
|
||||
// allocate a descriptor set
|
||||
vk::UniqueDescriptorSet descriptorSet = std::move(
|
||||
device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, 1, &*descriptorSetLayout ) )
|
||||
device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, *descriptorSetLayout ) )
|
||||
.front() );
|
||||
|
||||
vk::DescriptorBufferInfo descriptorBufferInfo( uniformBufferData.buffer.get(), 0, sizeof( glm::mat4x4 ) );
|
||||
device->updateDescriptorSets(
|
||||
vk::WriteDescriptorSet(
|
||||
descriptorSet.get(), 0, 0, 1, vk::DescriptorType::eUniformBuffer, nullptr, &descriptorBufferInfo ),
|
||||
vk::WriteDescriptorSet( descriptorSet.get(), 0, 0, vk::DescriptorType::eUniformBuffer, {}, descriptorBufferInfo ),
|
||||
{} );
|
||||
|
||||
/* VULKAN_HPP_KEY_END */
|
||||
@ -76,9 +75,9 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
std::cout << "vk::SystemError: " << err.what() << std::endl;
|
||||
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 );
|
||||
}
|
||||
catch ( ... )
|
||||
|
@ -52,7 +52,7 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
|
||||
/* VULKAN_HPP_KEY_START */
|
||||
|
||||
vk::AttachmentDescription attachmentDescriptions[2];
|
||||
std::array<vk::AttachmentDescription, 2> attachmentDescriptions;
|
||||
attachmentDescriptions[0] = vk::AttachmentDescription( vk::AttachmentDescriptionFlags(),
|
||||
colorFormat,
|
||||
vk::SampleCountFlagBits::e1,
|
||||
@ -74,17 +74,11 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
|
||||
vk::AttachmentReference colorReference( 0, vk::ImageLayout::eColorAttachmentOptimal );
|
||||
vk::AttachmentReference depthReference( 1, vk::ImageLayout::eDepthStencilAttachmentOptimal );
|
||||
vk::SubpassDescription subpass( vk::SubpassDescriptionFlags(),
|
||||
vk::PipelineBindPoint::eGraphics,
|
||||
0,
|
||||
nullptr,
|
||||
1,
|
||||
&colorReference,
|
||||
nullptr,
|
||||
&depthReference );
|
||||
vk::SubpassDescription subpass(
|
||||
vk::SubpassDescriptionFlags(), vk::PipelineBindPoint::eGraphics, {}, colorReference, {}, &depthReference );
|
||||
|
||||
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
|
||||
// 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;
|
||||
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 );
|
||||
}
|
||||
catch ( ... )
|
||||
|
@ -47,16 +47,14 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
bool ok = vk::su::GLSLtoSPV( vk::ShaderStageFlagBits::eVertex, vertexShaderText_PC_C, vertexShaderSPV );
|
||||
assert( ok );
|
||||
|
||||
vk::ShaderModuleCreateInfo vertexShaderModuleCreateInfo(
|
||||
vk::ShaderModuleCreateFlags(), vertexShaderSPV.size() * sizeof( unsigned int ), vertexShaderSPV.data() );
|
||||
vk::UniqueShaderModule vertexShaderModule = device->createShaderModuleUnique( vertexShaderModuleCreateInfo );
|
||||
vk::ShaderModuleCreateInfo vertexShaderModuleCreateInfo( vk::ShaderModuleCreateFlags(), vertexShaderSPV );
|
||||
vk::UniqueShaderModule vertexShaderModule = device->createShaderModuleUnique( vertexShaderModuleCreateInfo );
|
||||
|
||||
std::vector<unsigned int> fragmentShaderSPV;
|
||||
ok = vk::su::GLSLtoSPV( vk::ShaderStageFlagBits::eFragment, fragmentShaderText_C_C, fragmentShaderSPV );
|
||||
assert( ok );
|
||||
|
||||
vk::ShaderModuleCreateInfo fragmentShaderModuleCreateInfo(
|
||||
vk::ShaderModuleCreateFlags(), fragmentShaderSPV.size() * sizeof( unsigned int ), fragmentShaderSPV.data() );
|
||||
vk::ShaderModuleCreateInfo fragmentShaderModuleCreateInfo( vk::ShaderModuleCreateFlags(), fragmentShaderSPV );
|
||||
vk::UniqueShaderModule fragmentShaderModule = device->createShaderModuleUnique( fragmentShaderModuleCreateInfo );
|
||||
|
||||
glslang::FinalizeProcess();
|
||||
@ -71,9 +69,9 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
std::cout << "vk::SystemError: " << err.what() << std::endl;
|
||||
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 );
|
||||
}
|
||||
catch ( ... )
|
||||
|
@ -58,7 +58,7 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
|
||||
/* VULKAN_KEY_START */
|
||||
|
||||
vk::ImageView attachments[2];
|
||||
std::array<vk::ImageView, 2> attachments;
|
||||
attachments[1] = depthBufferData.imageView.get();
|
||||
|
||||
std::vector<vk::UniqueFramebuffer> framebuffers;
|
||||
@ -68,7 +68,6 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
attachments[0] = view.get();
|
||||
framebuffers.push_back( device->createFramebufferUnique( vk::FramebufferCreateInfo( vk::FramebufferCreateFlags(),
|
||||
renderPass.get(),
|
||||
2,
|
||||
attachments,
|
||||
surfaceData.extent.width,
|
||||
surfaceData.extent.height,
|
||||
@ -85,9 +84,9 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
std::cout << "vk::SystemError: " << err.what() << std::endl;
|
||||
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 );
|
||||
}
|
||||
catch ( ... )
|
||||
|
@ -98,7 +98,7 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
assert( currentBuffer.result == vk::Result::eSuccess );
|
||||
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[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
|
||||
|
||||
@ -107,7 +107,6 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
vk::RenderPassBeginInfo renderPassBeginInfo( renderPass.get(),
|
||||
framebuffers[currentBuffer.value].get(),
|
||||
vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ),
|
||||
2,
|
||||
clearValues );
|
||||
commandBuffer->beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
|
||||
|
||||
@ -128,9 +127,9 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
std::cout << "vk::SystemError: " << err.what() << std::endl;
|
||||
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 );
|
||||
}
|
||||
catch ( ... )
|
||||
|
@ -53,7 +53,7 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
vk::UniqueDescriptorSetLayout descriptorSetLayout = vk::su::createDescriptorSetLayout(
|
||||
device, { { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex } } );
|
||||
vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique(
|
||||
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), 1, &descriptorSetLayout.get() ) );
|
||||
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), *descriptorSetLayout ) );
|
||||
|
||||
glslang::InitializeProcess();
|
||||
vk::UniqueShaderModule vertexShaderModule =
|
||||
@ -64,24 +64,22 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
|
||||
/* VULKAN_KEY_START */
|
||||
|
||||
vk::PipelineShaderStageCreateInfo pipelineShaderStageCreateInfos[2] = {
|
||||
std::array<vk::PipelineShaderStageCreateInfo, 2> pipelineShaderStageCreateInfos = {
|
||||
vk::PipelineShaderStageCreateInfo(
|
||||
vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eVertex, vertexShaderModule.get(), "main" ),
|
||||
vk::PipelineShaderStageCreateInfo(
|
||||
vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eFragment, fragmentShaderModule.get(), "main" )
|
||||
};
|
||||
|
||||
vk::VertexInputBindingDescription vertexInputBindingDescription( 0, sizeof( coloredCubeData[0] ) );
|
||||
vk::VertexInputAttributeDescription vertexInputAttributeDescriptions[2] = {
|
||||
vk::VertexInputBindingDescription vertexInputBindingDescription( 0, sizeof( coloredCubeData[0] ) );
|
||||
std::array<vk::VertexInputAttributeDescription, 2> vertexInputAttributeDescriptions = {
|
||||
vk::VertexInputAttributeDescription( 0, 0, vk::Format::eR32G32B32A32Sfloat, 0 ),
|
||||
vk::VertexInputAttributeDescription( 1, 0, vk::Format::eR32G32B32A32Sfloat, 16 )
|
||||
};
|
||||
vk::PipelineVertexInputStateCreateInfo pipelineVertexInputStateCreateInfo(
|
||||
vk::PipelineVertexInputStateCreateFlags(), // flags
|
||||
1, // vertexBindingDescriptionCount
|
||||
&vertexInputBindingDescription, // pVertexBindingDescription
|
||||
2, // vertexAttributeDescriptionCount
|
||||
vertexInputAttributeDescriptions // pVertexAttributeDescriptions
|
||||
vertexInputBindingDescription, // vertexBindingDescriptions
|
||||
vertexInputAttributeDescriptions // vertexAttributeDescriptions
|
||||
);
|
||||
|
||||
vk::PipelineInputAssemblyStateCreateInfo pipelineInputAssemblyStateCreateInfo(
|
||||
@ -139,19 +137,17 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
vk::PipelineColorBlendStateCreateFlags(), // flags
|
||||
false, // logicOpEnable
|
||||
vk::LogicOp::eNoOp, // logicOp
|
||||
1, // attachmentCount
|
||||
&pipelineColorBlendAttachmentState, // pAttachments
|
||||
pipelineColorBlendAttachmentState, // attachments
|
||||
{ { 1.0f, 1.0f, 1.0f, 1.0f } } // blendConstants
|
||||
);
|
||||
|
||||
vk::DynamicState dynamicStates[2] = { vk::DynamicState::eViewport, vk::DynamicState::eScissor };
|
||||
vk::PipelineDynamicStateCreateInfo pipelineDynamicStateCreateInfo(
|
||||
vk::PipelineDynamicStateCreateFlags(), 2, dynamicStates );
|
||||
std::array<vk::DynamicState, 2> dynamicStates = { vk::DynamicState::eViewport, vk::DynamicState::eScissor };
|
||||
vk::PipelineDynamicStateCreateInfo pipelineDynamicStateCreateInfo( vk::PipelineDynamicStateCreateFlags(),
|
||||
dynamicStates );
|
||||
|
||||
vk::GraphicsPipelineCreateInfo graphicsPipelineCreateInfo(
|
||||
vk::PipelineCreateFlags(), // flags
|
||||
2, // stageCount
|
||||
pipelineShaderStageCreateInfos, // pStages
|
||||
pipelineShaderStageCreateInfos, // stages
|
||||
&pipelineVertexInputStateCreateInfo, // pVertexInputState
|
||||
&pipelineInputAssemblyStateCreateInfo, // pInputAssemblyState
|
||||
nullptr, // pTessellationState
|
||||
@ -174,9 +170,9 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
std::cout << "vk::SystemError: " << err.what() << std::endl;
|
||||
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 );
|
||||
}
|
||||
catch ( ... )
|
||||
|
@ -75,7 +75,7 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
vk::UniqueDescriptorSetLayout descriptorSetLayout = vk::su::createDescriptorSetLayout(
|
||||
device, { { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex } } );
|
||||
vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique(
|
||||
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), 1, &descriptorSetLayout.get() ) );
|
||||
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), *descriptorSetLayout ) );
|
||||
|
||||
vk::UniqueRenderPass renderPass = vk::su::createRenderPass(
|
||||
device,
|
||||
@ -102,14 +102,11 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
vk::UniqueDescriptorPool descriptorPool =
|
||||
vk::su::createDescriptorPool( device, { { vk::DescriptorType::eUniformBuffer, 1 } } );
|
||||
vk::UniqueDescriptorSet descriptorSet = std::move(
|
||||
device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, 1, &*descriptorSetLayout ) )
|
||||
device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, *descriptorSetLayout ) )
|
||||
.front() );
|
||||
|
||||
vk::su::updateDescriptorSets(
|
||||
device,
|
||||
descriptorSet,
|
||||
{ { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, {} } },
|
||||
{} );
|
||||
device, descriptorSet, { { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, {} } }, {} );
|
||||
|
||||
vk::UniquePipelineCache pipelineCache = device->createPipelineCacheUnique( vk::PipelineCacheCreateInfo() );
|
||||
vk::UniquePipeline graphicsPipeline = vk::su::createGraphicsPipeline(
|
||||
@ -134,13 +131,12 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
|
||||
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[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
|
||||
vk::RenderPassBeginInfo renderPassBeginInfo( renderPass.get(),
|
||||
framebuffers[currentBuffer.value].get(),
|
||||
vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ),
|
||||
2,
|
||||
clearValues );
|
||||
commandBuffer->beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
|
||||
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::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() );
|
||||
|
||||
while ( vk::Result::eTimeout == device->waitForFences( drawFence.get(), VK_TRUE, vk::su::FenceTimeout ) )
|
||||
;
|
||||
|
||||
presentQueue.presentKHR(
|
||||
vk::PresentInfoKHR( 0, nullptr, 1, &swapChainData.swapChain.get(), ¤tBuffer.value ) );
|
||||
presentQueue.presentKHR( vk::PresentInfoKHR( {}, *swapChainData.swapChain, currentBuffer.value ) );
|
||||
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
|
||||
|
||||
/* VULKAN_KEY_END */
|
||||
@ -183,9 +178,9 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
std::cout << "vk::SystemError: " << err.what() << std::endl;
|
||||
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 );
|
||||
}
|
||||
catch ( ... )
|
||||
|
@ -111,9 +111,9 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
std::cout << "vk::SystemError: " << err.what() << std::endl;
|
||||
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 );
|
||||
}
|
||||
catch ( ... )
|
||||
|
@ -122,7 +122,7 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
/* Queue the command buffer for execution */
|
||||
vk::UniqueFence commandFence = device->createFenceUnique( {} );
|
||||
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() );
|
||||
|
||||
/* Make sure command buffer is finished before mapping */
|
||||
@ -222,7 +222,7 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
commandBuffer->end();
|
||||
|
||||
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();
|
||||
|
||||
/* 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 */
|
||||
presentQueue.presentKHR(
|
||||
vk::PresentInfoKHR( 0, nullptr, 1, &swapChainData.swapChain.get(), ¤tBuffer, nullptr ) );
|
||||
presentQueue.presentKHR( vk::PresentInfoKHR( {}, *swapChainData.swapChain, currentBuffer, {} ) );
|
||||
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
|
||||
|
||||
/* VULKAN_KEY_END */
|
||||
@ -241,9 +240,9 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
std::cout << "vk::SystemError: " << err.what() << std::endl;
|
||||
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 );
|
||||
}
|
||||
catch ( ... )
|
||||
|
@ -127,7 +127,7 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
vk::ApplicationInfo applicationInfo( AppName, 1, EngineName, 1, VK_API_VERSION_1_1 );
|
||||
const char * extensionName = VK_EXT_DEBUG_UTILS_EXTENSION_NAME;
|
||||
vk::UniqueInstance instance = vk::createInstanceUnique(
|
||||
vk::InstanceCreateInfo( vk::InstanceCreateFlags(), &applicationInfo, 0, nullptr, 1, &extensionName ) );
|
||||
vk::InstanceCreateInfo( vk::InstanceCreateFlags(), &applicationInfo, {}, extensionName ) );
|
||||
|
||||
pfnVkCreateDebugUtilsMessengerEXT =
|
||||
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;
|
||||
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 );
|
||||
}
|
||||
catch ( ... )
|
||||
|
@ -68,9 +68,9 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
std::cout << "vk::SystemError: " << err.what() << std::endl;
|
||||
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 );
|
||||
}
|
||||
catch ( ... )
|
||||
|
@ -82,7 +82,7 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
{ { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex },
|
||||
{ vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment } } );
|
||||
vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique(
|
||||
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), 1, &descriptorSetLayout.get() ) );
|
||||
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), *descriptorSetLayout ) );
|
||||
|
||||
vk::UniqueRenderPass renderPass = vk::su::createRenderPass(
|
||||
device,
|
||||
@ -109,14 +109,11 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
vk::UniqueDescriptorPool descriptorPool = vk::su::createDescriptorPool(
|
||||
device, { { vk::DescriptorType::eUniformBuffer, 1 }, { vk::DescriptorType::eCombinedImageSampler, 1 } } );
|
||||
vk::UniqueDescriptorSet descriptorSet = std::move(
|
||||
device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, 1, &*descriptorSetLayout ) )
|
||||
device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, *descriptorSetLayout ) )
|
||||
.front() );
|
||||
|
||||
vk::su::updateDescriptorSets(
|
||||
device,
|
||||
descriptorSet,
|
||||
{ { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, {} } },
|
||||
textureData );
|
||||
device, descriptorSet, { { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, {} } }, textureData );
|
||||
|
||||
vk::UniquePipelineCache pipelineCache = device->createPipelineCacheUnique( vk::PipelineCacheCreateInfo() );
|
||||
vk::UniquePipeline graphicsPipeline =
|
||||
@ -141,13 +138,12 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
|
||||
// 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[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
|
||||
vk::RenderPassBeginInfo renderPassBeginInfo( renderPass.get(),
|
||||
framebuffers[currentBuffer.value].get(),
|
||||
vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ),
|
||||
2,
|
||||
clearValues );
|
||||
commandBuffer->beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
|
||||
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::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() );
|
||||
|
||||
while ( vk::Result::eTimeout == device->waitForFences( drawFence.get(), VK_TRUE, vk::su::FenceTimeout ) )
|
||||
;
|
||||
|
||||
presentQueue.presentKHR(
|
||||
vk::PresentInfoKHR( 0, nullptr, 1, &swapChainData.swapChain.get(), ¤tBuffer.value ) );
|
||||
presentQueue.presentKHR( vk::PresentInfoKHR( {}, *swapChainData.swapChain, currentBuffer.value ) );
|
||||
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
|
||||
|
||||
/* VULKAN_KEY_END */
|
||||
@ -190,9 +185,9 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
std::cout << "vk::SystemError: " << err.what() << std::endl;
|
||||
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 );
|
||||
}
|
||||
catch ( ... )
|
||||
|
@ -140,20 +140,17 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
vk::UniqueDescriptorSetLayout descriptorSetLayout = vk::su::createDescriptorSetLayout(
|
||||
device, { { vk::DescriptorType::eUniformBufferDynamic, 1, vk::ShaderStageFlagBits::eVertex } } );
|
||||
vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique(
|
||||
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), 1, &descriptorSetLayout.get() ) );
|
||||
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), *descriptorSetLayout ) );
|
||||
|
||||
// create a DescriptorPool with vk::DescriptorType::eUniformBufferDynamic
|
||||
vk::UniqueDescriptorPool descriptorPool =
|
||||
vk::su::createDescriptorPool( device, { { vk::DescriptorType::eUniformBufferDynamic, 1 } } );
|
||||
vk::UniqueDescriptorSet descriptorSet = std::move(
|
||||
device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, 1, &*descriptorSetLayout ) )
|
||||
device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, *descriptorSetLayout ) )
|
||||
.front() );
|
||||
|
||||
vk::su::updateDescriptorSets(
|
||||
device,
|
||||
descriptorSet,
|
||||
{ { vk::DescriptorType::eUniformBufferDynamic, uniformBufferData.buffer, {} } },
|
||||
{} );
|
||||
device, descriptorSet, { { vk::DescriptorType::eUniformBufferDynamic, uniformBufferData.buffer, {} } }, {} );
|
||||
|
||||
vk::UniquePipelineCache pipelineCache = device->createPipelineCacheUnique( vk::PipelineCacheCreateInfo() );
|
||||
vk::UniquePipeline graphicsPipeline = vk::su::createGraphicsPipeline(
|
||||
@ -176,13 +173,12 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
|
||||
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[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
|
||||
vk::RenderPassBeginInfo renderPassBeginInfo( renderPass.get(),
|
||||
framebuffers[currentBuffer.value].get(),
|
||||
vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ),
|
||||
2,
|
||||
clearValues );
|
||||
commandBuffer->beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
|
||||
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::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() );
|
||||
|
||||
while ( vk::Result::eTimeout == device->waitForFences( drawFence.get(), VK_TRUE, vk::su::FenceTimeout ) )
|
||||
;
|
||||
|
||||
presentQueue.presentKHR(
|
||||
vk::PresentInfoKHR( 0, nullptr, 1, &swapChainData.swapChain.get(), ¤tBuffer.value ) );
|
||||
presentQueue.presentKHR( vk::PresentInfoKHR( {}, *swapChainData.swapChain, currentBuffer.value ) );
|
||||
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
|
||||
|
||||
/* VULKAN_KEY_END */
|
||||
@ -235,9 +230,9 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
std::cout << "vk::SystemError: " << err.what() << std::endl;
|
||||
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 );
|
||||
}
|
||||
catch ( ... )
|
||||
|
@ -136,13 +136,9 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
instanceExtensionNames.push_back( VK_EXT_DEBUG_UTILS_EXTENSION_NAME );
|
||||
|
||||
vk::ApplicationInfo applicationInfo( AppName, 1, EngineName, 1, VK_API_VERSION_1_1 );
|
||||
vk::InstanceCreateInfo instanceCreateInfo( vk::InstanceCreateFlags(),
|
||||
&applicationInfo,
|
||||
vk::su::checked_cast<uint32_t>( instanceLayerNames.size() ),
|
||||
instanceLayerNames.data(),
|
||||
vk::su::checked_cast<uint32_t>( instanceExtensionNames.size() ),
|
||||
instanceExtensionNames.data() );
|
||||
vk::UniqueInstance instance = vk::createInstanceUnique( instanceCreateInfo );
|
||||
vk::InstanceCreateInfo instanceCreateInfo(
|
||||
vk::InstanceCreateFlags(), &applicationInfo, instanceLayerNames, instanceExtensionNames );
|
||||
vk::UniqueInstance instance = vk::createInstanceUnique( instanceCreateInfo );
|
||||
|
||||
#if ( VULKAN_HPP_DISPATCH_LOADER_DYNAMIC == 1 )
|
||||
// initialize function pointers for instance
|
||||
@ -189,7 +185,7 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
vk::DeviceQueueCreateInfo deviceQueueCreateInfo(
|
||||
vk::DeviceQueueCreateFlags(), queueFamilyIndex, 1, &queuePriority );
|
||||
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!
|
||||
vk::CommandPool commandPool =
|
||||
@ -207,9 +203,9 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
std::cout << "vk::SystemError: " << err.what() << std::endl;
|
||||
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 );
|
||||
}
|
||||
catch ( ... )
|
||||
|
@ -69,6 +69,11 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
std::cout << "vk::SystemError: " << err.what() << std::endl;
|
||||
exit( -1 );
|
||||
}
|
||||
catch ( std::exception & err )
|
||||
{
|
||||
std::cout << "std::exception: " << err.what() << std::endl;
|
||||
exit( -1 );
|
||||
}
|
||||
catch ( ... )
|
||||
{
|
||||
std::cout << "unknown error\n";
|
||||
|
@ -55,8 +55,7 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
|
||||
vk::UniqueFence fence = device->createFenceUnique( vk::FenceCreateInfo() );
|
||||
|
||||
vk::PipelineStageFlags waitDestinationStageMask( vk::PipelineStageFlagBits::eColorAttachmentOutput );
|
||||
vk::SubmitInfo submitInfo( 0, nullptr, &waitDestinationStageMask, 1, &commandBuffer.get() );
|
||||
vk::SubmitInfo submitInfo( {}, {}, *commandBuffer );
|
||||
graphicsQueue.submit( submitInfo, fence.get() );
|
||||
|
||||
// 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.
|
||||
// Execute the code from vk::Queue::submit() through vk::Device::setEvent() without breakpoints
|
||||
waitDestinationStageMask = vk::PipelineStageFlagBits::eBottomOfPipe;
|
||||
graphicsQueue.submit( submitInfo, fence.get() );
|
||||
|
||||
// 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;
|
||||
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 );
|
||||
}
|
||||
catch ( ... )
|
||||
|
@ -101,30 +101,28 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
commandBuffer->begin( vk::CommandBufferBeginInfo() );
|
||||
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( 1,
|
||||
vk::DescriptorType::eCombinedImageSampler,
|
||||
1,
|
||||
vk::ShaderStageFlagBits::eFragment,
|
||||
&textureData.textureSampler.get() )
|
||||
vk::DescriptorSetLayoutBinding(
|
||||
1, vk::DescriptorType::eCombinedImageSampler, vk::ShaderStageFlagBits::eFragment, *textureData.textureSampler )
|
||||
};
|
||||
vk::UniqueDescriptorSetLayout descriptorSetLayout = device->createDescriptorSetLayoutUnique(
|
||||
vk::DescriptorSetLayoutCreateInfo( vk::DescriptorSetLayoutCreateFlags(), 2, bindings ) );
|
||||
vk::DescriptorSetLayoutCreateInfo( vk::DescriptorSetLayoutCreateFlags(), bindings ) );
|
||||
|
||||
// Create pipeline layout
|
||||
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
|
||||
vk::DescriptorPoolSize poolSizes[2] = { vk::DescriptorPoolSize( vk::DescriptorType::eUniformBuffer, 1 ),
|
||||
vk::DescriptorPoolSize( vk::DescriptorType::eCombinedImageSampler, 1 ) };
|
||||
vk::UniqueDescriptorPool descriptorPool = device->createDescriptorPoolUnique(
|
||||
vk::DescriptorPoolCreateInfo( vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 1, 2, poolSizes ) );
|
||||
std::array<vk::DescriptorPoolSize, 2> poolSizes = { vk::DescriptorPoolSize( vk::DescriptorType::eUniformBuffer, 1 ),
|
||||
vk::DescriptorPoolSize(
|
||||
vk::DescriptorType::eCombinedImageSampler, 1 ) };
|
||||
vk::UniqueDescriptorPool descriptorPool = device->createDescriptorPoolUnique(
|
||||
vk::DescriptorPoolCreateInfo( vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 1, poolSizes ) );
|
||||
|
||||
// Populate descriptor sets
|
||||
vk::UniqueDescriptorSet descriptorSet = std::move(
|
||||
device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, 1, &*descriptorSetLayout ) )
|
||||
device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, *descriptorSetLayout ) )
|
||||
.front() );
|
||||
|
||||
vk::DescriptorBufferInfo bufferInfo( uniformBufferData.buffer.get(), 0, sizeof( glm::mat4x4 ) );
|
||||
@ -132,8 +130,8 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
textureData.imageData->imageView.get(),
|
||||
vk::ImageLayout::eShaderReadOnlyOptimal );
|
||||
vk::WriteDescriptorSet writeDescriptorSets[2] = {
|
||||
vk::WriteDescriptorSet( descriptorSet.get(), 0, 0, 1, vk::DescriptorType::eUniformBuffer, nullptr, &bufferInfo ),
|
||||
vk::WriteDescriptorSet( descriptorSet.get(), 1, 0, 1, vk::DescriptorType::eCombinedImageSampler, &imageInfo )
|
||||
vk::WriteDescriptorSet( descriptorSet.get(), 0, 0, vk::DescriptorType::eUniformBuffer, {}, bufferInfo ),
|
||||
vk::WriteDescriptorSet( descriptorSet.get(), 1, 0, vk::DescriptorType::eCombinedImageSampler, imageInfo )
|
||||
};
|
||||
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.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[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
|
||||
vk::RenderPassBeginInfo renderPassBeginInfo( renderPass.get(),
|
||||
framebuffers[currentBuffer.value].get(),
|
||||
vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ),
|
||||
2,
|
||||
clearValues );
|
||||
commandBuffer->beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
|
||||
commandBuffer->bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline.get() );
|
||||
@ -187,8 +184,7 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
|
||||
vk::su::submitAndWait( device, graphicsQueue, commandBuffer );
|
||||
|
||||
presentQueue.presentKHR(
|
||||
vk::PresentInfoKHR( 0, nullptr, 1, &swapChainData.swapChain.get(), ¤tBuffer.value ) );
|
||||
presentQueue.presentKHR( vk::PresentInfoKHR( {}, *swapChainData.swapChain, currentBuffer.value ) );
|
||||
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
|
||||
|
||||
device->waitIdle();
|
||||
@ -198,9 +194,9 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
std::cout << "vk::SystemError: " << err.what() << std::endl;
|
||||
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 );
|
||||
}
|
||||
catch ( ... )
|
||||
|
@ -74,8 +74,7 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
vk::ImageUsageFlagBits::eSampled |
|
||||
( needsStaging ? vk::ImageUsageFlagBits::eTransferDst : vk::ImageUsageFlagBits() ),
|
||||
vk::SharingMode::eExclusive,
|
||||
0,
|
||||
nullptr,
|
||||
{},
|
||||
needsStaging ? vk::ImageLayout::eUndefined : vk::ImageLayout::ePreinitialized ) );
|
||||
|
||||
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;
|
||||
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 );
|
||||
}
|
||||
catch ( ... )
|
||||
|
@ -162,12 +162,12 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
vk::DescriptorSetLayoutBinding layoutBinding(
|
||||
0, vk::DescriptorType::eInputAttachment, 1, vk::ShaderStageFlagBits::eFragment );
|
||||
vk::UniqueDescriptorSetLayout descriptorSetLayout = device->createDescriptorSetLayoutUnique(
|
||||
vk::DescriptorSetLayoutCreateInfo( vk::DescriptorSetLayoutCreateFlags(), 1, &layoutBinding ) );
|
||||
vk::DescriptorSetLayoutCreateInfo( vk::DescriptorSetLayoutCreateFlags(), layoutBinding ) );
|
||||
|
||||
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
|
||||
// PRESENT_SRC_KHR at the end of renderpass
|
||||
vk::AttachmentDescription( vk::AttachmentDescriptionFlags(),
|
||||
@ -195,9 +195,9 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
vk::AttachmentReference colorReference( 0, vk::ImageLayout::eColorAttachmentOptimal );
|
||||
vk::AttachmentReference inputReference( 1, vk::ImageLayout::eShaderReadOnlyOptimal );
|
||||
vk::SubpassDescription subPass(
|
||||
vk::SubpassDescriptionFlags(), vk::PipelineBindPoint::eGraphics, 1, &inputReference, 1, &colorReference );
|
||||
vk::UniqueRenderPass renderPass = device->createRenderPassUnique(
|
||||
vk::RenderPassCreateInfo( vk::RenderPassCreateFlags(), 2, attachments, 1, &subPass ) );
|
||||
vk::SubpassDescriptionFlags(), vk::PipelineBindPoint::eGraphics, inputReference, colorReference );
|
||||
vk::UniqueRenderPass renderPass =
|
||||
device->createRenderPassUnique( vk::RenderPassCreateInfo( vk::RenderPassCreateFlags(), attachments, subPass ) );
|
||||
|
||||
glslang::InitializeProcess();
|
||||
vk::UniqueShaderModule vertexShaderModule =
|
||||
@ -211,16 +211,16 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
|
||||
vk::DescriptorPoolSize poolSize( vk::DescriptorType::eInputAttachment, 1 );
|
||||
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(
|
||||
device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, 1, &*descriptorSetLayout ) )
|
||||
device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, *descriptorSetLayout ) )
|
||||
.front() );
|
||||
|
||||
vk::DescriptorImageInfo inputImageInfo(
|
||||
nullptr, inputAttachmentView.get(), vk::ImageLayout::eShaderReadOnlyOptimal );
|
||||
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 );
|
||||
|
||||
vk::UniquePipelineCache pipelineCache = device->createPipelineCacheUnique( vk::PipelineCacheCreateInfo() );
|
||||
@ -248,8 +248,7 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
commandBuffer->beginRenderPass( vk::RenderPassBeginInfo( renderPass.get(),
|
||||
framebuffers[currentBuffer].get(),
|
||||
vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ),
|
||||
1,
|
||||
&clearValue ),
|
||||
clearValue ),
|
||||
vk::SubpassContents::eInline );
|
||||
commandBuffer->bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline.get() );
|
||||
commandBuffer->bindDescriptorSets(
|
||||
@ -272,7 +271,7 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
|
||||
vk::su::submitAndWait( device, graphicsQueue, commandBuffer );
|
||||
|
||||
presentQueue.presentKHR( vk::PresentInfoKHR( 0, nullptr, 1, &swapChainData.swapChain.get(), ¤tBuffer ) );
|
||||
presentQueue.presentKHR( vk::PresentInfoKHR( {}, *swapChainData.swapChain, currentBuffer ) );
|
||||
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
|
||||
}
|
||||
catch ( vk::SystemError & err )
|
||||
@ -280,9 +279,9 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
std::cout << "vk::SystemError: " << err.what() << std::endl;
|
||||
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 );
|
||||
}
|
||||
catch ( ... )
|
||||
|
@ -55,9 +55,9 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
std::cout << "vk::SystemError: " << err.what() << std::endl;
|
||||
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 );
|
||||
}
|
||||
catch ( ... )
|
||||
|
@ -90,9 +90,9 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
std::cout << "vk::SystemError: " << err.what() << std::endl;
|
||||
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 );
|
||||
}
|
||||
catch ( ... )
|
||||
|
@ -54,9 +54,9 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
std::cout << "vk::SystemError: " << err.what() << std::endl;
|
||||
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 );
|
||||
}
|
||||
catch ( ... )
|
||||
|
@ -45,9 +45,9 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
std::cout << "vk::SystemError: " << err.what() << std::endl;
|
||||
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 );
|
||||
}
|
||||
catch ( ... )
|
||||
|
@ -155,40 +155,41 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
vk::DescriptorSetLayoutBinding uniformBinding(
|
||||
0, vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex );
|
||||
vk::UniqueDescriptorSetLayout uniformLayout = device->createDescriptorSetLayoutUnique(
|
||||
vk::DescriptorSetLayoutCreateInfo( vk::DescriptorSetLayoutCreateFlags(), 1, &uniformBinding ) );
|
||||
vk::DescriptorSetLayoutCreateInfo( vk::DescriptorSetLayoutCreateFlags(), uniformBinding ) );
|
||||
|
||||
// Create second layout containing combined sampler/image data
|
||||
vk::DescriptorSetLayoutBinding sampler2DBinding(
|
||||
0, vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eVertex );
|
||||
vk::UniqueDescriptorSetLayout samplerLayout = device->createDescriptorSetLayoutUnique(
|
||||
vk::DescriptorSetLayoutCreateInfo( vk::DescriptorSetLayoutCreateFlags(), 1, &sampler2DBinding ) );
|
||||
vk::DescriptorSetLayoutCreateInfo( vk::DescriptorSetLayoutCreateFlags(), sampler2DBinding ) );
|
||||
|
||||
// Create pipeline layout with multiple descriptor sets
|
||||
std::array<vk::DescriptorSetLayout, 2> descriptorSetLayouts = { { uniformLayout.get(), samplerLayout.get() } };
|
||||
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
|
||||
vk::DescriptorPoolSize poolSizes[2] = { vk::DescriptorPoolSize( vk::DescriptorType::eUniformBuffer, 1 ),
|
||||
vk::DescriptorPoolSize( vk::DescriptorType::eCombinedImageSampler, 1 ) };
|
||||
vk::UniqueDescriptorPool descriptorPool = device->createDescriptorPoolUnique(
|
||||
vk::DescriptorPoolCreateInfo( vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 2, 2, poolSizes ) );
|
||||
std::array<vk::DescriptorPoolSize, 2> poolSizes = { vk::DescriptorPoolSize( vk::DescriptorType::eUniformBuffer, 1 ),
|
||||
vk::DescriptorPoolSize(
|
||||
vk::DescriptorType::eCombinedImageSampler, 1 ) };
|
||||
vk::UniqueDescriptorPool descriptorPool = device->createDescriptorPoolUnique(
|
||||
vk::DescriptorPoolCreateInfo( vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 2, poolSizes ) );
|
||||
|
||||
// Populate descriptor sets
|
||||
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
|
||||
vk::DescriptorBufferInfo uniformBufferInfo( uniformBufferData.buffer.get(), 0, sizeof( glm::mat4x4 ) );
|
||||
vk::DescriptorImageInfo textureImageInfo( textureData.textureSampler.get(),
|
||||
textureData.imageData->imageView.get(),
|
||||
vk::ImageLayout::eShaderReadOnlyOptimal );
|
||||
std::array<vk::WriteDescriptorSet, 2> writeDescriptorSets = { {
|
||||
vk::WriteDescriptorSet(
|
||||
descriptorSets[0].get(), 0, 0, 1, vk::DescriptorType::eUniformBuffer, nullptr, &uniformBufferInfo ),
|
||||
vk::WriteDescriptorSet(
|
||||
descriptorSets[1].get(), 0, 0, 1, vk::DescriptorType::eCombinedImageSampler, &textureImageInfo )
|
||||
} };
|
||||
std::array<vk::WriteDescriptorSet, 2> writeDescriptorSets = {
|
||||
{ vk::WriteDescriptorSet(
|
||||
descriptorSets[0].get(), 0, 0, vk::DescriptorType::eUniformBuffer, {}, uniformBufferInfo ),
|
||||
vk::WriteDescriptorSet(
|
||||
descriptorSets[1].get(), 0, 0, vk::DescriptorType::eCombinedImageSampler, textureImageInfo ) }
|
||||
};
|
||||
device->updateDescriptorSets( writeDescriptorSets, nullptr );
|
||||
|
||||
/* VULKAN_KEY_END */
|
||||
@ -213,13 +214,12 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
assert( currentBuffer.result == vk::Result::eSuccess );
|
||||
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[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
|
||||
vk::RenderPassBeginInfo renderPassBeginInfo( renderPass.get(),
|
||||
framebuffers[currentBuffer.value].get(),
|
||||
vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ),
|
||||
2,
|
||||
clearValues );
|
||||
commandBuffer->beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
|
||||
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::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() );
|
||||
|
||||
while ( vk::Result::eTimeout == device->waitForFences( drawFence.get(), VK_TRUE, vk::su::FenceTimeout ) )
|
||||
;
|
||||
|
||||
presentQueue.presentKHR(
|
||||
vk::PresentInfoKHR( 0, nullptr, 1, &swapChainData.swapChain.get(), ¤tBuffer.value ) );
|
||||
presentQueue.presentKHR( vk::PresentInfoKHR( {}, *swapChainData.swapChain, currentBuffer.value ) );
|
||||
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
|
||||
|
||||
device->waitIdle();
|
||||
@ -263,9 +262,9 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
std::cout << "vk::SystemError: " << err.what() << std::endl;
|
||||
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 );
|
||||
}
|
||||
catch ( ... )
|
||||
|
@ -75,7 +75,7 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
vk::UniqueDescriptorSetLayout descriptorSetLayout = vk::su::createDescriptorSetLayout(
|
||||
device, { { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex } } );
|
||||
vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique(
|
||||
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), 1, &descriptorSetLayout.get() ) );
|
||||
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), *descriptorSetLayout ) );
|
||||
|
||||
vk::UniqueRenderPass renderPass = vk::su::createRenderPass(
|
||||
device,
|
||||
@ -102,14 +102,11 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
vk::UniqueDescriptorPool descriptorPool =
|
||||
vk::su::createDescriptorPool( device, { { vk::DescriptorType::eUniformBuffer, 1 } } );
|
||||
vk::UniqueDescriptorSet descriptorSet = std::move(
|
||||
device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, 1, &*descriptorSetLayout ) )
|
||||
device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, *descriptorSetLayout ) )
|
||||
.front() );
|
||||
|
||||
vk::su::updateDescriptorSets(
|
||||
device,
|
||||
descriptorSet,
|
||||
{ { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, {} } },
|
||||
{} );
|
||||
device, descriptorSet, { { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, {} } }, {} );
|
||||
|
||||
vk::UniquePipelineCache pipelineCache = device->createPipelineCacheUnique( vk::PipelineCacheCreateInfo() );
|
||||
vk::UniquePipeline graphicsPipeline = vk::su::createGraphicsPipeline(
|
||||
@ -157,13 +154,12 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
commandBuffer->begin( vk::CommandBufferBeginInfo( vk::CommandBufferUsageFlags() ) );
|
||||
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[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
|
||||
commandBuffer->beginRenderPass( vk::RenderPassBeginInfo( renderPass.get(),
|
||||
framebuffers[currentBuffer.value].get(),
|
||||
vk::Rect2D( vk::Offset2D(), surfaceData.extent ),
|
||||
2,
|
||||
clearValues ),
|
||||
vk::SubpassContents::eInline );
|
||||
|
||||
@ -201,7 +197,7 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
vk::UniqueFence drawFence = device->createFenceUnique( vk::FenceCreateInfo() );
|
||||
|
||||
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.waitIdle();
|
||||
@ -231,8 +227,7 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
while ( vk::Result::eTimeout == device->waitForFences( drawFence.get(), VK_TRUE, vk::su::FenceTimeout ) )
|
||||
;
|
||||
|
||||
presentQueue.presentKHR(
|
||||
vk::PresentInfoKHR( 0, nullptr, 1, &swapChainData.swapChain.get(), ¤tBuffer.value ) );
|
||||
presentQueue.presentKHR( vk::PresentInfoKHR( {}, *swapChainData.swapChain, currentBuffer.value ) );
|
||||
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
|
||||
|
||||
/* VULKAN_KEY_END */
|
||||
@ -242,9 +237,9 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
std::cout << "vk::SystemError: " << err.what() << std::endl;
|
||||
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 );
|
||||
}
|
||||
catch ( ... )
|
||||
|
@ -64,9 +64,9 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
std::cout << "vk::SystemError: " << err.what() << std::endl;
|
||||
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 );
|
||||
}
|
||||
catch ( ... )
|
||||
|
@ -805,9 +805,9 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
std::cout << "vk::SystemError: " << err.what() << std::endl;
|
||||
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 );
|
||||
}
|
||||
catch ( ... )
|
||||
|
@ -72,7 +72,7 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
float queuePriority = 0.0f;
|
||||
vk::DeviceQueueCreateInfo deviceQueueCreateInfo(
|
||||
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,
|
||||
groupProperties[i].physicalDevices );
|
||||
@ -89,9 +89,9 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
std::cout << "vk::SystemError: " << err.what() << std::endl;
|
||||
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 );
|
||||
}
|
||||
catch ( ... )
|
||||
|
@ -101,9 +101,9 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
std::cout << "vk::SystemError: " << err.what() << std::endl;
|
||||
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 );
|
||||
}
|
||||
catch ( ... )
|
||||
|
@ -1273,9 +1273,9 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
std::cout << "vk::SystemError: " << err.what() << std::endl;
|
||||
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 );
|
||||
}
|
||||
catch ( ... )
|
||||
|
@ -93,9 +93,9 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
std::cout << "vk::SystemError: " << err.what() << std::endl;
|
||||
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 );
|
||||
}
|
||||
catch ( ... )
|
||||
|
@ -113,7 +113,7 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
{ { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex },
|
||||
{ vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment } } );
|
||||
vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique(
|
||||
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), 1, &descriptorSetLayout.get() ) );
|
||||
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), *descriptorSetLayout ) );
|
||||
|
||||
vk::UniqueRenderPass renderPass = vk::su::createRenderPass(
|
||||
device,
|
||||
@ -140,14 +140,11 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
vk::UniqueDescriptorPool descriptorPool = vk::su::createDescriptorPool(
|
||||
device, { { vk::DescriptorType::eUniformBuffer, 1 }, { vk::DescriptorType::eCombinedImageSampler, 1 } } );
|
||||
vk::UniqueDescriptorSet descriptorSet = std::move(
|
||||
device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, 1, &*descriptorSetLayout ) )
|
||||
device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, *descriptorSetLayout ) )
|
||||
.front() );
|
||||
|
||||
vk::su::updateDescriptorSets(
|
||||
device,
|
||||
descriptorSet,
|
||||
{ { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, {} } },
|
||||
textureData );
|
||||
device, descriptorSet, { { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, {} } }, textureData );
|
||||
|
||||
/* VULKAN_KEY_START */
|
||||
|
||||
@ -314,14 +311,13 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
assert( currentBuffer.result == vk::Result::eSuccess );
|
||||
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[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
|
||||
|
||||
commandBuffer->beginRenderPass( vk::RenderPassBeginInfo( renderPass.get(),
|
||||
framebuffers[currentBuffer.value].get(),
|
||||
vk::Rect2D( vk::Offset2D(), surfaceData.extent ),
|
||||
2,
|
||||
clearValues ),
|
||||
vk::SubpassContents::eInline );
|
||||
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::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() );
|
||||
|
||||
while ( vk::Result::eTimeout == device->waitForFences( drawFence.get(), VK_TRUE, vk::su::FenceTimeout ) )
|
||||
;
|
||||
|
||||
presentQueue.presentKHR(
|
||||
vk::PresentInfoKHR( 0, nullptr, 1, &swapChainData.swapChain.get(), ¤tBuffer.value ) );
|
||||
presentQueue.presentKHR( vk::PresentInfoKHR( {}, *swapChainData.swapChain, currentBuffer.value ) );
|
||||
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
|
||||
|
||||
// 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;
|
||||
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 );
|
||||
}
|
||||
catch ( ... )
|
||||
|
@ -80,7 +80,7 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
{ { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex },
|
||||
{ vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment } } );
|
||||
vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique(
|
||||
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), 1, &descriptorSetLayout.get() ) );
|
||||
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), *descriptorSetLayout ) );
|
||||
|
||||
vk::UniqueRenderPass renderPass = vk::su::createRenderPass(
|
||||
device,
|
||||
@ -107,14 +107,11 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
vk::UniqueDescriptorPool descriptorPool = vk::su::createDescriptorPool(
|
||||
device, { { vk::DescriptorType::eUniformBuffer, 1 }, { vk::DescriptorType::eCombinedImageSampler, 1 } } );
|
||||
vk::UniqueDescriptorSet descriptorSet = std::move(
|
||||
device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, 1, &*descriptorSetLayout ) )
|
||||
device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, *descriptorSetLayout ) )
|
||||
.front() );
|
||||
|
||||
vk::su::updateDescriptorSets(
|
||||
device,
|
||||
descriptorSet,
|
||||
{ { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, {} } },
|
||||
textureData );
|
||||
device, descriptorSet, { { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, {} } }, textureData );
|
||||
|
||||
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.
|
||||
// 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::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eVertex, vertexShaderModule.get(), "main" ),
|
||||
vk::PipelineShaderStageCreateInfo(
|
||||
vk::PipelineShaderStageCreateFlags(), vk::ShaderStageFlagBits::eFragment, fragmentShaderModule.get(), "main" )
|
||||
};
|
||||
|
||||
vk::VertexInputBindingDescription vertexInputBindingDescription( 0, sizeof( texturedCubeData[0] ) );
|
||||
vk::VertexInputAttributeDescription vertexInputAttributeDescriptions[2] = {
|
||||
vk::VertexInputBindingDescription vertexInputBindingDescription( 0, sizeof( texturedCubeData[0] ) );
|
||||
std::array<vk::VertexInputAttributeDescription, 2> vertexInputAttributeDescriptions = {
|
||||
vk::VertexInputAttributeDescription( 0, 0, vk::Format::eR32G32B32A32Sfloat, 0 ),
|
||||
vk::VertexInputAttributeDescription( 1, 0, vk::Format::eR32G32B32A32Sfloat, 16 )
|
||||
};
|
||||
vk::PipelineVertexInputStateCreateInfo pipelineVertexInputStateCreateInfo(
|
||||
vk::PipelineVertexInputStateCreateFlags(),
|
||||
1,
|
||||
&vertexInputBindingDescription,
|
||||
2,
|
||||
vertexInputAttributeDescriptions );
|
||||
vk::PipelineVertexInputStateCreateFlags(), vertexInputBindingDescription, vertexInputAttributeDescriptions );
|
||||
|
||||
vk::PipelineInputAssemblyStateCreateInfo pipelineInputAssemblyStateCreateInfo(
|
||||
vk::PipelineInputAssemblyStateCreateFlags(), vk::PrimitiveTopology::eTriangleList );
|
||||
@ -190,16 +183,14 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
vk::PipelineColorBlendStateCreateInfo pipelineColorBlendStateCreateInfo( vk::PipelineColorBlendStateCreateFlags(),
|
||||
false,
|
||||
vk::LogicOp::eNoOp,
|
||||
1,
|
||||
&pipelineColorBlendAttachmentState,
|
||||
pipelineColorBlendAttachmentState,
|
||||
{ { 1.0f, 1.0f, 1.0f, 1.0f } } );
|
||||
|
||||
vk::DynamicState dynamicStates[2] = { vk::DynamicState::eViewport, vk::DynamicState::eScissor };
|
||||
vk::PipelineDynamicStateCreateInfo pipelineDynamicStateCreateInfo(
|
||||
vk::PipelineDynamicStateCreateFlags(), 2, dynamicStates );
|
||||
std::array<vk::DynamicState, 2> dynamicStates = { vk::DynamicState::eViewport, vk::DynamicState::eScissor };
|
||||
vk::PipelineDynamicStateCreateInfo pipelineDynamicStateCreateInfo( vk::PipelineDynamicStateCreateFlags(),
|
||||
dynamicStates );
|
||||
|
||||
vk::GraphicsPipelineCreateInfo graphicsPipelineCreateInfo( vk::PipelineCreateFlagBits::eAllowDerivatives,
|
||||
2,
|
||||
pipelineShaderStageCreateInfos,
|
||||
&pipelineVertexInputStateCreateInfo,
|
||||
&pipelineInputAssemblyStateCreateInfo,
|
||||
@ -259,14 +250,13 @@ void main()
|
||||
assert( currentBuffer.result == vk::Result::eSuccess );
|
||||
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[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
|
||||
|
||||
commandBuffer->beginRenderPass( vk::RenderPassBeginInfo( renderPass.get(),
|
||||
framebuffers[currentBuffer.value].get(),
|
||||
vk::Rect2D( vk::Offset2D(), surfaceData.extent ),
|
||||
2,
|
||||
clearValues ),
|
||||
vk::SubpassContents::eInline );
|
||||
commandBuffer->bindPipeline( vk::PipelineBindPoint::eGraphics, derivedPipeline.get() );
|
||||
@ -290,14 +280,13 @@ void main()
|
||||
vk::UniqueFence drawFence = device->createFenceUnique( vk::FenceCreateInfo() );
|
||||
|
||||
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() );
|
||||
|
||||
while ( vk::Result::eTimeout == device->waitForFences( drawFence.get(), VK_TRUE, vk::su::FenceTimeout ) )
|
||||
;
|
||||
|
||||
presentQueue.presentKHR(
|
||||
vk::PresentInfoKHR( 0, nullptr, 1, &swapChainData.swapChain.get(), ¤tBuffer.value ) );
|
||||
presentQueue.presentKHR( vk::PresentInfoKHR( {}, *swapChainData.swapChain, currentBuffer.value ) );
|
||||
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
|
||||
}
|
||||
catch ( vk::SystemError & err )
|
||||
@ -305,9 +294,9 @@ void main()
|
||||
std::cout << "vk::SystemError: " << err.what() << std::endl;
|
||||
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 );
|
||||
}
|
||||
catch ( ... )
|
||||
|
@ -144,24 +144,25 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
|
||||
// Set up our push constant range, which mirrors the declaration of
|
||||
vk::PushConstantRange pushConstantRanges( vk::ShaderStageFlagBits::eFragment, 0, 8 );
|
||||
vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique( vk::PipelineLayoutCreateInfo(
|
||||
vk::PipelineLayoutCreateFlags(), 1, &descriptorSetLayout.get(), 1, &pushConstantRanges ) );
|
||||
vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique(
|
||||
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), *descriptorSetLayout, pushConstantRanges ) );
|
||||
|
||||
// Create a single pool to contain data for our descriptor set
|
||||
vk::DescriptorPoolSize poolSizes[2] = { vk::DescriptorPoolSize( vk::DescriptorType::eUniformBuffer, 1 ),
|
||||
vk::DescriptorPoolSize( vk::DescriptorType::eCombinedImageSampler, 1 ) };
|
||||
vk::UniqueDescriptorPool descriptorPool = device->createDescriptorPoolUnique(
|
||||
vk::DescriptorPoolCreateInfo( vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 1, 2, poolSizes ) );
|
||||
std::array<vk::DescriptorPoolSize, 2> poolSizes = { vk::DescriptorPoolSize( vk::DescriptorType::eUniformBuffer, 1 ),
|
||||
vk::DescriptorPoolSize(
|
||||
vk::DescriptorType::eCombinedImageSampler, 1 ) };
|
||||
vk::UniqueDescriptorPool descriptorPool = device->createDescriptorPoolUnique(
|
||||
vk::DescriptorPoolCreateInfo( vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 1, poolSizes ) );
|
||||
|
||||
// Populate descriptor sets
|
||||
vk::UniqueDescriptorSet descriptorSet = std::move(
|
||||
device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, 1, &*descriptorSetLayout ) )
|
||||
device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, *descriptorSetLayout ) )
|
||||
.front() );
|
||||
|
||||
// Populate with info about our uniform buffer for MVP
|
||||
vk::DescriptorBufferInfo bufferInfo( uniformBufferData.buffer.get(), 0, sizeof( glm::mat4x4 ) );
|
||||
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
|
||||
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.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[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
|
||||
|
||||
vk::RenderPassBeginInfo renderPassBeginInfo( renderPass.get(),
|
||||
framebuffers[currentBuffer.value].get(),
|
||||
vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ),
|
||||
2,
|
||||
clearValues );
|
||||
commandBuffer->beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
|
||||
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::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() );
|
||||
|
||||
while ( vk::Result::eTimeout == device->waitForFences( drawFence.get(), VK_TRUE, vk::su::FenceTimeout ) )
|
||||
;
|
||||
|
||||
presentQueue.presentKHR(
|
||||
vk::PresentInfoKHR( 0, nullptr, 1, &swapChainData.swapChain.get(), ¤tBuffer.value ) );
|
||||
presentQueue.presentKHR( vk::PresentInfoKHR( {}, *swapChainData.swapChain, currentBuffer.value ) );
|
||||
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
|
||||
}
|
||||
catch ( vk::SystemError & err )
|
||||
@ -240,9 +239,9 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
std::cout << "vk::SystemError: " << err.what() << std::endl;
|
||||
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 );
|
||||
}
|
||||
catch ( ... )
|
||||
|
@ -119,7 +119,7 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
{ vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment } },
|
||||
vk::DescriptorSetLayoutCreateFlagBits::ePushDescriptorKHR );
|
||||
vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique(
|
||||
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), 1, &descriptorSetLayout.get() ) );
|
||||
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), *descriptorSetLayout ) );
|
||||
|
||||
vk::UniqueRenderPass renderPass = vk::su::createRenderPass(
|
||||
device,
|
||||
@ -163,13 +163,12 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
assert( currentBuffer.result == vk::Result::eSuccess );
|
||||
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[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
|
||||
vk::RenderPassBeginInfo renderPassBeginInfo( renderPass.get(),
|
||||
framebuffers[currentBuffer.value].get(),
|
||||
vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ),
|
||||
2,
|
||||
clearValues );
|
||||
commandBuffer->beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
|
||||
commandBuffer->bindPipeline( vk::PipelineBindPoint::eGraphics, graphicsPipeline.get() );
|
||||
@ -179,8 +178,8 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
textureData.imageData->imageView.get(),
|
||||
vk::ImageLayout::eShaderReadOnlyOptimal );
|
||||
vk::WriteDescriptorSet writeDescriptorSets[2] = {
|
||||
vk::WriteDescriptorSet( {}, 0, 0, 1, vk::DescriptorType::eUniformBuffer, nullptr, &bufferInfo ),
|
||||
vk::WriteDescriptorSet( {}, 1, 0, 1, vk::DescriptorType::eCombinedImageSampler, &imageInfo )
|
||||
vk::WriteDescriptorSet( {}, 0, 0, vk::DescriptorType::eUniformBuffer, {}, bufferInfo ),
|
||||
vk::WriteDescriptorSet( {}, 1, 0, vk::DescriptorType::eCombinedImageSampler, imageInfo )
|
||||
};
|
||||
|
||||
// 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::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() );
|
||||
|
||||
while ( vk::Result::eTimeout == device->waitForFences( drawFence.get(), VK_TRUE, vk::su::FenceTimeout ) )
|
||||
;
|
||||
|
||||
presentQueue.presentKHR(
|
||||
vk::PresentInfoKHR( 0, nullptr, 1, &swapChainData.swapChain.get(), ¤tBuffer.value ) );
|
||||
presentQueue.presentKHR( vk::PresentInfoKHR( {}, *swapChainData.swapChain, currentBuffer.value ) );
|
||||
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
|
||||
|
||||
/* VULKAN_KEY_END */
|
||||
@ -223,9 +221,9 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
std::cout << "vk::SystemError: " << err.what() << std::endl;
|
||||
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 );
|
||||
}
|
||||
catch ( ... )
|
||||
|
@ -15,8 +15,11 @@
|
||||
// VulkanHpp Samples : RayTracing
|
||||
// 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 <GLFW/glfw3.h>
|
||||
// clang-format on
|
||||
#include <numeric>
|
||||
#include <random>
|
||||
#include <sstream>
|
||||
@ -46,11 +49,11 @@ struct GeometryInstanceData
|
||||
uint32_t instanceOffset_,
|
||||
uint8_t flags_,
|
||||
uint64_t accelerationStructureHandle_ )
|
||||
: instanceId( instanceID_ ),
|
||||
mask( mask_ ),
|
||||
instanceOffset( instanceOffset_ ),
|
||||
flags( flags_ ),
|
||||
accelerationStructureHandle( accelerationStructureHandle_ )
|
||||
: instanceId( instanceID_ )
|
||||
, mask( mask_ )
|
||||
, instanceOffset( instanceOffset_ )
|
||||
, flags( flags_ )
|
||||
, accelerationStructureHandle( accelerationStructureHandle_ )
|
||||
{
|
||||
assert( !( instanceID_ & 0xFF000000 ) && !( instanceOffset_ & 0xFF000000 ) );
|
||||
memcpy( transform, &transform_, 12 * sizeof( float ) );
|
||||
@ -86,11 +89,8 @@ AccelerationStructureData
|
||||
|
||||
vk::AccelerationStructureTypeNV accelerationStructureType =
|
||||
instances.empty() ? vk::AccelerationStructureTypeNV::eBottomLevel : vk::AccelerationStructureTypeNV::eTopLevel;
|
||||
vk::AccelerationStructureInfoNV accelerationStructureInfo( accelerationStructureType,
|
||||
{},
|
||||
vk::su::checked_cast<uint32_t>( instances.size() ),
|
||||
vk::su::checked_cast<uint32_t>( geometries.size() ),
|
||||
geometries.data() );
|
||||
vk::AccelerationStructureInfoNV accelerationStructureInfo(
|
||||
accelerationStructureType, {}, vk::su::checked_cast<uint32_t>( instances.size() ), geometries );
|
||||
accelerationStructureData.acclerationStructure = device->createAccelerationStructureNVUnique(
|
||||
vk::AccelerationStructureCreateInfoNV( 0, accelerationStructureInfo ) );
|
||||
|
||||
@ -157,11 +157,8 @@ AccelerationStructureData
|
||||
*accelerationStructureData.acclerationStructure, *accelerationStructureData.resultBufferData->deviceMemory ) );
|
||||
|
||||
commandBuffer->buildAccelerationStructureNV(
|
||||
vk::AccelerationStructureInfoNV( accelerationStructureType,
|
||||
{},
|
||||
vk::su::checked_cast<uint32_t>( instances.size() ),
|
||||
vk::su::checked_cast<uint32_t>( geometries.size() ),
|
||||
geometries.data() ),
|
||||
vk::AccelerationStructureInfoNV(
|
||||
accelerationStructureType, {}, vk::su::checked_cast<uint32_t>( instances.size() ), geometries ),
|
||||
accelerationStructureData.instanceBufferData ? *accelerationStructureData.instanceBufferData->buffer : nullptr,
|
||||
0,
|
||||
false,
|
||||
@ -871,7 +868,7 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
static_cast<uint32_t>( textures.size() ),
|
||||
vk::ShaderStageFlagBits::eFragment } } );
|
||||
vk::UniquePipelineLayout pipelineLayout =
|
||||
device->createPipelineLayoutUnique( vk::PipelineLayoutCreateInfo( {}, 1, &( *descriptorSetLayout ) ) );
|
||||
device->createPipelineLayoutUnique( vk::PipelineLayoutCreateInfo( {}, *descriptorSetLayout ) );
|
||||
|
||||
glslang::InitializeProcess();
|
||||
vk::UniqueShaderModule vertexShaderModule =
|
||||
@ -899,14 +896,13 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
physicalDevice, device, sizeof( UniformBufferObject ), vk::BufferUsageFlagBits::eUniformBuffer );
|
||||
|
||||
vk::UniqueDescriptorSet descriptorSet = std::move(
|
||||
device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, 1, &*descriptorSetLayout ) )
|
||||
device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, *descriptorSetLayout ) )
|
||||
.front() );
|
||||
vk::su::updateDescriptorSets(
|
||||
device,
|
||||
descriptorSet,
|
||||
{ { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, {} },
|
||||
{ vk::DescriptorType::eStorageBuffer, materialBufferData.buffer, {} } },
|
||||
textures );
|
||||
vk::su::updateDescriptorSets( device,
|
||||
descriptorSet,
|
||||
{ { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, {} },
|
||||
{ vk::DescriptorType::eStorageBuffer, materialBufferData.buffer, {} } },
|
||||
textures );
|
||||
|
||||
// RayTracing specific stuff
|
||||
|
||||
@ -996,18 +992,16 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
vk::DescriptorPoolCreateInfo descriptorPoolCreateInfo(
|
||||
vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet,
|
||||
vk::su::checked_cast<uint32_t>( swapChainData.images.size() ),
|
||||
vk::su::checked_cast<uint32_t>( descriptorPoolSizes.size() ),
|
||||
descriptorPoolSizes.data() );
|
||||
descriptorPoolSizes );
|
||||
vk::UniqueDescriptorPool rayTracingDescriptorPool = device->createDescriptorPoolUnique( descriptorPoolCreateInfo );
|
||||
vk::UniqueDescriptorSetLayout rayTracingDescriptorSetLayout = device->createDescriptorSetLayoutUnique(
|
||||
vk::DescriptorSetLayoutCreateInfo( {}, static_cast<uint32_t>( bindings.size() ), bindings.data() ) );
|
||||
vk::UniqueDescriptorSetLayout rayTracingDescriptorSetLayout =
|
||||
device->createDescriptorSetLayoutUnique( vk::DescriptorSetLayoutCreateInfo( {}, bindings ) );
|
||||
std::vector<vk::DescriptorSetLayout> layouts;
|
||||
for ( size_t i = 0; i < swapChainData.images.size(); i++ )
|
||||
{
|
||||
layouts.push_back( *rayTracingDescriptorSetLayout );
|
||||
}
|
||||
vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo(
|
||||
*rayTracingDescriptorPool, vk::su::checked_cast<uint32_t>( layouts.size() ), layouts.data() );
|
||||
vk::DescriptorSetAllocateInfo descriptorSetAllocateInfo( *rayTracingDescriptorPool, layouts );
|
||||
std::vector<vk::UniqueDescriptorSet> rayTracingDescriptorSets =
|
||||
device->allocateDescriptorSetsUnique( descriptorSetAllocateInfo );
|
||||
|
||||
@ -1027,15 +1021,14 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
// view)
|
||||
for ( size_t i = 0; i < rayTracingDescriptorSets.size(); i++ )
|
||||
{
|
||||
vk::su::updateDescriptorSets(
|
||||
device,
|
||||
rayTracingDescriptorSets[i],
|
||||
{ { bindings[2].descriptorType, uniformBufferData.buffer, {} },
|
||||
{ bindings[3].descriptorType, vertexBufferData.buffer, {} },
|
||||
{ bindings[4].descriptorType, indexBufferData.buffer, {} },
|
||||
{ bindings[5].descriptorType, materialBufferData.buffer, {} } },
|
||||
textures,
|
||||
2 );
|
||||
vk::su::updateDescriptorSets( device,
|
||||
rayTracingDescriptorSets[i],
|
||||
{ { bindings[2].descriptorType, uniformBufferData.buffer, {} },
|
||||
{ bindings[3].descriptorType, vertexBufferData.buffer, {} },
|
||||
{ bindings[4].descriptorType, indexBufferData.buffer, {} },
|
||||
{ bindings[5].descriptorType, materialBufferData.buffer, {} } },
|
||||
textures,
|
||||
2 );
|
||||
}
|
||||
|
||||
// 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
|
||||
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
|
||||
// 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
|
||||
// in the ray generation to avoid deep recursion.
|
||||
uint32_t maxRecursionDepth = 2;
|
||||
vk::RayTracingPipelineCreateInfoNV rayTracingPipelineCreateInfo( {},
|
||||
static_cast<uint32_t>( shaderStages.size() ),
|
||||
shaderStages.data(),
|
||||
static_cast<uint32_t>( shaderGroups.size() ),
|
||||
shaderGroups.data(),
|
||||
maxRecursionDepth,
|
||||
*rayTracingPipelineLayout );
|
||||
vk::UniquePipeline rayTracingPipeline =
|
||||
vk::RayTracingPipelineCreateInfoNV rayTracingPipelineCreateInfo(
|
||||
{}, shaderStages, shaderGroups, maxRecursionDepth, *rayTracingPipelineLayout );
|
||||
vk::UniquePipeline rayTracingPipeline =
|
||||
device->createRayTracingPipelineNVUnique( nullptr, rayTracingPipelineCreateInfo );
|
||||
|
||||
uint32_t shaderGroupHandleSize =
|
||||
@ -1208,8 +1196,7 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
commandBuffer->beginRenderPass( vk::RenderPassBeginInfo( *renderPass,
|
||||
*framebuffers[backBufferIndex],
|
||||
vk::Rect2D( vk::Offset2D( 0, 0 ), windowExtent ),
|
||||
static_cast<uint32_t>( clearValues.size() ),
|
||||
clearValues.data() ),
|
||||
clearValues ),
|
||||
vk::SubpassContents::eInline );
|
||||
|
||||
commandBuffer->bindPipeline( vk::PipelineBindPoint::eGraphics, *graphicsPipeline );
|
||||
@ -1237,7 +1224,7 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
nullptr, *swapChainData.imageViews[backBufferIndex], vk::ImageLayout::eGeneral );
|
||||
device->updateDescriptorSets(
|
||||
vk::WriteDescriptorSet(
|
||||
*rayTracingDescriptorSets[backBufferIndex], 1, 0, 1, bindings[1].descriptorType, &imageInfo ),
|
||||
*rayTracingDescriptorSets[backBufferIndex], 1, 0, bindings[1].descriptorType, imageInfo ),
|
||||
{} );
|
||||
|
||||
vk::su::setImageLayout( commandBuffer,
|
||||
@ -1293,11 +1280,8 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
1,
|
||||
&( *perFrameData[frameIndex].renderCompleteSemaphore ) ),
|
||||
*perFrameData[frameIndex].fence );
|
||||
presentQueue.presentKHR( vk::PresentInfoKHR( 1,
|
||||
&( *perFrameData[frameIndex].renderCompleteSemaphore ),
|
||||
1,
|
||||
&( *swapChainData.swapChain ),
|
||||
&backBufferIndex ) );
|
||||
presentQueue.presentKHR( vk::PresentInfoKHR(
|
||||
*perFrameData[frameIndex].renderCompleteSemaphore, *swapChainData.swapChain, backBufferIndex ) );
|
||||
frameIndex = ( frameIndex + 1 ) % IMGUI_VK_QUEUED_FRAMES;
|
||||
|
||||
double endTime = glfwGetTime();
|
||||
@ -1330,9 +1314,9 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
std::cout << "vk::SystemError: " << err.what() << std::endl;
|
||||
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 );
|
||||
}
|
||||
catch ( ... )
|
||||
|
@ -77,7 +77,7 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
{ { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex },
|
||||
{ vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment } } );
|
||||
vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique(
|
||||
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), 1, &descriptorSetLayout.get() ) );
|
||||
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), *descriptorSetLayout ) );
|
||||
|
||||
vk::UniqueRenderPass renderPass = vk::su::createRenderPass(
|
||||
device,
|
||||
@ -129,21 +129,19 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
vk::UniqueDescriptorPool descriptorPool = vk::su::createDescriptorPool(
|
||||
device, { { vk::DescriptorType::eUniformBuffer, 2 }, { vk::DescriptorType::eCombinedImageSampler, 2 } } );
|
||||
|
||||
vk::DescriptorSetLayout layouts[] = { descriptorSetLayout.get(), descriptorSetLayout.get() };
|
||||
std::vector<vk::UniqueDescriptorSet> descriptorSets =
|
||||
device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( descriptorPool.get(), 2, layouts ) );
|
||||
std::array<vk::DescriptorSetLayout, 2> layouts = { descriptorSetLayout.get(), descriptorSetLayout.get() };
|
||||
std::vector<vk::UniqueDescriptorSet> descriptorSets =
|
||||
device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( descriptorPool.get(), layouts ) );
|
||||
assert( descriptorSets.size() == 2 );
|
||||
|
||||
vk::su::updateDescriptorSets(
|
||||
device,
|
||||
descriptorSets[0],
|
||||
{ { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, {} } },
|
||||
greenTextureData );
|
||||
vk::su::updateDescriptorSets(
|
||||
device,
|
||||
descriptorSets[1],
|
||||
{ { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, {} } },
|
||||
checkeredTextureData );
|
||||
vk::su::updateDescriptorSets( device,
|
||||
descriptorSets[0],
|
||||
{ { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, {} } },
|
||||
greenTextureData );
|
||||
vk::su::updateDescriptorSets( device,
|
||||
descriptorSets[1],
|
||||
{ { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, {} } },
|
||||
checkeredTextureData );
|
||||
|
||||
/* VULKAN_KEY_START */
|
||||
|
||||
@ -191,14 +189,13 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
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[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
|
||||
|
||||
vk::RenderPassBeginInfo renderPassBeginInfo( renderPass.get(),
|
||||
framebuffers[currentBuffer.value].get(),
|
||||
vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ),
|
||||
2,
|
||||
clearValues );
|
||||
// specifying VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS means this render pass may ONLY call
|
||||
// vkCmdExecuteCommands
|
||||
@ -226,14 +223,13 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
vk::UniqueFence drawFence = device->createFenceUnique( vk::FenceCreateInfo() );
|
||||
|
||||
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() );
|
||||
|
||||
while ( vk::Result::eTimeout == device->waitForFences( drawFence.get(), VK_TRUE, vk::su::FenceTimeout ) )
|
||||
;
|
||||
|
||||
presentQueue.presentKHR(
|
||||
vk::PresentInfoKHR( 0, nullptr, 1, &swapChainData.swapChain.get(), ¤tBuffer.value ) );
|
||||
presentQueue.presentKHR( vk::PresentInfoKHR( {}, *swapChainData.swapChain, currentBuffer.value ) );
|
||||
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
|
||||
|
||||
/* VULKAN_KEY_END */
|
||||
@ -245,9 +241,9 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
std::cout << "vk::SystemError: " << err.what() << std::endl;
|
||||
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 );
|
||||
}
|
||||
catch ( ... )
|
||||
|
@ -154,34 +154,30 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
// binding 0 = uniform buffer (MVP)
|
||||
// binding 1 = texture2D
|
||||
// binding 2 = sampler
|
||||
std::array<vk::DescriptorSetLayoutBinding, 3> resourceBindings = { {
|
||||
vk::DescriptorSetLayoutBinding( 0, vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex ),
|
||||
vk::DescriptorSetLayoutBinding( 1, vk::DescriptorType::eSampledImage, 1, vk::ShaderStageFlagBits::eFragment ),
|
||||
vk::DescriptorSetLayoutBinding( 2, vk::DescriptorType::eSampler, 1, vk::ShaderStageFlagBits::eFragment )
|
||||
}
|
||||
std::array<vk::DescriptorSetLayoutBinding, 3> resourceBindings = {
|
||||
{ vk::DescriptorSetLayoutBinding( 0, vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex ),
|
||||
vk::DescriptorSetLayoutBinding( 1, vk::DescriptorType::eSampledImage, 1, vk::ShaderStageFlagBits::eFragment ),
|
||||
vk::DescriptorSetLayoutBinding( 2, vk::DescriptorType::eSampler, 1, vk::ShaderStageFlagBits::eFragment ) }
|
||||
};
|
||||
vk::UniqueDescriptorSetLayout descriptorSetLayout = device->createDescriptorSetLayoutUnique(
|
||||
vk::DescriptorSetLayoutCreateInfo( vk::DescriptorSetLayoutCreateFlags(),
|
||||
static_cast<uint32_t>( resourceBindings.size() ),
|
||||
resourceBindings.data() ) );
|
||||
vk::DescriptorSetLayoutCreateInfo( vk::DescriptorSetLayoutCreateFlags(), resourceBindings ) );
|
||||
|
||||
// Create pipeline layout
|
||||
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
|
||||
std::array<vk::DescriptorPoolSize, 3> poolSizes = { { vk::DescriptorPoolSize( vk::DescriptorType::eUniformBuffer, 1 ),
|
||||
vk::DescriptorPoolSize( vk::DescriptorType::eSampledImage, 1 ),
|
||||
vk::DescriptorPoolSize( vk::DescriptorType::eSampler, 1 ) } };
|
||||
vk::UniqueDescriptorPool descriptorPool = device->createDescriptorPoolUnique(
|
||||
vk::DescriptorPoolCreateInfo( vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet,
|
||||
1,
|
||||
static_cast<uint32_t>( poolSizes.size() ),
|
||||
poolSizes.data() ) );
|
||||
std::array<vk::DescriptorPoolSize, 3> poolSizes = {
|
||||
{ vk::DescriptorPoolSize( vk::DescriptorType::eUniformBuffer, 1 ),
|
||||
vk::DescriptorPoolSize( vk::DescriptorType::eSampledImage, 1 ),
|
||||
vk::DescriptorPoolSize( vk::DescriptorType::eSampler, 1 ) }
|
||||
};
|
||||
vk::UniqueDescriptorPool descriptorPool = device->createDescriptorPoolUnique(
|
||||
vk::DescriptorPoolCreateInfo( vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 1, poolSizes ) );
|
||||
|
||||
// Populate descriptor sets
|
||||
vk::UniqueDescriptorSet descriptorSet = std::move(
|
||||
device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, 1, &*descriptorSetLayout ) )
|
||||
device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, *descriptorSetLayout ) )
|
||||
.front() );
|
||||
|
||||
vk::DescriptorBufferInfo bufferInfo( uniformBufferData.buffer.get(), 0, sizeof( glm::mat4x4 ) );
|
||||
@ -189,11 +185,11 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
textureData.imageData->imageView.get(),
|
||||
vk::ImageLayout::eShaderReadOnlyOptimal );
|
||||
vk::DescriptorImageInfo samplerInfo( sampler.get(), {}, {} );
|
||||
std::array<vk::WriteDescriptorSet, 3> descriptorWrites = { {
|
||||
vk::WriteDescriptorSet( *descriptorSet, 0, 0, 1, vk::DescriptorType::eUniformBuffer, nullptr, &bufferInfo ),
|
||||
vk::WriteDescriptorSet( *descriptorSet, 1, 0, 1, vk::DescriptorType::eSampledImage, &imageInfo ),
|
||||
vk::WriteDescriptorSet( *descriptorSet, 2, 0, 1, vk::DescriptorType::eSampler, &samplerInfo )
|
||||
} };
|
||||
std::array<vk::WriteDescriptorSet, 3> descriptorWrites = {
|
||||
{ vk::WriteDescriptorSet( *descriptorSet, 0, 0, vk::DescriptorType::eUniformBuffer, {}, bufferInfo ),
|
||||
vk::WriteDescriptorSet( *descriptorSet, 1, 0, vk::DescriptorType::eSampledImage, imageInfo ),
|
||||
vk::WriteDescriptorSet( *descriptorSet, 2, 0, vk::DescriptorType::eSampler, samplerInfo ) }
|
||||
};
|
||||
device->updateDescriptorSets( descriptorWrites, nullptr );
|
||||
|
||||
/* VULKAN_KEY_END */
|
||||
@ -219,14 +215,13 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
assert( currentBuffer.result == vk::Result::eSuccess );
|
||||
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[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
|
||||
|
||||
vk::RenderPassBeginInfo renderPassBeginInfo( renderPass.get(),
|
||||
framebuffers[currentBuffer.value].get(),
|
||||
vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ),
|
||||
2,
|
||||
clearValues );
|
||||
commandBuffer->beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
|
||||
|
||||
@ -251,14 +246,13 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
vk::UniqueFence drawFence = device->createFenceUnique( vk::FenceCreateInfo() );
|
||||
|
||||
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() );
|
||||
|
||||
while ( vk::Result::eTimeout == device->waitForFences( drawFence.get(), VK_TRUE, vk::su::FenceTimeout ) )
|
||||
;
|
||||
|
||||
presentQueue.presentKHR(
|
||||
vk::PresentInfoKHR( 0, nullptr, 1, &swapChainData.swapChain.get(), ¤tBuffer.value ) );
|
||||
presentQueue.presentKHR( vk::PresentInfoKHR( {}, *swapChainData.swapChain, currentBuffer.value ) );
|
||||
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
|
||||
|
||||
device->waitIdle();
|
||||
@ -268,9 +262,9 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
std::cout << "vk::SystemError: " << err.what() << std::endl;
|
||||
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 );
|
||||
}
|
||||
catch ( ... )
|
||||
|
@ -173,9 +173,9 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
std::cout << "vk::SystemError: " << err.what() << std::endl;
|
||||
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 );
|
||||
}
|
||||
catch ( ... )
|
||||
|
@ -65,9 +65,9 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
std::cout << "vk::SystemError: " << err.what() << std::endl;
|
||||
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 );
|
||||
}
|
||||
catch ( ... )
|
||||
|
@ -82,7 +82,7 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
{ { vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eVertex },
|
||||
{ vk::DescriptorType::eCombinedImageSampler, 1, vk::ShaderStageFlagBits::eFragment } } );
|
||||
vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique(
|
||||
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), 1, &descriptorSetLayout.get() ) );
|
||||
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), *descriptorSetLayout ) );
|
||||
|
||||
vk::UniqueRenderPass renderPass = vk::su::createRenderPass(
|
||||
device,
|
||||
@ -109,13 +109,10 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
vk::UniqueDescriptorPool descriptorPool = vk::su::createDescriptorPool(
|
||||
device, { { vk::DescriptorType::eUniformBuffer, 1 }, { vk::DescriptorType::eCombinedImageSampler, 1 } } );
|
||||
vk::UniqueDescriptorSet descriptorSet = std::move(
|
||||
device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, 1, &*descriptorSetLayout ) )
|
||||
device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, *descriptorSetLayout ) )
|
||||
.front() );
|
||||
vk::su::updateDescriptorSets(
|
||||
device,
|
||||
descriptorSet,
|
||||
{ { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, {} } },
|
||||
textureData );
|
||||
device, descriptorSet, { { vk::DescriptorType::eUniformBuffer, uniformBufferData.buffer, {} } }, textureData );
|
||||
|
||||
vk::UniquePipelineCache pipelineCache = device->createPipelineCacheUnique( vk::PipelineCacheCreateInfo() );
|
||||
vk::UniquePipeline graphicsPipeline =
|
||||
@ -137,13 +134,12 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
assert( currentBuffer.result == vk::Result::eSuccess );
|
||||
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[1].depthStencil = vk::ClearDepthStencilValue( 1.0f, 0 );
|
||||
vk::RenderPassBeginInfo renderPassBeginInfo( renderPass.get(),
|
||||
framebuffers[currentBuffer.value].get(),
|
||||
vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ),
|
||||
2,
|
||||
clearValues );
|
||||
|
||||
commandBuffer->beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
|
||||
@ -168,14 +164,13 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
vk::UniqueFence drawFence = device->createFenceUnique( vk::FenceCreateInfo() );
|
||||
|
||||
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() );
|
||||
|
||||
while ( vk::Result::eTimeout == device->waitForFences( drawFence.get(), VK_TRUE, vk::su::FenceTimeout ) )
|
||||
;
|
||||
|
||||
presentQueue.presentKHR(
|
||||
vk::PresentInfoKHR( 0, nullptr, 1, &swapChainData.swapChain.get(), ¤tBuffer.value ) );
|
||||
presentQueue.presentKHR( vk::PresentInfoKHR( {}, *swapChainData.swapChain, currentBuffer.value ) );
|
||||
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
|
||||
|
||||
device->waitIdle();
|
||||
@ -185,9 +180,9 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
std::cout << "vk::SystemError: " << err.what() << std::endl;
|
||||
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 );
|
||||
}
|
||||
catch ( ... )
|
||||
|
@ -117,7 +117,7 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
vk::UniqueDescriptorSetLayout descriptorSetLayout = vk::su::createDescriptorSetLayout(
|
||||
device, { { vk::DescriptorType::eUniformTexelBuffer, 1, vk::ShaderStageFlagBits::eVertex } } );
|
||||
vk::UniquePipelineLayout pipelineLayout = device->createPipelineLayoutUnique(
|
||||
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), 1, &descriptorSetLayout.get() ) );
|
||||
vk::PipelineLayoutCreateInfo( vk::PipelineLayoutCreateFlags(), *descriptorSetLayout ) );
|
||||
|
||||
vk::UniqueRenderPass renderPass = vk::su::createRenderPass(
|
||||
device,
|
||||
@ -137,7 +137,7 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
vk::UniqueDescriptorPool descriptorPool =
|
||||
vk::su::createDescriptorPool( device, { { vk::DescriptorType::eUniformTexelBuffer, 1 } } );
|
||||
vk::UniqueDescriptorSet descriptorSet = std::move(
|
||||
device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, 1, &*descriptorSetLayout ) )
|
||||
device->allocateDescriptorSetsUnique( vk::DescriptorSetAllocateInfo( *descriptorPool, *descriptorSetLayout ) )
|
||||
.front() );
|
||||
vk::su::updateDescriptorSets(
|
||||
device,
|
||||
@ -174,8 +174,7 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
vk::RenderPassBeginInfo renderPassBeginInfo( renderPass.get(),
|
||||
framebuffers[currentBuffer.value].get(),
|
||||
vk::Rect2D( vk::Offset2D( 0, 0 ), surfaceData.extent ),
|
||||
1,
|
||||
&clearValue );
|
||||
clearValue );
|
||||
|
||||
commandBuffer->beginRenderPass( renderPassBeginInfo, vk::SubpassContents::eInline );
|
||||
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::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() );
|
||||
|
||||
while ( vk::Result::eTimeout == device->waitForFences( drawFence.get(), VK_TRUE, vk::su::FenceTimeout ) )
|
||||
;
|
||||
|
||||
presentQueue.presentKHR(
|
||||
vk::PresentInfoKHR( 0, nullptr, 1, &swapChainData.swapChain.get(), ¤tBuffer.value ) );
|
||||
presentQueue.presentKHR( vk::PresentInfoKHR( {}, *swapChainData.swapChain, currentBuffer.value ) );
|
||||
std::this_thread::sleep_for( std::chrono::milliseconds( 1000 ) );
|
||||
|
||||
/* VULKAN_KEY_END */
|
||||
@ -217,9 +215,9 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
std::cout << "vk::SystemError: " << err.what() << std::endl;
|
||||
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 );
|
||||
}
|
||||
catch ( ... )
|
||||
|
@ -94,8 +94,7 @@ namespace vk
|
||||
bool ok = GLSLtoSPV( shaderStage, shaderText, shaderSPV );
|
||||
assert( ok );
|
||||
|
||||
return device->createShaderModuleUnique( vk::ShaderModuleCreateInfo(
|
||||
vk::ShaderModuleCreateFlags(), shaderSPV.size() * sizeof( unsigned int ), shaderSPV.data() ) );
|
||||
return device->createShaderModuleUnique( vk::ShaderModuleCreateInfo( vk::ShaderModuleCreateFlags(), shaderSPV ) );
|
||||
}
|
||||
} // namespace su
|
||||
} // namespace vk
|
||||
|
@ -76,10 +76,8 @@ namespace vk
|
||||
} );
|
||||
assert( 0 < maxSets );
|
||||
|
||||
vk::DescriptorPoolCreateInfo descriptorPoolCreateInfo( vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet,
|
||||
maxSets,
|
||||
checked_cast<uint32_t>( poolSizes.size() ),
|
||||
poolSizes.data() );
|
||||
vk::DescriptorPoolCreateInfo descriptorPoolCreateInfo(
|
||||
vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, maxSets, poolSizes );
|
||||
return device->createDescriptorPoolUnique( descriptorPoolCreateInfo );
|
||||
}
|
||||
|
||||
@ -96,8 +94,7 @@ namespace vk
|
||||
std::get<1>( bindingData[i] ),
|
||||
std::get<2>( bindingData[i] ) );
|
||||
}
|
||||
return device->createDescriptorSetLayoutUnique(
|
||||
vk::DescriptorSetLayoutCreateInfo( flags, checked_cast<uint32_t>( bindings.size() ), bindings.data() ) );
|
||||
return device->createDescriptorSetLayoutUnique( vk::DescriptorSetLayoutCreateInfo( flags, bindings ) );
|
||||
}
|
||||
|
||||
vk::UniqueDevice createDevice( vk::PhysicalDevice physicalDevice,
|
||||
@ -117,14 +114,8 @@ namespace vk
|
||||
float queuePriority = 0.0f;
|
||||
vk::DeviceQueueCreateInfo deviceQueueCreateInfo(
|
||||
vk::DeviceQueueCreateFlags(), queueFamilyIndex, 1, &queuePriority );
|
||||
vk::DeviceCreateInfo deviceCreateInfo( vk::DeviceCreateFlags(),
|
||||
1,
|
||||
&deviceQueueCreateInfo,
|
||||
0,
|
||||
nullptr,
|
||||
checked_cast<uint32_t>( enabledExtensions.size() ),
|
||||
enabledExtensions.data(),
|
||||
physicalDeviceFeatures );
|
||||
vk::DeviceCreateInfo deviceCreateInfo(
|
||||
vk::DeviceCreateFlags(), deviceQueueCreateInfo, {}, enabledExtensions, physicalDeviceFeatures );
|
||||
deviceCreateInfo.pNext = pNext;
|
||||
return physicalDevice.createDeviceUnique( deviceCreateInfo );
|
||||
}
|
||||
@ -168,7 +159,7 @@ namespace vk
|
||||
vk::UniquePipelineLayout const & pipelineLayout,
|
||||
vk::UniqueRenderPass const & renderPass )
|
||||
{
|
||||
vk::PipelineShaderStageCreateInfo pipelineShaderStageCreateInfos[2] = {
|
||||
std::array<vk::PipelineShaderStageCreateInfo, 2> pipelineShaderStageCreateInfos = {
|
||||
vk::PipelineShaderStageCreateInfo( vk::PipelineShaderStageCreateFlags(),
|
||||
vk::ShaderStageFlagBits::eVertex,
|
||||
vertexShaderData.first,
|
||||
@ -193,11 +184,8 @@ namespace vk
|
||||
vertexInputAttributeDescriptions.push_back( vk::VertexInputAttributeDescription(
|
||||
i, 0, vertexInputAttributeFormatOffset[i].first, vertexInputAttributeFormatOffset[i].second ) );
|
||||
}
|
||||
pipelineVertexInputStateCreateInfo.vertexBindingDescriptionCount = 1;
|
||||
pipelineVertexInputStateCreateInfo.pVertexBindingDescriptions = &vertexInputBindingDescription;
|
||||
pipelineVertexInputStateCreateInfo.vertexAttributeDescriptionCount =
|
||||
vk::su::checked_cast<uint32_t>( vertexInputAttributeDescriptions.size() );
|
||||
pipelineVertexInputStateCreateInfo.pVertexAttributeDescriptions = vertexInputAttributeDescriptions.data();
|
||||
pipelineVertexInputStateCreateInfo.setVertexBindingDescriptions( vertexInputBindingDescription );
|
||||
pipelineVertexInputStateCreateInfo.setVertexAttributeDescriptions( vertexInputAttributeDescriptions );
|
||||
}
|
||||
|
||||
vk::PipelineInputAssemblyStateCreateInfo pipelineInputAssemblyStateCreateInfo(
|
||||
@ -246,16 +234,14 @@ namespace vk
|
||||
vk::PipelineColorBlendStateCreateInfo pipelineColorBlendStateCreateInfo( vk::PipelineColorBlendStateCreateFlags(),
|
||||
false,
|
||||
vk::LogicOp::eNoOp,
|
||||
1,
|
||||
&pipelineColorBlendAttachmentState,
|
||||
pipelineColorBlendAttachmentState,
|
||||
{ { 1.0f, 1.0f, 1.0f, 1.0f } } );
|
||||
|
||||
vk::DynamicState dynamicStates[2] = { vk::DynamicState::eViewport, vk::DynamicState::eScissor };
|
||||
vk::PipelineDynamicStateCreateInfo pipelineDynamicStateCreateInfo(
|
||||
vk::PipelineDynamicStateCreateFlags(), 2, dynamicStates );
|
||||
std::array<vk::DynamicState, 2> dynamicStates = { vk::DynamicState::eViewport, vk::DynamicState::eScissor };
|
||||
vk::PipelineDynamicStateCreateInfo pipelineDynamicStateCreateInfo( vk::PipelineDynamicStateCreateFlags(),
|
||||
dynamicStates );
|
||||
|
||||
vk::GraphicsPipelineCreateInfo graphicsPipelineCreateInfo( vk::PipelineCreateFlags(),
|
||||
2,
|
||||
pipelineShaderStageCreateInfos,
|
||||
&pipelineVertexInputStateCreateInfo,
|
||||
&pipelineInputAssemblyStateCreateInfo,
|
||||
@ -346,12 +332,7 @@ namespace vk
|
||||
#if defined( NDEBUG )
|
||||
// in non-debug mode just use the InstanceCreateInfo for instance creation
|
||||
vk::StructureChain<vk::InstanceCreateInfo> instanceCreateInfo(
|
||||
{ {},
|
||||
&applicationInfo,
|
||||
checked_cast<uint32_t>( enabledLayers.size() ),
|
||||
enabledLayers.data(),
|
||||
checked_cast<uint32_t>( enabledExtensions.size() ),
|
||||
enabledExtensions.data() } );
|
||||
{ {}, &applicationInfo, enabledLayers, enabledExtensions } );
|
||||
#else
|
||||
// in debug mode, addionally use the debugUtilsMessengerCallback in instance creation!
|
||||
vk::DebugUtilsMessageSeverityFlagsEXT severityFlags( vk::DebugUtilsMessageSeverityFlagBitsEXT::eWarning |
|
||||
@ -360,12 +341,7 @@ namespace vk
|
||||
vk::DebugUtilsMessageTypeFlagBitsEXT::ePerformance |
|
||||
vk::DebugUtilsMessageTypeFlagBitsEXT::eValidation );
|
||||
vk::StructureChain<vk::InstanceCreateInfo, vk::DebugUtilsMessengerCreateInfoEXT> instanceCreateInfo(
|
||||
{ {},
|
||||
&applicationInfo,
|
||||
checked_cast<uint32_t>( enabledLayers.size() ),
|
||||
enabledLayers.data(),
|
||||
checked_cast<uint32_t>( enabledExtensions.size() ),
|
||||
enabledExtensions.data() },
|
||||
{ {}, &applicationInfo, enabledLayers, enabledExtensions },
|
||||
{ {}, severityFlags, messageTypeFlags, &vk::su::debugUtilsMessengerCallback } );
|
||||
#endif
|
||||
vk::UniqueInstance instance = vk::createInstanceUnique( instanceCreateInfo.get<vk::InstanceCreateInfo>() );
|
||||
@ -412,19 +388,13 @@ namespace vk
|
||||
vk::AttachmentReference depthAttachment( 1, vk::ImageLayout::eDepthStencilAttachmentOptimal );
|
||||
vk::SubpassDescription subpassDescription( vk::SubpassDescriptionFlags(),
|
||||
vk::PipelineBindPoint::eGraphics,
|
||||
0,
|
||||
nullptr,
|
||||
1,
|
||||
&colorAttachment,
|
||||
nullptr,
|
||||
{},
|
||||
colorAttachment,
|
||||
{},
|
||||
( depthFormat != vk::Format::eUndefined ) ? &depthAttachment
|
||||
: nullptr );
|
||||
return device->createRenderPassUnique(
|
||||
vk::RenderPassCreateInfo( vk::RenderPassCreateFlags(),
|
||||
static_cast<uint32_t>( attachmentDescriptions.size() ),
|
||||
attachmentDescriptions.data(),
|
||||
1,
|
||||
&subpassDescription ) );
|
||||
vk::RenderPassCreateInfo( vk::RenderPassCreateFlags(), attachmentDescriptions, subpassDescription ) );
|
||||
}
|
||||
|
||||
VKAPI_ATTR VkBool32 VKAPI_CALL
|
||||
@ -753,8 +723,7 @@ namespace vk
|
||||
void submitAndWait( vk::UniqueDevice & device, vk::Queue queue, vk::UniqueCommandBuffer & commandBuffer )
|
||||
{
|
||||
vk::UniqueFence fence = device->createFenceUnique( vk::FenceCreateInfo() );
|
||||
vk::PipelineStageFlags pipelineStageFlags = vk::PipelineStageFlagBits::eColorAttachmentOutput;
|
||||
queue.submit( vk::SubmitInfo( 0, nullptr, &pipelineStageFlags, 1, &commandBuffer.get() ), fence.get() );
|
||||
queue.submit( vk::SubmitInfo( {}, {}, *commandBuffer ), fence.get() );
|
||||
while ( vk::Result::eTimeout == device->waitForFences( fence.get(), VK_TRUE, vk::su::FenceTimeout ) )
|
||||
;
|
||||
}
|
||||
@ -789,7 +758,7 @@ namespace vk
|
||||
vk::DescriptorImageInfo imageInfo(
|
||||
*textureData.textureSampler, *textureData.imageData->imageView, vk::ImageLayout::eShaderReadOnlyOptimal );
|
||||
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 );
|
||||
}
|
||||
@ -896,8 +865,7 @@ namespace vk
|
||||
tiling,
|
||||
usage | vk::ImageUsageFlagBits::eSampled,
|
||||
vk::SharingMode::eExclusive,
|
||||
0,
|
||||
nullptr,
|
||||
{},
|
||||
initialLayout );
|
||||
image = device->createImageUnique( imageCreateInfo );
|
||||
|
||||
@ -981,8 +949,7 @@ namespace vk
|
||||
1,
|
||||
usage,
|
||||
vk::SharingMode::eExclusive,
|
||||
0,
|
||||
nullptr,
|
||||
{},
|
||||
preTransform,
|
||||
compositeAlpha,
|
||||
presentMode,
|
||||
|
@ -47,7 +47,7 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
vk::DeviceQueueCreateInfo deviceQueueCreateInfo(
|
||||
vk::DeviceQueueCreateFlags(), static_cast<uint32_t>( graphicsQueueFamilyIndex ), 1, &queuePriority );
|
||||
vk::UniqueDevice device =
|
||||
physicalDevice.createDeviceUnique( vk::DeviceCreateInfo( vk::DeviceCreateFlags(), 1, &deviceQueueCreateInfo ) );
|
||||
physicalDevice.createDeviceUnique( vk::DeviceCreateInfo( vk::DeviceCreateFlags(), deviceQueueCreateInfo ) );
|
||||
|
||||
std::vector<uint8_t> data;
|
||||
device->getAccelerationStructureHandleNV<uint8_t>( {}, data, vk::DispatchLoaderDynamic() );
|
||||
|
@ -60,7 +60,7 @@ int main( int /*argc*/, char ** /*argv*/ )
|
||||
vk::DeviceQueueCreateFlags(), static_cast<uint32_t>( graphicsQueueFamilyIndex ), 1, &queuePriority );
|
||||
vk::UniqueDevice device =
|
||||
physicalDevices[0]
|
||||
.createDeviceUnique( vk::DeviceCreateInfo( vk::DeviceCreateFlags(), 1, &deviceQueueCreateInfo ) )
|
||||
.createDeviceUnique( vk::DeviceCreateInfo( vk::DeviceCreateFlags(), deviceQueueCreateInfo ) )
|
||||
.value;
|
||||
VULKAN_HPP_DEFAULT_DISPATCHER.init( *device );
|
||||
|
||||
|
1654
vulkan/vulkan.hpp
1654
vulkan/vulkan.hpp
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user