mirror of
https://github.com/KhronosGroup/Vulkan-Hpp.git
synced 2024-10-14 16:32:17 +00:00
Merge pull request #988 from KhronosGroup/multifile
Split vulkan.hpp into multiple sub-headers
This commit is contained in:
commit
88f95a700d
@ -83,9 +83,22 @@ if (NOT DEFINED VulkanHeaders_INCLUDE_DIR)
|
|||||||
endif()
|
endif()
|
||||||
file(TO_NATIVE_PATH ${VulkanHeaders_INCLUDE_DIR}/vulkan/vulkan.hpp vulkan_hpp)
|
file(TO_NATIVE_PATH ${VulkanHeaders_INCLUDE_DIR}/vulkan/vulkan.hpp vulkan_hpp)
|
||||||
string(REPLACE "\\" "\\\\" vulkan_hpp ${vulkan_hpp})
|
string(REPLACE "\\" "\\\\" vulkan_hpp ${vulkan_hpp})
|
||||||
|
file(TO_NATIVE_PATH ${VulkanHeaders_INCLUDE_DIR}/vulkan/vulkan_enums.hpp vulkan_enums_hpp)
|
||||||
|
string(REPLACE "\\" "\\\\" vulkan_enums_hpp ${vulkan_enums_hpp})
|
||||||
|
file(TO_NATIVE_PATH ${VulkanHeaders_INCLUDE_DIR}/vulkan/vulkan_funcs.hpp vulkan_funcs_hpp)
|
||||||
|
string(REPLACE "\\" "\\\\" vulkan_funcs_hpp ${vulkan_funcs_hpp})
|
||||||
|
file(TO_NATIVE_PATH ${VulkanHeaders_INCLUDE_DIR}/vulkan/vulkan_handles.hpp vulkan_handles_hpp)
|
||||||
|
string(REPLACE "\\" "\\\\" vulkan_handles_hpp ${vulkan_handles_hpp})
|
||||||
|
file(TO_NATIVE_PATH ${VulkanHeaders_INCLUDE_DIR}/vulkan/vulkan_structs.hpp vulkan_structs_hpp)
|
||||||
|
string(REPLACE "\\" "\\\\" vulkan_structs_hpp ${vulkan_structs_hpp})
|
||||||
file(TO_NATIVE_PATH ${VulkanHeaders_INCLUDE_DIR}/vulkan/vulkan_raii.hpp vulkan_raii_hpp)
|
file(TO_NATIVE_PATH ${VulkanHeaders_INCLUDE_DIR}/vulkan/vulkan_raii.hpp vulkan_raii_hpp)
|
||||||
string(REPLACE "\\" "\\\\" vulkan_raii_hpp ${vulkan_raii_hpp})
|
string(REPLACE "\\" "\\\\" vulkan_raii_hpp ${vulkan_raii_hpp})
|
||||||
add_definitions(-DVULKAN_HPP_FILE="${vulkan_hpp}" -DVULKAN_RAII_HPP_FILE="${vulkan_raii_hpp}")
|
add_definitions(-DVULKAN_HPP_FILE="${vulkan_hpp}"
|
||||||
|
-DVULKAN_ENUMS_HPP_FILE="${vulkan_enums_hpp}"
|
||||||
|
-DVULKAN_FUNCS_HPP_FILE="${vulkan_funcs_hpp}"
|
||||||
|
-DVULKAN_HANDLES_HPP_FILE="${vulkan_handles_hpp}"
|
||||||
|
-DVULKAN_STRUCTS_HPP_FILE="${vulkan_structs_hpp}"
|
||||||
|
-DVULKAN_RAII_HPP_FILE="${vulkan_raii_hpp}")
|
||||||
include_directories(${VulkanHeaders_INCLUDE_DIR})
|
include_directories(${VulkanHeaders_INCLUDE_DIR})
|
||||||
|
|
||||||
set(HEADERS
|
set(HEADERS
|
||||||
|
@ -68,6 +68,7 @@ std::string trim( std::string const & input );
|
|||||||
std::string trimEnd( std::string const & input );
|
std::string trimEnd( std::string const & input );
|
||||||
std::string trimStars( std::string const & input );
|
std::string trimStars( std::string const & input );
|
||||||
void warn( bool condition, int line, std::string const & message );
|
void warn( bool condition, int line, std::string const & message );
|
||||||
|
void writeToFile( std::string const & str, std::string const & fileName );
|
||||||
|
|
||||||
const std::set<std::string> ignoreLens = { "null-terminated",
|
const std::set<std::string> ignoreLens = { "null-terminated",
|
||||||
R"(latexmath:[\lceil{\mathit{rasterizationSamples} \over 32}\rceil])",
|
R"(latexmath:[\lceil{\mathit{rasterizationSamples} \over 32}\rceil])",
|
||||||
@ -702,6 +703,24 @@ void warn( bool condition, int line, std::string const & message )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void writeToFile( std::string const & str, std::string const & fileName )
|
||||||
|
{
|
||||||
|
std::ofstream ofs( fileName );
|
||||||
|
assert( !ofs.fail() );
|
||||||
|
ofs << str;
|
||||||
|
ofs.close();
|
||||||
|
|
||||||
|
#if defined( CLANG_FORMAT_EXECUTABLE )
|
||||||
|
std::cout << "VulkanHppGenerator: Formatting " << fileName << " ..." << std::endl;
|
||||||
|
std::string commandString = "\"" CLANG_FORMAT_EXECUTABLE "\" -i --style=file " + fileName;
|
||||||
|
int ret = std::system( commandString.c_str() );
|
||||||
|
if ( ret != 0 )
|
||||||
|
{
|
||||||
|
std::cout << "VulkanHppGenerator: failed to format file " << fileName << " with error <" << ret << ">\n";
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
VulkanHppGenerator::VulkanHppGenerator( tinyxml2::XMLDocument const & document )
|
VulkanHppGenerator::VulkanHppGenerator( tinyxml2::XMLDocument const & document )
|
||||||
{
|
{
|
||||||
// insert the default "handle" without class (for createInstance, and such)
|
// insert the default "handle" without class (for createInstance, and such)
|
||||||
@ -2754,7 +2773,7 @@ void VulkanHppGenerator::appendHandle( std::string & str, std::pair<std::string,
|
|||||||
assert( commandIt != m_commands.end() );
|
assert( commandIt != m_commands.end() );
|
||||||
for ( auto const & parameter : commandIt->second.params )
|
for ( auto const & parameter : commandIt->second.params )
|
||||||
{
|
{
|
||||||
if ( handleData.first != parameter.type.type ) // the commands use this handleData type !
|
if ( isHandleType( parameter.type.type ) && ( handleData.first != parameter.type.type ) ) // the commands use this handleData type !
|
||||||
{
|
{
|
||||||
appendType( str, parameter.type.type );
|
appendType( str, parameter.type.type );
|
||||||
}
|
}
|
||||||
@ -3028,6 +3047,17 @@ ${usingAlias}${leave})";
|
|||||||
void VulkanHppGenerator::appendHandles( std::string & str )
|
void VulkanHppGenerator::appendHandles( std::string & str )
|
||||||
{
|
{
|
||||||
// Note reordering structs or handles by features and extensions is not possible!
|
// Note reordering structs or handles by features and extensions is not possible!
|
||||||
|
// first, forward declare all the structs!
|
||||||
|
for ( auto const & structure : m_structures )
|
||||||
|
{
|
||||||
|
std::string enter, leave;
|
||||||
|
std::tie( enter, leave ) = generateProtection( structure.first, !structure.second.aliases.empty() );
|
||||||
|
str += enter + ( structure.second.isUnion ? " union " : " struct " ) + stripPrefix( structure.first, "Vk" ) + ";\n" + leave;
|
||||||
|
for ( auto const & alias : structure.second.aliases )
|
||||||
|
{
|
||||||
|
str += " using " + stripPrefix( alias, "Vk" ) + " = " + stripPrefix( structure.first, "Vk" ) + ";\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
for ( auto const & handle : m_handles )
|
for ( auto const & handle : m_handles )
|
||||||
{
|
{
|
||||||
if ( m_listedTypes.find( handle.first ) == m_listedTypes.end() )
|
if ( m_listedTypes.find( handle.first ) == m_listedTypes.end() )
|
||||||
@ -16216,17 +16246,6 @@ extern "C" __declspec( dllimport ) FARPROC __stdcall GetProcAddress( HINSTANCE h
|
|||||||
# include <compare>
|
# include <compare>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
)";
|
|
||||||
|
|
||||||
static const std::string is_error_code_enum = R"(
|
|
||||||
#ifndef VULKAN_HPP_NO_EXCEPTIONS
|
|
||||||
namespace std
|
|
||||||
{
|
|
||||||
template <>
|
|
||||||
struct is_error_code_enum<VULKAN_HPP_NAMESPACE::Result> : public true_type
|
|
||||||
{};
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
)";
|
)";
|
||||||
|
|
||||||
static const std::string structResultValue = R"(
|
static const std::string structResultValue = R"(
|
||||||
@ -16540,10 +16559,79 @@ namespace std
|
|||||||
std::cout << "VulkanHppGenerator: Parsing " << filename << std::endl;
|
std::cout << "VulkanHppGenerator: Parsing " << filename << std::endl;
|
||||||
VulkanHppGenerator generator( doc );
|
VulkanHppGenerator generator( doc );
|
||||||
|
|
||||||
std::cout << "VulkanHppGenerator: Generating " << VULKAN_HPP_FILE << std::endl;
|
std::cout << "VulkanHppGenerator: Generating" << VULKAN_ENUMS_HPP_FILE << " ..." << std::endl;
|
||||||
std::string str;
|
std::string str;
|
||||||
static const size_t estimatedLength = 4 * 1024 * 1024;
|
str = generator.getVulkanLicenseHeader();
|
||||||
str.reserve( estimatedLength );
|
str += +R"(
|
||||||
|
#ifndef VULKAN_ENUMS_HPP
|
||||||
|
# define VULKAN_ENUMS_HPP
|
||||||
|
|
||||||
|
namespace VULKAN_HPP_NAMESPACE
|
||||||
|
{
|
||||||
|
)";
|
||||||
|
str += typeTraits;
|
||||||
|
generator.appendEnums( str );
|
||||||
|
generator.appendIndexTypeTraits( str );
|
||||||
|
str += generator.generateBitmasks();
|
||||||
|
str += R"(
|
||||||
|
} // namespace VULKAN_HPP_NAMESPACE
|
||||||
|
#endif
|
||||||
|
)";
|
||||||
|
writeToFile( str, VULKAN_ENUMS_HPP_FILE );
|
||||||
|
|
||||||
|
std::cout << "VulkanHppGenerator: Generating " << VULKAN_HANDLES_HPP_FILE << " ..." << std::endl;
|
||||||
|
str.clear();
|
||||||
|
str = generator.getVulkanLicenseHeader();
|
||||||
|
str += +R"(
|
||||||
|
#ifndef VULKAN_HANDLES_HPP
|
||||||
|
# define VULKAN_HANDLES_HPP
|
||||||
|
|
||||||
|
namespace VULKAN_HPP_NAMESPACE
|
||||||
|
{
|
||||||
|
)";
|
||||||
|
generator.appendHandles( str );
|
||||||
|
str += R"(
|
||||||
|
} // namespace VULKAN_HPP_NAMESPACE
|
||||||
|
#endif
|
||||||
|
)";
|
||||||
|
writeToFile( str, VULKAN_HANDLES_HPP_FILE );
|
||||||
|
|
||||||
|
std::cout << "VulkanHppGenerator: Generating " << VULKAN_STRUCTS_HPP_FILE << " ..." << std::endl;
|
||||||
|
str.clear();
|
||||||
|
str = generator.getVulkanLicenseHeader();
|
||||||
|
str += +R"(
|
||||||
|
#ifndef VULKAN_STRUCTS_HPP
|
||||||
|
# define VULKAN_STRUCTS_HPP
|
||||||
|
|
||||||
|
namespace VULKAN_HPP_NAMESPACE
|
||||||
|
{
|
||||||
|
)";
|
||||||
|
generator.appendStructs( str );
|
||||||
|
str += R"(
|
||||||
|
} // namespace VULKAN_HPP_NAMESPACE
|
||||||
|
#endif
|
||||||
|
)";
|
||||||
|
writeToFile( str, VULKAN_STRUCTS_HPP_FILE );
|
||||||
|
|
||||||
|
std::cout << "VulkanHppGenerator: Generating " << VULKAN_FUNCS_HPP_FILE << " ..." << std::endl;
|
||||||
|
str.clear();
|
||||||
|
str = generator.getVulkanLicenseHeader();
|
||||||
|
str += +R"(
|
||||||
|
#ifndef VULKAN_FUNCS_HPP
|
||||||
|
# define VULKAN_FUNCS_HPP
|
||||||
|
|
||||||
|
namespace VULKAN_HPP_NAMESPACE
|
||||||
|
{
|
||||||
|
)";
|
||||||
|
generator.appendHandlesCommandDefinitions( str );
|
||||||
|
str += R"(
|
||||||
|
} // namespace VULKAN_HPP_NAMESPACE
|
||||||
|
#endif
|
||||||
|
)";
|
||||||
|
writeToFile( str, VULKAN_FUNCS_HPP_FILE );
|
||||||
|
|
||||||
|
std::cout << "VulkanHppGenerator: Generating " << VULKAN_HPP_FILE << " ..." << std::endl;
|
||||||
|
str.clear();
|
||||||
str += generator.getVulkanLicenseHeader() + includes + "\n";
|
str += generator.getVulkanLicenseHeader() + includes + "\n";
|
||||||
str += "static_assert( VK_HEADER_VERSION == " + generator.getVersion() +
|
str += "static_assert( VK_HEADER_VERSION == " + generator.getVersion() +
|
||||||
" , \"Wrong VK_HEADER_VERSION!\" );\n"
|
" , \"Wrong VK_HEADER_VERSION!\" );\n"
|
||||||
@ -16563,18 +16651,38 @@ namespace std
|
|||||||
generator.appendDispatchLoaderDefault( str );
|
generator.appendDispatchLoaderDefault( str );
|
||||||
str += classObjectDestroy + classObjectFree + classObjectRelease + classPoolFree + "\n";
|
str += classObjectDestroy + classObjectFree + classObjectRelease + classPoolFree + "\n";
|
||||||
str += generator.generateBaseTypes();
|
str += generator.generateBaseTypes();
|
||||||
str += typeTraits;
|
str += R"(} // namespace VULKAN_HPP_NAMESPACE
|
||||||
generator.appendEnums( str );
|
|
||||||
generator.appendIndexTypeTraits( str );
|
#include <vulkan/vulkan_enums.hpp>
|
||||||
str += generator.generateBitmasks();
|
|
||||||
str += "} // namespace VULKAN_HPP_NAMESPACE\n" + is_error_code_enum + "\n" + "namespace VULKAN_HPP_NAMESPACE\n" +
|
#ifndef VULKAN_HPP_NO_EXCEPTIONS
|
||||||
"{\n" + "#ifndef VULKAN_HPP_NO_EXCEPTIONS" + exceptions;
|
namespace std
|
||||||
|
{
|
||||||
|
template <>
|
||||||
|
struct is_error_code_enum<VULKAN_HPP_NAMESPACE::Result> : public true_type
|
||||||
|
{};
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace VULKAN_HPP_NAMESPACE
|
||||||
|
{
|
||||||
|
#ifndef VULKAN_HPP_NO_EXCEPTIONS
|
||||||
|
)";
|
||||||
|
str += exceptions;
|
||||||
generator.appendResultExceptions( str );
|
generator.appendResultExceptions( str );
|
||||||
generator.appendThrowExceptions( str );
|
generator.appendThrowExceptions( str );
|
||||||
str += "#endif\n" + structResultValue;
|
str += "#endif\n" + structResultValue;
|
||||||
generator.appendStructs( str );
|
str += R"(} // namespace VULKAN_HPP_NAMESPACE
|
||||||
generator.appendHandles( str );
|
|
||||||
generator.appendHandlesCommandDefinitions( str );
|
// clang-format off
|
||||||
|
#include <vulkan/vulkan_handles.hpp>
|
||||||
|
#include <vulkan/vulkan_structs.hpp>
|
||||||
|
#include <vulkan/vulkan_funcs.hpp>
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
|
namespace VULKAN_HPP_NAMESPACE
|
||||||
|
{
|
||||||
|
)";
|
||||||
generator.appendStructureChainValidation( str );
|
generator.appendStructureChainValidation( str );
|
||||||
generator.appendDispatchLoaderDynamic( str );
|
generator.appendDispatchLoaderDynamic( str );
|
||||||
str +=
|
str +=
|
||||||
@ -16587,24 +16695,9 @@ namespace std
|
|||||||
"} // namespace std\n"
|
"} // namespace std\n"
|
||||||
"#endif\n";
|
"#endif\n";
|
||||||
|
|
||||||
std::ofstream ofs( VULKAN_HPP_FILE );
|
writeToFile( str, VULKAN_HPP_FILE );
|
||||||
assert( !ofs.fail() );
|
|
||||||
ofs << str;
|
|
||||||
ofs.close();
|
|
||||||
|
|
||||||
#if defined( CLANG_FORMAT_EXECUTABLE )
|
std::cout << "VulkanHppGenerator: Generating " << VULKAN_RAII_HPP_FILE << " ..." << std::endl;
|
||||||
int ret = std::system( "\"" CLANG_FORMAT_EXECUTABLE "\" --version" );
|
|
||||||
assert( ret == 0 );
|
|
||||||
std::cout << "VulkanHppGenerator: Formatting " << VULKAN_HPP_FILE << " using clang-format..." << std::endl;
|
|
||||||
ret = std::system( "\"" CLANG_FORMAT_EXECUTABLE "\" -i --style=file " VULKAN_HPP_FILE );
|
|
||||||
if ( ret != 0 )
|
|
||||||
{
|
|
||||||
std::cout << "VulkanHppGenerator: failed to format file " << VULKAN_HPP_FILE << " with error <" << ret << ">\n";
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
std::cout << "VulkanHppGenerator: Generating " << VULKAN_RAII_HPP_FILE << std::endl;
|
|
||||||
str.clear();
|
str.clear();
|
||||||
str = generator.getVulkanLicenseHeader() + R"(
|
str = generator.getVulkanLicenseHeader() + R"(
|
||||||
#ifndef VULKAN_RAII_HPP
|
#ifndef VULKAN_RAII_HPP
|
||||||
@ -16648,21 +16741,9 @@ namespace VULKAN_HPP_NAMESPACE
|
|||||||
#endif
|
#endif
|
||||||
)";
|
)";
|
||||||
|
|
||||||
ofs.open( VULKAN_RAII_HPP_FILE );
|
writeToFile( str, VULKAN_RAII_HPP_FILE );
|
||||||
assert( !ofs.fail() );
|
|
||||||
ofs << str;
|
|
||||||
ofs.close();
|
|
||||||
|
|
||||||
#if defined( CLANG_FORMAT_EXECUTABLE )
|
#if !defined( CLANG_FORMAT_EXECUTABLE )
|
||||||
std::cout << "VulkanHppGenerator: Formatting " << VULKAN_RAII_HPP_FILE << " using clang-format..." << std::endl;
|
|
||||||
ret = std::system( "\"" CLANG_FORMAT_EXECUTABLE "\" -i --style=file " VULKAN_RAII_HPP_FILE );
|
|
||||||
if ( ret != 0 )
|
|
||||||
{
|
|
||||||
std::cout << "VulkanHppGenerator: failed to format file " << VULKAN_RAII_HPP_FILE << " with error <" << ret
|
|
||||||
<< ">\n";
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
std::cout
|
std::cout
|
||||||
<< "VulkanHppGenerator: could not find clang-format. The generated files will not be formatted accordingly.\n";
|
<< "VulkanHppGenerator: could not find clang-format. The generated files will not be formatted accordingly.\n";
|
||||||
#endif
|
#endif
|
||||||
|
114132
vulkan/vulkan.hpp
114132
vulkan/vulkan.hpp
File diff suppressed because it is too large
Load Diff
13987
vulkan/vulkan_enums.hpp
Normal file
13987
vulkan/vulkan_enums.hpp
Normal file
File diff suppressed because it is too large
Load Diff
18043
vulkan/vulkan_funcs.hpp
Normal file
18043
vulkan/vulkan_funcs.hpp
Normal file
File diff suppressed because it is too large
Load Diff
13511
vulkan/vulkan_handles.hpp
Normal file
13511
vulkan/vulkan_handles.hpp
Normal file
File diff suppressed because it is too large
Load Diff
69492
vulkan/vulkan_structs.hpp
Normal file
69492
vulkan/vulkan_structs.hpp
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user