blob: d431022079bea10d8d692feaa7845c6c5904675b [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
Greg Daniel2f2caea2019-07-08 14:24:47 -040031 bool isFormatTexturable(GrColorType, const GrBackendFormat&) const override;
Robert Phillipsd8f79a22019-06-24 13:25:42 -040032
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,
Greg Daniel5c96db82019-07-09 14:06:58 -040038 GrColorType, 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
Greg Daniel5c96db82019-07-09 14:06:58 -040041 int maxRenderTargetSampleCount(GrColorType, 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
Greg Daniel5c96db82019-07-09 14:06:58 -040048 bool isFormatCopyable(GrColorType, const GrBackendFormat&) const override { return true; }
Robert Phillipsd8f79a22019-06-24 13:25:42 -040049 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
Jim Van Verthd361e642019-07-11 15:40:53 -040062 bool canCopyAsResolve(GrSurface* dst, int dstSampleCount, GrSurface* src, int srcSampleCount,
63 const SkIRect& srcRect, const SkIPoint& dstPoint) const;
64
Greg Daniel46cfbc62019-06-07 11:43:30 -040065 bool initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc,
Greg Danielcebcb842017-07-31 10:45:52 -040066 bool* rectsMustMatch, bool* disallowSubrect) const override {
67 return false;
68 }
69
Brian Salomonf391d0f2018-12-14 09:18:50 -050070 GrPixelConfig validateBackendRenderTarget(const GrBackendRenderTarget&,
Robert Phillips1e2cb442019-07-02 15:51:28 -040071 GrColorType) const override;
Greg Danielf5d87582017-12-18 14:48:15 -050072
Greg Danield742b6b2019-02-05 15:15:31 -050073 GrPixelConfig getYUVAConfigFromBackendFormat(const GrBackendFormat&) const override;
Jim Van Verthb7f0b9c2018-10-22 14:12:03 -040074
Greg Daniele877dce2019-07-11 10:52:43 -040075 GrBackendFormat getBackendFormatFromColorType(GrColorType ct) const override;
Brian Salomonbb8dde82019-06-27 10:52:13 -040076 GrBackendFormat getBackendFormatFromCompressionType(SkImage::CompressionType) const override;
Greg Daniel4065d452018-11-16 15:43:41 -050077
Greg Danieleb4a8272019-05-16 16:52:55 -040078 GrSwizzle getTextureSwizzle(const GrBackendFormat&, GrColorType) const override;
79 GrSwizzle getOutputSwizzle(const GrBackendFormat&, GrColorType) const override;
80
Greg Danielfaa095e2017-12-19 13:15:02 -050081private:
Greg Danielcebcb842017-07-31 10:45:52 -040082 void initFeatureSet(MTLFeatureSet featureSet);
Ben Wagner63fd7602017-10-09 15:45:33 -040083
Ethan Nicholas01063512018-10-08 16:58:25 -040084 void initStencilFormat(const id<MTLDevice> device);
85
Greg Danielcebcb842017-07-31 10:45:52 -040086 void initGrCaps(const id<MTLDevice> device);
87 void initShaderCaps();
Timothy Liang036fdfe2018-06-28 15:50:36 -040088
Greg Danielcebcb842017-07-31 10:45:52 -040089 void initConfigTable();
90
Jim Van Verth686046b2019-03-18 15:39:22 -040091 bool onSurfaceSupportsWritePixels(const GrSurface*) const override;
Brian Salomonc67c31c2018-12-06 10:00:03 -050092 bool onCanCopySurface(const GrSurfaceProxy* dst, const GrSurfaceProxy* src,
93 const SkIRect& srcRect, const SkIPoint& dstPoint) const override;
Brian Salomon26de56e2019-04-10 12:14:26 -040094 size_t onTransferFromOffsetAlignment(GrColorType bufferColorType) const override {
95 // Transfer buffers not yet supported.
96 return 0;
97 }
Greg Daniel627d0532019-07-08 16:48:14 -040098 GrPixelConfig onGetConfigFromBackendFormat(const GrBackendFormat&, GrColorType) const override;
99 bool onAreColorTypeAndFormatCompatible(GrColorType, const GrBackendFormat&) const override;
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 };
110 static const uint16_t kAllFlags = kTextureable_Flag | kRenderable_Flag |
Jim Van Verthd361e642019-07-11 15:40:53 -0400111 kMSAA_Flag | kResolve_Flag;
Greg Danielcebcb842017-07-31 10:45:52 -0400112
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 Nicholas01063512018-10-08 16:58:25 -0400130 StencilFormat fPreferredStencilFormat;
131
Greg Danielcebcb842017-07-31 10:45:52 -0400132 typedef GrCaps INHERITED;
133};
134
135#endif