• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2019 Google Inc.
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 GrDawnOpsRenderPass_DEFINED
9 #define GrDawnOpsRenderPass_DEFINED
10 
11 #include "src/gpu/GrOpsRenderPass.h"
12 
13 #include "include/gpu/GrTypes.h"
14 #include "src/gpu/GrColor.h"
15 #include "dawn/webgpu_cpp.h"
16 
17 class GrDawnGpu;
18 class GrDawnRenderTarget;
19 struct GrDawnProgram;
20 
21 class GrDawnOpsRenderPass : public GrOpsRenderPass {
22 public:
23     GrDawnOpsRenderPass(GrDawnGpu*, GrRenderTarget*, GrSurfaceOrigin,
24                         const LoadAndStoreInfo&, const StencilLoadAndStoreInfo&);
25 
26     ~GrDawnOpsRenderPass() override;
27 
28     wgpu::RenderPassEncoder beginRenderPass(wgpu::LoadOp colorOp, wgpu::LoadOp stencilOp);
29 
30     void inlineUpload(GrOpFlushState* state, GrDeferredTextureUploadFn& upload) override;
31 
32     void submit();
33 
34 private:
35     GrGpu* gpu() override;
36 
37     void applyState(GrDawnProgram*, const GrProgramInfo& programInfo);
38 
39     void onEnd() override;
40     bool onBindPipeline(const GrProgramInfo& programInfo, const SkRect& drawBounds) override;
41     void onSetScissorRect(const SkIRect&) override;
42     bool onBindTextures(const GrGeometryProcessor&,
43                         const GrSurfaceProxy* const geomProcTextures[],
44                         const GrPipeline&) override;
45     void onBindBuffers(sk_sp<const GrBuffer> indexBuffer, sk_sp<const GrBuffer> instanceBuffer,
46                        sk_sp<const GrBuffer> vertexBuffer, GrPrimitiveRestart) override;
47     void onDraw(int vertexCount, int baseVertex) override;
48     void onDrawIndexed(int indexCount, int baseIndex, uint16_t minIndexValue,
49                        uint16_t maxIndexValue, int baseVertex) override;
50     void onDrawInstanced(int instanceCount, int baseInstance, int vertexCount,
51                          int baseVertex) override;
52     void onDrawIndexedInstanced(int indexCount, int baseIndex, int instanceCount, int baseInstance,
53                                 int baseVertex) override;
54 
55     void onClear(const GrScissorState& scissor, std::array<float, 4> color) override;
56 
57     void onClearStencilClip(const GrScissorState& scissor, bool insideStencilMask) override;
58 
59     struct InlineUploadInfo {
InlineUploadInfoInlineUploadInfo60         InlineUploadInfo(GrOpFlushState* state, const GrDeferredTextureUploadFn& upload)
61                 : fFlushState(state), fUpload(upload) {}
62 
63         GrOpFlushState* fFlushState;
64         GrDeferredTextureUploadFn fUpload;
65     };
66 
67     GrDawnGpu*                  fGpu;
68     wgpu::CommandEncoder        fEncoder;
69     wgpu::RenderPassEncoder     fPassEncoder;
70     sk_sp<GrDawnProgram>        fCurrentProgram;
71     LoadAndStoreInfo            fColorInfo;
72 
73     using INHERITED = GrOpsRenderPass    ;
74 };
75 
76 #endif
77