@@ -146,23 +146,30 @@ static inline MTLPixelFormat getDepthStencilAspectFormat(const MTLPixelFormat fo
146
146
147
147
uint8_t srcPlaneIndex = MVKImage::getPlaneFromVkImageAspectFlags (vkIC.srcSubresource .aspectMask );
148
148
uint8_t dstPlaneIndex = MVKImage::getPlaneFromVkImageAspectFlags (vkIC.dstSubresource .aspectMask );
149
-
149
+
150
+ uint32_t layerCount = vkIC.srcSubresource .layerCount == VK_REMAINING_ARRAY_LAYERS ?
151
+ _srcImage->getLayerCount () - vkIC.srcSubresource .baseArrayLayer :
152
+ vkIC.srcSubresource .layerCount ;
153
+
150
154
MTLPixelFormat srcMTLPixFmt = _srcImage->getMTLPixelFormat (srcPlaneIndex);
151
155
bool isSrcCompressed = _srcImage->getIsCompressed ();
156
+ bool isSrcColor = (vkIC.srcSubresource .aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) != 0 ;
152
157
bool isSrcCombinedDepthStencilAspect = getDepthStencilAspectFormat (srcMTLPixFmt, vkIC.srcSubresource .aspectMask ) != srcMTLPixFmt;
153
158
bool canReinterpretSrc = _srcImage->hasPixelFormatView (srcPlaneIndex);
154
159
155
160
MTLPixelFormat dstMTLPixFmt = _dstImage->getMTLPixelFormat (dstPlaneIndex);
156
161
bool isDstCompressed = _dstImage->getIsCompressed ();
162
+ bool isDstColor = (vkIC.dstSubresource .aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) != 0 ;
157
163
bool isDstCombinedDepthStencilAspect = getDepthStencilAspectFormat (dstMTLPixFmt, vkIC.dstSubresource .aspectMask ) != dstMTLPixFmt;
158
164
bool canReinterpretDst = _dstImage->hasPixelFormatView (dstPlaneIndex);
159
165
160
166
bool isEitherCompressed = isSrcCompressed || isDstCompressed;
161
- bool isOneCombinedDepthStencilAspect = isSrcCombinedDepthStencilAspect != isDstCombinedDepthStencilAspect;
167
+ bool isOnlyOneColor = isSrcColor != isDstColor;
168
+ bool isOnlyOneCombinedDepthStencilAspect = isSrcCombinedDepthStencilAspect != isDstCombinedDepthStencilAspect;
162
169
bool canReinterpret = canReinterpretSrc || canReinterpretDst;
163
170
164
171
// If source and destination can't be reinterpreted to matching formats use a temporary intermediary buffer
165
- bool useTempBuffer = (srcMTLPixFmt != dstMTLPixFmt) && (isEitherCompressed || isOneCombinedDepthStencilAspect || !canReinterpret);
172
+ bool useTempBuffer = (srcMTLPixFmt != dstMTLPixFmt) && (isEitherCompressed || isOnlyOneColor || isOnlyOneCombinedDepthStencilAspect || !canReinterpret);
166
173
167
174
if (useTempBuffer) {
168
175
// Add copy from source image to temp buffer.
@@ -201,7 +208,7 @@ static inline MTLPixelFormat getDepthStencilAspectFormat(const MTLPixelFormat fo
201
208
202
209
size_t bytesPerRow = pixFmts->getBytesPerRow (srcMTLPixFmt, vkIC.extent .width );
203
210
size_t bytesPerRegion = pixFmts->getBytesPerLayer (srcMTLPixFmt, bytesPerRow, vkIC.extent .height );
204
- tmpBuffSize += bytesPerRegion * vkIC.extent .depth ;
211
+ tmpBuffSize += bytesPerRegion * vkIC.extent .depth * layerCount ;
205
212
} else {
206
213
// Map the source pixel format to the dest pixel format through a texture view on the reinterpretable texture.
207
214
// If the source and dest pixel formats are the same, this will simply degenerate to the texture itself.
@@ -215,9 +222,6 @@ static inline MTLPixelFormat getDepthStencilAspectFormat(const MTLPixelFormat fo
215
222
// If copies can be performed using direct texture-texture copying, do so
216
223
uint32_t srcLevel = vkIC.srcSubresource .mipLevel ;
217
224
uint32_t srcBaseLayer = vkIC.srcSubresource .baseArrayLayer ;
218
- uint32_t srcLayerCount = vkIC.srcSubresource .layerCount == VK_REMAINING_ARRAY_LAYERS ?
219
- _srcImage->getLayerCount () - srcBaseLayer :
220
- vkIC.srcSubresource .layerCount ;
221
225
VkExtent3D srcExtent = _srcImage->getExtent3D (srcPlaneIndex, srcLevel);
222
226
uint32_t dstLevel = vkIC.dstSubresource .mipLevel ;
223
227
uint32_t dstBaseLayer = vkIC.dstSubresource .baseArrayLayer ;
@@ -233,7 +237,7 @@ static inline MTLPixelFormat getDepthStencilAspectFormat(const MTLPixelFormat fo
233
237
toTexture: dstMTLTex
234
238
destinationSlice: dstBaseLayer
235
239
destinationLevel: dstLevel
236
- sliceCount: srcLayerCount
240
+ sliceCount: layerCount
237
241
levelCount: 1 ];
238
242
} else {
239
243
MTLOrigin srcOrigin = mvkMTLOriginFromVkOffset3D (vkIC.srcOffset );
@@ -248,7 +252,7 @@ static inline MTLPixelFormat getDepthStencilAspectFormat(const MTLPixelFormat fo
248
252
mvkMTLSizeFromVkExtent3D (srcExtent));
249
253
srcSize.depth = 1 ;
250
254
} else {
251
- layCnt = srcLayerCount ;
255
+ layCnt = layerCount ;
252
256
srcSize = mvkClampMTLSize (mvkMTLSizeFromVkExtent3D (vkIC.extent ),
253
257
srcOrigin,
254
258
mvkMTLSizeFromVkExtent3D (srcExtent));
0 commit comments