Skip to content

Commit

Permalink
Moved constexprs to vulkan.hpp
Browse files Browse the repository at this point in the history
- Added `using` statements to `vulkan.ixx`
  • Loading branch information
sharadhr committed Jun 15, 2023
1 parent 8c16a3b commit e94a6a0
Show file tree
Hide file tree
Showing 4 changed files with 176 additions and 106 deletions.
33 changes: 27 additions & 6 deletions VulkanHppGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@ namespace VULKAN_HPP_NAMESPACE

${DynamicLoader}
${DispatchLoaderDynamic}
${constexprDefines}
} // namespace VULKAN_HPP_NAMESPACE
#endif
)";
Expand All @@ -506,6 +507,7 @@ namespace VULKAN_HPP_NAMESPACE
{ "ArrayWrapper1D", readSnippet( "ArrayWrapper1D.hpp" ) },
{ "ArrayWrapper2D", readSnippet( "ArrayWrapper2D.hpp" ) },
{ "baseTypes", generateBaseTypes() },
{ "constexprDefines", generateConstexprDefinesAndUsings().first },
{ "defines", readSnippet( "defines.hpp" ) },
{ "DispatchLoaderBase", readSnippet( "DispatchLoaderBase.hpp" ) },
{ "DispatchLoaderDefault", readSnippet( "DispatchLoaderDefault.hpp" ) },
Expand Down Expand Up @@ -685,10 +687,11 @@ export module ${api};
export namespace VULKAN_HPP_NAMESPACE
{
${usings}

${constexprUsings}
export namespace VULKAN_HPP_RAII_NAMESPACE {
${raiiUsings}
} // namespace VULKAN_HPP_RAII_NAMESPACE
${constexprDefines}
} // namespace VULKAN_HPP_NAMESPACE
)";

Expand All @@ -697,7 +700,7 @@ export namespace VULKAN_HPP_NAMESPACE
{ "api", m_api },
{ "usings", generateCppModuleUsings() },
{ "raiiUsings", generateCppModuleRaiiUsings() },
{ "constexprDefines", generateCppModuleConstexprDefines() } } );
{ "constexprUsings", generateConstexprDefinesAndUsings().second } } );

writeToFile( str, vulkan_ixx );
}
Expand Down Expand Up @@ -4710,7 +4713,7 @@ std::string VulkanHppGenerator::generateConstexprString( std::string const & str
return isConstExpression ? ( std::string( "VULKAN_HPP_CONSTEXPR" ) + ( ( containsUnion( structName ) || containsArray( structName ) ) ? "_14 " : " " ) ) : "";
}

std::string VulkanHppGenerator::generateCppModuleConstexprDefines() const
std::pair<std::string, std::string> VulkanHppGenerator::generateConstexprDefinesAndUsings() const
{
auto const constexprFunctionTemplate = std::string{ R"( ${deprecated}consteval auto ${constName}( ${arguments} )
{
Expand All @@ -4723,7 +4726,19 @@ std::string VulkanHppGenerator::generateCppModuleConstexprDefines() const
)" };
auto const deprecatedAttribute = std::string{ R"([[deprecated("${reason}")]] )" };

auto constexprDefines = std::stringstream{};
auto const constexprUsingTemplate = std::string{ R"( using VULKAN_HPP_NAMESPACE::${constName};
)" };

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

// handle the value and callee macros first so they are visible for use in functions below.

Expand All @@ -4732,8 +4747,10 @@ std::string VulkanHppGenerator::generateCppModuleConstexprDefines() const
{
// make `macro` PascalCase, and strip the `Vk` prefix
auto const constName = stripPrefix( toPascalCase( macro ), "Vk" );

constexprDefines << replaceWithMap( constexprValueTemplate,
{ { "type", data.type }, { "constName", constName }, { "deprecated", "" }, { "value", macro } } );
constexprUsings << replaceWithMap( constexprUsingTemplate, { { "constName", constName } } );
}

// M_DEFINE_HANDLE is macro magic that cannot be constexpr-ed
Expand All @@ -4757,7 +4774,9 @@ std::string VulkanHppGenerator::generateCppModuleConstexprDefines() const
auto const constName = stripPrefix( toPascalCase( macro ), "Vk" );
auto const valueString =
replaceWithMap( constexprValueTemplate, { { "type", "uint32_t" }, { "constName", constName }, { "deprecated", deprecated }, { "value", macro } } );

constexprDefines << valueString;
constexprUsings << replaceWithMap( constexprUsingTemplate, { { "constName", constName } } );
}

// functions
Expand All @@ -4784,6 +4803,7 @@ std::string VulkanHppGenerator::generateCppModuleConstexprDefines() const
{ { "arguments", parametersString }, { "constName", constName }, { "deprecated", deprecated }, { "implementation", data.possibleDefinition } } );

constexprDefines << functionString;
constexprUsings << replaceWithMap( constexprUsingTemplate, { { "constName", constName } } );
}

// callers
Expand All @@ -4795,7 +4815,7 @@ std::string VulkanHppGenerator::generateCppModuleConstexprDefines() const
{
auto const deprecated = data.deprecated ? replaceWithMap( deprecatedAttribute, { { "reason", data.deprecationReason } } ) : "";
// make `macro` PascalCase and strip the `Vk` prefix
auto const constName = stripPrefix( toCamelCase( macro ), "Vk" );
auto const constName = stripPrefix( toCamelCase( macro ), "Vk" );
auto argumentsString = std::string{};
// for every argument, append a comma if needed if needed (i.e. has more than one parameter, and not for the last one)
for ( auto const & argString : data.params )
Expand All @@ -4808,9 +4828,10 @@ std::string VulkanHppGenerator::generateCppModuleConstexprDefines() const
replaceWithMap( constexprCallTemplate,
{ { "arguments", argumentsString }, { "callee", data.possibleCallee }, { "constName", constName }, { "deprecated", deprecated } } );
constexprDefines << callerString;
constexprUsings << replaceWithMap( constexprUsingTemplate, { { "constName", constName } } );
}

return constexprDefines.str();
return { constexprDefines.str(), constexprUsings.str() };
}

std::string VulkanHppGenerator::generateCppModuleHandleUsings() const
Expand Down
39 changes: 20 additions & 19 deletions VulkanHppGenerator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -654,25 +654,25 @@ class VulkanHppGenerator
bool definition,
std::vector<size_t> const & returnParamIndices,
bool raii ) const;
std::string generateConstexprString( std::string const & structName ) const;
std::string generateCppModuleConstexprDefines() const;
std::string generateCppModuleHandleUsings() const;
std::string generateCppModuleStructUsings() const;
std::string generateCppModuleUniqueHandleUsings() const;
std::string generateCppModuleFuncsUsings() const;
std::string generateCppModuleEnumUsings() const;
std::string generateCppModuleUsings() const;
std::string generateCppModuleRaiiUsings() const;
std::string generateDataDeclarations( CommandData const & commandData,
std::vector<size_t> const & returnParams,
std::map<size_t, VectorParamData> const & vectorParams,
std::set<size_t> const & templatedParams,
CommandFlavourFlags flavourFlags,
bool raii,
std::vector<std::string> const & dataTypes,
std::string const & dataType,
std::string const & returnType,
std::string const & returnVariable ) const;
std::string generateConstexprString( std::string const & structName ) const;
std::pair<std::string, std::string> generateConstexprDefinesAndUsings() const;
std::string generateCppModuleHandleUsings() const;
std::string generateCppModuleStructUsings() const;
std::string generateCppModuleUniqueHandleUsings() const;
std::string generateCppModuleFuncsUsings() const;
std::string generateCppModuleEnumUsings() const;
std::string generateCppModuleUsings() const;
std::string generateCppModuleRaiiUsings() const;
std::string generateDataDeclarations( CommandData const & commandData,
std::vector<size_t> const & returnParams,
std::map<size_t, VectorParamData> const & vectorParams,
std::set<size_t> const & templatedParams,
CommandFlavourFlags flavourFlags,
bool raii,
std::vector<std::string> const & dataTypes,
std::string const & dataType,
std::string const & returnType,
std::string const & returnVariable ) const;
std::string generateDataDeclarations1Return( CommandData const & commandData,
std::vector<size_t> const & returnParams,
std::map<size_t, VectorParamData> const & vectorParams,
Expand Down Expand Up @@ -1053,6 +1053,7 @@ 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
84 changes: 84 additions & 0 deletions vulkan/vulkan.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16914,5 +16914,89 @@ namespace VULKAN_HPP_NAMESPACE
init( instance, device, dl );
}
};

//=========================================
//=== CONSTEXPR VARIABLES AND FUNCTIONS ===
//=========================================
constexpr uint32_t AttachmentUnused = VK_ATTACHMENT_UNUSED;
constexpr uint32_t False = VK_FALSE;
constexpr float LodClampNone = VK_LOD_CLAMP_NONE;
constexpr uint32_t LuidSize = VK_LUID_SIZE;
constexpr uint32_t MaxDescriptionSize = VK_MAX_DESCRIPTION_SIZE;
constexpr uint32_t MaxDeviceGroupSize = VK_MAX_DEVICE_GROUP_SIZE;
constexpr uint32_t MaxDriverInfoSize = VK_MAX_DRIVER_INFO_SIZE;
constexpr uint32_t MaxDriverNameSize = VK_MAX_DRIVER_NAME_SIZE;
constexpr uint32_t MaxExtensionNameSize = VK_MAX_EXTENSION_NAME_SIZE;
constexpr uint32_t MaxGlobalPrioritySizeKhr = VK_MAX_GLOBAL_PRIORITY_SIZE_KHR;
constexpr uint32_t MaxMemoryHeaps = VK_MAX_MEMORY_HEAPS;
constexpr uint32_t MaxMemoryTypes = VK_MAX_MEMORY_TYPES;
constexpr uint32_t MaxPhysicalDeviceNameSize = VK_MAX_PHYSICAL_DEVICE_NAME_SIZE;
constexpr uint32_t MaxShaderModuleIdentifierSizeExt = VK_MAX_SHADER_MODULE_IDENTIFIER_SIZE_EXT;
constexpr uint32_t QueueFamilyExternal = VK_QUEUE_FAMILY_EXTERNAL;
constexpr uint32_t QueueFamilyForeignExt = VK_QUEUE_FAMILY_FOREIGN_EXT;
constexpr uint32_t QueueFamilyIgnored = VK_QUEUE_FAMILY_IGNORED;
constexpr uint32_t Remaining3DSlicesExt = VK_REMAINING_3D_SLICES_EXT;
constexpr uint32_t RemainingArrayLayers = VK_REMAINING_ARRAY_LAYERS;
constexpr uint32_t RemainingMipLevels = VK_REMAINING_MIP_LEVELS;
constexpr uint32_t ShaderUnusedKhr = VK_SHADER_UNUSED_KHR;
constexpr uint32_t SubpassExternal = VK_SUBPASS_EXTERNAL;
constexpr uint32_t True = VK_TRUE;
constexpr uint32_t UuidSize = VK_UUID_SIZE;
constexpr uint64_t WholeSize = VK_WHOLE_SIZE;
constexpr uint32_t HeaderVersion = VK_HEADER_VERSION;

consteval auto ApiVersionMajor( auto const version )
{
return ( ( (uint32_t)( version ) >> 22U ) & 0x7FU );
}

consteval auto ApiVersionMinor( auto const version )
{
return ( ( (uint32_t)( version ) >> 12U ) & 0x3FFU );
}

consteval auto ApiVersionPatch( auto const version )
{
return ( (uint32_t)(version)&0xFFFU );
}

consteval auto ApiVersionVariant( auto const version )
{
return ( (uint32_t)( version ) >> 29U );
}

consteval auto MakeApiVersion( auto const variant, auto const major, auto const minor, auto const patch )
{
return ( ( ( (uint32_t)( variant ) ) << 29U ) | ( ( (uint32_t)( major ) ) << 22U ) | ( ( (uint32_t)( minor ) ) << 12U ) | ( (uint32_t)( patch ) ) );
}

[[deprecated( "This define is deprecated. VK_MAKE_API_VERSION should be used instead." )]] consteval auto
MakeVersion( auto const major, auto const minor, auto const patch )
{
return ( ( ( (uint32_t)( major ) ) << 22U ) | ( ( (uint32_t)( minor ) ) << 12U ) | ( (uint32_t)( patch ) ) );
}

[[deprecated( "This define is deprecated. VK_API_VERSION_MAJOR should be used instead." )]] consteval auto VersionMajor( auto const version )
{
return ( (uint32_t)( version ) >> 22U );
}

[[deprecated( "This define is deprecated. VK_API_VERSION_MINOR should be used instead." )]] consteval auto VersionMinor( auto const version )
{
return ( ( (uint32_t)( version ) >> 12U ) & 0x3FFU );
}

[[deprecated( "This define is deprecated. VK_API_VERSION_PATCH should be used instead." )]] consteval auto VersionPatch( auto const version )
{
return ( (uint32_t)(version)&0xFFFU );
}

constexpr auto ApiVersion = MakeApiVersion( 0, 1, 0, 0 );
constexpr auto ApiVersion10 = MakeApiVersion( 0, 1, 0, 0 );
constexpr auto ApiVersion11 = MakeApiVersion( 0, 1, 1, 0 );
constexpr auto ApiVersion12 = MakeApiVersion( 0, 1, 2, 0 );
constexpr auto ApiVersion13 = MakeApiVersion( 0, 1, 3, 0 );
constexpr auto HeaderVersionComplete = MakeApiVersion( 0, 1, 3, VK_HEADER_VERSION );

} // namespace VULKAN_HPP_NAMESPACE
#endif
Loading

0 comments on commit e94a6a0

Please sign in to comment.