VkAttachmentReference2 *color_ptr = color_refs;
VkAttachmentReference2 *ds_ptr = depth_stencil_ref;
unsigned i = 0;
- auto fill_attachment = [=, &color_ptr, &ds_ptr, &i](FrameAttachment a, VkSampleCountFlagBits samples, bool discard){
+ auto fill_attachment = [=, &color_ptr, &ds_ptr, &i](FrameAttachment a, VkSampleCountFlagBits samples, bool force_discard){
VkImageLayout subpass_layout = static_cast<VkImageLayout>(get_vulkan_attachment_layout(get_components(get_attachment_pixelformat(a))));
VkImageLayout external_layout = (to_present ? VK_IMAGE_LAYOUT_PRESENT_SRC_KHR : subpass_layout);
attachments[i].sType = VK_STRUCTURE_TYPE_ATTACHMENT_DESCRIPTION_2;
attachments[i].format = static_cast<VkFormat>(get_vulkan_pixelformat(get_attachment_pixelformat(a)));
attachments[i].samples = samples;
- attachments[i].loadOp = (discard ? VK_ATTACHMENT_LOAD_OP_DONT_CARE : clear ? VK_ATTACHMENT_LOAD_OP_CLEAR : VK_ATTACHMENT_LOAD_OP_LOAD);
+ if(force_discard || (clear && !clear_values))
+ attachments[i].loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
+ else if(clear && clear_values)
+ attachments[i].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
+ else
+ attachments[i].loadOp = VK_ATTACHMENT_LOAD_OP_LOAD;
attachments[i].storeOp = VK_ATTACHMENT_STORE_OP_STORE;
attachments[i].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_LOAD;
attachments[i].stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
- attachments[i].initialLayout = (discard ? VK_IMAGE_LAYOUT_UNDEFINED : external_layout);
+ if(force_discard || discard_fb_contents)
+ attachments[i].initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
+ else
+ attachments[i].initialLayout = external_layout;
attachments[i].finalLayout = external_layout;
if(subpass_layout==VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)
++i;
};
- bool discard = (clear && !clear_values && discard_fb_contents);
VkSampleCountFlagBits vk_samples = static_cast<VkSampleCountFlagBits>(get_vulkan_samples(format.get_samples()));
for(FrameAttachment a: format)
- fill_attachment(a, vk_samples, discard);
+ fill_attachment(a, vk_samples, false);
if(resolve)
{