MVKCmdBufferImageCopy don't supply bytes per image if not array texture.
MVKRPSKeyBlitImg::isArrayType() include multisample array type.
Clean up formatting in texture type functions in mvk_datatypes.mm.
diff --git a/Docs/Whats_New.md b/Docs/Whats_New.md
index 74e9250..6ecb7c0 100644
--- a/Docs/Whats_New.md
+++ b/Docs/Whats_New.md
@@ -32,6 +32,7 @@
- Fix race condition between swapchain image destruction and presentation completion callback.
- Set Metal texture usage to allow texture copy via view.
- `vkCmdCopyImage()` validate that formats are compatible for copying.
+- `vkCmdBufferImageCopy()` fix crash when setting bytes per image in non-arrayed images.
- Document that the functions in `vk_mvk_moltenvk.h` cannot be used with objects
retrieved through the *Vulkan SDK Loader and Layers* framework.
- Update `VK_MVK_MOLTENVK_SPEC_VERSION` to 21.
diff --git a/MoltenVK/MoltenVK/Commands/MVKCmdTransfer.h b/MoltenVK/MoltenVK/Commands/MVKCmdTransfer.h
index 72524e0..53b29d6 100644
--- a/MoltenVK/MoltenVK/Commands/MVKCmdTransfer.h
+++ b/MoltenVK/MoltenVK/Commands/MVKCmdTransfer.h
@@ -213,6 +213,8 @@
MVKCommand::MVKCommand((MVKCommandTypePool<MVKCommand>*)pool) {}
protected:
+ bool isArrayTexture();
+
MVKBuffer* _buffer;
MVKImage* _image;
VkImageLayout _imageLayout;
diff --git a/MoltenVK/MoltenVK/Commands/MVKCmdTransfer.mm b/MoltenVK/MoltenVK/Commands/MVKCmdTransfer.mm
index d08aaf3..4973d70 100644
--- a/MoltenVK/MoltenVK/Commands/MVKCmdTransfer.mm
+++ b/MoltenVK/MoltenVK/Commands/MVKCmdTransfer.mm
@@ -790,6 +790,10 @@
if (!needsTempBuff) { continue; }
}
#endif
+
+ // Don't supply bytes per image if not an arrayed texture
+ if ( !isArrayTexture() ) { bytesPerImg = 0; }
+
id<MTLBlitCommandEncoder> mtlBlitEnc = cmdEncoder->getMTLBlitEncoder(cmdUse);
for (uint32_t lyrIdx = 0; lyrIdx < cpyRgn.imageSubresource.layerCount; lyrIdx++) {
@@ -820,6 +824,16 @@
}
}
+bool MVKCmdBufferImageCopy::isArrayTexture() {
+ MTLTextureType mtlTexType = _image->getMTLTextureType();
+ return (mtlTexType == MTLTextureType3D ||
+ mtlTexType == MTLTextureType2DArray ||
+#if MVK_MACOS
+ mtlTexType == MTLTextureType2DMultisampleArray ||
+#endif
+ mtlTexType == MTLTextureType1DArray);
+}
+
#pragma mark -
#pragma mark MVKCmdClearAttachments
diff --git a/MoltenVK/MoltenVK/Commands/MVKCommandResourceFactory.h b/MoltenVK/MoltenVK/Commands/MVKCommandResourceFactory.h
index 55bef82..21de8ea 100644
--- a/MoltenVK/MoltenVK/Commands/MVKCommandResourceFactory.h
+++ b/MoltenVK/MoltenVK/Commands/MVKCommandResourceFactory.h
@@ -48,7 +48,12 @@
inline MTLTextureType getMTLTextureType() { return (MTLTextureType)mtlTexType; }
- inline bool isArrayType() { return (mtlTexType == MTLTextureType2DArray) || (mtlTexType == MTLTextureType1DArray); }
+ inline bool isArrayType() {
+ return (mtlTexType == MTLTextureType2DArray ||
+#if MVK_MACOS
+ mtlTexType == MTLTextureType2DMultisampleArray ||
+#endif
+ mtlTexType == MTLTextureType1DArray); }
std::size_t hash() const {
std::size_t hash = mtlTexType;
diff --git a/MoltenVK/MoltenVK/Vulkan/mvk_datatypes.mm b/MoltenVK/MoltenVK/Vulkan/mvk_datatypes.mm
index dceb9a3..4e4390e 100644
--- a/MoltenVK/MoltenVK/Vulkan/mvk_datatypes.mm
+++ b/MoltenVK/MoltenVK/Vulkan/mvk_datatypes.mm
@@ -809,32 +809,33 @@
}
MVK_PUBLIC_SYMBOL VkImageType mvkVkImageTypeFromMTLTextureType(MTLTextureType mtlTextureType) {
- switch (mtlTextureType) {
- case MTLTextureType1D: return VK_IMAGE_TYPE_1D;
- case MTLTextureType1DArray: return VK_IMAGE_TYPE_1D;
- case MTLTextureType3D: return VK_IMAGE_TYPE_3D;
- default: return VK_IMAGE_TYPE_2D;
- }
+ switch (mtlTextureType) {
+ case MTLTextureType1D:
+ case MTLTextureType1DArray:
+ return VK_IMAGE_TYPE_1D;
+ case MTLTextureType3D:
+ return VK_IMAGE_TYPE_3D;
+ default:
+ return VK_IMAGE_TYPE_2D;
+ }
}
MVK_PUBLIC_SYMBOL MTLTextureType mvkMTLTextureTypeFromVkImageViewType(VkImageViewType vkImageViewType,
- bool isMultisample) {
- switch (vkImageViewType) {
- case VK_IMAGE_VIEW_TYPE_1D: return MTLTextureType1D;
- case VK_IMAGE_VIEW_TYPE_1D_ARRAY: return MTLTextureType1DArray;
- case VK_IMAGE_VIEW_TYPE_2D: return (isMultisample ? MTLTextureType2DMultisample : MTLTextureType2D);
- case VK_IMAGE_VIEW_TYPE_2D_ARRAY:
+ bool isMultisample) {
+ switch (vkImageViewType) {
+ case VK_IMAGE_VIEW_TYPE_1D: return MTLTextureType1D;
+ case VK_IMAGE_VIEW_TYPE_1D_ARRAY: return MTLTextureType1DArray;
+ case VK_IMAGE_VIEW_TYPE_2D: return (isMultisample ? MTLTextureType2DMultisample : MTLTextureType2D);
+ case VK_IMAGE_VIEW_TYPE_2D_ARRAY:
#if MVK_MACOS
- if (isMultisample) {
- return MTLTextureType2DMultisampleArray;
- }
+ if (isMultisample) { return MTLTextureType2DMultisampleArray; }
#endif
- return MTLTextureType2DArray;
- case VK_IMAGE_VIEW_TYPE_3D: return MTLTextureType3D;
- case VK_IMAGE_VIEW_TYPE_CUBE: return MTLTextureTypeCube;
- case VK_IMAGE_VIEW_TYPE_CUBE_ARRAY: return MTLTextureTypeCubeArray;
- default: return MTLTextureType2D;
- }
+ return MTLTextureType2DArray;
+ case VK_IMAGE_VIEW_TYPE_3D: return MTLTextureType3D;
+ case VK_IMAGE_VIEW_TYPE_CUBE: return MTLTextureTypeCube;
+ case VK_IMAGE_VIEW_TYPE_CUBE_ARRAY: return MTLTextureTypeCubeArray;
+ default: return MTLTextureType2D;
+ }
}
MVK_PUBLIC_SYMBOL MTLTextureUsage mvkMTLTextureUsageFromVkImageUsageFlags(VkImageUsageFlags vkImageUsageFlags) {