From 67b8b4521a54782fdd419d54392826ae0ca6f087 Mon Sep 17 00:00:00 2001 From: baldurk Date: Sat, 13 Sep 2014 13:19:34 +0100 Subject: [PATCH] Add api for applications aware of renderdoc to get list of captures --- renderdoc/api/app/renderdoc_app.h | 3 +++ renderdoc/core/core.cpp | 14 +++++++------- renderdoc/core/core.h | 20 ++++++++++++++------ renderdoc/core/remote_access.cpp | 16 +++++++--------- renderdoc/os/linux/linux_threading.cpp | 5 +++++ renderdoc/os/os_specific.h | 1 + renderdoc/os/win32/win32_threading.cpp | 7 +++++++ renderdoc/replay/entry_points.cpp | 25 +++++++++++++++++++++++++ 8 files changed, 69 insertions(+), 22 deletions(-) diff --git a/renderdoc/api/app/renderdoc_app.h b/renderdoc/api/app/renderdoc_app.h index f17528f81..43c215895 100644 --- a/renderdoc/api/app/renderdoc_app.h +++ b/renderdoc/api/app/renderdoc_app.h @@ -152,6 +152,9 @@ typedef void (RENDERDOC_CC *pRENDERDOC_SetLogFile)(const wchar_t *logfile); extern "C" RENDERDOC_API const wchar_t* RENDERDOC_CC RENDERDOC_GetLogFile(); typedef const wchar_t* (RENDERDOC_CC *pRENDERDOC_GetLogFile)(); +extern "C" RENDERDOC_API bool RENDERDOC_CC RENDERDOC_GetCapture(uint32_t idx, wchar_t *logfile, uint32_t *pathlength, uint64_t *timestamp); +typedef bool (RENDERDOC_CC *pRENDERDOC_GetCapture)(uint32_t idx, wchar_t *logfile, uint32_t *pathlength, uint64_t *timestamp); + extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_SetCaptureOptions(const CaptureOptions *opts); typedef void (RENDERDOC_CC *pRENDERDOC_SetCaptureOptions)(const CaptureOptions *opts); diff --git a/renderdoc/core/core.cpp b/renderdoc/core/core.cpp index 2b109076f..2ed5cb72d 100644 --- a/renderdoc/core/core.cpp +++ b/renderdoc/core/core.cpp @@ -179,16 +179,16 @@ RenderDoc::~RenderDoc() SAFE_DELETE(m_ExHandler); } - for(size_t i=0; i < m_CapturePaths.size(); i++) + for(size_t i=0; i < m_Captures.size(); i++) { - if(m_CaptureRetrieved[i]) + if(m_Captures[i].retrieved) { - RDCLOG("Removing remotely retrieved capture %ls", m_CapturePaths[i].c_str()); - FileIO::UnlinkFileW(m_CapturePaths[i].c_str()); + RDCLOG("Removing remotely retrieved capture %ls", m_Captures[i].path.c_str()); + FileIO::UnlinkFileW(m_Captures[i].path.c_str()); } else { - RDCLOG("'Leaking' unretrieved capture %ls", m_CapturePaths[i].c_str()); + RDCLOG("'Leaking' unretrieved capture %ls", m_Captures[i].path.c_str()); } } @@ -555,9 +555,9 @@ void RenderDoc::SuccessfullyWrittenLog() { RDCLOG("Written to disk: %ls", m_CurrentLogFile.c_str()); + CaptureData cap(m_CurrentLogFile, Timing::GetUnixTimestamp()); { SCOPED_LOCK(m_CaptureLock); - m_CapturePaths.push_back(m_CurrentLogFile); - m_CaptureRetrieved.push_back(false); + m_Captures.push_back(cap); } } diff --git a/renderdoc/core/core.h b/renderdoc/core/core.h index 21792680e..d46814c8c 100644 --- a/renderdoc/core/core.h +++ b/renderdoc/core/core.h @@ -125,6 +125,15 @@ struct RDCInitParams Serialiser *m_pDebugSerialiser; }; +struct CaptureData +{ + CaptureData(wstring p, uint64_t t) : path(p), timestamp(t), retrieved(false) {} + + wstring path; + uint64_t timestamp; + bool retrieved; +}; + enum LoadProgressSection { DebugManagerInit, @@ -172,18 +181,18 @@ class RenderDoc Serialiser *OpenWriteSerialiser(uint32_t frameNum, RDCInitParams *params, void *thpixels, size_t thlen, uint32_t thwidth, uint32_t thheight); void SuccessfullyWrittenLog(); - vector GetCaptures() + vector GetCaptures() { SCOPED_LOCK(m_CaptureLock); - return m_CapturePaths; + return m_Captures; } void MarkCaptureRetrieved(uint32_t idx) { SCOPED_LOCK(m_CaptureLock); - if(idx < m_CapturePaths.size()) + if(idx < m_Captures.size()) { - m_CaptureRetrieved[idx] = true; + m_Captures[idx].retrieved = true; } } @@ -254,8 +263,7 @@ class RenderDoc float *m_ProgressPtr; Threading::CriticalSection m_CaptureLock; - vector m_CapturePaths; - vector m_CaptureRetrieved; + vector m_Captures; map m_DriverNames; map m_ReplayDriverProviders; diff --git a/renderdoc/core/remote_access.cpp b/renderdoc/core/remote_access.cpp index 59915641a..5c0490f28 100644 --- a/renderdoc/core/remote_access.cpp +++ b/renderdoc/core/remote_access.cpp @@ -74,7 +74,7 @@ void RenderDoc::RemoteAccessClientThread(void *s) const int ticktime = 10; // tick every 10ms int curtime = 0; - vector captures; + vector captures; while(client) { @@ -104,7 +104,7 @@ void RenderDoc::RemoteAccessClientThread(void *s) } else { - vector caps = RenderDoc::Inst().GetCaptures(); + vector caps = RenderDoc::Inst().GetCaptures(); if(caps.size() != captures.size()) { @@ -114,15 +114,13 @@ void RenderDoc::RemoteAccessClientThread(void *s) packetType = ePacket_NewCapture; - uint64_t timestamp = FileIO::GetModifiedTimestamp(captures.back().c_str()); ser.Serialise("", idx); - ser.Serialise("", timestamp); - - ser.Serialise("", captures.back()); + ser.Serialise("", captures.back().timestamp); + ser.Serialise("", captures.back().path); uint32_t len = 128*1024; byte *thumb = new byte[len]; - RENDERDOC_GetThumbnail(captures.back().c_str(), thumb, len); + RENDERDOC_GetThumbnail(captures.back().path.c_str(), thumb, len); size_t l = len; ser.Serialise("", len); @@ -159,7 +157,7 @@ void RenderDoc::RemoteAccessClientThread(void *s) } else if(type == ePacket_CopyCapture) { - vector caps = RenderDoc::Inst().GetCaptures(); + vector caps = RenderDoc::Inst().GetCaptures(); uint32_t id = 0; recvser->Serialise("", id); @@ -176,7 +174,7 @@ void RenderDoc::RemoteAccessClientThread(void *s) ser.Rewind(); - if(!SendChunkedFile(client, ePacket_CopyCapture, caps[id].c_str(), ser, NULL)) + if(!SendChunkedFile(client, ePacket_CopyCapture, caps[id].path.c_str(), ser, NULL)) { SAFE_DELETE(client); continue; diff --git a/renderdoc/os/linux/linux_threading.cpp b/renderdoc/os/linux/linux_threading.cpp index 8cbff9533..ac13e61c1 100644 --- a/renderdoc/os/linux/linux_threading.cpp +++ b/renderdoc/os/linux/linux_threading.cpp @@ -40,6 +40,11 @@ uint64_t Timing::GetTick() return uint64_t(ts.tv_sec)*1000000000ULL + uint32_t(ts.tv_nsec & 0xffffffff); } +uint64_t Timing::GetUnixTimestamp() +{ + return (uint64_t)time(); +} + namespace Atomic { int32_t Inc32(volatile int32_t *i) diff --git a/renderdoc/os/os_specific.h b/renderdoc/os/os_specific.h index 0abf52d98..1746438e5 100644 --- a/renderdoc/os/os_specific.h +++ b/renderdoc/os/os_specific.h @@ -57,6 +57,7 @@ namespace Timing { double GetTickFrequency(); uint64_t GetTick(); + uint64_t GetUnixTimestamp(); }; namespace Threading diff --git a/renderdoc/os/win32/win32_threading.cpp b/renderdoc/os/win32/win32_threading.cpp index b0b585c89..988f78a4b 100644 --- a/renderdoc/os/win32/win32_threading.cpp +++ b/renderdoc/os/win32/win32_threading.cpp @@ -25,6 +25,8 @@ #include "os/os_specific.h" +#include + double Timing::GetTickFrequency() { LARGE_INTEGER li; @@ -40,6 +42,11 @@ uint64_t Timing::GetTick() return li.QuadPart; } +uint64_t Timing::GetUnixTimestamp() +{ + return (uint64_t)time(NULL); +} + namespace Atomic { int32_t Inc32(volatile int32_t *i) diff --git a/renderdoc/replay/entry_points.cpp b/renderdoc/replay/entry_points.cpp index faf058def..f67b6e69a 100644 --- a/renderdoc/replay/entry_points.cpp +++ b/renderdoc/replay/entry_points.cpp @@ -102,6 +102,31 @@ const wchar_t* RENDERDOC_CC RENDERDOC_GetLogFile() return RDCGETLOGFILE(); } +extern "C" RENDERDOC_API +bool RENDERDOC_CC RENDERDOC_GetCapture(uint32_t idx, wchar_t *logfile, uint32_t *pathlength, uint64_t *timestamp) +{ + vector caps = RenderDoc::Inst().GetCaptures(); + + if(idx >= (uint32_t)caps.size()) + { + if(logfile) logfile[0] = 0; + if(pathlength) *pathlength = 0; + if(timestamp) *timestamp = 0; + return false; + } + + CaptureData &c = caps[idx]; + + if(logfile) + memcpy(logfile, c.path.c_str(), sizeof(wchar_t)*(c.path.size()+1)); + if(pathlength) + *pathlength = uint32_t(c.path.size()+1); + if(timestamp) + *timestamp = c.timestamp; + + return true; +} + extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_TriggerExceptionHandler(void *exceptionPtrs, bool crashed) {