blob: b53feca07e85b6b859fdf3cbf36c24683ea544ed [file] [log] [blame]
Stephen White985741a2019-07-18 11:43:45 -04001/*
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 Klein52337de2019-07-25 09:00:52 -05008#include "src/gpu/dawn/GrDawnCaps.h"
Stephen White985741a2019-07-18 11:43:45 -04009
10GrDawnCaps::GrDawnCaps(const GrContextOptions& contextOptions) : INHERITED(contextOptions) {
Stephen White170d9902019-08-15 16:48:24 -040011 fMipMapSupport = true;
Stephen White985741a2019-07-18 11:43:45 -040012 fBufferMapThreshold = SK_MaxS32; // FIXME: get this from Dawn?
13 fShaderCaps.reset(new GrShaderCaps(contextOptions));
Stephen White170d9902019-08-15 16:48:24 -040014 fMaxTextureSize = fMaxRenderTargetSize = 4096; // FIXME
Stephen Whited67c71f2019-08-06 11:15:41 -040015 fMaxVertexAttributes = 16; // FIXME
Stephen White170d9902019-08-15 16:48:24 -040016 fClampToBorderSupport = false;
Stephen White985741a2019-07-18 11:43:45 -040017 fPerformPartialClearsAsDraws = true;
Stephen Whitef813ef72019-08-09 12:28:37 -040018
Stephen White170d9902019-08-15 16:48:24 -040019 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 Whitef813ef72019-08-09 12:28:37 -040027 this->applyOptionsOverrides(contextOptions);
28 fShaderCaps->applyOptionsOverrides(contextOptions);
Stephen White985741a2019-07-18 11:43:45 -040029}
30
31bool GrDawnCaps::isFormatSRGB(const GrBackendFormat& format) const {
32 return false;
33}
34
Robert Phillips8ff8bcc2019-07-29 17:03:35 -040035bool GrDawnCaps::isFormatCompressed(const GrBackendFormat& format) const {
36 return false;
37}
38
Stephen White6db3b7b2019-08-15 16:48:05 -040039bool 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 White985741a2019-07-18 11:43:45 -040043}
44
45GrPixelConfig GrDawnCaps::onGetConfigFromBackendFormat(const GrBackendFormat& format,
Stephen Whited7325182019-08-02 17:22:59 -040046 GrColorType colorType) const {
Brian Salomond4764a12019-08-08 12:08:24 -040047 dawn::TextureFormat dawnFormat;
48 if (!format.asDawnFormat(&dawnFormat)) {
Stephen Whited7325182019-08-02 17:22:59 -040049 return kUnknown_GrPixelConfig;
50 }
Stephen White985741a2019-07-18 11:43:45 -040051 switch (colorType) {
52 case GrColorType::kUnknown:
53 return kUnknown_GrPixelConfig;
54 case GrColorType::kAlpha_8:
Brian Salomond4764a12019-08-08 12:08:24 -040055 if (dawn::TextureFormat::R8Unorm == dawnFormat) {
Stephen White985741a2019-07-18 11:43:45 -040056 return kAlpha_8_as_Red_GrPixelConfig;
57 }
58 break;
59 case GrColorType::kRGBA_8888:
Brian Salomond4764a12019-08-08 12:08:24 -040060 if (dawn::TextureFormat::RGBA8Unorm == dawnFormat) {
Stephen White985741a2019-07-18 11:43:45 -040061 return kRGBA_8888_GrPixelConfig;
Stephen Whitefe55c732019-08-09 12:24:30 -040062 } else if (dawn::TextureFormat::BGRA8Unorm == dawnFormat) {
Stephen Whited67c71f2019-08-06 11:15:41 -040063 // 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 White985741a2019-07-18 11:43:45 -040066 }
67 break;
68 case GrColorType::kRGB_888x:
69 break;
70 case GrColorType::kBGRA_8888:
Brian Salomond4764a12019-08-08 12:08:24 -040071 if (dawn::TextureFormat::BGRA8Unorm == dawnFormat) {
Stephen White985741a2019-07-18 11:43:45 -040072 return kBGRA_8888_GrPixelConfig;
Stephen Whitefe55c732019-08-09 12:24:30 -040073 } else if (dawn::TextureFormat::RGBA8Unorm == dawnFormat) {
Stephen Whited67c71f2019-08-06 11:15:41 -040074 return kRGBA_8888_GrPixelConfig;
Stephen White985741a2019-07-18 11:43:45 -040075 }
76 break;
77 default:
78 break;
79 }
80 return kUnknown_GrPixelConfig;
81}
82
Stephen White985741a2019-07-18 11:43:45 -040083static GrSwizzle get_swizzle(const GrBackendFormat& format, GrColorType colorType,
84 bool forOutput) {
Stephen White985741a2019-07-18 11:43:45 -040085 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 White6db3b7b2019-08-15 16:48:05 -0400108bool GrDawnCaps::isFormatTexturableAndUploadable(GrColorType ct,
109 const GrBackendFormat& format) const {
110 dawn::TextureFormat dawnFormat;
111 if (!format.asDawnFormat(&dawnFormat)) {
Stephen White985741a2019-07-18 11:43:45 -0400112 return false;
113 }
Stephen White6db3b7b2019-08-15 16:48:05 -0400114 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 White985741a2019-07-18 11:43:45 -0400125}
126
Stephen Whitefe55c732019-08-09 12:24:30 -0400127bool GrDawnCaps::isFormatRenderable(const GrBackendFormat& format,
Stephen Whited7325182019-08-02 17:22:59 -0400128 int sampleCount) const {
Brian Salomond4764a12019-08-08 12:08:24 -0400129 dawn::TextureFormat dawnFormat;
130 if (!format.isValid() || sampleCount > 1 || !format.asDawnFormat(&dawnFormat)) {
Stephen Whited7325182019-08-02 17:22:59 -0400131 return false;
Stephen White985741a2019-07-18 11:43:45 -0400132 }
133
Brian Salomond4764a12019-08-08 12:08:24 -0400134 return GrDawnFormatIsRenderable(dawnFormat);
Stephen Whited7325182019-08-02 17:22:59 -0400135}
136
Stephen Whitefe55c732019-08-09 12:24:30 -0400137bool GrDawnCaps::isFormatAsColorTypeRenderable(GrColorType ct, const GrBackendFormat& format,
138 int sampleCount) const {
139 return isFormatRenderable(format, sampleCount);
140}
141
142int GrDawnCaps::getRenderTargetSampleCount(int requestedCount,
Stephen Whited7325182019-08-02 17:22:59 -0400143 const GrBackendFormat& backendFormat) const {
Brian Salomond4764a12019-08-08 12:08:24 -0400144 dawn::TextureFormat dawnFormat;
Stephen Whitefe55c732019-08-09 12:24:30 -0400145 if (!backendFormat.asDawnFormat(&dawnFormat)) {
Stephen Whited7325182019-08-02 17:22:59 -0400146 return 0;
147 }
Brian Salomond4764a12019-08-08 12:08:24 -0400148 return GrDawnFormatIsRenderable(dawnFormat) ? 1 : 0;
Stephen Whited7325182019-08-02 17:22:59 -0400149}
150
Stephen Whited7325182019-08-02 17:22:59 -0400151int GrDawnCaps::maxRenderTargetSampleCount(const GrBackendFormat& format) const {
152 return format.isValid() ? 1 : 0;
Stephen White985741a2019-07-18 11:43:45 -0400153}
154
Robert Phillips0a15cc62019-07-30 12:49:10 -0400155GrBackendFormat GrDawnCaps::onGetDefaultBackendFormat(GrColorType ct,
156 GrRenderable renderable) const {
Stephen White985741a2019-07-18 11:43:45 -0400157 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
168GrBackendFormat GrDawnCaps::getBackendFormatFromCompressionType(SkImage::CompressionType type) const
169{
170 return GrBackendFormat();
171}
172
173GrSwizzle GrDawnCaps::getTextureSwizzle(const GrBackendFormat& format, GrColorType colorType) const
174{
175 return get_swizzle(format, colorType, false);
176}
177
Stephen White985741a2019-07-18 11:43:45 -0400178GrSwizzle GrDawnCaps::getOutputSwizzle(const GrBackendFormat& format, GrColorType colorType) const
179{
180 return get_swizzle(format, colorType, true);
181}
182
183bool GrDawnCaps::onAreColorTypeAndFormatCompatible(GrColorType ct,
184 const GrBackendFormat& format) const {
185 return true;
186}
Stephen Whiteb05ca082019-07-29 11:39:28 -0400187
Robert Phillips00c9f0d2019-08-02 17:17:35 -0400188GrColorType GrDawnCaps::getYUVAColorTypeFromBackendFormat(const GrBackendFormat&,
189 bool isAlphaChannel) const {
Stephen Whiteb05ca082019-07-29 11:39:28 -0400190 return GrColorType::kUnknown;
191}
Stephen Whited7325182019-08-02 17:22:59 -0400192
193#if GR_TEST_UTILS
194std::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 White6db3b7b2019-08-15 16:48:05 -0400198 { GrColorType::kRGBA_8888, GrBackendFormat::MakeDawn(dawn::TextureFormat::BGRA8Unorm) },
Stephen Whited7325182019-08-02 17:22:59 -0400199 { GrColorType::kRGB_888x, GrBackendFormat::MakeDawn(dawn::TextureFormat::RGBA8Unorm) },
Stephen White6db3b7b2019-08-15 16:48:05 -0400200 { GrColorType::kRGB_888x, GrBackendFormat::MakeDawn(dawn::TextureFormat::BGRA8Unorm) },
Stephen Whited7325182019-08-02 17:22:59 -0400201 { GrColorType::kBGRA_8888, GrBackendFormat::MakeDawn(dawn::TextureFormat::BGRA8Unorm) },
Stephen White6db3b7b2019-08-15 16:48:05 -0400202 { GrColorType::kBGRA_8888, GrBackendFormat::MakeDawn(dawn::TextureFormat::RGBA8Unorm) },
Stephen Whited7325182019-08-02 17:22:59 -0400203 };
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