Hal Canary | b6c5e5b | 2017-10-09 16:13:02 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
Kevin Lubick | cd65423 | 2022-09-21 11:41:10 -0400 | [diff] [blame] | 6 | * |
| 7 | * This file implements many functions defined in Test.h that are required to be implemented by |
| 8 | * test runners (such as DM) to support GPU backends. |
Hal Canary | b6c5e5b | 2017-10-09 16:13:02 -0400 | [diff] [blame] | 9 | */ |
| 10 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "tests/Test.h" |
Hal Canary | b6c5e5b | 2017-10-09 16:13:02 -0400 | [diff] [blame] | 12 | |
Robert Phillips | b87b39b | 2020-07-01 14:45:24 -0400 | [diff] [blame] | 13 | #include "include/gpu/GrDirectContext.h" |
| 14 | |
Kevin Lubick | 0f7b44e | 2023-02-28 09:13:11 -0500 | [diff] [blame] | 15 | #if defined(SK_GRAPHITE) |
Jim Van Verth | 42f710f | 2022-04-11 11:48:46 -0400 | [diff] [blame] | 16 | #include "include/gpu/graphite/Context.h" |
Robert Phillips | 3062759 | 2021-10-11 11:28:21 -0400 | [diff] [blame] | 17 | #include "tools/graphite/ContextFactory.h" |
Robert Phillips | b23372d | 2021-10-11 16:37:42 -0400 | [diff] [blame] | 18 | #endif |
Robert Phillips | 3062759 | 2021-10-11 11:28:21 -0400 | [diff] [blame] | 19 | |
Hal Canary | b6c5e5b | 2017-10-09 16:13:02 -0400 | [diff] [blame] | 20 | using sk_gpu_test::GrContextFactory; |
Leon Scroggins | 1351a59 | 2022-02-02 22:03:33 +0000 | [diff] [blame] | 21 | using sk_gpu_test::ContextInfo; |
Kevin Lubick | 805acda | 2022-02-02 09:55:42 -0500 | [diff] [blame] | 22 | |
Kevin Lubick | 49df61f | 2022-02-03 10:54:07 -0500 | [diff] [blame] | 23 | #ifdef SK_GL |
| 24 | using sk_gpu_test::GLTestContext; |
| 25 | #endif |
| 26 | |
Hal Canary | b6c5e5b | 2017-10-09 16:13:02 -0400 | [diff] [blame] | 27 | namespace skiatest { |
| 28 | |
John Stiles | ba7c525 | 2023-08-25 10:50:10 -0400 | [diff] [blame] | 29 | bool IsGLContextType(skgpu::ContextType type) { |
John Stiles | ac39b12 | 2023-08-25 16:23:37 -0400 | [diff] [blame] | 30 | #if defined(SK_GANESH) |
John Stiles | 365cde7 | 2023-08-25 15:34:46 -0400 | [diff] [blame] | 31 | return skgpu::ganesh::ContextTypeBackend(type) == GrBackendApi::kOpenGL; |
John Stiles | ac39b12 | 2023-08-25 16:23:37 -0400 | [diff] [blame] | 32 | #else |
| 33 | return false; |
| 34 | #endif |
Hal Canary | b6c5e5b | 2017-10-09 16:13:02 -0400 | [diff] [blame] | 35 | } |
John Stiles | ac39b12 | 2023-08-25 16:23:37 -0400 | [diff] [blame] | 36 | |
John Stiles | ba7c525 | 2023-08-25 10:50:10 -0400 | [diff] [blame] | 37 | bool IsVulkanContextType(skgpu::ContextType type) { |
John Stiles | ac39b12 | 2023-08-25 16:23:37 -0400 | [diff] [blame] | 38 | #if defined(SK_GANESH) |
John Stiles | 365cde7 | 2023-08-25 15:34:46 -0400 | [diff] [blame] | 39 | return skgpu::ganesh::ContextTypeBackend(type) == GrBackendApi::kVulkan; |
John Stiles | ac39b12 | 2023-08-25 16:23:37 -0400 | [diff] [blame] | 40 | #elif defined(SK_GRAPHITE) |
| 41 | return skgpu::graphite::ContextTypeBackend(type) == BackendApi::kVulkan; |
| 42 | #else |
| 43 | return false; |
| 44 | #endif |
Hal Canary | b6c5e5b | 2017-10-09 16:13:02 -0400 | [diff] [blame] | 45 | } |
John Stiles | ac39b12 | 2023-08-25 16:23:37 -0400 | [diff] [blame] | 46 | |
John Stiles | ba7c525 | 2023-08-25 10:50:10 -0400 | [diff] [blame] | 47 | bool IsMetalContextType(skgpu::ContextType type) { |
John Stiles | ac39b12 | 2023-08-25 16:23:37 -0400 | [diff] [blame] | 48 | #if defined(SK_GANESH) |
John Stiles | 365cde7 | 2023-08-25 15:34:46 -0400 | [diff] [blame] | 49 | return skgpu::ganesh::ContextTypeBackend(type) == GrBackendApi::kMetal; |
John Stiles | ac39b12 | 2023-08-25 16:23:37 -0400 | [diff] [blame] | 50 | #elif defined(SK_GRAPHITE) |
| 51 | return skgpu::graphite::ContextTypeBackend(type) == BackendApi::kMetal; |
| 52 | #else |
| 53 | return false; |
| 54 | #endif |
Timothy Liang | 760dbc4 | 2018-07-17 13:28:20 -0400 | [diff] [blame] | 55 | } |
John Stiles | ac39b12 | 2023-08-25 16:23:37 -0400 | [diff] [blame] | 56 | |
John Stiles | ba7c525 | 2023-08-25 10:50:10 -0400 | [diff] [blame] | 57 | bool IsDirect3DContextType(skgpu::ContextType type) { |
John Stiles | ac39b12 | 2023-08-25 16:23:37 -0400 | [diff] [blame] | 58 | #if defined(SK_GANESH) |
John Stiles | 365cde7 | 2023-08-25 15:34:46 -0400 | [diff] [blame] | 59 | return skgpu::ganesh::ContextTypeBackend(type) == GrBackendApi::kDirect3D; |
John Stiles | ac39b12 | 2023-08-25 16:23:37 -0400 | [diff] [blame] | 60 | #else |
| 61 | return false; |
| 62 | #endif |
Greg Daniel | d4928d0 | 2020-06-19 11:13:26 -0400 | [diff] [blame] | 63 | } |
John Stiles | ac39b12 | 2023-08-25 16:23:37 -0400 | [diff] [blame] | 64 | |
John Stiles | ba7c525 | 2023-08-25 10:50:10 -0400 | [diff] [blame] | 65 | bool IsDawnContextType(skgpu::ContextType type) { |
John Stiles | ac39b12 | 2023-08-25 16:23:37 -0400 | [diff] [blame] | 66 | #if defined(SK_GRAPHITE) |
| 67 | return skgpu::graphite::ContextTypeBackend(type) == skgpu::BackendApi::kDawn; |
| 68 | #else |
| 69 | return false; |
| 70 | #endif |
Greg Daniel | a58db7f | 2020-07-15 09:17:59 -0400 | [diff] [blame] | 71 | } |
John Stiles | ac39b12 | 2023-08-25 16:23:37 -0400 | [diff] [blame] | 72 | |
John Stiles | ba7c525 | 2023-08-25 10:50:10 -0400 | [diff] [blame] | 73 | bool IsMockContextType(skgpu::ContextType type) { |
| 74 | return type == skgpu::ContextType::kMock; |
Brian Osman | 7c59774 | 2019-03-26 11:10:11 -0400 | [diff] [blame] | 75 | } |
Hal Canary | b6c5e5b | 2017-10-09 16:13:02 -0400 | [diff] [blame] | 76 | |
John Stiles | 365cde7 | 2023-08-25 15:34:46 -0400 | [diff] [blame] | 77 | void RunWithGaneshTestContexts(GrContextTestFn* testFn, ContextTypeFilterFn* filter, |
Kevin Lubick | cd65423 | 2022-09-21 11:41:10 -0400 | [diff] [blame] | 78 | Reporter* reporter, const GrContextOptions& options) { |
Hal Canary | b6c5e5b | 2017-10-09 16:13:02 -0400 | [diff] [blame] | 79 | #if defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_WIN) || defined(SK_BUILD_FOR_MAC) |
John Stiles | ba7c525 | 2023-08-25 10:50:10 -0400 | [diff] [blame] | 80 | static constexpr auto kNativeGLType = skgpu::ContextType::kGL; |
Hal Canary | b6c5e5b | 2017-10-09 16:13:02 -0400 | [diff] [blame] | 81 | #else |
John Stiles | ba7c525 | 2023-08-25 10:50:10 -0400 | [diff] [blame] | 82 | static constexpr auto kNativeGLType = skgpu::ContextType::kGLES; |
Hal Canary | b6c5e5b | 2017-10-09 16:13:02 -0400 | [diff] [blame] | 83 | #endif |
| 84 | |
John Stiles | ba7c525 | 2023-08-25 10:50:10 -0400 | [diff] [blame] | 85 | for (int typeInt = 0; typeInt < skgpu::kContextTypeCount; ++typeInt) { |
| 86 | skgpu::ContextType contextType = static_cast<skgpu::ContextType>(typeInt); |
Hal Canary | b6c5e5b | 2017-10-09 16:13:02 -0400 | [diff] [blame] | 87 | // Use "native" instead of explicitly trying OpenGL and OpenGL ES. Do not use GLES on |
| 88 | // desktop since tests do not account for not fixing http://skbug.com/2809 |
John Stiles | ba7c525 | 2023-08-25 10:50:10 -0400 | [diff] [blame] | 89 | if (contextType == skgpu::ContextType::kGL || |
| 90 | contextType == skgpu::ContextType::kGLES) { |
Hal Canary | b6c5e5b | 2017-10-09 16:13:02 -0400 | [diff] [blame] | 91 | if (contextType != kNativeGLType) { |
| 92 | continue; |
| 93 | } |
| 94 | } |
Brian Salomon | dcfca43 | 2017-11-15 15:48:03 -0500 | [diff] [blame] | 95 | // We destroy the factory and its associated contexts after each test. This is due to the |
| 96 | // fact that the command buffer sits on top of the native GL windowing (cgl, wgl, ...) but |
| 97 | // also tracks which of its contexts is current above that API and gets tripped up if the |
| 98 | // native windowing API is used directly outside of the command buffer code. |
| 99 | GrContextFactory factory(options); |
Chris Dalton | b3c9745 | 2019-06-25 20:07:56 -0600 | [diff] [blame] | 100 | ContextInfo ctxInfo = factory.getContextInfo(contextType); |
Kevin Lubick | cd65423 | 2022-09-21 11:41:10 -0400 | [diff] [blame] | 101 | if (filter && !(*filter)(contextType)) { |
Hal Canary | b6c5e5b | 2017-10-09 16:13:02 -0400 | [diff] [blame] | 102 | continue; |
| 103 | } |
| 104 | |
John Stiles | ba7c525 | 2023-08-25 10:50:10 -0400 | [diff] [blame] | 105 | ReporterContext ctx(reporter, SkString(skgpu::ContextTypeName(contextType))); |
Robert Phillips | b87b39b | 2020-07-01 14:45:24 -0400 | [diff] [blame] | 106 | if (ctxInfo.directContext()) { |
Kevin Lubick | cd65423 | 2022-09-21 11:41:10 -0400 | [diff] [blame] | 107 | (*testFn)(reporter, ctxInfo); |
Greg Daniel | 58b5a54 | 2020-04-09 14:55:00 -0400 | [diff] [blame] | 108 | // In case the test changed the current context make sure we move it back before |
| 109 | // calling flush. |
| 110 | ctxInfo.testContext()->makeCurrent(); |
Brian Salomon | 7205080 | 2020-10-12 20:45:06 -0400 | [diff] [blame] | 111 | // Sync so any release/finished procs get called. |
Kevin Lubick | 99bcee2 | 2023-09-06 10:09:08 -0400 | [diff] [blame] | 112 | ctxInfo.directContext()->flushAndSubmit(GrSyncCpu::kYes); |
Hal Canary | b6c5e5b | 2017-10-09 16:13:02 -0400 | [diff] [blame] | 113 | } |
Hal Canary | b6c5e5b | 2017-10-09 16:13:02 -0400 | [diff] [blame] | 114 | } |
Hal Canary | b6c5e5b | 2017-10-09 16:13:02 -0400 | [diff] [blame] | 115 | } |
Robert Phillips | 3062759 | 2021-10-11 11:28:21 -0400 | [diff] [blame] | 116 | |
Kevin Lubick | 0f7b44e | 2023-02-28 09:13:11 -0500 | [diff] [blame] | 117 | #if defined(SK_GRAPHITE) |
Robert Phillips | 3062759 | 2021-10-11 11:28:21 -0400 | [diff] [blame] | 118 | |
| 119 | namespace graphite { |
| 120 | |
John Stiles | b5e8e34 | 2023-08-22 14:59:00 -0400 | [diff] [blame] | 121 | void RunWithGraphiteTestContexts(GraphiteTestFn* test, |
John Stiles | 365cde7 | 2023-08-25 15:34:46 -0400 | [diff] [blame] | 122 | ContextTypeFilterFn* filter, |
John Stiles | b5e8e34 | 2023-08-22 14:59:00 -0400 | [diff] [blame] | 123 | Reporter* reporter, |
Brian Salomon | 23e1cb2 | 2023-12-05 19:46:43 -0500 | [diff] [blame] | 124 | const skiatest::graphite::TestOptions& options) { |
| 125 | ContextFactory factory(options); |
John Stiles | ba7c525 | 2023-08-25 10:50:10 -0400 | [diff] [blame] | 126 | for (int typeInt = 0; typeInt < skgpu::kContextTypeCount; ++typeInt) { |
| 127 | skgpu::ContextType contextType = static_cast<skgpu::ContextType>(typeInt); |
Greg Daniel | 22d6c0f | 2022-10-12 15:26:09 -0400 | [diff] [blame] | 128 | if (filter && !(*filter)(contextType)) { |
| 129 | continue; |
| 130 | } |
| 131 | |
John Stiles | 6627074 | 2023-09-19 11:37:36 -0400 | [diff] [blame] | 132 | skiatest::graphite::ContextInfo ctxInfo = factory.getContextInfo(contextType); |
John Stiles | 8aafaa3 | 2023-09-19 11:37:37 -0400 | [diff] [blame] | 133 | if (!ctxInfo.fContext) { |
Greg Daniel | cb0e5d9 | 2022-09-16 14:45:17 -0400 | [diff] [blame] | 134 | continue; |
| 135 | } |
Robert Phillips | 3062759 | 2021-10-11 11:28:21 -0400 | [diff] [blame] | 136 | |
John Stiles | ba7c525 | 2023-08-25 10:50:10 -0400 | [diff] [blame] | 137 | ReporterContext ctx(reporter, SkString(skgpu::ContextTypeName(contextType))); |
John Stiles | 8aafaa3 | 2023-09-19 11:37:37 -0400 | [diff] [blame] | 138 | (*test)(reporter, ctxInfo.fContext, ctxInfo.fTestContext); |
Robert Phillips | 3062759 | 2021-10-11 11:28:21 -0400 | [diff] [blame] | 139 | } |
Robert Phillips | 3062759 | 2021-10-11 11:28:21 -0400 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | } // namespace graphite |
| 143 | |
Kevin Lubick | 0f7b44e | 2023-02-28 09:13:11 -0500 | [diff] [blame] | 144 | #endif // SK_GRAPHITE |
Robert Phillips | 3062759 | 2021-10-11 11:28:21 -0400 | [diff] [blame] | 145 | |
Hal Canary | b6c5e5b | 2017-10-09 16:13:02 -0400 | [diff] [blame] | 146 | } // namespace skiatest |