1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program Tester Core
3 * ----------------------------------------
4 *
5 * Copyright 2016 The Android Open Source Project
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 Win32 Vulkan platform
22 *//*--------------------------------------------------------------------*/
23
24 // \todo [2016-01-22 pyry] GetVersionEx() used by getOSInfo() is deprecated.
25 // Find a way to get version info without using deprecated APIs.
26 #pragma warning(disable : 4996)
27
28 #include "tcuWin32VulkanPlatform.hpp"
29 #include "tcuWin32Window.hpp"
30
31 #include "tcuFormatUtil.hpp"
32 #include "tcuFunctionLibrary.hpp"
33 #include "tcuVector.hpp"
34
35 #include "vkWsiPlatform.hpp"
36
37 #include "deUniquePtr.hpp"
38 #include "deMemory.h"
39
40 namespace tcu
41 {
42 namespace win32
43 {
44
45 using de::MovePtr;
46 using de::UniquePtr;
47
48 DE_STATIC_ASSERT(sizeof(vk::pt::Win32InstanceHandle) == sizeof(HINSTANCE));
49 DE_STATIC_ASSERT(sizeof(vk::pt::Win32WindowHandle) == sizeof(HWND));
50
51 class VulkanWindow : public vk::wsi::Win32WindowInterface
52 {
53 public:
VulkanWindow(MovePtr<win32::Window> window)54 VulkanWindow (MovePtr<win32::Window> window)
55 : vk::wsi::Win32WindowInterface (vk::pt::Win32WindowHandle(window->getHandle()))
56 , m_window (window)
57 {
58 }
59
resize(const UVec2 & newSize)60 void resize (const UVec2& newSize)
61 {
62 m_window->setSize((int)newSize.x(), (int)newSize.y());
63 }
64
65 private:
66 UniquePtr<win32::Window> m_window;
67 };
68
69 class VulkanDisplay : public vk::wsi::Win32DisplayInterface
70 {
71 public:
VulkanDisplay(HINSTANCE instance)72 VulkanDisplay (HINSTANCE instance)
73 : vk::wsi::Win32DisplayInterface (vk::pt::Win32InstanceHandle(instance))
74 {
75 }
76
createWindow(const Maybe<UVec2> & initialSize) const77 vk::wsi::Window* createWindow (const Maybe<UVec2>& initialSize) const
78 {
79 const HINSTANCE instance = (HINSTANCE)m_native.internal;
80 const deUint32 width = !initialSize ? 400 : initialSize->x();
81 const deUint32 height = !initialSize ? 300 : initialSize->y();
82
83 return new VulkanWindow(MovePtr<win32::Window>(new win32::Window(instance, (int)width, (int)height)));
84 }
85 };
86
87 class VulkanLibrary : public vk::Library
88 {
89 public:
VulkanLibrary(void)90 VulkanLibrary (void)
91 : m_library ("vulkan-1.dll")
92 , m_driver (m_library)
93 {
94 }
95
getPlatformInterface(void) const96 const vk::PlatformInterface& getPlatformInterface (void) const
97 {
98 return m_driver;
99 }
getFunctionLibrary(void) const100 const tcu::FunctionLibrary& getFunctionLibrary (void) const
101 {
102 return m_library;
103 }
104
105 private:
106 const tcu::DynamicFunctionLibrary m_library;
107 const vk::PlatformDriver m_driver;
108 };
109
VulkanPlatform(HINSTANCE instance)110 VulkanPlatform::VulkanPlatform (HINSTANCE instance)
111 : m_instance(instance)
112 {
113 }
114
~VulkanPlatform(void)115 VulkanPlatform::~VulkanPlatform (void)
116 {
117 }
118
createLibrary(void) const119 vk::Library* VulkanPlatform::createLibrary (void) const
120 {
121 return new VulkanLibrary();
122 }
123
getProductTypeName(WORD productType)124 const char* getProductTypeName (WORD productType)
125 {
126 switch (productType)
127 {
128 case VER_NT_DOMAIN_CONTROLLER: return "Windows Server (domain controller)";
129 case VER_NT_SERVER: return "Windows Server";
130 case VER_NT_WORKSTATION: return "Windows NT";
131 default: return DE_NULL;
132 }
133 }
134
getOSInfo(std::ostream & dst)135 static void getOSInfo (std::ostream& dst)
136 {
137 OSVERSIONINFOEX osInfo;
138
139 deMemset(&osInfo, 0, sizeof(osInfo));
140 osInfo.dwOSVersionInfoSize = (DWORD)sizeof(osInfo);
141
142 GetVersionEx((OSVERSIONINFO*)&osInfo);
143
144 {
145 const char* const productName = getProductTypeName(osInfo.wProductType);
146
147 if (productName)
148 dst << productName;
149 else
150 dst << "unknown product " << tcu::toHex(osInfo.wProductType);
151 }
152
153 dst << " " << osInfo.dwMajorVersion << "." << osInfo.dwMinorVersion
154 << ", service pack " << osInfo.wServicePackMajor << "." << osInfo.wServicePackMinor
155 << ", build " << osInfo.dwBuildNumber;
156 }
157
getProcessorArchitectureName(WORD arch)158 const char* getProcessorArchitectureName (WORD arch)
159 {
160 switch (arch)
161 {
162 case PROCESSOR_ARCHITECTURE_AMD64: return "AMD64";
163 case PROCESSOR_ARCHITECTURE_ARM: return "ARM";
164 case PROCESSOR_ARCHITECTURE_IA64: return "IA64";
165 case PROCESSOR_ARCHITECTURE_INTEL: return "INTEL";
166 case PROCESSOR_ARCHITECTURE_UNKNOWN: return "UNKNOWN";
167 default: return DE_NULL;
168 }
169 }
170
getProcessorInfo(std::ostream & dst)171 static void getProcessorInfo (std::ostream& dst)
172 {
173 SYSTEM_INFO sysInfo;
174
175 deMemset(&sysInfo, 0, sizeof(sysInfo));
176 GetSystemInfo(&sysInfo);
177
178 dst << "arch ";
179 {
180 const char* const archName = getProcessorArchitectureName(sysInfo.wProcessorArchitecture);
181
182 if (archName)
183 dst << archName;
184 else
185 dst << tcu::toHex(sysInfo.wProcessorArchitecture);
186 }
187
188 dst << ", level " << tcu::toHex(sysInfo.wProcessorLevel) << ", revision " << tcu::toHex(sysInfo.wProcessorRevision);
189 }
190
describePlatform(std::ostream & dst) const191 void VulkanPlatform::describePlatform (std::ostream& dst) const
192 {
193 dst << "OS: ";
194 getOSInfo(dst);
195 dst << "\n";
196
197 dst << "CPU: ";
198 getProcessorInfo(dst);
199 dst << "\n";
200 }
201
getMemoryLimits(vk::PlatformMemoryLimits & limits) const202 void VulkanPlatform::getMemoryLimits (vk::PlatformMemoryLimits& limits) const
203 {
204 limits.totalSystemMemory = 256*1024*1024;
205 limits.totalDeviceLocalMemory = 128*1024*1024;
206 limits.deviceMemoryAllocationGranularity = 64*1024;
207 limits.devicePageSize = 4096;
208 limits.devicePageTableEntrySize = 8;
209 limits.devicePageTableHierarchyLevels = 3;
210 }
211
createWsiDisplay(vk::wsi::Type wsiType) const212 vk::wsi::Display* VulkanPlatform::createWsiDisplay (vk::wsi::Type wsiType) const
213 {
214 if (wsiType != vk::wsi::TYPE_WIN32)
215 TCU_THROW(NotSupportedError, "WSI type not supported");
216
217 return new VulkanDisplay(m_instance);
218 }
219
220 } // win32
221 } // tcu
222