@@ -173,93 +173,102 @@ class VulkanExample: public VulkanExampleBase
173173
174174 // Create a pipeline library for the vertex input interface
175175 {
176- VkGraphicsPipelineLibraryCreateInfoEXT libraryInfo{};
177- libraryInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_LIBRARY_CREATE_INFO_EXT;
178- libraryInfo.flags = VK_GRAPHICS_PIPELINE_LIBRARY_VERTEX_INPUT_INTERFACE_BIT_EXT;
176+ VkGraphicsPipelineLibraryCreateInfoEXT libraryInfo{
177+ .sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_LIBRARY_CREATE_INFO_EXT,
178+ .flags = VK_GRAPHICS_PIPELINE_LIBRARY_VERTEX_INPUT_INTERFACE_BIT_EXT
179+ };
179180
180181 VkPipelineVertexInputStateCreateInfo vertexInputState = *vkglTF::Vertex::getPipelineVertexInputState ({ vkglTF::VertexComponent::Position, vkglTF::VertexComponent::Normal, vkglTF::VertexComponent::Color });
181182 VkPipelineInputAssemblyStateCreateInfo inputAssemblyState = vks::initializers::pipelineInputAssemblyStateCreateInfo (VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, 0 , VK_FALSE);
182183
183- VkGraphicsPipelineCreateInfo pipelineLibraryCI{};
184- pipelineLibraryCI .sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
185- pipelineLibraryCI. flags = VK_PIPELINE_CREATE_LIBRARY_BIT_KHR | VK_PIPELINE_CREATE_RETAIN_LINK_TIME_OPTIMIZATION_INFO_BIT_EXT;
186- pipelineLibraryCI. sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
187- pipelineLibraryCI. pNext = &libraryInfo;
188- pipelineLibraryCI .pInputAssemblyState = &inputAssemblyState;
189- pipelineLibraryCI. pVertexInputState = &vertexInputState ;
184+ VkGraphicsPipelineCreateInfo pipelineLibraryCI{
185+ .sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
186+ . pNext = &libraryInfo,
187+ . flags = VK_PIPELINE_CREATE_LIBRARY_BIT_KHR | VK_PIPELINE_CREATE_RETAIN_LINK_TIME_OPTIMIZATION_INFO_BIT_EXT,
188+ . pVertexInputState = &vertexInputState,
189+ .pInputAssemblyState = &inputAssemblyState,
190+ } ;
190191 VK_CHECK_RESULT (vkCreateGraphicsPipelines (device, pipelineCache, 1 , &pipelineLibraryCI, nullptr , &pipelineLibrary.vertexInputInterface ));
191192 }
192193
193194 // Creata a pipeline library for the vertex shader stage
194195 {
195- VkGraphicsPipelineLibraryCreateInfoEXT libraryInfo{};
196- libraryInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_LIBRARY_CREATE_INFO_EXT;
197- libraryInfo.flags = VK_GRAPHICS_PIPELINE_LIBRARY_PRE_RASTERIZATION_SHADERS_BIT_EXT;
198-
199196 VkDynamicState vertexDynamicStates[2 ] = {
200197 VK_DYNAMIC_STATE_VIEWPORT,
201198 VK_DYNAMIC_STATE_SCISSOR };
202199
203- VkPipelineDynamicStateCreateInfo dynamicInfo{};
204- dynamicInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
205- dynamicInfo.dynamicStateCount = 2 ;
206- dynamicInfo.pDynamicStates = vertexDynamicStates;
200+ VkPipelineDynamicStateCreateInfo dynamicInfo{
201+ .sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO,
202+ .dynamicStateCount = 2 ,
203+ .pDynamicStates = vertexDynamicStates
204+ };
207205
208- VkPipelineViewportStateCreateInfo viewportState = {};
209- viewportState.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
210- viewportState.viewportCount = 1 ;
211- viewportState.scissorCount = 1 ;
206+ VkPipelineViewportStateCreateInfo viewportState{
207+ .sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO,
208+ .viewportCount = 1 ,
209+ .scissorCount = 1
210+ };
212211
213212 VkPipelineRasterizationStateCreateInfo rasterizationState = vks::initializers::pipelineRasterizationStateCreateInfo (VK_POLYGON_MODE_FILL, VK_CULL_MODE_BACK_BIT, VK_FRONT_FACE_COUNTER_CLOCKWISE, 0 );
214213
215214 ShaderInfo shaderInfo{};
216215 loadShaderFile (getShadersPath () + " graphicspipelinelibrary/shared.vert.spv" , shaderInfo);
217216
218- VkShaderModuleCreateInfo shaderModuleCI{};
219- shaderModuleCI.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
220- shaderModuleCI.codeSize = shaderInfo.size ;
221- shaderModuleCI.pCode = shaderInfo.code ;
222-
223- VkPipelineShaderStageCreateInfo shaderStageCI{};
224- shaderStageCI.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
225- shaderStageCI.pNext = &shaderModuleCI;
226- shaderStageCI.stage = VK_SHADER_STAGE_VERTEX_BIT;
227- shaderStageCI.pName = " main" ;
228-
229- VkGraphicsPipelineCreateInfo pipelineLibraryCI{};
230- pipelineLibraryCI.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
231- pipelineLibraryCI.pNext = &libraryInfo;
232- pipelineLibraryCI.renderPass = renderPass;
233- pipelineLibraryCI.flags = VK_PIPELINE_CREATE_LIBRARY_BIT_KHR | VK_PIPELINE_CREATE_RETAIN_LINK_TIME_OPTIMIZATION_INFO_BIT_EXT;
234- pipelineLibraryCI.stageCount = 1 ;
235- pipelineLibraryCI.pStages = &shaderStageCI;
236- pipelineLibraryCI.layout = pipelineLayout;
237- pipelineLibraryCI.pDynamicState = &dynamicInfo;
238- pipelineLibraryCI.pViewportState = &viewportState;
239- pipelineLibraryCI.pRasterizationState = &rasterizationState;
217+ VkShaderModuleCreateInfo shaderModuleCI{
218+ .sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO,
219+ .codeSize = shaderInfo.size ,
220+ .pCode = shaderInfo.code
221+ };
222+
223+ VkPipelineShaderStageCreateInfo shaderStageCI{
224+ .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
225+ .pNext = &shaderModuleCI,
226+ .stage = VK_SHADER_STAGE_VERTEX_BIT,
227+ .pName = " main"
228+ };
229+
230+ VkGraphicsPipelineLibraryCreateInfoEXT libraryInfo{
231+ .sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_LIBRARY_CREATE_INFO_EXT,
232+ .flags = VK_GRAPHICS_PIPELINE_LIBRARY_PRE_RASTERIZATION_SHADERS_BIT_EXT
233+ };
234+
235+ VkGraphicsPipelineCreateInfo pipelineLibraryCI{
236+ .sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
237+ .pNext = &libraryInfo,
238+ .flags = VK_PIPELINE_CREATE_LIBRARY_BIT_KHR | VK_PIPELINE_CREATE_RETAIN_LINK_TIME_OPTIMIZATION_INFO_BIT_EXT,
239+ .stageCount = 1 ,
240+ .pStages = &shaderStageCI,
241+ .pViewportState = &viewportState,
242+ .pRasterizationState = &rasterizationState,
243+ .pDynamicState = &dynamicInfo,
244+ .layout = pipelineLayout,
245+ .renderPass = renderPass,
246+ };
240247 VK_CHECK_RESULT (vkCreateGraphicsPipelines (device, pipelineCache, 1 , &pipelineLibraryCI, nullptr , &pipelineLibrary.preRasterizationShaders ));
241248
242249 delete[] shaderInfo.code ;
243250 }
244251
245252 // Create a pipeline library for the fragment output interface
246253 {
247- VkGraphicsPipelineLibraryCreateInfoEXT libraryInfo{};
248- libraryInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_LIBRARY_CREATE_INFO_EXT;
249- libraryInfo.flags = VK_GRAPHICS_PIPELINE_LIBRARY_FRAGMENT_OUTPUT_INTERFACE_BIT_EXT;
254+ VkGraphicsPipelineLibraryCreateInfoEXT libraryInfo{
255+ .sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_LIBRARY_CREATE_INFO_EXT,
256+ .flags = VK_GRAPHICS_PIPELINE_LIBRARY_FRAGMENT_OUTPUT_INTERFACE_BIT_EXT
257+ };
250258
251259 VkPipelineColorBlendAttachmentState blendAttachmentSstate = vks::initializers::pipelineColorBlendAttachmentState (0xf , VK_FALSE);
252260 VkPipelineColorBlendStateCreateInfo colorBlendState = vks::initializers::pipelineColorBlendStateCreateInfo (1 , &blendAttachmentSstate);
253261 VkPipelineMultisampleStateCreateInfo multisampleState = vks::initializers::pipelineMultisampleStateCreateInfo (VK_SAMPLE_COUNT_1_BIT);
254262
255- VkGraphicsPipelineCreateInfo pipelineLibraryCI{};
256- pipelineLibraryCI.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
257- pipelineLibraryCI.pNext = &libraryInfo;
258- pipelineLibraryCI.layout = pipelineLayout;
259- pipelineLibraryCI.renderPass = renderPass;
260- pipelineLibraryCI.flags = VK_PIPELINE_CREATE_LIBRARY_BIT_KHR | VK_PIPELINE_CREATE_RETAIN_LINK_TIME_OPTIMIZATION_INFO_BIT_EXT;
261- pipelineLibraryCI.pColorBlendState = &colorBlendState;
262- pipelineLibraryCI.pMultisampleState = &multisampleState;
263+ VkGraphicsPipelineCreateInfo pipelineLibraryCI{
264+ .sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
265+ .pNext = &libraryInfo,
266+ .flags = VK_PIPELINE_CREATE_LIBRARY_BIT_KHR | VK_PIPELINE_CREATE_RETAIN_LINK_TIME_OPTIMIZATION_INFO_BIT_EXT,
267+ .pMultisampleState = &multisampleState,
268+ .pColorBlendState = &colorBlendState,
269+ .layout = pipelineLayout,
270+ .renderPass = renderPass
271+ };
263272 VK_CHECK_RESULT (vkCreateGraphicsPipelines (device, pipelineCache, 1 , &pipelineLibraryCI, nullptr , &pipelineLibrary.fragmentOutputInterface ));
264273 }
265274 }
@@ -288,9 +297,10 @@ class VulkanExample: public VulkanExampleBase
288297 void prepareNewPipeline ()
289298 {
290299 // Create the fragment shader part of the pipeline library with some random options
291- VkGraphicsPipelineLibraryCreateInfoEXT libraryInfo{};
292- libraryInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_LIBRARY_CREATE_INFO_EXT;
293- libraryInfo.flags = VK_GRAPHICS_PIPELINE_LIBRARY_FRAGMENT_SHADER_BIT_EXT;
300+ VkGraphicsPipelineLibraryCreateInfoEXT libraryInfo{
301+ .sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_LIBRARY_CREATE_INFO_EXT,
302+ .flags = VK_GRAPHICS_PIPELINE_LIBRARY_FRAGMENT_SHADER_BIT_EXT
303+ };
294304
295305 VkPipelineDepthStencilStateCreateInfo depthStencilState = vks::initializers::pipelineDepthStencilStateCreateInfo (VK_TRUE, VK_TRUE, VK_COMPARE_OP_LESS_OR_EQUAL);
296306 VkPipelineMultisampleStateCreateInfo multisampleState = vks::initializers::pipelineMultisampleStateCreateInfo (VK_SAMPLE_COUNT_1_BIT);
@@ -299,44 +309,49 @@ class VulkanExample: public VulkanExampleBase
299309 ShaderInfo shaderInfo{};
300310 loadShaderFile (getShadersPath () + " graphicspipelinelibrary/uber.frag.spv" , shaderInfo);
301311
302- VkShaderModuleCreateInfo shaderModuleCI{};
303- shaderModuleCI.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
304- shaderModuleCI.codeSize = shaderInfo.size ;
305- shaderModuleCI.pCode = shaderInfo.code ;
312+ VkShaderModuleCreateInfo shaderModuleCI{
313+ .sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO,
314+ .codeSize = shaderInfo.size ,
315+ .pCode = shaderInfo.code
316+ };
306317
307- VkPipelineShaderStageCreateInfo shaderStageCI{};
308- shaderStageCI.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
309- shaderStageCI.pNext = &shaderModuleCI;
310- shaderStageCI.stage = VK_SHADER_STAGE_FRAGMENT_BIT;
311- shaderStageCI.pName = " main" ;
318+ VkPipelineShaderStageCreateInfo shaderStageCI{
319+ .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
320+ .pNext = &shaderModuleCI,
321+ .stage = VK_SHADER_STAGE_FRAGMENT_BIT,
322+ .pName = " main"
323+ };
312324
313325 // Select lighting model using a specialization constant
314326 srand (benchmark.active ? 0 : ((unsigned int )time (NULL )));
315327 uint32_t lighting_model = (int )(rand () % 4 );
316328
317329 // Each shader constant of a shader stage corresponds to one map entry
318- VkSpecializationMapEntry specializationMapEntry{};
319- specializationMapEntry.constantID = 0 ;
320- specializationMapEntry.size = sizeof (uint32_t );
330+ VkSpecializationMapEntry specializationMapEntry{
331+ .constantID = 0 ,
332+ .size = sizeof (uint32_t )
333+ };
321334
322- VkSpecializationInfo specializationInfo{};
323- specializationInfo.mapEntryCount = 1 ;
324- specializationInfo.pMapEntries = &specializationMapEntry;
325- specializationInfo.dataSize = sizeof (uint32_t );
326- specializationInfo.pData = &lighting_model;
335+ VkSpecializationInfo specializationInfo{
336+ .mapEntryCount = 1 ,
337+ .pMapEntries = &specializationMapEntry,
338+ .dataSize = sizeof (uint32_t ),
339+ .pData = &lighting_model
340+ };
327341
328342 shaderStageCI.pSpecializationInfo = &specializationInfo;
329343
330- VkGraphicsPipelineCreateInfo pipelineCI{};
331- pipelineCI.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
332- pipelineCI.pNext = &libraryInfo;
333- pipelineCI.flags = VK_PIPELINE_CREATE_LIBRARY_BIT_KHR | VK_PIPELINE_CREATE_RETAIN_LINK_TIME_OPTIMIZATION_INFO_BIT_EXT;
334- pipelineCI.stageCount = 1 ;
335- pipelineCI.pStages = &shaderStageCI;
336- pipelineCI.layout = pipelineLayout;
337- pipelineCI.renderPass = renderPass;
338- pipelineCI.pDepthStencilState = &depthStencilState;
339- pipelineCI.pMultisampleState = &multisampleState;
344+ VkGraphicsPipelineCreateInfo pipelineCI{
345+ .sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
346+ .pNext = &libraryInfo,
347+ .flags = VK_PIPELINE_CREATE_LIBRARY_BIT_KHR | VK_PIPELINE_CREATE_RETAIN_LINK_TIME_OPTIMIZATION_INFO_BIT_EXT,
348+ .stageCount = 1 ,
349+ .pStages = &shaderStageCI,
350+ .pMultisampleState = &multisampleState,
351+ .pDepthStencilState = &depthStencilState,
352+ .layout = pipelineLayout,
353+ .renderPass = renderPass,
354+ };
340355 VkPipeline fragmentShader = VK_NULL_HANDLE;
341356 VK_CHECK_RESULT (vkCreateGraphicsPipelines (device, threadPipelineCache, 1 , &pipelineCI, nullptr , &fragmentShader));
342357
@@ -349,19 +364,21 @@ class VulkanExample: public VulkanExampleBase
349364 pipelineLibrary.fragmentOutputInterface };
350365
351366 // Link the library parts into a graphics pipeline
352- VkPipelineLibraryCreateInfoKHR pipelineLibraryCI{};
353- pipelineLibraryCI.sType = VK_STRUCTURE_TYPE_PIPELINE_LIBRARY_CREATE_INFO_KHR;
354- pipelineLibraryCI.libraryCount = static_cast <uint32_t >(libraries.size ());
355- pipelineLibraryCI.pLibraries = libraries.data ();
367+ VkPipelineLibraryCreateInfoKHR pipelineLibraryCI{
368+ .sType = VK_STRUCTURE_TYPE_PIPELINE_LIBRARY_CREATE_INFO_KHR,
369+ .libraryCount = static_cast <uint32_t >(libraries.size ()),
370+ .pLibraries = libraries.data ()
371+ };
356372
357373 // If set to true, we pass VK_PIPELINE_CREATE_LINK_TIME_OPTIMIZATION_BIT_EXT which will let the implementation do additional optimizations at link time
358374 // This trades in pipeline creation time for run-time performance
359375 bool optimized = true ;
360376
361- VkGraphicsPipelineCreateInfo executablePipelineCI{};
362- executablePipelineCI.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
363- executablePipelineCI.pNext = &pipelineLibraryCI;
364- executablePipelineCI.layout = pipelineLayout;
377+ VkGraphicsPipelineCreateInfo executablePipelineCI{
378+ .sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
379+ .pNext = &pipelineLibraryCI,
380+ .layout = pipelineLayout
381+ };
365382 if (linkTimeOptimization)
366383 {
367384 // If link time optimization is activated in the UI, we set the VK_PIPELINE_CREATE_LINK_TIME_OPTIMIZATION_BIT_EXT flag which will let the implementation do additional optimizations at link time
@@ -416,10 +433,11 @@ class VulkanExample: public VulkanExampleBase
416433 std::thread pipelineGenerationThread (&VulkanExample::threadFn, this );
417434
418435 // Stall in benchmark mode until pipeline creation is finished to measure work more consistently
419- if (benchmark.active )
420- pipelineGenerationThread.join ();
421- else
436+ if (benchmark.active ) {
437+ pipelineGenerationThread.join ();
438+ } else {
422439 pipelineGenerationThread.detach ();
440+ }
423441
424442 prepared = true ;
425443 }
@@ -434,15 +452,14 @@ class VulkanExample: public VulkanExampleBase
434452 clearValues[0 ].color = defaultClearColor;
435453 clearValues[1 ].depthStencil = { 1 .0f , 0 };
436454
437- VkRenderPassBeginInfo renderPassBeginInfo = vks::initializers::renderPassBeginInfo ();
438- renderPassBeginInfo.renderPass = renderPass;
439- renderPassBeginInfo.renderArea .offset .x = 0 ;
440- renderPassBeginInfo.renderArea .offset .y = 0 ;
441- renderPassBeginInfo.renderArea .extent .width = width;
442- renderPassBeginInfo.renderArea .extent .height = height;
443- renderPassBeginInfo.clearValueCount = 2 ;
444- renderPassBeginInfo.pClearValues = clearValues;
445- renderPassBeginInfo.framebuffer = frameBuffers[currentImageIndex];
455+ VkRenderPassBeginInfo renderPassBeginInfo{
456+ .sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
457+ .renderPass = renderPass,
458+ .framebuffer = frameBuffers[currentImageIndex],
459+ .renderArea = {.offset = {.x = 0 , .y = 0 }, .extent = {.width = width, .height = height } },
460+ .clearValueCount = 2 ,
461+ .pClearValues = clearValues,
462+ };
446463
447464 VK_CHECK_RESULT (vkBeginCommandBuffer (cmdBuffer, &cmdBufInfo));
448465
0 commit comments