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