1 #ifndef _VKPLATFORM_HPP
2 #define _VKPLATFORM_HPP
3 /*-------------------------------------------------------------------------
4 * Vulkan CTS Framework
5 * --------------------
6 *
7 * Copyright (c) 2015 Google Inc.
8 *
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 *
13 * http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 *
21 *//*!
22 * \file
23 * \brief Vulkan platform abstraction.
24 *//*--------------------------------------------------------------------*/
25
26 #include "vkDefs.hpp"
27
28 #include <ostream>
29
30 namespace tcu
31 {
32 class FunctionLibrary;
33 }
34
35 namespace vk
36 {
37
38 class Library
39 {
40 public:
Library(void)41 Library (void) {}
~Library(void)42 virtual ~Library (void) {}
43
44 virtual const PlatformInterface& getPlatformInterface (void) const = 0;
45 virtual const tcu::FunctionLibrary& getFunctionLibrary (void) const = 0;
46 };
47
48 class PlatformDriver : public PlatformInterface
49 {
50 public:
51 PlatformDriver (const tcu::FunctionLibrary& library);
52 ~PlatformDriver (void);
53
54 #include "vkConcretePlatformInterface.inl"
55
getGetInstanceProcAddr() const56 virtual GetInstanceProcAddrFunc getGetInstanceProcAddr () const {
57 return m_vk.getInstanceProcAddr;
58 }
59
60 protected:
61 struct Functions
62 {
63 #include "vkPlatformFunctionPointers.inl"
64 };
65
66 Functions m_vk;
67 };
68
69 class InstanceDriver : public InstanceInterface
70 {
71 public:
72 InstanceDriver (const PlatformInterface& platformInterface, VkInstance instance);
73 ~InstanceDriver (void);
74
75 #include "vkConcreteInstanceInterface.inl"
76
77 protected:
78 void loadFunctions (const PlatformInterface& platformInterface, VkInstance instance);
79
80 struct Functions
81 {
82 #include "vkInstanceFunctionPointers.inl"
83 };
84
85 Functions m_vk;
86 };
87
88 class DeviceDriver : public DeviceInterface
89 {
90 public:
91 DeviceDriver (const PlatformInterface& platformInterface, VkInstance instance, VkDevice device);
92 ~DeviceDriver (void);
93
94 #include "vkConcreteDeviceInterface.inl"
95
96 protected:
97 struct Functions
98 {
99 #include "vkDeviceFunctionPointers.inl"
100 };
101
102 Functions m_vk;
103 };
104
105 // Defined in vkWsiPlatform.hpp
106 namespace wsi
107 {
108 class Display;
109 } // wsi
110
111 struct PlatformMemoryLimits
112 {
113 // System memory properties
114 size_t totalSystemMemory; //!< #bytes of system memory (heap + HOST_LOCAL) tests must not exceed
115
116 // Device memory properties
117 VkDeviceSize totalDeviceLocalMemory; //!< #bytes of total DEVICE_LOCAL memory tests must not exceed or 0 if DEVICE_LOCAL counts against system memory
118 VkDeviceSize deviceMemoryAllocationGranularity; //!< VkDeviceMemory allocation granularity (typically page size)
119
120 // Device memory page table geometry
121 // \todo [2016-03-23 pyry] This becomes obsolete if Vulkan API adds a way for driver to expose internal device memory allocations
122 VkDeviceSize devicePageSize; //!< Page size on device (must be rounded up to nearest POT)
123 VkDeviceSize devicePageTableEntrySize; //!< Number of bytes per page table size
124 size_t devicePageTableHierarchyLevels; //!< Number of levels in device page table hierarchy
125
PlatformMemoryLimitsvk::PlatformMemoryLimits126 PlatformMemoryLimits (void)
127 : totalSystemMemory (0)
128 , totalDeviceLocalMemory (0)
129 , deviceMemoryAllocationGranularity (0)
130 , devicePageSize (0)
131 , devicePageTableEntrySize (0)
132 , devicePageTableHierarchyLevels (0)
133 {}
134 };
135
136 /*--------------------------------------------------------------------*//*!
137 * \brief Vulkan platform interface
138 *//*--------------------------------------------------------------------*/
139 class Platform
140 {
141 public:
Platform(void)142 Platform (void) {}
~Platform(void)143 ~Platform (void) {}
144
145 virtual Library* createLibrary (void) const = 0;
146
147 virtual wsi::Display* createWsiDisplay (wsi::Type wsiType) const;
148 virtual bool hasDisplay (wsi::Type wsiType) const;
149
150 virtual void getMemoryLimits (PlatformMemoryLimits& limits) const = 0;
151 virtual void describePlatform (std::ostream& dst) const;
152 };
153
getMemoryLimits(const Platform & platform)154 inline PlatformMemoryLimits getMemoryLimits (const Platform& platform)
155 {
156 PlatformMemoryLimits limits;
157 platform.getMemoryLimits(limits);
158 return limits;
159 }
160
161 } // vk
162
163 #endif // _VKPLATFORM_HPP
164