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
56 protected:
57 struct Functions
58 {
59 #include "vkPlatformFunctionPointers.inl"
60 };
61
62 Functions m_vk;
63 };
64
65 class InstanceDriver : public InstanceInterface
66 {
67 public:
68 InstanceDriver (const PlatformInterface& platformInterface, VkInstance instance);
69 ~InstanceDriver (void);
70
71 #include "vkConcreteInstanceInterface.inl"
72
73 protected:
74 void loadFunctions (const PlatformInterface& platformInterface, VkInstance instance);
75
76 struct Functions
77 {
78 #include "vkInstanceFunctionPointers.inl"
79 };
80
81 Functions m_vk;
82 };
83
84 class DeviceDriver : public DeviceInterface
85 {
86 public:
87 DeviceDriver (const PlatformInterface& platformInterface, VkInstance instance, VkDevice device);
88 ~DeviceDriver (void);
89
90 #include "vkConcreteDeviceInterface.inl"
91
92 protected:
93 struct Functions
94 {
95 #include "vkDeviceFunctionPointers.inl"
96 };
97
98 Functions m_vk;
99 };
100
101 // Defined in vkWsiPlatform.hpp
102 namespace wsi
103 {
104 class Display;
105 } // wsi
106
107 struct PlatformMemoryLimits
108 {
109 // System memory properties
110 size_t totalSystemMemory; //!< #bytes of system memory (heap + HOST_LOCAL) tests must not exceed
111
112 // Device memory properties
113 VkDeviceSize totalDeviceLocalMemory; //!< #bytes of total DEVICE_LOCAL memory tests must not exceed or 0 if DEVICE_LOCAL counts against system memory
114 VkDeviceSize deviceMemoryAllocationGranularity; //!< VkDeviceMemory allocation granularity (typically page size)
115
116 // Device memory page table geometry
117 // \todo [2016-03-23 pyry] This becomes obsolete if Vulkan API adds a way for driver to expose internal device memory allocations
118 VkDeviceSize devicePageSize; //!< Page size on device (must be rounded up to nearest POT)
119 VkDeviceSize devicePageTableEntrySize; //!< Number of bytes per page table size
120 size_t devicePageTableHierarchyLevels; //!< Number of levels in device page table hierarchy
121
PlatformMemoryLimitsvk::PlatformMemoryLimits122 PlatformMemoryLimits (void)
123 : totalSystemMemory (0)
124 , totalDeviceLocalMemory (0)
125 , deviceMemoryAllocationGranularity (0)
126 , devicePageSize (0)
127 , devicePageTableEntrySize (0)
128 , devicePageTableHierarchyLevels (0)
129 {}
130 };
131
132 /*--------------------------------------------------------------------*//*!
133 * \brief Vulkan platform interface
134 *//*--------------------------------------------------------------------*/
135 class Platform
136 {
137 public:
Platform(void)138 Platform (void) {}
~Platform(void)139 ~Platform (void) {}
140
141 virtual Library* createLibrary (void) const = 0;
142
143 virtual wsi::Display* createWsiDisplay (wsi::Type wsiType) const;
144 virtual bool hasDisplay (wsi::Type wsiType) const;
145
146 virtual void getMemoryLimits (PlatformMemoryLimits& limits) const = 0;
147 virtual void describePlatform (std::ostream& dst) const;
148 };
149
getMemoryLimits(const Platform & platform)150 inline PlatformMemoryLimits getMemoryLimits (const Platform& platform)
151 {
152 PlatformMemoryLimits limits;
153 platform.getMemoryLimits(limits);
154 return limits;
155 }
156
157 } // vk
158
159 #endif // _VKPLATFORM_HPP
160