Add functions isExtensionDeprecated() and getExtensionDeprecatedBy() to extension_inspection. (#1547)

This commit is contained in:
Andreas Süßenbach 2023-03-30 13:25:09 +02:00 committed by GitHub
parent 2175530fd0
commit 91a92c6c5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 207 additions and 19 deletions

View File

@ -135,18 +135,32 @@ namespace VULKAN_HPP_NAMESPACE
//=== Extension inspection functions ===
//======================================
VULKAN_HPP_CONSTEXPR_20 bool isDeviceExtension( std::string const & name );
VULKAN_HPP_CONSTEXPR_20 bool isInstanceExtension( std::string const & name );
VULKAN_HPP_CONSTEXPR_20 std::string getExtensionDeprecatedBy( std::string const & name );
VULKAN_HPP_CONSTEXPR_20 bool isDeviceExtension( std::string const & name );
VULKAN_HPP_CONSTEXPR_20 bool isExtensionDeprecated( std::string const & name );
VULKAN_HPP_CONSTEXPR_20 bool isInstanceExtension( std::string const & name );
//=====================================================
//=== Extension inspection function implementations ===
//=====================================================
VULKAN_HPP_INLINE VULKAN_HPP_CONSTEXPR_20 std::string getExtensionDeprecatedBy( std::string const & name )
{
${voidName}
${deprecatedBy}
}
VULKAN_HPP_INLINE VULKAN_HPP_CONSTEXPR_20 bool isDeviceExtension( std::string const & name )
{
return ${deviceTest};
}
VULKAN_HPP_INLINE VULKAN_HPP_CONSTEXPR_20 bool isExtensionDeprecated( std::string const & name )
{
${voidName}
return ${deprecatedTest};
}
VULKAN_HPP_INLINE VULKAN_HPP_CONSTEXPR_20 bool isInstanceExtension( std::string const & name )
{
return ${instanceTest};
@ -159,8 +173,11 @@ namespace VULKAN_HPP_NAMESPACE
std::string str = replaceWithMap( vulkanExtensionInspectionHppTemplate,
{ { "api", m_api },
{ "deviceTest", generateExtensionTypeTest( "device" ) },
{ "deprecatedBy", generateExtensionDeprecatedBy() },
{ "deprecatedTest", generateExtensionDeprecatedTest() },
{ "instanceTest", generateExtensionTypeTest( "instance" ) },
{ "licenseHeader", m_vulkanLicenseHeader } } );
{ "licenseHeader", m_vulkanLicenseHeader },
{ "voidName", ( m_api == "vulkan" ) ? "" : "(void)name;" } } );
writeToFile( str, vulkan_extension_inspection_hpp );
}
@ -5556,26 +5573,77 @@ std::string VulkanHppGenerator::generateEnumValueName( std::string const & enumN
return result;
}
std::string VulkanHppGenerator::generateExtensionDeprecatedBy() const
{
std::string deprecatedBy, previousEnter, previousLeave;
for ( auto const & extension : m_extensions )
{
if ( extension.isDeprecated )
{
auto [enter, leave] = generateProtection( getProtectFromTitle( extension.name ) );
deprecatedBy += ( ( previousEnter != enter ) ? ( "\n" + previousLeave + enter ) : "\n" ) + " if ( name == \"" + extension.name + "\" ) { return \"" +
extension.deprecatedBy + "\"; }";
previousEnter = enter;
previousLeave = leave;
}
}
if ( !previousLeave.empty() )
{
deprecatedBy += "\n" + previousLeave;
}
deprecatedBy += "\n return \"\";";
return deprecatedBy;
}
std::string VulkanHppGenerator::generateExtensionDeprecatedTest() const
{
std::string deprecatedTest, previousEnter, previousLeave;
for ( auto const & extension : m_extensions )
{
if ( extension.isDeprecated )
{
auto [enter, leave] = generateProtection( getProtectFromTitle( extension.name ) );
deprecatedTest += ( ( previousEnter != enter ) ? ( "\n" + previousLeave + enter ) : "\n" ) + "( name == \"" + extension.name + "\" ) || ";
previousEnter = enter;
previousLeave = leave;
}
}
if ( m_api == "vulkan" )
{
assert( deprecatedTest.ends_with( " || " ) );
deprecatedTest = deprecatedTest.substr( 0, deprecatedTest.length() - 4 );
}
if ( !previousLeave.empty() )
{
deprecatedTest += "\n" + previousLeave;
}
if ( m_api != "vulkan" )
{
deprecatedTest += "false"; // there might be no deprecations at all, so add a "false" at the end...
}
return deprecatedTest;
}
std::string VulkanHppGenerator::generateExtensionTypeTest( std::string const & type ) const
{
std::string deviceTest, previousEnter, previousLeave;
std::string typeTest, previousEnter, previousLeave;
for ( auto const & extension : m_extensions )
{
if ( extension.type == type )
{
auto [enter, leave] = generateProtection( getProtectFromTitle( extension.name ) );
deviceTest += ( ( previousEnter != enter ) ? ( "\n" + previousLeave + enter ) : "\n" ) + "( name == \"" + extension.name + "\" ) || ";
typeTest += ( ( previousEnter != enter ) ? ( "\n" + previousLeave + enter ) : "\n" ) + "( name == \"" + extension.name + "\" ) || ";
previousEnter = enter;
previousLeave = leave;
}
}
assert( deviceTest.ends_with( " || " ) );
deviceTest = deviceTest.substr( 0, deviceTest.length() - 4 );
assert( typeTest.ends_with( " || " ) );
typeTest = typeTest.substr( 0, typeTest.length() - 4 );
if ( !previousLeave.empty() )
{
deviceTest += "\n" + previousLeave;
typeTest += "\n" + previousLeave;
}
return deviceTest;
return typeTest;
}
std::string VulkanHppGenerator::generateFailureCheck( std::vector<std::string> const & successCodes ) const
@ -11493,6 +11561,7 @@ void VulkanHppGenerator::readExtension( tinyxml2::XMLElement const * element )
else if ( attribute.first == "deprecatedby" )
{
extensionData.deprecatedBy = attribute.second;
extensionData.isDeprecated = true;
}
else if ( attribute.first == "name" )
{

View File

@ -243,6 +243,7 @@ private:
struct ExtensionData
{
std::string deprecatedBy = {};
bool isDeprecated = false;
std::string name = {};
std::string number = {};
std::string obsoletedBy = {};
@ -692,6 +693,8 @@ private:
std::string generateEnumToString( std::pair<std::string, EnumData> const & enumData ) const;
std::pair<std::string, std::string> generateEnumSuffixes( std::string const & name, bool bitmask ) const;
std::string generateEnumValueName( std::string const & enumName, std::string const & valueName, bool bitmask ) const;
std::string generateExtensionDeprecatedBy() const;
std::string generateExtensionDeprecatedTest() const;
std::string generateExtensionTypeTest( std::string const & type ) const;
std::string generateFailureCheck( std::vector<std::string> const & successCodes ) const;
std::string generateFormatTraits() const;

View File

@ -17,15 +17,14 @@
#include <vulkan/vulkan_extension_inspection.hpp>
#if defined( _MSC_VER )
# pragma warning( disable : 4189 ) // local variable is initialized but not referenced
#elif defined( __clang__ ) || defined( __GNUC__ )
# pragma GCC diagnostic ignored "-Wunused-variable"
#endif
int main( int /*argc*/, char ** /*argv*/ )
{
bool ok = vk::isInstanceExtension( VK_KHR_SURFACE_EXTENSION_NAME ) && vk::isDeviceExtension( VK_KHR_SWAPCHAIN_EXTENSION_NAME );
(void)ok; // keep the compiler silent
if ( vk::isExtensionDeprecated( VK_EXT_DEBUG_REPORT_EXTENSION_NAME ) )
{
std::string ext = vk::getExtensionDeprecatedBy( VK_EXT_DEBUG_REPORT_EXTENSION_NAME );
}
return 0;
}

View File

@ -16,13 +16,86 @@ namespace VULKAN_HPP_NAMESPACE
//=== Extension inspection functions ===
//======================================
VULKAN_HPP_CONSTEXPR_20 bool isDeviceExtension( std::string const & name );
VULKAN_HPP_CONSTEXPR_20 bool isInstanceExtension( std::string const & name );
VULKAN_HPP_CONSTEXPR_20 std::string getExtensionDeprecatedBy( std::string const & name );
VULKAN_HPP_CONSTEXPR_20 bool isDeviceExtension( std::string const & name );
VULKAN_HPP_CONSTEXPR_20 bool isExtensionDeprecated( std::string const & name );
VULKAN_HPP_CONSTEXPR_20 bool isInstanceExtension( std::string const & name );
//=====================================================
//=== Extension inspection function implementations ===
//=====================================================
VULKAN_HPP_INLINE VULKAN_HPP_CONSTEXPR_20 std::string getExtensionDeprecatedBy( std::string const & name )
{
if ( name == "VK_EXT_debug_report" )
{
return "VK_EXT_debug_utils";
}
if ( name == "VK_NV_glsl_shader" )
{
return "";
}
if ( name == "VK_NV_dedicated_allocation" )
{
return "VK_KHR_dedicated_allocation";
}
if ( name == "VK_AMD_gpu_shader_half_float" )
{
return "VK_KHR_shader_float16_int8";
}
if ( name == "VK_IMG_format_pvrtc" )
{
return "";
}
if ( name == "VK_NV_external_memory_capabilities" )
{
return "VK_KHR_external_memory_capabilities";
}
if ( name == "VK_NV_external_memory" )
{
return "VK_KHR_external_memory";
}
#if defined( VK_USE_PLATFORM_WIN32_KHR )
if ( name == "VK_NV_external_memory_win32" )
{
return "VK_KHR_external_memory_win32";
}
#endif /*VK_USE_PLATFORM_WIN32_KHR*/
if ( name == "VK_EXT_validation_flags" )
{
return "VK_EXT_validation_features";
}
if ( name == "VK_EXT_shader_subgroup_ballot" )
{
return "VK_VERSION_1_2";
}
if ( name == "VK_EXT_shader_subgroup_vote" )
{
return "VK_VERSION_1_1";
}
#if defined( VK_USE_PLATFORM_IOS_MVK )
if ( name == "VK_MVK_ios_surface" )
{
return "VK_EXT_metal_surface";
}
#endif /*VK_USE_PLATFORM_IOS_MVK*/
#if defined( VK_USE_PLATFORM_MACOS_MVK )
if ( name == "VK_MVK_macos_surface" )
{
return "VK_EXT_metal_surface";
}
#endif /*VK_USE_PLATFORM_MACOS_MVK*/
if ( name == "VK_AMD_gpu_shader_int16" )
{
return "VK_KHR_shader_float16_int8";
}
if ( name == "VK_EXT_buffer_device_address" )
{
return "VK_KHR_buffer_device_address";
}
return "";
}
VULKAN_HPP_INLINE VULKAN_HPP_CONSTEXPR_20 bool isDeviceExtension( std::string const & name )
{
return ( name == "VK_KHR_swapchain" ) || ( name == "VK_KHR_display_swapchain" ) || ( name == "VK_NV_glsl_shader" ) ||
@ -168,6 +241,24 @@ namespace VULKAN_HPP_NAMESPACE
( name == "VK_QCOM_multiview_per_view_render_areas" );
}
VULKAN_HPP_INLINE VULKAN_HPP_CONSTEXPR_20 bool isExtensionDeprecated( std::string const & name )
{
return ( name == "VK_EXT_debug_report" ) || ( name == "VK_NV_glsl_shader" ) || ( name == "VK_NV_dedicated_allocation" ) ||
( name == "VK_AMD_gpu_shader_half_float" ) || ( name == "VK_IMG_format_pvrtc" ) || ( name == "VK_NV_external_memory_capabilities" ) ||
( name == "VK_NV_external_memory" ) ||
#if defined( VK_USE_PLATFORM_WIN32_KHR )
( name == "VK_NV_external_memory_win32" ) ||
#endif /*VK_USE_PLATFORM_WIN32_KHR*/
( name == "VK_EXT_validation_flags" ) || ( name == "VK_EXT_shader_subgroup_ballot" ) || ( name == "VK_EXT_shader_subgroup_vote" ) ||
#if defined( VK_USE_PLATFORM_IOS_MVK )
( name == "VK_MVK_ios_surface" ) ||
#endif /*VK_USE_PLATFORM_IOS_MVK*/
#if defined( VK_USE_PLATFORM_MACOS_MVK )
( name == "VK_MVK_macos_surface" ) ||
#endif /*VK_USE_PLATFORM_MACOS_MVK*/
( name == "VK_AMD_gpu_shader_int16" ) || ( name == "VK_EXT_buffer_device_address" );
}
VULKAN_HPP_INLINE VULKAN_HPP_CONSTEXPR_20 bool isInstanceExtension( std::string const & name )
{
return ( name == "VK_KHR_surface" ) || ( name == "VK_KHR_display" ) ||

View File

@ -16,13 +16,29 @@ namespace VULKAN_HPP_NAMESPACE
//=== Extension inspection functions ===
//======================================
VULKAN_HPP_CONSTEXPR_20 bool isDeviceExtension( std::string const & name );
VULKAN_HPP_CONSTEXPR_20 bool isInstanceExtension( std::string const & name );
VULKAN_HPP_CONSTEXPR_20 std::string getExtensionDeprecatedBy( std::string const & name );
VULKAN_HPP_CONSTEXPR_20 bool isDeviceExtension( std::string const & name );
VULKAN_HPP_CONSTEXPR_20 bool isExtensionDeprecated( std::string const & name );
VULKAN_HPP_CONSTEXPR_20 bool isInstanceExtension( std::string const & name );
//=====================================================
//=== Extension inspection function implementations ===
//=====================================================
VULKAN_HPP_INLINE VULKAN_HPP_CONSTEXPR_20 std::string getExtensionDeprecatedBy( std::string const & name )
{
(void)name;
#if defined( VK_USE_PLATFORM_SCI )
if ( name == "VK_NV_external_sci_sync" )
{
return "VK_NV_external_sci_sync2";
}
#endif /*VK_USE_PLATFORM_SCI*/
return "";
}
VULKAN_HPP_INLINE VULKAN_HPP_CONSTEXPR_20 bool isDeviceExtension( std::string const & name )
{
return ( name == "VK_KHR_swapchain" ) || ( name == "VK_KHR_display_swapchain" ) || ( name == "VK_EXT_depth_range_unrestricted" ) ||
@ -54,6 +70,16 @@ namespace VULKAN_HPP_NAMESPACE
;
}
VULKAN_HPP_INLINE VULKAN_HPP_CONSTEXPR_20 bool isExtensionDeprecated( std::string const & name )
{
(void)name;
return
#if defined( VK_USE_PLATFORM_SCI )
( name == "VK_NV_external_sci_sync" ) ||
#endif /*VK_USE_PLATFORM_SCI*/
false;
}
VULKAN_HPP_INLINE VULKAN_HPP_CONSTEXPR_20 bool isInstanceExtension( std::string const & name )
{
return ( name == "VK_KHR_surface" ) || ( name == "VK_KHR_display" ) || ( name == "VK_EXT_direct_mode_display" ) ||