xref: /aosp_15_r20/external/deqp/framework/platform/osx/tcuOSXVulkanPlatform.cpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1 /*-------------------------------------------------------------------------
2  * drawElements Quality Program Tester Core
3  * ----------------------------------------
4  *
5  * Copyright (c) 2018 The Khronos Group Inc.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  *//*!
20  * \file
21  * \brief OSX Vulkan Platform.
22  *//*--------------------------------------------------------------------*/
23 
24 #include "tcuOSXVulkanPlatform.hpp"
25 #include "tcuOSXPlatform.hpp"
26 #include "tcuOSXMetalView.hpp"
27 #include "vkWsiPlatform.hpp"
28 #include "gluPlatform.hpp"
29 #include "tcuFunctionLibrary.hpp"
30 #include "deUniquePtr.hpp"
31 #include "deMemory.h"
32 
33 #include <sys/utsname.h>
34 
35 using de::MovePtr;
36 using de::UniquePtr;
37 
38 namespace tcu
39 {
40 namespace osx
41 {
42 
43 class VulkanWindow : public vk::wsi::MacOSWindowInterface
44 {
45 public:
VulkanWindow(MovePtr<osx::MetalView> view)46     VulkanWindow(MovePtr<osx::MetalView> view) : vk::wsi::MacOSWindowInterface(view->getView()), m_view(view)
47     {
48     }
49 
setVisible(bool)50     void setVisible(bool)
51     {
52     }
53 
resize(const UVec2 & newSize)54     void resize(const UVec2 &newSize)
55     {
56         m_view->setSize(newSize.x(), newSize.y());
57     }
58 
setMinimized(bool minimized)59     void setMinimized(bool minimized)
60     {
61         DE_UNREF(minimized);
62         TCU_THROW(NotSupportedError, "Minimized on osx is not implemented");
63     }
64 
65 private:
66     UniquePtr<osx::MetalView> m_view;
67 };
68 
69 class VulkanDisplay : public vk::wsi::Display
70 {
71 public:
VulkanDisplay()72     VulkanDisplay()
73     {
74     }
75 
createWindow(const Maybe<UVec2> & initialSize) const76     vk::wsi::Window *createWindow(const Maybe<UVec2> &initialSize) const
77     {
78         const uint32_t width  = !initialSize ? 400 : initialSize->x();
79         const uint32_t height = !initialSize ? 300 : initialSize->y();
80         return new VulkanWindow(MovePtr<osx::MetalView>(new osx::MetalView(width, height)));
81     }
82 };
83 
84 class VulkanLibrary : public vk::Library
85 {
86 public:
VulkanLibrary(const char * libraryPath)87     VulkanLibrary(const char *libraryPath)
88         : m_library(libraryPath != DE_NULL ? libraryPath : "libvulkan.dylib")
89         , m_driver(m_library)
90     {
91     }
92 
getPlatformInterface(void) const93     const vk::PlatformInterface &getPlatformInterface(void) const
94     {
95         return m_driver;
96     }
97 
getFunctionLibrary(void) const98     const tcu::FunctionLibrary &getFunctionLibrary(void) const
99     {
100         return m_library;
101     }
102 
103 private:
104     const DynamicFunctionLibrary m_library;
105     const vk::PlatformDriver m_driver;
106 };
107 
108 struct VulkanWindowHeadless : public vk::wsi::Window
109 {
110 public:
setVisibletcu::osx::VulkanWindowHeadless111     void setVisible(bool /* visible */)
112     {
113     }
114 
resizetcu::osx::VulkanWindowHeadless115     void resize(const UVec2 &)
116     {
117     }
118 };
119 
120 class VulkanDisplayHeadless : public vk::wsi::Display
121 {
122 public:
VulkanDisplayHeadless()123     VulkanDisplayHeadless()
124     {
125     }
126 
createWindow(const Maybe<UVec2> &) const127     vk::wsi::Window *createWindow(const Maybe<UVec2> &) const
128     {
129         return new VulkanWindowHeadless();
130     }
131 };
132 
VulkanPlatform()133 VulkanPlatform::VulkanPlatform()
134 {
135 }
136 
createWsiDisplay(vk::wsi::Type wsiType) const137 vk::wsi::Display *VulkanPlatform::createWsiDisplay(vk::wsi::Type wsiType) const
138 {
139     switch (wsiType)
140     {
141     case vk::wsi::TYPE_MACOS:
142         return new VulkanDisplay();
143     case vk::wsi::TYPE_HEADLESS:
144         return new VulkanDisplayHeadless();
145     default:
146         TCU_THROW(NotSupportedError, "WSI type not supported");
147     }
148 }
149 
hasDisplay(vk::wsi::Type wsiType) const150 bool VulkanPlatform::hasDisplay(vk::wsi::Type wsiType) const
151 {
152     switch (wsiType)
153     {
154     case vk::wsi::TYPE_MACOS:
155     case vk::wsi::TYPE_HEADLESS:
156         return true;
157     default:
158         return false;
159     }
160 }
createLibrary(const char * libraryPath) const161 vk::Library *VulkanPlatform::createLibrary(const char *libraryPath) const
162 {
163     return new VulkanLibrary(libraryPath);
164 }
165 
describePlatform(std::ostream & dst) const166 void VulkanPlatform::describePlatform(std::ostream &dst) const
167 {
168     utsname sysInfo;
169     deMemset(&sysInfo, 0, sizeof(sysInfo));
170 
171     if (uname(&sysInfo) != 0)
172         throw std::runtime_error("uname() failed");
173 
174     dst << "OS: " << sysInfo.sysname << " " << sysInfo.release << " " << sysInfo.version << "\n";
175     dst << "CPU: " << sysInfo.machine << "\n";
176 }
177 
178 } // namespace osx
179 } // namespace tcu
180