Skip to content

Commit 9d072b3

Browse files
committed
Handle D24S8 copy for maintenance8 rules as well.
1 parent 9baacf7 commit 9d072b3

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

MoltenVK/MoltenVK/Commands/MVKCmdTransfer.mm

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,12 @@ static inline MTLSize mvkClampMTLSize(MTLSize size, MTLOrigin origin, MTLSize ma
103103
}
104104

105105
static inline MTLPixelFormat getDepthStencilAspectFormat(const MTLPixelFormat format, const VkImageAspectFlags aspectMask) {
106-
if (format == MTLPixelFormatDepth32Float_Stencil8) {
107-
if (aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) return MTLPixelFormatDepth32Float;
108-
if (aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) return MTLPixelFormatStencil8;
109-
}
106+
if (format == MTLPixelFormatDepth32Float_Stencil8 &&
107+
(aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT))
108+
return MTLPixelFormatDepth32Float;
109+
if ((format == MTLPixelFormatDepth32Float_Stencil8 || format == MTLPixelFormatDepth24Unorm_Stencil8) &&
110+
(aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT))
111+
return MTLPixelFormatStencil8;
110112
return format;
111113
}
112114

@@ -115,6 +117,7 @@ static inline MTLPixelFormat getDepthStencilAspectFormat(const MTLPixelFormat fo
115117
uint8_t srcPlaneIndex = MVKImage::getPlaneFromVkImageAspectFlags(region->srcSubresource.aspectMask);
116118
uint8_t dstPlaneIndex = MVKImage::getPlaneFromVkImageAspectFlags(region->dstSubresource.aspectMask);
117119

120+
// If the format is combined depth-stencil, use the format based on the aspect for the following checks.
118121
auto srcFormat = getDepthStencilAspectFormat(_srcImage->getMTLPixelFormat(srcPlaneIndex), region->srcSubresource.aspectMask);
119122
auto dstFormat = getDepthStencilAspectFormat(_dstImage->getMTLPixelFormat(dstPlaneIndex), region->dstSubresource.aspectMask);
120123

@@ -144,20 +147,20 @@ static inline MTLPixelFormat getDepthStencilAspectFormat(const MTLPixelFormat fo
144147

145148
MTLPixelFormat srcMTLPixFmt = _srcImage->getMTLPixelFormat(srcPlaneIndex);
146149
bool isSrcCompressed = _srcImage->getIsCompressed();
147-
bool isSrcCombinedDepthStencil = srcMTLPixFmt == MTLPixelFormatDepth32Float_Stencil8;
150+
bool isSrcCombinedDepthStencilAspect = getDepthStencilAspectFormat(srcMTLPixFmt, vkIC.srcSubresource.aspectMask) != srcMTLPixFmt;
148151
bool canReinterpretSrc = _srcImage->hasPixelFormatView(srcPlaneIndex);
149152

150153
MTLPixelFormat dstMTLPixFmt = _dstImage->getMTLPixelFormat(dstPlaneIndex);
151154
bool isDstCompressed = _dstImage->getIsCompressed();
152-
bool isDstCombinedDepthStencil = dstMTLPixFmt == MTLPixelFormatDepth32Float_Stencil8;
155+
bool isDstCombinedDepthStencilAspect = getDepthStencilAspectFormat(dstMTLPixFmt, vkIC.dstSubresource.aspectMask) != dstMTLPixFmt;
153156
bool canReinterpretDst = _dstImage->hasPixelFormatView(dstPlaneIndex);
154157

155158
bool isEitherCompressed = isSrcCompressed || isDstCompressed;
156-
bool isOneCombinedDepthStencil = isSrcCombinedDepthStencil != isDstCombinedDepthStencil;
159+
bool isOneCombinedDepthStencilAspect = isSrcCombinedDepthStencilAspect != isDstCombinedDepthStencilAspect;
157160
bool canReinterpret = canReinterpretSrc || canReinterpretDst;
158161

159162
// If source and destination can't be reinterpreted to matching formats use a temporary intermediary buffer
160-
bool useTempBuffer = (srcMTLPixFmt != dstMTLPixFmt) && (isEitherCompressed || isOneCombinedDepthStencil || !canReinterpret);
163+
bool useTempBuffer = (srcMTLPixFmt != dstMTLPixFmt) && (isEitherCompressed || isOneCombinedDepthStencilAspect || !canReinterpret);
161164

162165
if (useTempBuffer) {
163166
// Add copy from source image to temp buffer.

0 commit comments

Comments
 (0)