summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/bgfx/src/debug_renderdoc.cpp
diff options
context:
space:
mode:
author Branimir Karadžić <branimirkaradzic@gmail.com>2016-04-04 13:52:25 +0200
committer Miodrag Milanovic <mmicko@gmail.com>2016-04-04 13:52:25 +0200
commite63f379a0ef420cf720b7655ea63e19330954eb8 (patch)
tree1c51de36d7fbd9f5218b165b71f3ec9aa1bcfe36 /3rdparty/bgfx/src/debug_renderdoc.cpp
parent9496a5b24d7fb14dcb38bd16ec8ca528ebdfee1b (diff)
Update BGFX to latest (nw)
Diffstat (limited to '3rdparty/bgfx/src/debug_renderdoc.cpp')
-rw-r--r--3rdparty/bgfx/src/debug_renderdoc.cpp126
1 files changed, 126 insertions, 0 deletions
diff --git a/3rdparty/bgfx/src/debug_renderdoc.cpp b/3rdparty/bgfx/src/debug_renderdoc.cpp
new file mode 100644
index 00000000000..0cb7be99d64
--- /dev/null
+++ b/3rdparty/bgfx/src/debug_renderdoc.cpp
@@ -0,0 +1,126 @@
+/*
+ * Copyright 2011-2016 Branimir Karadzic. All rights reserved.
+ * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
+ */
+
+#include "bgfx_p.h"
+
+#if BGFX_CONFIG_DEBUG_PIX && (BX_PLATFORM_WINDOWS || BX_PLATFORM_LINUX)
+# if BX_PLATFORM_WINDOWS
+# include <psapi.h>
+# endif // BX_PLATFORM_WINDOWS
+# include <renderdoc/renderdoc_app.h>
+
+namespace bgfx
+{
+ bool findModule(const char* _name)
+ {
+#if BX_PLATFORM_WINDOWS
+ HANDLE process = GetCurrentProcess();
+ DWORD size;
+ BOOL result = EnumProcessModules(process
+ , NULL
+ , 0
+ , &size
+ );
+ if (0 != result)
+ {
+ HMODULE* modules = (HMODULE*)alloca(size);
+ result = EnumProcessModules(process
+ , modules
+ , size
+ , &size
+ );
+
+ if (0 != result)
+ {
+ char moduleName[MAX_PATH];
+ for (uint32_t ii = 0, num = uint32_t(size/sizeof(HMODULE) ); ii < num; ++ii)
+ {
+ result = GetModuleBaseNameA(process
+ , modules[ii]
+ , moduleName
+ , BX_COUNTOF(moduleName)
+ );
+ if (0 != result
+ && 0 == bx::stricmp(_name, moduleName) )
+ {
+ return true;
+ }
+ }
+ }
+ }
+#endif // BX_PLATFORM_WINDOWS
+ BX_UNUSED(_name);
+ return false;
+ }
+
+ pRENDERDOC_GetAPI RENDERDOC_GetAPI;
+ static RENDERDOC_API_1_0_0* s_renderDoc;
+
+ void* loadRenderDoc()
+ {
+ // Skip loading RenderDoc when IntelGPA is present to avoid RenderDoc crash.
+ if (findModule(BX_ARCH_32BIT ? "shimloader32.dll" : "shimloader64.dll") )
+ {
+ return NULL;
+ }
+
+ void* renderdocdll = bx::dlopen("renderdoc.dll");
+
+ if (NULL != renderdocdll)
+ {
+ RENDERDOC_GetAPI = (pRENDERDOC_GetAPI)bx::dlsym(renderdocdll, "RENDERDOC_GetAPI");
+ if (NULL != RENDERDOC_GetAPI
+ && 1 == RENDERDOC_GetAPI(eRENDERDOC_API_Version_1_0_0, (void**)&s_renderDoc) )
+ {
+ s_renderDoc->SetLogFilePathTemplate("temp/bgfx");
+
+ s_renderDoc->SetFocusToggleKeys(NULL, 0);
+
+ RENDERDOC_InputButton captureKey = eRENDERDOC_Key_F11;
+ s_renderDoc->SetCaptureKeys(&captureKey, 1);
+
+ s_renderDoc->SetCaptureOptionU32(eRENDERDOC_Option_AllowVSync, 1);
+ s_renderDoc->SetCaptureOptionU32(eRENDERDOC_Option_SaveAllInitials, 1);
+
+ s_renderDoc->MaskOverlayBits(eRENDERDOC_Overlay_None, eRENDERDOC_Overlay_None);
+ }
+ else
+ {
+ bx::dlclose(renderdocdll);
+ renderdocdll = NULL;
+ }
+ }
+
+ return renderdocdll;
+ }
+
+ void unloadRenderDoc(void* _renderdocdll)
+ {
+ if (NULL != _renderdocdll)
+ {
+ s_renderDoc->Shutdown();
+ bx::dlclose(_renderdocdll);
+ }
+ }
+
+} // namespace bgfx
+
+#else
+
+namespace bgfx
+{
+
+ void* loadRenderDoc()
+ {
+ return NULL;
+ }
+
+ void unloadRenderDoc(void*)
+ {
+ }
+
+} // namespace bgfx
+
+#endif // BGFX_CONFIG_DEBUG_PIX && (BX_PLATFORM_WINDOWS || BX_PLATFORM_LINUX)