Skip to content

Commit

Permalink
Change move assignment operators of vk::raii handles from using std::…
Browse files Browse the repository at this point in the history
…exchange to using std::swap (#1607)
  • Loading branch information
asuessenbach authored Jun 28, 2023
1 parent 6c1996f commit 2613539
Show file tree
Hide file tree
Showing 3 changed files with 191 additions and 254 deletions.
11 changes: 0 additions & 11 deletions RAII_Samples/SurfaceCapabilities/SurfaceCapabilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ int main( int /*argc*/, char ** /*argv*/ )
.getSurfaceCapabilities2KHR<vk::SurfaceCapabilities2KHR,
vk::DisplayNativeHdrSurfaceCapabilitiesAMD,
vk::SharedPresentSurfaceCapabilitiesKHR,
vk::SurfaceCapabilitiesFullScreenExclusiveEXT,
vk::SurfaceProtectedCapabilitiesKHR>( { *surfaceData.surface } );

vk::SurfaceCapabilitiesKHR const & surfaceCapabilities = surfaceCapabilities2.get<vk::SurfaceCapabilities2KHR>().surfaceCapabilities;
Expand All @@ -112,16 +111,6 @@ int main( int /*argc*/, char ** /*argv*/ )
std::cout << "\n";
}

if ( vk::su::contains( extensionProperties, "VK_EXT_full_screen_exclusive" ) )
{
vk::SurfaceCapabilitiesFullScreenExclusiveEXT surfaceCapabilitiesFullScreenExclusive =
surfaceCapabilities2.get<vk::SurfaceCapabilitiesFullScreenExclusiveEXT>();
std::cout << std::string( "\t" ) << "SurfaceCapabilitiesFullScreenExclusiveEXT:\n";
std::cout << std::string( "\t\t" ) << "fullScreenExclusiveSupported = " << !!surfaceCapabilitiesFullScreenExclusive.fullScreenExclusiveSupported
<< "\n";
std::cout << "\n";
}

if ( vk::su::contains( extensionProperties, "VK_KHR_surface_protected_capabilities" ) )
{
vk::SurfaceProtectedCapabilitiesKHR surfaceProtectedCapabilities = surfaceCapabilities2.get<vk::SurfaceProtectedCapabilitiesKHR>();
Expand Down
21 changes: 7 additions & 14 deletions VulkanHppGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9254,8 +9254,6 @@ std::tuple<std::string, std::string, std::string, std::string, std::string, std:

if ( handle.second.destructorIt != m_commands.end() )
{
moveAssignmentInstructions = " clear();";

clearMembers = " if ( m_" + handleName + " )\n";
clearMembers += " {\n";
clearMembers += " getDispatcher()->" + handle.second.destructorIt->first + "( " +
Expand Down Expand Up @@ -9291,8 +9289,7 @@ std::tuple<std::string, std::string, std::string, std::string, std::string, std:
{
clearMembers += "\n m_" + memberName + " = nullptr;";
moveConstructorInitializerList += "m_" + memberName + "( VULKAN_HPP_NAMESPACE::VULKAN_HPP_RAII_NAMESPACE::exchange( rhs.m_" + memberName + ", {} ) ), ";
moveAssignmentInstructions +=
"\n m_" + memberName + " = VULKAN_HPP_NAMESPACE::VULKAN_HPP_RAII_NAMESPACE::exchange( rhs.m_" + memberName + ", {} );";
moveAssignmentInstructions += "\n std::swap( m_" + memberName + ", rhs.m_" + memberName + " );";
memberVariables += "\n " + memberType + " m_" + memberName + " = {};";
swapMembers += "\n std::swap( m_" + memberName + ", rhs.m_" + memberName + " );";
if ( destructorParam.type.type != handle.first )
Expand All @@ -9319,16 +9316,14 @@ std::tuple<std::string, std::string, std::string, std::string, std::string, std:

clearMembers += "\n m_" + frontName + " = nullptr;";
moveConstructorInitializerList = "m_" + frontName + "( VULKAN_HPP_NAMESPACE::VULKAN_HPP_RAII_NAMESPACE::exchange( rhs.m_" + frontName + ", {} ) ), ";
moveAssignmentInstructions =
"\n m_" + frontName + " = VULKAN_HPP_NAMESPACE::VULKAN_HPP_RAII_NAMESPACE::exchange( rhs.m_" + frontName + ", {} );";
memberVariables = "\n VULKAN_HPP_NAMESPACE::" + stripPrefix( frontType, "Vk" ) + " m_" + frontName + " = {};";
swapMembers = "\n std::swap( m_" + frontName + ", rhs.m_" + frontName + " );";
moveAssignmentInstructions = "\n std::swap( m_" + frontName + ", rhs.m_" + frontName + " );";
memberVariables = "\n VULKAN_HPP_NAMESPACE::" + stripPrefix( frontType, "Vk" ) + " m_" + frontName + " = {};";
swapMembers = "\n std::swap( m_" + frontName + ", rhs.m_" + frontName + " );";
releaseMembers += "\n m_" + frontName + " = nullptr;";
}
clearMembers += "\n m_" + handleName + " = nullptr;";
moveConstructorInitializerList += "m_" + handleName + "( VULKAN_HPP_NAMESPACE::VULKAN_HPP_RAII_NAMESPACE::exchange( rhs.m_" + handleName + ", {} ) ), ";
moveAssignmentInstructions +=
"\n m_" + handleName + " = VULKAN_HPP_NAMESPACE::VULKAN_HPP_RAII_NAMESPACE::exchange( rhs.m_" + handleName + ", {} );";
moveAssignmentInstructions += "\n std::swap( m_" + handleName + ", rhs.m_" + handleName + " );";
memberVariables += "\n " + generateNamespacedType( handle.first ) + " m_" + handleName + " = {};";
swapMembers += "\n std::swap( m_" + handleName + ", rhs.m_" + handleName + " );";
}
Expand All @@ -9340,8 +9335,7 @@ std::tuple<std::string, std::string, std::string, std::string, std::string, std:
swapMembers += "\n std::swap( m_constructorSuccessCode, rhs.m_constructorSuccessCode );";
moveConstructorInitializerList +=
"m_constructorSuccessCode( VULKAN_HPP_NAMESPACE::VULKAN_HPP_RAII_NAMESPACE::exchange( rhs.m_constructorSuccessCode, {} ) ), ";
moveAssignmentInstructions +=
"\n m_constructorSuccessCode = VULKAN_HPP_NAMESPACE::VULKAN_HPP_RAII_NAMESPACE::exchange( rhs.m_constructorSuccessCode, {} );";
moveAssignmentInstructions += "\n std::swap( m_constructorSuccessCode, rhs.m_constructorSuccessCode );";
releaseMembers += "\n m_constructorSuccessCode = VULKAN_HPP_NAMESPACE::Result::eErrorUnknown;";
}

Expand Down Expand Up @@ -9369,13 +9363,12 @@ std::tuple<std::string, std::string, std::string, std::string, std::string, std:
if ( ( handle.first == "VkInstance" ) || ( handle.first == "VkDevice" ) )
{
moveConstructorInitializerList += "m_dispatcher( rhs.m_dispatcher.release() )";
moveAssignmentInstructions += "\n m_dispatcher.reset( rhs.m_dispatcher.release() );";
}
else
{
moveConstructorInitializerList += "m_dispatcher( VULKAN_HPP_NAMESPACE::VULKAN_HPP_RAII_NAMESPACE::exchange( rhs.m_dispatcher, nullptr ) )";
moveAssignmentInstructions += "\n m_dispatcher = VULKAN_HPP_NAMESPACE::VULKAN_HPP_RAII_NAMESPACE::exchange( rhs.m_dispatcher, nullptr );";
}
moveAssignmentInstructions += "\n std::swap( m_dispatcher, rhs.m_dispatcher );";

return std::make_tuple(
clearMembers, getConstructorSuccessCode, memberVariables, moveConstructorInitializerList, moveAssignmentInstructions, swapMembers, releaseMembers );
Expand Down
Loading

0 comments on commit 2613539

Please sign in to comment.