• 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_RENDERPIPELINE_H_
16 #define DAWNNATIVE_RENDERPIPELINE_H_
17 
18 #include "common/TypedInteger.h"
19 #include "dawn_native/AttachmentState.h"
20 #include "dawn_native/Forward.h"
21 #include "dawn_native/IntegerTypes.h"
22 #include "dawn_native/Pipeline.h"
23 
24 #include "dawn_native/dawn_platform.h"
25 
26 #include <array>
27 #include <bitset>
28 
29 namespace dawn_native {
30 
31     class DeviceBase;
32 
33     MaybeError ValidateRenderPipelineDescriptor(DeviceBase* device,
34                                                 const RenderPipelineDescriptor* descriptor);
35 
36     std::vector<StageAndDescriptor> GetRenderStagesAndSetDummyShader(
37         DeviceBase* device,
38         const RenderPipelineDescriptor* descriptor);
39 
40     size_t IndexFormatSize(wgpu::IndexFormat format);
41 
42     bool IsStripPrimitiveTopology(wgpu::PrimitiveTopology primitiveTopology);
43 
44     bool StencilTestEnabled(const DepthStencilState* depthStencil);
45 
46     struct VertexAttributeInfo {
47         wgpu::VertexFormat format;
48         uint64_t offset;
49         VertexAttributeLocation shaderLocation;
50         VertexBufferSlot vertexBufferSlot;
51     };
52 
53     struct VertexBufferInfo {
54         uint64_t arrayStride;
55         wgpu::VertexStepMode stepMode;
56         uint16_t usedBytesInStride;
57     };
58 
59     class RenderPipelineBase : public PipelineBase {
60       public:
61         RenderPipelineBase(DeviceBase* device, const RenderPipelineDescriptor* descriptor);
62         ~RenderPipelineBase() override;
63 
64         static RenderPipelineBase* MakeError(DeviceBase* device);
65 
66         ObjectType GetType() const override;
67 
68         const ityp::bitset<VertexAttributeLocation, kMaxVertexAttributes>&
69         GetAttributeLocationsUsed() const;
70         const VertexAttributeInfo& GetAttribute(VertexAttributeLocation location) const;
71         const ityp::bitset<VertexBufferSlot, kMaxVertexBuffers>& GetVertexBufferSlotsUsed() const;
72         const ityp::bitset<VertexBufferSlot, kMaxVertexBuffers>&
73         GetVertexBufferSlotsUsedAsVertexBuffer() const;
74         const ityp::bitset<VertexBufferSlot, kMaxVertexBuffers>&
75         GetVertexBufferSlotsUsedAsInstanceBuffer() const;
76         const VertexBufferInfo& GetVertexBuffer(VertexBufferSlot slot) const;
77         uint32_t GetVertexBufferCount() const;
78 
79         const ColorTargetState* GetColorTargetState(ColorAttachmentIndex attachmentSlot) const;
80         const DepthStencilState* GetDepthStencilState() const;
81         wgpu::PrimitiveTopology GetPrimitiveTopology() const;
82         wgpu::IndexFormat GetStripIndexFormat() const;
83         wgpu::CullMode GetCullMode() const;
84         wgpu::FrontFace GetFrontFace() const;
85         bool IsDepthBiasEnabled() const;
86         int32_t GetDepthBias() const;
87         float GetDepthBiasSlopeScale() const;
88         float GetDepthBiasClamp() const;
89         bool ShouldClampDepth() const;
90 
91         ityp::bitset<ColorAttachmentIndex, kMaxColorAttachments> GetColorAttachmentsMask() const;
92         bool HasDepthStencilAttachment() const;
93         wgpu::TextureFormat GetColorAttachmentFormat(ColorAttachmentIndex attachment) const;
94         wgpu::TextureFormat GetDepthStencilFormat() const;
95         uint32_t GetSampleCount() const;
96         uint32_t GetSampleMask() const;
97         bool IsAlphaToCoverageEnabled() const;
98         bool WritesDepth() const;
99         bool WritesStencil() const;
100 
101         const AttachmentState* GetAttachmentState() const;
102 
103         // Functions necessary for the unordered_set<RenderPipelineBase*>-based cache.
104         size_t ComputeContentHash() override;
105 
106         struct EqualityFunc {
107             bool operator()(const RenderPipelineBase* a, const RenderPipelineBase* b) const;
108         };
109 
110       protected:
111         // Constructor used only for mocking and testing.
112         RenderPipelineBase(DeviceBase* device);
113         void DestroyImpl() override;
114 
115       private:
116         RenderPipelineBase(DeviceBase* device, ObjectBase::ErrorTag tag);
117 
118         // Vertex state
119         uint32_t mVertexBufferCount;
120         ityp::bitset<VertexAttributeLocation, kMaxVertexAttributes> mAttributeLocationsUsed;
121         ityp::array<VertexAttributeLocation, VertexAttributeInfo, kMaxVertexAttributes>
122             mAttributeInfos;
123         ityp::bitset<VertexBufferSlot, kMaxVertexBuffers> mVertexBufferSlotsUsed;
124         ityp::bitset<VertexBufferSlot, kMaxVertexBuffers> mVertexBufferSlotsUsedAsVertexBuffer;
125         ityp::bitset<VertexBufferSlot, kMaxVertexBuffers> mVertexBufferSlotsUsedAsInstanceBuffer;
126         ityp::array<VertexBufferSlot, VertexBufferInfo, kMaxVertexBuffers> mVertexBufferInfos;
127 
128         // Attachments
129         Ref<AttachmentState> mAttachmentState;
130         ityp::array<ColorAttachmentIndex, ColorTargetState, kMaxColorAttachments> mTargets;
131         ityp::array<ColorAttachmentIndex, BlendState, kMaxColorAttachments> mTargetBlend;
132 
133         // Other state
134         PrimitiveState mPrimitive;
135         DepthStencilState mDepthStencil;
136         MultisampleState mMultisample;
137         bool mClampDepth = false;
138         bool mWritesDepth = false;
139         bool mWritesStencil = false;
140     };
141 
142 }  // namespace dawn_native
143 
144 #endif  // DAWNNATIVE_RENDERPIPELINE_H_
145