• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef _VKDEVICEPROPERTIES_HPP
2 #define _VKDEVICEPROPERTIES_HPP
3 /*-------------------------------------------------------------------------
4  * Vulkan CTS Framework
5  * --------------------
6  *
7  * Copyright (c) 2019 The Khronos Group 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 DeviceProperties class utility.
24  *//*--------------------------------------------------------------------*/
25 
26 #include <map>
27 #include <string>
28 #include <utility>
29 #include <vector>
30 
31 #include "deMemory.h"
32 #include "vkDefs.hpp"
33 
34 namespace vk
35 {
36 
37 // Structure describing vulkan property structure
38 struct PropertyDesc
39 {
40 	VkStructureType		sType;
41 	const char*			name;
42 	const deUint32		specVersion;
43 	const deUint32		typeId;
44 };
45 
46 // Structure containg all property blobs - this simplifies generated code
47 struct AllPropertiesBlobs
48 {
49 	VkPhysicalDeviceVulkan11Properties& vk11;
50 	VkPhysicalDeviceVulkan12Properties& vk12;
51 #ifndef CTS_USES_VULKANSC
52 	VkPhysicalDeviceVulkan13Properties& vk13;
53 #endif // CTS_USES_VULKANSC
54 	// add blobs from future vulkan versions here
55 };
56 
57 // Base class for all PropertyStructWrapper specialization
58 struct PropertyStructWrapperBase
59 {
~PropertyStructWrapperBasevk::PropertyStructWrapperBase60 	virtual					~PropertyStructWrapperBase	(void) {}
61 	virtual void			initializePropertyFromBlob	(const AllPropertiesBlobs& allPropertiesBlobs) = 0;
62 	virtual deUint32		getPropertyTypeId			(void) const = 0;
63 	virtual PropertyDesc	getPropertyDesc				(void) const = 0;
64 	virtual void**			getPropertyTypeNext			(void) = 0;
65 	virtual void*			getPropertyTypeRaw			(void) = 0;
66 };
67 
68 using PropertyStructWrapperCreator	= PropertyStructWrapperBase* (*) (void);
69 struct PropertyStructCreationData
70 {
71 	PropertyStructWrapperCreator creatorFunction;
72 	const char*					 name;
73 	deUint32					 specVersion;
74 };
75 
76 template<class PropertyType> class PropertyStructWrapper;
77 template<class PropertyType> PropertyDesc makePropertyDesc (void);
78 
79 template<class PropertyType>
createPropertyStructWrapper(void)80 PropertyStructWrapperBase* createPropertyStructWrapper (void)
81 {
82 	return new PropertyStructWrapper<PropertyType>(makePropertyDesc<PropertyType>());
83 }
84 
85 template<class PropertyType>
86 void initPropertyFromBlob(PropertyType& propertyType, const AllPropertiesBlobs& allPropertiesBlobs);
87 
88 template<class PropertyType>
initPropertyFromBlobWrapper(PropertyType & propertyType,const AllPropertiesBlobs & allPropertiesBlobs)89 void initPropertyFromBlobWrapper(PropertyType& propertyType, const AllPropertiesBlobs& allPropertiesBlobs)
90 {
91 	initPropertyFromBlob<PropertyType>(propertyType, allPropertiesBlobs);
92 }
93 
94 class DeviceProperties
95 {
96 public:
97 												DeviceProperties				(const InstanceInterface&			vki,
98 																				 const deUint32						apiVersion,
99 																				 const VkPhysicalDevice				physicalDevice,
100 																				 const std::vector<std::string>&	instanceExtensions,
101 																				 const std::vector<std::string>&	deviceExtensions);
102 
103 												~DeviceProperties				(void);
104 
105 	template<class PropertyType>
106 	const PropertyType&							getPropertyType				(void) const;
107 
getCoreProperties2(void) const108 	const VkPhysicalDeviceProperties2&			getCoreProperties2			(void) const { return m_coreProperties2; }
getVulkan11Properties(void) const109 	const VkPhysicalDeviceVulkan11Properties&	getVulkan11Properties		(void) const { return m_vulkan11Properties; }
getVulkan12Properties(void) const110 	const VkPhysicalDeviceVulkan12Properties&	getVulkan12Properties		(void) const { return m_vulkan12Properties; }
111 #ifndef CTS_USES_VULKANSC
getVulkan13Properties(void) const112 	const VkPhysicalDeviceVulkan13Properties&	getVulkan13Properties		(void) const { return m_vulkan13Properties; }
113 #endif // CTS_USES_VULKANSC
114 #ifdef CTS_USES_VULKANSC
getVulkanSC10Properties(void) const115 	const VkPhysicalDeviceVulkanSC10Properties&	getVulkanSC10Properties		(void) const { return m_vulkanSC10Properties; }
116 #endif // CTS_USES_VULKANSC
117 
118 	bool										contains					(const std::string& property, bool throwIfNotExists = false) const;
119 
120 	bool										isDevicePropertyInitialized	(VkStructureType sType) const;
121 
122 private:
123 
124 	static void									addToChainStructWrapper(void*** chainPNextPtr, PropertyStructWrapperBase* structWrapper);
125 
126 private:
127 
128 	VkPhysicalDeviceProperties2						m_coreProperties2;
129 	mutable std::vector<PropertyStructWrapperBase*>	m_properties;
130 	VkPhysicalDeviceVulkan11Properties				m_vulkan11Properties;
131 	VkPhysicalDeviceVulkan12Properties				m_vulkan12Properties;
132 #ifndef CTS_USES_VULKANSC
133 	VkPhysicalDeviceVulkan13Properties				m_vulkan13Properties;
134 #endif // CTS_USES_VULKANSC
135 #ifdef CTS_USES_VULKANSC
136 	VkPhysicalDeviceVulkanSC10Properties			m_vulkanSC10Properties;
137 #endif // CTS_USES_VULKANSC
138 };
139 
140 template<class PropertyType>
getPropertyType(void) const141 const PropertyType&	DeviceProperties::getPropertyType(void) const
142 {
143 	typedef PropertyStructWrapper<PropertyType>* PropertyWrapperPtr;
144 
145 	const PropertyDesc		propDesc	= makePropertyDesc<PropertyType>();
146 	const VkStructureType	sType		= propDesc.sType;
147 
148 	// try to find property by sType
149 	for (auto property : m_properties)
150 	{
151 		if (sType == property->getPropertyDesc().sType)
152 			return static_cast<PropertyWrapperPtr>(property)->getPropertyTypeRef();
153 	}
154 
155 	// try to find property by id that was assigned by gen_framework script
156 	const deUint32 propertyId = propDesc.typeId;
157 	for (auto property : m_properties)
158 	{
159 		if (propertyId == property->getPropertyTypeId())
160 			return static_cast<PropertyWrapperPtr>(property)->getPropertyTypeRef();
161 	}
162 
163 	// if initialized property structure was not found create empty one and return it
164 	m_properties.push_back(vk::createPropertyStructWrapper<PropertyType>());
165 	return static_cast<PropertyWrapperPtr>(m_properties.back())->getPropertyTypeRef();
166 }
167 
168 template<class PropertyType>
169 class PropertyStructWrapper : public PropertyStructWrapperBase
170 {
171 public:
PropertyStructWrapper(const PropertyDesc & propertyDesc)172 	PropertyStructWrapper (const PropertyDesc& propertyDesc)
173 		: m_propertyDesc(propertyDesc)
174 	{
175 		deMemset(&m_propertyType, 0, sizeof(m_propertyType));
176 		m_propertyType.sType = propertyDesc.sType;
177 	}
178 
initializePropertyFromBlob(const AllPropertiesBlobs & allPropertiesBlobs)179 	void initializePropertyFromBlob (const AllPropertiesBlobs& allPropertiesBlobs)
180 	{
181 		initPropertyFromBlobWrapper(m_propertyType, allPropertiesBlobs);
182 	}
183 
getPropertyTypeId(void) const184 	deUint32		getPropertyTypeId	(void) const	{ return m_propertyDesc.typeId;	}
getPropertyDesc(void) const185 	PropertyDesc	getPropertyDesc		(void) const	{ return m_propertyDesc;			}
getPropertyTypeNext(void)186 	void**			getPropertyTypeNext	(void)			{ return &m_propertyType.pNext;	}
getPropertyTypeRaw(void)187 	void*			getPropertyTypeRaw	(void)			{ return &m_propertyType;		}
getPropertyTypeRef(void)188 	PropertyType&	getPropertyTypeRef	(void)			{ return m_propertyType;			}
189 
190 public:
191 	// metadata about property structure
192 	const PropertyDesc	m_propertyDesc;
193 
194 	// actual vulkan property structure
195 	PropertyType			m_propertyType;
196 };
197 } // vk
198 
199 #endif // _VKDEVICEPROPERTIES_HPP
200