diff options
Diffstat (limited to 'src/core/tools/renderdoc.cpp')
| -rw-r--r-- | src/core/tools/renderdoc.cpp | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/core/tools/renderdoc.cpp b/src/core/tools/renderdoc.cpp new file mode 100644 index 000000000..44d24822a --- /dev/null +++ b/src/core/tools/renderdoc.cpp | |||
| @@ -0,0 +1,55 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | #include <renderdoc_app.h> | ||
| 5 | |||
| 6 | #include "common/assert.h" | ||
| 7 | #include "common/dynamic_library.h" | ||
| 8 | #include "core/tools/renderdoc.h" | ||
| 9 | |||
| 10 | #ifdef WIN32 | ||
| 11 | #include <windows.h> | ||
| 12 | #else | ||
| 13 | #include <dlfcn.h> | ||
| 14 | #endif | ||
| 15 | |||
| 16 | namespace Tools { | ||
| 17 | |||
| 18 | RenderdocAPI::RenderdocAPI() { | ||
| 19 | #ifdef WIN32 | ||
| 20 | if (HMODULE mod = GetModuleHandleA("renderdoc.dll")) { | ||
| 21 | const auto RENDERDOC_GetAPI = | ||
| 22 | reinterpret_cast<pRENDERDOC_GetAPI>(GetProcAddress(mod, "RENDERDOC_GetAPI")); | ||
| 23 | const s32 ret = RENDERDOC_GetAPI(eRENDERDOC_API_Version_1_6_0, (void**)&rdoc_api); | ||
| 24 | ASSERT(ret == 1); | ||
| 25 | } | ||
| 26 | #else | ||
| 27 | #ifdef ANDROID | ||
| 28 | static constexpr const char RENDERDOC_LIB[] = "libVkLayer_GLES_RenderDoc.so"; | ||
| 29 | #else | ||
| 30 | static constexpr const char RENDERDOC_LIB[] = "librenderdoc.so"; | ||
| 31 | #endif | ||
| 32 | if (void* mod = dlopen(RENDERDOC_LIB, RTLD_NOW | RTLD_NOLOAD)) { | ||
| 33 | const auto RENDERDOC_GetAPI = | ||
| 34 | reinterpret_cast<pRENDERDOC_GetAPI>(dlsym(mod, "RENDERDOC_GetAPI")); | ||
| 35 | const s32 ret = RENDERDOC_GetAPI(eRENDERDOC_API_Version_1_6_0, (void**)&rdoc_api); | ||
| 36 | ASSERT(ret == 1); | ||
| 37 | } | ||
| 38 | #endif | ||
| 39 | } | ||
| 40 | |||
| 41 | RenderdocAPI::~RenderdocAPI() = default; | ||
| 42 | |||
| 43 | void RenderdocAPI::ToggleCapture() { | ||
| 44 | if (!rdoc_api) [[unlikely]] { | ||
| 45 | return; | ||
| 46 | } | ||
| 47 | if (!is_capturing) { | ||
| 48 | rdoc_api->StartFrameCapture(NULL, NULL); | ||
| 49 | } else { | ||
| 50 | rdoc_api->EndFrameCapture(NULL, NULL); | ||
| 51 | } | ||
| 52 | is_capturing = !is_capturing; | ||
| 53 | } | ||
| 54 | |||
| 55 | } // namespace Tools | ||