Program Listing for File vulkan-range-repeat-cache.h
↰ Return to documentation for file (include\playback\vulkan-range-repeat-cache.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 "instrumentation/gpa-secure.h"
#include "logger/logger.h"
#include "object-map/object-map.h"
#include "playback/range-repeat-cache.h"
#include "playback-support/playback-support.h"
#include "reflection/argument.h"
#include "serialization/apicallcontext.h"
#if defined(_WIN32) || defined(_WIN64)
#define gvk_dlopen(LIBRARY_NAME) (void*)gpa::secure::LoadLibrarySDL(LIBRARY_NAME)
#endif
#include "gvk-defines.hpp"
#include "gvk-restore-info.hpp"
#include "gvk-structures.hpp"
#include "VK_LAYER_INTEL_gvk_state_tracker.hpp"
#define VK_NO_PROTOTYPES
#include <vulkan/vulkan.h>
#undef VK_NO_PROTOTYPES
#include "utility/assert.h"
#include <vector>
#define GVK_RESTORE_POINT_REPEAT_ENABLED 1
namespace gpa {
namespace playback {
class Callable;
namespace repeat {
namespace vulkan {
template<class BaseClass>
class RangeRepeatCacheVKInternal
: public BaseClass
{
public:
typedef std::shared_ptr<RangeRepeatCacheVKInternal<BaseClass>> Ptr;
RangeRepeatCacheVKInternal(VkObjectType objectType, void* object, uint64_t captureKey, Context* pContext, Callable* pCallable)
: BaseClass(pContext, pCallable)
, mObjectType{objectType}
{
GPA_ASSERT(pCallable);
mCreationCallable = *pCallable;
BaseClass::SetObject(captureKey, object);
uint64_t* pParentHandle = nullptr;
auto const* pPossiblyParentHandleArgument = pCallable->Argument(0, (const void**)&pParentHandle);
GPA_ASSERT(pPossiblyParentHandleArgument);
if (pPossiblyParentHandleArgument->Type() == serialization::BasicType::kHandle && pParentHandle) {
mParentHandle = *pParentHandle;
}
}
virtual ~RangeRepeatCacheVKInternal() override {}
virtual void OnRangeEnter(GPADispatchTable const*&) override { mRangeEntered = true; }
virtual void OnRangeRepeatRecreateObject(GPADispatchTable const*& pDispatchTable, uint64_t repeatPass)
{
(void)pDispatchTable;
(void)repeatPass;
// TODO : Maybe better to do during RangeRepeatCacheVkInstance objMap update
BaseClass::mObject = BaseClass::mContext->objMap->AcquireObject(BaseClass::mObjectKey);
GPA_ASSERT(BaseClass::mObject && "Could not obtain object from object map");
}
virtual void OnRangeRepeatDestroyObject(GPADispatchTable const*& table, uint64_t repeatPass) override
{
(void)table;
(void)repeatPass;
auto stateTrackedObject = gvk::get_default<GvkStateTrackedObject>();
stateTrackedObject.type = mObjectType;
stateTrackedObject.handle = (uint64_t)BaseClass::Object();
switch (stateTrackedObject.type) {
case VK_OBJECT_TYPE_INSTANCE:
case VK_OBJECT_TYPE_PHYSICAL_DEVICE:
case VK_OBJECT_TYPE_DEVICE:
case VK_OBJECT_TYPE_QUEUE:
case VK_OBJECT_TYPE_COMMAND_BUFFER: {
stateTrackedObject.dispatchableHandle = stateTrackedObject.handle;
} break;
default: {
stateTrackedObject.dispatchableHandle = mParentHandle;
} break;
}
MarkObjectForDestruction(stateTrackedObject);
}
virtual void OnRangeRepeatRestoreState(GPADispatchTable const*& pDispatchTable, uint64_t repeatPass)
{
(void)pDispatchTable;
mLastRestoreStatePass = repeatPass;
}
virtual void OnRangeExit(GPADispatchTable const*& pDispatchTable)
{
(void)pDispatchTable;
mRangeEntered = false;
BaseClass::mUsedInRange = false;
}
uint32_t GetCreationCallFunToken() const { return mCreationCallable.Token()._function; }
playback::Callable const& GetCreationCallable() const { return mCreationCallable; }
uint64_t GetParentHandle() { return mParentHandle; }
protected:
bool RangeEntered() { return mRangeEntered; }
bool ObjectRecreatedInThisPass(uint64_t pass) { return (pass == mLastRecreateObjectPass); }
bool StateRestoredInThisPass(uint64_t pass) { return (pass == mLastRestoreStatePass); }
static std::vector<GvkStateTrackedObject>& GetObjectsMarkedForDestruction()
{
static std::vector<GvkStateTrackedObject> sObjectsMarkedForDestruction;
return sObjectsMarkedForDestruction;
}
static void MarkObjectForDestruction(GvkStateTrackedObject const& stateTrackedObject)
{
GPA_ASSERT(stateTrackedObject.type);
GPA_ASSERT(stateTrackedObject.handle);
GPA_ASSERT(stateTrackedObject.dispatchableHandle);
auto& objectsMarkedForDestruction = GetObjectsMarkedForDestruction();
auto itr = std::lower_bound(objectsMarkedForDestruction.begin(), objectsMarkedForDestruction.end(), stateTrackedObject);
if (itr == objectsMarkedForDestruction.end() || *itr != stateTrackedObject) {
objectsMarkedForDestruction.insert(itr, stateTrackedObject);
}
}
private:
Callable mCreationCallable;
bool mRangeEntered{};
VkObjectType mObjectType{};
protected:
uint64_t mLastRecreateObjectPass{UINT64_MAX};
uint64_t mLastRestoreStatePass{UINT64_MAX};
uint64_t mParentHandle{};
};
using RangeRepeatCacheVK = RangeRepeatCacheVKInternal<gpa::playback::repeat::RangeRepeatCache>;
using RangeRepeatCacheVKForCommandBufers = RangeRepeatCacheVKInternal<gpa::playback::repeat::RangeRepeatCacheForCommandBuffers>;
} // namespace vulkan
} // namespace repeat
} // namespace playback
} // namespace gpa