Move extension inspection template to a snippet file. (#1992)

This commit is contained in:
Andreas Süßenbach 2024-11-11 11:41:24 +01:00 committed by GitHub
parent 4fb483e6a0
commit a4d53f4a22
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 158 additions and 157 deletions

View File

@ -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 <map>
# include <set>
# include <string>
# include <vector>
# include <vulkan/${api}.hpp>
#endif
namespace VULKAN_HPP_NAMESPACE
{
//======================================
//=== Extension inspection functions ===
//======================================
std::set<std::string> const & getDeviceExtensions();
std::set<std::string> const & getInstanceExtensions();
std::map<std::string, std::string> const & getDeprecatedExtensions();
std::map<std::string, std::vector<std::vector<std::string>>> const & getExtensionDepends( std::string const & extension );
${getExtensionDependsByVersionDeclaration}
std::map<std::string, std::string> const & getObsoletedExtensions();
std::map<std::string, std::string> 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<std::string, std::string> const & getDeprecatedExtensions()
{
static std::map<std::string, std::string> deprecatedExtensions = { ${deprecatedExtensions} };
return deprecatedExtensions;
}
VULKAN_HPP_INLINE std::set<std::string> const & getDeviceExtensions()
{
static std::set<std::string> deviceExtensions = { ${deviceExtensions} };
return deviceExtensions;
}
VULKAN_HPP_INLINE std::set<std::string> const & getInstanceExtensions()
{
static std::set<std::string> instanceExtensions = { ${instanceExtensions} };
return instanceExtensions;
}
VULKAN_HPP_INLINE std::map<std::string, std::vector<std::vector<std::string>>> const & getExtensionDepends( std::string const & extension )
{
static std::map<std::string, std::vector<std::vector<std::string>>> noDependencies;
static std::map<std::string, std::map<std::string, std::vector<std::vector<std::string>>>> dependencies = { ${extensionDependencies} };
auto depIt = dependencies.find( extension );
return ( depIt != dependencies.end() ) ? depIt->second : noDependencies;
}
${getExtensionDependsByVersionDefinition}
VULKAN_HPP_INLINE std::map<std::string, std::string> const & getObsoletedExtensions()
{
static std::map<std::string, std::string> obsoletedExtensions = { ${obsoletedExtensions} };
return obsoletedExtensions;
}
VULKAN_HPP_INLINE std::map<std::string, std::string> const & getPromotedExtensions()
{
static std::map<std::string, std::string> 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 );

View File

@ -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 <map>
# include <set>
# include <string>
# include <vector>
# include <vulkan/${api}.hpp>
#endif
namespace VULKAN_HPP_NAMESPACE
{
//======================================
//=== Extension inspection functions ===
//======================================
std::set<std::string> const & getDeviceExtensions();
std::set<std::string> const & getInstanceExtensions();
std::map<std::string, std::string> const & getDeprecatedExtensions();
std::map<std::string, std::vector<std::vector<std::string>>> const & getExtensionDepends( std::string const & extension );
${getExtensionDependsByVersionDeclaration}
std::map<std::string, std::string> const & getObsoletedExtensions();
std::map<std::string, std::string> 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<std::string, std::string> const & getDeprecatedExtensions()
{
static const std::map<std::string, std::string> deprecatedExtensions = { ${deprecatedExtensions} };
return deprecatedExtensions;
}
VULKAN_HPP_INLINE std::set<std::string> const & getDeviceExtensions()
{
static const std::set<std::string> deviceExtensions = { ${deviceExtensions} };
return deviceExtensions;
}
VULKAN_HPP_INLINE std::set<std::string> const & getInstanceExtensions()
{
static const std::set<std::string> instanceExtensions = { ${instanceExtensions} };
return instanceExtensions;
}
VULKAN_HPP_INLINE std::map<std::string, std::vector<std::vector<std::string>>> const & getExtensionDepends( std::string const & extension )
{
static const std::map<std::string, std::vector<std::vector<std::string>>> noDependencies;
static const std::map<std::string, std::map<std::string, std::vector<std::vector<std::string>>>> dependencies = { ${extensionDependencies} };
auto depIt = dependencies.find( extension );
return ( depIt != dependencies.end() ) ? depIt->second : noDependencies;
}
${getExtensionDependsByVersionDefinition}
VULKAN_HPP_INLINE std::map<std::string, std::string> const & getObsoletedExtensions()
{
static const std::map<std::string, std::string> obsoletedExtensions = { ${obsoletedExtensions} };
return obsoletedExtensions;
}
VULKAN_HPP_INLINE std::map<std::string, std::string> const & getPromotedExtensions()
{
static const std::map<std::string, std::string> 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

View File

@ -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<std::string, std::string> const & deprecatedExtensions = vk::getDeprecatedExtensions();
auto deprecatedIt = deprecatedExtensions.find( VK_EXT_DEBUG_REPORT_EXTENSION_NAME );

View File

@ -46,7 +46,7 @@ namespace VULKAN_HPP_NAMESPACE
VULKAN_HPP_INLINE std::map<std::string, std::string> const & getDeprecatedExtensions()
{
static std::map<std::string, std::string> deprecatedExtensions = {
static const std::map<std::string, std::string> 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<std::string> const & getDeviceExtensions()
{
static std::set<std::string> deviceExtensions = {
static const std::set<std::string> 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<std::string> const & getInstanceExtensions()
{
static std::set<std::string> instanceExtensions = {
static const std::set<std::string> 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<std::string, std::vector<std::vector<std::string>>> const & getExtensionDepends( std::string const & extension )
{
static std::map<std::string, std::vector<std::vector<std::string>>> noDependencies;
static std::map<std::string, std::map<std::string, std::vector<std::vector<std::string>>>> dependencies = {
static const std::map<std::string, std::vector<std::vector<std::string>>> noDependencies;
static const std::map<std::string, std::map<std::string, std::vector<std::vector<std::string>>>> dependencies = {
{ "VK_KHR_swapchain",
{ { "VK_VERSION_1_0",
{ {
@ -2414,13 +2414,13 @@ namespace VULKAN_HPP_NAMESPACE
VULKAN_HPP_INLINE std::map<std::string, std::string> const & getObsoletedExtensions()
{
static std::map<std::string, std::string> obsoletedExtensions = { { "VK_AMD_negative_viewport_height", "VK_KHR_maintenance1" } };
static const std::map<std::string, std::string> obsoletedExtensions = { { "VK_AMD_negative_viewport_height", "VK_KHR_maintenance1" } };
return obsoletedExtensions;
}
VULKAN_HPP_INLINE std::map<std::string, std::string> const & getPromotedExtensions()
{
static std::map<std::string, std::string> promotedExtensions = {
static const std::map<std::string, std::string> 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" },

View File

@ -24,7 +24,7 @@ namespace VULKAN_HPP_NAMESPACE
//=== Extension inspection functions ===
//======================================
std::set<std::string> const & getDeviceExtensions();
VULKAN_HPP_CONSTEXPR_20 std::set<std::string> const & getDeviceExtensions();
std::set<std::string> const & getInstanceExtensions();
std::map<std::string, std::string> const & getDeprecatedExtensions();
std::map<std::string, std::vector<std::vector<std::string>>> const & getExtensionDepends( std::string const & extension );
@ -44,7 +44,7 @@ namespace VULKAN_HPP_NAMESPACE
//=== Extension inspection function implementations ===
//=====================================================
VULKAN_HPP_INLINE std::map<std::string, std::string> const & getDeprecatedExtensions()
VULKAN_HPP_INLINE VULKAN_HPP_CONSTEXPR_20std::map<std::string, std::string> const & getDeprecatedExtensions()
{
static std::map<std::string, std::string> deprecatedExtensions = {
{ "VK_EXT_validation_features", "VK_EXT_layer_settings" },
@ -55,9 +55,9 @@ namespace VULKAN_HPP_NAMESPACE
return deprecatedExtensions;
}
VULKAN_HPP_INLINE std::set<std::string> const & getDeviceExtensions()
VULKAN_HPP_INLINE VULKAN_HPP_CONSTEXPR_20 std::set<std::string> const & getDeviceExtensions()
{
static std::set<std::string> deviceExtensions = {
static const std::set<std::string> deviceExtensions = {
"VK_KHR_swapchain",
"VK_KHR_display_swapchain",
"VK_EXT_depth_range_unrestricted",