• 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_ATTACHMENTSTATE_H_
16 #define DAWNNATIVE_ATTACHMENTSTATE_H_
17 
18 #include "common/Constants.h"
19 #include "common/ityp_array.h"
20 #include "common/ityp_bitset.h"
21 #include "dawn_native/CachedObject.h"
22 #include "dawn_native/IntegerTypes.h"
23 #include "dawn_native/ObjectBase.h"
24 
25 #include "dawn_native/dawn_platform.h"
26 
27 #include <array>
28 #include <bitset>
29 
30 namespace dawn_native {
31 
32     class DeviceBase;
33 
34     // AttachmentStateBlueprint and AttachmentState are separated so the AttachmentState
35     // can be constructed by copying the blueprint state instead of traversing descriptors.
36     // Also, AttachmentStateBlueprint does not need a refcount like AttachmentState.
37     class AttachmentStateBlueprint {
38       public:
39         // Note: Descriptors must be validated before the AttachmentState is constructed.
40         explicit AttachmentStateBlueprint(const RenderBundleEncoderDescriptor* descriptor);
41         explicit AttachmentStateBlueprint(const RenderPipelineDescriptor* descriptor);
42         explicit AttachmentStateBlueprint(const RenderPassDescriptor* descriptor);
43 
44         AttachmentStateBlueprint(const AttachmentStateBlueprint& rhs);
45 
46         // Functors necessary for the unordered_set<AttachmentState*>-based cache.
47         struct HashFunc {
48             size_t operator()(const AttachmentStateBlueprint* attachmentState) const;
49         };
50         struct EqualityFunc {
51             bool operator()(const AttachmentStateBlueprint* a,
52                             const AttachmentStateBlueprint* b) const;
53         };
54 
55       protected:
56         ityp::bitset<ColorAttachmentIndex, kMaxColorAttachments> mColorAttachmentsSet;
57         ityp::array<ColorAttachmentIndex, wgpu::TextureFormat, kMaxColorAttachments> mColorFormats;
58         // Default (texture format Undefined) indicates there is no depth stencil attachment.
59         wgpu::TextureFormat mDepthStencilFormat = wgpu::TextureFormat::Undefined;
60         uint32_t mSampleCount = 0;
61     };
62 
63     class AttachmentState final : public AttachmentStateBlueprint,
64                                   public ObjectBase,
65                                   public CachedObject {
66       public:
67         AttachmentState(DeviceBase* device, const AttachmentStateBlueprint& blueprint);
68 
69         ityp::bitset<ColorAttachmentIndex, kMaxColorAttachments> GetColorAttachmentsMask() const;
70         wgpu::TextureFormat GetColorAttachmentFormat(ColorAttachmentIndex index) const;
71         bool HasDepthStencilAttachment() const;
72         wgpu::TextureFormat GetDepthStencilFormat() const;
73         uint32_t GetSampleCount() const;
74 
75         size_t ComputeContentHash() override;
76 
77       private:
78         ~AttachmentState() override;
79     };
80 
81 }  // namespace dawn_native
82 
83 #endif  // DAWNNATIVE_ATTACHMENTSTATE_H_
84