quickgpu/builders/
dx_12_backend_options_builder.rs1pub use super::super::Nested;
5pub use std::{borrow::Cow, num::NonZeroU32, ops::Range};
6pub trait Field {}
7pub trait IsOptional {}
8#[doc = "\nBuilder for [`wgpu::Dx12BackendOptions`]\n \nSet all required fields and any optional fields, then call `build()`.\n\nBuilder field setters:\n - [shader_compiler](Dx12BackendOptionsBuilder::shader_compiler) Optional, defaults to [wgpu::Dx12Compiler::Fxc]\n - [presentation_system](Dx12BackendOptionsBuilder::presentation_system) Optional, defaults to [wgpu::Dx12SwapchainKind::DxgiFromHwnd]\n - [latency_waitable_object](Dx12BackendOptionsBuilder::latency_waitable_object) Optional, defaults to [wgpu::Dx12UseFrameLatencyWaitableObject::Wait]\n"]
9pub struct Dx12BackendOptionsBuilder<CS: State> {
10 shader_compiler: CS::ShaderCompiler,
11 presentation_system: CS::PresentationSystem,
12 latency_waitable_object: CS::LatencyWaitableObject,
13}
14impl Dx12BackendOptionsBuilder<Empty> {
15 pub fn new() -> Dx12BackendOptionsBuilder<Empty> {
16 Dx12BackendOptionsBuilder {
17 shader_compiler: ShaderCompilerEmpty,
18 presentation_system: PresentationSystemEmpty,
19 latency_waitable_object: LatencyWaitableObjectEmpty,
20 }
21 }
22}
23#[doc = "\nReturns [Dx12BackendOptionsBuilder] for building [`wgpu::Dx12BackendOptions`]\n \nSet all required fields and any optional fields, then call `build()`.\n\nBuilder field setters:\n - [shader_compiler](Dx12BackendOptionsBuilder::shader_compiler) Optional, defaults to [wgpu::Dx12Compiler::Fxc]\n - [presentation_system](Dx12BackendOptionsBuilder::presentation_system) Optional, defaults to [wgpu::Dx12SwapchainKind::DxgiFromHwnd]\n - [latency_waitable_object](Dx12BackendOptionsBuilder::latency_waitable_object) Optional, defaults to [wgpu::Dx12UseFrameLatencyWaitableObject::Wait]\n"]
24pub fn dx_12_backend_options() -> Dx12BackendOptionsBuilder<Empty> {
25 Dx12BackendOptionsBuilder::new()
26}
27pub struct ShaderCompilerEmpty;
28impl Field for ShaderCompilerEmpty {}
29pub trait ShaderCompilerIsEmpty {}
30impl ShaderCompilerIsEmpty for ShaderCompilerEmpty {}
31pub trait IsSetShaderCompiler {
32 fn get(self) -> wgpu::Dx12Compiler;
33}
34impl IsSetShaderCompiler for ShaderCompilerEmpty {
35 fn get(self) -> wgpu::Dx12Compiler {
36 wgpu::Dx12Compiler::Fxc
37 }
38}
39pub struct ShaderCompilerValue(pub wgpu::Dx12Compiler);
40impl Field for ShaderCompilerValue {}
41impl IsSetShaderCompiler for ShaderCompilerValue {
42 fn get(self) -> wgpu::Dx12Compiler {
43 self.0
44 }
45}
46pub struct PresentationSystemEmpty;
47impl Field for PresentationSystemEmpty {}
48pub trait PresentationSystemIsEmpty {}
49impl PresentationSystemIsEmpty for PresentationSystemEmpty {}
50pub trait IsSetPresentationSystem {
51 fn get(self) -> wgpu::Dx12SwapchainKind;
52}
53impl IsSetPresentationSystem for PresentationSystemEmpty {
54 fn get(self) -> wgpu::Dx12SwapchainKind {
55 wgpu::Dx12SwapchainKind::DxgiFromHwnd
56 }
57}
58pub struct PresentationSystemValue(pub wgpu::Dx12SwapchainKind);
59impl Field for PresentationSystemValue {}
60impl IsSetPresentationSystem for PresentationSystemValue {
61 fn get(self) -> wgpu::Dx12SwapchainKind {
62 self.0
63 }
64}
65pub struct LatencyWaitableObjectEmpty;
66impl Field for LatencyWaitableObjectEmpty {}
67pub trait LatencyWaitableObjectIsEmpty {}
68impl LatencyWaitableObjectIsEmpty for LatencyWaitableObjectEmpty {}
69pub trait IsSetLatencyWaitableObject {
70 fn get(self) -> wgpu::Dx12UseFrameLatencyWaitableObject;
71}
72impl IsSetLatencyWaitableObject for LatencyWaitableObjectEmpty {
73 fn get(self) -> wgpu::Dx12UseFrameLatencyWaitableObject {
74 wgpu::Dx12UseFrameLatencyWaitableObject::Wait
75 }
76}
77pub struct LatencyWaitableObjectValue(pub wgpu::Dx12UseFrameLatencyWaitableObject);
78impl Field for LatencyWaitableObjectValue {}
79impl IsSetLatencyWaitableObject for LatencyWaitableObjectValue {
80 fn get(self) -> wgpu::Dx12UseFrameLatencyWaitableObject {
81 self.0
82 }
83}
84pub trait State {
85 type ShaderCompiler: Field;
86 type PresentationSystem: Field;
87 type LatencyWaitableObject: Field;
88}
89pub struct Empty;
90impl State for Empty {
91 type ShaderCompiler = ShaderCompilerEmpty;
92 type PresentationSystem = PresentationSystemEmpty;
93 type LatencyWaitableObject = LatencyWaitableObjectEmpty;
94}
95pub struct SetShaderCompiler<CS>(CS);
96impl<CS: State> State for SetShaderCompiler<CS> {
97 type ShaderCompiler = ShaderCompilerValue;
98 type PresentationSystem = CS::PresentationSystem;
99 type LatencyWaitableObject = CS::LatencyWaitableObject;
100}
101pub struct SetPresentationSystem<CS>(CS);
102impl<CS: State> State for SetPresentationSystem<CS> {
103 type ShaderCompiler = CS::ShaderCompiler;
104 type PresentationSystem = PresentationSystemValue;
105 type LatencyWaitableObject = CS::LatencyWaitableObject;
106}
107pub struct SetLatencyWaitableObject<CS>(CS);
108impl<CS: State> State for SetLatencyWaitableObject<CS> {
109 type ShaderCompiler = CS::ShaderCompiler;
110 type PresentationSystem = CS::PresentationSystem;
111 type LatencyWaitableObject = LatencyWaitableObjectValue;
112}
113impl<CS: State> Dx12BackendOptionsBuilder<CS> {
114 #[doc = "Setter for [wgpu::Dx12BackendOptions::shader_compiler]. Optional, defaults to [wgpu::Dx12Compiler::Fxc].\n"]
115 pub fn shader_compiler(
116 self,
117 shader_compiler: wgpu::Dx12Compiler,
118 ) -> Dx12BackendOptionsBuilder<SetShaderCompiler<CS>>
119 where
120 CS::ShaderCompiler: ShaderCompilerIsEmpty,
121 {
122 Dx12BackendOptionsBuilder {
123 shader_compiler: ShaderCompilerValue(shader_compiler),
124 presentation_system: self.presentation_system,
125 latency_waitable_object: self.latency_waitable_object,
126 }
127 }
128 #[doc = "Setter for [wgpu::Dx12BackendOptions::presentation_system]. Optional, defaults to [wgpu::Dx12SwapchainKind::DxgiFromHwnd].\n"]
129 pub fn presentation_system(
130 self,
131 presentation_system: wgpu::Dx12SwapchainKind,
132 ) -> Dx12BackendOptionsBuilder<SetPresentationSystem<CS>>
133 where
134 CS::PresentationSystem: PresentationSystemIsEmpty,
135 {
136 Dx12BackendOptionsBuilder {
137 shader_compiler: self.shader_compiler,
138 presentation_system: PresentationSystemValue(presentation_system),
139 latency_waitable_object: self.latency_waitable_object,
140 }
141 }
142 #[doc = "Setter for [wgpu::Dx12BackendOptions::latency_waitable_object]. Optional, defaults to [wgpu::Dx12UseFrameLatencyWaitableObject::Wait].\n"]
143 pub fn latency_waitable_object(
144 self,
145 latency_waitable_object: wgpu::Dx12UseFrameLatencyWaitableObject,
146 ) -> Dx12BackendOptionsBuilder<SetLatencyWaitableObject<CS>>
147 where
148 CS::LatencyWaitableObject: LatencyWaitableObjectIsEmpty,
149 {
150 Dx12BackendOptionsBuilder {
151 shader_compiler: self.shader_compiler,
152 presentation_system: self.presentation_system,
153 latency_waitable_object: LatencyWaitableObjectValue(latency_waitable_object),
154 }
155 }
156}
157pub trait Complete:
158 State<
159 ShaderCompiler: IsSetShaderCompiler,
160 PresentationSystem: IsSetPresentationSystem,
161 LatencyWaitableObject: IsSetLatencyWaitableObject,
162>
163{
164}
165impl<
166 CS: State<
167 ShaderCompiler: IsSetShaderCompiler,
168 PresentationSystem: IsSetPresentationSystem,
169 LatencyWaitableObject: IsSetLatencyWaitableObject,
170 >,
171 > Complete for CS
172{
173}
174impl<CS: Complete> Dx12BackendOptionsBuilder<CS> {
175 pub fn build(self) -> wgpu::Dx12BackendOptions {
176 wgpu::Dx12BackendOptions {
177 shader_compiler: IsSetShaderCompiler::get(self.shader_compiler),
178 presentation_system: IsSetPresentationSystem::get(self.presentation_system),
179 latency_waitable_object: IsSetLatencyWaitableObject::get(self.latency_waitable_object),
180 }
181 }
182}
183impl Nested<wgpu::Dx12BackendOptions> for wgpu::Dx12BackendOptions {
184 fn unnest(self) -> wgpu::Dx12BackendOptions {
185 self
186 }
187}
188impl<CS: Complete> Nested<wgpu::Dx12BackendOptions> for Dx12BackendOptionsBuilder<CS> {
189 fn unnest(self) -> wgpu::Dx12BackendOptions {
190 self.build()
191 }
192}
193#[cfg(test)]
194mod tests {
195 #[allow(unused_imports)]
196 #[allow(unused_imports)]
197 use std::num::NonZeroU32;
198 #[test]
199 pub fn test_default() {
200 assert_eq!(
201 format!("{:#?}", super::dx_12_backend_options().build()),
202 format!("{:#?}", wgpu::Dx12BackendOptions::default()),
203 );
204 }
205}