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