Disabling inlining of counterSet checks

To help debug a suspect crash in these functions.

Also, change some of the counter checks to use more
Objective-C style checks instead of std::find.

Bug: dawn:1102
Change-Id: I693d1f2489116200b2c0608ca60bc3eb8ddb8571
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/71242
Reviewed-by: Jiawei Shao <jiawei.shao@intel.com>
Reviewed-by: Hao Li <hao.x.li@intel.com>
Commit-Queue: Austin Eng <enga@chromium.org>
diff --git a/src/common/Compiler.h b/src/common/Compiler.h
index 49e6db4..bb2d669 100644
--- a/src/common/Compiler.h
+++ b/src/common/Compiler.h
@@ -64,6 +64,7 @@
 #    if defined(NDEBUG)
 #        define DAWN_FORCE_INLINE inline __attribute__((always_inline))
 #    endif
+#    define DAWN_NOINLINE __attribute__((noinline))
 
 // MSVC
 #elif defined(_MSC_VER)
@@ -83,6 +84,7 @@
 #    if defined(NDEBUG)
 #        define DAWN_FORCE_INLINE __forceinline
 #    endif
+#    define DAWN_NOINLINE __declspec(noinline)
 
 #else
 #    error "Unsupported compiler"
@@ -106,6 +108,9 @@
 #if !defined(DAWN_FORCE_INLINE)
 #    define DAWN_FORCE_INLINE inline
 #endif
+#if !defined(DAWN_NOINLINE)
+#    define DAWN_NOINLINE
+#endif
 
 #if defined(__clang__)
 #    define DAWN_FALLTHROUGH [[clang::fallthrough]]
diff --git a/src/dawn_native/metal/BackendMTL.mm b/src/dawn_native/metal/BackendMTL.mm
index 33bfc986..8a7a770 100644
--- a/src/dawn_native/metal/BackendMTL.mm
+++ b/src/dawn_native/metal/BackendMTL.mm
@@ -174,7 +174,7 @@
 #    error "Unsupported Apple platform."
 #endif
 
-        bool IsCounterSamplingBoundarySupport(id<MTLDevice> device)
+        DAWN_NOINLINE bool IsCounterSamplingBoundarySupport(id<MTLDevice> device)
             API_AVAILABLE(macos(11.0), ios(14.0)) {
             bool isBlitBoundarySupported =
                 [device supportsCounterSampling:MTLCounterSamplingPointAtBlitBoundary];
@@ -187,9 +187,9 @@
                    isDrawBoundarySupported;
         }
 
-        bool IsGPUCounterSupported(id<MTLDevice> device,
-                                   MTLCommonCounterSet counterSetName,
-                                   std::vector<MTLCommonCounter> counters)
+        DAWN_NOINLINE bool IsGPUCounterSupported(id<MTLDevice> device,
+                                                 MTLCommonCounterSet counterSetName,
+                                                 std::vector<MTLCommonCounter> counterNames)
             API_AVAILABLE(macos(10.15), ios(14.0)) {
             // MTLDevice’s counterSets property declares which counter sets it supports. Check
             // whether it's available on the device before requesting a counter set.
@@ -209,13 +209,15 @@
             // A GPU might support a counter set, but only support a subset of the counters in that
             // set, check if the counter set supports all specific counters we need. Return false
             // if there is a counter unsupported.
-            std::vector<NSString*> supportedCounters;
-            for (id<MTLCounter> counter in counterSet.counters) {
-                supportedCounters.push_back(counter.name);
-            }
-            for (const auto& counterName : counters) {
-                if (std::find(supportedCounters.begin(), supportedCounters.end(), counterName) ==
-                    supportedCounters.end()) {
+            for (MTLCommonCounter counterName : counterNames) {
+                bool found = false;
+                for (id<MTLCounter> counter in counterSet.counters) {
+                    if ([counter.name caseInsensitiveCompare:counterName] == NSOrderedSame) {
+                        found = true;
+                        break;
+                    }
+                }
+                if (!found) {
                     return false;
                 }
             }