Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 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 | 52337de | 2019-07-25 09:00:52 -0500 | [diff] [blame] | 8 | #include "src/gpu/dawn/GrDawnCaps.h" |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 9 | |
| 10 | GrDawnCaps::GrDawnCaps(const GrContextOptions& contextOptions) : INHERITED(contextOptions) { |
Stephen White | 170d990 | 2019-08-15 16:48:24 -0400 | [diff] [blame] | 11 | fMipMapSupport = true; |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 12 | fBufferMapThreshold = SK_MaxS32; // FIXME: get this from Dawn? |
| 13 | fShaderCaps.reset(new GrShaderCaps(contextOptions)); |
Stephen White | 170d990 | 2019-08-15 16:48:24 -0400 | [diff] [blame] | 14 | fMaxTextureSize = fMaxRenderTargetSize = 4096; // FIXME |
Stephen White | d67c71f | 2019-08-06 11:15:41 -0400 | [diff] [blame] | 15 | fMaxVertexAttributes = 16; // FIXME |
Stephen White | 170d990 | 2019-08-15 16:48:24 -0400 | [diff] [blame] | 16 | fClampToBorderSupport = false; |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 17 | fPerformPartialClearsAsDraws = true; |
Stephen White | f813ef7 | 2019-08-09 12:28:37 -0400 | [diff] [blame] | 18 | |
Stephen White | 170d990 | 2019-08-15 16:48:24 -0400 | [diff] [blame] | 19 | fShaderCaps->fFlatInterpolationSupport = true; |
| 20 | fShaderCaps->fIntegerSupport = true; |
| 21 | // FIXME: each fragment sampler takes two binding slots in Dawn (sampler + texture). Limit to |
| 22 | // 6 * 2 = 12, since kMaxBindingsPerGroup is 16 in Dawn, and we need to keep a few for |
| 23 | // non-texture bindings. Eventually, we may be able to increase kMaxBindingsPerGroup in Dawn. |
| 24 | fShaderCaps->fMaxFragmentSamplers = 6; |
| 25 | fShaderCaps->fShaderDerivativeSupport = true; |
| 26 | |
Stephen White | f813ef7 | 2019-08-09 12:28:37 -0400 | [diff] [blame] | 27 | this->applyOptionsOverrides(contextOptions); |
| 28 | fShaderCaps->applyOptionsOverrides(contextOptions); |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | bool GrDawnCaps::isFormatSRGB(const GrBackendFormat& format) const { |
| 32 | return false; |
| 33 | } |
| 34 | |
Robert Phillips | 8ff8bcc | 2019-07-29 17:03:35 -0400 | [diff] [blame] | 35 | bool GrDawnCaps::isFormatCompressed(const GrBackendFormat& format) const { |
| 36 | return false; |
| 37 | } |
| 38 | |
Stephen White | 6db3b7b | 2019-08-15 16:48:05 -0400 | [diff] [blame] | 39 | bool GrDawnCaps::isFormatTexturable(const GrBackendFormat& format) const { |
| 40 | // Currently, all the formats in GrDawnFormatToPixelConfig are texturable. |
| 41 | dawn::TextureFormat dawnFormat; |
| 42 | return format.asDawnFormat(&dawnFormat); |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | GrPixelConfig GrDawnCaps::onGetConfigFromBackendFormat(const GrBackendFormat& format, |
Stephen White | d732518 | 2019-08-02 17:22:59 -0400 | [diff] [blame] | 46 | GrColorType colorType) const { |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 47 | dawn::TextureFormat dawnFormat; |
| 48 | if (!format.asDawnFormat(&dawnFormat)) { |
Stephen White | d732518 | 2019-08-02 17:22:59 -0400 | [diff] [blame] | 49 | return kUnknown_GrPixelConfig; |
| 50 | } |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 51 | switch (colorType) { |
| 52 | case GrColorType::kUnknown: |
| 53 | return kUnknown_GrPixelConfig; |
| 54 | case GrColorType::kAlpha_8: |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 55 | if (dawn::TextureFormat::R8Unorm == dawnFormat) { |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 56 | return kAlpha_8_as_Red_GrPixelConfig; |
| 57 | } |
| 58 | break; |
| 59 | case GrColorType::kRGBA_8888: |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 60 | if (dawn::TextureFormat::RGBA8Unorm == dawnFormat) { |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 61 | return kRGBA_8888_GrPixelConfig; |
Stephen White | fe55c73 | 2019-08-09 12:24:30 -0400 | [diff] [blame] | 62 | } else if (dawn::TextureFormat::BGRA8Unorm == dawnFormat) { |
Stephen White | d67c71f | 2019-08-06 11:15:41 -0400 | [diff] [blame] | 63 | // FIXME: This shouldn't be necessary, but on some platforms (Mac) |
| 64 | // Skia byte order is RGBA, while preferred swap format is BGRA. |
| 65 | return kBGRA_8888_GrPixelConfig; |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 66 | } |
| 67 | break; |
| 68 | case GrColorType::kRGB_888x: |
| 69 | break; |
| 70 | case GrColorType::kBGRA_8888: |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 71 | if (dawn::TextureFormat::BGRA8Unorm == dawnFormat) { |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 72 | return kBGRA_8888_GrPixelConfig; |
Stephen White | fe55c73 | 2019-08-09 12:24:30 -0400 | [diff] [blame] | 73 | } else if (dawn::TextureFormat::RGBA8Unorm == dawnFormat) { |
Stephen White | d67c71f | 2019-08-06 11:15:41 -0400 | [diff] [blame] | 74 | return kRGBA_8888_GrPixelConfig; |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 75 | } |
| 76 | break; |
| 77 | default: |
| 78 | break; |
| 79 | } |
| 80 | return kUnknown_GrPixelConfig; |
| 81 | } |
| 82 | |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 83 | static GrSwizzle get_swizzle(const GrBackendFormat& format, GrColorType colorType, |
| 84 | bool forOutput) { |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 85 | switch (colorType) { |
| 86 | case GrColorType::kAlpha_8: // fall through |
| 87 | case GrColorType::kAlpha_F16: |
| 88 | if (forOutput) { |
| 89 | return GrSwizzle::AAAA(); |
| 90 | } else { |
| 91 | return GrSwizzle::RRRR(); |
| 92 | } |
| 93 | case GrColorType::kGray_8: |
| 94 | if (!forOutput) { |
| 95 | return GrSwizzle::RRRA(); |
| 96 | } |
| 97 | break; |
| 98 | case GrColorType::kRGB_888x: |
| 99 | if (!forOutput) { |
| 100 | return GrSwizzle::RGB1(); |
| 101 | } |
| 102 | default: |
| 103 | return GrSwizzle::RGBA(); |
| 104 | } |
| 105 | return GrSwizzle::RGBA(); |
| 106 | } |
| 107 | |
Stephen White | 6db3b7b | 2019-08-15 16:48:05 -0400 | [diff] [blame] | 108 | bool GrDawnCaps::isFormatTexturableAndUploadable(GrColorType ct, |
| 109 | const GrBackendFormat& format) const { |
| 110 | dawn::TextureFormat dawnFormat; |
| 111 | if (!format.asDawnFormat(&dawnFormat)) { |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 112 | return false; |
| 113 | } |
Stephen White | 6db3b7b | 2019-08-15 16:48:05 -0400 | [diff] [blame] | 114 | switch (ct) { |
| 115 | case GrColorType::kAlpha_8: |
| 116 | return dawn::TextureFormat::R8Unorm == dawnFormat; |
| 117 | case GrColorType::kRGBA_8888: |
| 118 | case GrColorType::kRGB_888x: |
| 119 | case GrColorType::kBGRA_8888: |
| 120 | return dawn::TextureFormat::RGBA8Unorm == dawnFormat || |
| 121 | dawn::TextureFormat::BGRA8Unorm == dawnFormat; |
| 122 | default: |
| 123 | return false; |
| 124 | } |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 125 | } |
| 126 | |
Stephen White | fe55c73 | 2019-08-09 12:24:30 -0400 | [diff] [blame] | 127 | bool GrDawnCaps::isFormatRenderable(const GrBackendFormat& format, |
Stephen White | d732518 | 2019-08-02 17:22:59 -0400 | [diff] [blame] | 128 | int sampleCount) const { |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 129 | dawn::TextureFormat dawnFormat; |
| 130 | if (!format.isValid() || sampleCount > 1 || !format.asDawnFormat(&dawnFormat)) { |
Stephen White | d732518 | 2019-08-02 17:22:59 -0400 | [diff] [blame] | 131 | return false; |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 132 | } |
| 133 | |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 134 | return GrDawnFormatIsRenderable(dawnFormat); |
Stephen White | d732518 | 2019-08-02 17:22:59 -0400 | [diff] [blame] | 135 | } |
| 136 | |
Stephen White | fe55c73 | 2019-08-09 12:24:30 -0400 | [diff] [blame] | 137 | bool GrDawnCaps::isFormatAsColorTypeRenderable(GrColorType ct, const GrBackendFormat& format, |
| 138 | int sampleCount) const { |
| 139 | return isFormatRenderable(format, sampleCount); |
| 140 | } |
| 141 | |
| 142 | int GrDawnCaps::getRenderTargetSampleCount(int requestedCount, |
Stephen White | d732518 | 2019-08-02 17:22:59 -0400 | [diff] [blame] | 143 | const GrBackendFormat& backendFormat) const { |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 144 | dawn::TextureFormat dawnFormat; |
Stephen White | fe55c73 | 2019-08-09 12:24:30 -0400 | [diff] [blame] | 145 | if (!backendFormat.asDawnFormat(&dawnFormat)) { |
Stephen White | d732518 | 2019-08-02 17:22:59 -0400 | [diff] [blame] | 146 | return 0; |
| 147 | } |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 148 | return GrDawnFormatIsRenderable(dawnFormat) ? 1 : 0; |
Stephen White | d732518 | 2019-08-02 17:22:59 -0400 | [diff] [blame] | 149 | } |
| 150 | |
Stephen White | d732518 | 2019-08-02 17:22:59 -0400 | [diff] [blame] | 151 | int GrDawnCaps::maxRenderTargetSampleCount(const GrBackendFormat& format) const { |
| 152 | return format.isValid() ? 1 : 0; |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 153 | } |
| 154 | |
Robert Phillips | 0a15cc6 | 2019-07-30 12:49:10 -0400 | [diff] [blame] | 155 | GrBackendFormat GrDawnCaps::onGetDefaultBackendFormat(GrColorType ct, |
| 156 | GrRenderable renderable) const { |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 157 | GrPixelConfig config = GrColorTypeToPixelConfig(ct); |
| 158 | if (config == kUnknown_GrPixelConfig) { |
| 159 | return GrBackendFormat(); |
| 160 | } |
| 161 | dawn::TextureFormat format; |
| 162 | if (!GrPixelConfigToDawnFormat(config, &format)) { |
| 163 | return GrBackendFormat(); |
| 164 | } |
| 165 | return GrBackendFormat::MakeDawn(format); |
| 166 | } |
| 167 | |
| 168 | GrBackendFormat GrDawnCaps::getBackendFormatFromCompressionType(SkImage::CompressionType type) const |
| 169 | { |
| 170 | return GrBackendFormat(); |
| 171 | } |
| 172 | |
| 173 | GrSwizzle GrDawnCaps::getTextureSwizzle(const GrBackendFormat& format, GrColorType colorType) const |
| 174 | { |
| 175 | return get_swizzle(format, colorType, false); |
| 176 | } |
| 177 | |
Stephen White | 985741a | 2019-07-18 11:43:45 -0400 | [diff] [blame] | 178 | GrSwizzle GrDawnCaps::getOutputSwizzle(const GrBackendFormat& format, GrColorType colorType) const |
| 179 | { |
| 180 | return get_swizzle(format, colorType, true); |
| 181 | } |
| 182 | |
| 183 | bool GrDawnCaps::onAreColorTypeAndFormatCompatible(GrColorType ct, |
| 184 | const GrBackendFormat& format) const { |
| 185 | return true; |
| 186 | } |
Stephen White | b05ca08 | 2019-07-29 11:39:28 -0400 | [diff] [blame] | 187 | |
Robert Phillips | 00c9f0d | 2019-08-02 17:17:35 -0400 | [diff] [blame] | 188 | GrColorType GrDawnCaps::getYUVAColorTypeFromBackendFormat(const GrBackendFormat&, |
| 189 | bool isAlphaChannel) const { |
Stephen White | b05ca08 | 2019-07-29 11:39:28 -0400 | [diff] [blame] | 190 | return GrColorType::kUnknown; |
| 191 | } |
Stephen White | d732518 | 2019-08-02 17:22:59 -0400 | [diff] [blame] | 192 | |
| 193 | #if GR_TEST_UTILS |
| 194 | std::vector<GrCaps::TestFormatColorTypeCombination> GrDawnCaps::getTestingCombinations() const { |
| 195 | std::vector<GrCaps::TestFormatColorTypeCombination> combos = { |
| 196 | { GrColorType::kAlpha_8, GrBackendFormat::MakeDawn(dawn::TextureFormat::R8Unorm) }, |
| 197 | { GrColorType::kRGBA_8888, GrBackendFormat::MakeDawn(dawn::TextureFormat::RGBA8Unorm) }, |
Stephen White | 6db3b7b | 2019-08-15 16:48:05 -0400 | [diff] [blame] | 198 | { GrColorType::kRGBA_8888, GrBackendFormat::MakeDawn(dawn::TextureFormat::BGRA8Unorm) }, |
Stephen White | d732518 | 2019-08-02 17:22:59 -0400 | [diff] [blame] | 199 | { GrColorType::kRGB_888x, GrBackendFormat::MakeDawn(dawn::TextureFormat::RGBA8Unorm) }, |
Stephen White | 6db3b7b | 2019-08-15 16:48:05 -0400 | [diff] [blame] | 200 | { GrColorType::kRGB_888x, GrBackendFormat::MakeDawn(dawn::TextureFormat::BGRA8Unorm) }, |
Stephen White | d732518 | 2019-08-02 17:22:59 -0400 | [diff] [blame] | 201 | { GrColorType::kBGRA_8888, GrBackendFormat::MakeDawn(dawn::TextureFormat::BGRA8Unorm) }, |
Stephen White | 6db3b7b | 2019-08-15 16:48:05 -0400 | [diff] [blame] | 202 | { GrColorType::kBGRA_8888, GrBackendFormat::MakeDawn(dawn::TextureFormat::RGBA8Unorm) }, |
Stephen White | d732518 | 2019-08-02 17:22:59 -0400 | [diff] [blame] | 203 | }; |
| 204 | |
| 205 | #ifdef SK_DEBUG |
| 206 | for (auto combo : combos) { |
| 207 | SkASSERT(this->onAreColorTypeAndFormatCompatible(combo.fColorType, combo.fFormat)); |
| 208 | } |
| 209 | #endif |
| 210 | return combos; |
| 211 | } |
| 212 | #endif |