Program Listing for File vulkan-range-repeat-cache-resources.h

Return to documentation for file (include\playback\vulkan-range-repeat-cache-resources.h)

/******************************************************************************
© Intel Corporation.

This software and the related documents are Intel copyrighted materials,
and your use of them is governed by the express license under which they
were provided to you ("License"). Unless the License provides otherwise,
you may not use, modify, copy, publish, distribute, disclose or transmit
this software or the related documents without Intel's prior written
permission.


 This software and the related documents are provided as is, with no express
or implied warranties, other than those that are expressly stated in the
License.

******************************************************************************/

#pragma once

#include "playback/vulkan-range-repeat-cache.h"
#include "vk-state-tracking/VkStateTracker.h"
#include "vk-resource-utilities/managed-buffer.h"

#include <vector>

#define VK_NO_PROTOTYPES
#include <vulkan/vulkan.h>
#undef VK_NO_PROTOTYPES

namespace gpa {
namespace playback {

class Callable;

namespace repeat {
namespace vulkan {

class RangeRepeatCacheVkSwapChain;

// =============================== RangeRepeatCacheVkDeviceMemory ==============================
class RangeRepeatCacheVkDeviceMemory : public RangeRepeatCacheVK
{
    VkMemoryAllocateInfo mAllocateInfo = {};
    vulkan_state::DeviceMemory::MapInfo mMapInfoAtRangeStart = {};

public:
    typedef std::shared_ptr<RangeRepeatCacheVkDeviceMemory> Ptr;
    RangeRepeatCacheVkDeviceMemory(VkDeviceMemory object, uint64_t captureKey,
                                   playback::Context* context, playback::Callable* callable);
    virtual ~RangeRepeatCacheVkDeviceMemory();

    void OnRangeEnter(GPADispatchTable const*& table) override;
    void OnRangeRepeatRestoreState(GPADispatchTable const*& table, uint64_t repeatPass) override;
    void OnRangeExit(GPADispatchTable const*& table) override;

    VkMemoryAllocateInfo const& AllocateInfo() const;
};

struct ResourceMemoryBindingInfo
{
    VkDeviceMemory memory;
    VkDeviceSize memoryOffset;
};

// =============================== RangeRepeatCacheVkImage ==============================
class RangeRepeatCacheVkImage : public RangeRepeatCacheVK
{
    // Creation info
    VkDevice mDevice = VK_NULL_HANDLE;
    VkImageCreateInfo mImageInfo = {};

    // Recreation info
    VkCommandPool mCommandPool = VK_NULL_HANDLE;
    ResourceMemoryBindingInfo mMemoryBindingInfo = {};
    std::unordered_map<VkImageAspectFlags, vulkan_state::Image::BarrierState> mBarrierStateAtRangeStart;
    RangeRepeatCacheVK::Ptr mDeviceMemoryCachePtr = nullptr;

public:
    typedef std::shared_ptr<RangeRepeatCacheVkImage> Ptr;
    RangeRepeatCacheVkImage(VkImage object, uint64_t captureKey, playback::Context* context,
                            playback::Callable* callable);
    virtual ~RangeRepeatCacheVkImage();

    void OnRangeEnter(GPADispatchTable const*& table) override;
    void OnRangeRepeatRecreateObject(GPADispatchTable const*& table, uint64_t repeatPass) override;
    void OnRangeRepeatRestoreState(GPADispatchTable const*& table, uint64_t repeatPass) override;

    virtual bool IsSwapChainImage() const;
};

// =============================== RangeRepeatCacheVkBuffer ==============================
class RangeRepeatCacheVkBuffer : public RangeRepeatCacheVK
{
    bool mIsDirty = false;

    // Creation info
    VkDevice mDevice = VK_NULL_HANDLE;
    VkPhysicalDevice mPhysicalDevice = VK_NULL_HANDLE;
    VkBufferCreateInfo mBufferInfo = {};

    ResourceMemoryBindingInfo mMemoryBindingInfo = {};
    RangeRepeatCacheVK::Ptr mDeviceMemoryCachePtr = nullptr;

    // Recreation info
    VkCommandPool mCommandPool = VK_NULL_HANDLE;
    VkCommandBuffer mRestorationCommandBuffer = VK_NULL_HANDLE;
    vulkan_resources::ManagedBuffer mMirror;

public:
    typedef std::shared_ptr<RangeRepeatCacheVkBuffer> Ptr;
    RangeRepeatCacheVkBuffer(VkBuffer object, uint64_t captureKey, playback::Context* context,
                             playback::Callable* callable);
    virtual ~RangeRepeatCacheVkBuffer();

    void OnRangeEnter(GPADispatchTable const*& table) override;
    void OnRangeRepeatRecreateObject(GPADispatchTable const*& table, uint64_t repeatPass) override;
    void OnRangeRepeatRestoreState(GPADispatchTable const*& table, uint64_t repeatPass) override;

    void SetDirty(GPADispatchTable const*& table);

private:
    VkCommandBuffer AllocateAndRecordStateRestorationCommandBuffer(
        VkDevice device, VkCommandPool commandPool, VkBuffer buffer, VkDeviceSize bufferSize, GPADispatchTable const*& table);
};

// =============================== RangeRepeatCacheVkBufferView ==============================
class RangeRepeatCacheVkBufferView : public RangeRepeatCacheVK
{
    VkDevice mDevice = VK_NULL_HANDLE;
    VkBufferViewCreateInfo mBufferViewInfo = {};

public:
    typedef std::shared_ptr<RangeRepeatCacheVkBufferView> Ptr;
    RangeRepeatCacheVkBufferView(VkBufferView object, uint64_t captureKey,
                                 playback::Context* context, playback::Callable* callable);
    virtual ~RangeRepeatCacheVkBufferView();

    void OnRangeRepeatRecreateObject(GPADispatchTable const*& table, uint64_t repeatPass) override;
};

}  // namespace vulkan
}  // namespace repeat
}  // namespace playback
}  // namespace gpa