• 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_Caps_DEFINED
9 #define skgpu_Caps_DEFINED
10 
11 #include "experimental/graphite/src/ResourceTypes.h"
12 #include "include/core/SkImageInfo.h"
13 #include "include/core/SkRefCnt.h"
14 #include "src/gpu/ResourceKey.h"
15 
16 namespace SkSL {
17 struct ShaderCaps;
18 }
19 
20 namespace skgpu {
21 
22 class GraphicsPipelineDesc;
23 class GraphiteResourceKey;
24 struct RenderPassDesc;
25 class TextureInfo;
26 
27 class Caps : public SkRefCnt {
28 public:
29     ~Caps() override;
30 
shaderCaps()31     const SkSL::ShaderCaps* shaderCaps() const { return fShaderCaps.get(); }
32 
33     virtual TextureInfo getDefaultSampledTextureInfo(SkColorType,
34                                                      uint32_t levelCount,
35                                                      Protected,
36                                                      Renderable) const = 0;
37 
38     virtual TextureInfo getDefaultMSAATextureInfo(SkColorType,
39                                                   uint32_t sampleCount,
40                                                   Protected) const = 0;
41 
42     virtual TextureInfo getDefaultDepthStencilTextureInfo(Mask<DepthStencilFlags>,
43                                                           uint32_t sampleCount,
44                                                           Protected) const = 0;
45 
46     virtual UniqueKey makeGraphicsPipelineKey(const GraphicsPipelineDesc&,
47                                               const RenderPassDesc&) const = 0;
48 
49     bool areColorTypeAndTextureInfoCompatible(SkColorType, const TextureInfo&) const;
50 
51     bool isTexturable(const TextureInfo&) const;
52     virtual bool isRenderable(const TextureInfo&) const = 0;
53 
maxTextureSize()54     int maxTextureSize() const { return fMaxTextureSize; }
55 
56     virtual void buildKeyForTexture(SkISize dimensions,
57                                     const TextureInfo&,
58                                     ResourceType,
59                                     Shareable,
60                                     GraphiteResourceKey*) const = 0;
61 
62     // Returns the required alignment in bytes for the offset into a uniform buffer when binding it
63     // to a draw.
requiredUniformBufferAlignment()64     size_t requiredUniformBufferAlignment() const { return fRequiredUniformBufferAlignment; }
65 
66     // Returns the alignment in bytes for the offset into a Buffer when using it
67     // to transfer to or from a Texture with the given bytes per pixel.
68     virtual size_t getTransferBufferAlignment(size_t bytesPerPixel) const = 0;
69 
clampToBorderSupport()70     bool clampToBorderSupport() const { return fClampToBorderSupport; }
71 
72 protected:
73     Caps();
74 
75     int fMaxTextureSize = 0;
76     size_t fRequiredUniformBufferAlignment = 0;
77 
78     std::unique_ptr<SkSL::ShaderCaps> fShaderCaps;
79 
80     bool fClampToBorderSupport = true;
81 
82 private:
83     virtual bool onIsTexturable(const TextureInfo&) const = 0;
84     virtual bool onAreColorTypeAndTextureInfoCompatible(SkColorType, const TextureInfo&) const = 0;
85 };
86 
87 } // namespace skgpu
88 
89 #endif // skgpu_Caps_DEFINED
90