Skip to content

Commit fdda6ef

Browse files
VulkanTypeConversions: added ComponentTypeToVkAspectMask function
1 parent d9aec8a commit fdda6ef

File tree

4 files changed

+22
-19
lines changed

4 files changed

+22
-19
lines changed

Graphics/GraphicsEngineVulkan/include/VulkanTypeConversions.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,6 @@ VkComponentMapping TextureComponentMappingToVkComponentMapping(const TextureComp
129129
VkPipelineRenderingCreateInfoKHR GraphicsPipelineDesc_To_VkPipelineRenderingCreateInfo(const GraphicsPipelineDesc& PipelineDesc,
130130
std::vector<VkFormat>& ColorAttachmentFormats);
131131

132+
VkImageAspectFlags ComponentTypeToVkAspectMask(COMPONENT_TYPE ComponentType);
133+
132134
} // namespace Diligent

Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2332,14 +2332,7 @@ void DeviceContextVkImpl::CopyTexture(const CopyTextureAttribs& CopyAttribs)
23322332

23332333
auto GetAspectMak = [](TEXTURE_FORMAT Format) -> VkImageAspectFlags {
23342334
const TextureFormatAttribs& FmtAttribs = GetTextureFormatAttribs(Format);
2335-
switch (FmtAttribs.ComponentType)
2336-
{
2337-
// clang-format off
2338-
case COMPONENT_TYPE_DEPTH: return VK_IMAGE_ASPECT_DEPTH_BIT;
2339-
case COMPONENT_TYPE_DEPTH_STENCIL: return VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
2340-
// clang-format on
2341-
default: return VK_IMAGE_ASPECT_COLOR_BIT;
2342-
}
2335+
return ComponentTypeToVkAspectMask(FmtAttribs.ComponentType);
23432336
};
23442337
VkImageAspectFlags aspectMask = GetAspectMak(SrcTexDesc.Format);
23452338
DEV_CHECK_ERR(aspectMask == GetAspectMak(DstTexDesc.Format), "Vulkan spec requires that dst and src aspect masks must match");
@@ -2543,7 +2536,7 @@ static VkBufferImageCopy GetBufferImageCopyInfo(Uint64 BufferOffset,
25432536
// that is a (mostly) tightly packed representation of the depth or stencil data.
25442537
// To copy both the depth and stencil aspects of a depth/stencil format, two entries in
25452538
// pRegions can be used, where one specifies the depth aspect in imageSubresource, and the
2546-
// other specifies the stencil aspect (18.4)
2539+
// other specifies the stencil aspect.
25472540
}
25482541
else
25492542
CopyRegion.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
@@ -3020,7 +3013,7 @@ void DeviceContextVkImpl::TransitionTextureState(TextureVkImpl& Textur
30203013
{
30213014
// If image has a depth / stencil format with both depth and stencil components, then the
30223015
// aspectMask member of subresourceRange must include both VK_IMAGE_ASPECT_DEPTH_BIT and
3023-
// VK_IMAGE_ASPECT_STENCIL_BIT (6.7.3)
3016+
// VK_IMAGE_ASPECT_STENCIL_BIT
30243017
pSubresRange->aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
30253018
}
30263019
else
@@ -4083,14 +4076,7 @@ void DeviceContextVkImpl::BindSparseResourceMemory(const BindSparseResourceMemor
40834076
const TextureDesc& TexDesc = pTexVk->GetDesc();
40844077
const SparseTextureProperties& TexSparseProps = pTexVk->GetSparseProperties();
40854078
const TextureFormatAttribs& FmtAttribs = GetTextureFormatAttribs(TexDesc.Format);
4086-
4087-
VkImageAspectFlags aspectMask = 0;
4088-
if (FmtAttribs.ComponentType == COMPONENT_TYPE_DEPTH)
4089-
aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
4090-
else if (FmtAttribs.ComponentType == COMPONENT_TYPE_DEPTH_STENCIL)
4091-
aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
4092-
else
4093-
aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4079+
const VkImageAspectFlags aspectMask = ComponentTypeToVkAspectMask(FmtAttribs.ComponentType);
40944080

40954081
Uint32 NumImageBindsInRange = 0;
40964082
for (Uint32 r = 0; r < TexBind.NumRanges; ++r)

Graphics/GraphicsEngineVulkan/src/GenerateMipsVkHelper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ void GenerateMips(TextureViewVkImpl& TexView, DeviceContextVkImpl& Ctx)
7171
{
7272
// If image has a depth / stencil format with both depth and stencil components, then the
7373
// aspectMask member of subresourceRange must include both VK_IMAGE_ASPECT_DEPTH_BIT and
74-
// VK_IMAGE_ASPECT_STENCIL_BIT (6.7.3)
74+
// VK_IMAGE_ASPECT_STENCIL_BIT
7575
SubresRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
7676
}
7777
else

Graphics/GraphicsEngineVulkan/src/VulkanTypeConversions.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2253,4 +2253,19 @@ VkPipelineRenderingCreateInfoKHR GraphicsPipelineDesc_To_VkPipelineRenderingCrea
22532253
return PipelineRenderingCI;
22542254
}
22552255

2256+
VkImageAspectFlags ComponentTypeToVkAspectMask(COMPONENT_TYPE ComponentType)
2257+
{
2258+
switch (ComponentType)
2259+
{
2260+
case COMPONENT_TYPE_DEPTH:
2261+
return VK_IMAGE_ASPECT_DEPTH_BIT;
2262+
2263+
case COMPONENT_TYPE_DEPTH_STENCIL:
2264+
return VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
2265+
2266+
default:
2267+
return VK_IMAGE_ASPECT_COLOR_BIT;
2268+
}
2269+
}
2270+
22562271
} // namespace Diligent

0 commit comments

Comments
 (0)