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)
47 : vk::wsi::MacOSWindowInterface(view->getView())
48 , m_view(view)
49 {
50 }
51
resize(const UVec2 & newSize)52 void resize (const UVec2& newSize) {
53 m_view->setSize(newSize.x(), newSize.y());
54 }
55
56 private:
57 UniquePtr<osx::MetalView> m_view;
58 };
59
60 class VulkanDisplay : public vk::wsi::Display
61 {
62 public:
VulkanDisplay()63 VulkanDisplay ()
64 {
65 }
66
createWindow(const Maybe<UVec2> & initialSize) const67 vk::wsi::Window* createWindow (const Maybe<UVec2>& initialSize) const
68 {
69 const deUint32 width = !initialSize ? 400 : initialSize->x();
70 const deUint32 height = !initialSize ? 300 : initialSize->y();
71 return new VulkanWindow(MovePtr<osx::MetalView>(new osx::MetalView(width, height)));
72 }
73 };
74
75 class VulkanLibrary : public vk::Library
76 {
77 public:
VulkanLibrary(void)78 VulkanLibrary (void)
79 : m_library ("libvulkan.dylib")
80 , m_driver (m_library)
81 {
82 }
83
getPlatformInterface(void) const84 const vk::PlatformInterface& getPlatformInterface (void) const
85 {
86 return m_driver;
87 }
88
getFunctionLibrary(void) const89 const tcu::FunctionLibrary& getFunctionLibrary (void) const
90 {
91 return m_library;
92 }
93
94 private:
95 const DynamicFunctionLibrary m_library;
96 const vk::PlatformDriver m_driver;
97 };
98
VulkanPlatform()99 VulkanPlatform::VulkanPlatform ()
100 {
101 }
102
createWsiDisplay(vk::wsi::Type wsiType) const103 vk::wsi::Display* VulkanPlatform::createWsiDisplay (vk::wsi::Type wsiType) const
104 {
105 if (wsiType != vk::wsi::TYPE_MACOS)
106 TCU_THROW(NotSupportedError, "WSI type not supported");
107
108 return new VulkanDisplay();
109 }
110
hasDisplay(vk::wsi::Type wsiType) const111 bool VulkanPlatform::hasDisplay (vk::wsi::Type wsiType) const
112 {
113 if (wsiType != vk::wsi::TYPE_MACOS)
114 return false;
115
116 return true;
117 }
createLibrary(void) const118 vk::Library* VulkanPlatform::createLibrary (void) const
119 {
120 return new VulkanLibrary();
121 }
122
describePlatform(std::ostream & dst) const123 void VulkanPlatform::describePlatform (std::ostream& dst) const
124 {
125 utsname sysInfo;
126 deMemset(&sysInfo, 0, sizeof(sysInfo));
127
128 if (uname(&sysInfo) != 0)
129 throw std::runtime_error("uname() failed");
130
131 dst << "OS: " << sysInfo.sysname << " " << sysInfo.release << " " << sysInfo.version << "\n";
132 dst << "CPU: " << sysInfo.machine << "\n";
133 }
134
getMemoryLimits(vk::PlatformMemoryLimits & limits) const135 void VulkanPlatform::getMemoryLimits (vk::PlatformMemoryLimits& limits) const
136 {
137 limits.totalSystemMemory = 256*1024*1024;
138 limits.totalDeviceLocalMemory = 128*1024*1024;
139 limits.deviceMemoryAllocationGranularity = 64*1024;
140 limits.devicePageSize = 4096;
141 limits.devicePageTableEntrySize = 8;
142 limits.devicePageTableHierarchyLevels = 3;
143 }
144
145 } // osx
146 } // tcu
147
148