Debian Codegraph @

src/gpu/graphite/dawn/DawnGraphicsPipeline.h

raw ◀ ▶
1 Debian patch touch this file
1 /*
2 * Copyright 2022 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_DawnGraphicsPipeline_DEFINED
9 #define skgpu_graphite_DawnGraphicsPipeline_DEFINED
10
11 #include "include/core/SkRefCnt.h"
12 #include "include/core/SkSpan.h"
13 #include "include/ports/SkCFObject.h"
14 #include "include/private/base/SkTArray.h"
15 #include "src/gpu/graphite/DrawTypes.h"
16 #include "src/gpu/graphite/GraphicsPipeline.h"
17 #include "src/gpu/graphite/dawn/DawnAsyncWait.h"
18 #include "src/gpu/graphite/dawn/DawnSampler.h"
19
20 #include "webgpu/webgpu_cpp.h" // NO_G3_REWRITE
21
22 class SkUniform;
23
24 namespace SkSL {
25 class Compiler;
26 }
27 namespace skgpu {
28 struct BlendInfo;
29 }
30
31 namespace skgpu::graphite {
32
33 class Attribute;
34 class Context;
35 class GraphicsPipelineDesc;
36 class DawnResourceProvider;
37 class DawnSharedContext;
38 struct DepthStencilSettings;
39 struct RenderPassDesc;
40 class RuntimeEffectDictionary;
41
42 class DawnGraphicsPipeline final : public GraphicsPipeline {
43 public:
44 inline static constexpr unsigned int kUniformBufferBindGroupIndex = 0;
45 inline static constexpr unsigned int kTextureBindGroupIndex = 1;
46 inline static constexpr unsigned int kBindGroupCount = 2;
47
•48 // TODO(b/512814646): WASM does not support push constant usage, meaning that we often have 2
49 // uniform buffers within one BindGroup. This is unideal since we can store single-uniform
50 // BindGroups on DawnBuffers. Consider reorganizing uniform buffers such that we can more often
51 // only have one uniform buffer per BindGroup.
52 inline static constexpr unsigned int kIntrinsicUniformBufferIndex = 0;
53 inline static constexpr unsigned int kCombinedUniformIndex = 1;
54 inline static constexpr unsigned int kGradientBufferIndex = 2;
•55 inline static constexpr unsigned int kMaxNumUniformBuffers = 3;
56
57 inline static constexpr unsigned int kIntrinsicUniformSize = 32;
58
59 inline static constexpr unsigned int kStaticDataBufferIndex = 0;
60 inline static constexpr unsigned int kAppendDataBufferIndex = 1;
61 inline static constexpr unsigned int kNumVertexBuffers = 2;
62
63 static sk_sp<DawnGraphicsPipeline> Make(const DawnSharedContext* sharedContext,
64 const RuntimeEffectDictionary* runtimeDict,
65 const UniqueKey& pipelineKey,
66 const GraphicsPipelineDesc& pipelineDesc,
67 const RenderPassDesc& renderPassDesc,
68 SkEnumBitMask<PipelineCreationFlags>,
69 uint32_t compilationID);
70
71 ~DawnGraphicsPipeline() override;
72
73 bool didAsyncCompilationFail() const override;
74
75 uint32_t stencilReferenceValue() const { return fStencilReferenceValue; }
76 PrimitiveType primitiveType() const { return fPrimitiveType; }
77
78 const wgpu::RenderPipeline& dawnRenderPipeline() const;
79
80 using BindGroupLayouts = std::array<wgpu::BindGroupLayout, kBindGroupCount>;
81 const BindGroupLayouts& dawnGroupLayouts() const { return fGroupLayouts; }
82
83 // Returns null if the ith sampler is not an immutable sampler.
84 const DawnSampler* immutableSampler(int32_t index) const {
85 return fImmutableSamplers[index].get();
86 }
87
88 private:
89 struct AsyncPipelineCreation;
90
91 DawnGraphicsPipeline(const skgpu::graphite::SharedContext* sharedContext,
92 const PipelineInfo& pipelineInfo,
93 std::string_view pipelineLabel,
94 std::unique_ptr<AsyncPipelineCreation> pipelineCreationInfo,
95 BindGroupLayouts groupLayouts,
96 PrimitiveType primitiveType,
97 uint32_t refValue,
98 skia_private::TArray<sk_sp<DawnSampler>> immutableSamplers);
99
100 void freeGpuData() override;
101
102 std::unique_ptr<AsyncPipelineCreation> fAsyncPipelineCreation;
103 BindGroupLayouts fGroupLayouts;
104 const PrimitiveType fPrimitiveType;
105 const uint32_t fStencilReferenceValue;
106
107 // Hold a ref to immutable samplers used such that their lifetime is properly managed.
108 const skia_private::TArray<sk_sp<DawnSampler>> fImmutableSamplers;
109 };
110
111 } // namespace skgpu::graphite
112
113 #endif // skgpu_graphite_DawnGraphicsPipeline_DEFINED