Metal Replay resource creation helper methods

Added WrappedMTLDevice
void AddResource(ResourceId id, ResourceType type, const char *defaultNamePrefix);
void DerivedResource(ResourceId parentLive, ResourceId child);
template <typename MetalType> void DerivedResource(MetalType parent, ResourceId child);

Start of MetalReplay implementation to support replay resource creation:
ResourceDescription &GetResourceDesc(ResourceId id);

MetalReplay instance is not created in this commit
This commit is contained in:
Jake Turner
2022-08-12 06:10:19 +01:00
committed by Baldur Karlsson
parent 3448195d8e
commit 34b6f47362
5 changed files with 127 additions and 0 deletions
+2
View File
@@ -49,6 +49,8 @@ set(sources
metal_helpers_bridge.mm
metal_serialise.cpp
metal_stringise.cpp
metal_replay.h
metal_replay.cpp
official/metal-cpp.h
official/metal-cpp.cpp)
+26
View File
@@ -27,6 +27,7 @@
#include "metal_buffer.h"
#include "metal_command_buffer.h"
#include "metal_device.h"
#include "metal_replay.h"
#include "metal_texture.h"
WriteSerialiser &WrappedMTLDevice::GetThreadSerialiser()
@@ -68,6 +69,31 @@ void WrappedMTLDevice::AddEvent()
METAL_NOT_IMPLEMENTED();
}
void WrappedMTLDevice::AddResource(ResourceId id, ResourceType type, const char *defaultNamePrefix)
{
ResourceDescription &descr = GetReplay()->GetResourceDesc(id);
uint64_t num;
memcpy(&num, &id, sizeof(uint64_t));
descr.name = defaultNamePrefix + (" " + ToStr(num));
descr.autogeneratedName = true;
descr.type = type;
AddResourceCurChunk(descr);
}
void WrappedMTLDevice::DerivedResource(ResourceId parentLive, ResourceId child)
{
ResourceId parentId = GetResourceManager()->GetOriginalID(parentLive);
GetReplay()->GetResourceDesc(parentId).derivedResources.push_back(child);
GetReplay()->GetResourceDesc(child).parentResources.push_back(parentId);
}
void WrappedMTLDevice::AddResourceCurChunk(ResourceDescription &descr)
{
descr.initialisationChunks.push_back((uint32_t)m_StructuredFile->chunks.size() - 1);
}
void WrappedMTLDevice::WaitForGPU()
{
MTL::CommandBuffer *mtlCommandBuffer = m_mtlCommandQueue->commandBuffer();
+15
View File
@@ -29,6 +29,7 @@
#include "metal_manager.h"
class WrappedMTLDevice;
class MetalReplay;
class MetalCapturer : public IFrameCapturer
{
@@ -133,6 +134,15 @@ public:
void AddEvent();
void AddAction(const ActionDescription &a);
MetalReplay *GetReplay() { return m_Replay; }
void AddResource(ResourceId id, ResourceType type, const char *defaultNamePrefix);
void DerivedResource(ResourceId parentLive, ResourceId child);
template <typename MetalType>
void DerivedResource(MetalType parent, ResourceId child)
{
DerivedResource(GetResID(parent), child);
}
enum
{
TypeEnum = eResDevice
@@ -157,6 +167,8 @@ private:
template <typename SerialiserType>
bool Serialise_BeginCaptureFrame(SerialiserType &ser);
void AddResourceCurChunk(ResourceDescription &descr);
WrappedMTLTexture *Common_NewTexture(RDMTL::TextureDescriptor &descriptor, MetalChunk chunkType,
bool ioSurfaceTexture, IOSurfaceRef iosurface,
NS::UInteger plane);
@@ -165,6 +177,8 @@ private:
MetalResourceManager *m_ResourceManager = NULL;
MetalReplay *m_Replay = NULL;
// Back buffer and swap chain emulation
Threading::CriticalSection m_CapturePotentialBackBuffersLock;
std::unordered_set<WrappedMTLTexture *> m_CapturePotentialBackBuffers;
@@ -174,6 +188,7 @@ private:
CaptureState m_State;
bool m_AppControlledCapture = false;
SDFile *m_StructuredFile = NULL;
uint64_t threadSerialiserTLSSlot;
Threading::CriticalSection m_ThreadSerialisersLock;
+44
View File
@@ -0,0 +1,44 @@
/******************************************************************************
* The MIT License (MIT)
*
* Copyright (c) 2022 Baldur Karlsson
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
******************************************************************************/
#include "metal_replay.h"
MetalReplay::MetalReplay(WrappedMTLDevice *wrappedMTLDevice)
{
m_pDriver = wrappedMTLDevice;
}
ResourceDescription &MetalReplay::GetResourceDesc(ResourceId id)
{
auto it = m_ResourceIdx.find(id);
if(it == m_ResourceIdx.end())
{
m_ResourceIdx[id] = m_Resources.size();
m_Resources.push_back(ResourceDescription());
m_Resources.back().resourceId = id;
return m_Resources.back();
}
return m_Resources[it->second];
}
+40
View File
@@ -0,0 +1,40 @@
/******************************************************************************
* The MIT License (MIT)
*
* Copyright (c) 2022 Baldur Karlsson
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
******************************************************************************/
#pragma once
#include "metal_common.h"
class MetalReplay
{
public:
MetalReplay(WrappedMTLDevice *wrappedMTLDevice);
virtual ~MetalReplay() {}
ResourceDescription &GetResourceDesc(ResourceId id);
private:
WrappedMTLDevice *m_pDriver = NULL;
rdcarray<ResourceDescription> m_Resources;
std::map<ResourceId, size_t> m_ResourceIdx;
};