From e1b3585413152ff3f217a7412c2f7c95ae68cdf9 Mon Sep 17 00:00:00 2001 From: Bill Hollings Date: Thu, 21 Jan 2021 16:53:17 -0500 Subject: [PATCH] Add MVK_APPLE_SILICON macro definition. Use MVK_APPLE_SILICON instead of MVK_IOS_OR_TVOS || MVK_MACOS_APPLE_SILICON or MVK_MACOS_APPLE_SILICON || MVK_IOS_OR_TVOS. --- Common/MVKCommonEnvironment.h | 5 +++++ MoltenVK/MoltenVK/Commands/MVKCmdTransfer.mm | 2 +- MoltenVK/MoltenVK/GPUObjects/MVKBuffer.mm | 2 +- MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm | 4 ++-- MoltenVK/MoltenVK/GPUObjects/MVKDeviceMemory.h | 2 +- MoltenVK/MoltenVK/GPUObjects/MVKImage.mm | 6 +++--- MoltenVK/MoltenVK/GPUObjects/MVKPixelFormats.mm | 2 +- MoltenVK/MoltenVK/GPUObjects/MVKRenderPass.mm | 12 ++++++------ MoltenVK/MoltenVK/Vulkan/mvk_datatypes.mm | 2 +- 9 files changed, 21 insertions(+), 16 deletions(-) diff --git a/Common/MVKCommonEnvironment.h b/Common/MVKCommonEnvironment.h index 76fcc945..6d72a859 100644 --- a/Common/MVKCommonEnvironment.h +++ b/Common/MVKCommonEnvironment.h @@ -82,6 +82,11 @@ extern "C" { # define MVK_MACOS_APPLE_SILICON (__MAC_OS_X_VERSION_MAX_ALLOWED >= 101600) #endif +/** Building for Apple Silicon. */ +#ifndef MVK_APPLE_SILICON +# define MVK_APPLE_SILICON (MVK_IOS || MVK_TVOS || MVK_MACOS_APPLE_SILICON) +#endif + /** Building with Xcode 12. */ #ifndef MVK_XCODE_12 # define MVK_XCODE_12 (MVK_MACOS_APPLE_SILICON || \ diff --git a/MoltenVK/MoltenVK/Commands/MVKCmdTransfer.mm b/MoltenVK/MoltenVK/Commands/MVKCmdTransfer.mm index 8d97c790..e946072c 100644 --- a/MoltenVK/MoltenVK/Commands/MVKCmdTransfer.mm +++ b/MoltenVK/MoltenVK/Commands/MVKCmdTransfer.mm @@ -948,7 +948,7 @@ void MVKCmdBufferImageCopy::encode(MVKCommandEncoder* cmdEncoder) { } } -#if MVK_IOS_OR_TVOS || MVK_MACOS_APPLE_SILICON +#if MVK_APPLE_SILICON if (pixFmts->isPVRTCFormat(mtlPixFmt)) { blitOptions |= MTLBlitOptionRowLinearPVRTC; } diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKBuffer.mm b/MoltenVK/MoltenVK/GPUObjects/MVKBuffer.mm index f586a7e7..d37343e3 100644 --- a/MoltenVK/MoltenVK/GPUObjects/MVKBuffer.mm +++ b/MoltenVK/MoltenVK/GPUObjects/MVKBuffer.mm @@ -52,7 +52,7 @@ VkResult MVKBuffer::getMemoryRequirements(VkMemoryRequirements* pMemoryRequireme pMemoryRequirements->alignment = _byteAlignment; } pMemoryRequirements->memoryTypeBits = _device->getPhysicalDevice()->getAllMemoryTypes(); -#if MVK_IOS_OR_TVOS || MVK_MACOS_APPLE_SILICON +#if MVK_APPLE_SILICON // Memoryless storage is not allowed for buffers mvkDisableFlags(pMemoryRequirements->memoryTypeBits, _device->getPhysicalDevice()->getLazilyAllocatedMemoryTypes()); #endif diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm b/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm index 215a4d80..a11e858b 100644 --- a/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm +++ b/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm @@ -657,7 +657,7 @@ VkResult MVKPhysicalDevice::getImageFormatProperties(VkFormat format, return VK_ERROR_FORMAT_NOT_SUPPORTED; } #endif -#if MVK_IOS_OR_TVOS || MVK_MACOS_APPLE_SILICON +#if MVK_APPLE_SILICON // ETC2 and EAC formats aren't supported for 3D textures. switch (format) { case VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK: @@ -2998,7 +2998,7 @@ uint32_t MVKDevice::getVulkanMemoryTypeIndex(MTLStorageMode mtlStorageMode) { vkMemFlags = MVK_VK_MEMORY_TYPE_METAL_MANAGED; break; #endif -#if MVK_IOS_OR_TVOS || MVK_MACOS_APPLE_SILICON +#if MVK_APPLE_SILICON case MTLStorageModeMemoryless: vkMemFlags = MVK_VK_MEMORY_TYPE_METAL_MEMORYLESS; break; diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKDeviceMemory.h b/MoltenVK/MoltenVK/GPUObjects/MVKDeviceMemory.h index 3f64cc77..9040de03 100644 --- a/MoltenVK/MoltenVK/GPUObjects/MVKDeviceMemory.h +++ b/MoltenVK/MoltenVK/GPUObjects/MVKDeviceMemory.h @@ -52,7 +52,7 @@ public: /** Returns whether the memory is accessible from the host. */ inline bool isMemoryHostAccessible() { -#if MVK_IOS_OR_TVOS || MVK_MACOS_APPLE_SILICON +#if MVK_APPLE_SILICON if (_mtlStorageMode == MTLStorageModeMemoryless) return false; #endif diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKImage.mm b/MoltenVK/MoltenVK/GPUObjects/MVKImage.mm index 2c07932b..209a2513 100644 --- a/MoltenVK/MoltenVK/GPUObjects/MVKImage.mm +++ b/MoltenVK/MoltenVK/GPUObjects/MVKImage.mm @@ -647,7 +647,7 @@ VkResult MVKImage::getMemoryRequirements(VkMemoryRequirements* pMemoryRequiremen mvkDisableFlags(pMemoryRequirements->memoryTypeBits, _device->getPhysicalDevice()->getHostCoherentMemoryTypes()); } #endif -#if MVK_IOS_OR_TVOS || MVK_MACOS_APPLE_SILICON +#if MVK_APPLE_SILICON // Only transient attachments may use memoryless storage if (!mvkAreAllFlagsEnabled(_usage, VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT) ) { mvkDisableFlags(pMemoryRequirements->memoryTypeBits, _device->getPhysicalDevice()->getLazilyAllocatedMemoryTypes()); @@ -1668,7 +1668,7 @@ VkResult MVKImageView::validateSwizzledMTLPixelFormat(const VkImageViewCreateInf switch (mtlPixFmt) { case MTLPixelFormatR8Unorm: -#if MVK_MACOS_APPLE_SILICON || MVK_IOS_OR_TVOS +#if MVK_APPLE_SILICON case MTLPixelFormatR8Unorm_sRGB: #endif case MTLPixelFormatR8Snorm: @@ -1688,7 +1688,7 @@ VkResult MVKImageView::validateSwizzledMTLPixelFormat(const VkImageViewCreateInf break; case MTLPixelFormatRG8Unorm: -#if MVK_MACOS_APPLE_SILICON || MVK_IOS_OR_TVOS +#if MVK_APPLE_SILICON case MTLPixelFormatRG8Unorm_sRGB: #endif case MTLPixelFormatRG8Snorm: diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKPixelFormats.mm b/MoltenVK/MoltenVK/GPUObjects/MVKPixelFormats.mm index 1c0a1b7d..3c7fefc8 100644 --- a/MoltenVK/MoltenVK/GPUObjects/MVKPixelFormats.mm +++ b/MoltenVK/MoltenVK/GPUObjects/MVKPixelFormats.mm @@ -193,7 +193,7 @@ bool MVKPixelFormats::isStencilFormat(MTLPixelFormat mtlFormat) { bool MVKPixelFormats::isPVRTCFormat(MTLPixelFormat mtlFormat) { switch (mtlFormat) { -#if MVK_IOS_OR_TVOS || MVK_MACOS_APPLE_SILICON +#if MVK_APPLE_SILICON case MTLPixelFormatPVRTC_RGBA_2BPP: case MTLPixelFormatPVRTC_RGBA_2BPP_sRGB: case MTLPixelFormatPVRTC_RGBA_4BPP: diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKRenderPass.mm b/MoltenVK/MoltenVK/GPUObjects/MVKRenderPass.mm index c7e8d1c2..ff30e59e 100644 --- a/MoltenVK/MoltenVK/GPUObjects/MVKRenderPass.mm +++ b/MoltenVK/MoltenVK/GPUObjects/MVKRenderPass.mm @@ -211,7 +211,7 @@ void MVKRenderSubpass::populateMTLRenderPassDescriptor(MTLRenderPassDescriptor* MVKRenderPassAttachment* clrMVKRPAtt = &_renderPass->_attachments[clrRPAttIdx]; framebuffer->getAttachment(clrRPAttIdx)->populateMTLRenderPassAttachmentDescriptor(mtlColorAttDesc); bool isMemorylessAttachment = false; -#if MVK_IOS_OR_TVOS || MVK_MACOS_APPLE_SILICON +#if MVK_APPLE_SILICON isMemorylessAttachment = framebuffer->getAttachment(clrRPAttIdx)->getMTLTexture(0).storageMode == MTLStorageModeMemoryless; #endif if (clrMVKRPAtt->populateMTLRenderPassAttachmentDescriptor(mtlColorAttDesc, this, @@ -256,7 +256,7 @@ void MVKRenderSubpass::populateMTLRenderPassDescriptor(MTLRenderPassDescriptor* } dsImage->populateMTLRenderPassAttachmentDescriptor(mtlDepthAttDesc); bool isMemorylessAttachment = false; -#if MVK_IOS_OR_TVOS || MVK_MACOS_APPLE_SILICON +#if MVK_APPLE_SILICON isMemorylessAttachment = dsImage->getMTLTexture(0).storageMode == MTLStorageModeMemoryless; #endif if (dsMVKRPAtt->populateMTLRenderPassAttachmentDescriptor(mtlDepthAttDesc, this, @@ -284,7 +284,7 @@ void MVKRenderSubpass::populateMTLRenderPassDescriptor(MTLRenderPassDescriptor* } dsImage->populateMTLRenderPassAttachmentDescriptor(mtlStencilAttDesc); bool isMemorylessAttachment = false; -#if MVK_IOS_OR_TVOS || MVK_MACOS_APPLE_SILICON +#if MVK_APPLE_SILICON isMemorylessAttachment = dsImage->getMTLTexture(0).storageMode == MTLStorageModeMemoryless; #endif if (dsMVKRPAtt->populateMTLRenderPassAttachmentDescriptor(mtlStencilAttDesc, this, @@ -376,7 +376,7 @@ void MVKRenderSubpass::encodeStoreActions(MVKCommandEncoder* cmdEncoder, if (clrRPAttIdx != VK_ATTACHMENT_UNUSED) { bool hasResolveAttachment = _resolveAttachments.empty() ? false : _resolveAttachments[caIdx].attachment != VK_ATTACHMENT_UNUSED; bool isMemorylessAttachment = false; -#if MVK_IOS_OR_TVOS || MVK_MACOS_APPLE_SILICON +#if MVK_APPLE_SILICON isMemorylessAttachment = cmdEncoder->_framebuffer->getAttachment(clrRPAttIdx)->getMTLTexture(0).storageMode == MTLStorageModeMemoryless; #endif _renderPass->_attachments[clrRPAttIdx].encodeStoreAction(cmdEncoder, this, isRenderingEntireAttachment, isMemorylessAttachment, hasResolveAttachment, caIdx, false, storeOverride); @@ -388,7 +388,7 @@ void MVKRenderSubpass::encodeStoreActions(MVKCommandEncoder* cmdEncoder, bool hasDepthResolveAttachment = hasResolveAttachment && _depthResolveMode != VK_RESOLVE_MODE_NONE; bool hasStencilResolveAttachment = hasResolveAttachment && _stencilResolveMode != VK_RESOLVE_MODE_NONE; bool isMemorylessAttachment = false; -#if MVK_IOS_OR_TVOS || MVK_MACOS_APPLE_SILICON +#if MVK_APPLE_SILICON isMemorylessAttachment = cmdEncoder->_framebuffer->getAttachment(dsRPAttIdx)->getMTLTexture(0).storageMode == MTLStorageModeMemoryless; #endif _renderPass->_attachments[dsRPAttIdx].encodeStoreAction(cmdEncoder, this, isRenderingEntireAttachment, isMemorylessAttachment, hasDepthResolveAttachment, 0, false, storeOverride); @@ -783,7 +783,7 @@ MVKRenderPassAttachment::MVKRenderPassAttachment(MVKRenderPass* renderPass, #pragma mark MVKRenderPass VkExtent2D MVKRenderPass::getRenderAreaGranularity() { -#if MVK_IOS_OR_TVOS || MVK_MACOS_APPLE_SILICON +#if MVK_APPLE_SILICON if (_device->_pMetalFeatures->tileBasedDeferredRendering) { // This is the tile area. // FIXME: We really ought to use MTLRenderCommandEncoder.tile{Width,Height}, but that requires diff --git a/MoltenVK/MoltenVK/Vulkan/mvk_datatypes.mm b/MoltenVK/MoltenVK/Vulkan/mvk_datatypes.mm index f80f1050..9d5c19d2 100644 --- a/MoltenVK/MoltenVK/Vulkan/mvk_datatypes.mm +++ b/MoltenVK/MoltenVK/Vulkan/mvk_datatypes.mm @@ -736,7 +736,7 @@ MVK_PUBLIC_SYMBOL MTLStorageMode mvkMTLStorageModeFromVkMemoryPropertyFlags(VkMe // If not visible to the host: Private if ( !mvkAreAllFlagsEnabled(vkFlags, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) ) { -#if MVK_IOS_OR_TVOS || MVK_MACOS_APPLE_SILICON +#if MVK_APPLE_SILICON // iOS: If lazily allocated, Memoryless if (mvkAreAllFlagsEnabled(vkFlags, VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT)) { return MTLStorageModeMemoryless;