• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018 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_COMPUTEPASSENCODER_H_
16 #define DAWNNATIVE_COMPUTEPASSENCODER_H_
17 
18 #include "dawn_native/CommandBufferStateTracker.h"
19 #include "dawn_native/Error.h"
20 #include "dawn_native/Forward.h"
21 #include "dawn_native/PassResourceUsageTracker.h"
22 #include "dawn_native/ProgrammableEncoder.h"
23 
24 namespace dawn_native {
25 
26     class SyncScopeUsageTracker;
27 
28     class ComputePassEncoder final : public ProgrammableEncoder {
29       public:
30         ComputePassEncoder(DeviceBase* device,
31                            const ComputePassDescriptor* descriptor,
32                            CommandEncoder* commandEncoder,
33                            EncodingContext* encodingContext);
34 
35         static ComputePassEncoder* MakeError(DeviceBase* device,
36                                              CommandEncoder* commandEncoder,
37                                              EncodingContext* encodingContext);
38 
39         ObjectType GetType() const override;
40 
41         void APIEndPass();
42 
43         void APIDispatch(uint32_t x, uint32_t y = 1, uint32_t z = 1);
44         void APIDispatchIndirect(BufferBase* indirectBuffer, uint64_t indirectOffset);
45         void APISetPipeline(ComputePipelineBase* pipeline);
46 
47         void APISetBindGroup(uint32_t groupIndex,
48                              BindGroupBase* group,
49                              uint32_t dynamicOffsetCount = 0,
50                              const uint32_t* dynamicOffsets = nullptr);
51 
52         void APIWriteTimestamp(QuerySetBase* querySet, uint32_t queryIndex);
53 
54         CommandBufferStateTracker* GetCommandBufferStateTrackerForTesting();
RestoreCommandBufferStateForTesting(CommandBufferStateTracker state)55         void RestoreCommandBufferStateForTesting(CommandBufferStateTracker state) {
56             RestoreCommandBufferState(std::move(state));
57         }
58 
59       protected:
60         ComputePassEncoder(DeviceBase* device,
61                            CommandEncoder* commandEncoder,
62                            EncodingContext* encodingContext,
63                            ErrorTag errorTag);
64 
65       private:
66         void DestroyImpl() override;
67 
68         ResultOrError<std::pair<Ref<BufferBase>, uint64_t>> TransformIndirectDispatchBuffer(
69             Ref<BufferBase> indirectBuffer,
70             uint64_t indirectOffset);
71 
72         void RestoreCommandBufferState(CommandBufferStateTracker state);
73 
74         CommandBufferStateTracker mCommandBufferState;
75 
76         // Adds the bindgroups used for the current dispatch to the SyncScopeResourceUsage and
77         // records it in mUsageTracker.
78         void AddDispatchSyncScope(SyncScopeUsageTracker scope = {});
79         ComputePassResourceUsageTracker mUsageTracker;
80 
81         // For render and compute passes, the encoding context is borrowed from the command encoder.
82         // Keep a reference to the encoder to make sure the context isn't freed.
83         Ref<CommandEncoder> mCommandEncoder;
84     };
85 
86 }  // namespace dawn_native
87 
88 #endif  // DAWNNATIVE_COMPUTEPASSENCODER_H_
89