• 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 	VkPhysicalDeviceVulkan13Properties& vk13;
52 	// add blobs from future vulkan versions here
53 };
54 
55 // Base class for all PropertyStructWrapper specialization
56 struct PropertyStructWrapperBase
57 {
~PropertyStructWrapperBasevk::PropertyStructWrapperBase58 	virtual					~PropertyStructWrapperBase	(void) {}
59 	virtual void			initializePropertyFromBlob	(const AllPropertiesBlobs& allPropertiesBlobs) = 0;
60 	virtual deUint32		getPropertyTypeId			(void) const = 0;
61 	virtual PropertyDesc	getPropertyDesc				(void) const = 0;
62 	virtual void**			getPropertyTypeNext			(void) = 0;
63 	virtual void*			getPropertyTypeRaw			(void) = 0;
64 };
65 
66 using PropertyStructWrapperCreator	= PropertyStructWrapperBase* (*) (void);
67 struct PropertyStructCreationData
68 {
69 	PropertyStructWrapperCreator creatorFunction;
70 	const char*					 name;
71 	deUint32					 specVersion;
72 };
73 
74 template<class PropertyType> class PropertyStructWrapper;
75 template<class PropertyType> PropertyDesc makePropertyDesc (void);
76 
77 template<class PropertyType>
createPropertyStructWrapper(void)78 PropertyStructWrapperBase* createPropertyStructWrapper (void)
79 {
80 	return new PropertyStructWrapper<PropertyType>(makePropertyDesc<PropertyType>());
81 }
82 
83 template<class PropertyType>
84 void initPropertyFromBlob(PropertyType& propertyType, const AllPropertiesBlobs& allPropertiesBlobs);
85 
86 template<class PropertyType>
initPropertyFromBlobWrapper(PropertyType & propertyType,const AllPropertiesBlobs & allPropertiesBlobs)87 void initPropertyFromBlobWrapper(PropertyType& propertyType, const AllPropertiesBlobs& allPropertiesBlobs)
88 {
89 	initPropertyFromBlob<PropertyType>(propertyType, allPropertiesBlobs);
90 }
91 
92 class DeviceProperties
93 {
94 public:
95 												DeviceProperties				(const InstanceInterface&			vki,
96 																				 const deUint32						apiVersion,
97 																				 const VkPhysicalDevice				physicalDevice,
98 																				 const std::vector<std::string>&	instanceExtensions,
99 																				 const std::vector<std::string>&	deviceExtensions);
100 
101 												~DeviceProperties				(void);
102 
103 	template<class PropertyType>
104 	const PropertyType&							getPropertyType				(void) const;
105 
getCoreProperties2(void) const106 	const VkPhysicalDeviceProperties2&			getCoreProperties2			(void) const { return m_coreProperties2; }
getVulkan11Properties(void) const107 	const VkPhysicalDeviceVulkan11Properties&	getVulkan11Properties		(void) const { return m_vulkan11Properties; }
getVulkan12Properties(void) const108 	const VkPhysicalDeviceVulkan12Properties&	getVulkan12Properties		(void) const { return m_vulkan12Properties; }
getVulkan13Properties(void) const109 	const VkPhysicalDeviceVulkan13Properties&	getVulkan13Properties		(void) const { return m_vulkan13Properties; }
110 
111 	bool										contains					(const std::string& property, bool throwIfNotExists = false) const;
112 
113 	bool										isDevicePropertyInitialized	(VkStructureType sType) const;
114 
115 private:
116 
117 	static void									addToChainStructWrapper(void*** chainPNextPtr, PropertyStructWrapperBase* structWrapper);
118 
119 private:
120 
121 	VkPhysicalDeviceProperties2						m_coreProperties2;
122 	mutable std::vector<PropertyStructWrapperBase*>	m_properties;
123 	VkPhysicalDeviceVulkan11Properties				m_vulkan11Properties;
124 	VkPhysicalDeviceVulkan12Properties				m_vulkan12Properties;
125 	VkPhysicalDeviceVulkan13Properties				m_vulkan13Properties;
126 };
127 
128 template<class PropertyType>
getPropertyType(void) const129 const PropertyType&	DeviceProperties::getPropertyType(void) const
130 {
131 	typedef PropertyStructWrapper<PropertyType>* PropertyWrapperPtr;
132 
133 	const PropertyDesc		propDesc	= makePropertyDesc<PropertyType>();
134 	const VkStructureType	sType		= propDesc.sType;
135 
136 	// try to find property by sType
137 	for (auto property : m_properties)
138 	{
139 		if (sType == property->getPropertyDesc().sType)
140 			return static_cast<PropertyWrapperPtr>(property)->getPropertyTypeRef();
141 	}
142 
143 	// try to find property by id that was assigned by gen_framework script
144 	const deUint32 propertyId = propDesc.typeId;
145 	for (auto property : m_properties)
146 	{
147 		if (propertyId == property->getPropertyTypeId())
148 			return static_cast<PropertyWrapperPtr>(property)->getPropertyTypeRef();
149 	}
150 
151 	// if initialized property structure was not found create empty one and return it
152 	m_properties.push_back(vk::createPropertyStructWrapper<PropertyType>());
153 	return static_cast<PropertyWrapperPtr>(m_properties.back())->getPropertyTypeRef();
154 }
155 
156 template<class PropertyType>
157 class PropertyStructWrapper : public PropertyStructWrapperBase
158 {
159 public:
PropertyStructWrapper(const PropertyDesc & propertyDesc)160 	PropertyStructWrapper (const PropertyDesc& propertyDesc)
161 		: m_propertyDesc(propertyDesc)
162 	{
163 		deMemset(&m_propertyType, 0, sizeof(m_propertyType));
164 		m_propertyType.sType = propertyDesc.sType;
165 	}
166 
initializePropertyFromBlob(const AllPropertiesBlobs & allPropertiesBlobs)167 	void initializePropertyFromBlob (const AllPropertiesBlobs& allPropertiesBlobs)
168 	{
169 		initPropertyFromBlobWrapper(m_propertyType, allPropertiesBlobs);
170 	}
171 
getPropertyTypeId(void) const172 	deUint32		getPropertyTypeId	(void) const	{ return m_propertyDesc.typeId;	}
getPropertyDesc(void) const173 	PropertyDesc	getPropertyDesc		(void) const	{ return m_propertyDesc;			}
getPropertyTypeNext(void)174 	void**			getPropertyTypeNext	(void)			{ return &m_propertyType.pNext;	}
getPropertyTypeRaw(void)175 	void*			getPropertyTypeRaw	(void)			{ return &m_propertyType;		}
getPropertyTypeRef(void)176 	PropertyType&	getPropertyTypeRef	(void)			{ return m_propertyType;			}
177 
178 public:
179 	// metadata about property structure
180 	const PropertyDesc	m_propertyDesc;
181 
182 	// actual vulkan property structure
183 	PropertyType			m_propertyType;
184 };
185 } // vk
186 
187 #endif // _VKDEVICEPROPERTIES_HPP
188