1 /*-------------------------------------------------------------------------
2 * Vulkan CTS Framework
3 * --------------------
4 *
5 * Copyright (c) 2018 The Khronos Group Inc.
6 * Copyright (c) 2018 Intel Corporation
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 *
20 *//*!
21 * \file
22 * \brief RenderDoc utility
23 *//*--------------------------------------------------------------------*/
24
25 #include "vkRenderDocUtil.hpp"
26
27 #include "deDynamicLibrary.hpp"
28 #include "deUniquePtr.hpp"
29 #include "tcuDefs.hpp"
30
31 #if defined(DEQP_HAVE_RENDERDOC_HEADER)
32 #include "renderdoc_app.h"
33 #endif
34 #include <stdexcept>
35
36 #if (DE_OS == DE_OS_WIN32)
37 # define RENDERDOC_LIBRARY_NAME "renderdoc.dll"
38 #elif (DE_OS == DE_OS_ANDROID)
39 # define RENDERDOC_LIBRARY_NAME "libVkLayer_GLES_RenderDoc.so"
40 #else
41 # define RENDERDOC_LIBRARY_NAME "librenderdoc.so"
42 #endif
43
44 namespace vk
45 {
46
47 struct RenderDocPrivate
48 {
49 #if defined(DEQP_HAVE_RENDERDOC_HEADER)
RenderDocPrivatevk::RenderDocPrivate50 RenderDocPrivate (void) : m_api(DE_NULL), m_valid(false) {}
51
52 de::MovePtr<de::DynamicLibrary> m_library;
53 ::RENDERDOC_API_1_1_2* m_api;
54 bool m_valid;
55 #endif
56 };
57
RenderDocUtil(void)58 RenderDocUtil::RenderDocUtil (void)
59 : m_priv (new RenderDocPrivate)
60 {
61 #if defined(DEQP_HAVE_RENDERDOC_HEADER)
62 try
63 {
64 m_priv->m_library = de::MovePtr<de::DynamicLibrary>(new de::DynamicLibrary(RENDERDOC_LIBRARY_NAME));
65 }
66 catch (const std::runtime_error& e)
67 {
68 tcu::print("Library %s not loaded: %s, RenderDoc API not available", e.what(), RENDERDOC_LIBRARY_NAME);
69 }
70
71 if (m_priv->m_library)
72 {
73 ::pRENDERDOC_GetAPI pGetApi = (::pRENDERDOC_GetAPI)m_priv->m_library->getFunction("RENDERDOC_GetAPI");
74 const int ret = pGetApi(eRENDERDOC_API_Version_1_1_2, (void **)&m_priv->m_api);
75
76 if (ret == 1)
77 {
78 m_priv->m_api->TriggerCapture();
79
80 m_priv->m_valid = true;
81 }
82 else
83 {
84 tcu::print("RENDERDOC_GetAPI returned %d status, RenderDoc API not available", ret);
85 }
86 }
87 #endif
88 }
89
~RenderDocUtil(void)90 RenderDocUtil::~RenderDocUtil (void)
91 {
92 if (m_priv)
93 {
94 delete m_priv;
95 }
96 }
97
isValid(void)98 bool RenderDocUtil::isValid (void)
99 {
100 #if defined(DEQP_HAVE_RENDERDOC_HEADER)
101 return m_priv != DE_NULL && m_priv->m_valid;
102 #else
103 return false;
104 #endif
105 }
106
startFrame(vk::VkInstance instance)107 void RenderDocUtil::startFrame (vk::VkInstance instance)
108 {
109 if (!isValid()) return;
110 #if defined(DEQP_HAVE_RENDERDOC_HEADER)
111 m_priv->m_api->StartFrameCapture(RENDERDOC_DEVICEPOINTER_FROM_VKINSTANCE(instance), DE_NULL);
112 #else
113 (void) instance;
114 #endif
115 }
116
endFrame(vk::VkInstance instance)117 void RenderDocUtil::endFrame (vk::VkInstance instance)
118 {
119 if (!isValid()) return;
120 #if defined(DEQP_HAVE_RENDERDOC_HEADER)
121 m_priv->m_api->EndFrameCapture(RENDERDOC_DEVICEPOINTER_FROM_VKINSTANCE(instance), DE_NULL);
122 #else
123 (void) instance;
124 #endif
125 }
126
127 } // vk
128