Skip to content

Commit

Permalink
DeviceContextVkImpl::CopyTexture: validate that source and destinatio…
Browse files Browse the repository at this point in the history
…n aspect masks match
  • Loading branch information
TheMostDiligent committed Dec 2, 2023
1 parent 448e81e commit 9d94c3c
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2160,17 +2160,19 @@ void DeviceContextVkImpl::CopyTexture(const CopyTextureAttribs& CopyAttribs)
CopyRegion.extent.height = std::max(pSrcBox->Height(), 1u);
CopyRegion.extent.depth = std::max(pSrcBox->Depth(), 1u);

const auto& DstFmtAttribs = GetTextureFormatAttribs(DstTexDesc.Format);

VkImageAspectFlags aspectMask = 0;
if (DstFmtAttribs.ComponentType == COMPONENT_TYPE_DEPTH)
aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
else if (DstFmtAttribs.ComponentType == COMPONENT_TYPE_DEPTH_STENCIL)
{
aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
}
else
aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
auto GetAspectMak = [](TEXTURE_FORMAT Format) -> VkImageAspectFlags {
const auto& FmtAttribs = GetTextureFormatAttribs(Format);
switch (FmtAttribs.ComponentType)
{
// clang-format off
case COMPONENT_TYPE_DEPTH: return VK_IMAGE_ASPECT_DEPTH_BIT;
case COMPONENT_TYPE_DEPTH_STENCIL: return VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
// clang-format on
default: return VK_IMAGE_ASPECT_COLOR_BIT;
}
};
VkImageAspectFlags aspectMask = GetAspectMak(SrcTexDesc.Format);
DEV_CHECK_ERR(aspectMask == GetAspectMak(DstTexDesc.Format), "Vulkan spec requires that dst and src aspect masks must match");

CopyRegion.srcSubresource.baseArrayLayer = CopyAttribs.SrcSlice;
CopyRegion.srcSubresource.layerCount = 1;
Expand Down

0 comments on commit 9d94c3c

Please sign in to comment.