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

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

#include <vector>
#include <list>
#include <atomic>
#include <map>
#include <set>

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

namespace gpa {
namespace playback {

class Callable;

namespace repeat {
namespace vulkan {

struct MemoryBarrierChange
{
    VkAccessFlags dstAccessMask;
};

struct MemoryBarrierUpdates
{
    std::map<VkDeviceMemory, MemoryBarrierChange> memoryBarrierChanges;
    std::map<VkBuffer, MemoryBarrierChange> bufferBarrierChanges;
    std::map<VkImage, MemoryBarrierChange> imageBarrierChanges;
};

// =============================== RangeRepeatCacheVkCommandBuffer ==============================
class RangeRepeatCacheVkCommandBuffer : public RangeRepeatCacheVKForCommandBufers
{
public:
    typedef std::shared_ptr<RangeRepeatCacheVkCommandBuffer> Ptr;
    RangeRepeatCacheVkCommandBuffer(void* object, uint64_t captureKey,
                                    playback::Context* context, playback::Callable* callable);
    virtual ~RangeRepeatCacheVkCommandBuffer();

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

    void AddCall(Callable* callable) override;
    void SetUsedInRange(bool value) override;
    void ClearCallables() override;

    void OnReset();
    void OnReincarnation(playback::Context* context, playback::Callable* callable);
    void EnumerateCallablesFromIncarnation(uint64_t timestamp,
                                           CallableCache::EnumerateCallablesCallback callback,
                                           void* userData);

    MemoryBarrierUpdates& GetMemoryBarrierUpdates();
    void AddModifiedBuffer(VkBuffer buffer);
    std::set<VkBuffer> const& ModifiedBuffers();

    VkDevice GetDevice();

private:
    void FreeUsedReplacements(GPADispatchTable const*& table);

    VkCommandBufferAllocateInfo mCommandBufferInfo;
    VkDevice mDevice = VK_NULL_HANDLE;
    VkCommandBuffer mCurrentCommandBuffer = VK_NULL_HANDLE;

    std::vector<VkCommandBuffer> mSecondaryCommandBuffers;

    std::vector<VkCommandBuffer> mUsedReplacements;

    // Tracking final barrier changes
    struct MemoryBarrierUpdates mMemoryBarrierUpdates;
    std::set<VkBuffer> mModifiedBuffers;

    std::vector<CmdBufferIncarnation> mIncarnations;
};

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