From 6947fdf57ee91ec015b28e08f8c98d5f0ed2dd06 Mon Sep 17 00:00:00 2001 From: Chip Davis Date: Tue, 11 Sep 2018 11:33:16 -0500 Subject: [PATCH] Only set MTLTextureUsagePixelFormatView on depth/stencil views... ...and only if the device supports stencil views. --- MoltenVK/MoltenVK/GPUObjects/MVKImage.h | 3 +++ MoltenVK/MoltenVK/GPUObjects/MVKImage.mm | 15 ++++++++++++++- MoltenVK/MoltenVK/Vulkan/mvk_datatypes.mm | 2 +- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKImage.h b/MoltenVK/MoltenVK/GPUObjects/MVKImage.h index 48e0e536..9c83a487 100644 --- a/MoltenVK/MoltenVK/GPUObjects/MVKImage.h +++ b/MoltenVK/MoltenVK/GPUObjects/MVKImage.h @@ -168,6 +168,9 @@ public: /** Returns the Metal texture type of this image. */ inline MTLTextureType getMTLTextureType() { return _mtlTextureType; } + /** Returns the Metal texture usage of this image. */ + MTLTextureUsage getMTLTextureUsage(); + /** * Returns whether the Metal texel size is the same as the Vulkan texel size. * diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKImage.mm b/MoltenVK/MoltenVK/GPUObjects/MVKImage.mm index 96f24e13..e8d914d2 100644 --- a/MoltenVK/MoltenVK/GPUObjects/MVKImage.mm +++ b/MoltenVK/MoltenVK/GPUObjects/MVKImage.mm @@ -327,6 +327,19 @@ VkResult MVKImage::useIOSurface(IOSurfaceRef ioSurface) { return VK_SUCCESS; } +MTLTextureUsage MVKImage::getMTLTextureUsage() { + MTLTextureUsage usage = mvkMTLTextureUsageFromVkImageUsageFlags(_usage); + // If this is a depth/stencil texture, and the device supports it, tell + // Metal we may create texture views of this, too. + if ((_mtlPixelFormat == MTLPixelFormatDepth32Float_Stencil8 +#if MVK_MACOS + || _mtlPixelFormat == MTLPixelFormatDepth24Unorm_Stencil8 +#endif + ) && _device->_pMetalFeatures->stencilViews) + mvkEnableFlag(usage, MTLTextureUsagePixelFormatView); + return usage; +} + // Returns an autoreleased Metal texture descriptor constructed from the properties of this image. MTLTextureDescriptor* MVKImage::getMTLTextureDescriptor() { MTLTextureDescriptor* mtlTexDesc = [[MTLTextureDescriptor alloc] init]; @@ -338,7 +351,7 @@ MTLTextureDescriptor* MVKImage::getMTLTextureDescriptor() { mtlTexDesc.mipmapLevelCount = _mipLevels; mtlTexDesc.sampleCount = mvkSampleCountFromVkSampleCountFlagBits(_samples); mtlTexDesc.arrayLength = _arrayLayers; - mtlTexDesc.usageMVK = mvkMTLTextureUsageFromVkImageUsageFlags(_usage); + mtlTexDesc.usageMVK = getMTLTextureUsage(); mtlTexDesc.storageModeMVK = getMTLStorageMode(); mtlTexDesc.cpuCacheMode = getMTLCPUCacheMode(); diff --git a/MoltenVK/MoltenVK/Vulkan/mvk_datatypes.mm b/MoltenVK/MoltenVK/Vulkan/mvk_datatypes.mm index 76b02599..3e67654a 100644 --- a/MoltenVK/MoltenVK/Vulkan/mvk_datatypes.mm +++ b/MoltenVK/MoltenVK/Vulkan/mvk_datatypes.mm @@ -759,7 +759,7 @@ MVK_PUBLIC_SYMBOL MTLTextureUsage mvkMTLTextureUsageFromVkImageUsageFlags(VkImag } if ( mvkAreFlagsEnabled(vkImageUsageFlags, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) ) { mvkEnableFlag(mtlUsage, MTLTextureUsageRenderTarget); - mvkEnableFlag(mtlUsage, MTLTextureUsagePixelFormatView); + mvkDisableFlag(mtlUsage, MTLTextureUsagePixelFormatView); // Clears bit. Do this last. } return mtlUsage;