Skip to content

Commit 492c254

Browse files
committed
Minor cleanup
1 parent 4f589bd commit 492c254

File tree

1 file changed

+32
-31
lines changed

1 file changed

+32
-31
lines changed

base/VulkanUIOverlay.cpp

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -225,26 +225,45 @@ namespace vks
225225
.colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT
226226
};
227227

228+
// Vertex bindings an attributes based on ImGui vertex definition
229+
std::vector<VkVertexInputBindingDescription> vertexInputBindings = {
230+
{ .binding = 0, .stride = sizeof(ImDrawVert), .inputRate = VK_VERTEX_INPUT_RATE_VERTEX }
231+
};
232+
std::vector<VkVertexInputAttributeDescription> vertexInputAttributes = {
233+
{ .location = 0, .binding = 0, .format = VK_FORMAT_R32G32_SFLOAT, .offset = offsetof(ImDrawVert, pos) },
234+
{ .location = 1, .binding = 0, .format = VK_FORMAT_R32G32_SFLOAT, .offset = offsetof(ImDrawVert, uv) },
235+
{ .location = 2, .binding = 0, .format = VK_FORMAT_R8G8B8A8_UNORM, .offset = offsetof(ImDrawVert, col) },
236+
};
237+
VkPipelineVertexInputStateCreateInfo vertexInputState = vks::initializers::pipelineVertexInputStateCreateInfo();
238+
vertexInputState.vertexBindingDescriptionCount = static_cast<uint32_t>(vertexInputBindings.size());
239+
vertexInputState.pVertexBindingDescriptions = vertexInputBindings.data();
240+
vertexInputState.vertexAttributeDescriptionCount = static_cast<uint32_t>(vertexInputAttributes.size());
241+
vertexInputState.pVertexAttributeDescriptions = vertexInputAttributes.data();
242+
228243
VkPipelineColorBlendStateCreateInfo colorBlendState = vks::initializers::pipelineColorBlendStateCreateInfo(1, &blendAttachmentState);
229244
VkPipelineDepthStencilStateCreateInfo depthStencilState = vks::initializers::pipelineDepthStencilStateCreateInfo(VK_FALSE, VK_FALSE, VK_COMPARE_OP_ALWAYS);
230245
VkPipelineViewportStateCreateInfo viewportState = vks::initializers::pipelineViewportStateCreateInfo(1, 1, 0);
231246
VkPipelineMultisampleStateCreateInfo multisampleState = vks::initializers::pipelineMultisampleStateCreateInfo(rasterizationSamples);
232247
std::vector<VkDynamicState> dynamicStateEnables = { VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR };
233248
VkPipelineDynamicStateCreateInfo dynamicState = vks::initializers::pipelineDynamicStateCreateInfo(dynamicStateEnables);
234-
VkGraphicsPipelineCreateInfo pipelineCreateInfo = vks::initializers::pipelineCreateInfo(pipelineLayout, renderPass);
235-
pipelineCreateInfo.pInputAssemblyState = &inputAssemblyState;
236-
pipelineCreateInfo.pRasterizationState = &rasterizationState;
237-
pipelineCreateInfo.pColorBlendState = &colorBlendState;
238-
pipelineCreateInfo.pMultisampleState = &multisampleState;
239-
pipelineCreateInfo.pViewportState = &viewportState;
240-
pipelineCreateInfo.pDepthStencilState = &depthStencilState;
241-
pipelineCreateInfo.pDynamicState = &dynamicState;
242-
pipelineCreateInfo.stageCount = static_cast<uint32_t>(shaders.size());
243-
pipelineCreateInfo.pStages = shaders.data();
244-
pipelineCreateInfo.subpass = subpass;
245-
249+
VkGraphicsPipelineCreateInfo pipelineCreateInfo{
250+
.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
251+
.stageCount = static_cast<uint32_t>(shaders.size()),
252+
.pStages = shaders.data(),
253+
.pVertexInputState = &vertexInputState,
254+
.pInputAssemblyState = &inputAssemblyState,
255+
.pViewportState = &viewportState,
256+
.pRasterizationState = &rasterizationState,
257+
.pMultisampleState = &multisampleState,
258+
.pDepthStencilState = &depthStencilState,
259+
.pColorBlendState = &colorBlendState,
260+
.pDynamicState = &dynamicState,
261+
.layout = pipelineLayout,
262+
.renderPass = renderPass,
263+
.subpass = subpass,
264+
};
246265
#if defined(VK_KHR_dynamic_rendering)
247-
// Of we are using dynamic rendering (i.e. renderPass null), we must define color, depth and stencil attachments at pipeline create time
266+
// If we are using dynamic rendering (renderPass is null), we must define color, depth and stencil attachments at pipeline create time
248267
VkPipelineRenderingCreateInfo pipelineRenderingCreateInfo{};
249268
if (renderPass == VK_NULL_HANDLE) {
250269
pipelineRenderingCreateInfo = {
@@ -257,24 +276,6 @@ namespace vks
257276
pipelineCreateInfo.pNext = &pipelineRenderingCreateInfo;
258277
}
259278
#endif
260-
261-
// Vertex bindings an attributes based on ImGui vertex definition
262-
std::vector<VkVertexInputBindingDescription> vertexInputBindings = {
263-
vks::initializers::vertexInputBindingDescription(0, sizeof(ImDrawVert), VK_VERTEX_INPUT_RATE_VERTEX),
264-
};
265-
std::vector<VkVertexInputAttributeDescription> vertexInputAttributes = {
266-
vks::initializers::vertexInputAttributeDescription(0, 0, VK_FORMAT_R32G32_SFLOAT, offsetof(ImDrawVert, pos)), // Location 0: Position
267-
vks::initializers::vertexInputAttributeDescription(0, 1, VK_FORMAT_R32G32_SFLOAT, offsetof(ImDrawVert, uv)), // Location 1: UV
268-
vks::initializers::vertexInputAttributeDescription(0, 2, VK_FORMAT_R8G8B8A8_UNORM, offsetof(ImDrawVert, col)), // Location 0: Color
269-
};
270-
VkPipelineVertexInputStateCreateInfo vertexInputState = vks::initializers::pipelineVertexInputStateCreateInfo();
271-
vertexInputState.vertexBindingDescriptionCount = static_cast<uint32_t>(vertexInputBindings.size());
272-
vertexInputState.pVertexBindingDescriptions = vertexInputBindings.data();
273-
vertexInputState.vertexAttributeDescriptionCount = static_cast<uint32_t>(vertexInputAttributes.size());
274-
vertexInputState.pVertexAttributeDescriptions = vertexInputAttributes.data();
275-
276-
pipelineCreateInfo.pVertexInputState = &vertexInputState;
277-
278279
VK_CHECK_RESULT(vkCreateGraphicsPipelines(device->logicalDevice, pipelineCache, 1, &pipelineCreateInfo, nullptr, &pipeline));
279280
}
280281

0 commit comments

Comments
 (0)