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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "include/private/SkTDArray.h" |
| 12 | #include "src/gpu/GrCaps.h" |
| 13 | #include "src/gpu/mtl/GrMtlStencilAttachment.h" |
Greg Daniel | cebcb84 | 2017-07-31 10:45:52 -0400 | [diff] [blame] | 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 | |
Robert Phillips | f209e88 | 2019-06-25 15:59:50 -0400 | [diff] [blame] | 29 | bool isFormatSRGB(const GrBackendFormat& format) const override; |
| 30 | |
Robert Phillips | d8f79a2 | 2019-06-24 13:25:42 -0400 | [diff] [blame] | 31 | bool isFormatTexturable(SkColorType, const GrBackendFormat&) const override; |
| 32 | |
Greg Daniel | cebcb84 | 2017-07-31 10:45:52 -0400 | [diff] [blame] | 33 | bool isConfigTexturable(GrPixelConfig config) const override { |
| 34 | return SkToBool(fConfigTable[config].fFlags & ConfigInfo::kTextureable_Flag); |
| 35 | } |
| 36 | |
Robert Phillips | d8f79a2 | 2019-06-24 13:25:42 -0400 | [diff] [blame] | 37 | int getRenderTargetSampleCount(int requestedCount, |
| 38 | SkColorType, const GrBackendFormat&) const override; |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 39 | int getRenderTargetSampleCount(int requestedCount, GrPixelConfig) const override; |
Robert Phillips | d8f79a2 | 2019-06-24 13:25:42 -0400 | [diff] [blame] | 40 | |
| 41 | int maxRenderTargetSampleCount(SkColorType, const GrBackendFormat&) const override; |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 42 | int maxRenderTargetSampleCount(GrPixelConfig) const override; |
Greg Daniel | cebcb84 | 2017-07-31 10:45:52 -0400 | [diff] [blame] | 43 | |
Brian Salomon | dc0710f | 2019-07-01 14:59:32 -0400 | [diff] [blame] | 44 | SurfaceReadPixelsSupport surfaceSupportsReadPixels(const GrSurface*) const override { |
| 45 | return SurfaceReadPixelsSupport::kSupported; |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 46 | } |
Brian Salomon | 5f33a8c | 2018-02-26 14:32:39 -0500 | [diff] [blame] | 47 | |
Robert Phillips | d8f79a2 | 2019-06-24 13:25:42 -0400 | [diff] [blame] | 48 | bool isFormatCopyable(SkColorType, const GrBackendFormat&) const override { return true; } |
| 49 | bool isConfigCopyable(GrPixelConfig) const override { return true; } |
Greg Daniel | bb76ace | 2017-09-29 15:58:22 -0400 | [diff] [blame] | 50 | |
Greg Daniel | cebcb84 | 2017-07-31 10:45:52 -0400 | [diff] [blame] | 51 | /** |
| 52 | * Returns both a supported and most prefered stencil format to use in draws. |
| 53 | */ |
Ethan Nicholas | 0106351 | 2018-10-08 16:58:25 -0400 | [diff] [blame] | 54 | const StencilFormat& preferredStencilFormat() const { |
| 55 | return fPreferredStencilFormat; |
Greg Daniel | cebcb84 | 2017-07-31 10:45:52 -0400 | [diff] [blame] | 56 | } |
Ethan Nicholas | 0106351 | 2018-10-08 16:58:25 -0400 | [diff] [blame] | 57 | |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 58 | bool canCopyAsBlit(GrPixelConfig dstConfig, int dstSampleCount, GrPixelConfig srcConfig, |
| 59 | int srcSampleCount, const SkIRect& srcRect, const SkIPoint& dstPoint, |
Timothy Liang | e35055f | 2018-07-20 16:53:00 -0400 | [diff] [blame] | 60 | bool areDstSrcSameObj) const; |
| 61 | |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 62 | bool initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc, |
Greg Daniel | cebcb84 | 2017-07-31 10:45:52 -0400 | [diff] [blame] | 63 | bool* rectsMustMatch, bool* disallowSubrect) const override { |
| 64 | return false; |
| 65 | } |
| 66 | |
Brian Salomon | f391d0f | 2018-12-14 09:18:50 -0500 | [diff] [blame] | 67 | GrPixelConfig validateBackendRenderTarget(const GrBackendRenderTarget&, |
Robert Phillips | 1e2cb44 | 2019-07-02 15:51:28 -0400 | [diff] [blame^] | 68 | GrColorType) const override; |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 69 | |
Robert Phillips | 1e2cb44 | 2019-07-02 15:51:28 -0400 | [diff] [blame^] | 70 | bool areColorTypeAndFormatCompatible(GrColorType, const GrBackendFormat&) const override; |
Robert Phillips | c046ff0 | 2019-07-01 10:34:03 -0400 | [diff] [blame] | 71 | |
Robert Phillips | 1e2cb44 | 2019-07-02 15:51:28 -0400 | [diff] [blame^] | 72 | GrPixelConfig getConfigFromBackendFormat(const GrBackendFormat&, GrColorType) const override; |
Robert Phillips | fc711a2 | 2018-02-13 17:03:00 -0500 | [diff] [blame] | 73 | |
Greg Daniel | d742b6b | 2019-02-05 15:15:31 -0500 | [diff] [blame] | 74 | GrPixelConfig getYUVAConfigFromBackendFormat(const GrBackendFormat&) const override; |
Jim Van Verth | b7f0b9c | 2018-10-22 14:12:03 -0400 | [diff] [blame] | 75 | |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 76 | GrBackendFormat getBackendFormatFromGrColorType(GrColorType ct, |
| 77 | GrSRGBEncoded srgbEncoded) const override; |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 78 | GrBackendFormat getBackendFormatFromCompressionType(SkImage::CompressionType) const override; |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 79 | |
Greg Daniel | eb4a827 | 2019-05-16 16:52:55 -0400 | [diff] [blame] | 80 | GrSwizzle getTextureSwizzle(const GrBackendFormat&, GrColorType) const override; |
| 81 | GrSwizzle getOutputSwizzle(const GrBackendFormat&, GrColorType) const override; |
| 82 | |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 83 | private: |
Greg Daniel | cebcb84 | 2017-07-31 10:45:52 -0400 | [diff] [blame] | 84 | void initFeatureSet(MTLFeatureSet featureSet); |
Ben Wagner | 63fd760 | 2017-10-09 15:45:33 -0400 | [diff] [blame] | 85 | |
Ethan Nicholas | 0106351 | 2018-10-08 16:58:25 -0400 | [diff] [blame] | 86 | void initStencilFormat(const id<MTLDevice> device); |
| 87 | |
Greg Daniel | cebcb84 | 2017-07-31 10:45:52 -0400 | [diff] [blame] | 88 | void initGrCaps(const id<MTLDevice> device); |
| 89 | void initShaderCaps(); |
Timothy Liang | 036fdfe | 2018-06-28 15:50:36 -0400 | [diff] [blame] | 90 | |
Greg Daniel | cebcb84 | 2017-07-31 10:45:52 -0400 | [diff] [blame] | 91 | void initConfigTable(); |
| 92 | |
Jim Van Verth | 686046b | 2019-03-18 15:39:22 -0400 | [diff] [blame] | 93 | bool onSurfaceSupportsWritePixels(const GrSurface*) const override; |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 94 | bool onCanCopySurface(const GrSurfaceProxy* dst, const GrSurfaceProxy* src, |
| 95 | const SkIRect& srcRect, const SkIPoint& dstPoint) const override; |
Brian Salomon | 26de56e | 2019-04-10 12:14:26 -0400 | [diff] [blame] | 96 | size_t onTransferFromOffsetAlignment(GrColorType bufferColorType) const override { |
| 97 | // Transfer buffers not yet supported. |
| 98 | return 0; |
| 99 | } |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 100 | |
Greg Daniel | cebcb84 | 2017-07-31 10:45:52 -0400 | [diff] [blame] | 101 | struct ConfigInfo { |
| 102 | ConfigInfo() : fFlags(0) {} |
| 103 | |
| 104 | enum { |
| 105 | kTextureable_Flag = 0x1, |
| 106 | kRenderable_Flag = 0x2, // Color attachment and blendable |
| 107 | kMSAA_Flag = 0x4, |
| 108 | kResolve_Flag = 0x8, |
| 109 | }; |
Brian Osman | 6305105 | 2018-08-27 13:36:48 -0400 | [diff] [blame] | 110 | // TODO: Put kMSAA_Flag back when MSAA is implemented |
Greg Daniel | cebcb84 | 2017-07-31 10:45:52 -0400 | [diff] [blame] | 111 | static const uint16_t kAllFlags = kTextureable_Flag | kRenderable_Flag | |
Brian Osman | 6305105 | 2018-08-27 13:36:48 -0400 | [diff] [blame] | 112 | /*kMSAA_Flag |*/ kResolve_Flag; |
Greg Daniel | cebcb84 | 2017-07-31 10:45:52 -0400 | [diff] [blame] | 113 | |
| 114 | uint16_t fFlags; |
| 115 | }; |
| 116 | ConfigInfo fConfigTable[kGrPixelConfigCnt]; |
| 117 | |
| 118 | enum class Platform { |
| 119 | kMac, |
| 120 | kIOS |
| 121 | }; |
| 122 | bool isMac() { return Platform::kMac == fPlatform; } |
| 123 | bool isIOS() { return Platform::kIOS == fPlatform; } |
| 124 | |
| 125 | Platform fPlatform; |
| 126 | int fFamilyGroup; |
| 127 | int fVersion; |
| 128 | |
| 129 | SkTDArray<int> fSampleCounts; |
| 130 | |
Ethan Nicholas | 0106351 | 2018-10-08 16:58:25 -0400 | [diff] [blame] | 131 | StencilFormat fPreferredStencilFormat; |
| 132 | |
Greg Daniel | cebcb84 | 2017-07-31 10:45:52 -0400 | [diff] [blame] | 133 | typedef GrCaps INHERITED; |
| 134 | }; |
| 135 | |
| 136 | #endif |