Skip to content

Commit

Permalink
Formatting, signposting, misc fixes
Browse files Browse the repository at this point in the history
- Added newlines around macro guards
- Added signposting comments for relevant groups of `using`-statements in `vulkan.ixx`
- Guarded createInstanceUnique with macro guard
- Use m_handles.at("").commands for Funcs
  • Loading branch information
sharadhr committed Jun 16, 2023
1 parent 0f2c66c commit 7b4969b
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 47 deletions.
133 changes: 92 additions & 41 deletions VulkanHppGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4731,12 +4731,12 @@ std::pair<std::string, std::string> VulkanHppGenerator::generateConstexprDefines

auto constexprDefines = std::stringstream{} << R"(
//=========================================
//=== CONSTEXPR VARIABLES AND FUNCTIONS ===
//=== CONSTEXPR VARIABLEs AND FUNCTIONs ===
//=========================================
)";
auto constexprUsings = std::stringstream{} << R"(
//=========================================
//=== CONSTEXPR VARIABLES AND FUNCTIONS ===
//=== CONSTEXPR VARIABLEs AND FUNCTIONs ===
//=========================================
)";

Expand Down Expand Up @@ -4824,9 +4824,10 @@ std::pair<std::string, std::string> VulkanHppGenerator::generateConstexprDefines
}
// trim the last two characters (i.e. the last comma and the space)
argumentsString.resize( argumentsString.size() - 2 );
auto const callerString =
replaceWithMap( constexprCallTemplate,
{ { "arguments", argumentsString }, { "callee", startLowerCase( data.possibleCallee ) }, { "constName", constName }, { "deprecated", deprecated } } );

auto const callerString = replaceWithMap(
constexprCallTemplate,
{ { "arguments", argumentsString }, { "callee", startLowerCase( data.possibleCallee ) }, { "constName", constName }, { "deprecated", deprecated } } );
constexprDefines << callerString;
constexprUsings << replaceWithMap( constexprUsingTemplate, { { "constName", constName } } );
}
Expand All @@ -4839,7 +4840,11 @@ std::string VulkanHppGenerator::generateCppModuleHandleUsings() const
auto const usingTemplate = std::string{ R"( using VULKAN_HPP_NAMESPACE::${className};
)" };

auto handleUsings = std::stringstream{};
auto handleUsings = std::stringstream{} << R"(
//===============
//=== HANDLEs ===
//===============
)";

auto const generateUsingsAndProtection = [&usingTemplate, this]( std::vector<RequireData> const & requireData, std::string const & title )
{
Expand Down Expand Up @@ -4875,7 +4880,11 @@ std::string VulkanHppGenerator::generateCppModuleStructUsings() const
auto const usingTemplate = std::string{ R"( using VULKAN_HPP_NAMESPACE::${structName};
)" };

auto structUsings = std::stringstream{};
auto structUsings = std::stringstream{} << R"(
//===============
//=== STRUCTs ===
//===============
)";
auto listedStructs = std::set<std::string>{};

auto const generateUsingsAndProtection = [&listedStructs, &usingTemplate, this]( std::vector<RequireData> const & requireData, std::string const & title )
Expand Down Expand Up @@ -4930,10 +4939,14 @@ std::string VulkanHppGenerator::generateCppModuleUniqueHandleUsings() const
auto const usingTemplate = std::string{ R"( using VULKAN_HPP_NAMESPACE::Unique${handleName};
)" };

auto uniqueHandleUsings = std::stringstream{};
auto uniqueHandleUsings = std::stringstream{} << R"(
//======================
//=== UNIQUE HANDLEs ===
//======================
)";
auto const [smartHandleEnter, smartHandleLeave] = generateNotProtection( "VULKAN_HPP_NO_SMART_HANDLE" );

uniqueHandleUsings << smartHandleEnter;
uniqueHandleUsings << std::endl << smartHandleEnter;

auto const generateUsingsAndProtection = [&usingTemplate, this]( std::vector<RequireData> const & requireData, std::string const & title )
{
Expand Down Expand Up @@ -4961,10 +4974,10 @@ std::string VulkanHppGenerator::generateCppModuleUniqueHandleUsings() const
uniqueHandleUsings << generateUsingsAndProtection( extension.requireData, extension.name );
}

uniqueHandleUsings << replaceWithMap( R"( using VULKAN_HPP_NAMESPACE::${handleName};
)",
{ { "handleName", "UniqueHandleTraits" } } );
uniqueHandleUsings << smartHandleLeave;
uniqueHandleUsings << R"( using VULKAN_HPP_NAMESPACE::UniqueHandleTraits;
)";

uniqueHandleUsings << smartHandleLeave << std::endl;

return uniqueHandleUsings.str();
}
Expand All @@ -4973,18 +4986,21 @@ std::string VulkanHppGenerator::generateCppModuleFuncsUsings() const
{
auto const usingTemplate = std::string{ R"( using VULKAN_HPP_NAMESPACE::${funcName};
)" };

auto funcUsings = std::stringstream{} << R"( //===========================
//=== COMMAND Definitions ===
//===========================
)";

// TODO: generate the loose functions in `vulkan_funcs.hpp` instead of hard-coding them here
auto funcUsings = std::stringstream{};
auto const funcs = std::array{
"createInstance", "createInstanceUnique", "enumerateInstanceExtensionProperties", "enumerateInstanceLayerProperties", "enumerateInstanceVersion"
};

for ( auto const & func : funcs )
for ( auto const & func :
m_handles.at( "" ).commands | std::views::transform( []( auto const & func ) { return startLowerCase( stripPrefix( func, "vk" ) ); } ) )
{
funcUsings << replaceWithMap( usingTemplate, { { "funcName", func } } );
}

auto const [enter, leave] = generateNotProtection( "VULKAN_HPP_NO_SMART_HANDLE" );
funcUsings << std::endl << enter << replaceWithMap( usingTemplate, { { "funcName", "createInstanceUnique" } } ) << leave << std::endl;

return funcUsings.str();
}

Expand All @@ -4993,7 +5009,11 @@ std::string VulkanHppGenerator::generateCppModuleEnumUsings() const
auto const usingTemplate = std::string{ R"( using VULKAN_HPP_NAMESPACE::${enumName};
)" };

auto enumUsings = std::stringstream{};
auto enumUsings = std::stringstream{} << R"(
//=============
//=== ENUMs ===
//=============
)";
auto listedEnums = std::set<std::string>{};

// insert CppType first
Expand Down Expand Up @@ -5039,7 +5059,12 @@ std::string VulkanHppGenerator::generateCppModuleEnumUsings() const
}

// finally insert IndexTypeValue
enumUsings << replaceWithMap( usingTemplate, { { "enumName", "IndexTypeValue" } } );
auto const indexTypeComment = R"(
//=========================
//=== Index Type Traits ===
//=========================
)";
enumUsings << indexTypeComment << replaceWithMap( usingTemplate, { { "enumName", "IndexTypeValue" } } );

return enumUsings.str();
}
Expand All @@ -5054,7 +5079,10 @@ std::string VulkanHppGenerator::generateCppModuleUsings() const
std::array{ "ArrayProxy", "ArrayProxyNoTemporaries", "StridedArrayProxy", "Optional", "StructureChain", "UniqueHandle" };
auto const hardCodedSmartHandleTypes = std::array{ "ObjectDestroy", "ObjectFree", "ObjectRelease", "PoolFree" };

auto usings = std::stringstream{};
auto usings = std::stringstream{} << R"( //=====================================
//=== HARDCODED TYPEs AND FUNCTIONs ===
//=====================================
)";

for ( auto const & className : hardCodedTypes )
{
Expand All @@ -5063,9 +5091,7 @@ std::string VulkanHppGenerator::generateCppModuleUsings() const

auto const & [noPrototypesEnter, noPrototypesLeave] = generateNotProtection( "VK_NO_PROTOTYPES" );

usings << noPrototypesEnter;
usings << replaceWithMap( usingTemplate, { { "className", "DispatchLoaderStatic" } } );
usings << noPrototypesLeave;
usings << std::endl << noPrototypesEnter << replaceWithMap( usingTemplate, { { "className", "DispatchLoaderStatic" } } ) << noPrototypesLeave << std::endl;

// insert the Flags bitwise operators
auto const flagsBitWiseOperatorsUsings = std::array{ "operator&", "operator|", "operator^", "operator~" };
Expand All @@ -5075,7 +5101,8 @@ std::string VulkanHppGenerator::generateCppModuleUsings() const
}

// delete the namespace declaration for the default dispatcher macro using statement
usings << replaceWithMap( "using ${macro};", { { "macro", "VULKAN_HPP_DEFAULT_DISPATCHER_TYPE" } } ) << std::endl;
usings << R"(using VULKAN_HPP_DEFAULT_DISPATCHER_TYPE;
)";

auto enhancedModeUsings = std::stringstream{};
for ( auto const & className : hardCodedEnhancedModeTypes )
Expand All @@ -5084,7 +5111,7 @@ std::string VulkanHppGenerator::generateCppModuleUsings() const
}
// protect the enhanced-mode usings with a macro
auto [enterEnhancedMode, leaveEnhancedMode] = generateNotProtection( "VULKAN_HPP_DISABLE_ENHANCED_MODE" );
usings << enterEnhancedMode << enhancedModeUsings.rdbuf() << leaveEnhancedMode;
usings << std::endl << enterEnhancedMode << enhancedModeUsings.rdbuf() << leaveEnhancedMode << std::endl;

auto noSmartHandleUsings = std::stringstream{};
for ( auto const & className : hardCodedSmartHandleTypes )
Expand All @@ -5093,10 +5120,14 @@ std::string VulkanHppGenerator::generateCppModuleUsings() const
}
// likewise for the smart-handle usings
auto [enterNoSmartHandle, leaveNoSmartHandle] = generateNotProtection( "VULKAN_HPP_NO_SMART_HANDLE" );
usings << enterNoSmartHandle << noSmartHandleUsings.str() << leaveNoSmartHandle;
usings << std::endl << enterNoSmartHandle << noSmartHandleUsings.str() << leaveNoSmartHandle << std::endl;

// now generate baseTypes
auto baseTypes = std::stringstream{};
auto baseTypes = std::stringstream{} << R"(
//==================
//=== BASE TYPEs ===
//==================
)";
for ( auto const & baseType : m_baseTypes )
{
if ( baseType.first != "VkFlags" && baseType.first != "VkFlags64" && !baseType.second.typeInfo.type.empty() )
Expand All @@ -5113,25 +5144,34 @@ std::string VulkanHppGenerator::generateCppModuleUsings() const
auto const toString = std::array{ "to_string", "toHexString" };
auto const [toStringEnter, toStringLeave] = generateNotProtection( "VULKAN_HPP_NO_TO_STRING" );

usings << toStringEnter;
usings << R"(
//======================
//=== ENUM to_string ===
//======================
)" << toStringEnter;
for ( auto const & name : toString )
{
usings << replaceWithMap( usingTemplate, { { "className", name } } );
}
usings << toStringLeave;
usings << toStringLeave << std::endl;

// hardcoded exceptions and functions
auto const hardCodedExceptionTypesAndFunctions =
std::array{ "ErrorCategoryImpl", "Error", "LogicError", "SystemError", "errorCategory", "make_error_code", "make_error_condition" };
auto [exceptionsEnter, exceptionsLeave] = generateNotProtection( "VULKAN_HPP_NO_EXCEPTIONS" );

auto exceptionsUsings = std::stringstream{};
auto exceptionsUsings = std::stringstream{} << R"(
//=============================
//=== EXCEPTIONs AND ERRORs ===
//=============================
)" << exceptionsEnter;

for ( auto const & name : hardCodedExceptionTypesAndFunctions )
{
exceptionsUsings << replaceWithMap( usingTemplate, { { "className", name } } );
}
auto [exceptionsEnter, exceptionsLeave] = generateNotProtection( "VULKAN_HPP_NO_EXCEPTIONS" );

usings << exceptionsEnter << exceptionsUsings.rdbuf();
usings << exceptionsUsings.rdbuf();

// result Exceptions
auto resultExceptionsUsings = std::stringstream{};
Expand All @@ -5141,14 +5181,18 @@ std::string VulkanHppGenerator::generateCppModuleUsings() const
if ( alias.empty() && enumName.starts_with( "VK_ERROR" ) )
{
auto [enter, leave] = generateProtection( protect );
enter = enter.empty() ? enter : "\n" + enter;
leave = leave.empty() ? leave : leave + "\n";

auto const valueName = generateEnumValueName( name, enumName, false );
auto const className = stripPrefix( valueName, "eError" ) + "Error";

resultExceptionsUsings << enter << replaceWithMap( usingTemplate, { { "className", className } } ) << leave;
}
}
usings << resultExceptionsUsings.rdbuf();

usings << exceptionsLeave;
usings << exceptionsLeave << std::endl;

// ResultValue
auto const hardCodedResultValueTypes = std::array{ "ignore", "ResultValue", "ResultValueType", "createResultValueType" };
Expand All @@ -5167,10 +5211,10 @@ std::string VulkanHppGenerator::generateCppModuleUsings() const
usings << generateCppModuleFuncsUsings();

auto const [enterDisableEnhanced, leaveDisableEnhanced] = generateNotProtection( "VULKAN_HPP_DISABLE_ENHANCED_MODE" );
usings << enterDisableEnhanced << replaceWithMap( usingTemplate, { { "className", "StructExtends" } } ) << leaveDisableEnhanced;
usings << std::endl << enterDisableEnhanced << replaceWithMap( usingTemplate, { { "className", "StructExtends" } } ) << leaveDisableEnhanced << std::endl;

auto const [enterDynamicLoader, leaveDynamicLoader] = generateProtection( "VULKAN_HPP_DYNAMIC_LOADER_TOOL" );
usings << enterDynamicLoader << replaceWithMap( usingTemplate, { { "className", "DynamicLoader" } } ) << leaveDynamicLoader;
usings << std::endl << enterDynamicLoader << replaceWithMap( usingTemplate, { { "className", "DynamicLoader" } } ) << leaveDynamicLoader << std::endl;

usings << replaceWithMap( usingTemplate, { { "className", "DispatchLoaderDynamic" } } ) << std::endl;

Expand All @@ -5184,15 +5228,22 @@ std::string VulkanHppGenerator::generateCppModuleRaiiUsings() const
auto usings = std::stringstream{};

// A lot of hard-coded stuff spread throughout the RAII generators, which we consolidate here
auto const hardcoded = R"( using VULKAN_HPP_RAII_NAMESPACE::exchange;
auto const hardcoded = R"( //======================
//=== RAII HARDCODED ===
//======================

using VULKAN_HPP_RAII_NAMESPACE::exchange;
using VULKAN_HPP_RAII_NAMESPACE::Context;
using VULKAN_HPP_RAII_NAMESPACE::ContextDispatcher;
using VULKAN_HPP_RAII_NAMESPACE::InstanceDispatcher;
using VULKAN_HPP_RAII_NAMESPACE::DeviceDispatcher;

)";

usings << hardcoded;
usings << hardcoded << R"(
//====================
//=== RAII HANDLEs ===
//====================
)";

// now, insert features and extensions with protection, and strip Vk prefix
for ( auto const & feature : m_features )
Expand Down
1 change: 0 additions & 1 deletion VulkanHppGenerator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,6 @@ class VulkanHppGenerator
std::map<std::string, AliasData> m_commandAliases;
std::map<std::string, CommandData> m_commands;
std::map<std::string, AliasData> m_constantAliases;
std::vector<std::string> m_constexprs;
std::map<std::string, ConstantData> m_constants;
std::map<std::string, DefineData> m_defines;
std::map<std::string, AliasData> m_enumAliases;
Expand Down
2 changes: 1 addition & 1 deletion vulkan/vulkan.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16916,7 +16916,7 @@ namespace VULKAN_HPP_NAMESPACE
};

//=========================================
//=== CONSTEXPR VARIABLES AND FUNCTIONS ===
//=== CONSTEXPR VARIABLEs AND FUNCTIONs ===
//=========================================
VULKAN_HPP_CONSTEXPR uint32_t AttachmentUnused = VK_ATTACHMENT_UNUSED;
VULKAN_HPP_CONSTEXPR uint32_t False = VK_FALSE;
Expand Down
Loading

0 comments on commit 7b4969b

Please sign in to comment.