diff --git a/Docs/Whats_New.md b/Docs/Whats_New.md index 310d84cb..62a48bb1 100644 --- a/Docs/Whats_New.md +++ b/Docs/Whats_New.md @@ -21,6 +21,7 @@ Released TBD - Add `MVK_USE_METAL_PRIVATE_API` build setting to allow **MoltenVK** to be built with access to _Metal_ private API calls. - Add support for `VkPhysicalDeviceFeatures::wideLines` feature when `MVK_USE_METAL_PRIVATE_API` is enabled in a **MoltenVK** build. - Add support for the `VkPhysicalDeviceFeatures::logicOp` feature when `MVK_USE_METAL_PRIVATE_API` is enabled in a **MoltenVK** build. +- Add support for the `VkPhysicalDevicePortabilitySubsetFeaturesKHR::samplerMipLodBias` feature when `MVK_USE_METAL_PRIVATE_API` is enabled in a **MoltenVK** build. - Fix potential crash when using multi-planar images. - Ensure buffers available for buffer addresses in push constants. - Support `libMoltenVK.dylib` for _iOS Simulator_ architecture. diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm b/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm index 9dbdf29a..cbb8d566 100644 --- a/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm +++ b/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm @@ -366,7 +366,7 @@ void MVKPhysicalDevice::getFeatures(VkPhysicalDeviceFeatures2* features) { portabilityFeatures->multisampleArrayImage = _metalFeatures.multisampleArrayTextures; portabilityFeatures->mutableComparisonSamplers = _metalFeatures.depthSampleCompare; portabilityFeatures->pointPolygons = false; - portabilityFeatures->samplerMipLodBias = false; + portabilityFeatures->samplerMipLodBias = getMVKConfig().useMetalPrivateAPI; portabilityFeatures->separateStencilMaskRef = true; portabilityFeatures->shaderSampleRateInterpolationFunctions = _metalFeatures.pullModelInterpolation; portabilityFeatures->tessellationIsolines = false; @@ -2523,6 +2523,10 @@ void MVKPhysicalDevice::initLimits() { _properties.limits.maxImageDimension3D = _metalFeatures.maxTextureLayers; _properties.limits.maxImageArrayLayers = _metalFeatures.maxTextureLayers; + // Max sum of API and shader values. Bias not publicly supported in API, but can be applied in the shader directly. + // The lack of API value is covered by VkPhysicalDevicePortabilitySubsetFeaturesKHR::samplerMipLodBias. + // Metal does not specify a limit for the shader value, so choose something reasonable. + _properties.limits.maxSamplerLodBias = getMVKConfig().useMetalPrivateAPI ? 16 : 4; _properties.limits.maxSamplerAnisotropy = 16; _properties.limits.maxVertexInputAttributes = 31; @@ -2799,11 +2803,6 @@ void MVKPhysicalDevice::initLimits() { #endif } - // Max sum of API and shader values. Bias not supported in API, but can be applied in shader directly. - // The lack of API value is covered by VkPhysicalDevicePortabilitySubsetFeaturesKHR::samplerMipLodBias. - // Metal does not specify limit for shader value, so choose something reasonable. - _properties.limits.maxSamplerLodBias = 4; - _properties.limits.minTexelOffset = -8; _properties.limits.maxTexelOffset = 7; _properties.limits.minTexelGatherOffset = _properties.limits.minTexelOffset; diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKImage.mm b/MoltenVK/MoltenVK/GPUObjects/MVKImage.mm index 6fb3be5b..08541c74 100644 --- a/MoltenVK/MoltenVK/GPUObjects/MVKImage.mm +++ b/MoltenVK/MoltenVK/GPUObjects/MVKImage.mm @@ -2198,6 +2198,11 @@ MTLSamplerDescriptor* MVKSampler::newMTLSamplerDescriptor(const VkSamplerCreateI mtlSampDesc.mipFilter = (pCreateInfo->unnormalizedCoordinates ? MTLSamplerMipFilterNotMipmapped : mvkMTLSamplerMipFilterFromVkSamplerMipmapMode(pCreateInfo->mipmapMode)); +#if MVK_USE_METAL_PRIVATE_API + if (getMVKConfig().useMetalPrivateAPI) { + mtlSampDesc.lodBiasMVK = pCreateInfo->mipLodBias; + } +#endif mtlSampDesc.lodMinClamp = pCreateInfo->minLod; mtlSampDesc.lodMaxClamp = pCreateInfo->maxLod; mtlSampDesc.maxAnisotropy = (pCreateInfo->anisotropyEnable diff --git a/MoltenVK/MoltenVK/OS/MTLSamplerDescriptor+MoltenVK.h b/MoltenVK/MoltenVK/OS/MTLSamplerDescriptor+MoltenVK.h index 39c87231..09055bc9 100644 --- a/MoltenVK/MoltenVK/OS/MTLSamplerDescriptor+MoltenVK.h +++ b/MoltenVK/MoltenVK/OS/MTLSamplerDescriptor+MoltenVK.h @@ -41,4 +41,13 @@ */ @property(nonatomic, readwrite) /*MTLSamplerBorderColor*/ NSUInteger borderColorMVK; +/** + * Replacement for the lodBias property. + * + * This property allows support under all OS versions. Delegates to the lodBias + * property if it is available. otherwise, returns 0 when read and + * does nothing when set. + */ +@property(nonatomic, readwrite) float lodBiasMVK; + @end diff --git a/MoltenVK/MoltenVK/OS/MTLSamplerDescriptor+MoltenVK.m b/MoltenVK/MoltenVK/OS/MTLSamplerDescriptor+MoltenVK.m index 1ffd51ab..20805c55 100644 --- a/MoltenVK/MoltenVK/OS/MTLSamplerDescriptor+MoltenVK.m +++ b/MoltenVK/MoltenVK/OS/MTLSamplerDescriptor+MoltenVK.m @@ -21,6 +21,15 @@ #include "MVKCommonEnvironment.h" +#if MVK_USE_METAL_PRIVATE_API +/** Additional methods not necessarily declared in . */ +@interface MTLSamplerDescriptor () + +@property(nonatomic, readwrite) float lodBias; + +@end +#endif + @implementation MTLSamplerDescriptor (MoltenVK) -(MTLCompareFunction) compareFunctionMVK { @@ -45,4 +54,15 @@ #endif } +#if MVK_USE_METAL_PRIVATE_API +-(float) lodBiasMVK { + if ( [self respondsToSelector: @selector(lodBias)] ) { return self.lodBias; } + return 0.0f; +} + +-(void) setLodBiasMVK: (float) bias { + if ( [self respondsToSelector: @selector(setLodBias:)] ) { self.lodBias = bias; } +} +#endif + @end diff --git a/README.md b/README.md index 9bf87cac..ac63c460 100644 --- a/README.md +++ b/README.md @@ -329,6 +329,7 @@ included in any of the `make` command-line build commands [mentioned above](#com Functionality added with `MVK_USE_METAL_PRIVATE_API` enabled includes: - `VkPhysicalDeviceFeatures::wideLines` - `VkPhysicalDeviceFeatures::logicOp` +- `VkPhysicalDevicePortabilitySubsetFeaturesKHR::samplerMipLodBias`