• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*-------------------------------------------------------------------------
2  * Vulkan CTS Framework
3  * --------------------
4  *
5  * Copyright (c) 2021 The Khronos Group Inc.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  *-------------------------------------------------------------------------*/
20 
21 #include "vksJson.hpp"
22 
23 #define VULKAN_JSON_CTS
24 #ifdef __GNUC__
25 	#pragma GCC diagnostic push
26 	#pragma GCC diagnostic ignored "-Wunused-parameter"
27 	#pragma GCC diagnostic ignored "-Wunused-function"
28 	#pragma GCC diagnostic ignored "-Wunused-variable"
29 #endif // __GNUC__
30 #ifdef __clang__
31 	#pragma clang diagnostic push
32 	#pragma clang diagnostic ignored "-Wpointer-bool-conversion"
33 #endif
34 
35 #include "vulkan_json_parser.hpp"
36 #include "vulkan_json_data.hpp"
37 
38 #include "tlsWrapper.hpp"
39 
40 TLS_INSTANCE();
41 namespace vk_json_parser {
42 GlobalMem<deUint32, deUint8> &
TLSGetGlobalMem()43 TLSGetGlobalMem() {
44 	return TLSWrapper<GlobalMem<deUint32, deUint8>>::instance.attach();
45 }
46 }
47 namespace vk_json {
48 std::stringstream &
TLSGetStrStream()49 TLSGetStrStream() {
50 	return TLSWrapper<std::stringstream>::instance.attach();
51 }
52 }
53 
54 #ifdef __GNUC__
55 	#pragma GCC diagnostic pop
56 #endif // __GNUC__
57 #ifdef __clang__
58 	#pragma clang diagnostic pop
59 #endif
60 
61 #include "vksStructsVKSC.hpp"
62 
63 namespace vksc_server
64 {
65 
66 namespace json
67 {
68 
Context()69 Context::Context()
70 {
71 	Json::CharReaderBuilder builder;
72 	builder.settings_["allowSpecialFloats"] = 1;
73 	reader.reset( builder.newCharReader() );
74 }
75 
~Context()76 Context::~Context()
77 {
78 }
79 
runGarbageCollection()80 void runGarbageCollection()
81 {
82 	vk_json_parser::s_globalMem.clear();
83 }
84 
VkObjectToString(const vk::VkDeviceObjectReservationCreateInfo & in,string & out)85 void VkObjectToString(const vk::VkDeviceObjectReservationCreateInfo& in, string& out)
86 {
87 	vk_json::_string_stream.str({});
88 	vk_json::_string_stream.clear();
89 	vk_json::print_VkDeviceObjectReservationCreateInfo(&in, "", false);
90 	out = vk_json::_string_stream.str();
91 }
92 
StringToVkObject(const string & in,vk::VkDeviceObjectReservationCreateInfo & out)93 void StringToVkObject(const string& in, vk::VkDeviceObjectReservationCreateInfo& out)
94 {
95 	Json::CharReaderBuilder				builder;
96 	builder.settings_["allowSpecialFloats"] = 1;
97 	std::unique_ptr<Json::CharReader>	jsonReader(builder.newCharReader());
98 
99 	Json::Value jsonRoot;
100 	string errors;
101 	if (!jsonReader->parse(in.data(), in.data() + in.size(), &jsonRoot, &errors))
102 	{
103 		throw std::runtime_error("json parse error");
104 	}
105 	vk_json_parser::parse_VkDeviceObjectReservationCreateInfo("", jsonRoot, out);
106 }
107 
writeJSON_VkGraphicsPipelineCreateInfo(const VkGraphicsPipelineCreateInfo & pCreateInfo)108 string writeJSON_VkGraphicsPipelineCreateInfo(const VkGraphicsPipelineCreateInfo&	pCreateInfo)
109 {
110 	vk_json::_string_stream.str({});
111 	vk_json::_string_stream.clear();
112 	vk_json::print_VkGraphicsPipelineCreateInfo(pCreateInfo, "", 0);
113 	return vk_json::_string_stream.str();
114 }
115 
writeJSON_VkComputePipelineCreateInfo(const VkComputePipelineCreateInfo & pCreateInfo)116 string writeJSON_VkComputePipelineCreateInfo(const VkComputePipelineCreateInfo&	pCreateInfo)
117 {
118 	vk_json::_string_stream.str({});
119 	vk_json::_string_stream.clear();
120 	vk_json::print_VkComputePipelineCreateInfo(pCreateInfo, "", 0);
121 	return vk_json::_string_stream.str();
122 }
123 
writeJSON_VkRenderPassCreateInfo(const VkRenderPassCreateInfo & pCreateInfo)124 string writeJSON_VkRenderPassCreateInfo (const VkRenderPassCreateInfo& pCreateInfo)
125 {
126 
127 	vk_json::_string_stream.str({});
128 	vk_json::_string_stream.clear();
129 	vk_json::print_VkRenderPassCreateInfo(&pCreateInfo, "", false);
130 	return vk_json::_string_stream.str();
131 }
132 
writeJSON_VkRenderPassCreateInfo2(const VkRenderPassCreateInfo2 & pCreateInfo)133 string writeJSON_VkRenderPassCreateInfo2 (const VkRenderPassCreateInfo2& pCreateInfo)
134 {
135 	vk_json::_string_stream.str({});
136 	vk_json::_string_stream.clear();
137 	vk_json::print_VkRenderPassCreateInfo2(&pCreateInfo, "", false);
138 	return vk_json::_string_stream.str();
139 }
140 
writeJSON_VkPipelineLayoutCreateInfo(const VkPipelineLayoutCreateInfo & pCreateInfo)141 string writeJSON_VkPipelineLayoutCreateInfo (const VkPipelineLayoutCreateInfo& pCreateInfo)
142 {
143 	vk_json::_string_stream.str({});
144 	vk_json::_string_stream.clear();
145 	vk_json::print_VkPipelineLayoutCreateInfo(&pCreateInfo, "", false);
146 	return vk_json::_string_stream.str();
147 }
148 
writeJSON_VkDescriptorSetLayoutCreateInfo(const VkDescriptorSetLayoutCreateInfo & pCreateInfo)149 string writeJSON_VkDescriptorSetLayoutCreateInfo (const VkDescriptorSetLayoutCreateInfo& pCreateInfo)
150 {
151 	vk_json::_string_stream.str({});
152 	vk_json::_string_stream.clear();
153 	vk_json::print_VkDescriptorSetLayoutCreateInfo(&pCreateInfo, "", false);
154 	return vk_json::_string_stream.str();
155 }
156 
writeJSON_VkSamplerCreateInfo(const VkSamplerCreateInfo & pCreateInfo)157 string writeJSON_VkSamplerCreateInfo(const VkSamplerCreateInfo& pCreateInfo)
158 {
159 	vk_json::_string_stream.str({});
160 	vk_json::_string_stream.clear();
161 	vk_json::print_VkSamplerCreateInfo(&pCreateInfo, "", false);
162 	return vk_json::_string_stream.str();
163 }
164 
writeJSON_VkDeviceObjectReservationCreateInfo(const VkDeviceObjectReservationCreateInfo & dmrCI)165 string writeJSON_VkDeviceObjectReservationCreateInfo (const VkDeviceObjectReservationCreateInfo& dmrCI)
166 {
167 	vk_json::_string_stream.str({});
168 	vk_json::_string_stream.clear();
169 	vk_json::print_VkDeviceObjectReservationCreateInfo(&dmrCI, "", false);
170 	return vk_json::_string_stream.str();
171 }
172 
writeJSON_VkPipelineOfflineCreateInfo(const vk::VkPipelineOfflineCreateInfo & piInfo)173 string	writeJSON_VkPipelineOfflineCreateInfo(const vk::VkPipelineOfflineCreateInfo& piInfo)
174 {
175 	vk_json::_string_stream.str({});
176 	vk_json::_string_stream.clear();
177 	vk_json::print_VkPipelineOfflineCreateInfo(&piInfo, "", false);
178 	return vk_json::_string_stream.str();
179 }
180 
writeJSON_GraphicsPipeline_vkpccjson(const std::string & filePrefix,deUint32 pipelineIndex,const vk::VkPipelineOfflineCreateInfo id,const VkGraphicsPipelineCreateInfo & gpCI,const vk::VkPhysicalDeviceFeatures2 & deviceFeatures2,const std::vector<std::string> & deviceExtensions,const std::map<VkSamplerYcbcrConversion,VkSamplerYcbcrConversionCreateInfo> & samplerYcbcrConversions,const std::map<VkSampler,VkSamplerCreateInfo> & samplers,const std::map<VkDescriptorSetLayout,VkDescriptorSetLayoutCreateInfo> & descriptorSetLayouts,const std::map<VkRenderPass,VkRenderPassCreateInfo> & renderPasses,const std::map<VkRenderPass,VkRenderPassCreateInfo2> & renderPasses2,const std::map<VkPipelineLayout,VkPipelineLayoutCreateInfo> & pipelineLayouts)181 string	writeJSON_GraphicsPipeline_vkpccjson (const std::string&															filePrefix,
182 											  deUint32																		pipelineIndex,
183 											  const vk::VkPipelineOfflineCreateInfo											id,
184 											  const VkGraphicsPipelineCreateInfo&											gpCI,
185 											  const vk::VkPhysicalDeviceFeatures2&											deviceFeatures2,
186 											  const std::vector<std::string>&												deviceExtensions,
187 											  const std::map<VkSamplerYcbcrConversion, VkSamplerYcbcrConversionCreateInfo>&	samplerYcbcrConversions,
188 											  const std::map<VkSampler, VkSamplerCreateInfo>&								samplers,
189 											  const std::map<VkDescriptorSetLayout, VkDescriptorSetLayoutCreateInfo>&		descriptorSetLayouts,
190 											  const std::map<VkRenderPass, VkRenderPassCreateInfo>&							renderPasses,
191 											  const std::map<VkRenderPass, VkRenderPassCreateInfo2>&						renderPasses2,
192 											  const std::map<VkPipelineLayout, VkPipelineLayoutCreateInfo>&					pipelineLayouts)
193 {
194 	vk_json::_string_stream.str({});
195 	vk_json::_string_stream.clear();
196 
197 	for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
198 	vk_json::_string_stream << "{" << std::endl;
199 	vk_json::s_num_spaces += 4;
200 
201 	for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
202 	vk_json::_string_stream << "\"GraphicsPipelineState\" :" << std::endl;
203 	for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
204 	vk_json::_string_stream << "{" << std::endl;
205 	vk_json::s_num_spaces += 4;
206 
207 	if (!renderPasses.empty())
208 	{
209 		for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
210 		vk_json::_string_stream << "\"Renderpass\" : " << std::endl;
211 		vk_json::print_VkRenderPassCreateInfo(begin(renderPasses)->second, "", true);
212 	}
213 	if (!renderPasses2.empty())
214 	{
215 		for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
216 		vk_json::_string_stream << "\"Renderpass2\" : " << std::endl;
217 		vk_json::print_VkRenderPassCreateInfo2(begin(renderPasses2)->second, "", true);
218 	}
219 	if (!samplerYcbcrConversions.empty())
220 	{
221 		for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
222 		vk_json::_string_stream << "\"YcbcrSamplers\" :" << std::endl;
223 		for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
224 		vk_json::_string_stream << "[" << std::endl;
225 		vk_json::s_num_spaces += 4;
226 
227 		size_t j = 0u;
228 		for (auto it = begin(samplerYcbcrConversions); it != end(samplerYcbcrConversions); ++it, ++j)
229 		{
230 			for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
231 			vk_json::_string_stream << "{" << std::endl;
232 			vk_json::s_num_spaces += 4;
233 
234 			for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
235 			vk_json::_string_stream << "\""<< it->first.getInternal() << "\":" << std::endl;
236 
237 			vk_json::print_VkSamplerYcbcrConversionCreateInfo(it->second, "", false);
238 
239 			vk_json::s_num_spaces -= 4;
240 			for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
241 			if((j + 1) < samplerYcbcrConversions.size())
242 				vk_json::_string_stream << "}," << std::endl;
243 			else
244 				vk_json::_string_stream << "}" << std::endl;
245 		}
246 
247 		vk_json::s_num_spaces -= 4;
248 		for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
249 		vk_json::_string_stream << "]," << std::endl;
250 	}
251 
252 	if (!samplers.empty())
253 	{
254 		for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
255 		vk_json::_string_stream << "\"ImmutableSamplers\" :" << std::endl;
256 		for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
257 		vk_json::_string_stream << "[" << std::endl;
258 		vk_json::s_num_spaces += 4;
259 
260 		size_t j = 0u;
261 		for (auto it = begin(samplers); it != end(samplers); ++it, ++j)
262 		{
263 			for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
264 			vk_json::_string_stream << "{" << std::endl;
265 			vk_json::s_num_spaces += 4;
266 
267 			for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
268 			vk_json::_string_stream << "\"" << it->first.getInternal() << "\":" << std::endl;
269 
270 			vk_json::print_VkSamplerCreateInfo(it->second, "", false);
271 
272 			vk_json::s_num_spaces -= 4;
273 			for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
274 
275 			if ((j + 1) < samplers.size())
276 				vk_json::_string_stream << "}," << std::endl;
277 			else
278 				vk_json::_string_stream << "}" << std::endl;
279 		}
280 
281 		vk_json::s_num_spaces -= 4;
282 		for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
283 		vk_json::_string_stream << "]," << std::endl;
284 	}
285 
286 	if (!descriptorSetLayouts.empty())
287 	{
288 		for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
289 		vk_json::_string_stream << "\"DescriptorSetLayouts\" :" << std::endl;
290 		for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
291 		vk_json::_string_stream << "[" << std::endl;
292 		vk_json::s_num_spaces += 4;
293 
294 		size_t j = 0u;
295 		for (auto it = begin(descriptorSetLayouts); it != end(descriptorSetLayouts); ++it, ++j)
296 		{
297 			for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
298 			vk_json::_string_stream << "{" << std::endl;
299 			vk_json::s_num_spaces += 4;
300 
301 			for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
302 			vk_json::_string_stream << "\"" << it->first.getInternal() << "\":" << std::endl;
303 
304 			vk_json::print_VkDescriptorSetLayoutCreateInfo(it->second, "", false);
305 
306 			vk_json::s_num_spaces -= 4;
307 			for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
308 
309 			if ((j + 1) < descriptorSetLayouts.size())
310 				vk_json::_string_stream << "}," << std::endl;
311 			else
312 				vk_json::_string_stream << "}" << std::endl;
313 		}
314 
315 		vk_json::s_num_spaces -= 4;
316 		for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
317 		vk_json::_string_stream << "]," << std::endl;
318 	}
319 
320 	for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
321 	vk_json::_string_stream << "\"PipelineLayout\" : " << std::endl;
322 	vk_json::print_VkPipelineLayoutCreateInfo(begin(pipelineLayouts)->second, "", true);
323 
324 	for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
325 	vk_json::_string_stream << "\"GraphicsPipeline\" : " << std::endl;
326 	vk_json::print_VkGraphicsPipelineCreateInfo(gpCI, "", true);
327 
328 	// shaders
329 	{
330 		for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
331 		vk_json::_string_stream << "\"ShaderFileNames\" :" << std::endl;
332 		for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
333 		vk_json::_string_stream << "[" << std::endl;
334 		vk_json::s_num_spaces += 4;
335 
336 		for( deUint32 j=0; j<gpCI.stageCount; ++j)
337 		{
338 			for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
339 			vk_json::_string_stream << "{" << std::endl;
340 			vk_json::s_num_spaces += 4;
341 
342 			vk_json::print_VkShaderStageFlagBits(gpCI.pStages[j].stage, "stage", 1);
343 
344 			std::stringstream shaderName;
345 			shaderName << filePrefix << "shader_" << pipelineIndex << "_" << gpCI.pStages[j].module.getInternal() << ".";
346 
347 			switch (gpCI.pStages[j].stage)
348 			{
349 			case VK_SHADER_STAGE_VERTEX_BIT:					shaderName << "vert";	break;
350 			case VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT:		shaderName << "tesc";	break;
351 			case VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT:	shaderName << "tese";	break;
352 			case VK_SHADER_STAGE_GEOMETRY_BIT:					shaderName << "geom";	break;
353 			case VK_SHADER_STAGE_FRAGMENT_BIT:					shaderName << "frag";	break;
354 			default:
355 				TCU_THROW(InternalError, "Unrecognized shader stage");
356 			}
357 			shaderName << ".spv";
358 
359 			for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
360 			vk_json::_string_stream << "\"filename\" : \"" << shaderName.str() << "\"" << std::endl;
361 			vk_json::s_num_spaces -= 4;
362 			for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
363 
364 			if ((j+1) >= gpCI.stageCount)
365 				vk_json::_string_stream << "}" << std::endl;
366 			else
367 				vk_json::_string_stream << "}," << std::endl;
368 		}
369 
370 		vk_json::s_num_spaces -= 4;
371 		for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
372 		vk_json::_string_stream << "]," << std::endl;
373 	}
374 
375 	// device features
376 	for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
377 	vk_json::_string_stream << "\"PhysicalDeviceFeatures\" : " << std::endl;
378 	vk_json::print_VkPhysicalDeviceFeatures2(deviceFeatures2, "", false);
379 
380 	// close GraphicsPipelineState
381 	vk_json::s_num_spaces -= 4;
382 	for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
383 	vk_json::_string_stream << "}," << std::endl;
384 
385 	// device extensions
386 	{
387 		for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
388 		vk_json::_string_stream << "\"EnabledExtensions\" : " << std::endl;
389 		for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
390 		vk_json::_string_stream << "[" << std::endl;
391 		vk_json::s_num_spaces += 4;
392 
393 		for (unsigned int j = 0; j < deviceExtensions.size(); j++)
394 			vk_json::print_char(deviceExtensions[j].data(), "", (j + 1) != deviceExtensions.size());
395 
396 		vk_json::s_num_spaces -= 4;
397 		for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
398 		vk_json::_string_stream << "]," << std::endl;
399 	}
400 
401 	// pipeline identifier
402 	for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
403 	vk_json::_string_stream << "\"PipelineUUID\" : " << std::endl;
404 	for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
405 	vk_json::_string_stream << "[" << std::endl;
406 	vk_json::s_num_spaces += 4;
407 	for (unsigned int j = 0; j < VK_UUID_SIZE; j++)
408 		vk_json::print_uint32_t((deUint32)id.pipelineIdentifier[j], "", (j + 1) != VK_UUID_SIZE);
409 	vk_json::s_num_spaces -= 4;
410 	for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
411 	vk_json::_string_stream << "]" << std::endl;
412 
413 	vk_json::s_num_spaces -= 4;
414 	for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
415 	vk_json::_string_stream << "}" << std::endl;
416 
417 	return vk_json::_string_stream.str();
418 }
419 
writeJSON_ComputePipeline_vkpccjson(const std::string & filePrefix,deUint32 pipelineIndex,const vk::VkPipelineOfflineCreateInfo id,const VkComputePipelineCreateInfo & cpCI,const vk::VkPhysicalDeviceFeatures2 & deviceFeatures2,const std::vector<std::string> & deviceExtensions,const std::map<VkSamplerYcbcrConversion,VkSamplerYcbcrConversionCreateInfo> & samplerYcbcrConversions,const std::map<VkSampler,VkSamplerCreateInfo> & samplers,const std::map<VkDescriptorSetLayout,VkDescriptorSetLayoutCreateInfo> & descriptorSetLayouts,const std::map<VkPipelineLayout,VkPipelineLayoutCreateInfo> & pipelineLayouts)420 string	writeJSON_ComputePipeline_vkpccjson (const std::string&																filePrefix,
421 											 deUint32																		pipelineIndex,
422 											 const vk::VkPipelineOfflineCreateInfo											id,
423 											 const VkComputePipelineCreateInfo&												cpCI,
424 											 const vk::VkPhysicalDeviceFeatures2&											deviceFeatures2,
425 											 const std::vector<std::string>&												deviceExtensions,
426 											 const std::map<VkSamplerYcbcrConversion, VkSamplerYcbcrConversionCreateInfo>&	samplerYcbcrConversions,
427 											 const std::map<VkSampler, VkSamplerCreateInfo>&								samplers,
428 											 const std::map<VkDescriptorSetLayout, VkDescriptorSetLayoutCreateInfo>&		descriptorSetLayouts,
429 											 const std::map<VkPipelineLayout, VkPipelineLayoutCreateInfo>&					pipelineLayouts)
430 {
431 	vk_json::_string_stream.str({});
432 	vk_json::_string_stream.clear();
433 
434 	for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
435 	vk_json::_string_stream << "{" << std::endl;
436 	vk_json::s_num_spaces += 4;
437 
438 	for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
439 	vk_json::_string_stream << "\"ComputePipelineState\" :" << std::endl;
440 	for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
441 	vk_json::_string_stream << "{" << std::endl;
442 	vk_json::s_num_spaces += 4;
443 
444 	if (!samplerYcbcrConversions.empty())
445 	{
446 		for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
447 		vk_json::_string_stream << "\"YcbcrSamplers\" :" << std::endl;
448 		for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
449 		vk_json::_string_stream << "[" << std::endl;
450 		vk_json::s_num_spaces += 4;
451 
452 		size_t j = 0u;
453 		for (auto it = begin(samplerYcbcrConversions); it != end(samplerYcbcrConversions); ++it, ++j)
454 		{
455 			for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
456 			vk_json::_string_stream << "{" << std::endl;
457 			vk_json::s_num_spaces += 4;
458 
459 			for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
460 			vk_json::_string_stream << "\"" << it->first.getInternal() << "\":" << std::endl;
461 
462 			vk_json::print_VkSamplerYcbcrConversionCreateInfo(it->second, "", false);
463 
464 			vk_json::s_num_spaces -= 4;
465 			for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
466 			if ((j + 1) < samplerYcbcrConversions.size())
467 				vk_json::_string_stream << "}," << std::endl;
468 			else
469 				vk_json::_string_stream << "}" << std::endl;
470 		}
471 
472 		vk_json::s_num_spaces -= 4;
473 		for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
474 		vk_json::_string_stream << "]," << std::endl;
475 	}
476 
477 	if (!samplers.empty())
478 	{
479 		for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
480 		vk_json::_string_stream << "\"ImmutableSamplers\" :" << std::endl;
481 		for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
482 		vk_json::_string_stream << "[" << std::endl;
483 		vk_json::s_num_spaces += 4;
484 
485 		size_t j = 0u;
486 		for (auto it = begin(samplers); it != end(samplers); ++it, ++j)
487 		{
488 			for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
489 			vk_json::_string_stream << "{" << std::endl;
490 			vk_json::s_num_spaces += 4;
491 
492 			for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
493 			vk_json::_string_stream << "\"" << it->first.getInternal() << "\":" << std::endl;
494 
495 			vk_json::print_VkSamplerCreateInfo(it->second, "", false);
496 
497 			vk_json::s_num_spaces -= 4;
498 			for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
499 
500 			if ((j + 1) < samplers.size())
501 				vk_json::_string_stream << "}," << std::endl;
502 			else
503 				vk_json::_string_stream << "}" << std::endl;
504 		}
505 
506 		vk_json::s_num_spaces -= 4;
507 		for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
508 		vk_json::_string_stream << "]," << std::endl;
509 	}
510 
511 	if (!descriptorSetLayouts.empty())
512 	{
513 		for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
514 		vk_json::_string_stream << "\"DescriptorSetLayouts\" :" << std::endl;
515 		for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
516 		vk_json::_string_stream << "[" << std::endl;
517 		vk_json::s_num_spaces += 4;
518 
519 		size_t j = 0u;
520 		for (auto it = begin(descriptorSetLayouts); it != end(descriptorSetLayouts); ++it, ++j)
521 		{
522 			for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
523 			vk_json::_string_stream << "{" << std::endl;
524 			vk_json::s_num_spaces += 4;
525 
526 			for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
527 			vk_json::_string_stream << "\"" << it->first.getInternal() << "\":" << std::endl;
528 
529 			vk_json::print_VkDescriptorSetLayoutCreateInfo(it->second, "", false);
530 
531 			vk_json::s_num_spaces -= 4;
532 			for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
533 
534 			if ((j + 1) < descriptorSetLayouts.size())
535 				vk_json::_string_stream << "}," << std::endl;
536 			else
537 				vk_json::_string_stream << "}" << std::endl;
538 		}
539 
540 		vk_json::s_num_spaces -= 4;
541 		for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
542 		vk_json::_string_stream << "]," << std::endl;
543 	}
544 
545 	for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
546 	vk_json::_string_stream << "\"PipelineLayout\" : " << std::endl;
547 	vk_json::print_VkPipelineLayoutCreateInfo(begin(pipelineLayouts)->second, "", true);
548 
549 	for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
550 	vk_json::_string_stream << "\"ComputePipeline\" : " << std::endl;
551 	vk_json::print_VkComputePipelineCreateInfo(cpCI, "", true);
552 
553 	// shaders
554 	{
555 		for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
556 		vk_json::_string_stream << "\"ShaderFileNames\" :" << std::endl;
557 		for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
558 		vk_json::_string_stream << "[" << std::endl;
559 		vk_json::s_num_spaces += 4;
560 
561 		{
562 			for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
563 			vk_json::_string_stream << "{" << std::endl;
564 			vk_json::s_num_spaces += 4;
565 
566 			vk_json::print_VkShaderStageFlagBits(cpCI.stage.stage, "stage", 1);
567 
568 			std::stringstream shaderName;
569 			shaderName << filePrefix << "shader_" << pipelineIndex << "_" << cpCI.stage.module.getInternal() << ".";
570 
571 			switch (cpCI.stage.stage)
572 			{
573 			case VK_SHADER_STAGE_COMPUTE_BIT:					shaderName << "comp";	break;
574 			default:
575 				TCU_THROW(InternalError, "Unrecognized shader stage");
576 			}
577 			shaderName << ".spv";
578 
579 			for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
580 			vk_json::_string_stream << "\"filename\" : \"" << shaderName.str() << "\"" << std::endl;
581 			vk_json::s_num_spaces -= 4;
582 			for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
583 
584 			vk_json::_string_stream << "}" << std::endl;
585 		}
586 
587 		vk_json::s_num_spaces -= 4;
588 		for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
589 		vk_json::_string_stream << "]," << std::endl;
590 	}
591 
592 	// device features
593 	for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
594 	vk_json::_string_stream << "\"PhysicalDeviceFeatures\" : " << std::endl;
595 	vk_json::print_VkPhysicalDeviceFeatures2(deviceFeatures2, "", false);
596 
597 	// close ComputePipelineState
598 	vk_json::s_num_spaces -= 4;
599 	for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
600 	vk_json::_string_stream << "}," << std::endl;
601 
602 	// device extensions
603 	{
604 		for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
605 		vk_json::_string_stream << "\"EnabledExtensions\" : " << std::endl;
606 		for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
607 		vk_json::_string_stream << "[" << std::endl;
608 		vk_json::s_num_spaces += 4;
609 
610 		for (unsigned int j = 0; j < deviceExtensions.size(); j++)
611 			vk_json::print_char(deviceExtensions[j].data(), "", (j + 1) != deviceExtensions.size());
612 
613 		vk_json::s_num_spaces -= 4;
614 		for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
615 		vk_json::_string_stream << "]," << std::endl;
616 	}
617 
618 	// pipeline identifier
619 	for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
620 	vk_json::_string_stream << "\"PipelineUUID\" : " << std::endl;
621 	for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
622 	vk_json::_string_stream << "[" << std::endl;
623 	vk_json::s_num_spaces += 4;
624 	for (unsigned int j = 0; j < VK_UUID_SIZE; j++)
625 		vk_json::print_uint32_t((deUint32)id.pipelineIdentifier[j], "", (j + 1) != VK_UUID_SIZE);
626 	vk_json::s_num_spaces -= 4;
627 	for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
628 	vk_json::_string_stream << "]" << std::endl;
629 
630 	vk_json::s_num_spaces -= 4;
631 	for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
632 	vk_json::_string_stream << "}" << std::endl;
633 
634 	return vk_json::_string_stream.str();
635 }
636 
writeJSON_VkPhysicalDeviceFeatures2(const vk::VkPhysicalDeviceFeatures2 & features)637 string writeJSON_VkPhysicalDeviceFeatures2 (const vk::VkPhysicalDeviceFeatures2& features)
638 {
639 	vk_json::_string_stream.str({});
640 	vk_json::_string_stream.clear();
641 	vk_json::print_VkPhysicalDeviceFeatures2(&features, "", false);
642 	return vk_json::_string_stream.str();
643 }
644 
writeJSON_pNextChain(const void * pNext)645 string	writeJSON_pNextChain (const void* pNext)
646 {
647 	vk_json::_string_stream.str({});
648 	vk_json::_string_stream.clear();
649 	vk_json::dumpPNextChain(pNext);
650 	std::string result = vk_json::_string_stream.str();
651 	// remove "pNext" at the beggining of result and trailing comma
652 	return std::string(begin(result) + result.find_first_of('{'), begin(result) + result.find_last_of('}') + 1u);
653 }
654 
writeJSON_VkSamplerYcbcrConversionCreateInfo(const VkSamplerYcbcrConversionCreateInfo & pCreateInfo)655 string writeJSON_VkSamplerYcbcrConversionCreateInfo (const VkSamplerYcbcrConversionCreateInfo& pCreateInfo)
656 {
657 	vk_json::_string_stream.str({});
658 	vk_json::_string_stream.clear();
659 	vk_json::print_VkSamplerYcbcrConversionCreateInfo(&pCreateInfo, "", false);
660 	return vk_json::_string_stream.str();
661 }
662 
print_VkShaderModuleCreateInfo(const VkShaderModuleCreateInfo * obj,const string & s,bool commaNeeded)663 static void print_VkShaderModuleCreateInfo (const VkShaderModuleCreateInfo* obj, const string& s, bool commaNeeded)
664 {
665 	DE_UNREF(s);
666 
667 	for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
668 		vk_json::_string_stream << "{" << std::endl;
669 		vk_json::s_num_spaces += 4;
670 
671 	vk_json::print_VkStructureType(obj->sType, "sType", 1);
672 
673 	if (obj->pNext) {
674 		vk_json::dumpPNextChain(obj->pNext);
675 	}
676 	else {
677 		for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
678 			vk_json::_string_stream << "\"pNext\":" << "\"NULL\"" << "," << std::endl;
679 	}
680 
681 	// VkShaderModuleCreateFlags is reserved for future use and must be 0.
682 	vk_json::print_uint32_t((deUint32)obj->flags, "flags", 1);
683 	vk_json::print_uint64_t((deUint64)obj->codeSize, "codeSize", 1);
684 
685 	// pCode must be translated into base64, because JSON
686 	vk_json::print_void_data(obj->pCode, static_cast<int>(obj->codeSize), "pCode", 0);
687 
688 	vk_json::s_num_spaces -= 4;
689 	for (int i = 0; i < vk_json::s_num_spaces; i++) vk_json::_string_stream << " ";
690 		if (commaNeeded)
691 			vk_json::_string_stream << "}," << std::endl;
692 		else
693 			vk_json::_string_stream << "}" << std::endl;
694 }
695 
writeJSON_VkShaderModuleCreateInfo(const VkShaderModuleCreateInfo & smCI)696 string writeJSON_VkShaderModuleCreateInfo (const VkShaderModuleCreateInfo& smCI)
697 {
698 	vk_json::_string_stream.str({});
699 	vk_json::_string_stream.clear();
700 	print_VkShaderModuleCreateInfo(&smCI, "", false);
701 	return vk_json::_string_stream.str();
702 }
703 
readJSON_VkGraphicsPipelineCreateInfo(Context & context,const string & graphicsPipelineCreateInfo,VkGraphicsPipelineCreateInfo & gpCI)704 void readJSON_VkGraphicsPipelineCreateInfo (Context& context,
705 											const string& graphicsPipelineCreateInfo,
706 											VkGraphicsPipelineCreateInfo&	gpCI)
707 {
708 	Json::Value						jsonRoot;
709 	string							errors;
710 	bool							parsingSuccessful = context.reader->parse(graphicsPipelineCreateInfo.c_str(), graphicsPipelineCreateInfo.c_str() + graphicsPipelineCreateInfo.size(), &jsonRoot, &errors);
711 	if (!parsingSuccessful)
712 		TCU_THROW(InternalError, ("JSON parsing error: " + errors).c_str());
713 	vk_json_parser::parse_VkGraphicsPipelineCreateInfo("", jsonRoot, gpCI);
714 }
715 
readJSON_VkComputePipelineCreateInfo(Context & context,const string & computePipelineCreateInfo,VkComputePipelineCreateInfo & cpCI)716 void readJSON_VkComputePipelineCreateInfo (Context& context,
717 										   const string& computePipelineCreateInfo,
718 										   VkComputePipelineCreateInfo&	cpCI)
719 {
720 	Json::Value						jsonRoot;
721 	string							errors;
722 	bool							parsingSuccessful = context.reader->parse(computePipelineCreateInfo.c_str(), computePipelineCreateInfo.c_str() + computePipelineCreateInfo.size(), &jsonRoot, &errors);
723 	if (!parsingSuccessful)
724 		TCU_THROW(InternalError, ("JSON parsing error: " + errors).c_str());
725 	vk_json_parser::parse_VkComputePipelineCreateInfo("", jsonRoot, cpCI);
726 }
727 
readJSON_VkRenderPassCreateInfo(Context & context,const string & renderPassCreateInfo,VkRenderPassCreateInfo & rpCI)728 void readJSON_VkRenderPassCreateInfo (Context& context,
729 									  const string& renderPassCreateInfo,
730 									  VkRenderPassCreateInfo&	rpCI)
731 {
732 	Json::Value						jsonRoot;
733 	string							errors;
734 	bool							parsingSuccessful = context.reader->parse(renderPassCreateInfo.c_str(), renderPassCreateInfo.c_str() + renderPassCreateInfo.size(), &jsonRoot, &errors);
735 	if (!parsingSuccessful)
736 		TCU_THROW(InternalError, ("JSON parsing error: " + errors).c_str());
737 	vk_json_parser::parse_VkRenderPassCreateInfo("", jsonRoot, rpCI);
738 }
739 
readJSON_VkRenderPassCreateInfo2(Context & context,const string & renderPassCreateInfo,VkRenderPassCreateInfo2 & rpCI)740 void readJSON_VkRenderPassCreateInfo2 (Context& context,
741 									   const string& renderPassCreateInfo,
742 									   VkRenderPassCreateInfo2&	rpCI)
743 {
744 	Json::Value						jsonRoot;
745 	string							errors;
746 	bool							parsingSuccessful = context.reader->parse(renderPassCreateInfo.c_str(), renderPassCreateInfo.c_str() + renderPassCreateInfo.size(), &jsonRoot, &errors);
747 	if (!parsingSuccessful)
748 		TCU_THROW(InternalError, ("JSON parsing error: " + errors).c_str());
749 	vk_json_parser::parse_VkRenderPassCreateInfo2("", jsonRoot, rpCI);
750 }
751 
readJSON_VkDescriptorSetLayoutCreateInfo(Context & context,const string & descriptorSetLayoutCreateInfo,VkDescriptorSetLayoutCreateInfo & dsCI)752 void readJSON_VkDescriptorSetLayoutCreateInfo (Context& context,
753 											   const string& descriptorSetLayoutCreateInfo,
754 											   VkDescriptorSetLayoutCreateInfo&	dsCI)
755 {
756 	Json::Value						jsonRoot;
757 	string							errors;
758 	bool							parsingSuccessful = context.reader->parse(descriptorSetLayoutCreateInfo.c_str(), descriptorSetLayoutCreateInfo.c_str() + descriptorSetLayoutCreateInfo.size(), &jsonRoot, &errors);
759 	if (!parsingSuccessful)
760 		TCU_THROW(InternalError, ("JSON parsing error: " + errors).c_str());
761 	vk_json_parser::parse_VkDescriptorSetLayoutCreateInfo("", jsonRoot, dsCI);
762 }
763 
readJSON_VkPipelineLayoutCreateInfo(Context & context,const string & pipelineLayoutCreateInfo,VkPipelineLayoutCreateInfo & plCI)764 void readJSON_VkPipelineLayoutCreateInfo (Context& context,
765 										  const string& pipelineLayoutCreateInfo,
766 										  VkPipelineLayoutCreateInfo& plCI)
767 {
768 	Json::Value						jsonRoot;
769 	string							errors;
770 	bool							parsingSuccessful = context.reader->parse(pipelineLayoutCreateInfo.c_str(), pipelineLayoutCreateInfo.c_str() + pipelineLayoutCreateInfo.size(), &jsonRoot, &errors);
771 	if (!parsingSuccessful)
772 		TCU_THROW(InternalError, ("JSON parsing error: " + errors).c_str());
773 	vk_json_parser::parse_VkPipelineLayoutCreateInfo("", jsonRoot, plCI);
774 }
775 
readJSON_VkDeviceObjectReservationCreateInfo(Context & context,const string & deviceMemoryReservation,VkDeviceObjectReservationCreateInfo & dmrCI)776 void readJSON_VkDeviceObjectReservationCreateInfo (Context& context,
777 												   const string& deviceMemoryReservation,
778 												   VkDeviceObjectReservationCreateInfo&	dmrCI)
779 {
780 	Json::Value						jsonRoot;
781 	string							errors;
782 	bool							parsingSuccessful	= context.reader->parse(deviceMemoryReservation.c_str(), deviceMemoryReservation.c_str() + deviceMemoryReservation.size(), &jsonRoot, &errors);
783 	if (!parsingSuccessful)
784 		TCU_THROW(InternalError, ("JSON parsing error: " + errors).c_str());
785 	vk_json_parser::parse_VkDeviceObjectReservationCreateInfo("", jsonRoot, dmrCI);
786 }
787 
readJSON_VkPipelineOfflineCreateInfo(Context & context,const string & pipelineIdentifierInfo,vk::VkPipelineOfflineCreateInfo & piInfo)788 void readJSON_VkPipelineOfflineCreateInfo (Context& context,
789 										   const string& pipelineIdentifierInfo,
790 										   vk::VkPipelineOfflineCreateInfo& piInfo)
791 {
792 	Json::Value						jsonRoot;
793 	string							errors;
794 	bool							parsingSuccessful	= context.reader->parse(pipelineIdentifierInfo.c_str(), pipelineIdentifierInfo.c_str() + pipelineIdentifierInfo.size(), &jsonRoot, &errors);
795 	if (!parsingSuccessful)
796 		TCU_THROW(InternalError, ("JSON parsing error: " + errors).c_str());
797 	vk_json_parser::parse_VkPipelineOfflineCreateInfo("", jsonRoot, piInfo);
798 }
799 
readJSON_VkSamplerCreateInfo(Context & context,const string & samplerCreateInfo,VkSamplerCreateInfo & sCI)800 void readJSON_VkSamplerCreateInfo (Context& context,
801 								   const string& samplerCreateInfo,
802 								   VkSamplerCreateInfo&	sCI)
803 {
804 	Json::Value						jsonRoot;
805 	string							errors;
806 	bool							parsingSuccessful = context.reader->parse(samplerCreateInfo.c_str(), samplerCreateInfo.c_str() + samplerCreateInfo.size(), &jsonRoot, &errors);
807 	if (!parsingSuccessful)
808 		TCU_THROW(InternalError, ("JSON parsing error: " + errors).c_str());
809 	vk_json_parser::parse_VkSamplerCreateInfo("", jsonRoot, sCI);
810 }
811 
readJSON_VkSamplerYcbcrConversionCreateInfo(Context & context,const std::string & samplerYcbcrConversionCreateInfo,VkSamplerYcbcrConversionCreateInfo & sycCI)812 void readJSON_VkSamplerYcbcrConversionCreateInfo (Context& context,
813 												  const std::string& samplerYcbcrConversionCreateInfo,
814 												  VkSamplerYcbcrConversionCreateInfo& sycCI)
815 {
816 	Json::Value						jsonRoot;
817 	std::string						errors;
818 	bool							parsingSuccessful = context.reader->parse(samplerYcbcrConversionCreateInfo.c_str(), samplerYcbcrConversionCreateInfo.c_str() + samplerYcbcrConversionCreateInfo.size(), &jsonRoot, &errors);
819 	if (!parsingSuccessful)
820 		TCU_THROW(InternalError, (std::string("JSON parsing error: ") + errors).c_str());
821 	vk_json_parser::parse_VkSamplerYcbcrConversionCreateInfo("", jsonRoot, sycCI);
822 }
823 
readJSON_VkPhysicalDeviceFeatures2(Context & context,const std::string & featuresJson,vk::VkPhysicalDeviceFeatures2 & features)824 void readJSON_VkPhysicalDeviceFeatures2 (Context&									context,
825 										 const std::string&							featuresJson,
826 										 vk::VkPhysicalDeviceFeatures2&				features)
827 {
828 	Json::Value						jsonRoot;
829 	std::string						errors;
830 	bool							parsingSuccessful = context.reader->parse(featuresJson.c_str(), featuresJson.c_str() + featuresJson.size(), &jsonRoot, &errors);
831 	if (!parsingSuccessful)
832 		TCU_THROW(InternalError, (std::string("JSON parsing error: ") + errors).c_str());
833 	vk_json_parser::parse_VkPhysicalDeviceFeatures2("", jsonRoot, features);
834 }
835 
readJSON_pNextChain(Context & context,const std::string & chainJson)836 void* readJSON_pNextChain (Context&				context,
837 						  const std::string&	chainJson)
838 {
839 	Json::Value						jsonRoot;
840 	std::string						errors;
841 	bool							parsingSuccessful = context.reader->parse(chainJson.c_str(), chainJson.c_str() + chainJson.size(), &jsonRoot, &errors);
842 	if (!parsingSuccessful)
843 		TCU_THROW(InternalError, (std::string("JSON parsing error: ") + errors).c_str());
844 	return vk_json_parser::parsePNextChain(jsonRoot);
845 }
846 
parse_VkShaderModuleCreateInfo(const char * s,Json::Value & obj,VkShaderModuleCreateInfo & o,std::vector<deUint8> & spirvShader)847 static void parse_VkShaderModuleCreateInfo (const char*					s,
848 											Json::Value&				obj,
849 											VkShaderModuleCreateInfo&	o,
850 											std::vector<deUint8>&		spirvShader)
851 {
852 	DE_UNREF(s);
853 
854 	vk_json_parser::parse_VkStructureType("sType", obj["sType"], (o.sType));
855 
856 	o.pNext = (VkDeviceObjectReservationCreateInfo*)vk_json_parser::parsePNextChain(obj);
857 
858 	vk_json_parser::parse_uint32_t("flags", obj["flags"], (o.flags));
859 	deUint64 codeSizeValue;
860 	vk_json_parser::parse_uint64_t("codeSize", obj["codeSize"], (codeSizeValue));
861 	o.codeSize = (deUintptr)codeSizeValue;
862 
863 	// pCode is encoded using Base64.
864 	spirvShader = vk_json_parser::base64decode(obj["pCode"].asString());
865 	// Base64 always decodes a multiple of 3 bytes, so the size could mismatch the module
866 	// size by one or two bytes. resize spirvShader to match.
867 	spirvShader.resize(o.codeSize);
868 	o.pCode = (deUint32*)spirvShader.data();
869 }
870 
readJSON_VkShaderModuleCreateInfo(Context & context,const string & shaderModuleCreate,VkShaderModuleCreateInfo & smCI,std::vector<deUint8> & spirvShader)871 void readJSON_VkShaderModuleCreateInfo (Context& context,
872 										const string&				shaderModuleCreate,
873 										VkShaderModuleCreateInfo&	smCI,
874 										std::vector<deUint8>&		spirvShader)
875 {
876 	Json::Value			jsonRoot;
877 	string				errors;
878 	bool				parsingSuccessful = context.reader->parse(shaderModuleCreate.c_str(), shaderModuleCreate.c_str() + shaderModuleCreate.size(), &jsonRoot, &errors);
879 	if (!parsingSuccessful)
880 		TCU_THROW(InternalError, ("JSON parsing error: " + errors).c_str());
881 	parse_VkShaderModuleCreateInfo("", jsonRoot, smCI, spirvShader);
882 }
883 
884 } // namespace json
885 
886 } // namespace vksc_server
887