| 54 | } |
| 55 | |
| 56 | FramebufferHandle Device::createFramebuffer(const FramebufferDesc& desc) |
| 57 | { |
| 58 | Framebuffer *fb = new Framebuffer(); |
| 59 | fb->desc = desc; |
| 60 | fb->framebufferInfo = FramebufferInfoEx(desc); |
| 61 | |
| 62 | for(uint32_t i = 0; i < desc.colorAttachments.size(); i++) |
| 63 | { |
| 64 | const auto& rt = desc.colorAttachments[i]; |
| 65 | Texture* t = checked_cast<Texture*>(rt.texture); |
| 66 | |
| 67 | assert(fb->framebufferInfo.width == std::max(t->desc.width >> rt.subresources.baseMipLevel, 1u)); |
| 68 | assert(fb->framebufferInfo.height == std::max(t->desc.height >> rt.subresources.baseMipLevel, 1u)); |
| 69 | |
| 70 | TextureSubresourceSet subresources = rt.subresources.resolve(t->desc, true); |
| 71 | |
| 72 | TextureDimension dimension = getDimensionForFramebuffer(t->desc.dimension, subresources.numArraySlices > 1); |
| 73 | |
| 74 | const auto& view = t->getSubresourceView(subresources, dimension, rt.format, vk::ImageUsageFlagBits::eColorAttachment); |
| 75 | |
| 76 | vk::RenderingAttachmentInfo& attachmentInfo = fb->colorAttachments.emplace_back(); |
| 77 | attachmentInfo = vk::RenderingAttachmentInfo() |
| 78 | .setImageView(view.view) |
| 79 | .setImageLayout(vk::ImageLayout::eColorAttachmentOptimal) |
| 80 | .setLoadOp(vk::AttachmentLoadOp::eLoad) |
| 81 | .setStoreOp(vk::AttachmentStoreOp::eStore); |
| 82 | |
| 83 | fb->resources.push_back(rt.texture); |
| 84 | } |
| 85 | |
| 86 | // add depth/stencil attachment if present |
| 87 | if (desc.depthAttachment.valid()) |
| 88 | { |
| 89 | const auto& att = desc.depthAttachment; |
| 90 | |
| 91 | Texture* texture = checked_cast<Texture*>(att.texture); |
| 92 | |
| 93 | assert(fb->framebufferInfo.width == std::max(texture->desc.width >> att.subresources.baseMipLevel, 1u)); |
| 94 | assert(fb->framebufferInfo.height == std::max(texture->desc.height >> att.subresources.baseMipLevel, 1u)); |
| 95 | |
| 96 | vk::ImageLayout depthLayout = vk::ImageLayout::eDepthStencilAttachmentOptimal; |
| 97 | if (desc.depthAttachment.isReadOnly) |
| 98 | { |
| 99 | depthLayout = vk::ImageLayout::eDepthStencilReadOnlyOptimal; |
| 100 | } |
| 101 | |
| 102 | TextureSubresourceSet subresources = att.subresources.resolve(texture->desc, true); |
| 103 | |
| 104 | TextureDimension dimension = getDimensionForFramebuffer(texture->desc.dimension, subresources.numArraySlices > 1); |
| 105 | |
| 106 | const auto& view = texture->getSubresourceView(subresources, dimension, att.format, vk::ImageUsageFlagBits::eDepthStencilAttachment); |
| 107 | |
| 108 | fb->depthAttachment = vk::RenderingAttachmentInfo() |
| 109 | .setImageView(view.view) |
| 110 | .setImageLayout(depthLayout) |
| 111 | .setLoadOp(vk::AttachmentLoadOp::eLoad) |
| 112 | .setStoreOp(vk::AttachmentStoreOp::eStore); |
| 113 |
nothing calls this directly
no test coverage detected