Greg Daniel | cebcb84 | 2017-07-31 10:45:52 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 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 | |
| 8 | #ifndef GrMtlCaps_DEFINED |
| 9 | #define GrMtlCaps_DEFINED |
| 10 | |
| 11 | #include "GrCaps.h" |
Ethan Nicholas | 0106351 | 2018-10-08 16:58:25 -0400 | [diff] [blame] | 12 | #include "GrMtlStencilAttachment.h" |
Greg Daniel | cebcb84 | 2017-07-31 10:45:52 -0400 | [diff] [blame] | 13 | #include "SkTDArray.h" |
| 14 | |
| 15 | #import <Metal/Metal.h> |
| 16 | |
| 17 | class GrShaderCaps; |
| 18 | |
| 19 | /** |
| 20 | * Stores some capabilities of a Mtl backend. |
| 21 | */ |
| 22 | class GrMtlCaps : public GrCaps { |
| 23 | public: |
Ethan Nicholas | 0106351 | 2018-10-08 16:58:25 -0400 | [diff] [blame] | 24 | typedef GrMtlStencilAttachment::Format StencilFormat; |
| 25 | |
Greg Daniel | cebcb84 | 2017-07-31 10:45:52 -0400 | [diff] [blame] | 26 | GrMtlCaps(const GrContextOptions& contextOptions, id<MTLDevice> device, |
| 27 | MTLFeatureSet featureSet); |
| 28 | |
Greg Daniel | cebcb84 | 2017-07-31 10:45:52 -0400 | [diff] [blame] | 29 | bool isConfigTexturable(GrPixelConfig config) const override { |
| 30 | return SkToBool(fConfigTable[config].fFlags & ConfigInfo::kTextureable_Flag); |
| 31 | } |
| 32 | |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 33 | int getRenderTargetSampleCount(int requestedCount, GrPixelConfig) const override; |
| 34 | int maxRenderTargetSampleCount(GrPixelConfig) const override; |
Greg Daniel | cebcb84 | 2017-07-31 10:45:52 -0400 | [diff] [blame] | 35 | |
Brian Salomon | 19eaf2d | 2018-03-19 16:06:44 -0400 | [diff] [blame] | 36 | bool surfaceSupportsWritePixels(const GrSurface*) const override { return true; } |
| 37 | bool surfaceSupportsReadPixels(const GrSurface*) const override { return true; } |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 38 | |
Greg Daniel | bb76ace | 2017-09-29 15:58:22 -0400 | [diff] [blame] | 39 | bool isConfigCopyable(GrPixelConfig config) const override { |
| 40 | return true; |
| 41 | } |
| 42 | |
Greg Daniel | cebcb84 | 2017-07-31 10:45:52 -0400 | [diff] [blame] | 43 | /** |
| 44 | * Returns both a supported and most prefered stencil format to use in draws. |
| 45 | */ |
Ethan Nicholas | 0106351 | 2018-10-08 16:58:25 -0400 | [diff] [blame] | 46 | const StencilFormat& preferredStencilFormat() const { |
| 47 | return fPreferredStencilFormat; |
Greg Daniel | cebcb84 | 2017-07-31 10:45:52 -0400 | [diff] [blame] | 48 | } |
Ethan Nicholas | 0106351 | 2018-10-08 16:58:25 -0400 | [diff] [blame] | 49 | |
Timothy Liang | e35055f | 2018-07-20 16:53:00 -0400 | [diff] [blame] | 50 | bool canCopyAsBlit(GrPixelConfig dstConfig, int dstSampleCount, GrSurfaceOrigin dstOrigin, |
| 51 | GrPixelConfig srcConfig, int srcSampleCount, GrSurfaceOrigin srcOrigin, |
| 52 | const SkIRect& srcRect, const SkIPoint& dstPoint, |
| 53 | bool areDstSrcSameObj) const; |
| 54 | |
Timothy Liang | e30739a | 2018-07-31 10:51:17 -0400 | [diff] [blame] | 55 | bool canCopyAsDraw(GrPixelConfig dstConfig, bool dstIsRenderable, |
| 56 | GrPixelConfig srcConfig, bool srcIsTextureable) const; |
| 57 | |
Timothy Liang | 70c787a | 2018-08-01 09:56:25 -0400 | [diff] [blame] | 58 | bool canCopyAsDrawThenBlit(GrPixelConfig dstConfig, GrPixelConfig srcConfig, |
| 59 | bool srcIsTextureable) const; |
| 60 | |
Greg Daniel | ba2c826 | 2018-05-03 15:28:58 -0400 | [diff] [blame] | 61 | bool canCopySurface(const GrSurfaceProxy* dst, const GrSurfaceProxy* src, |
Timothy Liang | e35055f | 2018-07-20 16:53:00 -0400 | [diff] [blame] | 62 | const SkIRect& srcRect, const SkIPoint& dstPoint) const override; |
Greg Daniel | ba2c826 | 2018-05-03 15:28:58 -0400 | [diff] [blame] | 63 | |
Brian Salomon | 2a4f983 | 2018-03-03 22:43:43 -0500 | [diff] [blame] | 64 | bool initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc, GrSurfaceOrigin*, |
Greg Daniel | cebcb84 | 2017-07-31 10:45:52 -0400 | [diff] [blame] | 65 | bool* rectsMustMatch, bool* disallowSubrect) const override { |
| 66 | return false; |
| 67 | } |
| 68 | |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 69 | bool validateBackendTexture(const GrBackendTexture&, SkColorType, |
| 70 | GrPixelConfig*) const override { |
| 71 | return false; |
| 72 | } |
| 73 | bool validateBackendRenderTarget(const GrBackendRenderTarget&, SkColorType, |
| 74 | GrPixelConfig*) const override { |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 75 | return false; |
| 76 | } |
| 77 | |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 78 | bool getConfigFromBackendFormat(const GrBackendFormat&, SkColorType, |
| 79 | GrPixelConfig*) const override { |
| 80 | return false; |
| 81 | } |
| 82 | |
Jim Van Verth | b7f0b9c | 2018-10-22 14:12:03 -0400 | [diff] [blame^] | 83 | bool getYUVAConfigFromBackendFormat(const GrBackendFormat&, |
| 84 | GrPixelConfig*) const override { |
| 85 | return false; |
| 86 | } |
| 87 | |
Ethan Nicholas | 56d19a5 | 2018-10-15 11:26:20 -0400 | [diff] [blame] | 88 | bool performPartialClearsAsDraws() const override { |
| 89 | return true; |
| 90 | } |
| 91 | |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 92 | private: |
Greg Daniel | cebcb84 | 2017-07-31 10:45:52 -0400 | [diff] [blame] | 93 | void initFeatureSet(MTLFeatureSet featureSet); |
Ben Wagner | 63fd760 | 2017-10-09 15:45:33 -0400 | [diff] [blame] | 94 | |
Ethan Nicholas | 0106351 | 2018-10-08 16:58:25 -0400 | [diff] [blame] | 95 | void initStencilFormat(const id<MTLDevice> device); |
| 96 | |
Greg Daniel | cebcb84 | 2017-07-31 10:45:52 -0400 | [diff] [blame] | 97 | void initGrCaps(const id<MTLDevice> device); |
| 98 | void initShaderCaps(); |
Timothy Liang | 036fdfe | 2018-06-28 15:50:36 -0400 | [diff] [blame] | 99 | |
| 100 | #ifdef GR_TEST_UTILS |
| 101 | GrBackendFormat onCreateFormatFromBackendTexture(const GrBackendTexture&) const override; |
| 102 | #endif |
| 103 | |
Greg Daniel | cebcb84 | 2017-07-31 10:45:52 -0400 | [diff] [blame] | 104 | void initConfigTable(); |
| 105 | |
| 106 | struct ConfigInfo { |
| 107 | ConfigInfo() : fFlags(0) {} |
| 108 | |
| 109 | enum { |
| 110 | kTextureable_Flag = 0x1, |
| 111 | kRenderable_Flag = 0x2, // Color attachment and blendable |
| 112 | kMSAA_Flag = 0x4, |
| 113 | kResolve_Flag = 0x8, |
| 114 | }; |
Brian Osman | 6305105 | 2018-08-27 13:36:48 -0400 | [diff] [blame] | 115 | // TODO: Put kMSAA_Flag back when MSAA is implemented |
Greg Daniel | cebcb84 | 2017-07-31 10:45:52 -0400 | [diff] [blame] | 116 | static const uint16_t kAllFlags = kTextureable_Flag | kRenderable_Flag | |
Brian Osman | 6305105 | 2018-08-27 13:36:48 -0400 | [diff] [blame] | 117 | /*kMSAA_Flag |*/ kResolve_Flag; |
Greg Daniel | cebcb84 | 2017-07-31 10:45:52 -0400 | [diff] [blame] | 118 | |
| 119 | uint16_t fFlags; |
| 120 | }; |
| 121 | ConfigInfo fConfigTable[kGrPixelConfigCnt]; |
| 122 | |
| 123 | enum class Platform { |
| 124 | kMac, |
| 125 | kIOS |
| 126 | }; |
| 127 | bool isMac() { return Platform::kMac == fPlatform; } |
| 128 | bool isIOS() { return Platform::kIOS == fPlatform; } |
| 129 | |
| 130 | Platform fPlatform; |
| 131 | int fFamilyGroup; |
| 132 | int fVersion; |
| 133 | |
| 134 | SkTDArray<int> fSampleCounts; |
| 135 | |
Ethan Nicholas | 0106351 | 2018-10-08 16:58:25 -0400 | [diff] [blame] | 136 | StencilFormat fPreferredStencilFormat; |
| 137 | |
Greg Daniel | cebcb84 | 2017-07-31 10:45:52 -0400 | [diff] [blame] | 138 | typedef GrCaps INHERITED; |
| 139 | }; |
| 140 | |
| 141 | #endif |