Metal: Added ability to make capture programmatically.

This commit is contained in:
Бранимир Караџић
2025-10-28 15:51:22 -07:00
parent 0fb116cf45
commit 45df9833a9
3 changed files with 41 additions and 2 deletions

View File

@@ -2410,7 +2410,7 @@ namespace bgfx
id pool;
};
#endif // BX_PLATFORM_OSX
#endif // BX_PLATFORM_OSX || BX_PLATFORM_IOS || BX_PLATFORM_VISIONOS
RenderFrame::Enum Context::renderFrame(int32_t _msecs)
{
@@ -2418,7 +2418,7 @@ namespace bgfx
#if BX_PLATFORM_OSX || BX_PLATFORM_IOS || BX_PLATFORM_VISIONOS
NSAutoreleasePoolScope pool;
#endif // BX_PLATFORM_OSX
#endif // BX_PLATFORM_OSX || BX_PLATFORM_IOS || BX_PLATFORM_VISIONOS
if (!m_flipAfterRender)
{

View File

@@ -1093,6 +1093,20 @@ namespace bgfx { namespace mtl
typedef MTLRenderPipelineReflection* RenderPipelineReflection;
typedef MTLCaptureManager* CaptureManager;
MTLCaptureManager* getSharedCaptureManager()
{
return [MTLCaptureManager sharedCaptureManager];
}
typedef MTLCaptureDescriptor* CaptureDescriptor;
inline MTLCaptureDescriptor* newCaptureDescriptor()
{
return [MTLCaptureDescriptor new];
}
//helper functions
inline void release(NSObject* _obj)
{

View File

@@ -4124,6 +4124,22 @@ BX_PRAGMA_DIAGNOSTIC_POP();
m_commandBuffer = m_cmd.alloc();
}
if (_render->m_capture)
{
CaptureManager captureMgr = getSharedCaptureManager();
CaptureDescriptor captureDesc = newCaptureDescriptor();
captureDesc.captureObject = m_device;
captureDesc.destination = MTLCaptureDestinationDeveloperTools;
NSError* err = NULL;
[captureMgr startCaptureWithDescriptor: captureDesc error: &err];
if (NULL != err)
{
BX_TRACE("Failed to start capture. Error %d: %s", err.code, err.localizedDescription.UTF8String);
}
}
BGFX_MTL_PROFILER_BEGIN_LITERAL("rendererSubmit", kColorFrame);
int64_t timeBegin = bx::getHPCounter();
@@ -5336,6 +5352,15 @@ BX_PRAGMA_DIAGNOSTIC_POP();
m_renderCommandEncoderFrameBufferHandle = BGFX_INVALID_HANDLE;
if (_render->m_capture)
{
CaptureManager captureMgr = getSharedCaptureManager();
if ([captureMgr isCapturing])
{
[captureMgr stopCapture];
}
}
if (m_screenshotTarget)
{
RenderPassDescriptor renderPassDescriptor = newRenderPassDescriptor();