From 2f0f850da8aab8ce4e5cde2e83f91421e559456d Mon Sep 17 00:00:00 2001 From: Austin Eng Date: Wed, 26 Feb 2020 08:06:00 +0000 Subject: [PATCH] Add Toggle to disable sampler compare function on Metal. This Toggle is set if MTLFeatureSet_iOS_GPUFamily3_v1 is not supported. Bug: dawn:342 Change-Id: Ia5f43e87fdd2c13eaffe9557cb0ce9a06dec3b29 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/16180 Reviewed-by: Jiawei Shao Reviewed-by: Corentin Wallez Commit-Queue: Corentin Wallez --- src/dawn_native/Toggles.cpp | 4 ++++ src/dawn_native/Toggles.h | 1 + src/dawn_native/metal/DeviceMTL.mm | 7 +++++++ src/dawn_native/metal/SamplerMTL.mm | 10 +++------- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/dawn_native/Toggles.cpp b/src/dawn_native/Toggles.cpp index cc83c9b09e..578d52d50f 100644 --- a/src/dawn_native/Toggles.cpp +++ b/src/dawn_native/Toggles.cpp @@ -102,6 +102,10 @@ namespace dawn_native { "backend will use D32S8 (toggle to on) but setting the toggle to off will make it" "use the D24S8 format when possible.", "https://crbug.com/dawn/286"}}, + {Toggle::MetalDisableSamplerCompare, + {"metal_disable_sampler_compare", + "Disables the use of sampler compare on Metal. This is unsupported before A9 " + "processors."}}, }}; } // anonymous namespace diff --git a/src/dawn_native/Toggles.h b/src/dawn_native/Toggles.h index 3fc1dc7cfc..3891f98d70 100644 --- a/src/dawn_native/Toggles.h +++ b/src/dawn_native/Toggles.h @@ -36,6 +36,7 @@ namespace dawn_native { UseSpvc, UseSpvcParser, VulkanUseD32S8, + MetalDisableSamplerCompare, EnumCount, InvalidEnum = EnumCount, diff --git a/src/dawn_native/metal/DeviceMTL.mm b/src/dawn_native/metal/DeviceMTL.mm index 2b4a6ecc7a..02873ac6e7 100644 --- a/src/dawn_native/metal/DeviceMTL.mm +++ b/src/dawn_native/metal/DeviceMTL.mm @@ -69,6 +69,13 @@ namespace dawn_native { namespace metal { #endif // On tvOS, we would need MTLFeatureSet_tvOS_GPUFamily2_v1. SetToggle(Toggle::EmulateStoreAndMSAAResolve, !haveStoreAndMSAAResolve); + + bool haveSamplerCompare = true; +#if defined(DAWN_PLATFORM_IOS) + haveSamplerCompare = [mMtlDevice supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily3_v1]; +#endif + // TODO(crbug.com/dawn/342): Investigate emulation -- possibly expensive. + SetToggle(Toggle::MetalDisableSamplerCompare, !haveSamplerCompare); } // TODO(jiawei.shao@intel.com): tighten this workaround when the driver bug is fixed. diff --git a/src/dawn_native/metal/SamplerMTL.mm b/src/dawn_native/metal/SamplerMTL.mm index e29fbe189c..e8946867da 100644 --- a/src/dawn_native/metal/SamplerMTL.mm +++ b/src/dawn_native/metal/SamplerMTL.mm @@ -52,15 +52,11 @@ namespace dawn_native { namespace metal { // static ResultOrError Sampler::Create(Device* device, const SamplerDescriptor* descriptor) { -#if defined(DAWN_PLATFORM_IOS) if (descriptor->compare != wgpu::CompareFunction::Never && - ![device->GetMTLDevice() supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily3_v1]) { - // Unsupported before A9. - // TODO(b/149025333): Investigate emulation -- possibly expensive. - return DAWN_VALIDATION_ERROR( - "Sampler compare function requires at least iOS GPU family 3, version 1"); + device->IsToggleEnabled(Toggle::MetalDisableSamplerCompare)) { + return DAWN_VALIDATION_ERROR("Sampler compare function not supported."); } -#endif + return new Sampler(device, descriptor); }