diff --git a/renderdoc/driver/metal/CMakeLists.txt b/renderdoc/driver/metal/CMakeLists.txt index 4a2bb3be6..3fd133099 100644 --- a/renderdoc/driver/metal/CMakeLists.txt +++ b/renderdoc/driver/metal/CMakeLists.txt @@ -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) diff --git a/renderdoc/driver/metal/metal_core.cpp b/renderdoc/driver/metal/metal_core.cpp index 427073a03..de307a5fd 100644 --- a/renderdoc/driver/metal/metal_core.cpp +++ b/renderdoc/driver/metal/metal_core.cpp @@ -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(); diff --git a/renderdoc/driver/metal/metal_device.h b/renderdoc/driver/metal/metal_device.h index ed51e7571..6e35aa66b 100644 --- a/renderdoc/driver/metal/metal_device.h +++ b/renderdoc/driver/metal/metal_device.h @@ -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 + void DerivedResource(MetalType parent, ResourceId child) + { + DerivedResource(GetResID(parent), child); + } + enum { TypeEnum = eResDevice @@ -157,6 +167,8 @@ private: template 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 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; diff --git a/renderdoc/driver/metal/metal_replay.cpp b/renderdoc/driver/metal/metal_replay.cpp new file mode 100644 index 000000000..25087fa46 --- /dev/null +++ b/renderdoc/driver/metal/metal_replay.cpp @@ -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]; +} diff --git a/renderdoc/driver/metal/metal_replay.h b/renderdoc/driver/metal/metal_replay.h new file mode 100644 index 000000000..15779d4ce --- /dev/null +++ b/renderdoc/driver/metal/metal_replay.h @@ -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 m_Resources; + std::map m_ResourceIdx; +};