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 }
53
54 de::MovePtr<de::DynamicLibrary> m_library;
55 ::RENDERDOC_API_1_1_2 *m_api;
56 bool m_valid;
57 #endif
58 };
59
RenderDocUtil(void)60 RenderDocUtil::RenderDocUtil(void) : m_priv(new RenderDocPrivate)
61 {
62 #if defined(DEQP_HAVE_RENDERDOC_HEADER)
63 try
64 {
65 m_priv->m_library = de::MovePtr<de::DynamicLibrary>(new de::DynamicLibrary(RENDERDOC_LIBRARY_NAME));
66 }
67 catch (const std::runtime_error &e)
68 {
69 tcu::print("Library %s not loaded: %s, RenderDoc API not available", e.what(), RENDERDOC_LIBRARY_NAME);
70 }
71
72 if (m_priv->m_library)
73 {
74 ::pRENDERDOC_GetAPI pGetApi = (::pRENDERDOC_GetAPI)m_priv->m_library->getFunction("RENDERDOC_GetAPI");
75 const int ret = pGetApi(eRENDERDOC_API_Version_1_1_2, (void **)&m_priv->m_api);
76
77 if (ret == 1)
78 {
79 m_priv->m_api->TriggerCapture();
80
81 m_priv->m_valid = true;
82 }
83 else
84 {
85 tcu::print("RENDERDOC_GetAPI returned %d status, RenderDoc API not available", ret);
86 }
87 }
88 #endif
89 }
90
~RenderDocUtil(void)91 RenderDocUtil::~RenderDocUtil(void)
92 {
93 if (m_priv)
94 {
95 delete m_priv;
96 }
97 }
98
isValid(void)99 bool RenderDocUtil::isValid(void)
100 {
101 #if defined(DEQP_HAVE_RENDERDOC_HEADER)
102 return m_priv != DE_NULL && m_priv->m_valid;
103 #else
104 return false;
105 #endif
106 }
107
startFrame(vk::VkInstance instance)108 void RenderDocUtil::startFrame(vk::VkInstance instance)
109 {
110 if (!isValid())
111 return;
112 #if defined(DEQP_HAVE_RENDERDOC_HEADER)
113 m_priv->m_api->StartFrameCapture(RENDERDOC_DEVICEPOINTER_FROM_VKINSTANCE(instance), DE_NULL);
114 #else
115 (void)instance;
116 #endif
117 }
118
endFrame(vk::VkInstance instance)119 void RenderDocUtil::endFrame(vk::VkInstance instance)
120 {
121 if (!isValid())
122 return;
123 #if defined(DEQP_HAVE_RENDERDOC_HEADER)
124 m_priv->m_api->EndFrameCapture(RENDERDOC_DEVICEPOINTER_FROM_VKINSTANCE(instance), DE_NULL);
125 #else
126 (void)instance;
127 #endif
128 }
129
130 } // namespace vk
131