From 0b6a5db0491ba10972f46223d4fc8fb5e639d3c1 Mon Sep 17 00:00:00 2001 From: Marko Pintera Date: Thu, 23 Jul 2020 15:02:26 +0200 Subject: [PATCH] Don't assign MTLTextureUsageRenderTarget to linear textures --- MoltenVK/MoltenVK/GPUObjects/MVKImage.h | 2 +- MoltenVK/MoltenVK/GPUObjects/MVKImage.mm | 2 +- MoltenVK/MoltenVK/GPUObjects/MVKPixelFormats.h | 4 +++- MoltenVK/MoltenVK/GPUObjects/MVKPixelFormats.mm | 11 +++++++++-- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKImage.h b/MoltenVK/MoltenVK/GPUObjects/MVKImage.h index 0d453737..c66efc41 100644 --- a/MoltenVK/MoltenVK/GPUObjects/MVKImage.h +++ b/MoltenVK/MoltenVK/GPUObjects/MVKImage.h @@ -312,7 +312,7 @@ public: * attempting to copy a depth image with a substituted format to and from a buffer. */ inline bool hasExpectedTexelSize() { return _hasExpectedTexelSize; } - + /** Returns the Metal resource options for this image. */ MTLStorageMode getMTLStorageMode(); diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKImage.mm b/MoltenVK/MoltenVK/GPUObjects/MVKImage.mm index 6efd58fa..07cf1a5f 100644 --- a/MoltenVK/MoltenVK/GPUObjects/MVKImage.mm +++ b/MoltenVK/MoltenVK/GPUObjects/MVKImage.mm @@ -120,7 +120,7 @@ MTLTextureDescriptor* MVKImagePlane::newMTLTextureDescriptor() { mtlTexDesc.mipmapLevelCount = _image->_mipLevels; mtlTexDesc.sampleCount = mvkSampleCountFromVkSampleCountFlagBits(_image->_samples); mtlTexDesc.arrayLength = _image->_arrayLayers; - mtlTexDesc.usageMVK = _image->getPixelFormats()->getMTLTextureUsage(_image->_usage, mtlPixFmt, minUsage); + mtlTexDesc.usageMVK = _image->getPixelFormats()->getMTLTextureUsage(_image->_usage, mtlPixFmt, minUsage, _image->_isLinear); mtlTexDesc.storageModeMVK = _image->getMTLStorageMode(); mtlTexDesc.cpuCacheMode = _image->getMTLCPUCacheMode(); diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKPixelFormats.h b/MoltenVK/MoltenVK/GPUObjects/MVKPixelFormats.h index cf49d8de..0c1a24c6 100644 --- a/MoltenVK/MoltenVK/GPUObjects/MVKPixelFormats.h +++ b/MoltenVK/MoltenVK/GPUObjects/MVKPixelFormats.h @@ -281,10 +281,12 @@ public: /** * Returns the Metal texture usage from the Vulkan image usage and Metal format, ensuring that at least the * usages in minUsage are included, even if they wouldn't naturally be included based on the other two parameters. + * isLinear further restricts the allowed usage to those that are valid for linear textures. */ MTLTextureUsage getMTLTextureUsage(VkImageUsageFlags vkImageUsageFlags, MTLPixelFormat mtlFormat, - MTLTextureUsage minUsage = MTLTextureUsageUnknown); + MTLTextureUsage minUsage = MTLTextureUsageUnknown, + bool isLinear = false); /** Enumerates all formats that support the given features, calling a specified function for each one. */ void enumerateSupportedFormats(VkFormatProperties properties, bool any, std::function func); diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKPixelFormats.mm b/MoltenVK/MoltenVK/GPUObjects/MVKPixelFormats.mm index aaa4147a..be97caf8 100644 --- a/MoltenVK/MoltenVK/GPUObjects/MVKPixelFormats.mm +++ b/MoltenVK/MoltenVK/GPUObjects/MVKPixelFormats.mm @@ -453,7 +453,8 @@ VkImageUsageFlags MVKPixelFormats::getVkImageUsageFlags(MTLTextureUsage mtlUsage MTLTextureUsage MVKPixelFormats::getMTLTextureUsage(VkImageUsageFlags vkImageUsageFlags, MTLPixelFormat mtlFormat, - MTLTextureUsage minUsage) { + MTLTextureUsage minUsage, + bool isLinear) { bool isDepthFmt = isDepthFormat(mtlFormat); bool isStencilFmt = isStencilFormat(mtlFormat); bool isCombinedDepthStencilFmt = isDepthFmt && isStencilFmt; @@ -484,7 +485,13 @@ MTLTextureUsage MVKPixelFormats::getMTLTextureUsage(VkImageUsageFlags vkImageUsa VK_IMAGE_USAGE_TRANSFER_DST_BIT)) && // Scaling a BLIT may use rendering. mvkIsAnyFlagEnabled(mtlFmtCaps, (kMVKMTLFmtCapsColorAtt | kMVKMTLFmtCapsDSAtt))) { - mvkEnableFlags(mtlUsage, MTLTextureUsageRenderTarget); +#if MVK_MACOS + if(!isLinear) { + mvkEnableFlags(mtlUsage, MTLTextureUsageRenderTarget); + } +#else + mvkEnableFlags(mtlUsage, MTLTextureUsageRenderTarget); +#endif } // Create view on, but only on color formats, or combined depth-stencil formats if supported by the GPU...