1pub use super::super::Nested;
5pub use std::{borrow::Cow, num::NonZeroU32, ops::Range};
6pub trait Field {}
7pub trait IsOptional {}
8#[doc = "\nBuilder for [`wgpu::ImageSubresourceRange`]\n \nSet all required fields and any optional fields, then call `build()`.\n\nBuilder field setters:\n - [aspect](ImageSubresourceRangeBuilder::aspect) Optional, defaults to [wgpu::TextureAspect::All]\n - [base_mip_level](ImageSubresourceRangeBuilder::base_mip_level) Optional, defaults to `0u32`\n - [mip_level_count](ImageSubresourceRangeBuilder::mip_level_count) Optional, defaults to `None`\n - [base_array_layer](ImageSubresourceRangeBuilder::base_array_layer) Optional, defaults to `0u32`\n - [array_layer_count](ImageSubresourceRangeBuilder::array_layer_count) Optional, defaults to `None`\n"]
9pub struct ImageSubresourceRangeBuilder<CS: State> {
10 aspect: CS::Aspect,
11 base_mip_level: CS::BaseMipLevel,
12 mip_level_count: CS::MipLevelCount,
13 base_array_layer: CS::BaseArrayLayer,
14 array_layer_count: CS::ArrayLayerCount,
15}
16impl ImageSubresourceRangeBuilder<Empty> {
17 pub fn new() -> ImageSubresourceRangeBuilder<Empty> {
18 ImageSubresourceRangeBuilder {
19 aspect: AspectEmpty,
20 base_mip_level: BaseMipLevelEmpty,
21 mip_level_count: MipLevelCountEmpty,
22 base_array_layer: BaseArrayLayerEmpty,
23 array_layer_count: ArrayLayerCountEmpty,
24 }
25 }
26}
27#[doc = "\nReturns [ImageSubresourceRangeBuilder] for building [`wgpu::ImageSubresourceRange`]\n \nSet all required fields and any optional fields, then call `build()`.\n\nBuilder field setters:\n - [aspect](ImageSubresourceRangeBuilder::aspect) Optional, defaults to [wgpu::TextureAspect::All]\n - [base_mip_level](ImageSubresourceRangeBuilder::base_mip_level) Optional, defaults to `0u32`\n - [mip_level_count](ImageSubresourceRangeBuilder::mip_level_count) Optional, defaults to `None`\n - [base_array_layer](ImageSubresourceRangeBuilder::base_array_layer) Optional, defaults to `0u32`\n - [array_layer_count](ImageSubresourceRangeBuilder::array_layer_count) Optional, defaults to `None`\n"]
28pub fn image_subresource_range() -> ImageSubresourceRangeBuilder<Empty> {
29 ImageSubresourceRangeBuilder::new()
30}
31pub struct AspectEmpty;
32impl Field for AspectEmpty {}
33pub trait AspectIsEmpty {}
34impl AspectIsEmpty for AspectEmpty {}
35pub trait IsSetAspect {
36 fn get(self) -> wgpu::TextureAspect;
37}
38impl IsSetAspect for AspectEmpty {
39 fn get(self) -> wgpu::TextureAspect {
40 wgpu::TextureAspect::All
41 }
42}
43pub struct AspectValue(pub wgpu::TextureAspect);
44impl Field for AspectValue {}
45impl IsSetAspect for AspectValue {
46 fn get(self) -> wgpu::TextureAspect {
47 self.0
48 }
49}
50pub struct BaseMipLevelEmpty;
51impl Field for BaseMipLevelEmpty {}
52pub trait BaseMipLevelIsEmpty {}
53impl BaseMipLevelIsEmpty for BaseMipLevelEmpty {}
54pub trait IsSetBaseMipLevel {
55 fn get(self) -> u32;
56}
57impl IsSetBaseMipLevel for BaseMipLevelEmpty {
58 fn get(self) -> u32 {
59 0u32
60 }
61}
62pub struct BaseMipLevelValue(pub u32);
63impl Field for BaseMipLevelValue {}
64impl IsSetBaseMipLevel for BaseMipLevelValue {
65 fn get(self) -> u32 {
66 self.0
67 }
68}
69pub struct MipLevelCountEmpty;
70impl Field for MipLevelCountEmpty {}
71pub trait MipLevelCountIsEmpty {}
72impl MipLevelCountIsEmpty for MipLevelCountEmpty {}
73pub trait IsSetMipLevelCount {
74 fn get(self) -> Option<u32>;
75}
76impl IsSetMipLevelCount for MipLevelCountEmpty {
77 fn get(self) -> Option<u32> {
78 None
79 }
80}
81pub struct MipLevelCountValue(pub Option<u32>);
82impl Field for MipLevelCountValue {}
83impl IsSetMipLevelCount for MipLevelCountValue {
84 fn get(self) -> Option<u32> {
85 self.0
86 }
87}
88pub struct BaseArrayLayerEmpty;
89impl Field for BaseArrayLayerEmpty {}
90pub trait BaseArrayLayerIsEmpty {}
91impl BaseArrayLayerIsEmpty for BaseArrayLayerEmpty {}
92pub trait IsSetBaseArrayLayer {
93 fn get(self) -> u32;
94}
95impl IsSetBaseArrayLayer for BaseArrayLayerEmpty {
96 fn get(self) -> u32 {
97 0u32
98 }
99}
100pub struct BaseArrayLayerValue(pub u32);
101impl Field for BaseArrayLayerValue {}
102impl IsSetBaseArrayLayer for BaseArrayLayerValue {
103 fn get(self) -> u32 {
104 self.0
105 }
106}
107pub struct ArrayLayerCountEmpty;
108impl Field for ArrayLayerCountEmpty {}
109pub trait ArrayLayerCountIsEmpty {}
110impl ArrayLayerCountIsEmpty for ArrayLayerCountEmpty {}
111pub trait IsSetArrayLayerCount {
112 fn get(self) -> Option<u32>;
113}
114impl IsSetArrayLayerCount for ArrayLayerCountEmpty {
115 fn get(self) -> Option<u32> {
116 None
117 }
118}
119pub struct ArrayLayerCountValue(pub Option<u32>);
120impl Field for ArrayLayerCountValue {}
121impl IsSetArrayLayerCount for ArrayLayerCountValue {
122 fn get(self) -> Option<u32> {
123 self.0
124 }
125}
126pub trait State {
127 type Aspect: Field;
128 type BaseMipLevel: Field;
129 type MipLevelCount: Field;
130 type BaseArrayLayer: Field;
131 type ArrayLayerCount: Field;
132}
133pub struct Empty;
134impl State for Empty {
135 type Aspect = AspectEmpty;
136 type BaseMipLevel = BaseMipLevelEmpty;
137 type MipLevelCount = MipLevelCountEmpty;
138 type BaseArrayLayer = BaseArrayLayerEmpty;
139 type ArrayLayerCount = ArrayLayerCountEmpty;
140}
141pub struct SetAspect<CS>(CS);
142impl<CS: State> State for SetAspect<CS> {
143 type Aspect = AspectValue;
144 type BaseMipLevel = CS::BaseMipLevel;
145 type MipLevelCount = CS::MipLevelCount;
146 type BaseArrayLayer = CS::BaseArrayLayer;
147 type ArrayLayerCount = CS::ArrayLayerCount;
148}
149pub struct SetBaseMipLevel<CS>(CS);
150impl<CS: State> State for SetBaseMipLevel<CS> {
151 type Aspect = CS::Aspect;
152 type BaseMipLevel = BaseMipLevelValue;
153 type MipLevelCount = CS::MipLevelCount;
154 type BaseArrayLayer = CS::BaseArrayLayer;
155 type ArrayLayerCount = CS::ArrayLayerCount;
156}
157pub struct SetMipLevelCount<CS>(CS);
158impl<CS: State> State for SetMipLevelCount<CS> {
159 type Aspect = CS::Aspect;
160 type BaseMipLevel = CS::BaseMipLevel;
161 type MipLevelCount = MipLevelCountValue;
162 type BaseArrayLayer = CS::BaseArrayLayer;
163 type ArrayLayerCount = CS::ArrayLayerCount;
164}
165pub struct SetBaseArrayLayer<CS>(CS);
166impl<CS: State> State for SetBaseArrayLayer<CS> {
167 type Aspect = CS::Aspect;
168 type BaseMipLevel = CS::BaseMipLevel;
169 type MipLevelCount = CS::MipLevelCount;
170 type BaseArrayLayer = BaseArrayLayerValue;
171 type ArrayLayerCount = CS::ArrayLayerCount;
172}
173pub struct SetArrayLayerCount<CS>(CS);
174impl<CS: State> State for SetArrayLayerCount<CS> {
175 type Aspect = CS::Aspect;
176 type BaseMipLevel = CS::BaseMipLevel;
177 type MipLevelCount = CS::MipLevelCount;
178 type BaseArrayLayer = CS::BaseArrayLayer;
179 type ArrayLayerCount = ArrayLayerCountValue;
180}
181impl<CS: State> ImageSubresourceRangeBuilder<CS> {
182 #[doc = "Setter for [wgpu::ImageSubresourceRange::aspect]. Optional, defaults to [wgpu::TextureAspect::All].\n"]
183 pub fn aspect(self, aspect: wgpu::TextureAspect) -> ImageSubresourceRangeBuilder<SetAspect<CS>>
184 where
185 CS::Aspect: AspectIsEmpty,
186 {
187 ImageSubresourceRangeBuilder {
188 aspect: AspectValue(aspect),
189 base_mip_level: self.base_mip_level,
190 mip_level_count: self.mip_level_count,
191 base_array_layer: self.base_array_layer,
192 array_layer_count: self.array_layer_count,
193 }
194 }
195 #[doc = "Setter for [wgpu::ImageSubresourceRange::base_mip_level]. Optional, defaults to `0u32`.\n"]
196 pub fn base_mip_level(
197 self,
198 base_mip_level: u32,
199 ) -> ImageSubresourceRangeBuilder<SetBaseMipLevel<CS>>
200 where
201 CS::BaseMipLevel: BaseMipLevelIsEmpty,
202 {
203 ImageSubresourceRangeBuilder {
204 aspect: self.aspect,
205 base_mip_level: BaseMipLevelValue(base_mip_level),
206 mip_level_count: self.mip_level_count,
207 base_array_layer: self.base_array_layer,
208 array_layer_count: self.array_layer_count,
209 }
210 }
211 #[doc = "Setter for [wgpu::ImageSubresourceRange::mip_level_count]. Optional, defaults to `None`.\n"]
212 pub fn mip_level_count(
213 self,
214 mip_level_count: u32,
215 ) -> ImageSubresourceRangeBuilder<SetMipLevelCount<CS>>
216 where
217 CS::MipLevelCount: MipLevelCountIsEmpty,
218 {
219 ImageSubresourceRangeBuilder {
220 aspect: self.aspect,
221 base_mip_level: self.base_mip_level,
222 mip_level_count: MipLevelCountValue(Some(mip_level_count)),
223 base_array_layer: self.base_array_layer,
224 array_layer_count: self.array_layer_count,
225 }
226 }
227 #[doc = "Setter for [wgpu::ImageSubresourceRange::mip_level_count]. Optional, defaults to `None`.\n"]
228 pub fn maybe_mip_level_count(
229 self,
230 mip_level_count: Option<u32>,
231 ) -> ImageSubresourceRangeBuilder<SetMipLevelCount<CS>>
232 where
233 CS::MipLevelCount: MipLevelCountIsEmpty,
234 {
235 ImageSubresourceRangeBuilder {
236 aspect: self.aspect,
237 base_mip_level: self.base_mip_level,
238 mip_level_count: MipLevelCountValue(mip_level_count),
239 base_array_layer: self.base_array_layer,
240 array_layer_count: self.array_layer_count,
241 }
242 }
243 #[doc = "Setter for [wgpu::ImageSubresourceRange::base_array_layer]. Optional, defaults to `0u32`.\n"]
244 pub fn base_array_layer(
245 self,
246 base_array_layer: u32,
247 ) -> ImageSubresourceRangeBuilder<SetBaseArrayLayer<CS>>
248 where
249 CS::BaseArrayLayer: BaseArrayLayerIsEmpty,
250 {
251 ImageSubresourceRangeBuilder {
252 aspect: self.aspect,
253 base_mip_level: self.base_mip_level,
254 mip_level_count: self.mip_level_count,
255 base_array_layer: BaseArrayLayerValue(base_array_layer),
256 array_layer_count: self.array_layer_count,
257 }
258 }
259 #[doc = "Setter for [wgpu::ImageSubresourceRange::array_layer_count]. Optional, defaults to `None`.\n"]
260 pub fn array_layer_count(
261 self,
262 array_layer_count: u32,
263 ) -> ImageSubresourceRangeBuilder<SetArrayLayerCount<CS>>
264 where
265 CS::ArrayLayerCount: ArrayLayerCountIsEmpty,
266 {
267 ImageSubresourceRangeBuilder {
268 aspect: self.aspect,
269 base_mip_level: self.base_mip_level,
270 mip_level_count: self.mip_level_count,
271 base_array_layer: self.base_array_layer,
272 array_layer_count: ArrayLayerCountValue(Some(array_layer_count)),
273 }
274 }
275 #[doc = "Setter for [wgpu::ImageSubresourceRange::array_layer_count]. Optional, defaults to `None`.\n"]
276 pub fn maybe_array_layer_count(
277 self,
278 array_layer_count: Option<u32>,
279 ) -> ImageSubresourceRangeBuilder<SetArrayLayerCount<CS>>
280 where
281 CS::ArrayLayerCount: ArrayLayerCountIsEmpty,
282 {
283 ImageSubresourceRangeBuilder {
284 aspect: self.aspect,
285 base_mip_level: self.base_mip_level,
286 mip_level_count: self.mip_level_count,
287 base_array_layer: self.base_array_layer,
288 array_layer_count: ArrayLayerCountValue(array_layer_count),
289 }
290 }
291}
292pub trait Complete:
293 State<
294 Aspect: IsSetAspect,
295 BaseMipLevel: IsSetBaseMipLevel,
296 MipLevelCount: IsSetMipLevelCount,
297 BaseArrayLayer: IsSetBaseArrayLayer,
298 ArrayLayerCount: IsSetArrayLayerCount,
299>
300{
301}
302impl<
303 CS: State<
304 Aspect: IsSetAspect,
305 BaseMipLevel: IsSetBaseMipLevel,
306 MipLevelCount: IsSetMipLevelCount,
307 BaseArrayLayer: IsSetBaseArrayLayer,
308 ArrayLayerCount: IsSetArrayLayerCount,
309 >,
310 > Complete for CS
311{
312}
313impl<CS: Complete> ImageSubresourceRangeBuilder<CS> {
314 pub fn build(self) -> wgpu::ImageSubresourceRange {
315 wgpu::ImageSubresourceRange {
316 aspect: IsSetAspect::get(self.aspect),
317 base_mip_level: IsSetBaseMipLevel::get(self.base_mip_level),
318 mip_level_count: IsSetMipLevelCount::get(self.mip_level_count),
319 base_array_layer: IsSetBaseArrayLayer::get(self.base_array_layer),
320 array_layer_count: IsSetArrayLayerCount::get(self.array_layer_count),
321 }
322 }
323}
324impl Nested<wgpu::ImageSubresourceRange> for wgpu::ImageSubresourceRange {
325 fn unnest(self) -> wgpu::ImageSubresourceRange {
326 self
327 }
328}
329impl<CS: Complete> Nested<wgpu::ImageSubresourceRange> for ImageSubresourceRangeBuilder<CS> {
330 fn unnest(self) -> wgpu::ImageSubresourceRange {
331 self.build()
332 }
333}
334#[cfg(test)]
335mod tests {
336 #[allow(unused_imports)]
337 #[allow(unused_imports)]
338 use std::num::NonZeroU32;
339 #[test]
340 pub fn test_default() {
341 assert_eq!(
342 format!("{:#?}", super::image_subresource_range().build()),
343 format!("{:#?}", wgpu::ImageSubresourceRange::default()),
344 );
345 }
346}