HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
render_doc.hpp
1// Copyright Take Vos 2020.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
8
9#include "renderdoc_app.h"
10#include "../utility/utility.hpp" // XXX #620
11#include "../char_maps/char_maps.hpp" // XXX #616
12#include "../telemetry/telemetry.hpp"
13#include "../macros.hpp"
14#include <type_traits>
15#include <filesystem>
16
17hi_export_module(hikogui.GFX.render_doc);
18
19hi_export namespace hi { inline namespace v1 {
20
21inline void *render_doc_api = nullptr;
22
23inline void render_doc_set_overlay(bool frameRate, bool frameNumber, bool captureList) noexcept
24{
25 if (not render_doc_api) {
26 return;
27 }
28
29 uint32_t or_mask = eRENDERDOC_Overlay_None;
30 uint32_t and_mask = eRENDERDOC_Overlay_None;
31
32 if (frameRate || frameNumber || captureList) {
33 or_mask |= eRENDERDOC_Overlay_Enabled;
34 } else {
35 and_mask |= eRENDERDOC_Overlay_Enabled;
36 }
37
38 if (frameRate) {
39 or_mask |= eRENDERDOC_Overlay_FrameRate;
40 } else {
41 and_mask |= eRENDERDOC_Overlay_FrameRate;
42 }
43
44 if (frameNumber) {
45 or_mask |= eRENDERDOC_Overlay_FrameNumber;
46 } else {
47 and_mask |= eRENDERDOC_Overlay_FrameNumber;
48 }
49
50 if (captureList) {
51 or_mask |= eRENDERDOC_Overlay_CaptureList;
52 } else {
53 and_mask |= eRENDERDOC_Overlay_CaptureList;
54 }
55
56 auto& api_ = *static_cast<RENDERDOC_API_1_4_1 *>(render_doc_api);
57
58 and_mask = ~and_mask;
59 api_.MaskOverlayBits(and_mask, or_mask);
60}
61
62inline void start_render_doc() noexcept
63{
64#ifndef NDEBUG
65#if HI_OPERATING_SYSTEM == HI_OS_WINDOWS
66 auto const dll_urls = std::vector{
67 std::filesystem::path{"renderdoc.dll"},
68 std::filesystem::path{"C:/Program Files/RenderDoc/renderdoc.dll"},
69 std::filesystem::path{"C:/Program Files (x86)/RenderDoc/renderdoc.dll"}};
70
71 auto mod = [&]() -> HMODULE {
72 for (auto const& dll_url : dll_urls) {
73 hi_log_debug("Trying to load: {}", dll_url.string());
74
75 if (auto mod = LoadLibraryW(dll_url.native().c_str())) {
76 return mod;
77 }
78 }
79 return nullptr;
80 }();
81
82 if (mod == nullptr) {
83 hi_log_warning("Could not load renderdoc.dll");
84 return;
85 }
86
87 auto RENDERDOC_GetAPI = (pRENDERDOC_GetAPI)GetProcAddress(mod, "RENDERDOC_GetAPI");
88 if (RENDERDOC_GetAPI == nullptr) {
89 hi_log_error("Could not find RENDERDOC_GetAPI in renderdoc.dll");
90 return;
91 }
92
93 int ret = RENDERDOC_GetAPI(eRENDERDOC_API_Version_1_4_1, &render_doc_api);
94 if (ret != 1) {
95 hi_log_error("RENDERDOC_GetAPI returns invalid value {}", ret);
96 render_doc_api = nullptr;
97 }
98
99 // At init, on linux/android.
100 // For android replace librenderdoc.so with libVkLayer_GLES_RenderDoc.so
101 // if(void *mod = dlopen("librenderdoc.so", RTLD_NOW | RTLD_NOLOAD))
102 //{
103 // pRENDERDOC_GetAPI RENDERDOC_GetAPI = (pRENDERDOC_GetAPI)dlsym(mod, "RENDERDOC_GetAPI");
104 // int ret = RENDERDOC_GetAPI(eRENDERDOC_API_Version_1_1_2, (void **)&rdoc_api);
105 // assert(ret == 1);
106 //}
107
108 render_doc_set_overlay(false, false, false);
109#endif
110#endif
111}
112
113
114}} // namespace hi::inline v1
Rules for working with win32 headers.
The HikoGUI namespace.
Definition array_generic.hpp:20
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
Definition renderdoc_app.h:579