• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 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_SUBRESOURCE_H_
16 #define DAWNNATIVE_SUBRESOURCE_H_
17 
18 #include "dawn_native/EnumClassBitmasks.h"
19 #include "dawn_native/dawn_platform.h"
20 
21 namespace dawn_native {
22 
23     // Note: Subresource indices are computed by iterating the aspects in increasing order.
24     // D3D12 uses these directly, so the order much match D3D12's indices.
25     //  - Depth/Stencil textures have Depth as Plane 0, and Stencil as Plane 1.
26     enum class Aspect : uint8_t {
27         None = 0x0,
28         Color = 0x1,
29         Depth = 0x2,
30         Stencil = 0x4,
31 
32         // Aspects used to select individual planes in a multi-planar format.
33         Plane0 = 0x8,
34         Plane1 = 0x10,
35 
36         // An aspect for that represents the combination of both the depth and stencil aspects. It
37         // can be ignored outside of the Vulkan backend.
38         CombinedDepthStencil = 0x20,
39     };
40 
41     template <>
42     struct EnumBitmaskSize<Aspect> {
43         static constexpr unsigned value = 6;
44     };
45 
46     // Convert the TextureAspect to an Aspect mask for the format. ASSERTs if the aspect
47     // does not exist in the format.
48     // Also ASSERTs if "All" is selected and results in more than one aspect.
49     Aspect ConvertSingleAspect(const Format& format, wgpu::TextureAspect aspect);
50 
51     // Convert the TextureAspect to an Aspect mask for the format. ASSERTs if the aspect
52     // does not exist in the format.
53     Aspect ConvertAspect(const Format& format, wgpu::TextureAspect aspect);
54 
55     // Returns the Aspects of the Format that are selected by the wgpu::TextureAspect.
56     // Note that this can return Aspect::None if the Format doesn't have any of the
57     // selected aspects.
58     Aspect SelectFormatAspects(const Format& format, wgpu::TextureAspect aspect);
59 
60     // Convert TextureAspect to the aspect which corresponds to the view format. This
61     // special cases per plane view formats before calling ConvertAspect.
62     Aspect ConvertViewAspect(const Format& format, wgpu::TextureAspect aspect);
63 
64     // Helper struct to make it clear that what the parameters of a range mean.
65     template <typename T>
66     struct FirstAndCountRange {
67         T first;
68         T count;
69     };
70 
71     struct SubresourceRange {
72         SubresourceRange(Aspect aspects,
73                          FirstAndCountRange<uint32_t> arrayLayerParam,
74                          FirstAndCountRange<uint32_t> mipLevelParams);
75         SubresourceRange();
76 
77         Aspect aspects;
78         uint32_t baseArrayLayer;
79         uint32_t layerCount;
80         uint32_t baseMipLevel;
81         uint32_t levelCount;
82 
83         static SubresourceRange SingleMipAndLayer(uint32_t baseMipLevel,
84                                                   uint32_t baseArrayLayer,
85                                                   Aspect aspects);
86         static SubresourceRange MakeSingle(Aspect aspect,
87                                            uint32_t baseArrayLayer,
88                                            uint32_t baseMipLevel);
89 
90         static SubresourceRange MakeFull(Aspect aspects, uint32_t layerCount, uint32_t levelCount);
91     };
92 
93     // Helper function to use aspects as linear indices in arrays.
94     uint8_t GetAspectIndex(Aspect aspect);
95     uint8_t GetAspectCount(Aspect aspects);
96 
97     // The maximum number of planes per format Dawn knows about. Asserts in BuildFormatTable that
98     // the per plane index does not exceed the known maximum plane count.
99     static constexpr uint32_t kMaxPlanesPerFormat = 3;
100 
101 }  // namespace dawn_native
102 
103 namespace dawn {
104 
105     template <>
106     struct IsDawnBitmask<dawn_native::Aspect> {
107         static constexpr bool enable = true;
108     };
109 
110 }  // namespace dawn
111 
112 #endif  // DAWNNATIVE_SUBRESOURCE_H_
113