• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2021 Google LLC
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 skgpu_MtlCaps_DEFINED
9 #define skgpu_MtlCaps_DEFINED
10 
11 #include "experimental/graphite/src/Caps.h"
12 
13 #import <Metal/Metal.h>
14 
15 namespace skgpu::mtl {
16 
17 class Caps final : public skgpu::Caps {
18 public:
19     Caps(const id<MTLDevice>);
~Caps()20     ~Caps() override {}
21 
22     skgpu::TextureInfo getDefaultSampledTextureInfo(SkColorType,
23                                                     uint32_t levelCount,
24                                                     Protected,
25                                                     Renderable) const override;
26 
27     skgpu::TextureInfo getDefaultMSAATextureInfo(SkColorType,
28                                                  uint32_t sampleCount,
29                                                  Protected) const override;
30 
31     skgpu::TextureInfo getDefaultDepthStencilTextureInfo(DepthStencilType,
32                                                          uint32_t sampleCount,
33                                                          Protected) const override;
34 
isMac()35     bool isMac() const { return fGPUFamily == GPUFamily::kMac; }
isApple()36     bool isApple()const  { return fGPUFamily == GPUFamily::kApple; }
37 
getMinBufferAlignment()38     size_t getMinBufferAlignment() const { return this->isMac() ? 4 : 1; }
39 
40 private:
41     void initGPUFamily(const id<MTLDevice>);
42 
43     void initCaps(const id<MTLDevice>);
44     void initShaderCaps();
45     void initFormatTable();
46 
47     enum class GPUFamily {
48         kMac,
49         kApple,
50     };
51     static bool GetGPUFamily(id<MTLDevice> device, GPUFamily* gpuFamily, int* group);
52     static bool GetGPUFamilyFromFeatureSet(id<MTLDevice> device, GPUFamily* gpuFamily,
53                                            int* group);
54 
55     GPUFamily fGPUFamily;
56     int fFamilyGroup;
57 };
58 
59 } // namespace skgpu::mtl
60 
61 #endif // skgpu_MtlCaps_DEFINED
62