| 315 | } |
| 316 | |
| 317 | void VulkanBaseContext::ApplyFramebuffer(std::string const & framebufferLabel) |
| 318 | { |
| 319 | vkCmdSetStencilReference(m_renderingCommandBuffers[m_inflightFrameIndex], VK_STENCIL_FRONT_AND_BACK, |
| 320 | m_stencilReferenceValue); |
| 321 | |
| 322 | // Calculate attachment operations. |
| 323 | auto attachmentsOp = GetAttachmensOperations(); |
| 324 | if (m_currentFramebuffer == nullptr) |
| 325 | { |
| 326 | attachmentsOp.m_color.m_loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; |
| 327 | attachmentsOp.m_depth.m_loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; |
| 328 | attachmentsOp.m_stencil.m_loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; |
| 329 | attachmentsOp.m_stencil.m_storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; |
| 330 | } |
| 331 | auto const packedAttachmentOperations = PackAttachmentsOperations(attachmentsOp); |
| 332 | |
| 333 | // Destroy data associated with current framebuffer if bound attachments operations |
| 334 | // are changed. |
| 335 | auto const ops = m_framebuffersData[m_currentFramebuffer].m_packedAttachmentOperations; |
| 336 | if (ops != packedAttachmentOperations) |
| 337 | { |
| 338 | vkDeviceWaitIdle(m_device); |
| 339 | DestroyRenderPassAndFramebuffer(m_currentFramebuffer); |
| 340 | } |
| 341 | |
| 342 | // Initialize render pass. |
| 343 | auto & fbData = m_framebuffersData[m_currentFramebuffer]; |
| 344 | if (fbData.m_renderPass == VK_NULL_HANDLE) |
| 345 | { |
| 346 | VkFormat colorFormat = {}; |
| 347 | VkFormat depthFormat = {}; |
| 348 | |
| 349 | if (m_currentFramebuffer == nullptr) |
| 350 | { |
| 351 | colorFormat = m_surfaceFormat->format; |
| 352 | depthFormat = VulkanFormatUnpacker::Unpack(TextureFormat::Depth); |
| 353 | |
| 354 | fbData.m_packedAttachmentOperations = packedAttachmentOperations; |
| 355 | fbData.m_renderPass = |
| 356 | CreateRenderPass(2 /* attachmentsCount */, attachmentsOp, colorFormat, VK_IMAGE_LAYOUT_UNDEFINED, |
| 357 | VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, depthFormat, VK_IMAGE_LAYOUT_UNDEFINED, |
| 358 | VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL); |
| 359 | } |
| 360 | else |
| 361 | { |
| 362 | ref_ptr<dp::Framebuffer> framebuffer = m_currentFramebuffer; |
| 363 | auto const depthStencilRef = framebuffer->GetDepthStencilRef(); |
| 364 | auto const attachmentsCount = (depthStencilRef != nullptr) ? 2 : 1; |
| 365 | colorFormat = VulkanFormatUnpacker::Unpack(framebuffer->GetTexture()->GetFormat()); |
| 366 | VkImageLayout initialDepthStencilLayout = VK_IMAGE_LAYOUT_UNDEFINED; |
| 367 | if (depthStencilRef != nullptr) |
| 368 | { |
| 369 | depthFormat = VulkanFormatUnpacker::Unpack(depthStencilRef->GetTexture()->GetFormat()); |
| 370 | ASSERT(dynamic_cast<VulkanTexture *>(depthStencilRef->GetTexture()->GetHardwareTexture().get()) != nullptr, ()); |
| 371 | ref_ptr<VulkanTexture> depthStencilAttachment = depthStencilRef->GetTexture()->GetHardwareTexture(); |
| 372 | initialDepthStencilLayout = depthStencilAttachment->GetCurrentLayout(); |
| 373 | } |
| 374 |
nothing calls this directly
no test coverage detected