Merge pull request #990 from asuessenbach/raii

Introduce VULKAN_HPP_RAII_ENABLE_DEFAULT_CONSTRUCTORS
This commit is contained in:
Andreas Süßenbach 2021-06-21 09:21:25 +02:00 committed by GitHub
commit 93b682419b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 474 additions and 114 deletions

View File

@ -565,6 +565,11 @@ By defining ```VULKAN_HPP_NO_SMART_HANDLE``` before including vulkan.hpp, the he
With C++20, the so-called spaceship-operator ```<=>``` is introduced. If that operator is supported, all the structs and classes in vulkan.hpp use the default implementation of it. As currently some implementations of this operator are very slow, and others seem to be incomplete, by defining ```VULKAN_HPP_NO_SPACESHIP_OPERATOR``` before including vulkan.hpp you can remove that operator from those structs and classes.
#### VULKAN_HPP_RAII_ENABLE_DEFAULT_CONSTRUCTORS
By default, the vk::raii wrapper classes don't support default constructors. It would be a contradiction to the raii-principle.
For those who are desparate enough to ignore that restriction, you can define VULKAN_HPP_RAII_ENABLE_DEFAULT_CONSTRUCTORS. The only thing you can do with a default contructed vk::raii wrapper object is move-assigning another vk::raii wrapper object onto it. And you have to make sure that that happens before you use it.
#### VULKAN_HPP_STORAGE_API
With this define you can specify whether the ```DispatchLoaderDynamic``` is imported or exported (see ```VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE```). If ```VULKAN_HPP_STORAGE_API``` is not defined externally, and ```VULKAN_HPP_STORAGE_SHARED``` is defined, depending on the ```VULKAN_HPP_STORAGE_SHARED_EXPORT``` being defined, ```VULKAN_HPP_STORAGE_API``` is either set to ```__declspec( dllexport )``` (for MSVC) / ```__attribute__( ( visibility( "default" ) ) )``` (for gcc or clang) or ```__declspec( dllimport )``` (for MSVC), respectively. For other compilers, you might specify the corresponding storage by defining ```VULKAN_HPP_STORAGE_API``` on your own.

View File

@ -3266,6 +3266,10 @@ ${members}
: vkGetInstanceProcAddr( getProcAddr )
{}
#if defined( VULKAN_HPP_RAII_ENABLE_DEFAULT_CONSTRUCTORS )
InstanceDispatcher() = default;
#endif
void init( VkInstance instance )
{
${initAssignments}
@ -3290,6 +3294,10 @@ ${members}
: vkGetDeviceProcAddr( getProcAddr )
{}
#if defined( VULKAN_HPP_RAII_ENABLE_DEFAULT_CONSTRUCTORS )
DeviceDispatcher() = default;
#endif
void init( VkDevice device )
{
${initAssignments}
@ -3420,7 +3428,11 @@ ${singularConstructors}
${upgradeConstructor}
${destructor}
#if defined( VULKAN_HPP_RAII_ENABLE_DEFAULT_CONSTRUCTORS )
${handleType}() = default;
#else
${handleType}() = delete;
#endif
${handleType}( ${handleType} const & ) = delete;
${handleType}( ${handleType} && rhs ) VULKAN_HPP_NOEXCEPT
: ${moveConstructorInitializerList}
@ -3480,7 +3492,11 @@ ${enter} class ${handleType}s : public std::vector<VULKAN_HPP_NAMESPACE::VULKAN
public:
${arrayConstructors}
#if defined( VULKAN_HPP_RAII_ENABLE_DEFAULT_CONSTRUCTORS )
${handleType}s() = default;
#else
${handleType}s() = delete;
#endif
${handleType}s( ${handleType}s const & ) = delete;
${handleType}s( ${handleType}s && rhs ) = default;
${handleType}s & operator=( ${handleType}s const & ) = delete;
@ -7371,7 +7387,15 @@ std::tuple<std::string, std::string, std::string, std::string>
", {} );";
if ( handle.second.destructorIt != m_commands.end() )
{
moveAssignmentInstructions = " getDispatcher()->" + destructorCall + ";\n" + moveAssignmentInstructions;
moveAssignmentInstructions = " if ( m_" + handleName +
" )\n"
" {\n"
" getDispatcher()->" +
destructorCall +
";\n"
" }\n"
" " +
moveAssignmentInstructions;
for ( auto const & destructorParam : handle.second.destructorIt->second.params )
{
if ( ( destructorParam.type.type != handle.first ) &&

File diff suppressed because it is too large Load Diff