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

Return to documentation for file (include\playback\vulkan-range-repeat-cache-swapchain.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 "playback/vulkan-range-repeat-cache-resources.h"

#include <list>
#include <vector>

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

namespace gpa {
namespace playback {

class Callable;

namespace repeat {
namespace vulkan {
// =============================== RangeRepeatCacheVkSwapChain ==============================
class RangeRepeatCacheVkSwapChain : public RangeRepeatCacheVK
{
public:
    struct BackBufferEntry
    {
        uint64_t key;
        VkImage image;
    };

private:
    uint32_t mSwapChainImageCount = 0;
    std::vector<BackBufferEntry> mSwapChainImages;
    uint32_t mCurrentRepeatOffset = 0;

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

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

    // custom
    void RegisterBackBuffer(uint32_t imageCount, uint32_t bbIndex, VkImage image, uint64_t key);
    std::vector<BackBufferEntry>& SwapChainImages();
    uint32_t GetCurrentSwapChainImageOffset();
};
// =============================== RangeRepeatCacheVkSwapChainImage ==============================
class RangeRepeatCacheVkSwapChainImage : public RangeRepeatCacheVkImage
{
    bool mIsSwapChainImage = false;
    uint32_t mSwapChainImageIndex = UINT32_MAX;
    RangeRepeatCacheVkSwapChain::Ptr mSwapChainCachePtr = nullptr;

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

    bool IsSwapChainImage() const override;

    uint32_t SwapChainImageIndex();
    RangeRepeatCacheVkSwapChain::Ptr SwapChainCachePtr();
};
// =============================== RangeRepeatCacheVkImageView ==============================
class RangeRepeatCacheVkImageView : public RangeRepeatCacheVK
{
    bool mIsSwapChainImageView = false;
    // TODO: document what this is. Generally if an imageview targets the swapchain image, this is
    // the array of imageviews for all the swapchain images
    std::vector<VkImageView> mSwapChainImageViews;

    VkDevice mDevice = VK_NULL_HANDLE;
    VkImageViewCreateInfo mImageViewInfo = {};

    uint32_t mCurrentRepeatOffset = 0;

    struct VkImageViewPNextElement
    {
        union
        {
            VkBaseInStructure vkBaseInStructure;
            VkImageViewASTCDecodeModeEXT vkImageViewASTCDecodeModeEXT;
            VkImageViewUsageCreateInfo vkImageViewUsageCreateInfo;
            VkSamplerYcbcrConversionInfo vkSamplerYcbcrConversionInfo;
        };
    };
    std::list<VkImageViewPNextElement> mImageViewInfoPNextChain;

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

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

    bool IsSwapChainImageView();
    std::vector<VkImageView>& SwapChainImageViews();
};
// =============================== RangeRepeatCacheVkFrameBuffer ==============================
class RangeRepeatCacheVkFramebuffer : public RangeRepeatCacheVK
{
    bool mIsFrameBufferWithSwapChainImageView = false;

    std::vector<VkFramebuffer> mFrameBuffersWithSwapChainImageViews;
    uint32_t mReferencedSwapChainImageIndex = 0;
    uint32_t mSwapChainImageViewAttachmentIndex = UINT32_MAX;
    RangeRepeatCacheVkImageView::Ptr mReferencedSwapChainImageViewCache = nullptr;

    VkDevice mDevice = VK_NULL_HANDLE;
    VkFramebufferCreateInfo mFrameBufferInfo = {};

    uint32_t mCurrentRepeatOffset = 0;

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

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

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