Debian Codegraph @

src/gpu/graphite/ShaderInfo.h

raw
1 /*
2 * Copyright 2024 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_graphite_ShaderInfo_DEFINED
9 #define skgpu_graphite_ShaderInfo_DEFINED
10
11 #include "include/private/base/SkTArray.h"
12 #include "src/base/SkArenaAlloc.h"
13 #include "src/gpu/Blend.h"
14 #include "src/gpu/Swizzle.h"
15 #include "src/gpu/graphite/Caps.h"
16 #include "src/gpu/graphite/ResourceTypes.h"
17 #include "src/gpu/graphite/UniquePaintParamsID.h"
18
19 namespace skgpu::graphite {
20
21 class RenderStep;
22 class RuntimeEffectDictionary;
23 class ShaderCodeDictionary;
24 class ShaderNode;
25 enum class TextureFormat : uint8_t;
26
27 // ShaderInfo holds all root ShaderNodes defined for a PaintParams as well as the extracted fixed
28 // function blending parameters and other aggregate requirements for the effect trees that have
29 // been linked into a single fragment program (sans any RenderStep fragment work and fixed SkSL
30 // logic required for all rendering in Graphite).
31 class ShaderInfo {
32 public:
33 // Accepts a real or, by default, an invalid/nullptr pointer to a container of SamplerDescs.
34 // Backend implementations which may utilize static / immutable samplers should pass in a real
35 // pointer to indicate that shader node data must be analyzed to determine whether
36 // immutable samplers are used, and if so, ascertain SamplerDescs for them.
37 // TODO(b/366220690): Actually perform this analysis.
38 //
39 // If provided a valid container ptr, this function will delegate the addition of SamplerDescs
40 // for each sampler the nodes utilize (dynamic and immutable). This way, a SamplerDesc's index
41 // within the container can inform its binding order. Each SamplerDesc will be either:
42 // 1) a default-constructed SamplerDesc, indicating the use of a "regular" dynamic sampler which
43 // requires no special handling OR
44 // 2) a real SamplerDesc describing an immutable sampler. Backend pipelines can then use the
45 // desc to obtain a real immutable sampler pointer (which typically must be included in
46 // pipeline layouts)
47 static std::unique_ptr<ShaderInfo> Make(const Caps*,
48 const ShaderCodeDictionary*,
49 const RuntimeEffectDictionary*,
50 const RenderPassDesc& rpDesc,
51 const RenderStep*,
52 UniquePaintParamsID,
53 skia_private::TArray<SamplerDesc>* outDescs = nullptr);
54
55 const ShaderCodeDictionary* shaderCodeDictionary() const {
56 return fShaderCodeDictionary;
57 }
58 const RuntimeEffectDictionary* runtimeEffectDictionary() const {
59 return fRuntimeEffectDictionary;
60 }
61
62 const char* uniformSsboIndex() const { return fUniformSsboIndex; }
63
64 DstReadStrategy dstReadStrategy() const { return fDstReadStrategy; }
65 const skgpu::BlendInfo& blendInfo() const { return fBlendInfo; }
66
67 const std::string& vertexSkSL() const { return fVertexSkSL; }
68 const std::string& fragmentSkSL() const { return fFragmentSkSL; }
69
70 const std::string& vsLabel() const { return fVSLabel; }
71 const std::string& fsLabel() const { return fFSLabel; }
72 // Matches ContextUtils::GetPipelineLabel() for the same args that were passed to Make()
73 const std::string& pipelineLabel() const { return fPipelineLabel; }
74
75 int numFragmentTexturesAndSamplers() const { return fNumFragmentTexturesAndSamplers; }
76 bool hasCombinedUniforms() const { return fHasCombinedUniforms; }
77 bool hasGradientBuffer() const { return fHasGradientBuffer; }
78
79 // Name used in-shader for gradient buffer uniform.
80 static constexpr char kGradientBufferName[] = "fsGradientBuffer";
81
82 private:
83 struct SharedGeneratorData;
84
85 ShaderInfo(const ShaderCodeDictionary*,
86 const RuntimeEffectDictionary*,
87 const char* uniformSsboIndex,
88 DstReadStrategy);
89
90 // Determines fNumFragmentTexturesAndSamplers, fHasPaintUniforms, fHasGradientBuffer,
91 // fHasSsboIndexVarying, and if a valid SamplerDesc ptr is passed in, any immutable
92 // sampler SamplerDescs.
93 void generateFragmentSkSL(const Caps*,
94 const ShaderCodeDictionary*,
95 const char* label,
96 const RenderStep*,
97 UniquePaintParamsID,
98 TextureFormat targetFormat,
99 skgpu::Swizzle writeSwizzle,
100 skia_private::TArray<SamplerDesc>* outDescs,
101 const SharedGeneratorData&);
102
103 void generateVertexSkSL(const Caps*,
104 const RenderStep*,
105 const SharedGeneratorData&);
106
107 const ShaderCodeDictionary* fShaderCodeDictionary;
108 const RuntimeEffectDictionary* fRuntimeEffectDictionary;
109 const char* fUniformSsboIndex;
110
111 // The blendInfo represents the actual GPU blend operations, which may or may not completely
112 // implement the paint and coverage blending defined by the root nodes.
113 skgpu::BlendInfo fBlendInfo;
114 DstReadStrategy fDstReadStrategy = DstReadStrategy::kNoneRequired;
115
116 std::string fVertexSkSL;
117 std::string fFragmentSkSL;
118 std::string fVSLabel;
119 std::string fFSLabel;
120 std::string fPipelineLabel;
121
122 int fNumFragmentTexturesAndSamplers = 0;
123 bool fHasCombinedUniforms = false;
124 bool fHasGradientBuffer = false;
125 };
126
127 } // namespace skgpu::graphite
128
129 #endif // skgpu_graphite_ShaderInfo_DEFINED