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 | |
Greg Daniel | 2f2caea | 2019-07-08 14:24:47 -0400 | [diff] [blame] | 31 | bool isFormatTexturable(GrColorType, const GrBackendFormat&) const override; |
Robert Phillips | d8f79a2 | 2019-06-24 13:25:42 -0400 | [diff] [blame] | 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, |
Greg Daniel | 5c96db8 | 2019-07-09 14:06:58 -0400 | [diff] [blame] | 38 | GrColorType, 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 | |
Greg Daniel | 5c96db8 | 2019-07-09 14:06:58 -0400 | [diff] [blame] | 41 | int maxRenderTargetSampleCount(GrColorType, 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 | |
Greg Daniel | 5c96db8 | 2019-07-09 14:06:58 -0400 | [diff] [blame] | 48 | bool isFormatCopyable(GrColorType, const GrBackendFormat&) const override { return true; } |
Robert Phillips | d8f79a2 | 2019-06-24 13:25:42 -0400 | [diff] [blame] | 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 | |
Jim Van Verth | d361e64 | 2019-07-11 15:40:53 -0400 | [diff] [blame^] | 62 | bool canCopyAsResolve(GrSurface* dst, int dstSampleCount, GrSurface* src, int srcSampleCount, |
| 63 | const SkIRect& srcRect, const SkIPoint& dstPoint) const; |
| 64 | |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 65 | bool initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc, |
Greg Daniel | cebcb84 | 2017-07-31 10:45:52 -0400 | [diff] [blame] | 66 | bool* rectsMustMatch, bool* disallowSubrect) const override { |
| 67 | return false; |
| 68 | } |
| 69 | |
Brian Salomon | f391d0f | 2018-12-14 09:18:50 -0500 | [diff] [blame] | 70 | GrPixelConfig validateBackendRenderTarget(const GrBackendRenderTarget&, |
Robert Phillips | 1e2cb44 | 2019-07-02 15:51:28 -0400 | [diff] [blame] | 71 | GrColorType) const override; |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 72 | |
Greg Daniel | d742b6b | 2019-02-05 15:15:31 -0500 | [diff] [blame] | 73 | GrPixelConfig getYUVAConfigFromBackendFormat(const GrBackendFormat&) const override; |
Jim Van Verth | b7f0b9c | 2018-10-22 14:12:03 -0400 | [diff] [blame] | 74 | |
Greg Daniel | e877dce | 2019-07-11 10:52:43 -0400 | [diff] [blame] | 75 | GrBackendFormat getBackendFormatFromColorType(GrColorType ct) const override; |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 76 | GrBackendFormat getBackendFormatFromCompressionType(SkImage::CompressionType) const override; |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 77 | |
Greg Daniel | eb4a827 | 2019-05-16 16:52:55 -0400 | [diff] [blame] | 78 | GrSwizzle getTextureSwizzle(const GrBackendFormat&, GrColorType) const override; |
| 79 | GrSwizzle getOutputSwizzle(const GrBackendFormat&, GrColorType) const override; |
| 80 | |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 81 | private: |
Greg Daniel | cebcb84 | 2017-07-31 10:45:52 -0400 | [diff] [blame] | 82 | void initFeatureSet(MTLFeatureSet featureSet); |
Ben Wagner | 63fd760 | 2017-10-09 15:45:33 -0400 | [diff] [blame] | 83 | |
Ethan Nicholas | 0106351 | 2018-10-08 16:58:25 -0400 | [diff] [blame] | 84 | void initStencilFormat(const id<MTLDevice> device); |
| 85 | |
Greg Daniel | cebcb84 | 2017-07-31 10:45:52 -0400 | [diff] [blame] | 86 | void initGrCaps(const id<MTLDevice> device); |
| 87 | void initShaderCaps(); |
Timothy Liang | 036fdfe | 2018-06-28 15:50:36 -0400 | [diff] [blame] | 88 | |
Greg Daniel | cebcb84 | 2017-07-31 10:45:52 -0400 | [diff] [blame] | 89 | void initConfigTable(); |
| 90 | |
Jim Van Verth | 686046b | 2019-03-18 15:39:22 -0400 | [diff] [blame] | 91 | bool onSurfaceSupportsWritePixels(const GrSurface*) const override; |
Brian Salomon | c67c31c | 2018-12-06 10:00:03 -0500 | [diff] [blame] | 92 | bool onCanCopySurface(const GrSurfaceProxy* dst, const GrSurfaceProxy* src, |
| 93 | const SkIRect& srcRect, const SkIPoint& dstPoint) const override; |
Brian Salomon | 26de56e | 2019-04-10 12:14:26 -0400 | [diff] [blame] | 94 | size_t onTransferFromOffsetAlignment(GrColorType bufferColorType) const override { |
| 95 | // Transfer buffers not yet supported. |
| 96 | return 0; |
| 97 | } |
Greg Daniel | 627d053 | 2019-07-08 16:48:14 -0400 | [diff] [blame] | 98 | GrPixelConfig onGetConfigFromBackendFormat(const GrBackendFormat&, GrColorType) const override; |
| 99 | bool onAreColorTypeAndFormatCompatible(GrColorType, const GrBackendFormat&) const override; |
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 | }; |
| 110 | static const uint16_t kAllFlags = kTextureable_Flag | kRenderable_Flag | |
Jim Van Verth | d361e64 | 2019-07-11 15:40:53 -0400 | [diff] [blame^] | 111 | kMSAA_Flag | kResolve_Flag; |
Greg Daniel | cebcb84 | 2017-07-31 10:45:52 -0400 | [diff] [blame] | 112 | |
| 113 | uint16_t fFlags; |
| 114 | }; |
| 115 | ConfigInfo fConfigTable[kGrPixelConfigCnt]; |
| 116 | |
| 117 | enum class Platform { |
| 118 | kMac, |
| 119 | kIOS |
| 120 | }; |
| 121 | bool isMac() { return Platform::kMac == fPlatform; } |
| 122 | bool isIOS() { return Platform::kIOS == fPlatform; } |
| 123 | |
| 124 | Platform fPlatform; |
| 125 | int fFamilyGroup; |
| 126 | int fVersion; |
| 127 | |
| 128 | SkTDArray<int> fSampleCounts; |
| 129 | |
Ethan Nicholas | 0106351 | 2018-10-08 16:58:25 -0400 | [diff] [blame] | 130 | StencilFormat fPreferredStencilFormat; |
| 131 | |
Greg Daniel | cebcb84 | 2017-07-31 10:45:52 -0400 | [diff] [blame] | 132 | typedef GrCaps INHERITED; |
| 133 | }; |
| 134 | |
| 135 | #endif |