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 | fDiscardRenderTargetSupport = false; |
| 23 | fReuseScratchTextures = true; |
robertphillips | 1b8e1b5 | 2015-06-24 06:54:10 -0700 | [diff] [blame] | 24 | fReuseScratchBuffers = true; |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 25 | fGpuTracingSupport = false; |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 26 | fOversizedStencilSupport = false; |
| 27 | fTextureBarrierSupport = false; |
Robert Phillips | 7f86192 | 2018-01-30 13:13:42 +0000 | [diff] [blame] | 28 | fSampleLocationsSupport = false; |
csmartdalton | 2b5f2cb | 2016-06-10 14:06:32 -0700 | [diff] [blame] | 29 | fMultisampleDisableSupport = false; |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 30 | fInstanceAttribSupport = false; |
egdaniel | eed519e | 2016-01-15 11:36:18 -0800 | [diff] [blame] | 31 | fUsesMixedSamples = 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; |
Chris Dalton | a8fbeba | 2019-03-30 00:31:23 -0600 | [diff] [blame] | 48 | fDriverBlacklistCCPR = false; |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 49 | |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 50 | fBlendEquationSupport = kBasic_BlendEquationSupport; |
cdalton | 1dd0542 | 2015-06-12 09:01:18 -0700 | [diff] [blame] | 51 | fAdvBlendEqBlacklist = 0; |
| 52 | |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 53 | fMapBufferFlags = kNone_MapFlags; |
| 54 | |
bsalomon | 7dbd45d | 2016-03-23 10:40:53 -0700 | [diff] [blame] | 55 | fMaxVertexAttributes = 0; |
egdaniel | ff1d547 | 2015-09-10 08:37:20 -0700 | [diff] [blame] | 56 | fMaxRenderTargetSize = 1; |
Chris Dalton | 2612bae | 2018-02-22 13:41:37 -0700 | [diff] [blame] | 57 | fMaxPreferredRenderTargetSize = 1; |
egdaniel | ff1d547 | 2015-09-10 08:37:20 -0700 | [diff] [blame] | 58 | fMaxTextureSize = 1; |
csmartdalton | 9bc1187 | 2016-08-09 12:42:47 -0700 | [diff] [blame] | 59 | fMaxWindowRectangles = 0; |
Chris Dalton | 1e6c5b8 | 2019-06-17 14:16:49 -0600 | [diff] [blame] | 60 | fPreferredInternalSampleCount = 0; |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 61 | |
robertphillips | caef345 | 2015-11-11 13:18:11 -0800 | [diff] [blame] | 62 | fSuppressPrints = options.fSuppressPrints; |
Brian Osman | 195c05b | 2017-08-30 15:14:04 -0400 | [diff] [blame] | 63 | #if GR_TEST_UTILS |
Jim Van Verth | fbdc080 | 2017-05-02 16:15:53 -0400 | [diff] [blame] | 64 | fWireframeMode = options.fWireframeMode; |
Brian Osman | 195c05b | 2017-08-30 15:14:04 -0400 | [diff] [blame] | 65 | #else |
| 66 | fWireframeMode = false; |
| 67 | #endif |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 68 | fBufferMapThreshold = options.fBufferMapThreshold; |
Eric Karl | 5c77975 | 2017-05-08 12:02:07 -0700 | [diff] [blame] | 69 | fAvoidStencilBuffers = false; |
Greg Daniel | 4374e96 | 2018-09-28 15:09:47 -0400 | [diff] [blame] | 70 | fAvoidWritePixelsFastPath = false; |
robertphillips | 6392668 | 2015-08-20 09:39:02 -0700 | [diff] [blame] | 71 | |
| 72 | fPreferVRAMUseOverFlushes = true; |
Adrienne Walker | ab7181d | 2018-05-14 14:02:03 -0700 | [diff] [blame] | 73 | |
Chris Dalton | 0dffbab | 2019-03-27 13:08:50 -0600 | [diff] [blame] | 74 | fPreferTrianglesOverSampleMask = false; |
| 75 | |
Michael Ludwig | f23a152 | 2018-12-10 11:36:13 -0500 | [diff] [blame] | 76 | // Default to true, allow older versions of OpenGL to disable explicitly |
| 77 | fClampToBorderSupport = true; |
| 78 | |
Adrienne Walker | ab7181d | 2018-05-14 14:02:03 -0700 | [diff] [blame] | 79 | fDriverBugWorkarounds = options.fDriverBugWorkarounds; |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 80 | } |
| 81 | |
bsalomon | 4ee6bd8 | 2015-05-27 13:23:23 -0700 | [diff] [blame] | 82 | void GrCaps::applyOptionsOverrides(const GrContextOptions& options) { |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 83 | this->onApplyOptionsOverrides(options); |
Brian Salomon | 01b476a | 2018-01-23 11:06:41 -0500 | [diff] [blame] | 84 | if (options.fDisableDriverCorrectnessWorkarounds) { |
Chris Dalton | a8fbeba | 2019-03-30 00:31:23 -0600 | [diff] [blame] | 85 | SkASSERT(!fDriverBlacklistCCPR); |
Brian Salomon | 01b476a | 2018-01-23 11:06:41 -0500 | [diff] [blame] | 86 | SkASSERT(!fAvoidStencilBuffers); |
| 87 | SkASSERT(!fAdvBlendEqBlacklist); |
Michael Ludwig | a21d196 | 2019-01-11 15:26:22 -0500 | [diff] [blame] | 88 | SkASSERT(!fPerformColorClearsAsDraws); |
| 89 | SkASSERT(!fPerformStencilClearsAsDraws); |
| 90 | // Don't check the partial-clear workaround, since that is a backend limitation, not a |
| 91 | // driver workaround (it just so happens the fallbacks are the same). |
| 92 | } |
| 93 | if (GrContextOptions::Enable::kNo == options.fUseDrawInsteadOfClear) { |
| 94 | fPerformColorClearsAsDraws = false; |
| 95 | fPerformStencilClearsAsDraws = false; |
| 96 | } else if (GrContextOptions::Enable::kYes == options.fUseDrawInsteadOfClear) { |
| 97 | fPerformColorClearsAsDraws = true; |
| 98 | fPerformStencilClearsAsDraws = true; |
Brian Salomon | 01b476a | 2018-01-23 11:06:41 -0500 | [diff] [blame] | 99 | } |
| 100 | |
Chris Dalton | a8fbeba | 2019-03-30 00:31:23 -0600 | [diff] [blame] | 101 | fAllowCoverageCounting = !options.fDisableCoverageCountingPaths; |
| 102 | |
bsalomon | 4ee6bd8 | 2015-05-27 13:23:23 -0700 | [diff] [blame] | 103 | fMaxTextureSize = SkTMin(fMaxTextureSize, options.fMaxTextureSizeOverride); |
Brian Osman | 195c05b | 2017-08-30 15:14:04 -0400 | [diff] [blame] | 104 | fMaxTileSize = fMaxTextureSize; |
| 105 | #if GR_TEST_UTILS |
bsalomon | 8c07b7a | 2015-11-02 11:36:52 -0800 | [diff] [blame] | 106 | // 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] | 107 | if (options.fMaxTileSizeOverride && options.fMaxTileSizeOverride < fMaxTextureSize) { |
bsalomon | 8c07b7a | 2015-11-02 11:36:52 -0800 | [diff] [blame] | 108 | fMaxTileSize = options.fMaxTileSizeOverride; |
| 109 | } |
Chris Dalton | 040238b | 2017-12-18 14:22:34 -0700 | [diff] [blame] | 110 | if (options.fSuppressGeometryShaders) { |
| 111 | fShaderCaps->fGeometryShaderSupport = false; |
| 112 | } |
Brian Osman | 195c05b | 2017-08-30 15:14:04 -0400 | [diff] [blame] | 113 | #endif |
Chris Dalton | 1e6c5b8 | 2019-06-17 14:16:49 -0600 | [diff] [blame] | 114 | |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 115 | if (fMaxWindowRectangles > GrWindowRectangles::kMaxWindows) { |
csmartdalton | 7535f41 | 2016-08-23 06:51:00 -0700 | [diff] [blame] | 116 | SkDebugf("WARNING: capping window rectangles at %i. HW advertises support for %i.\n", |
| 117 | GrWindowRectangles::kMaxWindows, fMaxWindowRectangles); |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 118 | fMaxWindowRectangles = GrWindowRectangles::kMaxWindows; |
| 119 | } |
Chris Dalton | 1e6c5b8 | 2019-06-17 14:16:49 -0600 | [diff] [blame] | 120 | |
| 121 | fPreferredInternalSampleCount = options.fPreferredInternalSampleCount; |
| 122 | |
Eric Karl | 5c77975 | 2017-05-08 12:02:07 -0700 | [diff] [blame] | 123 | fAvoidStencilBuffers = options.fAvoidStencilBuffers; |
Adrienne Walker | ab7181d | 2018-05-14 14:02:03 -0700 | [diff] [blame] | 124 | |
| 125 | fDriverBugWorkarounds.applyOverrides(options.fDriverBugWorkarounds); |
bsalomon | 4ee6bd8 | 2015-05-27 13:23:23 -0700 | [diff] [blame] | 126 | } |
| 127 | |
Kevin Lubick | f4def34 | 2018-10-04 12:52:50 -0400 | [diff] [blame] | 128 | |
| 129 | #ifdef SK_ENABLE_DUMP_GPU |
| 130 | static const char* pixel_config_name(GrPixelConfig config) { |
| 131 | switch (config) { |
| 132 | case kUnknown_GrPixelConfig: return "Unknown"; |
| 133 | case kAlpha_8_GrPixelConfig: return "Alpha8"; |
| 134 | case kAlpha_8_as_Alpha_GrPixelConfig: return "Alpha8_asAlpha"; |
| 135 | case kAlpha_8_as_Red_GrPixelConfig: return "Alpha8_asRed"; |
| 136 | case kGray_8_GrPixelConfig: return "Gray8"; |
| 137 | case kGray_8_as_Lum_GrPixelConfig: return "Gray8_asLum"; |
| 138 | case kGray_8_as_Red_GrPixelConfig: return "Gray8_asRed"; |
| 139 | case kRGB_565_GrPixelConfig: return "RGB565"; |
| 140 | case kRGBA_4444_GrPixelConfig: return "RGBA444"; |
| 141 | case kRGBA_8888_GrPixelConfig: return "RGBA8888"; |
| 142 | case kRGB_888_GrPixelConfig: return "RGB888"; |
Greg Daniel | f259b8b | 2019-02-14 09:03:43 -0500 | [diff] [blame] | 143 | case kRGB_888X_GrPixelConfig: return "RGB888X"; |
Jim Van Verth | 69e5785 | 2018-12-05 13:38:59 -0500 | [diff] [blame] | 144 | case kRG_88_GrPixelConfig: return "RG88"; |
Kevin Lubick | f4def34 | 2018-10-04 12:52:50 -0400 | [diff] [blame] | 145 | case kBGRA_8888_GrPixelConfig: return "BGRA8888"; |
| 146 | case kSRGBA_8888_GrPixelConfig: return "SRGBA8888"; |
| 147 | case kSBGRA_8888_GrPixelConfig: return "SBGRA8888"; |
| 148 | case kRGBA_1010102_GrPixelConfig: return "RGBA1010102"; |
| 149 | case kRGBA_float_GrPixelConfig: return "RGBAFloat"; |
| 150 | case kRG_float_GrPixelConfig: return "RGFloat"; |
| 151 | case kAlpha_half_GrPixelConfig: return "AlphaHalf"; |
| 152 | case kAlpha_half_as_Red_GrPixelConfig: return "AlphaHalf_asRed"; |
| 153 | case kRGBA_half_GrPixelConfig: return "RGBAHalf"; |
Brian Osman | d0626aa | 2019-03-11 15:28:06 -0400 | [diff] [blame] | 154 | case kRGBA_half_Clamped_GrPixelConfig: return "RGBAHalfClamped"; |
Jim Van Verth | 1676cb9 | 2019-01-15 13:24:45 -0500 | [diff] [blame] | 155 | case kRGB_ETC1_GrPixelConfig: return "RGBETC1"; |
Robert Phillips | f83c468 | 2019-06-13 16:49:21 +0000 | [diff] [blame] | 156 | // Experimental (for P016 and P010) |
Robert Phillips | fe18de5 | 2019-06-06 17:21:50 -0400 | [diff] [blame] | 157 | case kR_16_GrPixelConfig: return "R16"; |
| 158 | case kRG_1616_GrPixelConfig: return "RG1616"; |
Kevin Lubick | f4def34 | 2018-10-04 12:52:50 -0400 | [diff] [blame] | 159 | } |
| 160 | SK_ABORT("Invalid pixel config"); |
| 161 | return "<invalid>"; |
| 162 | } |
| 163 | |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 164 | static SkString map_flags_to_string(uint32_t flags) { |
| 165 | SkString str; |
| 166 | if (GrCaps::kNone_MapFlags == flags) { |
| 167 | str = "none"; |
| 168 | } else { |
| 169 | SkASSERT(GrCaps::kCanMap_MapFlag & flags); |
| 170 | SkDEBUGCODE(flags &= ~GrCaps::kCanMap_MapFlag); |
| 171 | str = "can_map"; |
| 172 | |
| 173 | if (GrCaps::kSubset_MapFlag & flags) { |
| 174 | str.append(" partial"); |
| 175 | } else { |
| 176 | str.append(" full"); |
| 177 | } |
| 178 | SkDEBUGCODE(flags &= ~GrCaps::kSubset_MapFlag); |
Brian Salomon | 105d7c2 | 2019-04-16 13:46:14 -0400 | [diff] [blame] | 179 | if (GrCaps::kAsyncRead_MapFlag & flags) { |
| 180 | str.append(" async_read"); |
| 181 | } else { |
| 182 | str.append(" sync_read"); |
| 183 | } |
| 184 | SkDEBUGCODE(flags &= ~GrCaps::kAsyncRead_MapFlag); |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 185 | } |
| 186 | SkASSERT(0 == flags); // Make sure we handled all the flags. |
| 187 | return str; |
| 188 | } |
| 189 | |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 190 | void GrCaps::dumpJSON(SkJSONWriter* writer) const { |
| 191 | writer->beginObject(); |
jvanverth | 84741b3 | 2016-09-30 08:39:02 -0700 | [diff] [blame] | 192 | |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 193 | writer->appendBool("MIP Map Support", fMipMapSupport); |
| 194 | writer->appendBool("NPOT Texture Tile Support", fNPOTTextureTileSupport); |
| 195 | writer->appendBool("sRGB Support", fSRGBSupport); |
| 196 | writer->appendBool("sRGB Write Control", fSRGBWriteControl); |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 197 | writer->appendBool("Discard Render Target Support", fDiscardRenderTargetSupport); |
| 198 | writer->appendBool("Reuse Scratch Textures", fReuseScratchTextures); |
| 199 | writer->appendBool("Reuse Scratch Buffers", fReuseScratchBuffers); |
| 200 | writer->appendBool("Gpu Tracing Support", fGpuTracingSupport); |
| 201 | writer->appendBool("Oversized Stencil Support", fOversizedStencilSupport); |
| 202 | writer->appendBool("Texture Barrier Support", fTextureBarrierSupport); |
Robert Phillips | 7f86192 | 2018-01-30 13:13:42 +0000 | [diff] [blame] | 203 | writer->appendBool("Sample Locations Support", fSampleLocationsSupport); |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 204 | writer->appendBool("Multisample disable support", fMultisampleDisableSupport); |
| 205 | writer->appendBool("Instance Attrib Support", fInstanceAttribSupport); |
| 206 | writer->appendBool("Uses Mixed Samples", fUsesMixedSamples); |
Chris Dalton | 27059d3 | 2018-01-23 14:06:50 -0700 | [diff] [blame] | 207 | writer->appendBool("Use primitive restart", fUsePrimitiveRestart); |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 208 | writer->appendBool("Prefer client-side dynamic buffers", fPreferClientSideDynamicBuffers); |
Chris Dalton | 344e903 | 2017-12-11 15:42:09 -0700 | [diff] [blame] | 209 | writer->appendBool("Prefer fullscreen clears", fPreferFullscreenClears); |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 210 | writer->appendBool("Must clear buffer memory", fMustClearUploadedBufferData); |
Kevin Lubick | 61a5f0a | 2019-03-28 09:47:15 -0400 | [diff] [blame] | 211 | writer->appendBool("Should initialize textures", fShouldInitializeTextures); |
Greg Daniel | b2acf0a | 2018-09-12 09:17:11 -0400 | [diff] [blame] | 212 | writer->appendBool("Supports importing AHardwareBuffers", fSupportsAHardwareBufferImages); |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 213 | writer->appendBool("Fence sync support", fFenceSyncSupport); |
Brian Salomon | 9ff5acb | 2019-05-08 09:04:47 -0400 | [diff] [blame] | 214 | writer->appendBool("Semaphore support", fSemaphoreSupport); |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 215 | writer->appendBool("Cross context texture support", fCrossContextTextureSupport); |
Brian Osman | 499bf1a | 2018-09-17 11:32:42 -0400 | [diff] [blame] | 216 | writer->appendBool("Half float vertex attribute support", fHalfFloatVertexAttributeSupport); |
Brian Salomon | f723264 | 2018-09-19 08:58:08 -0400 | [diff] [blame] | 217 | writer->appendBool("Specify GeometryProcessor textures as a dynamic state array", |
| 218 | fDynamicStateArrayGeometryProcessorTextureSupport); |
Michael Ludwig | a21d196 | 2019-01-11 15:26:22 -0500 | [diff] [blame] | 219 | writer->appendBool("Use draws for partial clears", fPerformPartialClearsAsDraws); |
| 220 | writer->appendBool("Use draws for color clears", fPerformColorClearsAsDraws); |
| 221 | writer->appendBool("Use draws for stencil clip clears", fPerformStencilClearsAsDraws); |
Chris Dalton | a8fbeba | 2019-03-30 00:31:23 -0600 | [diff] [blame] | 222 | writer->appendBool("Allow coverage counting shortcuts", fAllowCoverageCounting); |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 223 | writer->appendBool("Supports transfer buffers", fTransferBufferSupport); |
Chris Dalton | a8fbeba | 2019-03-30 00:31:23 -0600 | [diff] [blame] | 224 | writer->appendBool("Blacklist CCPR on current driver [workaround]", fDriverBlacklistCCPR); |
Michael Ludwig | a21d196 | 2019-01-11 15:26:22 -0500 | [diff] [blame] | 225 | writer->appendBool("Clamp-to-border", fClampToBorderSupport); |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 226 | |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 227 | writer->appendBool("Prefer VRAM Use over flushes [workaround]", fPreferVRAMUseOverFlushes); |
Chris Dalton | 0dffbab | 2019-03-27 13:08:50 -0600 | [diff] [blame] | 228 | writer->appendBool("Prefer more triangles over sample mask [MSAA only]", |
| 229 | fPreferTrianglesOverSampleMask); |
Robert Phillips | f2ec024 | 2018-03-01 16:51:25 -0500 | [diff] [blame] | 230 | writer->appendBool("Avoid stencil buffers [workaround]", fAvoidStencilBuffers); |
robertphillips | 6392668 | 2015-08-20 09:39:02 -0700 | [diff] [blame] | 231 | |
cdalton | 1dd0542 | 2015-06-12 09:01:18 -0700 | [diff] [blame] | 232 | if (this->advancedBlendEquationSupport()) { |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 233 | writer->appendHexU32("Advanced Blend Equation Blacklist", fAdvBlendEqBlacklist); |
cdalton | 1dd0542 | 2015-06-12 09:01:18 -0700 | [diff] [blame] | 234 | } |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 235 | |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 236 | writer->appendS32("Max Vertex Attributes", fMaxVertexAttributes); |
| 237 | writer->appendS32("Max Texture Size", fMaxTextureSize); |
| 238 | writer->appendS32("Max Render Target Size", fMaxRenderTargetSize); |
Chris Dalton | 2612bae | 2018-02-22 13:41:37 -0700 | [diff] [blame] | 239 | writer->appendS32("Max Preferred Render Target Size", fMaxPreferredRenderTargetSize); |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 240 | writer->appendS32("Max Window Rectangles", fMaxWindowRectangles); |
Chris Dalton | 1e6c5b8 | 2019-06-17 14:16:49 -0600 | [diff] [blame] | 241 | writer->appendS32("Preferred Sample Count for Internal MSAA and Mixed Samples", |
| 242 | fPreferredInternalSampleCount); |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 243 | |
| 244 | static const char* kBlendEquationSupportNames[] = { |
| 245 | "Basic", |
| 246 | "Advanced", |
| 247 | "Advanced Coherent", |
| 248 | }; |
| 249 | GR_STATIC_ASSERT(0 == kBasic_BlendEquationSupport); |
| 250 | GR_STATIC_ASSERT(1 == kAdvanced_BlendEquationSupport); |
| 251 | GR_STATIC_ASSERT(2 == kAdvancedCoherent_BlendEquationSupport); |
| 252 | GR_STATIC_ASSERT(SK_ARRAY_COUNT(kBlendEquationSupportNames) == kLast_BlendEquationSupport + 1); |
| 253 | |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 254 | writer->appendString("Blend Equation Support", |
| 255 | kBlendEquationSupportNames[fBlendEquationSupport]); |
| 256 | writer->appendString("Map Buffer Support", map_flags_to_string(fMapBufferFlags).c_str()); |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 257 | |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 258 | SkASSERT(!this->isConfigRenderable(kUnknown_GrPixelConfig)); |
Brian Osman | 0f450ac | 2017-08-09 20:45:52 +0000 | [diff] [blame] | 259 | SkASSERT(!this->isConfigTexturable(kUnknown_GrPixelConfig)); |
Brian Osman | 175af0d | 2017-08-09 14:29:36 -0400 | [diff] [blame] | 260 | |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 261 | writer->beginArray("configs"); |
| 262 | |
| 263 | for (size_t i = 1; i < kGrPixelConfigCnt; ++i) { |
Brian Osman | 0f450ac | 2017-08-09 20:45:52 +0000 | [diff] [blame] | 264 | GrPixelConfig config = static_cast<GrPixelConfig>(i); |
Brian Osman | 8048822 | 2017-08-10 13:29:30 -0400 | [diff] [blame] | 265 | writer->beginObject(nullptr, false); |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 266 | writer->appendString("name", pixel_config_name(config)); |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 267 | writer->appendS32("max sample count", this->maxRenderTargetSampleCount(config)); |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 268 | writer->appendBool("texturable", this->isConfigTexturable(config)); |
| 269 | writer->endObject(); |
Brian Osman | 0f450ac | 2017-08-09 20:45:52 +0000 | [diff] [blame] | 270 | } |
Brian Osman | 175af0d | 2017-08-09 14:29:36 -0400 | [diff] [blame] | 271 | |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 272 | writer->endArray(); |
| 273 | |
| 274 | this->onDumpJSON(writer); |
| 275 | |
| 276 | writer->appendName("shaderCaps"); |
| 277 | this->shaderCaps()->dumpJSON(writer); |
| 278 | |
| 279 | writer->endObject(); |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 280 | } |
Kevin Lubick | f4def34 | 2018-10-04 12:52:50 -0400 | [diff] [blame] | 281 | #else |
| 282 | void GrCaps::dumpJSON(SkJSONWriter* writer) const { } |
| 283 | #endif |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 284 | |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 285 | bool GrCaps::surfaceSupportsWritePixels(const GrSurface* surface) const { |
| 286 | return surface->readOnly() ? false : this->onSurfaceSupportsWritePixels(surface); |
| 287 | } |
| 288 | |
Brian Salomon | 26de56e | 2019-04-10 12:14:26 -0400 | [diff] [blame] | 289 | size_t GrCaps::transferFromOffsetAlignment(GrColorType bufferColorType) const { |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 290 | if (!this->transferBufferSupport()) { |
Brian Salomon | 26de56e | 2019-04-10 12:14:26 -0400 | [diff] [blame] | 291 | return 0; |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 292 | } |
Brian Salomon | 26de56e | 2019-04-10 12:14:26 -0400 | [diff] [blame] | 293 | size_t result = this->onTransferFromOffsetAlignment(bufferColorType); |
| 294 | if (!result) { |
| 295 | return 0; |
| 296 | } |
| 297 | // It's very convenient to access 1 byte-per-channel 32 bitvRGB/RGBA color types as uint32_t. |
| 298 | // Make those aligned reads out of the buffer even if the underlying API doesn't require it. |
| 299 | auto componentFlags = GrColorTypeComponentFlags(bufferColorType); |
| 300 | if ((componentFlags == kRGBA_SkColorTypeComponentFlags || |
| 301 | componentFlags == kRGB_SkColorTypeComponentFlags) && |
| 302 | GrColorTypeBytesPerPixel(bufferColorType) == 4) { |
| 303 | switch (result & 0b11) { |
| 304 | // offset alignment already a multiple of 4 |
| 305 | case 0: return result; |
| 306 | // offset alignment is a multiple of 2 but not 4. |
| 307 | case 2: return 2 * result; |
| 308 | // offset alignment is not a multiple of 2. |
| 309 | default: return 4 * result; |
| 310 | } |
| 311 | } |
| 312 | return result; |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 313 | } |
| 314 | |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 315 | bool GrCaps::canCopySurface(const GrSurfaceProxy* dst, const GrSurfaceProxy* src, |
| 316 | const SkIRect& srcRect, const SkIPoint& dstPoint) const { |
| 317 | return dst->readOnly() ? false : this->onCanCopySurface(dst, src, srcRect, dstPoint); |
| 318 | } |
| 319 | |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 320 | bool GrCaps::validateSurfaceDesc(const GrSurfaceDesc& desc, GrMipMapped mipped) const { |
| 321 | if (!this->isConfigTexturable(desc.fConfig)) { |
| 322 | return false; |
| 323 | } |
| 324 | |
Brian Salomon | 5711133 | 2018-02-05 15:55:54 -0500 | [diff] [blame] | 325 | if (GrMipMapped::kYes == mipped && !this->mipMapSupport()) { |
| 326 | return false; |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | if (desc.fWidth < 1 || desc.fHeight < 1) { |
| 330 | return false; |
| 331 | } |
| 332 | |
| 333 | if (SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag)) { |
| 334 | if (0 == this->getRenderTargetSampleCount(desc.fSampleCnt, desc.fConfig)) { |
| 335 | return false; |
| 336 | } |
| 337 | int maxRTSize = this->maxRenderTargetSize(); |
| 338 | if (desc.fWidth > maxRTSize || desc.fHeight > maxRTSize) { |
| 339 | return false; |
| 340 | } |
| 341 | } else { |
| 342 | // We currently do not support multisampled textures |
| 343 | if (desc.fSampleCnt > 1) { |
| 344 | return false; |
| 345 | } |
| 346 | int maxSize = this->maxTextureSize(); |
| 347 | if (desc.fWidth > maxSize || desc.fHeight > maxSize) { |
| 348 | return false; |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | return true; |
| 353 | } |
Timothy Liang | 036fdfe | 2018-06-28 15:50:36 -0400 | [diff] [blame] | 354 | |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 355 | GrBackendFormat GrCaps::getBackendFormatFromColorType(SkColorType ct) const { |
| 356 | return this->getBackendFormatFromGrColorType(SkColorTypeToGrColorType(ct), GrSRGBEncoded::kNo); |
| 357 | } |