blob: 94724167dc13aace3a2090d4f5525664cb5f104d [file] [log] [blame]
Greg Danielcebcb842017-07-31 10:45:52 -04001/*
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 Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/private/SkTDArray.h"
12#include "src/gpu/GrCaps.h"
13#include "src/gpu/mtl/GrMtlStencilAttachment.h"
Greg Danielcebcb842017-07-31 10:45:52 -040014
15#import <Metal/Metal.h>
16
17class GrShaderCaps;
18
19/**
20 * Stores some capabilities of a Mtl backend.
21 */
22class GrMtlCaps : public GrCaps {
23public:
Ethan Nicholas01063512018-10-08 16:58:25 -040024 typedef GrMtlStencilAttachment::Format StencilFormat;
25
Greg Danielcebcb842017-07-31 10:45:52 -040026 GrMtlCaps(const GrContextOptions& contextOptions, id<MTLDevice> device,
27 MTLFeatureSet featureSet);
28
Robert Phillipsf209e882019-06-25 15:59:50 -040029 bool isFormatSRGB(const GrBackendFormat& format) const override;
30
Robert Phillipsd8f79a22019-06-24 13:25:42 -040031 bool isFormatTexturable(SkColorType, const GrBackendFormat&) const override;
32
Greg Danielcebcb842017-07-31 10:45:52 -040033 bool isConfigTexturable(GrPixelConfig config) const override {
34 return SkToBool(fConfigTable[config].fFlags & ConfigInfo::kTextureable_Flag);
35 }
36
Robert Phillipsd8f79a22019-06-24 13:25:42 -040037 int getRenderTargetSampleCount(int requestedCount,
38 SkColorType, const GrBackendFormat&) const override;
Brian Salomonbdecacf2018-02-02 20:32:49 -050039 int getRenderTargetSampleCount(int requestedCount, GrPixelConfig) const override;
Robert Phillipsd8f79a22019-06-24 13:25:42 -040040
41 int maxRenderTargetSampleCount(SkColorType, const GrBackendFormat&) const override;
Brian Salomonbdecacf2018-02-02 20:32:49 -050042 int maxRenderTargetSampleCount(GrPixelConfig) const override;
Greg Danielcebcb842017-07-31 10:45:52 -040043
Brian Salomondc0710f2019-07-01 14:59:32 -040044 SurfaceReadPixelsSupport surfaceSupportsReadPixels(const GrSurface*) const override {
45 return SurfaceReadPixelsSupport::kSupported;
Emircan Uysaler23ca4e72019-06-24 10:53:09 -040046 }
Brian Salomon5f33a8c2018-02-26 14:32:39 -050047
Robert Phillipsd8f79a22019-06-24 13:25:42 -040048 bool isFormatCopyable(SkColorType, const GrBackendFormat&) const override { return true; }
49 bool isConfigCopyable(GrPixelConfig) const override { return true; }
Greg Danielbb76ace2017-09-29 15:58:22 -040050
Greg Danielcebcb842017-07-31 10:45:52 -040051 /**
52 * Returns both a supported and most prefered stencil format to use in draws.
53 */
Ethan Nicholas01063512018-10-08 16:58:25 -040054 const StencilFormat& preferredStencilFormat() const {
55 return fPreferredStencilFormat;
Greg Danielcebcb842017-07-31 10:45:52 -040056 }
Ethan Nicholas01063512018-10-08 16:58:25 -040057
Greg Daniel46cfbc62019-06-07 11:43:30 -040058 bool canCopyAsBlit(GrPixelConfig dstConfig, int dstSampleCount, GrPixelConfig srcConfig,
59 int srcSampleCount, const SkIRect& srcRect, const SkIPoint& dstPoint,
Timothy Liange35055f2018-07-20 16:53:00 -040060 bool areDstSrcSameObj) const;
61
Greg Daniel46cfbc62019-06-07 11:43:30 -040062 bool initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc,
Greg Danielcebcb842017-07-31 10:45:52 -040063 bool* rectsMustMatch, bool* disallowSubrect) const override {
64 return false;
65 }
66
Brian Salomonf391d0f2018-12-14 09:18:50 -050067 GrPixelConfig validateBackendRenderTarget(const GrBackendRenderTarget&,
Robert Phillips1e2cb442019-07-02 15:51:28 -040068 GrColorType) const override;
Greg Danielf5d87582017-12-18 14:48:15 -050069
Robert Phillips1e2cb442019-07-02 15:51:28 -040070 bool areColorTypeAndFormatCompatible(GrColorType, const GrBackendFormat&) const override;
Robert Phillipsc046ff02019-07-01 10:34:03 -040071
Robert Phillips1e2cb442019-07-02 15:51:28 -040072 GrPixelConfig getConfigFromBackendFormat(const GrBackendFormat&, GrColorType) const override;
Robert Phillipsfc711a22018-02-13 17:03:00 -050073
Greg Danield742b6b2019-02-05 15:15:31 -050074 GrPixelConfig getYUVAConfigFromBackendFormat(const GrBackendFormat&) const override;
Jim Van Verthb7f0b9c2018-10-22 14:12:03 -040075
Greg Daniel4065d452018-11-16 15:43:41 -050076 GrBackendFormat getBackendFormatFromGrColorType(GrColorType ct,
77 GrSRGBEncoded srgbEncoded) const override;
Brian Salomonbb8dde82019-06-27 10:52:13 -040078 GrBackendFormat getBackendFormatFromCompressionType(SkImage::CompressionType) const override;
Greg Daniel4065d452018-11-16 15:43:41 -050079
Greg Danieleb4a8272019-05-16 16:52:55 -040080 GrSwizzle getTextureSwizzle(const GrBackendFormat&, GrColorType) const override;
81 GrSwizzle getOutputSwizzle(const GrBackendFormat&, GrColorType) const override;
82
Greg Danielfaa095e2017-12-19 13:15:02 -050083private:
Greg Danielcebcb842017-07-31 10:45:52 -040084 void initFeatureSet(MTLFeatureSet featureSet);
Ben Wagner63fd7602017-10-09 15:45:33 -040085
Ethan Nicholas01063512018-10-08 16:58:25 -040086 void initStencilFormat(const id<MTLDevice> device);
87
Greg Danielcebcb842017-07-31 10:45:52 -040088 void initGrCaps(const id<MTLDevice> device);
89 void initShaderCaps();
Timothy Liang036fdfe2018-06-28 15:50:36 -040090
Greg Danielcebcb842017-07-31 10:45:52 -040091 void initConfigTable();
92
Jim Van Verth686046b2019-03-18 15:39:22 -040093 bool onSurfaceSupportsWritePixels(const GrSurface*) const override;
Brian Salomonc67c31c2018-12-06 10:00:03 -050094 bool onCanCopySurface(const GrSurfaceProxy* dst, const GrSurfaceProxy* src,
95 const SkIRect& srcRect, const SkIPoint& dstPoint) const override;
Brian Salomon26de56e2019-04-10 12:14:26 -040096 size_t onTransferFromOffsetAlignment(GrColorType bufferColorType) const override {
97 // Transfer buffers not yet supported.
98 return 0;
99 }
Brian Salomonc67c31c2018-12-06 10:00:03 -0500100
Greg Danielcebcb842017-07-31 10:45:52 -0400101 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 Osman63051052018-08-27 13:36:48 -0400110 // TODO: Put kMSAA_Flag back when MSAA is implemented
Greg Danielcebcb842017-07-31 10:45:52 -0400111 static const uint16_t kAllFlags = kTextureable_Flag | kRenderable_Flag |
Brian Osman63051052018-08-27 13:36:48 -0400112 /*kMSAA_Flag |*/ kResolve_Flag;
Greg Danielcebcb842017-07-31 10:45:52 -0400113
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 Nicholas01063512018-10-08 16:58:25 -0400131 StencilFormat fPreferredStencilFormat;
132
Greg Danielcebcb842017-07-31 10:45:52 -0400133 typedef GrCaps INHERITED;
134};
135
136#endif