bsalomon | 3724e57 | 2016-03-30 18:56:19 -0700 | [diff] [blame] | 1 | |
djsollen | e454521 | 2014-11-13 11:12:41 -0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2014 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
| 8 | |
Robert Phillips | 00f78de | 2020-07-01 16:09:43 -0400 | [diff] [blame] | 9 | #include "include/gpu/GrDirectContext.h" |
Adlai Holler | a069304 | 2020-10-14 11:23:11 -0400 | [diff] [blame] | 10 | #include "src/gpu/GrDirectContextPriv.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "tools/gpu/GrContextFactory.h" |
John Rosasco | a9b348f | 2019-11-08 13:18:15 -0800 | [diff] [blame] | 12 | #ifdef SK_GL |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 13 | #include "tools/gpu/gl/GLTestContext.h" |
John Rosasco | a9b348f | 2019-11-08 13:18:15 -0800 | [diff] [blame] | 14 | #endif |
djsollen | e454521 | 2014-11-13 11:12:41 -0800 | [diff] [blame] | 15 | |
Mike Klein | c168a3a | 2016-11-14 14:53:13 +0000 | [diff] [blame] | 16 | #if SK_ANGLE |
Jim Van Verth | b01e12b | 2020-02-18 14:34:38 -0500 | [diff] [blame] | 17 | #include "tools/gpu/gl/angle/GLTestContext_angle.h" |
Mike Klein | c168a3a | 2016-11-14 14:53:13 +0000 | [diff] [blame] | 18 | #endif |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 19 | #include "tools/gpu/gl/command_buffer/GLTestContext_command_buffer.h" |
djsollen | 7e73108 | 2016-06-09 13:07:13 -0700 | [diff] [blame] | 20 | #ifdef SK_VULKAN |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 21 | #include "tools/gpu/vk/VkTestContext.h" |
bsalomon | 7c62b47 | 2016-04-01 07:42:05 -0700 | [diff] [blame] | 22 | #endif |
Greg Daniel | b76a72a | 2017-07-13 15:07:54 -0400 | [diff] [blame] | 23 | #ifdef SK_METAL |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 24 | #include "tools/gpu/mtl/MtlTestContext.h" |
Greg Daniel | b76a72a | 2017-07-13 15:07:54 -0400 | [diff] [blame] | 25 | #endif |
Jim Van Verth | b01e12b | 2020-02-18 14:34:38 -0500 | [diff] [blame] | 26 | #ifdef SK_DIRECT3D |
| 27 | #include "tools/gpu/d3d/D3DTestContext.h" |
| 28 | #endif |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 29 | #ifdef SK_DAWN |
| 30 | #include "tools/gpu/dawn/DawnTestContext.h" |
| 31 | #endif |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 32 | #include "src/gpu/GrCaps.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 33 | #include "tools/gpu/mock/MockTestContext.h" |
djsollen | e454521 | 2014-11-13 11:12:41 -0800 | [diff] [blame] | 34 | |
Mike Klein | 8f11d4d | 2018-01-24 12:42:55 -0500 | [diff] [blame] | 35 | #if defined(SK_BUILD_FOR_WIN) && defined(SK_ENABLE_DISCRETE_GPU) |
Brian Osman | 3f375d0 | 2016-12-28 11:19:22 -0500 | [diff] [blame] | 36 | extern "C" { |
| 37 | // NVIDIA documents that the presence and value of this symbol programmatically enable the high |
| 38 | // performance GPU in laptops with switchable graphics. |
| 39 | // https://docs.nvidia.com/gameworks/content/technologies/desktop/optimus.htm |
| 40 | // From testing, including this symbol, even if it is set to 0, we still get the NVIDIA GPU. |
| 41 | _declspec(dllexport) unsigned long NvOptimusEnablement = 0x00000001; |
| 42 | |
| 43 | // AMD has a similar mechanism, although I don't have an AMD laptop, so this is untested. |
| 44 | // https://community.amd.com/thread/169965 |
| 45 | __declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1; |
| 46 | } |
| 47 | #endif |
| 48 | |
bsalomon | 3724e57 | 2016-03-30 18:56:19 -0700 | [diff] [blame] | 49 | namespace sk_gpu_test { |
kkinnunen | 3405800 | 2016-01-06 23:49:30 -0800 | [diff] [blame] | 50 | GrContextFactory::GrContextFactory() { } |
| 51 | |
| 52 | GrContextFactory::GrContextFactory(const GrContextOptions& opts) |
| 53 | : fGlobalOptions(opts) { |
| 54 | } |
| 55 | |
| 56 | GrContextFactory::~GrContextFactory() { |
| 57 | this->destroyContexts(); |
| 58 | } |
| 59 | |
| 60 | void GrContextFactory::destroyContexts() { |
Greg Daniel | f0fe02f | 2018-01-16 11:20:41 -0500 | [diff] [blame] | 61 | // We must delete the test contexts in reverse order so that any child context is finished and |
| 62 | // deleted before a parent context. This relies on the fact that when we make a new context we |
| 63 | // append it to the end of fContexts array. |
| 64 | // TODO: Look into keeping a dependency dag for contexts and deletion order |
| 65 | for (int i = fContexts.count() - 1; i >= 0; --i) { |
| 66 | Context& context = fContexts[i]; |
Brian Salomon | 55ad774 | 2017-11-17 09:25:23 -0500 | [diff] [blame] | 67 | SkScopeExit restore(nullptr); |
bsalomon | 18a2f9d | 2016-05-11 10:09:18 -0700 | [diff] [blame] | 68 | if (context.fTestContext) { |
Brian Salomon | 55ad774 | 2017-11-17 09:25:23 -0500 | [diff] [blame] | 69 | restore = context.fTestContext->makeCurrentAndAutoRestore(); |
kkinnunen | 3405800 | 2016-01-06 23:49:30 -0800 | [diff] [blame] | 70 | } |
| 71 | if (!context.fGrContext->unique()) { |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 72 | context.fGrContext->releaseResourcesAndAbandonContext(); |
| 73 | context.fAbandoned = true; |
kkinnunen | 3405800 | 2016-01-06 23:49:30 -0800 | [diff] [blame] | 74 | } |
| 75 | context.fGrContext->unref(); |
bsalomon | 18a2f9d | 2016-05-11 10:09:18 -0700 | [diff] [blame] | 76 | delete context.fTestContext; |
kkinnunen | 3405800 | 2016-01-06 23:49:30 -0800 | [diff] [blame] | 77 | } |
| 78 | fContexts.reset(); |
| 79 | } |
| 80 | |
| 81 | void GrContextFactory::abandonContexts() { |
Greg Daniel | f0fe02f | 2018-01-16 11:20:41 -0500 | [diff] [blame] | 82 | // We must abandon the test contexts in reverse order so that any child context is finished and |
| 83 | // abandoned before a parent context. This relies on the fact that when we make a new context we |
| 84 | // append it to the end of fContexts array. |
| 85 | // TODO: Look into keeping a dependency dag for contexts and deletion order |
| 86 | for (int i = fContexts.count() - 1; i >= 0; --i) { |
| 87 | Context& context = fContexts[i]; |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 88 | if (!context.fAbandoned) { |
bsalomon | 18a2f9d | 2016-05-11 10:09:18 -0700 | [diff] [blame] | 89 | if (context.fTestContext) { |
Brian Salomon | 55ad774 | 2017-11-17 09:25:23 -0500 | [diff] [blame] | 90 | auto restore = context.fTestContext->makeCurrentAndAutoRestore(); |
bsalomon | 18a2f9d | 2016-05-11 10:09:18 -0700 | [diff] [blame] | 91 | context.fTestContext->testAbandon(); |
Greg Daniel | f0e04f0 | 2019-12-04 15:17:54 -0500 | [diff] [blame] | 92 | } |
Stephen White | 37a46d2 | 2020-06-05 11:42:39 -0400 | [diff] [blame] | 93 | GrBackendApi api = context.fGrContext->backend(); |
| 94 | bool requiresEarlyAbandon = api == GrBackendApi::kVulkan || api == GrBackendApi::kDawn; |
Greg Daniel | f0e04f0 | 2019-12-04 15:17:54 -0500 | [diff] [blame] | 95 | if (requiresEarlyAbandon) { |
| 96 | context.fGrContext->abandonContext(); |
| 97 | } |
| 98 | if (context.fTestContext) { |
bsalomon | 18a2f9d | 2016-05-11 10:09:18 -0700 | [diff] [blame] | 99 | delete(context.fTestContext); |
| 100 | context.fTestContext = nullptr; |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 101 | } |
Greg Daniel | f0e04f0 | 2019-12-04 15:17:54 -0500 | [diff] [blame] | 102 | if (!requiresEarlyAbandon) { |
| 103 | context.fGrContext->abandonContext(); |
| 104 | } |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 105 | context.fAbandoned = true; |
kkinnunen | 3405800 | 2016-01-06 23:49:30 -0800 | [diff] [blame] | 106 | } |
kkinnunen | 3405800 | 2016-01-06 23:49:30 -0800 | [diff] [blame] | 107 | } |
| 108 | } |
| 109 | |
bsalomon | 6e2aad4 | 2016-04-01 11:54:31 -0700 | [diff] [blame] | 110 | void GrContextFactory::releaseResourcesAndAbandonContexts() { |
Greg Daniel | f0fe02f | 2018-01-16 11:20:41 -0500 | [diff] [blame] | 111 | // We must abandon the test contexts in reverse order so that any child context is finished and |
| 112 | // abandoned before a parent context. This relies on the fact that when we make a new context we |
| 113 | // append it to the end of fContexts array. |
| 114 | // TODO: Look into keeping a dependency dag for contexts and deletion order |
| 115 | for (int i = fContexts.count() - 1; i >= 0; --i) { |
| 116 | Context& context = fContexts[i]; |
Brian Salomon | 55ad774 | 2017-11-17 09:25:23 -0500 | [diff] [blame] | 117 | SkScopeExit restore(nullptr); |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 118 | if (!context.fAbandoned) { |
bsalomon | 18a2f9d | 2016-05-11 10:09:18 -0700 | [diff] [blame] | 119 | if (context.fTestContext) { |
Brian Salomon | 55ad774 | 2017-11-17 09:25:23 -0500 | [diff] [blame] | 120 | restore = context.fTestContext->makeCurrentAndAutoRestore(); |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 121 | } |
bsalomon | 6e2aad4 | 2016-04-01 11:54:31 -0700 | [diff] [blame] | 122 | context.fGrContext->releaseResourcesAndAbandonContext(); |
bsalomon | 18a2f9d | 2016-05-11 10:09:18 -0700 | [diff] [blame] | 123 | if (context.fTestContext) { |
| 124 | delete context.fTestContext; |
| 125 | context.fTestContext = nullptr; |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 126 | } |
Greg Daniel | f0e04f0 | 2019-12-04 15:17:54 -0500 | [diff] [blame] | 127 | context.fAbandoned = true; |
bsalomon | 6e2aad4 | 2016-04-01 11:54:31 -0700 | [diff] [blame] | 128 | } |
| 129 | } |
| 130 | } |
| 131 | |
Robert Phillips | 00f78de | 2020-07-01 16:09:43 -0400 | [diff] [blame] | 132 | GrDirectContext* GrContextFactory::get(ContextType type, ContextOverrides overrides) { |
| 133 | return this->getContextInfo(type, overrides).directContext(); |
Robert Phillips | cdabbcc | 2017-06-08 16:03:17 -0400 | [diff] [blame] | 134 | } |
| 135 | |
Brian Osman | 9eac2ea | 2017-02-24 14:51:44 -0500 | [diff] [blame] | 136 | ContextInfo GrContextFactory::getContextInfoInternal(ContextType type, ContextOverrides overrides, |
Robert Phillips | 00f78de | 2020-07-01 16:09:43 -0400 | [diff] [blame] | 137 | GrDirectContext* shareContext, |
| 138 | uint32_t shareIndex) { |
Brian Osman | 60c774d | 2017-02-21 16:58:08 -0500 | [diff] [blame] | 139 | // (shareIndex != 0) -> (shareContext != nullptr) |
| 140 | SkASSERT((shareIndex == 0) || (shareContext != nullptr)); |
| 141 | |
djsollen | e454521 | 2014-11-13 11:12:41 -0800 | [diff] [blame] | 142 | for (int i = 0; i < fContexts.count(); ++i) { |
kkinnunen | 3405800 | 2016-01-06 23:49:30 -0800 | [diff] [blame] | 143 | Context& context = fContexts[i]; |
kkinnunen | 3405800 | 2016-01-06 23:49:30 -0800 | [diff] [blame] | 144 | if (context.fType == type && |
csmartdalton | e812d49 | 2017-02-21 12:36:05 -0700 | [diff] [blame] | 145 | context.fOverrides == overrides && |
Brian Osman | 60c774d | 2017-02-21 16:58:08 -0500 | [diff] [blame] | 146 | context.fShareContext == shareContext && |
| 147 | context.fShareIndex == shareIndex && |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 148 | !context.fAbandoned) { |
bsalomon | 18a2f9d | 2016-05-11 10:09:18 -0700 | [diff] [blame] | 149 | context.fTestContext->makeCurrent(); |
Brian Salomon | 43f8bf0 | 2017-10-18 08:33:29 -0400 | [diff] [blame] | 150 | return ContextInfo(context.fType, context.fTestContext, context.fGrContext, |
| 151 | context.fOptions); |
djsollen | e454521 | 2014-11-13 11:12:41 -0800 | [diff] [blame] | 152 | } |
| 153 | } |
Brian Osman | 60c774d | 2017-02-21 16:58:08 -0500 | [diff] [blame] | 154 | |
Leon Scroggins III | 7530639 | 2020-07-30 16:07:01 -0400 | [diff] [blame] | 155 | // If we're trying to create a context in a share group, find the primary context |
| 156 | Context* primaryContext = nullptr; |
Brian Osman | 60c774d | 2017-02-21 16:58:08 -0500 | [diff] [blame] | 157 | if (shareContext) { |
| 158 | for (int i = 0; i < fContexts.count(); ++i) { |
| 159 | if (!fContexts[i].fAbandoned && fContexts[i].fGrContext == shareContext) { |
Leon Scroggins III | 7530639 | 2020-07-30 16:07:01 -0400 | [diff] [blame] | 160 | primaryContext = &fContexts[i]; |
Brian Osman | 60c774d | 2017-02-21 16:58:08 -0500 | [diff] [blame] | 161 | break; |
| 162 | } |
| 163 | } |
Leon Scroggins III | 7530639 | 2020-07-30 16:07:01 -0400 | [diff] [blame] | 164 | SkASSERT(primaryContext && primaryContext->fType == type); |
Brian Osman | 60c774d | 2017-02-21 16:58:08 -0500 | [diff] [blame] | 165 | } |
| 166 | |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 167 | std::unique_ptr<TestContext> testCtx; |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 168 | GrBackendApi backend = ContextTypeBackend(type); |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 169 | switch (backend) { |
John Rosasco | a9b348f | 2019-11-08 13:18:15 -0800 | [diff] [blame] | 170 | #ifdef SK_GL |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 171 | case GrBackendApi::kOpenGL: { |
Leon Scroggins III | 7530639 | 2020-07-30 16:07:01 -0400 | [diff] [blame] | 172 | GLTestContext* glShareContext = primaryContext |
| 173 | ? static_cast<GLTestContext*>(primaryContext->fTestContext) : nullptr; |
bsalomon | 18a2f9d | 2016-05-11 10:09:18 -0700 | [diff] [blame] | 174 | GLTestContext* glCtx; |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 175 | switch (type) { |
| 176 | case kGL_ContextType: |
Brian Osman | 60c774d | 2017-02-21 16:58:08 -0500 | [diff] [blame] | 177 | glCtx = CreatePlatformGLTestContext(kGL_GrGLStandard, glShareContext); |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 178 | break; |
| 179 | case kGLES_ContextType: |
Brian Osman | 60c774d | 2017-02-21 16:58:08 -0500 | [diff] [blame] | 180 | glCtx = CreatePlatformGLTestContext(kGLES_GrGLStandard, glShareContext); |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 181 | break; |
Mike Klein | c168a3a | 2016-11-14 14:53:13 +0000 | [diff] [blame] | 182 | #if SK_ANGLE |
bsalomon | 11abd8d | 2016-10-14 08:13:48 -0700 | [diff] [blame] | 183 | case kANGLE_D3D9_ES2_ContextType: |
Brian Osman | 60c774d | 2017-02-21 16:58:08 -0500 | [diff] [blame] | 184 | glCtx = MakeANGLETestContext(ANGLEBackend::kD3D9, ANGLEContextVersion::kES2, |
| 185 | glShareContext).release(); |
Brian Salomon | 414782d | 2020-04-17 09:34:17 -0400 | [diff] [blame] | 186 | // Chrome will only run on D3D9 with NVIDIA for 2012 and earlier drivers. |
| 187 | // (<= 269.73). We get shader link failures when testing on recent drivers |
| 188 | // using this backend. |
| 189 | if (glCtx) { |
Brian Salomon | 1989342 | 2021-05-06 15:11:43 -0400 | [diff] [blame] | 190 | GrGLDriverInfo info = GrGLGetDriverInfo(glCtx->gl()); |
Brian Salomon | 96263aa | 2021-05-07 13:42:17 -0400 | [diff] [blame] | 191 | if (info.fANGLEVendor == GrGLVendor::kNVIDIA) { |
Brian Salomon | 414782d | 2020-04-17 09:34:17 -0400 | [diff] [blame] | 192 | delete glCtx; |
| 193 | return ContextInfo(); |
| 194 | } |
| 195 | } |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 196 | break; |
bsalomon | 11abd8d | 2016-10-14 08:13:48 -0700 | [diff] [blame] | 197 | case kANGLE_D3D11_ES2_ContextType: |
Brian Osman | 60c774d | 2017-02-21 16:58:08 -0500 | [diff] [blame] | 198 | glCtx = MakeANGLETestContext(ANGLEBackend::kD3D11, ANGLEContextVersion::kES2, |
| 199 | glShareContext).release(); |
bsalomon | 11abd8d | 2016-10-14 08:13:48 -0700 | [diff] [blame] | 200 | break; |
| 201 | case kANGLE_D3D11_ES3_ContextType: |
Brian Osman | 60c774d | 2017-02-21 16:58:08 -0500 | [diff] [blame] | 202 | glCtx = MakeANGLETestContext(ANGLEBackend::kD3D11, ANGLEContextVersion::kES3, |
| 203 | glShareContext).release(); |
bsalomon | 11abd8d | 2016-10-14 08:13:48 -0700 | [diff] [blame] | 204 | break; |
| 205 | case kANGLE_GL_ES2_ContextType: |
Brian Osman | 60c774d | 2017-02-21 16:58:08 -0500 | [diff] [blame] | 206 | glCtx = MakeANGLETestContext(ANGLEBackend::kOpenGL, ANGLEContextVersion::kES2, |
| 207 | glShareContext).release(); |
bsalomon | 11abd8d | 2016-10-14 08:13:48 -0700 | [diff] [blame] | 208 | break; |
| 209 | case kANGLE_GL_ES3_ContextType: |
Brian Osman | 60c774d | 2017-02-21 16:58:08 -0500 | [diff] [blame] | 210 | glCtx = MakeANGLETestContext(ANGLEBackend::kOpenGL, ANGLEContextVersion::kES3, |
| 211 | glShareContext).release(); |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 212 | break; |
Mike Klein | c168a3a | 2016-11-14 14:53:13 +0000 | [diff] [blame] | 213 | #endif |
Kevin Lubick | ffce079 | 2017-05-24 15:30:35 -0400 | [diff] [blame] | 214 | #ifndef SK_NO_COMMAND_BUFFER |
Chris Dalton | e0f4de6 | 2021-06-28 08:43:08 -0600 | [diff] [blame] | 215 | case kCommandBuffer_ES2_ContextType: |
| 216 | glCtx = CommandBufferGLTestContext::Create(2, glShareContext); |
| 217 | break; |
| 218 | case kCommandBuffer_ES3_ContextType: |
| 219 | glCtx = CommandBufferGLTestContext::Create(3, glShareContext); |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 220 | break; |
Kevin Lubick | ffce079 | 2017-05-24 15:30:35 -0400 | [diff] [blame] | 221 | #endif |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 222 | default: |
| 223 | return ContextInfo(); |
| 224 | } |
bsalomon | 18a2f9d | 2016-05-11 10:09:18 -0700 | [diff] [blame] | 225 | if (!glCtx) { |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 226 | return ContextInfo(); |
| 227 | } |
Brian Salomon | b2b7f80 | 2020-08-26 15:27:03 -0400 | [diff] [blame] | 228 | if (glCtx->gl()->fStandard == kGLES_GrGLStandard && |
| 229 | (overrides & ContextOverrides::kFakeGLESVersionAs2)) { |
| 230 | glCtx->overrideVersion("OpenGL ES 2.0", "OpenGL ES GLSL ES 1.00"); |
| 231 | } |
bsalomon | 18a2f9d | 2016-05-11 10:09:18 -0700 | [diff] [blame] | 232 | testCtx.reset(glCtx); |
djsollen | e454521 | 2014-11-13 11:12:41 -0800 | [diff] [blame] | 233 | break; |
bsalomon | 18a2f9d | 2016-05-11 10:09:18 -0700 | [diff] [blame] | 234 | } |
John Rosasco | a9b348f | 2019-11-08 13:18:15 -0800 | [diff] [blame] | 235 | #endif // SK_GL |
jvanverth | a50e17a | 2015-08-12 12:19:36 -0700 | [diff] [blame] | 236 | #ifdef SK_VULKAN |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 237 | case GrBackendApi::kVulkan: { |
Leon Scroggins III | 7530639 | 2020-07-30 16:07:01 -0400 | [diff] [blame] | 238 | VkTestContext* vkSharedContext = primaryContext |
| 239 | ? static_cast<VkTestContext*>(primaryContext->fTestContext) : nullptr; |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 240 | SkASSERT(kVulkan_ContextType == type); |
Greg Daniel | 604b197 | 2017-05-15 13:50:35 -0400 | [diff] [blame] | 241 | testCtx.reset(CreatePlatformVkTestContext(vkSharedContext)); |
bsalomon | 18a2f9d | 2016-05-11 10:09:18 -0700 | [diff] [blame] | 242 | if (!testCtx) { |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 243 | return ContextInfo(); |
| 244 | } |
bsalomon | 18a2f9d | 2016-05-11 10:09:18 -0700 | [diff] [blame] | 245 | |
Brian Salomon | f4ba4ec | 2020-03-19 15:54:28 -0400 | [diff] [blame] | 246 | // We previously had an issue where the VkDevice destruction would occasionally hang |
| 247 | // on systems with NVIDIA GPUs and having an existing GL context fixed it. Now (March |
| 248 | // 2020) we still need the GL context to keep Vulkan/TSAN bots from running incredibly |
| 249 | // slow. Perhaps this prevents repeated driver loading/unloading? Note that keeping |
| 250 | // a persistent VkTestContext around instead was tried and did not work. |
Brian Salomon | 7f9c29a | 2017-01-24 22:22:05 +0000 | [diff] [blame] | 251 | if (!fSentinelGLContext) { |
| 252 | fSentinelGLContext.reset(CreatePlatformGLTestContext(kGL_GrGLStandard)); |
| 253 | if (!fSentinelGLContext) { |
| 254 | fSentinelGLContext.reset(CreatePlatformGLTestContext(kGLES_GrGLStandard)); |
| 255 | } |
| 256 | } |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 257 | break; |
Greg Daniel | 604b197 | 2017-05-15 13:50:35 -0400 | [diff] [blame] | 258 | } |
jvanverth | a50e17a | 2015-08-12 12:19:36 -0700 | [diff] [blame] | 259 | #endif |
Greg Daniel | b76a72a | 2017-07-13 15:07:54 -0400 | [diff] [blame] | 260 | #ifdef SK_METAL |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 261 | case GrBackendApi::kMetal: { |
Leon Scroggins III | 7530639 | 2020-07-30 16:07:01 -0400 | [diff] [blame] | 262 | MtlTestContext* mtlSharedContext = primaryContext |
| 263 | ? static_cast<MtlTestContext*>(primaryContext->fTestContext) : nullptr; |
Jim Van Verth | a3407ab | 2019-03-15 15:22:39 -0400 | [diff] [blame] | 264 | SkASSERT(kMetal_ContextType == type); |
| 265 | testCtx.reset(CreatePlatformMtlTestContext(mtlSharedContext)); |
Greg Daniel | b76a72a | 2017-07-13 15:07:54 -0400 | [diff] [blame] | 266 | if (!testCtx) { |
| 267 | return ContextInfo(); |
| 268 | } |
| 269 | break; |
| 270 | } |
| 271 | #endif |
Jim Van Verth | b01e12b | 2020-02-18 14:34:38 -0500 | [diff] [blame] | 272 | #ifdef SK_DIRECT3D |
| 273 | case GrBackendApi::kDirect3D: { |
Leon Scroggins III | 7530639 | 2020-07-30 16:07:01 -0400 | [diff] [blame] | 274 | D3DTestContext* d3dSharedContext = primaryContext |
| 275 | ? static_cast<D3DTestContext*>(primaryContext->fTestContext) : nullptr; |
Jim Van Verth | b01e12b | 2020-02-18 14:34:38 -0500 | [diff] [blame] | 276 | SkASSERT(kDirect3D_ContextType == type); |
| 277 | testCtx.reset(CreatePlatformD3DTestContext(d3dSharedContext)); |
| 278 | if (!testCtx) { |
| 279 | return ContextInfo(); |
| 280 | } |
| 281 | break; |
| 282 | } |
| 283 | #endif |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 284 | #ifdef SK_DAWN |
| 285 | case GrBackendApi::kDawn: { |
Leon Scroggins III | 7530639 | 2020-07-30 16:07:01 -0400 | [diff] [blame] | 286 | DawnTestContext* dawnSharedContext = primaryContext |
| 287 | ? static_cast<DawnTestContext*>(primaryContext->fTestContext) : nullptr; |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 288 | testCtx.reset(CreatePlatformDawnTestContext(dawnSharedContext)); |
| 289 | if (!testCtx) { |
| 290 | return ContextInfo(); |
| 291 | } |
| 292 | break; |
| 293 | } |
| 294 | #endif |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 295 | case GrBackendApi::kMock: { |
Leon Scroggins III | 7530639 | 2020-07-30 16:07:01 -0400 | [diff] [blame] | 296 | TestContext* sharedContext = primaryContext ? primaryContext->fTestContext : nullptr; |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 297 | SkASSERT(kMock_ContextType == type); |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 298 | testCtx.reset(CreateMockTestContext(sharedContext)); |
| 299 | if (!testCtx) { |
| 300 | return ContextInfo(); |
| 301 | } |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 302 | break; |
| 303 | } |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 304 | default: |
| 305 | return ContextInfo(); |
| 306 | } |
Brian Salomon | 55ad774 | 2017-11-17 09:25:23 -0500 | [diff] [blame] | 307 | |
bsalomon | 18a2f9d | 2016-05-11 10:09:18 -0700 | [diff] [blame] | 308 | SkASSERT(testCtx && testCtx->backend() == backend); |
csmartdalton | e0d3629 | 2016-07-29 08:14:20 -0700 | [diff] [blame] | 309 | GrContextOptions grOptions = fGlobalOptions; |
Eric Karl | 5c77975 | 2017-05-08 12:02:07 -0700 | [diff] [blame] | 310 | if (ContextOverrides::kAvoidStencilBuffers & overrides) { |
| 311 | grOptions.fAvoidStencilBuffers = true; |
| 312 | } |
Brian Salomon | 91216d5 | 2021-04-09 11:57:59 -0400 | [diff] [blame] | 313 | if (ContextOverrides::kReducedShaders & overrides) { |
| 314 | grOptions.fReducedShaderVariations = true; |
| 315 | } |
Robert Phillips | 00f78de | 2020-07-01 16:09:43 -0400 | [diff] [blame] | 316 | sk_sp<GrDirectContext> grCtx; |
Brian Salomon | 55ad774 | 2017-11-17 09:25:23 -0500 | [diff] [blame] | 317 | { |
| 318 | auto restore = testCtx->makeCurrentAndAutoRestore(); |
Robert Phillips | f4f8011 | 2020-07-13 16:13:31 -0400 | [diff] [blame] | 319 | grCtx = testCtx->makeContext(grOptions); |
Brian Salomon | 55ad774 | 2017-11-17 09:25:23 -0500 | [diff] [blame] | 320 | } |
John Stiles | a008b0f | 2020-08-16 08:48:02 -0400 | [diff] [blame] | 321 | if (!grCtx) { |
kkinnunen | 3405800 | 2016-01-06 23:49:30 -0800 | [diff] [blame] | 322 | return ContextInfo(); |
djsollen | e454521 | 2014-11-13 11:12:41 -0800 | [diff] [blame] | 323 | } |
kkinnunen | cfe62e3 | 2015-07-01 02:58:50 -0700 | [diff] [blame] | 324 | |
Robert Phillips | edff467 | 2021-03-11 09:16:25 -0500 | [diff] [blame] | 325 | if (shareContext) { |
| 326 | SkASSERT(grCtx->directContextID() != shareContext->directContextID()); |
| 327 | } |
| 328 | |
Greg Daniel | f0fe02f | 2018-01-16 11:20:41 -0500 | [diff] [blame] | 329 | // We must always add new contexts by pushing to the back so that when we delete them we delete |
| 330 | // them in reverse order in which they were made. |
kkinnunen | 3405800 | 2016-01-06 23:49:30 -0800 | [diff] [blame] | 331 | Context& context = fContexts.push_back(); |
bsalomon | 18a2f9d | 2016-05-11 10:09:18 -0700 | [diff] [blame] | 332 | context.fBackend = backend; |
| 333 | context.fTestContext = testCtx.release(); |
kkinnunen | 3405800 | 2016-01-06 23:49:30 -0800 | [diff] [blame] | 334 | context.fGrContext = SkRef(grCtx.get()); |
| 335 | context.fType = type; |
csmartdalton | e812d49 | 2017-02-21 12:36:05 -0700 | [diff] [blame] | 336 | context.fOverrides = overrides; |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 337 | context.fAbandoned = false; |
Brian Osman | 60c774d | 2017-02-21 16:58:08 -0500 | [diff] [blame] | 338 | context.fShareContext = shareContext; |
| 339 | context.fShareIndex = shareIndex; |
Brian Salomon | 43f8bf0 | 2017-10-18 08:33:29 -0400 | [diff] [blame] | 340 | context.fOptions = grOptions; |
Brian Salomon | 55ad774 | 2017-11-17 09:25:23 -0500 | [diff] [blame] | 341 | context.fTestContext->makeCurrent(); |
Brian Salomon | 43f8bf0 | 2017-10-18 08:33:29 -0400 | [diff] [blame] | 342 | return ContextInfo(context.fType, context.fTestContext, context.fGrContext, context.fOptions); |
djsollen | e454521 | 2014-11-13 11:12:41 -0800 | [diff] [blame] | 343 | } |
Brian Osman | 60c774d | 2017-02-21 16:58:08 -0500 | [diff] [blame] | 344 | |
Brian Osman | 9eac2ea | 2017-02-24 14:51:44 -0500 | [diff] [blame] | 345 | ContextInfo GrContextFactory::getContextInfo(ContextType type, ContextOverrides overrides) { |
| 346 | return this->getContextInfoInternal(type, overrides, nullptr, 0); |
| 347 | } |
| 348 | |
Robert Phillips | 00f78de | 2020-07-01 16:09:43 -0400 | [diff] [blame] | 349 | ContextInfo GrContextFactory::getSharedContextInfo(GrDirectContext* shareContext, |
| 350 | uint32_t shareIndex) { |
Brian Osman | 9eac2ea | 2017-02-24 14:51:44 -0500 | [diff] [blame] | 351 | SkASSERT(shareContext); |
| 352 | for (int i = 0; i < fContexts.count(); ++i) { |
| 353 | if (!fContexts[i].fAbandoned && fContexts[i].fGrContext == shareContext) { |
| 354 | return this->getContextInfoInternal(fContexts[i].fType, fContexts[i].fOverrides, |
| 355 | shareContext, shareIndex); |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | return ContextInfo(); |
| 360 | } |
| 361 | |
bsalomon | 3724e57 | 2016-03-30 18:56:19 -0700 | [diff] [blame] | 362 | } // namespace sk_gpu_test |