Skip to content

Commit 05d10d1

Browse files
committed
Deploying to master from @ gfx-rs/wgpu@ef996e6 🚀
1 parent 7edb3ba commit 05d10d1

File tree

5 files changed

+218
-54
lines changed

5 files changed

+218
-54
lines changed

doc/src/wgpu_examples/framework.rs.html

Lines changed: 11 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -619,26 +619,6 @@
619619
<a href="#618" id="618">618</a>
620620
<a href="#619" id="619">619</a>
621621
<a href="#620" id="620">620</a>
622-
<a href="#621" id="621">621</a>
623-
<a href="#622" id="622">622</a>
624-
<a href="#623" id="623">623</a>
625-
<a href="#624" id="624">624</a>
626-
<a href="#625" id="625">625</a>
627-
<a href="#626" id="626">626</a>
628-
<a href="#627" id="627">627</a>
629-
<a href="#628" id="628">628</a>
630-
<a href="#629" id="629">629</a>
631-
<a href="#630" id="630">630</a>
632-
<a href="#631" id="631">631</a>
633-
<a href="#632" id="632">632</a>
634-
<a href="#633" id="633">633</a>
635-
<a href="#634" id="634">634</a>
636-
<a href="#635" id="635">635</a>
637-
<a href="#636" id="636">636</a>
638-
<a href="#637" id="637">637</a>
639-
<a href="#638" id="638">638</a>
640-
<a href="#639" id="639">639</a>
641-
<a href="#640" id="640">640</a>
642622
</pre></div><pre class="rust"><code><span class="kw">use </span>std::sync::Arc;
643623

644624
<span class="kw">use </span>wgpu::{Instance, Surface};
@@ -920,37 +900,14 @@
920900
gles_minor_version,
921901
});
922902
surface.pre_adapter(<span class="kw-2">&amp;</span>instance, window);
923-
<span class="kw">let </span>adapter = wgpu::util::initialize_adapter_from_env_or_default(<span class="kw-2">&amp;</span>instance, surface.get())
924-
.<span class="kw">await
925-
</span>.expect(<span class="string">"No suitable GPU adapters found on the system!"</span>);
926-
927-
<span class="kw">let </span>adapter_info = adapter.get_info();
928-
<span class="macro">log::info!</span>(<span class="string">"Using {} ({:?})"</span>, adapter_info.name, adapter_info.backend);
929-
930-
<span class="kw">let </span>optional_features = E::optional_features();
931-
<span class="kw">let </span>required_features = E::required_features();
932-
<span class="kw">let </span>adapter_features = adapter.features();
933-
<span class="macro">assert!</span>(
934-
adapter_features.contains(required_features),
935-
<span class="string">"Adapter does not support required features for this example: {:?}"</span>,
936-
required_features - adapter_features
937-
);
938-
939-
<span class="kw">let </span>required_downlevel_capabilities = E::required_downlevel_capabilities();
940-
<span class="kw">let </span>downlevel_capabilities = adapter.get_downlevel_capabilities();
941-
<span class="macro">assert!</span>(
942-
downlevel_capabilities.shader_model &gt;= required_downlevel_capabilities.shader_model,
943-
<span class="string">"Adapter does not support the minimum shader model required to run this example: {:?}"</span>,
944-
required_downlevel_capabilities.shader_model
945-
);
946-
<span class="macro">assert!</span>(
947-
downlevel_capabilities
948-
.flags
949-
.contains(required_downlevel_capabilities.flags),
950-
<span class="string">"Adapter does not support the downlevel capabilities required to run this example: {:?}"</span>,
951-
required_downlevel_capabilities.flags - downlevel_capabilities.flags
952-
);
953903

904+
<span class="kw">let </span>adapter = get_adapter_with_capabilities_or_from_env(
905+
<span class="kw-2">&amp;</span>instance,
906+
<span class="kw-2">&amp;</span>E::required_features(),
907+
<span class="kw-2">&amp;</span>E::required_downlevel_capabilities(),
908+
<span class="kw-2">&amp;</span>surface.get(),
909+
)
910+
.<span class="kw">await</span>;
954911
<span class="comment">// Make sure we use the texture resolution limits from the adapter, so we can support images the size of the surface.
955912
</span><span class="kw">let </span>needed_limits = E::required_limits().using_resolution(adapter.limits());
956913

@@ -959,7 +916,8 @@
959916
.request_device(
960917
<span class="kw-2">&amp;</span>wgpu::DeviceDescriptor {
961918
label: <span class="prelude-val">None</span>,
962-
required_features: (optional_features &amp; adapter_features) | required_features,
919+
required_features: (E::optional_features() &amp; adapter.features())
920+
| E::required_features(),
963921
required_limits: needed_limits,
964922
memory_hints: wgpu::MemoryHints::MemoryUsage,
965923
},
@@ -1155,6 +1113,8 @@
11551113
<span class="attr">#[cfg(test)]
11561114
</span><span class="kw">pub use </span>wgpu_test::image::ComparisonType;
11571115

1116+
<span class="kw">use </span><span class="kw">crate</span>::utils::get_adapter_with_capabilities_or_from_env;
1117+
11581118
<span class="attr">#[cfg(test)]
11591119
#[derive(Clone)]
11601120
</span><span class="kw">pub struct </span>ExampleTestParams&lt;E&gt; {

doc/src/wgpu_examples/utils.rs.html

Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,108 @@
157157
<a href="#156" id="156">156</a>
158158
<a href="#157" id="157">157</a>
159159
<a href="#158" id="158">158</a>
160+
<a href="#159" id="159">159</a>
161+
<a href="#160" id="160">160</a>
162+
<a href="#161" id="161">161</a>
163+
<a href="#162" id="162">162</a>
164+
<a href="#163" id="163">163</a>
165+
<a href="#164" id="164">164</a>
166+
<a href="#165" id="165">165</a>
167+
<a href="#166" id="166">166</a>
168+
<a href="#167" id="167">167</a>
169+
<a href="#168" id="168">168</a>
170+
<a href="#169" id="169">169</a>
171+
<a href="#170" id="170">170</a>
172+
<a href="#171" id="171">171</a>
173+
<a href="#172" id="172">172</a>
174+
<a href="#173" id="173">173</a>
175+
<a href="#174" id="174">174</a>
176+
<a href="#175" id="175">175</a>
177+
<a href="#176" id="176">176</a>
178+
<a href="#177" id="177">177</a>
179+
<a href="#178" id="178">178</a>
180+
<a href="#179" id="179">179</a>
181+
<a href="#180" id="180">180</a>
182+
<a href="#181" id="181">181</a>
183+
<a href="#182" id="182">182</a>
184+
<a href="#183" id="183">183</a>
185+
<a href="#184" id="184">184</a>
186+
<a href="#185" id="185">185</a>
187+
<a href="#186" id="186">186</a>
188+
<a href="#187" id="187">187</a>
189+
<a href="#188" id="188">188</a>
190+
<a href="#189" id="189">189</a>
191+
<a href="#190" id="190">190</a>
192+
<a href="#191" id="191">191</a>
193+
<a href="#192" id="192">192</a>
194+
<a href="#193" id="193">193</a>
195+
<a href="#194" id="194">194</a>
196+
<a href="#195" id="195">195</a>
197+
<a href="#196" id="196">196</a>
198+
<a href="#197" id="197">197</a>
199+
<a href="#198" id="198">198</a>
200+
<a href="#199" id="199">199</a>
201+
<a href="#200" id="200">200</a>
202+
<a href="#201" id="201">201</a>
203+
<a href="#202" id="202">202</a>
204+
<a href="#203" id="203">203</a>
205+
<a href="#204" id="204">204</a>
206+
<a href="#205" id="205">205</a>
207+
<a href="#206" id="206">206</a>
208+
<a href="#207" id="207">207</a>
209+
<a href="#208" id="208">208</a>
210+
<a href="#209" id="209">209</a>
211+
<a href="#210" id="210">210</a>
212+
<a href="#211" id="211">211</a>
213+
<a href="#212" id="212">212</a>
214+
<a href="#213" id="213">213</a>
215+
<a href="#214" id="214">214</a>
216+
<a href="#215" id="215">215</a>
217+
<a href="#216" id="216">216</a>
218+
<a href="#217" id="217">217</a>
219+
<a href="#218" id="218">218</a>
220+
<a href="#219" id="219">219</a>
221+
<a href="#220" id="220">220</a>
222+
<a href="#221" id="221">221</a>
223+
<a href="#222" id="222">222</a>
224+
<a href="#223" id="223">223</a>
225+
<a href="#224" id="224">224</a>
226+
<a href="#225" id="225">225</a>
227+
<a href="#226" id="226">226</a>
228+
<a href="#227" id="227">227</a>
229+
<a href="#228" id="228">228</a>
230+
<a href="#229" id="229">229</a>
231+
<a href="#230" id="230">230</a>
232+
<a href="#231" id="231">231</a>
233+
<a href="#232" id="232">232</a>
234+
<a href="#233" id="233">233</a>
235+
<a href="#234" id="234">234</a>
236+
<a href="#235" id="235">235</a>
237+
<a href="#236" id="236">236</a>
238+
<a href="#237" id="237">237</a>
239+
<a href="#238" id="238">238</a>
240+
<a href="#239" id="239">239</a>
241+
<a href="#240" id="240">240</a>
242+
<a href="#241" id="241">241</a>
243+
<a href="#242" id="242">242</a>
244+
<a href="#243" id="243">243</a>
245+
<a href="#244" id="244">244</a>
246+
<a href="#245" id="245">245</a>
247+
<a href="#246" id="246">246</a>
248+
<a href="#247" id="247">247</a>
249+
<a href="#248" id="248">248</a>
250+
<a href="#249" id="249">249</a>
251+
<a href="#250" id="250">250</a>
252+
<a href="#251" id="251">251</a>
253+
<a href="#252" id="252">252</a>
254+
<a href="#253" id="253">253</a>
255+
<a href="#254" id="254">254</a>
256+
<a href="#255" id="255">255</a>
257+
<a href="#256" id="256">256</a>
258+
<a href="#257" id="257">257</a>
259+
<a href="#258" id="258">258</a>
260+
<a href="#259" id="259">259</a>
261+
<a href="#260" id="260">260</a>
160262
</pre></div><pre class="rust"><code><span class="attr">#[cfg(not(target_arch = <span class="string">"wasm32"</span>))]
161263
</span><span class="kw">use </span>std::io::Write;
162264
<span class="attr">#[cfg(target_arch = <span class="string">"wasm32"</span>)]
@@ -315,4 +417,106 @@
315417
<span class="macro">log::info!</span>(<span class="string">"Created new output target image: {:?}"</span>, <span class="kw-2">&amp;</span>new_image);
316418
new_image
317419
}
420+
421+
<span class="attr">#[cfg(not(target_arch = <span class="string">"wasm32"</span>))]
422+
</span><span class="doccomment">/// If the environment variable `WGPU_ADAPTER_NAME` is set, this function will attempt to
423+
/// initialize the adapter with that name. If it is not set, it will attempt to initialize
424+
/// the adapter which supports the required features.
425+
</span><span class="kw">pub</span>(<span class="kw">crate</span>) <span class="kw">async fn </span>get_adapter_with_capabilities_or_from_env(
426+
instance: <span class="kw-2">&amp;</span>wgpu::Instance,
427+
required_features: <span class="kw-2">&amp;</span>wgpu::Features,
428+
required_downlevel_capabilities: <span class="kw-2">&amp;</span>wgpu::DownlevelCapabilities,
429+
surface: <span class="kw-2">&amp;</span><span class="prelude-ty">Option</span>&lt;<span class="kw-2">&amp;</span>wgpu::Surface&lt;<span class="lifetime">'_</span>&gt;&gt;,
430+
) -&gt; wgpu::Adapter {
431+
<span class="kw">use </span>wgpu::Backends;
432+
<span class="kw">if </span>std::env::var(<span class="string">"WGPU_ADAPTER_NAME"</span>).is_ok() {
433+
<span class="kw">let </span>adapter = wgpu::util::initialize_adapter_from_env_or_default(instance, <span class="kw-2">*</span>surface)
434+
.<span class="kw">await
435+
</span>.expect(<span class="string">"No suitable GPU adapters found on the system!"</span>);
436+
437+
<span class="kw">let </span>adapter_info = adapter.get_info();
438+
<span class="macro">log::info!</span>(<span class="string">"Using {} ({:?})"</span>, adapter_info.name, adapter_info.backend);
439+
440+
<span class="kw">let </span>adapter_features = adapter.features();
441+
<span class="macro">assert!</span>(
442+
adapter_features.contains(<span class="kw-2">*</span>required_features),
443+
<span class="string">"Adapter does not support required features for this example: {:?}"</span>,
444+
<span class="kw-2">*</span>required_features - adapter_features
445+
);
446+
447+
<span class="kw">let </span>downlevel_capabilities = adapter.get_downlevel_capabilities();
448+
<span class="macro">assert!</span>(
449+
downlevel_capabilities.shader_model &gt;= required_downlevel_capabilities.shader_model,
450+
<span class="string">"Adapter does not support the minimum shader model required to run this example: {:?}"</span>,
451+
required_downlevel_capabilities.shader_model
452+
);
453+
<span class="macro">assert!</span>(
454+
downlevel_capabilities
455+
.flags
456+
.contains(required_downlevel_capabilities.flags),
457+
<span class="string">"Adapter does not support the downlevel capabilities required to run this example: {:?}"</span>,
458+
required_downlevel_capabilities.flags - downlevel_capabilities.flags
459+
);
460+
adapter
461+
} <span class="kw">else </span>{
462+
<span class="kw">let </span>adapters = instance.enumerate_adapters(Backends::all());
463+
464+
<span class="kw">let </span><span class="kw-2">mut </span>chosen_adapter = <span class="prelude-val">None</span>;
465+
<span class="kw">for </span>adapter <span class="kw">in </span>adapters {
466+
<span class="kw">if let </span><span class="prelude-val">Some</span>(surface) = surface {
467+
<span class="kw">if </span>!adapter.is_surface_supported(surface) {
468+
<span class="kw">continue</span>;
469+
}
470+
}
471+
472+
<span class="kw">let </span>required_features = <span class="kw-2">*</span>required_features;
473+
<span class="kw">let </span>adapter_features = adapter.features();
474+
<span class="kw">if </span>!adapter_features.contains(required_features) {
475+
<span class="kw">continue</span>;
476+
} <span class="kw">else </span>{
477+
chosen_adapter = <span class="prelude-val">Some</span>(adapter);
478+
<span class="kw">break</span>;
479+
}
480+
}
481+
482+
chosen_adapter.expect(<span class="string">"No suitable GPU adapters found on the system!"</span>)
483+
}
484+
}
485+
486+
<span class="attr">#[cfg(target_arch = <span class="string">"wasm32"</span>)]
487+
</span><span class="kw">pub</span>(<span class="kw">crate</span>) <span class="kw">async fn </span>get_adapter_with_capabilities_or_from_env(
488+
instance: <span class="kw-2">&amp;</span>wgpu::Instance,
489+
required_features: <span class="kw-2">&amp;</span>wgpu::Features,
490+
required_downlevel_capabilities: <span class="kw-2">&amp;</span>wgpu::DownlevelCapabilities,
491+
surface: <span class="kw-2">&amp;</span><span class="prelude-ty">Option</span>&lt;<span class="kw-2">&amp;</span>wgpu::Surface&lt;<span class="lifetime">'_</span>&gt;&gt;,
492+
) -&gt; wgpu::Adapter {
493+
<span class="kw">let </span>adapter = wgpu::util::initialize_adapter_from_env_or_default(instance, <span class="kw-2">*</span>surface)
494+
.<span class="kw">await
495+
</span>.expect(<span class="string">"No suitable GPU adapters found on the system!"</span>);
496+
497+
<span class="kw">let </span>adapter_info = adapter.get_info();
498+
<span class="macro">log::info!</span>(<span class="string">"Using {} ({:?})"</span>, adapter_info.name, adapter_info.backend);
499+
500+
<span class="kw">let </span>adapter_features = adapter.features();
501+
<span class="macro">assert!</span>(
502+
adapter_features.contains(<span class="kw-2">*</span>required_features),
503+
<span class="string">"Adapter does not support required features for this example: {:?}"</span>,
504+
<span class="kw-2">*</span>required_features - adapter_features
505+
);
506+
507+
<span class="kw">let </span>downlevel_capabilities = adapter.get_downlevel_capabilities();
508+
<span class="macro">assert!</span>(
509+
downlevel_capabilities.shader_model &gt;= required_downlevel_capabilities.shader_model,
510+
<span class="string">"Adapter does not support the minimum shader model required to run this example: {:?}"</span>,
511+
required_downlevel_capabilities.shader_model
512+
);
513+
<span class="macro">assert!</span>(
514+
downlevel_capabilities
515+
.flags
516+
.contains(required_downlevel_capabilities.flags),
517+
<span class="string">"Adapter does not support the downlevel capabilities required to run this example: {:?}"</span>,
518+
required_downlevel_capabilities.flags - downlevel_capabilities.flags
519+
);
520+
adapter
521+
}
318522
</code></pre></div></section></main></body></html>

0 commit comments

Comments
 (0)