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