• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef _VKSSTRUCTSVKSC_HPP
2 #define _VKSSTRUCTSVKSC_HPP
3 
4 /*-------------------------------------------------------------------------
5  * Vulkan CTS Framework
6  * --------------------
7  *
8  * Copyright (c) 2021 The Khronos Group Inc.
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  *      http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  *-------------------------------------------------------------------------*/
23 
24 #include "vksSerializerVKSC.hpp"
25 
26 namespace vksc_server
27 {
28 
29 struct SourceVariant
30 {
31 	string												active;
32 	vk::GlslSource										glsl;
33 	vk::HlslSource										hlsl;
34 	vk::SpirVAsmSource									spirv;
35 
36 	template <typename TYPE>
Serializevksc_server::SourceVariant37 	void Serialize (Serializer<TYPE>& archive)
38 	{
39 		archive.Serialize(active);
40 		if (active == "glsl") archive.Serialize(glsl);
41 		else if (active == "hlsl") archive.Serialize(hlsl);
42 		else if (active == "spirv") archive.Serialize(spirv);
43 		else throw std::runtime_error("incorrect shader type");
44 	}
45 };
46 
47 struct VulkanJsonPipelineDescription
48 {
VulkanJsonPipelineDescriptionvksc_server::VulkanJsonPipelineDescription49 	VulkanJsonPipelineDescription	()
50 		: currentCount	(0u)
51 		, maxCount		(0u)
52 		, allCount		(0u)
53 	{
54 	}
VulkanJsonPipelineDescriptionvksc_server::VulkanJsonPipelineDescription55 	VulkanJsonPipelineDescription	(const vk::VkPipelineOfflineCreateInfo&	id_,
56 									 const string&							pipelineContents_,
57 									 const string&							deviceFeatures_,
58 									 const vector<string>&					deviceExtensions_,
59 									 const std::string&						test)
60 		: id				(id_)
61 		, pipelineContents	(pipelineContents_)
62 		, deviceFeatures	(deviceFeatures_)
63 		, deviceExtensions	(deviceExtensions_)
64 		, currentCount	(1u)
65 		, maxCount		(1u)
66 		, allCount		(1u)
67 	{
68 		tests.insert(test);
69 	}
70 
addvksc_server::VulkanJsonPipelineDescription71 	void add	(const std::string& test)
72 	{
73 		tests.insert(test);
74 		allCount++;
75 		currentCount++;
76 		maxCount = de::max(maxCount, currentCount);
77 	}
78 
removevksc_server::VulkanJsonPipelineDescription79 	void remove	()
80 	{
81 		currentCount--;
82 	}
83 
84 	vk::VkPipelineOfflineCreateInfo						id;
85 	string												pipelineContents;
86 	string												deviceFeatures;
87 	vector<string>										deviceExtensions;
88 	deUint32											currentCount;
89 	deUint32											maxCount;
90 	deUint32											allCount;
91 	std::set<string>									tests;
92 };
93 
SerializeItem(Serializer<ToRead> & serializer,VulkanJsonPipelineDescription & v)94 inline void SerializeItem(Serializer<ToRead>& serializer, VulkanJsonPipelineDescription& v)
95 {
96 	serializer.Serialize(v.id, v.pipelineContents, v.deviceFeatures, v.deviceExtensions, v.currentCount, v.maxCount, v.allCount, v.tests);
97 }
98 
SerializeItem(Serializer<ToWrite> & serializer,VulkanJsonPipelineDescription & v)99 inline void SerializeItem(Serializer<ToWrite>& serializer, VulkanJsonPipelineDescription& v)
100 {
101 	serializer.Serialize(v.id, v.pipelineContents, v.deviceFeatures, v.deviceExtensions, v.currentCount, v.maxCount, v.allCount, v.tests);
102 }
103 
104 struct VulkanPipelineSize
105 {
106 	vk::VkPipelineOfflineCreateInfo						id;
107 	deUint32											count;
108 	deUint32											size;
109 };
110 
SerializeItem(Serializer<ToRead> & serializer,VulkanPipelineSize & v)111 inline void SerializeItem(Serializer<ToRead>& serializer, VulkanPipelineSize& v)
112 {
113 	serializer.Serialize(v.id, v.count, v.size);
114 }
115 
SerializeItem(Serializer<ToWrite> & serializer,VulkanPipelineSize & v)116 inline void SerializeItem(Serializer<ToWrite>& serializer, VulkanPipelineSize& v)
117 {
118 	serializer.Serialize(v.id, v.count, v.size);
119 }
120 
121 struct PipelineIdentifierEqual
122 {
PipelineIdentifierEqualvksc_server::PipelineIdentifierEqual123 	PipelineIdentifierEqual(const vk::VkPipelineOfflineCreateInfo& p)
124 		: searched(p)
125 	{
126 	}
operator ()vksc_server::PipelineIdentifierEqual127 	bool operator() (const vksc_server::VulkanJsonPipelineDescription& item) const
128 	{
129 		for (deUint32 i = 0; i < VK_UUID_SIZE; ++i)
130 			if (searched.pipelineIdentifier[i] != item.id.pipelineIdentifier[i])
131 				return false;
132 		return true;
133 	}
operator ()vksc_server::PipelineIdentifierEqual134 	bool operator() (const vksc_server::VulkanPipelineSize& item) const
135 	{
136 		for (deUint32 i = 0; i < VK_UUID_SIZE; ++i)
137 			if (searched.pipelineIdentifier[i] != item.id.pipelineIdentifier[i])
138 				return false;
139 		return true;
140 	}
141 
142 	const vk::VkPipelineOfflineCreateInfo& searched;
143 };
144 
145 struct VulkanPipelineCacheInput
146 {
147 	std::map<vk::VkSamplerYcbcrConversion, string>		samplerYcbcrConversions;
148 	std::map<vk::VkSampler, string>						samplers;
149 	std::map<vk::VkShaderModule, string>				shaderModules;
150 	std::map<vk::VkRenderPass, string>					renderPasses;
151 	std::map<vk::VkPipelineLayout, string>				pipelineLayouts;
152 	std::map<vk::VkDescriptorSetLayout, string>			descriptorSetLayouts;
153 	std::vector<VulkanJsonPipelineDescription>			pipelines;
154 
155 	template <typename TYPE>
Serializevksc_server::VulkanPipelineCacheInput156 	void Serialize (Serializer<TYPE>& archive)
157 	{
158 		archive.Serialize(samplerYcbcrConversions, samplers, shaderModules, renderPasses, pipelineLayouts, descriptorSetLayouts, pipelines);
159 	}
160 };
161 
SerializeItem(Serializer<ToRead> & serializer,VulkanPipelineCacheInput & v)162 inline void SerializeItem(Serializer<ToRead>& serializer, VulkanPipelineCacheInput& v)
163 {
164 	serializer.Serialize(v.samplerYcbcrConversions, v.samplers, v.shaderModules, v.renderPasses, v.pipelineLayouts, v.descriptorSetLayouts, v.pipelines);
165 }
166 
SerializeItem(Serializer<ToWrite> & serializer,VulkanPipelineCacheInput & v)167 inline void SerializeItem(Serializer<ToWrite>& serializer, VulkanPipelineCacheInput& v)
168 {
169 	serializer.Serialize(v.samplerYcbcrConversions, v.samplers, v.shaderModules, v.renderPasses, v.pipelineLayouts, v.descriptorSetLayouts, v.pipelines);
170 }
171 
172 struct VulkanCommandMemoryConsumption
173 {
VulkanCommandMemoryConsumptionvksc_server::VulkanCommandMemoryConsumption174 	VulkanCommandMemoryConsumption()
175 		: commandPool						(0u)
176 		, commandBufferCount				(0u)
177 		, currentCommandPoolAllocated		(0u)
178 		, maxCommandPoolAllocated			(0u)
179 		, currentCommandPoolReservedSize	(0u)
180 		, maxCommandPoolReservedSize		(0u)
181 		, currentCommandBufferAllocated		(0u)
182 		, maxCommandBufferAllocated			(0u)
183 	{
184 	}
185 
VulkanCommandMemoryConsumptionvksc_server::VulkanCommandMemoryConsumption186 	VulkanCommandMemoryConsumption (deUint64 commandPool_)
187 		: commandPool						(commandPool_)
188 		, commandBufferCount				(0u)
189 		, currentCommandPoolAllocated		(0u)
190 		, maxCommandPoolAllocated			(0u)
191 		, currentCommandPoolReservedSize	(0u)
192 		, maxCommandPoolReservedSize		(0u)
193 		, currentCommandBufferAllocated		(0u)
194 		, maxCommandBufferAllocated			(0u)
195 	{
196 	}
updateValuesvksc_server::VulkanCommandMemoryConsumption197 	void updateValues(vk::VkDeviceSize cpAlloc, vk::VkDeviceSize cpReserved, vk::VkDeviceSize cbAlloc)
198 	{
199 		currentCommandPoolAllocated		+= cpAlloc;		maxCommandPoolAllocated		= de::max(currentCommandPoolAllocated, maxCommandPoolAllocated);
200 		currentCommandPoolReservedSize	+= cpReserved;	maxCommandPoolReservedSize	= de::max(currentCommandPoolReservedSize, maxCommandPoolReservedSize);
201 		currentCommandBufferAllocated	+= cbAlloc;		maxCommandBufferAllocated	= de::max(currentCommandBufferAllocated, maxCommandBufferAllocated);
202 	}
resetValuesvksc_server::VulkanCommandMemoryConsumption203 	void resetValues()
204 	{
205 		currentCommandPoolAllocated		= 0u;
206 		currentCommandPoolReservedSize	= 0u;
207 		currentCommandBufferAllocated	= 0u;
208 	}
209 
210 	deUint64			commandPool;
211 	deUint32			commandBufferCount;
212 	vk::VkDeviceSize	currentCommandPoolAllocated;
213 	vk::VkDeviceSize	maxCommandPoolAllocated;
214 	vk::VkDeviceSize	currentCommandPoolReservedSize;
215 	vk::VkDeviceSize	maxCommandPoolReservedSize;
216 	vk::VkDeviceSize	currentCommandBufferAllocated;
217 	vk::VkDeviceSize	maxCommandBufferAllocated;
218 };
219 
SerializeItem(Serializer<ToRead> & serializer,VulkanCommandMemoryConsumption & v)220 inline void SerializeItem(Serializer<ToRead>& serializer, VulkanCommandMemoryConsumption& v)
221 {
222 	serializer.Serialize(v.commandPool, v.commandBufferCount, v.currentCommandPoolAllocated, v.maxCommandPoolAllocated, v.currentCommandPoolReservedSize, v.maxCommandPoolReservedSize, v.currentCommandBufferAllocated, v.maxCommandBufferAllocated);
223 }
224 
SerializeItem(Serializer<ToWrite> & serializer,VulkanCommandMemoryConsumption & v)225 inline void SerializeItem(Serializer<ToWrite>& serializer, VulkanCommandMemoryConsumption& v)
226 {
227 	serializer.Serialize(v.commandPool, v.commandBufferCount, v.currentCommandPoolAllocated, v.maxCommandPoolAllocated, v.currentCommandPoolReservedSize, v.maxCommandPoolReservedSize, v.currentCommandBufferAllocated, v.maxCommandBufferAllocated);
228 }
229 
230 struct VulkanDataTransmittedFromMainToSubprocess
231 {
VulkanDataTransmittedFromMainToSubprocessvksc_server::VulkanDataTransmittedFromMainToSubprocess232 	VulkanDataTransmittedFromMainToSubprocess ()
233 	{
234 	}
VulkanDataTransmittedFromMainToSubprocessvksc_server::VulkanDataTransmittedFromMainToSubprocess235 	VulkanDataTransmittedFromMainToSubprocess (const VulkanPipelineCacheInput&						pipelineCacheInput_,
236 											   const vk::VkDeviceObjectReservationCreateInfo&		memoryReservation_,
237 											   const std::vector<VulkanCommandMemoryConsumption>&	commandPoolMemoryConsumption_,
238 											   const std::vector<VulkanPipelineSize>&				pipelineSizes_)
239 		: pipelineCacheInput			(pipelineCacheInput_)
240 		, memoryReservation				(memoryReservation_)
241 		, commandPoolMemoryConsumption	(commandPoolMemoryConsumption_)
242 		, pipelineSizes					(pipelineSizes_)
243 	{
244 	}
245 
246 	VulkanPipelineCacheInput					pipelineCacheInput;
247 	vk::VkDeviceObjectReservationCreateInfo		memoryReservation;
248 	std::vector<VulkanCommandMemoryConsumption>	commandPoolMemoryConsumption;
249 	std::vector<VulkanPipelineSize>				pipelineSizes;
250 
251 	template <typename TYPE>
Serializevksc_server::VulkanDataTransmittedFromMainToSubprocess252 	void Serialize(Serializer<TYPE>& archive)
253 	{
254 		archive.Serialize(pipelineCacheInput, memoryReservation, commandPoolMemoryConsumption, pipelineSizes);
255 	}
256 };
257 
258 struct CmdLineParams
259 {
260 	std::string											compilerPath;
261 	std::string											compilerDataDir;
262 	std::string											compilerPipelineCacheFile;
263 	std::string											compilerLogFile;
264 	std::string											compilerArgs;
265 };
266 
267 }
268 
269 #endif // _VKSSTRUCTSVKSC_HPP
270