• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 The Dawn Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef DAWNNATIVE_RENDERENCODERBASE_H_
16 #define DAWNNATIVE_RENDERENCODERBASE_H_
17 
18 #include "dawn_native/AttachmentState.h"
19 #include "dawn_native/CommandBufferStateTracker.h"
20 #include "dawn_native/Error.h"
21 #include "dawn_native/IndirectDrawMetadata.h"
22 #include "dawn_native/PassResourceUsageTracker.h"
23 #include "dawn_native/ProgrammableEncoder.h"
24 
25 namespace dawn_native {
26 
27     class RenderEncoderBase : public ProgrammableEncoder {
28       public:
29         RenderEncoderBase(DeviceBase* device,
30                           const char* label,
31                           EncodingContext* encodingContext,
32                           Ref<AttachmentState> attachmentState,
33                           bool depthReadOnly,
34                           bool stencilReadOnly);
35 
36         void APIDraw(uint32_t vertexCount,
37                      uint32_t instanceCount = 1,
38                      uint32_t firstVertex = 0,
39                      uint32_t firstInstance = 0);
40         void APIDrawIndexed(uint32_t vertexCount,
41                             uint32_t instanceCount,
42                             uint32_t firstIndex,
43                             int32_t baseVertex,
44                             uint32_t firstInstance);
45 
46         void APIDrawIndirect(BufferBase* indirectBuffer, uint64_t indirectOffset);
47         void APIDrawIndexedIndirect(BufferBase* indirectBuffer, uint64_t indirectOffset);
48 
49         void APISetPipeline(RenderPipelineBase* pipeline);
50 
51         void APISetVertexBuffer(uint32_t slot, BufferBase* buffer, uint64_t offset, uint64_t size);
52         void APISetIndexBuffer(BufferBase* buffer,
53                                wgpu::IndexFormat format,
54                                uint64_t offset,
55                                uint64_t size);
56 
57         void APISetBindGroup(uint32_t groupIndex,
58                              BindGroupBase* group,
59                              uint32_t dynamicOffsetCount = 0,
60                              const uint32_t* dynamicOffsets = nullptr);
61 
62         const AttachmentState* GetAttachmentState() const;
63         bool IsDepthReadOnly() const;
64         bool IsStencilReadOnly() const;
65         Ref<AttachmentState> AcquireAttachmentState();
66 
67       protected:
68         // Construct an "error" render encoder base.
69         RenderEncoderBase(DeviceBase* device, EncodingContext* encodingContext, ErrorTag errorTag);
70 
71         void DestroyImpl() override;
72 
73         CommandBufferStateTracker mCommandBufferState;
74         RenderPassResourceUsageTracker mUsageTracker;
75         IndirectDrawMetadata mIndirectDrawMetadata;
76 
77       private:
78         Ref<AttachmentState> mAttachmentState;
79         const bool mDisableBaseVertex;
80         const bool mDisableBaseInstance;
81         bool mDepthReadOnly = false;
82         bool mStencilReadOnly = false;
83     };
84 
85 }  // namespace dawn_native
86 
87 #endif  // DAWNNATIVE_RENDERENCODERBASE_H_
88