From a4d53f4a2209cee859dab83f0ab7ddb7ceca6b7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20S=C3=BC=C3=9Fenbach?= Date: Mon, 11 Nov 2024 11:41:24 +0100 Subject: [PATCH] Move extension inspection template to a snippet file. (#1992) --- VulkanHppGenerator.cpp | 164 ++---------------- snippets/ExtensionInspection.hpp | 127 ++++++++++++++ .../ExtensionInspection.cpp | 2 +- vulkan/vulkan_extension_inspection.hpp | 14 +- vulkan/vulkansc_extension_inspection.hpp | 8 +- 5 files changed, 158 insertions(+), 157 deletions(-) create mode 100644 snippets/ExtensionInspection.hpp diff --git a/VulkanHppGenerator.cpp b/VulkanHppGenerator.cpp index cc6f7e1..52c7279 100644 --- a/VulkanHppGenerator.cpp +++ b/VulkanHppGenerator.cpp @@ -126,145 +126,27 @@ void VulkanHppGenerator::generateExtensionInspectionFile() const std::string const vulkan_extension_inspection_hpp = std::string( BASE_PATH ) + "/vulkan/" + m_api + "_extension_inspection.hpp"; std::cout << "VulkanHppGenerator: Generating " << vulkan_extension_inspection_hpp << " ..." << std::endl; - std::string const vulkanExtensionInspectionHppTemplate = R"(${licenseHeader} -#ifndef VULKAN_EXTENSION_INSPECTION_HPP -# define VULKAN_EXTENSION_INSPECTION_HPP - -#if defined( VULKAN_HPP_ENABLE_STD_MODULE ) && defined( VULKAN_HPP_STD_MODULE ) -import VULKAN_HPP_STD_MODULE; -#else -# include -# include -# include -# include -# include -#endif - -namespace VULKAN_HPP_NAMESPACE -{ - //====================================== - //=== Extension inspection functions === - //====================================== - - std::set const & getDeviceExtensions(); - std::set const & getInstanceExtensions(); - std::map const & getDeprecatedExtensions(); - std::map>> const & getExtensionDepends( std::string const & extension ); - ${getExtensionDependsByVersionDeclaration} - std::map const & getObsoletedExtensions(); - std::map const & getPromotedExtensions(); - VULKAN_HPP_CONSTEXPR_20 std::string getExtensionDeprecatedBy( std::string const & extension ); - VULKAN_HPP_CONSTEXPR_20 std::string getExtensionObsoletedBy( std::string const & extension ); - VULKAN_HPP_CONSTEXPR_20 std::string getExtensionPromotedTo( std::string const & extension ); - VULKAN_HPP_CONSTEXPR_20 bool isDeprecatedExtension( std::string const & extension ); - VULKAN_HPP_CONSTEXPR_20 bool isDeviceExtension( std::string const & extension ); - VULKAN_HPP_CONSTEXPR_20 bool isInstanceExtension( std::string const & extension ); - VULKAN_HPP_CONSTEXPR_20 bool isObsoletedExtension( std::string const & extension ); - VULKAN_HPP_CONSTEXPR_20 bool isPromotedExtension( std::string const & extension ); - - //===================================================== - //=== Extension inspection function implementations === - //===================================================== - - VULKAN_HPP_INLINE std::map const & getDeprecatedExtensions() - { - static std::map deprecatedExtensions = { ${deprecatedExtensions} }; - return deprecatedExtensions; - } - - VULKAN_HPP_INLINE std::set const & getDeviceExtensions() - { - static std::set deviceExtensions = { ${deviceExtensions} }; - return deviceExtensions; - } - - VULKAN_HPP_INLINE std::set const & getInstanceExtensions() - { - static std::set instanceExtensions = { ${instanceExtensions} }; - return instanceExtensions; - } - - VULKAN_HPP_INLINE std::map>> const & getExtensionDepends( std::string const & extension ) - { - static std::map>> noDependencies; - static std::map>>> dependencies = { ${extensionDependencies} }; - auto depIt = dependencies.find( extension ); - return ( depIt != dependencies.end() ) ? depIt->second : noDependencies; - } - - ${getExtensionDependsByVersionDefinition} - - VULKAN_HPP_INLINE std::map const & getObsoletedExtensions() - { - static std::map obsoletedExtensions = { ${obsoletedExtensions} }; - return obsoletedExtensions; - } - - VULKAN_HPP_INLINE std::map const & getPromotedExtensions() - { - static std::map promotedExtensions = { ${promotedExtensions} }; - return promotedExtensions; - } - - VULKAN_HPP_INLINE VULKAN_HPP_CONSTEXPR_20 std::string getExtensionDeprecatedBy( std::string const & extension ) - { - ${voidExtension} - ${deprecatedBy} - } - - VULKAN_HPP_INLINE VULKAN_HPP_CONSTEXPR_20 std::string getExtensionObsoletedBy( std::string const & extension ) - { - ${voidExtension} - ${obsoletedBy} - } - - VULKAN_HPP_INLINE VULKAN_HPP_CONSTEXPR_20 std::string getExtensionPromotedTo( std::string const & extension ) - { - ${promotedTo} - } - - VULKAN_HPP_INLINE VULKAN_HPP_CONSTEXPR_20 bool isDeprecatedExtension( std::string const & extension ) - { - ${voidExtension} - return ${deprecatedTest}; - } - - VULKAN_HPP_INLINE VULKAN_HPP_CONSTEXPR_20 bool isDeviceExtension( std::string const & extension ) - { - return ${deviceTest}; - } - - VULKAN_HPP_INLINE VULKAN_HPP_CONSTEXPR_20 bool isInstanceExtension( std::string const & extension ) - { - return ${instanceTest}; - } - - VULKAN_HPP_INLINE VULKAN_HPP_CONSTEXPR_20 bool isObsoletedExtension( std::string const & extension ) - { - ${voidExtension} - return ${obsoletedTest}; - } - - VULKAN_HPP_INLINE VULKAN_HPP_CONSTEXPR_20 bool isPromotedExtension( std::string const & extension ) - { - return ${promotedTest}; - } -} // namespace VULKAN_HPP_NAMESPACE - -#endif -)"; + std::string const vulkanExtensionInspectionHppTemplate = readSnippet( "ExtensionInspection.hpp" ); + std::string const deprecatedExtensions = generateReplacedExtensionsList( []( ExtensionData const & extension ) { return extension.isDeprecated; }, + []( ExtensionData const & extension ) { return extension.deprecatedBy; } ); + std::string const deprecatedBy = generateExtensionReplacedBy( []( ExtensionData const & extension ) { return extension.isDeprecated; }, + []( ExtensionData const & extension ) { return extension.deprecatedBy; } ); + std::string const obsoletedBy = generateExtensionReplacedBy( []( ExtensionData const & extension ) { return !extension.obsoletedBy.empty(); }, + []( ExtensionData const & extension ) { return extension.obsoletedBy; } ); + std::string const obsoletedExtensions = generateReplacedExtensionsList( []( ExtensionData const & extension ) { return !extension.obsoletedBy.empty(); }, + []( ExtensionData const & extension ) { return extension.obsoletedBy; } ); + std::string const promotedExtensions = generateReplacedExtensionsList( []( ExtensionData const & extension ) { return !extension.promotedTo.empty(); }, + []( ExtensionData const & extension ) { return extension.promotedTo; } ); + std::string const promotedTo = generateExtensionReplacedBy( []( ExtensionData const & extension ) { return !extension.promotedTo.empty(); }, + []( ExtensionData const & extension ) { return extension.promotedTo; } ); std::string str = replaceWithMap( vulkanExtensionInspectionHppTemplate, { { "api", m_api }, - { "deprecatedExtensions", - generateReplacedExtensionsList( []( ExtensionData const & extension ) { return extension.isDeprecated; }, - []( ExtensionData const & extension ) { return extension.deprecatedBy; } ) }, + { "deprecatedExtensions", deprecatedExtensions }, { "deviceExtensions", generateExtensionsList( "device" ) }, { "deviceTest", generateExtensionTypeTest( "device" ) }, - { "deprecatedBy", - generateExtensionReplacedBy( []( ExtensionData const & extension ) { return extension.isDeprecated; }, - []( ExtensionData const & extension ) { return extension.deprecatedBy; } ) }, + { "deprecatedBy", deprecatedBy }, { "deprecatedTest", generateExtensionReplacedTest( []( ExtensionData const & extension ) { return extension.isDeprecated; } ) }, { "extensionDependencies", generateExtensionDependencies() }, { "getExtensionDependsByVersionDeclaration", generateExtensionDependsByVersion( false ) }, @@ -272,20 +154,12 @@ namespace VULKAN_HPP_NAMESPACE { "instanceExtensions", generateExtensionsList( "instance" ) }, { "instanceTest", generateExtensionTypeTest( "instance" ) }, { "licenseHeader", m_vulkanLicenseHeader }, - { "obsoletedBy", - generateExtensionReplacedBy( []( ExtensionData const & extension ) { return !extension.obsoletedBy.empty(); }, - []( ExtensionData const & extension ) { return extension.obsoletedBy; } ) }, - { "obsoletedExtensions", - generateReplacedExtensionsList( []( ExtensionData const & extension ) { return !extension.obsoletedBy.empty(); }, - []( ExtensionData const & extension ) { return extension.obsoletedBy; } ) }, + { "obsoletedBy", obsoletedBy }, + { "obsoletedExtensions", obsoletedExtensions }, { "obsoletedTest", generateExtensionReplacedTest( []( ExtensionData const & extension ) { return !extension.obsoletedBy.empty(); } ) }, - { "promotedExtensions", - generateReplacedExtensionsList( []( ExtensionData const & extension ) { return !extension.promotedTo.empty(); }, - []( ExtensionData const & extension ) { return extension.promotedTo; } ) }, + { "promotedExtensions", promotedExtensions }, { "promotedTest", generateExtensionReplacedTest( []( ExtensionData const & extension ) { return !extension.promotedTo.empty(); } ) }, - { "promotedTo", - generateExtensionReplacedBy( []( ExtensionData const & extension ) { return !extension.promotedTo.empty(); }, - []( ExtensionData const & extension ) { return extension.promotedTo; } ) }, + { "promotedTo", promotedTo }, { "voidExtension", ( m_api == "vulkan" ) ? "" : "(void)extension;" } } ); writeToFile( str, vulkan_extension_inspection_hpp ); diff --git a/snippets/ExtensionInspection.hpp b/snippets/ExtensionInspection.hpp new file mode 100644 index 0000000..feb97d1 --- /dev/null +++ b/snippets/ExtensionInspection.hpp @@ -0,0 +1,127 @@ +${licenseHeader} + +#ifndef VULKAN_EXTENSION_INSPECTION_HPP +# define VULKAN_EXTENSION_INSPECTION_HPP + +#if defined( VULKAN_HPP_ENABLE_STD_MODULE ) && defined( VULKAN_HPP_STD_MODULE ) +import VULKAN_HPP_STD_MODULE; +#else +# include +# include +# include +# include +# include +#endif + +namespace VULKAN_HPP_NAMESPACE +{ + //====================================== + //=== Extension inspection functions === + //====================================== + + std::set const & getDeviceExtensions(); + std::set const & getInstanceExtensions(); + std::map const & getDeprecatedExtensions(); + std::map>> const & getExtensionDepends( std::string const & extension ); + ${getExtensionDependsByVersionDeclaration} + std::map const & getObsoletedExtensions(); + std::map const & getPromotedExtensions(); + VULKAN_HPP_CONSTEXPR_20 std::string getExtensionDeprecatedBy( std::string const & extension ); + VULKAN_HPP_CONSTEXPR_20 std::string getExtensionObsoletedBy( std::string const & extension ); + VULKAN_HPP_CONSTEXPR_20 std::string getExtensionPromotedTo( std::string const & extension ); + VULKAN_HPP_CONSTEXPR_20 bool isDeprecatedExtension( std::string const & extension ); + VULKAN_HPP_CONSTEXPR_20 bool isDeviceExtension( std::string const & extension ); + VULKAN_HPP_CONSTEXPR_20 bool isInstanceExtension( std::string const & extension ); + VULKAN_HPP_CONSTEXPR_20 bool isObsoletedExtension( std::string const & extension ); + VULKAN_HPP_CONSTEXPR_20 bool isPromotedExtension( std::string const & extension ); + + //===================================================== + //=== Extension inspection function implementations === + //===================================================== + + VULKAN_HPP_INLINE std::map const & getDeprecatedExtensions() + { + static const std::map deprecatedExtensions = { ${deprecatedExtensions} }; + return deprecatedExtensions; + } + + VULKAN_HPP_INLINE std::set const & getDeviceExtensions() + { + static const std::set deviceExtensions = { ${deviceExtensions} }; + return deviceExtensions; + } + + VULKAN_HPP_INLINE std::set const & getInstanceExtensions() + { + static const std::set instanceExtensions = { ${instanceExtensions} }; + return instanceExtensions; + } + + VULKAN_HPP_INLINE std::map>> const & getExtensionDepends( std::string const & extension ) + { + static const std::map>> noDependencies; + static const std::map>>> dependencies = { ${extensionDependencies} }; + auto depIt = dependencies.find( extension ); + return ( depIt != dependencies.end() ) ? depIt->second : noDependencies; + } + + ${getExtensionDependsByVersionDefinition} + + VULKAN_HPP_INLINE std::map const & getObsoletedExtensions() + { + static const std::map obsoletedExtensions = { ${obsoletedExtensions} }; + return obsoletedExtensions; + } + + VULKAN_HPP_INLINE std::map const & getPromotedExtensions() + { + static const std::map promotedExtensions = { ${promotedExtensions} }; + return promotedExtensions; + } + + VULKAN_HPP_INLINE VULKAN_HPP_CONSTEXPR_20 std::string getExtensionDeprecatedBy( std::string const & extension ) + { + ${voidExtension} + ${deprecatedBy} + } + + VULKAN_HPP_INLINE VULKAN_HPP_CONSTEXPR_20 std::string getExtensionObsoletedBy( std::string const & extension ) + { + ${voidExtension} + ${obsoletedBy} + } + + VULKAN_HPP_INLINE VULKAN_HPP_CONSTEXPR_20 std::string getExtensionPromotedTo( std::string const & extension ) + { + ${promotedTo} + } + + VULKAN_HPP_INLINE VULKAN_HPP_CONSTEXPR_20 bool isDeprecatedExtension( std::string const & extension ) + { + ${voidExtension} + return ${deprecatedTest}; + } + + VULKAN_HPP_INLINE VULKAN_HPP_CONSTEXPR_20 bool isDeviceExtension( std::string const & extension ) + { + return ${deviceTest}; + } + + VULKAN_HPP_INLINE VULKAN_HPP_CONSTEXPR_20 bool isInstanceExtension( std::string const & extension ) + { + return ${instanceTest}; + } + + VULKAN_HPP_INLINE VULKAN_HPP_CONSTEXPR_20 bool isObsoletedExtension( std::string const & extension ) + { + ${voidExtension} + return ${obsoletedTest}; + } + + VULKAN_HPP_INLINE VULKAN_HPP_CONSTEXPR_20 bool isPromotedExtension( std::string const & extension ) + { + return ${promotedTest}; + } +} // namespace VULKAN_HPP_NAMESPACE + +#endif diff --git a/tests/ExtensionInspection/ExtensionInspection.cpp b/tests/ExtensionInspection/ExtensionInspection.cpp index e64c7ae..3ebb1bd 100644 --- a/tests/ExtensionInspection/ExtensionInspection.cpp +++ b/tests/ExtensionInspection/ExtensionInspection.cpp @@ -66,7 +66,7 @@ int main( int /*argc*/, char ** /*argv*/ ) assert( !available3 ); auto [available4, deps4] = vk::getExtensionDepends( "VK_VERSION_1_3", VK_EXT_SHADER_TILE_IMAGE_EXTENSION_NAME ); - assert( available4 && deps4.empty() ); + assert( available4 && ( deps4.size() == 1 ) && deps4[0].empty() ); std::map const & deprecatedExtensions = vk::getDeprecatedExtensions(); auto deprecatedIt = deprecatedExtensions.find( VK_EXT_DEBUG_REPORT_EXTENSION_NAME ); diff --git a/vulkan/vulkan_extension_inspection.hpp b/vulkan/vulkan_extension_inspection.hpp index 3075472..e6045f8 100644 --- a/vulkan/vulkan_extension_inspection.hpp +++ b/vulkan/vulkan_extension_inspection.hpp @@ -46,7 +46,7 @@ namespace VULKAN_HPP_NAMESPACE VULKAN_HPP_INLINE std::map const & getDeprecatedExtensions() { - static std::map deprecatedExtensions = { + static const std::map deprecatedExtensions = { { "VK_EXT_debug_report", "VK_EXT_debug_utils" }, { "VK_NV_glsl_shader", "" }, { "VK_NV_dedicated_allocation", "VK_KHR_dedicated_allocation" }, @@ -76,7 +76,7 @@ namespace VULKAN_HPP_NAMESPACE VULKAN_HPP_INLINE std::set const & getDeviceExtensions() { - static std::set deviceExtensions = { + static const std::set deviceExtensions = { "VK_KHR_swapchain", "VK_KHR_display_swapchain", "VK_NV_glsl_shader", @@ -462,7 +462,7 @@ namespace VULKAN_HPP_NAMESPACE VULKAN_HPP_INLINE std::set const & getInstanceExtensions() { - static std::set instanceExtensions = { + static const std::set instanceExtensions = { "VK_KHR_surface", "VK_KHR_display", #if defined( VK_USE_PLATFORM_XLIB_KHR ) @@ -536,8 +536,8 @@ namespace VULKAN_HPP_NAMESPACE VULKAN_HPP_INLINE std::map>> const & getExtensionDepends( std::string const & extension ) { - static std::map>> noDependencies; - static std::map>>> dependencies = { + static const std::map>> noDependencies; + static const std::map>>> dependencies = { { "VK_KHR_swapchain", { { "VK_VERSION_1_0", { { @@ -2414,13 +2414,13 @@ namespace VULKAN_HPP_NAMESPACE VULKAN_HPP_INLINE std::map const & getObsoletedExtensions() { - static std::map obsoletedExtensions = { { "VK_AMD_negative_viewport_height", "VK_KHR_maintenance1" } }; + static const std::map obsoletedExtensions = { { "VK_AMD_negative_viewport_height", "VK_KHR_maintenance1" } }; return obsoletedExtensions; } VULKAN_HPP_INLINE std::map const & getPromotedExtensions() { - static std::map promotedExtensions = { + static const std::map promotedExtensions = { { "VK_KHR_sampler_mirror_clamp_to_edge", "VK_VERSION_1_2" }, { "VK_EXT_debug_marker", "VK_EXT_debug_utils" }, { "VK_AMD_draw_indirect_count", "VK_KHR_draw_indirect_count" }, diff --git a/vulkan/vulkansc_extension_inspection.hpp b/vulkan/vulkansc_extension_inspection.hpp index cc1b668..0204187 100644 --- a/vulkan/vulkansc_extension_inspection.hpp +++ b/vulkan/vulkansc_extension_inspection.hpp @@ -24,7 +24,7 @@ namespace VULKAN_HPP_NAMESPACE //=== Extension inspection functions === //====================================== - std::set const & getDeviceExtensions(); + VULKAN_HPP_CONSTEXPR_20 std::set const & getDeviceExtensions(); std::set const & getInstanceExtensions(); std::map const & getDeprecatedExtensions(); std::map>> const & getExtensionDepends( std::string const & extension ); @@ -44,7 +44,7 @@ namespace VULKAN_HPP_NAMESPACE //=== Extension inspection function implementations === //===================================================== - VULKAN_HPP_INLINE std::map const & getDeprecatedExtensions() + VULKAN_HPP_INLINE VULKAN_HPP_CONSTEXPR_20std::map const & getDeprecatedExtensions() { static std::map deprecatedExtensions = { { "VK_EXT_validation_features", "VK_EXT_layer_settings" }, @@ -55,9 +55,9 @@ namespace VULKAN_HPP_NAMESPACE return deprecatedExtensions; } - VULKAN_HPP_INLINE std::set const & getDeviceExtensions() + VULKAN_HPP_INLINE VULKAN_HPP_CONSTEXPR_20 std::set const & getDeviceExtensions() { - static std::set deviceExtensions = { + static const std::set deviceExtensions = { "VK_KHR_swapchain", "VK_KHR_display_swapchain", "VK_EXT_depth_range_unrestricted",