Giter VIP home page Giter VIP logo

Comments (5)

asuessenbach avatar asuessenbach commented on August 15, 2024

That might be a good addition to the vk::handles... but they're already nothrow_move_constructible, as checked by a static_assertion in vulkan_static_assertions.hpp.

from vulkan-hpp.

caiovpsilveira avatar caiovpsilveira commented on August 15, 2024

Yes, but consider the following:

I have a Swapchain class, that contains a device and a swapchainKHR.

I want to have multiple windows, so each window require it swapchains. I will use the same device to create these swapchains.
Because of that, I will use vk::SharedDevice to store the device handle in the Swapchain class.

My swapchain class will own the swapchainKHR. Because I already have the device handle for shared ownership, I will use vk::Swapchain KHR instead of vk::UniqueSwapchainKHR, to not have an extra copy of the parent handle, as UniqueHandle does.

class Swapchain
{
public:
    Swapchain() = default;
    Swapchain(vk::SharedDevice device, ...);
    ~Swapchain() noexcept;
private:
    vk::SharedDevice m_device;
    vk::SwapchainKHR m_swapchain;
}

~Swapchain() noexcept
{
    if (m_swapchain)
    {
        assert(m_device);
        m_device->destroySwapchainKHR(m_swapchain);
    }
}

Now consider what happens if I do Swapchain(Swapchain&&) = default;

SharedHandles provide move operators. So for that it's safe.
But because std::move(vk::SwapchainKHR) is a copy operation, it will discard the previous handle and now I have a leak and possibly a double call to m_device->destroy().

Because of that I need to implement a move constructor for the Swapchain class, which does std::swap.
Would be nice If I could just do = default instead.

from vulkan-hpp.

caiovpsilveira avatar caiovpsilveira commented on August 15, 2024

Or this is intended to be handled this way? Should vk::Handles be treated like regular pointers?

from vulkan-hpp.

asuessenbach avatar asuessenbach commented on August 15, 2024

Should vk::Handles be treated like regular pointers?

Yes, vk::Handles don't own anything. Otherwise, they would not be copyable.
If you want to manage ownership, you need to do it on your own or use something like vk::UniqueHandle, vk::SharedHandle, or vk::raii::Handle.

from vulkan-hpp.

caiovpsilveira avatar caiovpsilveira commented on August 15, 2024

Ok, then I misunderstood. Thanks for clarifying.

from vulkan-hpp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.