PipelineCacheVk.h#

The Pipeline Cache class.

Includes#

  • PVRVk/DeviceVk.h

Included By#

Namespaces#

Classes#

Source Code#

#pragma once
#include "PVRVk/DeviceVk.h"
namespace pvrvk {
namespace impl {
class PipelineCache_ : public PVRVkDeviceObjectBase<VkPipelineCache, ObjectType::e_PIPELINE_CACHE>, public DeviceObjectDebugUtils<PipelineCache_>
{
private:
    friend class Device_;

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

    static PipelineCache constructShared(const DeviceWeakPtr& device, const PipelineCacheCreateInfo& createInfo)
    {
        return std::make_shared<PipelineCache_>(make_shared_enabler{}, device, createInfo);
    }

    PipelineCacheCreateInfo _createInfo;

public:
    DECLARE_NO_COPY_SEMANTICS(PipelineCache_)
    PipelineCache_(make_shared_enabler, const DeviceWeakPtr& device, const PipelineCacheCreateInfo& createInfo) : PVRVkDeviceObjectBase(device), DeviceObjectDebugUtils()
    {
        _createInfo = createInfo;

        VkPipelineCacheCreateInfo vkCreateInfo = {};
        vkCreateInfo.sType = static_cast<VkStructureType>(StructureType::e_PIPELINE_CACHE_CREATE_INFO);
        vkCreateInfo.flags = static_cast<VkPipelineCacheCreateFlags>(_createInfo.getFlags());
        vkCreateInfo.initialDataSize = _createInfo.getInitialDataSize();
        vkCreateInfo.pInitialData = _createInfo.getInitialData();

        vkThrowIfFailed(getDevice()->getVkBindings().vkCreatePipelineCache(getDevice()->getVkHandle(), &vkCreateInfo, nullptr, &_vkHandle), "Failed to create Pipeline Cache");
    }

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

    inline PipelineCacheCreateFlags getFlags() const { return _createInfo.getFlags(); }
    inline size_t getInitialDataSize() const { return _createInfo.getInitialDataSize(); }
    inline const void* getInitialData() const { return _createInfo.getInitialData(); }

    size_t getCacheMaxDataSize() const
    {
        size_t dataSize = 0;
        vkThrowIfFailed(getDevice()->getVkBindings().vkGetPipelineCacheData(getDevice()->getVkHandle(), getVkHandle(), &dataSize, nullptr), "Failed to get max pipeline cache data size");
        return dataSize;
    }

    size_t getCacheData(size_t size, void* inOutData) const
    {
        assert(size && inOutData && "size and the data must be valid");
        size_t mySize = size;
        getDevice()->getVkBindings().vkGetPipelineCacheData(getDevice()->getVkHandle(), getVkHandle(), &mySize, inOutData);
        return mySize;
    }

    PipelineCacheCreateInfo getCreateInfo() const { return _createInfo; }
};
} // namespace impl
} // namespace pvrvk