• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2021 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 // RenderDoc:
7 //   Connection to renderdoc for capturing tests through its API.
8 //
9 
10 #include "RenderDoc.h"
11 
12 #include "common/angleutils.h"
13 #include "common/debug.h"
14 
RenderDoc()15 RenderDoc::RenderDoc() : mRenderDocModule(nullptr), mApi(nullptr) {}
16 
~RenderDoc()17 RenderDoc::~RenderDoc()
18 {
19     SafeDelete(mRenderDocModule);
20 }
21 
22 #if defined(ANGLE_PLATFORM_ANDROID) || defined(ANGLE_PLATFORM_LINUX) || \
23     defined(ANGLE_PLATFORM_WINDOWS)
24 #    include "third_party/renderdoc/src/renderdoc_app.h"
25 
26 #    if defined(ANGLE_PLATFORM_WINDOWS)
27 constexpr char kRenderDocModuleName[] = "renderdoc";
28 #    elif defined(ANGLE_PLATFORM_ANDROID)
29 constexpr char kRenderDocModuleName[] = "libVkLayer_GLES_RenderDoc";
30 #    else
31 constexpr char kRenderDocModuleName[] = "librenderdoc";
32 #    endif
33 
attach()34 void RenderDoc::attach()
35 {
36     mRenderDocModule = OpenSharedLibrary(kRenderDocModuleName, angle::SearchType::AlreadyLoaded);
37     if (mRenderDocModule == nullptr || mRenderDocModule->getNative() == nullptr)
38     {
39         return;
40     }
41     void *getApi = mRenderDocModule->getSymbol("RENDERDOC_GetAPI");
42     if (getApi == nullptr)
43     {
44         return;
45     }
46 
47     int result = reinterpret_cast<pRENDERDOC_GetAPI>(getApi)(eRENDERDOC_API_Version_1_1_2, &mApi);
48     if (result != 1)
49     {
50         ERR() << "RenderDoc module is present but API 1.1.2 is unavailable";
51         mApi = nullptr;
52     }
53 }
54 
startFrame()55 void RenderDoc::startFrame()
56 {
57     if (mApi)
58     {
59         static_cast<RENDERDOC_API_1_1_2 *>(mApi)->StartFrameCapture(nullptr, nullptr);
60     }
61 }
62 
endFrame()63 void RenderDoc::endFrame()
64 {
65     if (mApi)
66     {
67         static_cast<RENDERDOC_API_1_1_2 *>(mApi)->EndFrameCapture(nullptr, nullptr);
68     }
69 }
70 
71 #else  // defiend(ANGLE_PLATFORM_ANDROID) || defined(ANGLE_PLATFORM_LINUX) ||
72        // defined(ANGLE_PLATFORM_WINDOWS)
73 
74 // Stub out the implementation on unsupported platforms.
attach()75 void RenderDoc::attach()
76 {
77     mApi = nullptr;
78 }
79 
startFrame()80 void RenderDoc::startFrame() {}
81 
endFrame()82 void RenderDoc::endFrame() {}
83 
84 #endif  // defiend(ANGLE_PLATFORM_ANDROID) || defined(ANGLE_PLATFORM_LINUX) ||
85         // defined(ANGLE_PLATFORM_WINDOWS)
86