MCPcopy Create free account
hub / github.com/Rust-GPU/rust-gpu / run

Function run

examples/runners/wgpu/src/graphics.rs:34–331  ·  view source on GitHub ↗
(
    options: Options,
    event_loop: EventLoop<CompiledShaderModules>,
    window: Window,
    compiled_shader_modules: CompiledShaderModules,
)

Source from the content-addressed store, hash-verified

32}
33
34async fn run(
35 options: Options,
36 event_loop: EventLoop<CompiledShaderModules>,
37 window: Window,
38 compiled_shader_modules: CompiledShaderModules,
39) {
40 let backends = wgpu::util::backend_bits_from_env()
41 .unwrap_or(wgpu::Backends::VULKAN | wgpu::Backends::METAL);
42 let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
43 backends,
44 dx12_shader_compiler: wgpu::util::dx12_shader_compiler_from_env().unwrap_or_default(),
45 });
46
47 // HACK(eddyb) marker error type for lazily-created surfaces (e.g. on Android).
48 struct SurfaceCreationPending {
49 preferred_format: wgpu::TextureFormat,
50 }
51
52 // Wait for Resumed event on Android; the surface is only otherwise needed
53 // early to find an adapter that can render to this surface.
54 let initial_surface = if cfg!(target_os = "android") {
55 Err(SurfaceCreationPending {
56 preferred_format: wgpu::TextureFormat::Rgba8UnormSrgb,
57 })
58 } else {
59 Ok(unsafe { instance.create_surface(&window) }
60 .expect("Failed to create surface from window"))
61 };
62
63 let adapter = wgpu::util::initialize_adapter_from_env_or_default(
64 &instance,
65 backends,
66 // Request an adapter which can render to our surface
67 initial_surface.as_ref().ok(),
68 )
69 .await
70 .expect("Failed to find an appropriate adapter");
71
72 let mut features = wgpu::Features::PUSH_CONSTANTS;
73 if options.force_spirv_passthru {
74 features |= wgpu::Features::SPIRV_SHADER_PASSTHROUGH;
75 }
76 let limits = wgpu::Limits {
77 max_push_constant_size: 128,
78 ..Default::default()
79 };
80
81 // Create the logical device and command queue
82 let (device, queue) = adapter
83 .request_device(
84 &wgpu::DeviceDescriptor {
85 label: None,
86 features,
87 limits,
88 },
89 None,
90 )
91 .await

Callers

nothing calls this directly

Calls 6

create_pipelineFunction · 0.85
mouse_button_indexFunction · 0.85
expectMethod · 0.80
drawMethod · 0.80
as_refMethod · 0.45

Tested by

no test coverage detected