From 75a088dbe05eb969d9fc424740133b0fd549177b Mon Sep 17 00:00:00 2001 From: Bill Hollings Date: Tue, 2 Apr 2019 00:40:57 -0400 Subject: [PATCH] API: Add MVKPhysicalDeviceMetalFeatures::depthSampleCompare. Set MTLSamplerDescriptor.compareFunction only if depthSampleCompare enabled. Update VK_MVK_MOLTENVK_SPEC_VERSION to 19. --- Docs/Whats_New.md | 5 ++++- MoltenVK/MoltenVK/API/vk_mvk_moltenvk.h | 3 ++- MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm | 2 ++ MoltenVK/MoltenVK/GPUObjects/MVKImage.mm | 12 +++++++++--- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/Docs/Whats_New.md b/Docs/Whats_New.md index 1619aa02..72bc1b48 100644 --- a/Docs/Whats_New.md +++ b/Docs/Whats_New.md @@ -25,6 +25,7 @@ Released TBD - Add support for tracking device features enabled during `vkCreateDevice()`. - Handle surface loss due to window moved between screens or a window style change. - Allow zero offset and stride combo in `VkVertexInputBindingDescription`. +- API: Add MVKPhysicalDeviceMetalFeatures::depthSampleCompare. - Fix conditions under which functions return `VK_INCOMPLETE`. - Fix potential memory leak on synchronous command buffer submission. - Increase shader float constant accuracy beyond 6 digits of precision. @@ -39,13 +40,15 @@ Released TBD - Fixed crash within `MVKPushConstantsCommandEncoderState` when accessing absent graphics pipeline during a compute stage. - Renderpass width/height clamped to the `renderArea` includes offset, not just the extent. -- Set options properly on a buffer view's MTLTextureDescriptor. +- Set options properly on a buffer view's `MTLTextureDescriptor`. +- Don't set `MTLSamplerDescriptor.compareFunction` on devices that don't support it. - Debug build mode includes `dSYM` file for each `dylib` file. - Explicitly build dSYM files in `BUILT_PRODUCTS_DIR` to avoid conflict between macOS and iOS build locations. - `Makefile` supports `install` target to install `MoltenVK.framework` into `/Library/Frameworks/`. Support Xcode 10.2. +- Update `VK_MVK_MOLTENVK_SPEC_VERSION` to 19. - Update to latest SPIRV-Cross version: - MSL: Add support for Metal 2 indirect argument buffers. - MSL: Add support for tessellation control & evaluation shaders. diff --git a/MoltenVK/MoltenVK/API/vk_mvk_moltenvk.h b/MoltenVK/MoltenVK/API/vk_mvk_moltenvk.h index 87f649be..5921a0c2 100644 --- a/MoltenVK/MoltenVK/API/vk_mvk_moltenvk.h +++ b/MoltenVK/MoltenVK/API/vk_mvk_moltenvk.h @@ -55,7 +55,7 @@ typedef unsigned long MTLLanguageVersion; #define MVK_MAKE_VERSION(major, minor, patch) (((major) * 10000) + ((minor) * 100) + (patch)) #define MVK_VERSION MVK_MAKE_VERSION(MVK_VERSION_MAJOR, MVK_VERSION_MINOR, MVK_VERSION_PATCH) -#define VK_MVK_MOLTENVK_SPEC_VERSION 18 +#define VK_MVK_MOLTENVK_SPEC_VERSION 19 #define VK_MVK_MOLTENVK_EXTENSION_NAME "VK_MVK_moltenvk" /** @@ -515,6 +515,7 @@ typedef struct { VkBool32 arrayOfTextures; /**< If true, arrays of textures is supported. */ VkBool32 arrayOfSamplers; /**< If true, arrays of texture samplers is supported. */ MTLLanguageVersion mslVersionEnum; /**< The version of the Metal Shading Language available on this device, as a Metal enumeration. */ + VkBool32 depthSampleCompare; /**< If true, depth texture samplers support the comparison of the pixel value against a reference value. */ } MVKPhysicalDeviceMetalFeatures; /** diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm b/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm index 2fe62042..ab095c40 100644 --- a/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm +++ b/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm @@ -742,6 +742,7 @@ void MVKPhysicalDevice::initMetalFeatures() { _metalFeatures.combinedStoreResolveAction = true; _metalFeatures.mtlBufferAlignment = 16; // Min float4 alignment for typical vertex buffers. MTLBuffer may go down to 4 bytes for other data. _metalFeatures.maxTextureDimension = (16 * KIBI); + _metalFeatures.depthSampleCompare = true; } if ( [_mtlDevice supportsFeatureSet: MTLFeatureSet_iOS_GPUFamily3_v2] ) { @@ -766,6 +767,7 @@ void MVKPhysicalDevice::initMetalFeatures() { _metalFeatures.baseVertexInstanceDrawing = true; _metalFeatures.layeredRendering = true; _metalFeatures.maxTextureDimension = (16 * KIBI); + _metalFeatures.depthSampleCompare = true; if ( [_mtlDevice supportsFeatureSet: MTLFeatureSet_macOS_GPUFamily1_v2] ) { _metalFeatures.mslVersionEnum = MTLLanguageVersion1_2; diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKImage.mm b/MoltenVK/MoltenVK/GPUObjects/MVKImage.mm index 46da11ee..fdadf9d9 100644 --- a/MoltenVK/MoltenVK/GPUObjects/MVKImage.mm +++ b/MoltenVK/MoltenVK/GPUObjects/MVKImage.mm @@ -993,9 +993,15 @@ MTLSamplerDescriptor* MVKSampler::getMTLSamplerDescriptor(const VkSamplerCreateI ? mvkClamp(pCreateInfo->maxAnisotropy, 1.0f, _device->_pProperties->limits.maxSamplerAnisotropy) : 1); mtlSampDesc.normalizedCoordinates = !pCreateInfo->unnormalizedCoordinates; - mtlSampDesc.compareFunctionMVK = (pCreateInfo->compareEnable - ? mvkMTLCompareFunctionFromVkCompareOp(pCreateInfo->compareOp) - : MTLCompareFunctionNever); + + if (pCreateInfo->compareEnable) { + if (_device->_pMetalFeatures->depthSampleCompare) { + mtlSampDesc.compareFunctionMVK = mvkMTLCompareFunctionFromVkCompareOp(pCreateInfo->compareOp); + } else { + setConfigurationResult(mvkNotifyErrorWithText(VK_ERROR_FEATURE_NOT_PRESENT, "vkCreateSampler(): Depth texture samplers do not support the comparison of the pixel value against a reference value.")); + } + } + #if MVK_MACOS mtlSampDesc.borderColorMVK = mvkMTLSamplerBorderColorFromVkBorderColor(pCreateInfo->borderColor); if (_device->getPhysicalDevice()->getMetalFeatures()->samplerClampToBorder) {