Hi all. I am a beginner in graphics API and I’m learning vulkan. I have a few questions please help
1.about Vulkan input attachments and sub passes
If there is only the sample1 and in shader code i can get the color.view by layout (binding = 0) .It is ok.
sample1
VkFramebufferCreateInfo frameBufferCI{};
frameBufferCI.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
frameBufferCI.renderPass = renderPass;
frameBufferCI.attachmentCount = 3;
frameBufferCI.pAttachments = views;
frameBufferCI.width = width;
frameBufferCI.height = height;
frameBufferCI.layers = 1;
frameBuffers.resize(swapChain.imageCount);
for (uint32_t i = 0; i < frameBuffers.size(); i++)
{
views[0] = swapChain.buffers[i].view;
views[1] = attachments[i].color.view;
views[2] = attachments[i].depth.view;
VK_CHECK_RESULT(vkCreateFramebuffer(device, &frameBufferCI, nullptr, &frameBuffers[i]));
}
If there is only the sample2 and in shader code i can get the color.view by layout (input_attachment_index = 0) .It is ok too.
std::vector<VkDescriptorImageInfo> descriptors = {
vks::initializers::descriptorImageInfo(VK_NULL_HANDLE, attachments[index].color.view, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL),
vks::initializers::descriptorImageInfo(VK_NULL_HANDLE, attachments[index].depth.view, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL)
};
But when these two pieces of code are put together and the shader code is as follows, I get very confused. Why specify the same underlying resource twice in different ways. This feels repetitive and increases the chance of errors due to inconsistent parameters.
layout (input_attachment_index = 0, binding = 0) uniform subpassInput inputColor;
layout (input_attachment_index = 1, binding = 1) uniform subpassInput inputDepth;
2.When we wrote code in the past, if we needed a member already included in the parameter, we would try to get this member from the parameter through the interface instead of specifying the same parameter again, so as to avoid repetition and potential inconsistency. But in the process of learning vulkan, I often encounter situations where I need to repeatedly set certain parameters, which makes me feel very distressed, because sometimes I don’t understand the intention.