test_shader.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // 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. #ifndef COMPONENTS_METAL_UTIL_TEST_SHADER_H_
  5. #define COMPONENTS_METAL_UTIL_TEST_SHADER_H_
  6. #include <vector>
  7. #include "base/callback.h"
  8. #include "base/task/task_runner.h"
  9. #include "base/time/time.h"
  10. #include "components/metal_util/metal_util_export.h"
  11. namespace metal {
  12. enum class TestShaderComponent {
  13. // Test a shader compile from source.
  14. kCompile,
  15. // Test linking a precompiled shader.
  16. kLink,
  17. };
  18. enum class TestShaderResult {
  19. // Not attempted (e.g, because macOS version does not support Metal).
  20. kNotAttempted,
  21. // Shader compile succeeded.
  22. kSucceeded,
  23. // Shader compile failed.
  24. kFailed,
  25. // Shader compile timed out.
  26. kTimedOut,
  27. };
  28. using TestShaderCallback =
  29. base::OnceCallback<void(TestShaderComponent component,
  30. TestShaderResult result,
  31. const base::TimeDelta& compile_time)>;
  32. // A default timeout value for compiling the test shader.
  33. constexpr base::TimeDelta kTestShaderTimeout = base::Minutes(1);
  34. // Return the value kTestShaderTimeoutTime for |compile_time| if it times out.
  35. constexpr base::TimeDelta kTestShaderTimeForever = base::Minutes(3);
  36. // A default delay before attempting to compile the test shader.
  37. constexpr base::TimeDelta kTestShaderDelay = base::Minutes(3);
  38. // Attempt to asynchronously compile a trivial Metal shader. If |delay| is zero,
  39. // then compile synchronously, otherwise, post a delayed task to do the compile.
  40. // |callback| with the result when the shader succeeds or after |timeout| has
  41. // elapsed. Whether compile or link was tested is communicated to |callback| in
  42. // its |component| argument.
  43. //
  44. // This is used to determine of the Metal shader compiler is resposive. Note
  45. // that |callback| will be called either on another thread or inside the
  46. // TestShader function call.
  47. // https://crbug.com/974219
  48. METAL_UTIL_EXPORT void TestShader(
  49. TestShaderCallback callback,
  50. const base::TimeDelta& delay = kTestShaderDelay,
  51. const base::TimeDelta& timeout = kTestShaderTimeForever);
  52. // Exposed for testing.
  53. METAL_UTIL_EXPORT extern const size_t kTestLibSize;
  54. METAL_UTIL_EXPORT extern const size_t kLiteralOffset;
  55. METAL_UTIL_EXPORT extern const size_t kLiteralSize;
  56. METAL_UTIL_EXPORT std::vector<uint8_t> GetAlteredLibraryData();
  57. } // namespace metal
  58. #endif // COMPONENTS_METAL_UTIL_TEST_SHADER_H_