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