Skip to content

Commit

Permalink
igl | vulkan | Ensure proper image usage flags
Browse files Browse the repository at this point in the history
Summary: Ensure proper image usage flags for framebuffer attachments.

Reviewed By: pixelperfect3

Differential Revision: D49173842

fbshipit-source-id: 61aa780cc66598d38129edd7dae296edc7378110
  • Loading branch information
corporateshark authored and facebook-github-bot committed Sep 13, 2023
1 parent b983388 commit 0fc8158
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/igl/vulkan/CommandBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,14 @@ void transitionToColorAttachment(VkCommandBuffer buffer,
const auto& colorImg = vkTex.getVulkanTexture().getVulkanImage();
if (IGL_UNEXPECTED(colorImg.isDepthFormat_ || colorImg.isStencilFormat_)) {
IGL_ASSERT_MSG(false, "Color attachments cannot have depth/stencil formats");
IGL_LOG_ERROR("Color attachments cannot have depth/stencil formats");
return;
}
IGL_ASSERT_MSG(colorImg.imageFormat_ != VK_FORMAT_UNDEFINED, "Invalid color attachment format");
if (!IGL_VERIFY((colorImg.usageFlags_ & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) != 0)) {
IGL_ASSERT_MSG(false, "Did you forget to specify TextureUsageBit::Attachment usage bit?");
IGL_LOG_ERROR("Did you forget to specify TextureUsageBit::Attachment usage bit?");
}
colorImg.transitionLayout(
buffer,
VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
Expand Down
12 changes: 12 additions & 0 deletions src/igl/vulkan/Framebuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,24 @@ Framebuffer::Framebuffer(const Device& device, FramebufferDesc desc) :
for (const auto& attachment : desc_.colorAttachments) {
const auto& colorTexture = static_cast<vulkan::Texture&>(*attachment.second.texture);
ensureSize(colorTexture);
if (!IGL_VERIFY((colorTexture.getUsage() & TextureDesc::TextureUsageBits::Attachment) != 0)) {
IGL_ASSERT_MSG(
false, "Did you forget to specify TextureUsageBits::Attachment on your color texture?");
IGL_LOG_ERROR(
"Did you forget to specify TextureUsageBits::Attachment on your color texture?");
}
}

const auto* depthTexture = static_cast<vulkan::Texture*>(desc_.depthAttachment.texture.get());

if (depthTexture) {
ensureSize(*depthTexture);
if (!IGL_VERIFY((depthTexture->getUsage() & TextureDesc::TextureUsageBits::Attachment) != 0)) {
IGL_ASSERT_MSG(
false, "Did you forget to specify TextureUsageBits::Attachment on your depth texture?");
IGL_LOG_ERROR(
"Did you forget to specify TextureUsageBits::Attachment on your depth texture?");
}
}

IGL_ASSERT(width_);
Expand Down

0 comments on commit 0fc8158

Please sign in to comment.