Add a configuration parameter to control the use of Metal SPIs.

With the new `MVK_CONFIG_USE_METAL_PRIVATE_API`, the user can prevent their
use at run time without recompiling MoltenVK. This may be useful for
troubleshooting purposes.

The extra member is because the compiler adds tail padding to make the
struct aligned on an 8-byte boundary, so the `static_assert()` fails
without it.
This commit is contained in:
Chip Davis 2023-12-29 04:42:17 -07:00
parent 622ab5ad8e
commit 06d493dcc1
7 changed files with 36 additions and 4 deletions

View File

@ -663,3 +663,16 @@ Determines the style used to implement _Vulkan_ semaphore (`VkSemaphore`) functi
In the special case of `VK_SEMAPHORE_TYPE_TIMELINE` semaphores, **MoltenVK** will always use
`MTLSharedEvent` if it is available on the platform, regardless of the value of this parameter.
---------------------------------------
#### MVK_CONFIG_USE_METAL_PRIVATE_API
##### Type: Boolean
##### Default: Value of `MVK_USE_METAL_PRIVATE_API`
If enabled, **MoltenVK** will _use_ private interfaces exposed by _Metal_ to implement _Vulkan_
features that are difficult to support otherwise.
Unlike `MVK_USE_METAL_PRIVATE_API`, this setting may be overridden at run time.
This option is not available unless MoltenVK were built with `MVK_USE_METAL_PRIVATE_API` set to `1`.

View File

@ -240,6 +240,8 @@ typedef struct {
MVKConfigCompressionAlgorithm shaderSourceCompressionAlgorithm; /**< MVK_CONFIG_SHADER_COMPRESSION_ALGORITHM */
VkBool32 shouldMaximizeConcurrentCompilation; /**< MVK_CONFIG_SHOULD_MAXIMIZE_CONCURRENT_COMPILATION */
float timestampPeriodLowPassAlpha; /**< MVK_CONFIG_TIMESTAMP_PERIOD_LOWPASS_ALPHA */
VkBool32 useMetalPrivateAPI; /**< MVK_CONFIG_USE_METAL_PRIVATE_API */
uint32_t _unused_struct_padding;
} MVKConfiguration;
// Legacy support for renamed struct elements.

View File

@ -2341,7 +2341,7 @@ void MVKPhysicalDevice::initFeatures() {
_features.depthBiasClamp = true;
_features.fillModeNonSolid = true;
_features.largePoints = true;
_features.wideLines = static_cast<bool>(MVK_USE_METAL_PRIVATE_API);
_features.wideLines = getMVKConfig().useMetalPrivateAPI;
_features.alphaToOne = true;
_features.samplerAnisotropy = true;
_features.shaderImageGatherExtended = true;

View File

@ -81,6 +81,8 @@ MVK_CONFIG_MEMBER(useMetalArgumentBuffers, MVKUseMetalArgumentBuf
MVK_CONFIG_MEMBER(shaderSourceCompressionAlgorithm, MVKConfigCompressionAlgorithm, SHADER_COMPRESSION_ALGORITHM)
MVK_CONFIG_MEMBER(shouldMaximizeConcurrentCompilation, VkBool32, SHOULD_MAXIMIZE_CONCURRENT_COMPILATION)
MVK_CONFIG_MEMBER(timestampPeriodLowPassAlpha, float, TIMESTAMP_PERIOD_LOWPASS_ALPHA)
MVK_CONFIG_MEMBER(useMetalPrivateAPI, VkBool32, USE_METAL_PRIVATE_API)
MVK_CONFIG_MEMBER(_unused_struct_padding, uint32_t, _UNUSED_STRUCT_PADDING)
#undef MVK_CONFIG_MEMBER
#undef MVK_CONFIG_MEMBER_STRING

View File

@ -66,6 +66,9 @@ void mvkSetConfig(MVKConfiguration& dstMVKConfig, const MVKConfiguration& srcMVK
// Clamp timestampPeriodLowPassAlpha between 0.0 and 1.0.
dstMVKConfig.timestampPeriodLowPassAlpha = mvkClamp(dstMVKConfig.timestampPeriodLowPassAlpha, 0.0f, 1.0f);
// Only allow useMetalPrivateAPI to be enabled if we were built with support for it.
dstMVKConfig.useMetalPrivateAPI = dstMVKConfig.useMetalPrivateAPI && MVK_USE_METAL_PRIVATE_API;
// For each string member of the destination MVKConfiguration, store the contents
// in a std::string, then repoint the member to the contents of the std::string.
#define MVK_CONFIG_MEMBER(member, mbrType, name)

View File

@ -348,3 +348,14 @@ void mvkSetConfig(MVKConfiguration& dstMVKConfig, const MVKConfiguration& srcMVK
#ifndef MVK_CONFIG_TIMESTAMP_PERIOD_LOWPASS_ALPHA
# define MVK_CONFIG_TIMESTAMP_PERIOD_LOWPASS_ALPHA 1.0
#endif
/**
* Enable the use of Metal private interfaces, also known as "Service Provider Interfaces" (SPIs),
* to support Vulkan features. Enabled by default if support is included.
*/
#ifndef MVK_CONFIG_USE_METAL_PRIVATE_API
# define MVK_CONFIG_USE_METAL_PRIVATE_API MVK_USE_METAL_PRIVATE_API
#endif
#undef MVK_CONFIG__UNUSED_STRUCT_PADDING
#define MVK_CONFIG__UNUSED_STRUCT_PADDING 0

View File

@ -317,9 +317,10 @@ _Vulkan_ API calls as function pointers.
<a name="metal_private_api"></a>
### Accessing _Metal_ Private API calls
You can optionally build **MoltenVK** with access to private _Metal_ API calls.
Doing so will allow **MoltenVK** to extend its functionality by using certain private _Metal_
API calls, but it will also disqualify the app from being distributed via _Apple_ App Stores.
You can optionally build **MoltenVK** with access to private _Metal_ API calls, also known
as "Service Provider Interfaces" (SPIs). Doing so will allow **MoltenVK** to extend its
functionality by using certain private _Metal_ API calls, but it will also disqualify the
app from being distributed via _Apple_ App Stores.
To do so, when building **MoltenVK**, set the build setting `MVK_USE_METAL_PRIVATE_API=1`.
This build setting can be set in the `MoltenVK.xcodeproj` *Xcode* project, or it can be