mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-05-05 01:20:42 +00:00
2d6290bab1
Captures can be manually triggered from renderdoccmd capture <application> using F12 or from the UI on the in-development Metal replay branch. The captures can be loaded and replayed on the in-development Metal replay branch. The command buffer tracking and serialization are done by GPU submission order which is not necessarily the same as CPU commit order. The command buffer tracking for GPU submission order is currently using an rdcarray, this might change in the future to use a linked list if the performance of appending and deleting from the rdcarray becomes a performance bottleneck. Does not include support for the presented MTLDrawable ie. * Thumbnail generation of the final presented image. * Serializing the presented texture ID. Does not include support for initial state data. No MTLBuffer data contents are serialized. There is a lot missing and a lot of TODOs. This is the basic structure for capturing which is then built upon. Includes: * register the Metal device as a frame capturer ie. AddDeviceFrameCapturer * logic for triggering captures at Present ie. AddActiveDriver, StartFrameCapture, EndFrameCapture. * Stopped declaring MetalResourceManager as a friend of WrappedMTLDevice which meant making the initial state-related APIs public instead of private. * IFrameCapturer interface APIs * Command buffer tracking for including in the output capture CaptureCmdBufCommit and CaptureCmdBufEnqueue. * Serialise_MTLCreateSystemDefaultDevice(SerialiserType &ser) * A helper class MetalCapturer which is derived from IFrameCapturer and registered with the RenderDoc instance. This is because Wrapped Metal classes can't have virtual tables as a requirement for how the C++ and Objective C overlay is implemented. * The frame capture chunk and API AddFrameCaptureRecordChunk * MetalInitParams data and serialization. Helper Methods and Members in MTLDevice * WaitForGPU() * MTL::CommandQueue *m_mtlCommandQueue which is used to implement WaitForGPU() * CaptureClearSubmittedCmdBuffers() & CaptureCmdBufSubmit() * RegisterMetalLayer() & UnregisterMetalLayer() used to track active Metal swapchains Details on the memory lifetime for WrappedMTLCommandBuffer retain the real resource in WrappedMTLCommandBuffer::commit() release the real resource when no longer needed to be tracked: for background capture in during WrappedMTLDevice::CaptureCmdBufSubmit, for active capture in WrappedMTLDevice::EndFrameCapture. During capture (Background or Active) * AddRef() record when command buffer is enqueued (explicit or implicit) * Delete() record at end of command buffer submit During Active capture * AddRef() record in command buffer submit * Delete() submitted command buffers as part of finalizing the capture Added TrackedCAMetalLayer & ObjCTrackedCAMetalLayer to track the lifetime of CA::MetalLayer. The CA::MetalLayer is tracked in the hook for CAMetalLayer::nextDrawable(), with ObjCTrackedCAMetalLayer set as an association to the CAMetalLayer. Then ObjCTrackedCAMetalLayer::dealloc() triggers ending the tracking.
138 lines
3.6 KiB
C++
138 lines
3.6 KiB
C++
/******************************************************************************
|
|
* The MIT License (MIT)
|
|
*
|
|
* Copyright (c) 2019-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 "renderdoccmd.h"
|
|
#include <locale.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
#include <string>
|
|
|
|
// helpers defined in cocoa_window.mm
|
|
extern void *cocoa_windowCreate(int width, int height, const char *title);
|
|
extern void *cocoa_windowGetView(void *cocoaWindow);
|
|
extern void *cocoa_windowGetLayer(void *cocoaWindow);
|
|
extern bool cocoa_windowShouldClose(void *cocoaWindow);
|
|
extern bool cocoa_windowPoll(unsigned short &appleKeyCode);
|
|
|
|
void Daemonise()
|
|
{
|
|
}
|
|
|
|
WindowingData DisplayRemoteServerPreview(bool active, const rdcarray<WindowingSystem> &systems)
|
|
{
|
|
WindowingData ret = {WindowingSystem::Unknown};
|
|
return ret;
|
|
}
|
|
|
|
void DisplayRendererPreview(IReplayController *renderer, TextureDisplay &displayCfg, uint32_t width,
|
|
uint32_t height, uint32_t numLoops)
|
|
{
|
|
void *cocoaWindow = cocoa_windowCreate(width, height, "renderdoccmd");
|
|
void *view = cocoa_windowGetView(cocoaWindow);
|
|
void *layer = cocoa_windowGetLayer(cocoaWindow);
|
|
IReplayOutput *out =
|
|
renderer->CreateOutput(CreateMacOSWindowingData(view, layer), ReplayOutputType::Texture);
|
|
|
|
out->SetTextureDisplay(displayCfg);
|
|
|
|
uint32_t loopCount = 0;
|
|
|
|
bool done = false;
|
|
while(!done)
|
|
{
|
|
if(cocoa_windowShouldClose(cocoaWindow))
|
|
{
|
|
break;
|
|
}
|
|
|
|
unsigned short appleKeyCode;
|
|
if(cocoa_windowPoll(appleKeyCode))
|
|
{
|
|
// kVK_Escape
|
|
if(appleKeyCode == 0x35)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
|
|
renderer->SetFrameEvent(10000000, true);
|
|
out->Display();
|
|
|
|
usleep(100000);
|
|
|
|
loopCount++;
|
|
|
|
if(numLoops > 0 && loopCount == numLoops)
|
|
break;
|
|
}
|
|
}
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
setlocale(LC_CTYPE, "");
|
|
|
|
// do any apple-specific setup here
|
|
|
|
// process any apple-specific arguments here
|
|
|
|
GlobalEnvironment env;
|
|
|
|
// add compiled-in support to version line
|
|
{
|
|
std::string support = "APIs supported at compile-time: ";
|
|
int count = 0;
|
|
|
|
#if defined(RENDERDOC_SUPPORT_VULKAN)
|
|
support += "Vulkan, ";
|
|
count++;
|
|
#endif
|
|
|
|
#if defined(RENDERDOC_SUPPORT_GL)
|
|
support += "GL, ";
|
|
count++;
|
|
#endif
|
|
|
|
#if defined(RENDERDOC_SUPPORT_METAL)
|
|
support += "Metal, ";
|
|
count++;
|
|
#endif
|
|
|
|
if(count == 0)
|
|
{
|
|
support += "None.";
|
|
}
|
|
else
|
|
{
|
|
// remove trailing ', '
|
|
support.pop_back();
|
|
support.pop_back();
|
|
support += ".";
|
|
}
|
|
|
|
add_version_line(support);
|
|
}
|
|
|
|
return renderdoccmd(env, argc, argv);
|
|
}
|