From 355e200a29d5fe63b7739b45a9127398bddef5ff Mon Sep 17 00:00:00 2001 From: Bill Hollings Date: Mon, 29 Jul 2019 15:52:24 -0400 Subject: [PATCH 1/2] Revert to supporting host-coherent memory for linear images on macOS. MVKImage::getMemoryRequirements() include host-coherent for linear images. Cube demo on macOS not use staging buffers for loading images. --- .../xcshareddata/xcschemes/API-Samples-macOS.xcscheme | 6 +++--- .../LunarG-VulkanSamples/Cube/macOS/DemoViewController.m | 7 ++----- Docs/Whats_New.md | 9 +++++++++ MoltenVK/MoltenVK/GPUObjects/MVKImage.mm | 6 ++++-- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/Demos/LunarG-VulkanSamples/API-Samples/API-Samples.xcodeproj/xcshareddata/xcschemes/API-Samples-macOS.xcscheme b/Demos/LunarG-VulkanSamples/API-Samples/API-Samples.xcodeproj/xcshareddata/xcschemes/API-Samples-macOS.xcscheme index f3506472..12f43fac 100644 --- a/Demos/LunarG-VulkanSamples/API-Samples/API-Samples.xcodeproj/xcshareddata/xcschemes/API-Samples-macOS.xcscheme +++ b/Demos/LunarG-VulkanSamples/API-Samples/API-Samples.xcodeproj/xcshareddata/xcschemes/API-Samples-macOS.xcscheme @@ -42,9 +42,9 @@ getPhysicalDevice()->getPrivateMemoryTypes() : _device->getPhysicalDevice()->getAllMemoryTypes()); #if MVK_MACOS - // Textures must not use shared memory - mvkDisableFlag(pMemoryRequirements->memoryTypeBits, _device->getPhysicalDevice()->getHostCoherentMemoryTypes()); + // Metal on macOS does not provide native support for host-coherent memory, but Vulkan requires it for Linear images + if ( !_isLinear ) { + mvkDisableFlag(pMemoryRequirements->memoryTypeBits, _device->getPhysicalDevice()->getHostCoherentMemoryTypes()); + } #endif #if MVK_IOS // Only transient attachments may use memoryless storage From c857014bb345399658dc23a1968151e6589cae6a Mon Sep 17 00:00:00 2001 From: Bill Hollings Date: Mon, 29 Jul 2019 17:50:42 -0400 Subject: [PATCH 2/2] Ensure Vulkan loader magic number persists in objects pooled by MoltenVK. MVKDispatchableVulkanAPIObject::getVkHandle() re-establishes the loader magic number before returning, in case the loader overwrote it before returning the object. --- Docs/Whats_New.md | 1 + .../MoltenVK/GPUObjects/MVKVulkanAPIObject.h | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Docs/Whats_New.md b/Docs/Whats_New.md index b8800318..50c5b0bf 100644 --- a/Docs/Whats_New.md +++ b/Docs/Whats_New.md @@ -19,6 +19,7 @@ MoltenVK 1.0.37 Released TBD - Revert to supporting host-coherent memory for linear images on macOS. +- Ensure Vulkan loader magic number is set every time before returning any dispatchable Vulkan handle. diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKVulkanAPIObject.h b/MoltenVK/MoltenVK/GPUObjects/MVKVulkanAPIObject.h index abf78635..8b3ada07 100644 --- a/MoltenVK/MoltenVK/GPUObjects/MVKVulkanAPIObject.h +++ b/MoltenVK/MoltenVK/GPUObjects/MVKVulkanAPIObject.h @@ -122,21 +122,30 @@ class MVKDispatchableVulkanAPIObject : public MVKVulkanAPIObject { public: /** - * Returns a reference to this object suitable for use as a Vulkan API handle. - * This is the compliment of the getDispatchableObject() method. + * Returns a reference to this object suitable for use as a dispatchable Vulkan API handle. + * + * Establishes the loader magic number every time, in case the loader + * overwrote it for some reason before passing the object back, + * particularly in pooled objects that the loader might consider freed. + * + * This is the compliment of the getDispatchableObject() function. */ - void* getVkHandle() override { return &_icdRef; } + void* getVkHandle() override { + set_loader_magic_value(&_icdRef); + return &_icdRef; + } /** * Retrieves the MVKDispatchableVulkanAPIObject instance referenced by the dispatchable Vulkan handle. - * This is the compliment of the getVkHandle() method. + * + * This is the compliment of the getVkHandle() function. */ static inline MVKDispatchableVulkanAPIObject* getDispatchableObject(void* vkHandle) { return vkHandle ? ((MVKDispatchableObjectICDRef*)vkHandle)->mvkObject : nullptr; } protected: - MVKDispatchableObjectICDRef _icdRef = { ICD_LOADER_MAGIC, this }; + MVKDispatchableObjectICDRef _icdRef = { VK_NULL_HANDLE, this }; };