CommandPoolVk.h#

The PVRVk CommandPool, a pool that can Allocate and Free Command Buffers.

Includes#

  • PVRVk/DeviceVk.h

Included By#

Namespaces#

Classes#

Source Code#

#pragma once
#include "PVRVk/DeviceVk.h"

namespace pvrvk {
struct CommandPoolCreateInfo
{
public:
    explicit CommandPoolCreateInfo(uint32_t queueFamilyIndex, CommandPoolCreateFlags flags = CommandPoolCreateFlags::e_NONE) : _flags(flags), _queueFamilyIndex(queueFamilyIndex) {}

    inline CommandPoolCreateFlags getFlags() const { return _flags; }
    inline void setFlags(CommandPoolCreateFlags flags) { this->_flags = flags; }
    inline uint32_t getQueueFamilyIndex() const { return _queueFamilyIndex; }
    inline void setQueueFamilyIndex(uint32_t queueFamilyIndex) { this->_queueFamilyIndex = queueFamilyIndex; }

private:
    CommandPoolCreateFlags _flags;
    uint32_t _queueFamilyIndex;
};

namespace impl {
class CommandPool_ : public PVRVkDeviceObjectBase<VkCommandPool, ObjectType::e_COMMAND_POOL>, public DeviceObjectDebugUtils<CommandPool_>, public std::enable_shared_from_this<CommandPool_>
{
private:
    friend class Device_;

    class make_shared_enabler
    {
    protected:
        make_shared_enabler() {}
        friend class CommandPool_;
    };

    static CommandPool constructShared(const DeviceWeakPtr& device, const CommandPoolCreateInfo& createInfo)
    {
        return std::make_shared<CommandPool_>(make_shared_enabler{}, device, createInfo);
    }

    CommandPoolCreateInfo _createInfo;

public:
    DECLARE_NO_COPY_SEMANTICS(CommandPool_)
    CommandPool_(make_shared_enabler, const DeviceWeakPtr& device, const CommandPoolCreateInfo& createInfo);

    ~CommandPool_()
    {
        if (getVkHandle() != VK_NULL_HANDLE)
        {
            if (!_device.expired())
            {
                getDevice()->getVkBindings().vkDestroyCommandPool(getDevice()->getVkHandle(), getVkHandle(), nullptr);
                _vkHandle = VK_NULL_HANDLE;
            }
            else
            {
                reportDestroyedAfterDevice();
            }
        }
    }

    CommandBuffer allocateCommandBuffer();

    void allocateCommandBuffers(uint32_t numCommandbuffers, CommandBuffer* outCmdBuffers);

    SecondaryCommandBuffer allocateSecondaryCommandBuffer();

    void allocateSecondaryCommandBuffers(uint32_t numCommandbuffers, SecondaryCommandBuffer* outCmdBuffers);

    inline CommandPoolCreateFlags getFlags() const { return _createInfo.getFlags(); }
    inline uint32_t getQueueFamilyIndex() const { return _createInfo.getQueueFamilyIndex(); }

    void reset(pvrvk::CommandPoolResetFlags flags);
};
} // namespace impl
} // namespace pvrvk