| 141 | } |
| 142 | |
| 143 | void MSAASample::prepare_render_context() |
| 144 | { |
| 145 | get_render_context().prepare(1, std::bind(&MSAASample::create_render_target, this, std::placeholders::_1)); |
| 146 | } |
| 147 | |
| 148 | std::unique_ptr<vkb::rendering::RenderTargetC> MSAASample::create_render_target(vkb::core::Image &&swapchain_image) |
| 149 | { |
| 150 | auto &device = swapchain_image.get_device(); |
| 151 | auto &extent = swapchain_image.get_extent(); |
| 152 | |
| 153 | auto depth_format = vkb::get_suitable_depth_format(device.get_gpu().get_handle()); |
| 154 | bool msaa_enabled = sample_count != VK_SAMPLE_COUNT_1_BIT; |
| 155 | VkImageUsageFlags depth_usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; |
| 156 | VkImageUsageFlags depth_resolve_usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; |
| 157 | if (run_postprocessing) |
| 158 | { |
| 159 | // Depth needs to be read by the postprocessing subpass |
| 160 | if (msaa_enabled && depth_writeback_resolve_supported && resolve_depth_on_writeback) |
| 161 | { |
| 162 | // Depth is resolved |
| 163 | depth_usage |= VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT; |
| 164 | depth_resolve_usage |= VK_IMAGE_USAGE_SAMPLED_BIT; |
| 165 | } |
| 166 | else |
| 167 | { |
| 168 | // Postprocessing reads multisampled depth |
| 169 | depth_usage |= VK_IMAGE_USAGE_SAMPLED_BIT; |
| 170 | depth_resolve_usage |= VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT; |
| 171 | } |
| 172 | } |
| 173 | else |
| 174 | { |
| 175 | // Depth attachments are transient |
| 176 | depth_usage |= VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT; |
| 177 | depth_resolve_usage |= VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT; |
| 178 | } |
| 179 | |
| 180 | vkb::core::Image depth_image{device, |
| 181 | extent, |
| 182 | depth_format, |
| 183 | depth_usage, |
| 184 | VMA_MEMORY_USAGE_GPU_ONLY, |
| 185 | sample_count}; |
| 186 | |
| 187 | vkb::core::Image depth_resolve_image{device, |
| 188 | extent, |
| 189 | depth_format, |
| 190 | depth_resolve_usage, |
| 191 | VMA_MEMORY_USAGE_GPU_ONLY, |
| 192 | VK_SAMPLE_COUNT_1_BIT}; |
| 193 | |
| 194 | VkImageUsageFlags color_ms_usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 195 | if (ColorResolve::OnWriteback == color_resolve_method) |
| 196 | { |
| 197 | // Writeback resolve means that the multisampled attachment |
| 198 | // can be discarded at the end of the render pass |
| 199 | color_ms_usage |= VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT; |
| 200 | } |
nothing calls this directly
no test coverage detected