From 6e83e6284eb6a83e3ffce3e1d7d78cfee3130833 Mon Sep 17 00:00:00 2001 From: Austin Eng Date: Tue, 30 Nov 2021 04:16:18 +0000 Subject: [PATCH] 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 Reviewed-by: Hao Li Commit-Queue: Austin Eng --- src/common/Compiler.h | 5 +++++ src/dawn_native/metal/BackendMTL.mm | 24 +++++++++++++----------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/common/Compiler.h b/src/common/Compiler.h index 49e6db4c5e..bb2d669857 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 @@ extern void __cdecl __debugbreak(void); # if defined(NDEBUG) # define DAWN_FORCE_INLINE __forceinline # endif +# define DAWN_NOINLINE __declspec(noinline) #else # error "Unsupported compiler" @@ -106,6 +108,9 @@ extern void __cdecl __debugbreak(void); #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 33bfc9862b..8a7a770d87 100644 --- a/src/dawn_native/metal/BackendMTL.mm +++ b/src/dawn_native/metal/BackendMTL.mm @@ -174,7 +174,7 @@ namespace dawn_native { namespace metal { # error "Unsupported Apple platform." #endif - bool IsCounterSamplingBoundarySupport(id device) + DAWN_NOINLINE bool IsCounterSamplingBoundarySupport(id device) API_AVAILABLE(macos(11.0), ios(14.0)) { bool isBlitBoundarySupported = [device supportsCounterSampling:MTLCounterSamplingPointAtBlitBoundary]; @@ -187,9 +187,9 @@ namespace dawn_native { namespace metal { isDrawBoundarySupported; } - bool IsGPUCounterSupported(id device, - MTLCommonCounterSet counterSetName, - std::vector counters) + DAWN_NOINLINE bool IsGPUCounterSupported(id device, + MTLCommonCounterSet counterSetName, + std::vector 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 @@ namespace dawn_native { namespace metal { // 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 supportedCounters; - for (id 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 counter in counterSet.counters) { + if ([counter.name caseInsensitiveCompare:counterName] == NSOrderedSame) { + found = true; + break; + } + } + if (!found) { return false; } }