-
-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into shader-decomp
- Loading branch information
Showing
11 changed files
with
946 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project | ||
# SPDX-License-Identifier: GPL-2.0-or-later | ||
|
||
set(RENDERDOC_INCLUDE_DIR third_party/renderdoc) | ||
|
||
if (RENDERDOC_INCLUDE_DIR AND EXISTS "${RENDERDOC_INCLUDE_DIR}/renderdoc_app.h") | ||
file(STRINGS "${RENDERDOC_INCLUDE_DIR}/renderdoc_app.h" RENDERDOC_VERSION_LINE REGEX "typedef struct RENDERDOC_API") | ||
string(REGEX REPLACE ".*typedef struct RENDERDOC_API_([0-9]+)_([0-9]+)_([0-9]+).*" "\\1.\\2.\\3" RENDERDOC_VERSION "${RENDERDOC_VERSION_LINE}") | ||
unset(RENDERDOC_VERSION_LINE) | ||
endif() | ||
|
||
include(FindPackageHandleStandardArgs) | ||
find_package_handle_standard_args(RenderDoc | ||
REQUIRED_VARS RENDERDOC_INCLUDE_DIR | ||
VERSION_VAR RENDERDOC_VERSION | ||
) | ||
|
||
if (RenderDoc_FOUND AND NOT TARGET RenderDoc::API) | ||
add_library(RenderDoc::API INTERFACE IMPORTED) | ||
set_target_properties(RenderDoc::API PROPERTIES | ||
INTERFACE_INCLUDE_DIRECTORIES "${RENDERDOC_INCLUDE_DIR}" | ||
) | ||
endif() | ||
|
||
mark_as_advanced(RENDERDOC_INCLUDE_DIR) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
|
||
#pragma once | ||
#include <string> | ||
|
||
#include "helpers.hpp" | ||
|
||
#ifdef PANDA3DS_ENABLE_RENDERDOC | ||
namespace Renderdoc { | ||
// Loads renderdoc dynamic library module. | ||
void loadRenderdoc(); | ||
|
||
// Begins a capture if a renderdoc instance is attached. | ||
void startCapture(); | ||
|
||
// Ends current renderdoc capture. | ||
void endCapture(); | ||
|
||
// Triggers capturing process. | ||
void triggerCapture(); | ||
|
||
// Sets output directory for captures | ||
void setOutputDir(const std::string& path, const std::string& prefix); | ||
|
||
// Returns whether we've compiled with Renderdoc support | ||
static constexpr bool isSupported() { return true; } | ||
} // namespace Renderdoc | ||
#else | ||
namespace Renderdoc { | ||
static void loadRenderdoc() {} | ||
static void startCapture() { Helpers::panic("Tried to start a Renderdoc capture while support for renderdoc is disabled") } | ||
static void endCapture() { Helpers::panic("Tried to end a Renderdoc capture while support for renderdoc is disabled") } | ||
static void triggerCapture() { Helpers::panic("Tried to trigger a Renderdoc capture while support for renderdoc is disabled") } | ||
static void setOutputDir(const std::string& path, const std::string& prefix) {} | ||
static constexpr bool isSupported() { return false; } | ||
} // namespace Renderdoc | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
|
||
#ifdef PANDA3DS_ENABLE_RENDERDOC | ||
#include "renderdoc.hpp" | ||
|
||
#include <renderdoc_app.h> | ||
|
||
#ifdef _WIN32 | ||
#include <windows.h> | ||
#else | ||
#include <dlfcn.h> | ||
#endif | ||
|
||
#include <array> | ||
#include <filesystem> | ||
|
||
namespace Renderdoc { | ||
enum class CaptureState { | ||
Idle, | ||
Triggered, | ||
InProgress, | ||
}; | ||
|
||
static CaptureState captureState{CaptureState::Idle}; | ||
RENDERDOC_API_1_6_0* rdocAPI{}; | ||
|
||
void loadRenderdoc() { | ||
#ifdef WIN32 | ||
// Check if we are running in Renderdoc GUI | ||
HMODULE mod = GetModuleHandleA("renderdoc.dll"); | ||
if (!mod) { | ||
// If enabled in config, try to load RDoc runtime in offline mode | ||
HKEY h_reg_key; | ||
LONG result = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Classes\\RenderDoc.RDCCapture.1\\DefaultIcon\\", 0, KEY_READ, &h_reg_key); | ||
if (result != ERROR_SUCCESS) { | ||
return; | ||
} | ||
std::array<wchar_t, MAX_PATH> keyString{}; | ||
DWORD stringSize{keyString.size()}; | ||
result = RegQueryValueExW(h_reg_key, L"", 0, NULL, (LPBYTE)keyString.data(), &stringSize); | ||
if (result != ERROR_SUCCESS) { | ||
return; | ||
} | ||
|
||
std::filesystem::path path{keyString.cbegin(), keyString.cend()}; | ||
path = path.parent_path().append("renderdoc.dll"); | ||
const auto path_to_lib = path.generic_string(); | ||
mod = LoadLibraryA(path_to_lib.c_str()); | ||
} | ||
|
||
if (mod) { | ||
const auto RENDERDOC_GetAPI = reinterpret_cast<pRENDERDOC_GetAPI>(GetProcAddress(mod, "RENDERDOC_GetAPI")); | ||
const s32 ret = RENDERDOC_GetAPI(eRENDERDOC_API_Version_1_6_0, (void**)&rdocAPI); | ||
|
||
if (ret != 1) { | ||
Helpers::panic("Invalid return value from RENDERDOC_GetAPI"); | ||
} | ||
} | ||
#else | ||
#ifdef ANDROID | ||
static constexpr const char RENDERDOC_LIB[] = "libVkLayer_GLES_RenderDoc.so"; | ||
#else | ||
static constexpr const char RENDERDOC_LIB[] = "librenderdoc.so"; | ||
#endif | ||
if (void* mod = dlopen(RENDERDOC_LIB, RTLD_NOW | RTLD_NOLOAD)) { | ||
const auto RENDERDOC_GetAPI = reinterpret_cast<pRENDERDOC_GetAPI>(dlsym(mod, "RENDERDOC_GetAPI")); | ||
const s32 ret = RENDERDOC_GetAPI(eRENDERDOC_API_Version_1_6_0, (void**)&rdocAPI); | ||
|
||
if (ret != 1) { | ||
Helpers::panic("Invalid return value from RENDERDOC_GetAPI"); | ||
} | ||
} | ||
#endif | ||
if (rdocAPI) { | ||
// Disable default capture keys as they suppose to trigger present-to-present capturing | ||
// and it is not what we want | ||
rdocAPI->SetCaptureKeys(nullptr, 0); | ||
|
||
// Also remove rdoc crash handler | ||
rdocAPI->UnloadCrashHandler(); | ||
} | ||
} | ||
|
||
void startCapture() { | ||
if (!rdocAPI) { | ||
return; | ||
} | ||
|
||
if (captureState == CaptureState::Triggered) { | ||
rdocAPI->StartFrameCapture(nullptr, nullptr); | ||
captureState = CaptureState::InProgress; | ||
} | ||
} | ||
|
||
void endCapture() { | ||
if (!rdocAPI) { | ||
return; | ||
} | ||
|
||
if (captureState == CaptureState::InProgress) { | ||
rdocAPI->EndFrameCapture(nullptr, nullptr); | ||
captureState = CaptureState::Idle; | ||
} | ||
} | ||
|
||
void triggerCapture() { | ||
if (captureState == CaptureState::Idle) { | ||
captureState = CaptureState::Triggered; | ||
} | ||
} | ||
|
||
void setOutputDir(const std::string& path, const std::string& prefix) { | ||
if (rdocAPI) { | ||
rdocAPI->SetCaptureFilePathTemplate((path + '\\' + prefix).c_str()); | ||
} | ||
} | ||
} // namespace Renderdoc | ||
#endif |
Oops, something went wrong.