bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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. |
| 6 | */ |
| 7 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "include/gpu/GrBackendSurface.h" |
| 9 | #include "include/gpu/GrContextOptions.h" |
| 10 | #include "include/gpu/GrSurface.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "include/private/GrTypesPriv.h" |
| 12 | #include "src/gpu/GrCaps.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 13 | #include "src/gpu/GrSurfaceProxy.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 14 | #include "src/gpu/GrWindowRectangles.h" |
| 15 | #include "src/utils/SkJSONWriter.h" |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 16 | |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 17 | GrCaps::GrCaps(const GrContextOptions& options) { |
| 18 | fMipMapSupport = false; |
| 19 | fNPOTTextureTileSupport = false; |
brianosman | a635936 | 2016-03-21 06:55:37 -0700 | [diff] [blame] | 20 | fSRGBSupport = false; |
brianosman | 35b784d | 2016-05-05 11:52:53 -0700 | [diff] [blame] | 21 | fSRGBWriteControl = false; |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 22 | fReuseScratchTextures = true; |
robertphillips | 1b8e1b5 | 2015-06-24 06:54:10 -0700 | [diff] [blame] | 23 | fReuseScratchBuffers = true; |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 24 | fGpuTracingSupport = false; |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 25 | fOversizedStencilSupport = false; |
| 26 | fTextureBarrierSupport = false; |
Robert Phillips | 7f86192 | 2018-01-30 13:13:42 +0000 | [diff] [blame] | 27 | fSampleLocationsSupport = false; |
csmartdalton | 2b5f2cb | 2016-06-10 14:06:32 -0700 | [diff] [blame] | 28 | fMultisampleDisableSupport = false; |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 29 | fInstanceAttribSupport = false; |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 30 | fMixedSamplesSupport = false; |
Chris Dalton | d5d8a64 | 2019-08-08 15:29:20 -0600 | [diff] [blame] | 31 | fMSAAResolvesAutomatically = false; |
Chris Dalton | 27059d3 | 2018-01-23 14:06:50 -0700 | [diff] [blame] | 32 | fUsePrimitiveRestart = false; |
csmartdalton | 485a120 | 2016-07-13 10:16:32 -0700 | [diff] [blame] | 33 | fPreferClientSideDynamicBuffers = false; |
Chris Dalton | 344e903 | 2017-12-11 15:42:09 -0700 | [diff] [blame] | 34 | fPreferFullscreenClears = false; |
bsalomon | 7dea7b7 | 2015-08-19 08:26:51 -0700 | [diff] [blame] | 35 | fMustClearUploadedBufferData = false; |
Kevin Lubick | 61a5f0a | 2019-03-28 09:47:15 -0400 | [diff] [blame] | 36 | fShouldInitializeTextures = false; |
Greg Daniel | b2acf0a | 2018-09-12 09:17:11 -0400 | [diff] [blame] | 37 | fSupportsAHardwareBufferImages = false; |
jvanverth | 84741b3 | 2016-09-30 08:39:02 -0700 | [diff] [blame] | 38 | fFenceSyncSupport = false; |
Brian Salomon | 9ff5acb | 2019-05-08 09:04:47 -0400 | [diff] [blame] | 39 | fSemaphoreSupport = false; |
Brian Osman | 2c2bc11 | 2017-02-28 10:02:49 -0500 | [diff] [blame] | 40 | fCrossContextTextureSupport = false; |
Brian Osman | 499bf1a | 2018-09-17 11:32:42 -0400 | [diff] [blame] | 41 | fHalfFloatVertexAttributeSupport = false; |
Brian Salomon | f723264 | 2018-09-19 08:58:08 -0400 | [diff] [blame] | 42 | fDynamicStateArrayGeometryProcessorTextureSupport = false; |
Michael Ludwig | a21d196 | 2019-01-11 15:26:22 -0500 | [diff] [blame] | 43 | fPerformPartialClearsAsDraws = false; |
| 44 | fPerformColorClearsAsDraws = false; |
| 45 | fPerformStencilClearsAsDraws = false; |
Chris Dalton | a8fbeba | 2019-03-30 00:31:23 -0600 | [diff] [blame] | 46 | fAllowCoverageCounting = false; |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 47 | fTransferBufferSupport = false; |
Brian Salomon | 1047a49 | 2019-07-02 12:25:21 -0400 | [diff] [blame] | 48 | fWritePixelsRowBytesSupport = false; |
| 49 | fReadPixelsRowBytesSupport = false; |
Chris Dalton | a8fbeba | 2019-03-30 00:31:23 -0600 | [diff] [blame] | 50 | fDriverBlacklistCCPR = false; |
Chris Dalton | 7c01208 | 2019-07-22 00:45:52 -0400 | [diff] [blame] | 51 | fDriverBlacklistMSAACCPR = false; |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 52 | |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 53 | fBlendEquationSupport = kBasic_BlendEquationSupport; |
cdalton | 1dd0542 | 2015-06-12 09:01:18 -0700 | [diff] [blame] | 54 | fAdvBlendEqBlacklist = 0; |
| 55 | |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 56 | fMapBufferFlags = kNone_MapFlags; |
| 57 | |
bsalomon | 7dbd45d | 2016-03-23 10:40:53 -0700 | [diff] [blame] | 58 | fMaxVertexAttributes = 0; |
egdaniel | ff1d547 | 2015-09-10 08:37:20 -0700 | [diff] [blame] | 59 | fMaxRenderTargetSize = 1; |
Chris Dalton | 2612bae | 2018-02-22 13:41:37 -0700 | [diff] [blame] | 60 | fMaxPreferredRenderTargetSize = 1; |
egdaniel | ff1d547 | 2015-09-10 08:37:20 -0700 | [diff] [blame] | 61 | fMaxTextureSize = 1; |
csmartdalton | 9bc1187 | 2016-08-09 12:42:47 -0700 | [diff] [blame] | 62 | fMaxWindowRectangles = 0; |
Chris Dalton | a1638a5 | 2019-06-24 11:54:24 -0600 | [diff] [blame] | 63 | fInternalMultisampleCount = 0; |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 64 | |
robertphillips | caef345 | 2015-11-11 13:18:11 -0800 | [diff] [blame] | 65 | fSuppressPrints = options.fSuppressPrints; |
Brian Osman | 195c05b | 2017-08-30 15:14:04 -0400 | [diff] [blame] | 66 | #if GR_TEST_UTILS |
Jim Van Verth | fbdc080 | 2017-05-02 16:15:53 -0400 | [diff] [blame] | 67 | fWireframeMode = options.fWireframeMode; |
Brian Osman | 195c05b | 2017-08-30 15:14:04 -0400 | [diff] [blame] | 68 | #else |
| 69 | fWireframeMode = false; |
| 70 | #endif |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 71 | fBufferMapThreshold = options.fBufferMapThreshold; |
Eric Karl | 5c77975 | 2017-05-08 12:02:07 -0700 | [diff] [blame] | 72 | fAvoidStencilBuffers = false; |
Greg Daniel | 4374e96 | 2018-09-28 15:09:47 -0400 | [diff] [blame] | 73 | fAvoidWritePixelsFastPath = false; |
robertphillips | 6392668 | 2015-08-20 09:39:02 -0700 | [diff] [blame] | 74 | |
| 75 | fPreferVRAMUseOverFlushes = true; |
Adrienne Walker | ab7181d | 2018-05-14 14:02:03 -0700 | [diff] [blame] | 76 | |
Chris Dalton | 0dffbab | 2019-03-27 13:08:50 -0600 | [diff] [blame] | 77 | fPreferTrianglesOverSampleMask = false; |
| 78 | |
Michael Ludwig | f23a152 | 2018-12-10 11:36:13 -0500 | [diff] [blame] | 79 | // Default to true, allow older versions of OpenGL to disable explicitly |
| 80 | fClampToBorderSupport = true; |
| 81 | |
Adrienne Walker | ab7181d | 2018-05-14 14:02:03 -0700 | [diff] [blame] | 82 | fDriverBugWorkarounds = options.fDriverBugWorkarounds; |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 83 | } |
| 84 | |
bsalomon | 4ee6bd8 | 2015-05-27 13:23:23 -0700 | [diff] [blame] | 85 | void GrCaps::applyOptionsOverrides(const GrContextOptions& options) { |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 86 | this->onApplyOptionsOverrides(options); |
Brian Salomon | 01b476a | 2018-01-23 11:06:41 -0500 | [diff] [blame] | 87 | if (options.fDisableDriverCorrectnessWorkarounds) { |
Chris Dalton | a8fbeba | 2019-03-30 00:31:23 -0600 | [diff] [blame] | 88 | SkASSERT(!fDriverBlacklistCCPR); |
Chris Dalton | 7c01208 | 2019-07-22 00:45:52 -0400 | [diff] [blame] | 89 | SkASSERT(!fDriverBlacklistMSAACCPR); |
Brian Salomon | 01b476a | 2018-01-23 11:06:41 -0500 | [diff] [blame] | 90 | SkASSERT(!fAvoidStencilBuffers); |
| 91 | SkASSERT(!fAdvBlendEqBlacklist); |
Michael Ludwig | a21d196 | 2019-01-11 15:26:22 -0500 | [diff] [blame] | 92 | SkASSERT(!fPerformColorClearsAsDraws); |
| 93 | SkASSERT(!fPerformStencilClearsAsDraws); |
| 94 | // Don't check the partial-clear workaround, since that is a backend limitation, not a |
| 95 | // driver workaround (it just so happens the fallbacks are the same). |
| 96 | } |
| 97 | if (GrContextOptions::Enable::kNo == options.fUseDrawInsteadOfClear) { |
| 98 | fPerformColorClearsAsDraws = false; |
| 99 | fPerformStencilClearsAsDraws = false; |
| 100 | } else if (GrContextOptions::Enable::kYes == options.fUseDrawInsteadOfClear) { |
| 101 | fPerformColorClearsAsDraws = true; |
| 102 | fPerformStencilClearsAsDraws = true; |
Brian Salomon | 01b476a | 2018-01-23 11:06:41 -0500 | [diff] [blame] | 103 | } |
| 104 | |
Chris Dalton | a8fbeba | 2019-03-30 00:31:23 -0600 | [diff] [blame] | 105 | fAllowCoverageCounting = !options.fDisableCoverageCountingPaths; |
| 106 | |
bsalomon | 4ee6bd8 | 2015-05-27 13:23:23 -0700 | [diff] [blame] | 107 | fMaxTextureSize = SkTMin(fMaxTextureSize, options.fMaxTextureSizeOverride); |
Brian Osman | 195c05b | 2017-08-30 15:14:04 -0400 | [diff] [blame] | 108 | fMaxTileSize = fMaxTextureSize; |
| 109 | #if GR_TEST_UTILS |
bsalomon | 8c07b7a | 2015-11-02 11:36:52 -0800 | [diff] [blame] | 110 | // If the max tile override is zero, it means we should use the max texture size. |
Brian Osman | 195c05b | 2017-08-30 15:14:04 -0400 | [diff] [blame] | 111 | if (options.fMaxTileSizeOverride && options.fMaxTileSizeOverride < fMaxTextureSize) { |
bsalomon | 8c07b7a | 2015-11-02 11:36:52 -0800 | [diff] [blame] | 112 | fMaxTileSize = options.fMaxTileSizeOverride; |
| 113 | } |
Chris Dalton | 040238b | 2017-12-18 14:22:34 -0700 | [diff] [blame] | 114 | if (options.fSuppressGeometryShaders) { |
| 115 | fShaderCaps->fGeometryShaderSupport = false; |
| 116 | } |
Brian Salomon | a3e2996 | 2019-07-16 11:52:08 -0400 | [diff] [blame] | 117 | if (options.fClearAllTextures) { |
| 118 | fShouldInitializeTextures = true; |
| 119 | } |
Brian Osman | 195c05b | 2017-08-30 15:14:04 -0400 | [diff] [blame] | 120 | #endif |
Chris Dalton | 1e6c5b8 | 2019-06-17 14:16:49 -0600 | [diff] [blame] | 121 | |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 122 | if (fMaxWindowRectangles > GrWindowRectangles::kMaxWindows) { |
csmartdalton | 7535f41 | 2016-08-23 06:51:00 -0700 | [diff] [blame] | 123 | SkDebugf("WARNING: capping window rectangles at %i. HW advertises support for %i.\n", |
| 124 | GrWindowRectangles::kMaxWindows, fMaxWindowRectangles); |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 125 | fMaxWindowRectangles = GrWindowRectangles::kMaxWindows; |
| 126 | } |
Chris Dalton | 1e6c5b8 | 2019-06-17 14:16:49 -0600 | [diff] [blame] | 127 | |
Chris Dalton | a1638a5 | 2019-06-24 11:54:24 -0600 | [diff] [blame] | 128 | fInternalMultisampleCount = options.fInternalMultisampleCount; |
Chris Dalton | 1e6c5b8 | 2019-06-17 14:16:49 -0600 | [diff] [blame] | 129 | |
Eric Karl | 5c77975 | 2017-05-08 12:02:07 -0700 | [diff] [blame] | 130 | fAvoidStencilBuffers = options.fAvoidStencilBuffers; |
Adrienne Walker | ab7181d | 2018-05-14 14:02:03 -0700 | [diff] [blame] | 131 | |
| 132 | fDriverBugWorkarounds.applyOverrides(options.fDriverBugWorkarounds); |
bsalomon | 4ee6bd8 | 2015-05-27 13:23:23 -0700 | [diff] [blame] | 133 | } |
| 134 | |
Kevin Lubick | f4def34 | 2018-10-04 12:52:50 -0400 | [diff] [blame] | 135 | |
| 136 | #ifdef SK_ENABLE_DUMP_GPU |
Robert Phillips | bac4672 | 2019-08-01 15:09:17 -0400 | [diff] [blame] | 137 | #include "src/gpu/GrTestUtils.h" |
Kevin Lubick | f4def34 | 2018-10-04 12:52:50 -0400 | [diff] [blame] | 138 | |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 139 | static SkString map_flags_to_string(uint32_t flags) { |
| 140 | SkString str; |
| 141 | if (GrCaps::kNone_MapFlags == flags) { |
| 142 | str = "none"; |
| 143 | } else { |
| 144 | SkASSERT(GrCaps::kCanMap_MapFlag & flags); |
| 145 | SkDEBUGCODE(flags &= ~GrCaps::kCanMap_MapFlag); |
| 146 | str = "can_map"; |
| 147 | |
| 148 | if (GrCaps::kSubset_MapFlag & flags) { |
| 149 | str.append(" partial"); |
| 150 | } else { |
| 151 | str.append(" full"); |
| 152 | } |
| 153 | SkDEBUGCODE(flags &= ~GrCaps::kSubset_MapFlag); |
Brian Salomon | 105d7c2 | 2019-04-16 13:46:14 -0400 | [diff] [blame] | 154 | if (GrCaps::kAsyncRead_MapFlag & flags) { |
| 155 | str.append(" async_read"); |
| 156 | } else { |
| 157 | str.append(" sync_read"); |
| 158 | } |
| 159 | SkDEBUGCODE(flags &= ~GrCaps::kAsyncRead_MapFlag); |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 160 | } |
| 161 | SkASSERT(0 == flags); // Make sure we handled all the flags. |
| 162 | return str; |
| 163 | } |
| 164 | |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 165 | void GrCaps::dumpJSON(SkJSONWriter* writer) const { |
| 166 | writer->beginObject(); |
jvanverth | 84741b3 | 2016-09-30 08:39:02 -0700 | [diff] [blame] | 167 | |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 168 | writer->appendBool("MIP Map Support", fMipMapSupport); |
| 169 | writer->appendBool("NPOT Texture Tile Support", fNPOTTextureTileSupport); |
| 170 | writer->appendBool("sRGB Support", fSRGBSupport); |
| 171 | writer->appendBool("sRGB Write Control", fSRGBWriteControl); |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 172 | writer->appendBool("Reuse Scratch Textures", fReuseScratchTextures); |
| 173 | writer->appendBool("Reuse Scratch Buffers", fReuseScratchBuffers); |
| 174 | writer->appendBool("Gpu Tracing Support", fGpuTracingSupport); |
| 175 | writer->appendBool("Oversized Stencil Support", fOversizedStencilSupport); |
| 176 | writer->appendBool("Texture Barrier Support", fTextureBarrierSupport); |
Robert Phillips | 7f86192 | 2018-01-30 13:13:42 +0000 | [diff] [blame] | 177 | writer->appendBool("Sample Locations Support", fSampleLocationsSupport); |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 178 | writer->appendBool("Multisample disable support", fMultisampleDisableSupport); |
| 179 | writer->appendBool("Instance Attrib Support", fInstanceAttribSupport); |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 180 | writer->appendBool("Mixed Samples Support", fMixedSamplesSupport); |
Chris Dalton | d5d8a64 | 2019-08-08 15:29:20 -0600 | [diff] [blame] | 181 | writer->appendBool("MSAA Resolves Automatically", fMSAAResolvesAutomatically); |
Chris Dalton | 27059d3 | 2018-01-23 14:06:50 -0700 | [diff] [blame] | 182 | writer->appendBool("Use primitive restart", fUsePrimitiveRestart); |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 183 | writer->appendBool("Prefer client-side dynamic buffers", fPreferClientSideDynamicBuffers); |
Chris Dalton | 344e903 | 2017-12-11 15:42:09 -0700 | [diff] [blame] | 184 | writer->appendBool("Prefer fullscreen clears", fPreferFullscreenClears); |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 185 | writer->appendBool("Must clear buffer memory", fMustClearUploadedBufferData); |
Kevin Lubick | 61a5f0a | 2019-03-28 09:47:15 -0400 | [diff] [blame] | 186 | writer->appendBool("Should initialize textures", fShouldInitializeTextures); |
Greg Daniel | b2acf0a | 2018-09-12 09:17:11 -0400 | [diff] [blame] | 187 | writer->appendBool("Supports importing AHardwareBuffers", fSupportsAHardwareBufferImages); |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 188 | writer->appendBool("Fence sync support", fFenceSyncSupport); |
Brian Salomon | 9ff5acb | 2019-05-08 09:04:47 -0400 | [diff] [blame] | 189 | writer->appendBool("Semaphore support", fSemaphoreSupport); |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 190 | writer->appendBool("Cross context texture support", fCrossContextTextureSupport); |
Brian Osman | 499bf1a | 2018-09-17 11:32:42 -0400 | [diff] [blame] | 191 | writer->appendBool("Half float vertex attribute support", fHalfFloatVertexAttributeSupport); |
Brian Salomon | f723264 | 2018-09-19 08:58:08 -0400 | [diff] [blame] | 192 | writer->appendBool("Specify GeometryProcessor textures as a dynamic state array", |
| 193 | fDynamicStateArrayGeometryProcessorTextureSupport); |
Michael Ludwig | a21d196 | 2019-01-11 15:26:22 -0500 | [diff] [blame] | 194 | writer->appendBool("Use draws for partial clears", fPerformPartialClearsAsDraws); |
| 195 | writer->appendBool("Use draws for color clears", fPerformColorClearsAsDraws); |
| 196 | writer->appendBool("Use draws for stencil clip clears", fPerformStencilClearsAsDraws); |
Chris Dalton | a8fbeba | 2019-03-30 00:31:23 -0600 | [diff] [blame] | 197 | writer->appendBool("Allow coverage counting shortcuts", fAllowCoverageCounting); |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 198 | writer->appendBool("Supports transfer buffers", fTransferBufferSupport); |
Brian Salomon | 1047a49 | 2019-07-02 12:25:21 -0400 | [diff] [blame] | 199 | writer->appendBool("Write pixels row bytes support", fWritePixelsRowBytesSupport); |
| 200 | writer->appendBool("Read pixels row bytes support", fReadPixelsRowBytesSupport); |
Chris Dalton | a8fbeba | 2019-03-30 00:31:23 -0600 | [diff] [blame] | 201 | writer->appendBool("Blacklist CCPR on current driver [workaround]", fDriverBlacklistCCPR); |
Chris Dalton | 7c01208 | 2019-07-22 00:45:52 -0400 | [diff] [blame] | 202 | writer->appendBool("Blacklist MSAA version of CCPR on current driver [workaround]", |
| 203 | fDriverBlacklistMSAACCPR); |
Michael Ludwig | a21d196 | 2019-01-11 15:26:22 -0500 | [diff] [blame] | 204 | writer->appendBool("Clamp-to-border", fClampToBorderSupport); |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 205 | |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 206 | writer->appendBool("Prefer VRAM Use over flushes [workaround]", fPreferVRAMUseOverFlushes); |
Chris Dalton | 0dffbab | 2019-03-27 13:08:50 -0600 | [diff] [blame] | 207 | writer->appendBool("Prefer more triangles over sample mask [MSAA only]", |
| 208 | fPreferTrianglesOverSampleMask); |
Robert Phillips | f2ec024 | 2018-03-01 16:51:25 -0500 | [diff] [blame] | 209 | writer->appendBool("Avoid stencil buffers [workaround]", fAvoidStencilBuffers); |
robertphillips | 6392668 | 2015-08-20 09:39:02 -0700 | [diff] [blame] | 210 | |
cdalton | 1dd0542 | 2015-06-12 09:01:18 -0700 | [diff] [blame] | 211 | if (this->advancedBlendEquationSupport()) { |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 212 | writer->appendHexU32("Advanced Blend Equation Blacklist", fAdvBlendEqBlacklist); |
cdalton | 1dd0542 | 2015-06-12 09:01:18 -0700 | [diff] [blame] | 213 | } |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 214 | |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 215 | writer->appendS32("Max Vertex Attributes", fMaxVertexAttributes); |
| 216 | writer->appendS32("Max Texture Size", fMaxTextureSize); |
| 217 | writer->appendS32("Max Render Target Size", fMaxRenderTargetSize); |
Chris Dalton | 2612bae | 2018-02-22 13:41:37 -0700 | [diff] [blame] | 218 | writer->appendS32("Max Preferred Render Target Size", fMaxPreferredRenderTargetSize); |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 219 | writer->appendS32("Max Window Rectangles", fMaxWindowRectangles); |
Chris Dalton | 1e6c5b8 | 2019-06-17 14:16:49 -0600 | [diff] [blame] | 220 | writer->appendS32("Preferred Sample Count for Internal MSAA and Mixed Samples", |
Chris Dalton | a1638a5 | 2019-06-24 11:54:24 -0600 | [diff] [blame] | 221 | fInternalMultisampleCount); |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 222 | |
| 223 | static const char* kBlendEquationSupportNames[] = { |
| 224 | "Basic", |
| 225 | "Advanced", |
| 226 | "Advanced Coherent", |
| 227 | }; |
| 228 | GR_STATIC_ASSERT(0 == kBasic_BlendEquationSupport); |
| 229 | GR_STATIC_ASSERT(1 == kAdvanced_BlendEquationSupport); |
| 230 | GR_STATIC_ASSERT(2 == kAdvancedCoherent_BlendEquationSupport); |
| 231 | GR_STATIC_ASSERT(SK_ARRAY_COUNT(kBlendEquationSupportNames) == kLast_BlendEquationSupport + 1); |
| 232 | |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 233 | writer->appendString("Blend Equation Support", |
| 234 | kBlendEquationSupportNames[fBlendEquationSupport]); |
| 235 | writer->appendString("Map Buffer Support", map_flags_to_string(fMapBufferFlags).c_str()); |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 236 | |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 237 | writer->beginArray("configs"); |
| 238 | |
Greg Daniel | eadfac9 | 2019-08-02 09:03:53 -0400 | [diff] [blame] | 239 | // TODO: Either move this logic into individual backends dump and do it based on format and |
| 240 | // colorType, or have a loop printing out the defaults for given GrColorTypes. Or both. |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 241 | for (size_t i = 1; i < kGrPixelConfigCnt; ++i) { |
Brian Osman | 0f450ac | 2017-08-09 20:45:52 +0000 | [diff] [blame] | 242 | GrPixelConfig config = static_cast<GrPixelConfig>(i); |
Brian Osman | 8048822 | 2017-08-10 13:29:30 -0400 | [diff] [blame] | 243 | writer->beginObject(nullptr, false); |
Robert Phillips | bac4672 | 2019-08-01 15:09:17 -0400 | [diff] [blame] | 244 | writer->appendString("name", GrPixelConfigToStr(config)); |
Greg Daniel | eadfac9 | 2019-08-02 09:03:53 -0400 | [diff] [blame] | 245 | //writer->appendS32("max sample count", this->maxRenderTargetSampleCount(config)); |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 246 | // writer->appendBool("texturable", this->isConfigTexturable(config)); |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 247 | writer->endObject(); |
Brian Osman | 0f450ac | 2017-08-09 20:45:52 +0000 | [diff] [blame] | 248 | } |
Brian Osman | 175af0d | 2017-08-09 14:29:36 -0400 | [diff] [blame] | 249 | |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 250 | writer->endArray(); |
| 251 | |
| 252 | this->onDumpJSON(writer); |
| 253 | |
| 254 | writer->appendName("shaderCaps"); |
| 255 | this->shaderCaps()->dumpJSON(writer); |
| 256 | |
| 257 | writer->endObject(); |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 258 | } |
Kevin Lubick | f4def34 | 2018-10-04 12:52:50 -0400 | [diff] [blame] | 259 | #else |
| 260 | void GrCaps::dumpJSON(SkJSONWriter* writer) const { } |
| 261 | #endif |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 262 | |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 263 | bool GrCaps::surfaceSupportsWritePixels(const GrSurface* surface) const { |
| 264 | return surface->readOnly() ? false : this->onSurfaceSupportsWritePixels(surface); |
| 265 | } |
| 266 | |
| 267 | bool GrCaps::canCopySurface(const GrSurfaceProxy* dst, const GrSurfaceProxy* src, |
| 268 | const SkIRect& srcRect, const SkIPoint& dstPoint) const { |
Greg Daniel | 2c3398d | 2019-06-19 11:58:01 -0400 | [diff] [blame] | 269 | if (dst->readOnly()) { |
| 270 | return false; |
| 271 | } |
| 272 | // Currently we only ever do copies where the configs are the same. This check really should be |
| 273 | // checking if the backend formats, color types, and swizzle are compatible. Our copy always |
| 274 | // copies exact byte to byte from src to dst so when need to check the if we do this, the dst |
| 275 | // has the expected values stored in the right places taking the swizzle into account. For now |
| 276 | // we can be more restrictive and just make sure the configs are the same and if we generalize |
| 277 | // copies and swizzles more in the future this can be updated. |
Brian Salomon | 947efe2 | 2019-07-16 15:36:11 -0400 | [diff] [blame] | 278 | if (this->makeConfigSpecific(dst->config(), dst->backendFormat()) != |
| 279 | this->makeConfigSpecific(src->config(), src->backendFormat())) { |
Greg Daniel | 2c3398d | 2019-06-19 11:58:01 -0400 | [diff] [blame] | 280 | return false; |
| 281 | } |
| 282 | return this->onCanCopySurface(dst, src, srcRect, dstPoint); |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 283 | } |
| 284 | |
Greg Daniel | 6fa62e2 | 2019-08-07 15:52:37 -0400 | [diff] [blame] | 285 | bool GrCaps::validateSurfaceParams(const SkISize& size, const GrBackendFormat& format, |
| 286 | GrPixelConfig config, GrRenderable renderable, |
| 287 | int renderTargetSampleCnt, GrMipMapped mipped) const { |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 288 | if (!this->isFormatTexturable(format)) { |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 289 | return false; |
| 290 | } |
| 291 | |
Brian Salomon | 5711133 | 2018-02-05 15:55:54 -0500 | [diff] [blame] | 292 | if (GrMipMapped::kYes == mipped && !this->mipMapSupport()) { |
| 293 | return false; |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 294 | } |
| 295 | |
Greg Daniel | 6fa62e2 | 2019-08-07 15:52:37 -0400 | [diff] [blame] | 296 | if (size.width() < 1 || size.height() < 1) { |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 297 | return false; |
| 298 | } |
| 299 | |
Brian Salomon | f2c2ba9 | 2019-07-17 09:59:59 -0400 | [diff] [blame] | 300 | if (renderable == GrRenderable::kYes) { |
Greg Daniel | 6fa62e2 | 2019-08-07 15:52:37 -0400 | [diff] [blame] | 301 | if (!this->isFormatRenderable(format, renderTargetSampleCnt)) { |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 302 | return false; |
| 303 | } |
| 304 | int maxRTSize = this->maxRenderTargetSize(); |
Greg Daniel | 6fa62e2 | 2019-08-07 15:52:37 -0400 | [diff] [blame] | 305 | if (size.width() > maxRTSize || size.height() > maxRTSize) { |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 306 | return false; |
| 307 | } |
| 308 | } else { |
| 309 | // We currently do not support multisampled textures |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 310 | if (renderTargetSampleCnt != 1) { |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 311 | return false; |
| 312 | } |
| 313 | int maxSize = this->maxTextureSize(); |
Greg Daniel | 6fa62e2 | 2019-08-07 15:52:37 -0400 | [diff] [blame] | 314 | if (size.width() > maxSize || size.height() > maxSize) { |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 315 | return false; |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | return true; |
| 320 | } |
Timothy Liang | 036fdfe | 2018-06-28 15:50:36 -0400 | [diff] [blame] | 321 | |
Greg Daniel | c6dc5cf | 2019-07-17 16:02:00 -0400 | [diff] [blame] | 322 | GrCaps::SupportedRead GrCaps::supportedReadPixelsColorType(GrColorType srcColorType, |
Greg Daniel | ba88ab6 | 2019-07-26 09:14:01 -0400 | [diff] [blame] | 323 | const GrBackendFormat& srcFormat, |
Brian Salomon | f30b1c1 | 2019-06-20 12:25:02 -0400 | [diff] [blame] | 324 | GrColorType dstColorType) const { |
Greg Daniel | ba88ab6 | 2019-07-26 09:14:01 -0400 | [diff] [blame] | 325 | SupportedRead read = this->onSupportedReadPixelsColorType(srcColorType, srcFormat, |
| 326 | dstColorType); |
| 327 | |
| 328 | // There are known problems with 24 vs 32 bit BPP with this color type. Just fail for now if |
| 329 | // using a transfer buffer. |
| 330 | if (GrColorType::kRGB_888x == read.fColorType) { |
| 331 | read.fOffsetAlignmentForTransferBuffer = 0; |
| 332 | } |
Brian Salomon | 8f8354a | 2019-07-31 20:12:02 -0400 | [diff] [blame] | 333 | // It's very convenient to access 1 byte-per-channel 32 bit color types as uint32_t on the CPU. |
Greg Daniel | ba88ab6 | 2019-07-26 09:14:01 -0400 | [diff] [blame] | 334 | // Make those aligned reads out of the buffer even if the underlying API doesn't require it. |
| 335 | auto componentFlags = GrColorTypeComponentFlags(read.fColorType); |
| 336 | if ((componentFlags == kRGBA_SkColorTypeComponentFlags || |
Brian Salomon | 8f8354a | 2019-07-31 20:12:02 -0400 | [diff] [blame] | 337 | componentFlags == kRGB_SkColorTypeComponentFlags || |
| 338 | componentFlags == kAlpha_SkColorTypeComponentFlag || |
| 339 | componentFlags == kGray_SkColorTypeComponentFlag) && |
Greg Daniel | ba88ab6 | 2019-07-26 09:14:01 -0400 | [diff] [blame] | 340 | GrColorTypeBytesPerPixel(read.fColorType) == 4) { |
| 341 | switch (read.fOffsetAlignmentForTransferBuffer & 0b11) { |
| 342 | // offset alignment already a multiple of 4 |
| 343 | case 0: |
| 344 | break; |
| 345 | // offset alignment is a multiple of 2 but not 4. |
| 346 | case 2: |
| 347 | read.fOffsetAlignmentForTransferBuffer *= 2; |
| 348 | // offset alignment is not a multiple of 2. |
| 349 | default: |
| 350 | read.fOffsetAlignmentForTransferBuffer *= 4; |
| 351 | } |
| 352 | } |
| 353 | return read; |
Brian Salomon | f30b1c1 | 2019-06-20 12:25:02 -0400 | [diff] [blame] | 354 | } |
Robert Phillips | 0902c98 | 2019-07-16 07:47:56 -0400 | [diff] [blame] | 355 | |
| 356 | #ifdef SK_DEBUG |
| 357 | bool GrCaps::AreConfigsCompatible(GrPixelConfig genericConfig, GrPixelConfig specificConfig) { |
| 358 | bool compatible = false; |
| 359 | |
| 360 | switch (genericConfig) { |
| 361 | case kAlpha_8_GrPixelConfig: |
| 362 | compatible = kAlpha_8_GrPixelConfig == specificConfig || // here bc of the mock context |
| 363 | kAlpha_8_as_Alpha_GrPixelConfig == specificConfig || |
| 364 | kAlpha_8_as_Red_GrPixelConfig == specificConfig; |
| 365 | break; |
| 366 | case kGray_8_GrPixelConfig: |
| 367 | compatible = kGray_8_GrPixelConfig == specificConfig || // here bc of the mock context |
| 368 | kGray_8_as_Lum_GrPixelConfig == specificConfig || |
| 369 | kGray_8_as_Red_GrPixelConfig == specificConfig; |
| 370 | break; |
| 371 | case kAlpha_half_GrPixelConfig: |
| 372 | compatible = kAlpha_half_GrPixelConfig == specificConfig || // bc of the mock context |
Robert Phillips | ebab03f | 2019-07-22 08:48:18 -0400 | [diff] [blame] | 373 | kAlpha_half_as_Red_GrPixelConfig == specificConfig || |
| 374 | kAlpha_half_as_Lum_GrPixelConfig == specificConfig; |
Robert Phillips | 0902c98 | 2019-07-16 07:47:56 -0400 | [diff] [blame] | 375 | break; |
| 376 | case kRGB_888_GrPixelConfig: |
| 377 | compatible = kRGB_888_GrPixelConfig == specificConfig || |
| 378 | kRGB_888X_GrPixelConfig == specificConfig; |
| 379 | break; |
| 380 | case kRGBA_8888_GrPixelConfig: |
| 381 | compatible = kRGBA_8888_GrPixelConfig == specificConfig || |
| 382 | kBGRA_8888_GrPixelConfig == specificConfig; |
| 383 | break; |
| 384 | default: |
| 385 | compatible = genericConfig == specificConfig; |
| 386 | break; |
| 387 | } |
| 388 | |
| 389 | if (!compatible) { |
| 390 | SkDebugf("Configs are not compatible: %d %d\n", genericConfig, specificConfig); |
| 391 | } |
| 392 | |
| 393 | return compatible; |
| 394 | } |
| 395 | #endif |
Robert Phillips | 0a15cc6 | 2019-07-30 12:49:10 -0400 | [diff] [blame] | 396 | |
| 397 | GrBackendFormat GrCaps::getDefaultBackendFormat(GrColorType grColorType, |
| 398 | GrRenderable renderable) const { |
| 399 | GrBackendFormat format = this->onGetDefaultBackendFormat(grColorType, renderable); |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 400 | if (!this->isFormatTexturableAndUploadable(grColorType, format)) { |
Robert Phillips | 0a15cc6 | 2019-07-30 12:49:10 -0400 | [diff] [blame] | 401 | return {}; |
| 402 | } |
| 403 | |
| 404 | if (renderable == GrRenderable::kYes) { |
Greg Daniel | 900583a | 2019-08-06 12:05:31 -0400 | [diff] [blame] | 405 | if (!this->isFormatAsColorTypeRenderable(grColorType, format)) { |
Robert Phillips | 0a15cc6 | 2019-07-30 12:49:10 -0400 | [diff] [blame] | 406 | return {}; |
| 407 | } |
| 408 | } |
| 409 | |
| 410 | return format; |
| 411 | } |
Greg Daniel | eadfac9 | 2019-08-02 09:03:53 -0400 | [diff] [blame] | 412 | |