summaryrefslogtreecommitdiff
path: root/chromium/components/metal_util/test_shader.mm
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/components/metal_util/test_shader.mm')
-rw-r--r--chromium/components/metal_util/test_shader.mm221
1 files changed, 168 insertions, 53 deletions
diff --git a/chromium/components/metal_util/test_shader.mm b/chromium/components/metal_util/test_shader.mm
index 49b56df11cc..d92484403d4 100644
--- a/chromium/components/metal_util/test_shader.mm
+++ b/chromium/components/metal_util/test_shader.mm
@@ -4,10 +4,11 @@
#include "components/metal_util/test_shader.h"
+#include <CommonCrypto/CommonDigest.h>
#import <Metal/Metal.h>
#include "base/bind.h"
-#include "base/debug/dump_without_crashing.h"
+#include "base/command_line.h"
#include "base/mac/scoped_dispatch_object.h"
#include "base/mac/scoped_nsobject.h"
#include "base/memory/ref_counted.h"
@@ -19,13 +20,12 @@
#include "base/task/thread_pool.h"
#include "components/crash/core/common/crash_key.h"
#include "components/metal_util/device.h"
+#include "components/metal_util/switches.h"
namespace metal {
namespace {
-constexpr uint32_t kCrashKeyLength = 1024;
-
const char* kTestShaderSource =
""
"#include <metal_stdlib>\n"
@@ -51,7 +51,7 @@ const char* kTestShaderSource =
"}\n"
"";
-size_t kTestLibSize = 5990;
+size_t kTestLibSize = 0x1766;
uint8_t kTestLibData[] = {
0x4d, 0x54, 0x4c, 0x42, 0x01, 0x80, 0x02, 0x00, 0x03, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x66, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@@ -554,8 +554,131 @@ uint8_t kTestLibData[] = {
0x2e, 0x31, 0x34, 0x2e, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00};
+// There exists a 4-byte literal at this offset, which can be changed to any
+// value in kValidLiteral to defeat caching.
+const size_t kLiteralOffset = 0x167c;
+const size_t kLiteralSize = 0x4;
+const uint8_t kValidLiteralValues[] = {
+ 0xef, 0x4c, 0x9a, 0x68, 0xef, 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itcode that is hashed is stored at this offset and with this size.
+const size_t kTestLibBitcodeOffset = 0xd16;
+const size_t kTestLibBitcodeSize = 0xa50;
+
+crash_reporter::CrashKeyString<32>& GetLinkIndexCrashKey() {
+ static crash_reporter::CrashKeyString<32> crash_key("metal-link-index");
+ return crash_key;
+}
+
+std::vector<uint8_t> GetAlteredLibraryData() {
+ // Make a copy of the shader's data.
+ std::vector<uint8_t> data(kTestLibData, kTestLibData + kTestLibSize);
+
+ // Alter the data at kLiteralOffset to defeat caching.
+ uint64_t index = base::RandInt(0, sizeof(kValidLiteralValues) / kLiteralSize);
+ for (size_t i = 0; i < kLiteralSize; ++i)
+ data[kLiteralOffset + i] = kValidLiteralValues[kLiteralSize * index + i];
+
+ // Compute the hash of the altered bitcode and and place it in the data.
+ CC_SHA256(&data[kTestLibBitcodeOffset], kTestLibBitcodeSize,
+ &data[kTestLibHashOffset]);
+
+ // Shader link crashes have been observed on bots. Record what index caused
+ // them if they appear in the wild.
+ GetLinkIndexCrashKey().Set(base::StringPrintf("%llu", index));
+ return data;
+}
+
base::ScopedDispatchObject<dispatch_data_t> GetLibraryData() {
- std::vector<uint8_t> vector_data(kTestLibData, kTestLibData + kTestLibSize);
+ auto vector_data = GetAlteredLibraryData();
base::ScopedDispatchObject<dispatch_data_t> dispatch_data(
dispatch_data_create(vector_data.data(), vector_data.size(), nullptr,
DISPATCH_DATA_DESTRUCTOR_DEFAULT));
@@ -566,8 +689,11 @@ base::ScopedDispatchObject<dispatch_data_t> GetLibraryData() {
class API_AVAILABLE(macos(10.11)) TestShaderState
: public base::RefCountedThreadSafe<TestShaderState> {
public:
- TestShaderState(TestShaderCallback callback, const base::TimeDelta& timeout)
+ TestShaderState(TestShaderCallback callback,
+ TestShaderComponent component,
+ const base::TimeDelta& timeout)
: callback_(std::move(callback)),
+ component_(component),
timeout_(timeout),
start_time_(base::TimeTicks::Now()) {}
@@ -635,16 +761,23 @@ class API_AVAILABLE(macos(10.11)) TestShaderState
std::min(timeout_, completion_handler_called_time_ - start_time_);
// Set up the callback to execute once we release the lock.
- closure = base::BindOnce(std::move(callback_), result_, method_time,
+ closure = base::BindOnce(std::move(callback_), component_, result_,
compile_time);
}
- if (closure)
+ if (closure) {
+ // If this is a link that has completed, then we set the crash key when
+ // constructing the shader binary. Clear it now, because Metal didn't
+ // crash while linking the shader.
+ if (component_ == TestShaderComponent::kLink)
+ GetLinkIndexCrashKey().Clear();
std::move(closure).Run();
+ }
}
base::Lock lock_;
TestShaderCallback callback_;
TestShaderResult result_ = TestShaderResult::kTimedOut;
+ const TestShaderComponent component_;
const base::TimeDelta timeout_;
const base::TimeTicks start_time_;
base::TimeTicks method_completed_time_;
@@ -667,19 +800,13 @@ void TestRenderPipelineStateNow(base::scoped_nsprotocol<id<MTLDevice>> device,
[library newFunctionWithName:@"vertexShader"]);
base::scoped_nsprotocol<id<MTLFunction>> fragment_fn(
[library newFunctionWithName:@"fragmentShader"]);
- if (error || !library || !vertex_fn || !fragment_fn) {
- static crash_reporter::CrashKeyString<kCrashKeyLength> crash_key(
- "newLibraryWithData");
- crash_reporter::ScopedCrashKeyString value(
- &crash_key, base::SysNSStringToUTF8([error description]));
- base::debug::DumpWithoutCrashing();
+ if (error || !library || !vertex_fn || !fragment_fn)
return;
- }
// Initialize the TestShaderState and post the timeout callback, before
// calling into the Metal API.
- auto state =
- base::MakeRefCounted<TestShaderState>(std::move(callback), timeout);
+ auto state = base::MakeRefCounted<TestShaderState>(
+ std::move(callback), TestShaderComponent::kLink, timeout);
base::ThreadPool::PostDelayedTask(
FROM_HERE, {}, base::BindOnce(&TestShaderState::OnTimeout, state),
timeout);
@@ -693,13 +820,6 @@ void TestRenderPipelineStateNow(base::scoped_nsprotocol<id<MTLDevice>> device,
[descriptor colorAttachments][0].pixelFormat = MTLPixelFormatBGRA8Unorm;
MTLNewRenderPipelineStateCompletionHandler completion_handler =
^(id<MTLRenderPipelineState> render_pipeline_state, NSError* error) {
- if (!render_pipeline_state) {
- static crash_reporter::CrashKeyString<kCrashKeyLength> crash_key(
- "newRenderPipelineStateWithDescriptor");
- crash_reporter::ScopedCrashKeyString value(
- &crash_key, base::SysNSStringToUTF8([error description]));
- base::debug::DumpWithoutCrashing();
- }
state->OnCompletionHandlerCalled(render_pipeline_state
? TestShaderResult::kSucceeded
: TestShaderResult::kFailed);
@@ -712,11 +832,11 @@ void TestRenderPipelineStateNow(base::scoped_nsprotocol<id<MTLDevice>> device,
void TestShaderNow(base::scoped_nsprotocol<id<MTLDevice>> device,
const base::TimeDelta& timeout,
- TestShaderCallback callback) API_AVAILABLE(macos(10.11)) {
+ TestShaderCallback callback) API_AVAILABLE(macos(10.14)) {
// Initialize the TestShaderState and post the timeout callback, before
// calling into the Metal API.
- auto state =
- base::MakeRefCounted<TestShaderState>(std::move(callback), timeout);
+ auto state = base::MakeRefCounted<TestShaderState>(
+ std::move(callback), TestShaderComponent::kCompile, timeout);
base::ThreadPool::PostDelayedTask(
FROM_HERE, {}, base::BindOnce(&TestShaderState::OnTimeout, state),
timeout);
@@ -730,13 +850,6 @@ void TestShaderNow(base::scoped_nsprotocol<id<MTLDevice>> device,
[[MTLCompileOptions alloc] init]);
MTLNewLibraryCompletionHandler completion_handler =
^(id<MTLLibrary> library, NSError* error) {
- if (!error) {
- static crash_reporter::CrashKeyString<kCrashKeyLength> crash_key(
- "newLibraryWithSource");
- crash_reporter::ScopedCrashKeyString value(
- &crash_key, base::SysNSStringToUTF8([error description]));
- base::debug::DumpWithoutCrashing();
- }
state->OnCompletionHandlerCalled(library ? TestShaderResult::kSucceeded
: TestShaderResult::kFailed);
};
@@ -750,9 +863,21 @@ void TestShaderNow(base::scoped_nsprotocol<id<MTLDevice>> device,
void TestShader(TestShaderCallback callback,
const base::TimeDelta& delay,
- const base::TimeDelta& timeout,
- TestShaderComponent component) {
- if (@available(macOS 10.11, *)) {
+ const base::TimeDelta& timeout) {
+ bool disabled_at_command_line =
+ base::CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kDisableMetalTestShaders);
+ if (disabled_at_command_line)
+ return;
+
+ // Select a component to test at random.
+ TestShaderComponent component = base::RandInt(0, 1)
+ ? TestShaderComponent::kLink
+ : TestShaderComponent::kCompile;
+
+ // The metallib listed above is in MTLLanguageVersion2_1, which is available
+ // only on 10.14 and above.
+ if (@available(macOS 10.14, *)) {
base::scoped_nsprotocol<id<MTLDevice>> device(CreateDefaultDevice());
if (device) {
// Select the callback depending on if we're testing online or offline
@@ -764,29 +889,19 @@ void TestShader(TestShaderCallback callback,
std::move(callback));
break;
case TestShaderComponent::kLink:
- // The metallib listed above is in MTLLanguageVersion2_1, which is
- // available only on 10.14 and above.
- if (@available(macOS 10.14, *)) {
- closure = base::BindOnce(&TestRenderPipelineStateNow, device,
- timeout, std::move(callback));
- }
+ closure = base::BindOnce(&TestRenderPipelineStateNow, device, timeout,
+ std::move(callback));
break;
}
-
- // Run either immediately or after the specified delay.
if (closure) {
- if (delay.is_zero()) {
- std::move(closure).Run();
- } else {
- base::ThreadPool::PostDelayedTask(FROM_HERE,
- {base::TaskPriority::HIGHEST},
- std::move(closure), delay);
- }
+ base::ThreadPool::PostDelayedTask(FROM_HERE,
+ {base::TaskPriority::HIGHEST},
+ std::move(closure), delay);
return;
}
}
}
- std::move(callback).Run(TestShaderResult::kNotAttempted, base::TimeDelta(),
+ std::move(callback).Run(component, TestShaderResult::kNotAttempted,
base::TimeDelta());
}