• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 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_PIPELINELAYOUTD3D12_H_
16 #define DAWNNATIVE_D3D12_PIPELINELAYOUTD3D12_H_
17 
18 #include "common/Constants.h"
19 #include "common/ityp_array.h"
20 #include "dawn_native/BindingInfo.h"
21 #include "dawn_native/PipelineLayout.h"
22 #include "dawn_native/d3d12/d3d12_platform.h"
23 
24 namespace dawn_native { namespace d3d12 {
25 
26     class Device;
27 
28     class PipelineLayout final : public PipelineLayoutBase {
29       public:
30         static ResultOrError<Ref<PipelineLayout>> Create(
31             Device* device,
32             const PipelineLayoutDescriptor* descriptor);
33 
34         uint32_t GetCbvUavSrvRootParameterIndex(BindGroupIndex group) const;
35         uint32_t GetSamplerRootParameterIndex(BindGroupIndex group) const;
36 
37         // Returns the index of the root parameter reserved for a dynamic buffer binding
38         uint32_t GetDynamicRootParameterIndex(BindGroupIndex group,
39                                               BindingIndex bindingIndex) const;
40 
41         uint32_t GetFirstIndexOffsetRegisterSpace() const;
42         uint32_t GetFirstIndexOffsetShaderRegister() const;
43         uint32_t GetFirstIndexOffsetParameterIndex() const;
44 
45         uint32_t GetNumWorkgroupsRegisterSpace() const;
46         uint32_t GetNumWorkgroupsShaderRegister() const;
47         uint32_t GetNumWorkgroupsParameterIndex() const;
48 
49         uint32_t GetDynamicStorageBufferLengthsRegisterSpace() const;
50         uint32_t GetDynamicStorageBufferLengthsShaderRegister() const;
51         uint32_t GetDynamicStorageBufferLengthsParameterIndex() const;
52 
53         ID3D12RootSignature* GetRootSignature() const;
54 
55         ID3D12CommandSignature* GetDispatchIndirectCommandSignatureWithNumWorkgroups();
56 
57         struct PerBindGroupDynamicStorageBufferLengthInfo {
58             // First register offset for a bind group's dynamic storage buffer lengths.
59             // This is the index into the array of root constants where this bind group's
60             // lengths start.
61             uint32_t firstRegisterOffset;
62 
63             struct BindingAndRegisterOffset {
64                 BindingNumber binding;
65                 uint32_t registerOffset;
66             };
67             // Associative list of (BindingNumber,registerOffset) pairs, which is passed into
68             // the shader to map the BindingPoint(thisGroup, BindingNumber) to the registerOffset
69             // into the root constant array which holds the dynamic storage buffer lengths.
70             std::vector<BindingAndRegisterOffset> bindingAndRegisterOffsets;
71         };
72 
73         // Flat map from bind group index to the list of (BindingNumber,Register) pairs.
74         // Each pair is used in shader translation to
75         using DynamicStorageBufferLengthInfo =
76             ityp::array<BindGroupIndex, PerBindGroupDynamicStorageBufferLengthInfo, kMaxBindGroups>;
77 
78         const DynamicStorageBufferLengthInfo& GetDynamicStorageBufferLengthInfo() const;
79 
80       private:
81         ~PipelineLayout() override = default;
82         using PipelineLayoutBase::PipelineLayoutBase;
83         MaybeError Initialize();
84         ityp::array<BindGroupIndex, uint32_t, kMaxBindGroups> mCbvUavSrvRootParameterInfo;
85         ityp::array<BindGroupIndex, uint32_t, kMaxBindGroups> mSamplerRootParameterInfo;
86         ityp::array<BindGroupIndex,
87                     ityp::array<BindingIndex, uint32_t, kMaxDynamicBuffersPerPipelineLayout>,
88                     kMaxBindGroups>
89             mDynamicRootParameterIndices;
90         DynamicStorageBufferLengthInfo mDynamicStorageBufferLengthInfo;
91         uint32_t mFirstIndexOffsetParameterIndex;
92         uint32_t mNumWorkgroupsParameterIndex;
93         uint32_t mDynamicStorageBufferLengthsParameterIndex;
94         ComPtr<ID3D12RootSignature> mRootSignature;
95         ComPtr<ID3D12CommandSignature> mDispatchIndirectCommandSignatureWithNumWorkgroups;
96     };
97 
98 }}  // namespace dawn_native::d3d12
99 
100 #endif  // DAWNNATIVE_D3D12_PIPELINELAYOUTD3D12_H_
101