Merge pull request #1179 from js6i/no_fast_math
Config: Added setting for fastMathEnabled Metal Compiler option.
diff --git a/MoltenVK/MoltenVK/API/vk_mvk_moltenvk.h b/MoltenVK/MoltenVK/API/vk_mvk_moltenvk.h
index 00c2420..9b667a7 100644
--- a/MoltenVK/MoltenVK/API/vk_mvk_moltenvk.h
+++ b/MoltenVK/MoltenVK/API/vk_mvk_moltenvk.h
@@ -558,6 +558,19 @@
*/
uint32_t defaultGPUCaptureScopeQueueIndex;
+ /**
+ * Corresponds to the fastMathEnabled property of MTLCompileOptions.
+ * Setting it may cause the Metal Compiler to optimize floating point operations
+ * in ways that may violate the IEEE 754 standard.
+ *
+ * Must be changed before creating a VkDevice, for the change to take effect.
+ *
+ * The initial value or this parameter is set by the
+ * MVK_CONFIG_FAST_MATH_ENABLED
+ * runtime environment variable or MoltenVK compile-time build setting.
+ * If neither is set, the value of this parameter defaults to false.
+ */
+ VkBool32 fastMathEnabled;
} MVKConfiguration;
/**
diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm b/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm
index 6b3d5c1..6545444 100644
--- a/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm
+++ b/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm
@@ -4086,6 +4086,7 @@
void MVKDevice::initMTLCompileOptions() {
_mtlCompileOptions = [MTLCompileOptions new]; // retained
_mtlCompileOptions.languageVersion = _pMetalFeatures->mslVersionEnum;
+ _mtlCompileOptions.fastMathEnabled = _pMVKConfig->fastMathEnabled;
}
MVKDevice::~MVKDevice() {
diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKInstance.mm b/MoltenVK/MoltenVK/GPUObjects/MVKInstance.mm
index 4c22b55..78efef5 100644
--- a/MoltenVK/MoltenVK/GPUObjects/MVKInstance.mm
+++ b/MoltenVK/MoltenVK/GPUObjects/MVKInstance.mm
@@ -710,6 +710,7 @@
MVK_SET_FROM_ENV_OR_BUILD_BOOL( _mvkConfig.fullImageViewSwizzle, MVK_CONFIG_FULL_IMAGE_VIEW_SWIZZLE);
MVK_SET_FROM_ENV_OR_BUILD_BOOL( _mvkConfig.defaultGPUCaptureScopeQueueFamilyIndex, MVK_CONFIG_DEFAULT_GPU_CAPTURE_SCOPE_QUEUE_FAMILY_INDEX);
MVK_SET_FROM_ENV_OR_BUILD_BOOL( _mvkConfig.defaultGPUCaptureScopeQueueIndex, MVK_CONFIG_DEFAULT_GPU_CAPTURE_SCOPE_QUEUE_INDEX);
+ MVK_SET_FROM_ENV_OR_BUILD_BOOL( _mvkConfig.fastMathEnabled, MVK_CONFIG_FAST_MATH_ENABLED);
MVK_SET_FROM_ENV_OR_BUILD_INT32(_autoGPUCaptureScope, MVK_CONFIG_AUTO_GPU_CAPTURE_SCOPE);
MVK_SET_FROM_ENV_OR_BUILD_STRING(_autoGPUCaptureOutputFile, MVK_CONFIG_AUTO_GPU_CAPTURE_OUTPUT_FILE);
diff --git a/MoltenVK/MoltenVK/Utility/MVKEnvironment.h b/MoltenVK/MoltenVK/Utility/MVKEnvironment.h
index 22905fd..63cc2eb 100644
--- a/MoltenVK/MoltenVK/Utility/MVKEnvironment.h
+++ b/MoltenVK/MoltenVK/Utility/MVKEnvironment.h
@@ -138,6 +138,11 @@
# define MVK_CONFIG_FULL_IMAGE_VIEW_SWIZZLE 0
#endif
+/** Set the fastMathEnabled Metal Compiler option. Disabled by default. */
+#ifndef MVK_CONFIG_FAST_MATH_ENABLED
+# define MVK_CONFIG_FAST_MATH_ENABLED 0
+#endif
+
/**
* The index of the queue family whose presentation submissions will
* be used as the default GPU Capture Scope during debugging in Xcode.