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(Mask<DepthStencilFlags>, 32 uint32_t sampleCount, 33 Protected) const override; 34 35 UniqueKey makeGraphicsPipelineKey(const GraphicsPipelineDesc&, 36 const RenderPassDesc&) const override; 37 isMac()38 bool isMac() const { return fGPUFamily == GPUFamily::kMac; } isApple()39 bool isApple()const { return fGPUFamily == GPUFamily::kApple; } 40 getMinBufferAlignment()41 size_t getMinBufferAlignment() const { return this->isMac() ? 4 : 1; } 42 43 bool isRenderable(const skgpu::TextureInfo&) const override; 44 45 void buildKeyForTexture(SkISize dimensions, 46 const skgpu::TextureInfo&, 47 ResourceType, 48 Shareable, 49 GraphiteResourceKey*) const override; 50 51 private: 52 void initGPUFamily(const id<MTLDevice>); 53 54 void initCaps(const id<MTLDevice>); 55 void initShaderCaps(); 56 void initFormatTable(); 57 58 enum class GPUFamily { 59 kMac, 60 kApple, 61 }; 62 static bool GetGPUFamily(id<MTLDevice> device, GPUFamily* gpuFamily, int* group); 63 static bool GetGPUFamilyFromFeatureSet(id<MTLDevice> device, GPUFamily* gpuFamily, 64 int* group); 65 66 bool onAreColorTypeAndTextureInfoCompatible(SkColorType, 67 const skgpu::TextureInfo&) const override; 68 69 bool onIsTexturable(const skgpu::TextureInfo&) const override; 70 bool isTexturable(MTLPixelFormat) const; 71 bool isRenderable(MTLPixelFormat, uint32_t numSamples) const; 72 73 size_t getTransferBufferAlignment(size_t bytesPerPixel) const override; 74 75 GPUFamily fGPUFamily; 76 int fFamilyGroup; 77 }; 78 79 } // namespace skgpu::mtl 80 81 #endif // skgpu_MtlCaps_DEFINED 82