| 87 | } // namespace |
| 88 | |
| 89 | extern "C" void portRenderDocInit(void) |
| 90 | { |
| 91 | if (sInitTried) { |
| 92 | return; |
| 93 | } |
| 94 | sInitTried = true; |
| 95 | |
| 96 | const char *frames_env = std::getenv("SSB64_RENDERDOC_FRAMES"); |
| 97 | if (frames_env == nullptr || *frames_env == '\0') { |
| 98 | // Feature disabled — zero overhead, no logging noise. |
| 99 | return; |
| 100 | } |
| 101 | |
| 102 | if (std::strcmp(frames_env, "all") == 0) { |
| 103 | sCaptureAll = true; |
| 104 | } else { |
| 105 | sCaptureFrames = parse_frame_list(frames_env); |
| 106 | if (sCaptureFrames.empty()) { |
| 107 | port_log("SSB64: RenderDoc SSB64_RENDERDOC_FRAMES='%s' parsed to empty set; disabling\n", |
| 108 | frames_env); |
| 109 | return; |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | #ifdef _WIN32 |
| 114 | // If RenderDoc was injected at process launch, the DLL is already loaded. |
| 115 | // Otherwise try to load it from the default DLL search path, then fall |
| 116 | // back to the standard installer location. The installer does NOT add |
| 117 | // the install dir to PATH by default, so the hard-coded fallback catches |
| 118 | // the common "RenderDoc is installed but PATH isn't set" case. |
| 119 | HMODULE mod = GetModuleHandleA("renderdoc.dll"); |
| 120 | if (mod == nullptr) { |
| 121 | mod = LoadLibraryA("renderdoc.dll"); |
| 122 | } |
| 123 | if (mod == nullptr) { |
| 124 | // Common install locations. Users can override by adding the |
| 125 | // install dir to PATH or by injecting RenderDoc via the UI. |
| 126 | static const char *const kFallbackPaths[] = { |
| 127 | "C:\\Program Files\\RenderDoc\\renderdoc.dll", |
| 128 | "C:\\Program Files (x86)\\RenderDoc\\renderdoc.dll", |
| 129 | }; |
| 130 | for (const char *path : kFallbackPaths) { |
| 131 | mod = LoadLibraryA(path); |
| 132 | if (mod != nullptr) { |
| 133 | port_log("SSB64: RenderDoc loaded from fallback path %s\n", path); |
| 134 | break; |
| 135 | } |
| 136 | } |
| 137 | } |
| 138 | if (mod == nullptr) { |
| 139 | port_log("SSB64: RenderDoc requested but renderdoc.dll not loadable (not on PATH and not in default install dirs)\n"); |
| 140 | return; |
| 141 | } |
| 142 | pRENDERDOC_GetAPI getApi = |
| 143 | reinterpret_cast<pRENDERDOC_GetAPI>( |
| 144 | reinterpret_cast<void *>(GetProcAddress(mod, "RENDERDOC_GetAPI"))); |
| 145 | #else |
| 146 | // Linux/macOS: try librenderdoc.so. RTLD_NOLOAD first so we only probe |
no test coverage detected