• 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_RENDERPASSENCODER_H_
16 #define DAWNNATIVE_RENDERPASSENCODER_H_
17 
18 #include "dawn_native/Error.h"
19 #include "dawn_native/Forward.h"
20 #include "dawn_native/RenderEncoderBase.h"
21 
22 namespace dawn_native {
23 
24     class RenderBundleBase;
25 
26     class RenderPassEncoder final : public RenderEncoderBase {
27       public:
28         RenderPassEncoder(DeviceBase* device,
29                           const RenderPassDescriptor* descriptor,
30                           CommandEncoder* commandEncoder,
31                           EncodingContext* encodingContext,
32                           RenderPassResourceUsageTracker usageTracker,
33                           Ref<AttachmentState> attachmentState,
34                           QuerySetBase* occlusionQuerySet,
35                           uint32_t renderTargetWidth,
36                           uint32_t renderTargetHeight,
37                           bool depthReadOnly,
38                           bool stencilReadOnly);
39 
40         static RenderPassEncoder* MakeError(DeviceBase* device,
41                                             CommandEncoder* commandEncoder,
42                                             EncodingContext* encodingContext);
43 
44         ObjectType GetType() const override;
45 
46         void APIEndPass();
47 
48         void APISetStencilReference(uint32_t reference);
49         void APISetBlendConstant(const Color* color);
50         void APISetViewport(float x,
51                             float y,
52                             float width,
53                             float height,
54                             float minDepth,
55                             float maxDepth);
56         void APISetScissorRect(uint32_t x, uint32_t y, uint32_t width, uint32_t height);
57         void APIExecuteBundles(uint32_t count, RenderBundleBase* const* renderBundles);
58 
59         void APIBeginOcclusionQuery(uint32_t queryIndex);
60         void APIEndOcclusionQuery();
61 
62         void APIWriteTimestamp(QuerySetBase* querySet, uint32_t queryIndex);
63 
64       protected:
65         RenderPassEncoder(DeviceBase* device,
66                           CommandEncoder* commandEncoder,
67                           EncodingContext* encodingContext,
68                           ErrorTag errorTag);
69 
70       private:
71         void DestroyImpl() override;
72 
73         void TrackQueryAvailability(QuerySetBase* querySet, uint32_t queryIndex);
74 
75         // For render and compute passes, the encoding context is borrowed from the command encoder.
76         // Keep a reference to the encoder to make sure the context isn't freed.
77         Ref<CommandEncoder> mCommandEncoder;
78 
79         uint32_t mRenderTargetWidth;
80         uint32_t mRenderTargetHeight;
81 
82         // The resources for occlusion query
83         Ref<QuerySetBase> mOcclusionQuerySet;
84         uint32_t mCurrentOcclusionQueryIndex = 0;
85         bool mOcclusionQueryActive = false;
86     };
87 
88 }  // namespace dawn_native
89 
90 #endif  // DAWNNATIVE_RENDERPASSENCODER_H_
91