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")
41 archive.Serialize(glsl);
42 else if (active == "hlsl")
43 archive.Serialize(hlsl);
44 else if (active == "spirv")
45 archive.Serialize(spirv);
46 else
47 throw std::runtime_error("incorrect shader type");
48 }
49 };
50
51 struct VulkanJsonPipelineDescription
52 {
VulkanJsonPipelineDescriptionvksc_server::VulkanJsonPipelineDescription53 VulkanJsonPipelineDescription() : currentCount(0u), maxCount(0u), allCount(0u)
54 {
55 }
VulkanJsonPipelineDescriptionvksc_server::VulkanJsonPipelineDescription56 VulkanJsonPipelineDescription(const vk::VkPipelineOfflineCreateInfo &id_, const string &pipelineContents_,
57 const string &deviceFeatures_, const vector<string> &deviceExtensions_,
58 const std::string &test)
59 : id(id_)
60 , pipelineContents(pipelineContents_)
61 , deviceFeatures(deviceFeatures_)
62 , deviceExtensions(deviceExtensions_)
63 , currentCount(1u)
64 , maxCount(1u)
65 , allCount(1u)
66 {
67 tests.insert(test);
68 }
69
addvksc_server::VulkanJsonPipelineDescription70 void add(const std::string &test)
71 {
72 tests.insert(test);
73 allCount++;
74 currentCount++;
75 maxCount = de::max(maxCount, currentCount);
76 }
77
removevksc_server::VulkanJsonPipelineDescription78 void remove()
79 {
80 currentCount--;
81 }
82
83 vk::VkPipelineOfflineCreateInfo id;
84 string pipelineContents;
85 string deviceFeatures;
86 vector<string> deviceExtensions;
87 uint32_t currentCount;
88 uint32_t maxCount;
89 uint32_t allCount;
90 std::set<string> tests;
91 };
92
SerializeItem(Serializer<ToRead> & serializer,VulkanJsonPipelineDescription & v)93 inline void SerializeItem(Serializer<ToRead> &serializer, VulkanJsonPipelineDescription &v)
94 {
95 serializer.Serialize(v.id, v.pipelineContents, v.deviceFeatures, v.deviceExtensions, v.currentCount, v.maxCount,
96 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,
102 v.allCount, v.tests);
103 }
104
105 struct VulkanPipelineSize
106 {
107 vk::VkPipelineOfflineCreateInfo id;
108 uint32_t count;
109 uint32_t size;
110 };
111
SerializeItem(Serializer<ToRead> & serializer,VulkanPipelineSize & v)112 inline void SerializeItem(Serializer<ToRead> &serializer, VulkanPipelineSize &v)
113 {
114 serializer.Serialize(v.id, v.count, v.size);
115 }
116
SerializeItem(Serializer<ToWrite> & serializer,VulkanPipelineSize & v)117 inline void SerializeItem(Serializer<ToWrite> &serializer, VulkanPipelineSize &v)
118 {
119 serializer.Serialize(v.id, v.count, v.size);
120 }
121
122 struct PipelineIdentifierEqual
123 {
PipelineIdentifierEqualvksc_server::PipelineIdentifierEqual124 PipelineIdentifierEqual(const vk::VkPipelineOfflineCreateInfo &p) : searched(p)
125 {
126 }
operator ()vksc_server::PipelineIdentifierEqual127 bool operator()(const vksc_server::VulkanJsonPipelineDescription &item) const
128 {
129 for (uint32_t 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 (uint32_t 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,
159 descriptorSetLayouts, pipelines);
160 }
161 };
162
SerializeItem(Serializer<ToRead> & serializer,VulkanPipelineCacheInput & v)163 inline void SerializeItem(Serializer<ToRead> &serializer, VulkanPipelineCacheInput &v)
164 {
165 serializer.Serialize(v.samplerYcbcrConversions, v.samplers, v.shaderModules, v.renderPasses, v.pipelineLayouts,
166 v.descriptorSetLayouts, v.pipelines);
167 }
168
SerializeItem(Serializer<ToWrite> & serializer,VulkanPipelineCacheInput & v)169 inline void SerializeItem(Serializer<ToWrite> &serializer, VulkanPipelineCacheInput &v)
170 {
171 serializer.Serialize(v.samplerYcbcrConversions, v.samplers, v.shaderModules, v.renderPasses, v.pipelineLayouts,
172 v.descriptorSetLayouts, v.pipelines);
173 }
174
175 struct VulkanCommandMemoryConsumption
176 {
VulkanCommandMemoryConsumptionvksc_server::VulkanCommandMemoryConsumption177 VulkanCommandMemoryConsumption()
178 : commandPool(0u)
179 , commandBufferCount(0u)
180 , currentCommandPoolAllocated(0u)
181 , maxCommandPoolAllocated(0u)
182 , currentCommandPoolReservedSize(0u)
183 , maxCommandPoolReservedSize(0u)
184 , currentCommandBufferAllocated(0u)
185 , maxCommandBufferAllocated(0u)
186 {
187 }
188
VulkanCommandMemoryConsumptionvksc_server::VulkanCommandMemoryConsumption189 VulkanCommandMemoryConsumption(uint64_t commandPool_)
190 : commandPool(commandPool_)
191 , commandBufferCount(0u)
192 , currentCommandPoolAllocated(0u)
193 , maxCommandPoolAllocated(0u)
194 , currentCommandPoolReservedSize(0u)
195 , maxCommandPoolReservedSize(0u)
196 , currentCommandBufferAllocated(0u)
197 , maxCommandBufferAllocated(0u)
198 {
199 }
updateValuesvksc_server::VulkanCommandMemoryConsumption200 void updateValues(vk::VkDeviceSize cpAlloc, vk::VkDeviceSize cpReserved, vk::VkDeviceSize cbAlloc)
201 {
202 currentCommandPoolAllocated += cpAlloc;
203 maxCommandPoolAllocated = de::max(currentCommandPoolAllocated, maxCommandPoolAllocated);
204 currentCommandPoolReservedSize += cpReserved;
205 maxCommandPoolReservedSize = de::max(currentCommandPoolReservedSize, maxCommandPoolReservedSize);
206 currentCommandBufferAllocated += cbAlloc;
207 maxCommandBufferAllocated = de::max(currentCommandBufferAllocated, maxCommandBufferAllocated);
208 }
resetValuesvksc_server::VulkanCommandMemoryConsumption209 void resetValues()
210 {
211 currentCommandPoolAllocated = 0u;
212 currentCommandPoolReservedSize = 0u;
213 currentCommandBufferAllocated = 0u;
214 }
215
216 uint64_t commandPool;
217 uint32_t commandBufferCount;
218 vk::VkDeviceSize currentCommandPoolAllocated;
219 vk::VkDeviceSize maxCommandPoolAllocated;
220 vk::VkDeviceSize currentCommandPoolReservedSize;
221 vk::VkDeviceSize maxCommandPoolReservedSize;
222 vk::VkDeviceSize currentCommandBufferAllocated;
223 vk::VkDeviceSize maxCommandBufferAllocated;
224 };
225
SerializeItem(Serializer<ToRead> & serializer,VulkanCommandMemoryConsumption & v)226 inline void SerializeItem(Serializer<ToRead> &serializer, VulkanCommandMemoryConsumption &v)
227 {
228 serializer.Serialize(v.commandPool, v.commandBufferCount, v.currentCommandPoolAllocated, v.maxCommandPoolAllocated,
229 v.currentCommandPoolReservedSize, v.maxCommandPoolReservedSize,
230 v.currentCommandBufferAllocated, v.maxCommandBufferAllocated);
231 }
232
SerializeItem(Serializer<ToWrite> & serializer,VulkanCommandMemoryConsumption & v)233 inline void SerializeItem(Serializer<ToWrite> &serializer, VulkanCommandMemoryConsumption &v)
234 {
235 serializer.Serialize(v.commandPool, v.commandBufferCount, v.currentCommandPoolAllocated, v.maxCommandPoolAllocated,
236 v.currentCommandPoolReservedSize, v.maxCommandPoolReservedSize,
237 v.currentCommandBufferAllocated, v.maxCommandBufferAllocated);
238 }
239
240 struct VulkanDataTransmittedFromMainToSubprocess
241 {
VulkanDataTransmittedFromMainToSubprocessvksc_server::VulkanDataTransmittedFromMainToSubprocess242 VulkanDataTransmittedFromMainToSubprocess()
243 {
244 }
VulkanDataTransmittedFromMainToSubprocessvksc_server::VulkanDataTransmittedFromMainToSubprocess245 VulkanDataTransmittedFromMainToSubprocess(
246 const VulkanPipelineCacheInput &pipelineCacheInput_,
247 const vk::VkDeviceObjectReservationCreateInfo &memoryReservation_,
248 const std::vector<VulkanCommandMemoryConsumption> &commandPoolMemoryConsumption_,
249 const std::vector<VulkanPipelineSize> &pipelineSizes_)
250 : pipelineCacheInput(pipelineCacheInput_)
251 , memoryReservation(memoryReservation_)
252 , commandPoolMemoryConsumption(commandPoolMemoryConsumption_)
253 , pipelineSizes(pipelineSizes_)
254 {
255 }
256
257 VulkanPipelineCacheInput pipelineCacheInput;
258 vk::VkDeviceObjectReservationCreateInfo memoryReservation;
259 std::vector<VulkanCommandMemoryConsumption> commandPoolMemoryConsumption;
260 std::vector<VulkanPipelineSize> pipelineSizes;
261
262 template <typename TYPE>
Serializevksc_server::VulkanDataTransmittedFromMainToSubprocess263 void Serialize(Serializer<TYPE> &archive)
264 {
265 archive.Serialize(pipelineCacheInput, memoryReservation, commandPoolMemoryConsumption, pipelineSizes);
266 }
267 };
268
269 struct CmdLineParams
270 {
271 std::string compilerPath;
272 std::string compilerDataDir;
273 std::string compilerPipelineCacheFile;
274 std::string compilerLogFile;
275 std::string compilerArgs;
276 };
277
278 } // namespace vksc_server
279
280 #endif // _VKSSTRUCTSVKSC_HPP
281