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