Fixed problems with image layouts and layout transitions.
This commit is contained in:
parent
0f8bed9fde
commit
2141145523
5 changed files with 16 additions and 30 deletions
|
|
@ -28,7 +28,6 @@ namespace vks
|
||||||
VkFormat format;
|
VkFormat format;
|
||||||
VkImageSubresourceRange subresourceRange;
|
VkImageSubresourceRange subresourceRange;
|
||||||
VkAttachmentDescription description;
|
VkAttachmentDescription description;
|
||||||
VkImageLayout initialLayout;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns true if the attachment has a depth component
|
* @brief Returns true if the attachment has a depth component
|
||||||
|
|
@ -139,7 +138,6 @@ namespace vks
|
||||||
attachment.format = createinfo.format;
|
attachment.format = createinfo.format;
|
||||||
|
|
||||||
VkImageAspectFlags aspectMask = VK_FLAGS_NONE;
|
VkImageAspectFlags aspectMask = VK_FLAGS_NONE;
|
||||||
VkImageLayout imageLayout;
|
|
||||||
|
|
||||||
// Select aspect mask and layout depending on usage
|
// Select aspect mask and layout depending on usage
|
||||||
|
|
||||||
|
|
@ -147,8 +145,6 @@ namespace vks
|
||||||
if (createinfo.usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT)
|
if (createinfo.usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT)
|
||||||
{
|
{
|
||||||
aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
||||||
attachment.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
|
||||||
imageLayout = (createinfo.usage & VK_IMAGE_USAGE_SAMPLED_BIT) ? VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL : VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Depth (and/or stencil) attachment
|
// Depth (and/or stencil) attachment
|
||||||
|
|
@ -162,8 +158,6 @@ namespace vks
|
||||||
{
|
{
|
||||||
aspectMask = aspectMask | VK_IMAGE_ASPECT_STENCIL_BIT;
|
aspectMask = aspectMask | VK_IMAGE_ASPECT_STENCIL_BIT;
|
||||||
}
|
}
|
||||||
attachment.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
|
|
||||||
imageLayout = (createinfo.usage & VK_IMAGE_USAGE_SAMPLED_BIT) ? VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL : VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(aspectMask > 0);
|
assert(aspectMask > 0);
|
||||||
|
|
@ -218,11 +212,11 @@ namespace vks
|
||||||
// If not, final layout depends on attachment type
|
// If not, final layout depends on attachment type
|
||||||
if (attachment.hasDepth() || attachment.hasStencil())
|
if (attachment.hasDepth() || attachment.hasStencil())
|
||||||
{
|
{
|
||||||
attachment.description.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
|
attachment.description.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
attachment.description.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
attachment.description.finalLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
attachments.push_back(attachment);
|
attachments.push_back(attachment);
|
||||||
|
|
|
||||||
|
|
@ -519,6 +519,8 @@ namespace vks
|
||||||
pipelineCreateInfo.layout = layout;
|
pipelineCreateInfo.layout = layout;
|
||||||
pipelineCreateInfo.renderPass = renderPass;
|
pipelineCreateInfo.renderPass = renderPass;
|
||||||
pipelineCreateInfo.flags = flags;
|
pipelineCreateInfo.flags = flags;
|
||||||
|
pipelineCreateInfo.basePipelineIndex = -1;
|
||||||
|
pipelineCreateInfo.basePipelineHandle = VK_NULL_HANDLE;
|
||||||
return pipelineCreateInfo;
|
return pipelineCreateInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -720,19 +720,19 @@ public:
|
||||||
vks::initializers::descriptorImageInfo(
|
vks::initializers::descriptorImageInfo(
|
||||||
colorSampler,
|
colorSampler,
|
||||||
offScreenFrameBuf.position.view,
|
offScreenFrameBuf.position.view,
|
||||||
VK_IMAGE_LAYOUT_GENERAL);
|
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
|
||||||
|
|
||||||
VkDescriptorImageInfo texDescriptorNormal =
|
VkDescriptorImageInfo texDescriptorNormal =
|
||||||
vks::initializers::descriptorImageInfo(
|
vks::initializers::descriptorImageInfo(
|
||||||
colorSampler,
|
colorSampler,
|
||||||
offScreenFrameBuf.normal.view,
|
offScreenFrameBuf.normal.view,
|
||||||
VK_IMAGE_LAYOUT_GENERAL);
|
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
|
||||||
|
|
||||||
VkDescriptorImageInfo texDescriptorAlbedo =
|
VkDescriptorImageInfo texDescriptorAlbedo =
|
||||||
vks::initializers::descriptorImageInfo(
|
vks::initializers::descriptorImageInfo(
|
||||||
colorSampler,
|
colorSampler,
|
||||||
offScreenFrameBuf.albedo.view,
|
offScreenFrameBuf.albedo.view,
|
||||||
VK_IMAGE_LAYOUT_GENERAL);
|
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
|
||||||
|
|
||||||
writeDescriptorSets = {
|
writeDescriptorSets = {
|
||||||
// Binding 0 : Vertex shader uniform buffer
|
// Binding 0 : Vertex shader uniform buffer
|
||||||
|
|
|
||||||
|
|
@ -260,16 +260,6 @@ public:
|
||||||
|
|
||||||
// Create default renderpass for the framebuffer
|
// Create default renderpass for the framebuffer
|
||||||
VK_CHECK_RESULT(frameBuffers.shadow->createRenderPass());
|
VK_CHECK_RESULT(frameBuffers.shadow->createRenderPass());
|
||||||
|
|
||||||
VkCommandBuffer cmdBuf = vulkanDevice->createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true);
|
|
||||||
vks::tools::setImageLayout(
|
|
||||||
cmdBuf,
|
|
||||||
frameBuffers.shadow->attachments[0].image,
|
|
||||||
VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT,
|
|
||||||
VK_IMAGE_LAYOUT_UNDEFINED,
|
|
||||||
VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
|
|
||||||
frameBuffers.shadow->attachments[0].subresourceRange);
|
|
||||||
vulkanDevice->flushCommandBuffer(cmdBuf, queue);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepare the framebuffer for offscreen rendering with multiple attachments used as render targets inside the fragment shaders
|
// Prepare the framebuffer for offscreen rendering with multiple attachments used as render targets inside the fragment shaders
|
||||||
|
|
@ -710,7 +700,7 @@ public:
|
||||||
vks::initializers::descriptorImageInfo(
|
vks::initializers::descriptorImageInfo(
|
||||||
frameBuffers.shadow->sampler,
|
frameBuffers.shadow->sampler,
|
||||||
frameBuffers.shadow->attachments[0].view,
|
frameBuffers.shadow->attachments[0].view,
|
||||||
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
|
VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL);
|
||||||
|
|
||||||
writeDescriptorSets = {
|
writeDescriptorSets = {
|
||||||
// Binding 0: Vertex shader uniform buffer
|
// Binding 0: Vertex shader uniform buffer
|
||||||
|
|
|
||||||
|
|
@ -328,7 +328,7 @@ public:
|
||||||
attachmentDescs[i].storeOp = VK_ATTACHMENT_STORE_OP_STORE;
|
attachmentDescs[i].storeOp = VK_ATTACHMENT_STORE_OP_STORE;
|
||||||
attachmentDescs[i].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
attachmentDescs[i].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
||||||
attachmentDescs[i].stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
attachmentDescs[i].stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
||||||
attachmentDescs[i].finalLayout = (i == 3) ? VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL : VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
|
attachmentDescs[i].finalLayout = (i == 3) ? VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL : VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Formats
|
// Formats
|
||||||
|
|
@ -799,8 +799,8 @@ public:
|
||||||
descriptorAllocInfo.pSetLayouts = &descriptorSetLayouts.ssao;
|
descriptorAllocInfo.pSetLayouts = &descriptorSetLayouts.ssao;
|
||||||
VK_CHECK_RESULT(vkAllocateDescriptorSets(device, &descriptorAllocInfo, &descriptorSets.ssao));
|
VK_CHECK_RESULT(vkAllocateDescriptorSets(device, &descriptorAllocInfo, &descriptorSets.ssao));
|
||||||
imageDescriptors = {
|
imageDescriptors = {
|
||||||
vks::initializers::descriptorImageInfo(colorSampler, frameBuffers.offscreen.position.view, VK_IMAGE_LAYOUT_GENERAL),
|
vks::initializers::descriptorImageInfo(colorSampler, frameBuffers.offscreen.position.view, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL),
|
||||||
vks::initializers::descriptorImageInfo(colorSampler, frameBuffers.offscreen.normal.view, VK_IMAGE_LAYOUT_GENERAL),
|
vks::initializers::descriptorImageInfo(colorSampler, frameBuffers.offscreen.normal.view, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL),
|
||||||
};
|
};
|
||||||
writeDescriptorSets = {
|
writeDescriptorSets = {
|
||||||
vks::initializers::writeDescriptorSet(descriptorSets.ssao, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 0, &imageDescriptors[0]), // FS Position+Depth
|
vks::initializers::writeDescriptorSet(descriptorSets.ssao, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 0, &imageDescriptors[0]), // FS Position+Depth
|
||||||
|
|
@ -846,11 +846,11 @@ public:
|
||||||
descriptorAllocInfo.pSetLayouts = &descriptorSetLayouts.composition;
|
descriptorAllocInfo.pSetLayouts = &descriptorSetLayouts.composition;
|
||||||
VK_CHECK_RESULT(vkAllocateDescriptorSets(device, &descriptorAllocInfo, &descriptorSets.composition));
|
VK_CHECK_RESULT(vkAllocateDescriptorSets(device, &descriptorAllocInfo, &descriptorSets.composition));
|
||||||
imageDescriptors = {
|
imageDescriptors = {
|
||||||
vks::initializers::descriptorImageInfo(colorSampler, frameBuffers.offscreen.position.view, VK_IMAGE_LAYOUT_GENERAL),
|
vks::initializers::descriptorImageInfo(colorSampler, frameBuffers.offscreen.position.view, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL),
|
||||||
vks::initializers::descriptorImageInfo(colorSampler, frameBuffers.offscreen.normal.view, VK_IMAGE_LAYOUT_GENERAL),
|
vks::initializers::descriptorImageInfo(colorSampler, frameBuffers.offscreen.normal.view, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL),
|
||||||
vks::initializers::descriptorImageInfo(colorSampler, frameBuffers.offscreen.albedo.view, VK_IMAGE_LAYOUT_GENERAL),
|
vks::initializers::descriptorImageInfo(colorSampler, frameBuffers.offscreen.albedo.view, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL),
|
||||||
vks::initializers::descriptorImageInfo(colorSampler, frameBuffers.ssao.color.view, VK_IMAGE_LAYOUT_GENERAL),
|
vks::initializers::descriptorImageInfo(colorSampler, frameBuffers.ssao.color.view, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL),
|
||||||
vks::initializers::descriptorImageInfo(colorSampler, frameBuffers.ssaoBlur.color.view, VK_IMAGE_LAYOUT_GENERAL),
|
vks::initializers::descriptorImageInfo(colorSampler, frameBuffers.ssaoBlur.color.view, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL),
|
||||||
};
|
};
|
||||||
writeDescriptorSets = {
|
writeDescriptorSets = {
|
||||||
vks::initializers::writeDescriptorSet(descriptorSets.composition, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 0, &imageDescriptors[0]), // FS Sampler Position+Depth
|
vks::initializers::writeDescriptorSet(descriptorSets.composition, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 0, &imageDescriptors[0]), // FS Sampler Position+Depth
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue