• 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_D3D12_RENDERPASSBUILDERD3D12_H_
16 #define DAWNNATIVE_D3D12_RENDERPASSBUILDERD3D12_H_
17 
18 #include "common/Constants.h"
19 #include "common/ityp_array.h"
20 #include "common/ityp_span.h"
21 #include "dawn_native/IntegerTypes.h"
22 #include "dawn_native/d3d12/d3d12_platform.h"
23 #include "dawn_native/dawn_platform.h"
24 
25 #include <array>
26 
27 namespace dawn_native { namespace d3d12 {
28 
29     class TextureView;
30 
31     // RenderPassBuilder stores parameters related to render pass load and store operations.
32     // When the D3D12 render pass API is available, the needed descriptors can be fetched
33     // directly from the RenderPassBuilder. When the D3D12 render pass API is not available, the
34     // descriptors are still fetched and any information necessary to emulate the load and store
35     // operations is extracted from the descriptors.
36     class RenderPassBuilder {
37       public:
38         RenderPassBuilder(bool hasUAV);
39 
40         ColorAttachmentIndex GetColorAttachmentCount() const;
41 
42         // Returns descriptors that are fed directly to BeginRenderPass, or are used as parameter
43         // storage if D3D12 render pass API is unavailable.
44         ityp::span<ColorAttachmentIndex, const D3D12_RENDER_PASS_RENDER_TARGET_DESC>
45         GetRenderPassRenderTargetDescriptors() const;
46         const D3D12_RENDER_PASS_DEPTH_STENCIL_DESC* GetRenderPassDepthStencilDescriptor() const;
47 
48         D3D12_RENDER_PASS_FLAGS GetRenderPassFlags() const;
49 
50         // Returns attachment RTVs to use with OMSetRenderTargets.
51         const D3D12_CPU_DESCRIPTOR_HANDLE* GetRenderTargetViews() const;
52 
53         bool HasDepth() const;
54 
55         // Functions that set the appropriate values in the render pass descriptors.
56         void SetDepthAccess(wgpu::LoadOp loadOp,
57                             wgpu::StoreOp storeOp,
58                             float clearDepth,
59                             DXGI_FORMAT format);
60         void SetDepthNoAccess();
61         void SetDepthStencilNoAccess();
62         void SetRenderTargetBeginningAccess(ColorAttachmentIndex attachment,
63                                             wgpu::LoadOp loadOp,
64                                             dawn_native::Color clearColor,
65                                             DXGI_FORMAT format);
66         void SetRenderTargetEndingAccess(ColorAttachmentIndex attachment, wgpu::StoreOp storeOp);
67         void SetRenderTargetEndingAccessResolve(ColorAttachmentIndex attachment,
68                                                 wgpu::StoreOp storeOp,
69                                                 TextureView* resolveSource,
70                                                 TextureView* resolveDestination);
71         void SetStencilAccess(wgpu::LoadOp loadOp,
72                               wgpu::StoreOp storeOp,
73                               uint8_t clearStencil,
74                               DXGI_FORMAT format);
75         void SetStencilNoAccess();
76 
77         void SetRenderTargetView(ColorAttachmentIndex attachmentIndex,
78                                  D3D12_CPU_DESCRIPTOR_HANDLE baseDescriptor);
79         void SetDepthStencilView(D3D12_CPU_DESCRIPTOR_HANDLE baseDescriptor);
80 
81       private:
82         ColorAttachmentIndex mColorAttachmentCount{uint8_t(0)};
83         bool mHasDepth = false;
84         D3D12_RENDER_PASS_FLAGS mRenderPassFlags = D3D12_RENDER_PASS_FLAG_NONE;
85         D3D12_RENDER_PASS_DEPTH_STENCIL_DESC mRenderPassDepthStencilDesc;
86         ityp::
87             array<ColorAttachmentIndex, D3D12_RENDER_PASS_RENDER_TARGET_DESC, kMaxColorAttachments>
88                 mRenderPassRenderTargetDescriptors;
89         ityp::array<ColorAttachmentIndex, D3D12_CPU_DESCRIPTOR_HANDLE, kMaxColorAttachments>
90             mRenderTargetViews;
91         ityp::array<ColorAttachmentIndex,
92                     D3D12_RENDER_PASS_ENDING_ACCESS_RESOLVE_SUBRESOURCE_PARAMETERS,
93                     kMaxColorAttachments>
94             mSubresourceParams;
95     };
96 }}  // namespace dawn_native::d3d12
97 
98 #endif  // DAWNNATIVE_D3D12_RENDERPASSBUILDERD3D12_H_
99