blob: c892b5cd1d4f43d2aefdb3da3d6ecbfaa19fbc9f [file] [log] [blame]
Christopher Cameron7e9874732019-10-25 00:40:361// Copyright 2019 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef COMPONENTS_METAL_UTIL_TEST_SHADER_H_
6#define COMPONENTS_METAL_UTIL_TEST_SHADER_H_
7
8#include "base/callback.h"
9#include "base/task_runner.h"
10#include "base/time/time.h"
11#include "components/metal_util/metal_util_export.h"
12
13namespace metal {
14
Christopher Cameron83dc2c42020-01-29 00:09:2115enum class METAL_UTIL_EXPORT TestShaderComponent {
16 // Test a shader compile from source.
17 kCompile,
18 // Test linking a precompiled shader.
19 kLink,
20};
21
Christopher Cameron7e9874732019-10-25 00:40:3622enum class METAL_UTIL_EXPORT TestShaderResult {
23 // Not attempted (e.g, because macOS version does not support Metal).
24 kNotAttempted,
25 // Shader compile succeeded.
26 kSucceeded,
27 // Shader compile failed.
28 kFailed,
29 // Shader compile timed out.
30 kTimedOut,
31};
32
Christopher Camerond362a662019-11-27 17:45:1833using TestShaderCallback =
34 base::OnceCallback<void(TestShaderResult result,
35 const base::TimeDelta& method_time,
36 const base::TimeDelta& compile_time)>;
Christopher Cameron7e9874732019-10-25 00:40:3637
Christopher Camerond362a662019-11-27 17:45:1838// A default timeout value for compiling the test shader.
39constexpr base::TimeDelta kTestShaderTimeout = base::TimeDelta::FromMinutes(1);
40
41// Return the value kTestShaderTimeoutTime for |method_time| and |compile_time|
42// if they time out.
43constexpr base::TimeDelta kTestShaderTimeForever =
44 base::TimeDelta::FromMinutes(3);
45
46// A default delay before attempting to compile the test shader.
Christopher Cameron83dc2c42020-01-29 00:09:2147constexpr base::TimeDelta kTestShaderDelay = base::TimeDelta::FromMinutes(3);
Christopher Camerond362a662019-11-27 17:45:1848
49// Attempt to asynchronously compile a trivial Metal shader. If |delay| is zero,
50// then compile synchronously, otherwise, post a delayed task to do the compile.
51// |callback| with the result when the shader succeeds or after |timeout| has
52// elapsed.
53//
Christopher Cameron7e9874732019-10-25 00:40:3654// This is used to determine of the Metal shader compiler is resposive. Note
55// that |callback| will be called either on another thread or inside the
Christopher Camerond362a662019-11-27 17:45:1856// TestShader function call.
Christopher Cameron7e9874732019-10-25 00:40:3657// https://crbug.com/974219
Christopher Camerond362a662019-11-27 17:45:1858void METAL_UTIL_EXPORT
59TestShader(TestShaderCallback callback,
60 const base::TimeDelta& delay = kTestShaderDelay,
Christopher Cameron83dc2c42020-01-29 00:09:2161 const base::TimeDelta& timeout = kTestShaderTimeout,
62 TestShaderComponent component = TestShaderComponent::kLink);
Christopher Cameron21c4abc2019-11-15 04:06:1563
Christopher Cameron7e9874732019-10-25 00:40:3664} // namespace metal
65
66#endif // COMPONENTS_METAL_UTIL_TEST_SHADER_H_