1#![deny(missing_docs)]
2#![doc = include_str!("../README.md")]
3
4pub use offscreen::{COMPOSITION_BYTES_PER_PIXEL, offscreen_render_target_for_tests};
5pub use render::presentable_root_usages;
6mod ablation;
7mod arc_trig_fill;
8mod capture_hash;
9mod captured_frame;
10mod collect;
11mod cpu_allocation_stats;
12mod depth_gate;
13mod device_error_sentry;
14mod draw_pass;
15mod effect_renderer;
16mod fast_cores;
17mod frame;
18mod geometry;
19mod idle_pool;
20mod layer_cache;
21mod renderer_impl;
22pub use fast_cores::pin_current_thread_to_fast_cores;
23#[cfg(all(target_arch = "wasm32", feature = "gl-templates"))]
24mod first_screen_glsl;
25mod fixed_pipeline;
26mod frame_graph;
27mod frame_packet;
28mod frontend;
29mod gpu_target;
30mod host_gl;
31#[cfg(all(target_arch = "wasm32", feature = "gl-templates"))]
32pub use first_screen_glsl::{
33 FirstScreenGlslError, first_screen_stages, list_first_screen_stages, use_first_screen_glsl,
34};
35#[cfg(all(target_arch = "wasm32", feature = "gl-templates"))]
37mod gl_templates {
38 include!(concat!(env!("OUT_DIR"), "/gl_templates.rs"));
39}
40#[cfg(test)]
41#[path = "tests/gles_lowering.rs"]
42mod gles_lowering;
43mod glyph_run;
44mod glyph_run_arena;
45pub(crate) mod gpu_stats;
46mod initial_present;
47#[cfg(all(not(target_arch = "wasm32"), feature = "test-support"))]
48mod inline_present_runtime;
49mod instant_triangles;
50mod lazy_resource;
51mod mesh_fallback;
52mod offscreen;
53mod opaque_prefix;
54mod output_conversion;
55mod pipeline;
56mod pipeline_compiler;
57#[cfg(not(target_arch = "wasm32"))]
60pub mod pipeline_disk_cache;
61mod pipeline_recorder;
62mod pipeline_records;
63#[cfg(not(target_arch = "wasm32"))]
64mod present_handle;
65#[cfg(not(target_arch = "wasm32"))]
66mod present_observer;
67#[cfg(not(target_arch = "wasm32"))]
68mod present_runtime;
69#[cfg(not(target_arch = "wasm32"))]
70mod present_thread;
71mod rc_slice_pool;
72mod record_columns;
73mod render;
74mod rrect_shadow;
75mod run_geometry;
76mod run_store;
77mod scene;
78mod scene_depth;
79mod scene_pass;
80mod scissor;
81mod shader_cache;
82mod shaders;
83mod shape_pipelines;
84mod shared_shader;
85mod target_state;
86#[cfg(test)]
87mod test_support;
88#[cfg(all(not(target_arch = "wasm32"), feature = "test-support"))]
89mod test_target;
90mod text_system;
91mod thread_state;
92mod window_packets;
93
94use std::sync::Arc;
95
96pub use captured_frame::CapturedFrame;
97pub use cpu_allocation_stats::DebugCpuAllocationStats;
98use cranpose_render_common::text_fonts::TextFonts;
99use cranpose_ui_graphics::Rect;
100pub use frame_graph::pass_timing::{GpuPassTimingEntry, GpuPassTimingReport};
101pub use frame_packet::PresentTimings;
102use frame_packet::RenderReturns;
103#[doc(hidden)]
104pub use frame_packet::{CancelReason, PresentOutcome};
105use frontend::RendererFrontend;
106pub use gpu_stats::{FrameDamage, FrameStatsSnapshot as RenderStatsSnapshot, WindowRects};
107pub use gpu_target::{GpuTarget, optional_device_features};
108pub use initial_present::{clear_to_background, clear_to_default_background};
109#[cfg(all(not(target_arch = "wasm32"), feature = "test-support"))]
110pub use inline_present_runtime::InlinePresentRuntime;
111use pipeline_compiler::PipelineCompilation;
112#[cfg(not(target_arch = "wasm32"))]
113use present_handle::PresentHandle;
114#[cfg(not(target_arch = "wasm32"))]
115pub use present_observer::PresentObserver;
116#[cfg(not(target_arch = "wasm32"))]
117use present_runtime::PresentRuntimeInit;
118#[cfg(not(target_arch = "wasm32"))]
119pub use present_thread::PresentThread;
120use render::{FrameOutput, FrameSubmit, GpuRenderer, GpuRendererInit};
121pub use render::{
122 frame_clear_color, frames_presented, pipelines_created, pipelines_created_off_frame,
123};
124pub use scene::{HitRegion, Scene};
125pub use scene_pass::SCENE_DEPTH_FORMAT;
126pub use shared_shader::{shader_stages_flattened, shader_stages_folded};
127#[cfg(all(not(target_arch = "wasm32"), feature = "test-support"))]
128pub use test_target::TestImages;
129pub use text_system::WgpuTextSystem;
130
131pub(crate) fn rect_to_quad(rect: Rect) -> [[f32; 2]; 4] {
132 [
133 [rect.x, rect.y],
134 [rect.x + rect.width, rect.y],
135 [rect.x, rect.y + rect.height],
136 [rect.x + rect.width, rect.y + rect.height],
137 ]
138}
139
140#[derive(Debug)]
142pub enum WgpuRendererError {
143 Wgpu(String),
146}
147
148struct SyncPresenter {
151 renderer: GpuRenderer,
152 submit: FrameSubmit,
153}
154
155enum PresentBackend {
156 None,
157 Sync(Box<SyncPresenter>),
158 #[cfg(not(target_arch = "wasm32"))]
159 Threaded(PresentHandle),
160}
161
162impl PresentBackend {
163 fn sync_mut(&mut self) -> Result<&mut SyncPresenter, WgpuRendererError> {
165 match self {
166 Self::Sync(sync) => Ok(sync),
167 _ => Err(WgpuRendererError::Wgpu(
168 "GPU renderer not initialized for synchronous rendering. Call init_gpu() first."
169 .to_string(),
170 )),
171 }
172 }
173}
174
175#[derive(Clone, Copy, Debug, PartialEq, Eq)]
177pub enum PublishOutcome {
178 NoGraph,
180 NoCredit,
183 Published,
185}
186
187pub struct WgpuRenderer {
195 frontend: RendererFrontend,
196 backend: PresentBackend,
197 renderer_epoch: u64,
198 surface_epoch: u64,
199 on_device_lost: Option<DeviceLostHandler>,
200}
201
202pub type DeviceLostHandler = Arc<dyn Fn() + Send + Sync>;
205
206impl WgpuRenderer {
207 pub fn new(fonts: &[&'static [u8]]) -> Self {
214 Self::with_text_system(WgpuTextSystem::from_fonts(fonts))
215 }
216
217 pub fn with_text_fonts(fonts: TextFonts) -> Self {
219 Self::with_text_system(WgpuTextSystem::from_text_fonts(fonts))
220 }
221
222 pub fn with_text_system(text_system: WgpuTextSystem) -> Self {
224 Self {
225 frontend: RendererFrontend::new(text_system.fonts().clone()),
226 backend: PresentBackend::None,
227 renderer_epoch: 0,
228 surface_epoch: 0,
229 on_device_lost: None,
230 }
231 }
232
233 pub fn set_device_lost_handler(&mut self, handler: DeviceLostHandler) {
236 self.on_device_lost = Some(handler);
237 }
238
239 fn sync_gpu_renderer(&self) -> Option<&GpuRenderer> {
240 match &self.backend {
241 PresentBackend::Sync(sync) => Some(&sync.renderer),
242 _ => None,
243 }
244 }
245
246 fn retire_live_backend(&mut self) {
247 #[allow(unused_mut, reason = "only native targets change the backend")]
248 let mut backend = std::mem::replace(&mut self.backend, PresentBackend::None);
249 #[cfg(not(target_arch = "wasm32"))]
250 if let PresentBackend::Threaded(handle) = &mut backend {
251 while let Some(returns) = handle.try_drain() {
252 self.frontend.apply_returns(returns);
253 }
254 handle.shutdown();
255 }
256 drop(backend);
257 }
258
259 pub fn release_gpu(&mut self) {
264 self.retire_live_backend();
265 }
266
267 pub fn init_gpu(&mut self, target: GpuTarget) {
273 self.install_gpu(target, PipelineCompilation::Background);
274 }
275
276 #[doc(hidden)]
280 pub fn init_gpu_compiling_inline_for_tests(&mut self, target: GpuTarget) {
281 self.install_gpu(target, PipelineCompilation::Inline);
282 }
283
284 fn install_gpu(&mut self, target: GpuTarget, pipeline_compilation: PipelineCompilation) {
285 let init = self.next_gpu_init(target, pipeline_compilation);
286 let submit = FrameSubmit::new(&init);
287 self.backend = PresentBackend::Sync(Box::new(SyncPresenter {
288 renderer: GpuRenderer::new(init),
289 submit,
290 }));
291 }
292
293 fn next_gpu_init(
296 &mut self,
297 target: GpuTarget,
298 pipeline_compilation: PipelineCompilation,
299 ) -> GpuRendererInit {
300 self.retire_live_backend();
301 self.renderer_epoch = self.renderer_epoch.wrapping_add(1);
302 target.renderer_init(
303 self.renderer_epoch,
304 pipeline_compilation,
305 self.on_device_lost.clone(),
306 )
307 }
308
309 #[cfg(not(target_arch = "wasm32"))]
326 pub fn init_gpu_threaded(
327 &mut self,
328 target: GpuTarget,
329 waker: Arc<dyn Fn() + Send + Sync>,
330 clock: Option<Arc<dyn Fn() -> i64 + Send + Sync>>,
331 observer: Option<Box<dyn PresentObserver>>,
332 ) -> Result<(), WgpuRendererError> {
333 let init = PresentRuntimeInit {
334 gpu: self.next_gpu_init(target, PipelineCompilation::Background),
335 clock,
336 observer,
337 };
338 let handle = PresentHandle::spawn(init, waker).map_err(WgpuRendererError::Wgpu)?;
339 self.backend = PresentBackend::Threaded(handle);
340 Ok(())
341 }
342
343 #[cfg(all(not(target_arch = "wasm32"), feature = "test-support"))]
344 #[doc(hidden)]
345 pub fn init_gpu_inline_for_tests(&mut self, target: GpuTarget) -> InlinePresentRuntime {
346 let init = PresentRuntimeInit {
347 gpu: self.next_gpu_init(target, PipelineCompilation::Background),
348 clock: None,
349 observer: None,
350 };
351 let (handle, state, msg_rx) = PresentHandle::new_inline(init, Arc::new(|| {}));
352 self.backend = PresentBackend::Threaded(handle);
353 InlinePresentRuntime::new(state, msg_rx)
354 }
355
356 pub fn note_surface_reconfigured(&mut self) {
361 self.surface_epoch = self.surface_epoch.wrapping_add(1);
362 }
363
364 pub fn set_transparent_background(&mut self, transparent: bool) {
369 self.frontend.transparent_background = transparent;
370 }
371
372 pub fn root_scale(&self) -> f32 {
375 self.frontend.root_scale
376 }
377
378 pub fn render(
385 &mut self,
386 texture: &wgpu::Texture,
387 view: &wgpu::TextureView,
388 width: u32,
389 height: u32,
390 ) -> Result<(), WgpuRendererError> {
391 self.render_frame(texture, view, width, height, frame::ImageContent::Untracked)
392 }
393
394 pub fn render_surface_texture(
405 &mut self,
406 frame: &wgpu::SurfaceTexture,
407 view: &wgpu::TextureView,
408 width: u32,
409 height: u32,
410 ) -> Result<(), WgpuRendererError> {
411 let image = frame::ImageContent::of(frame);
412 self.render_frame(&frame.texture, view, width, height, image)
413 }
414
415 #[cfg(target_arch = "wasm32")]
422 pub fn hide_drawn_frame(&mut self, view: &wgpu::TextureView) {
423 let Some(gpu_renderer) = self.sync_gpu_renderer() else {
424 return;
425 };
426 clear_to_background(
427 &gpu_renderer.device,
428 &gpu_renderer.queue,
429 view,
430 frame_clear_color(self.frontend.transparent_background),
431 );
432 self.release_kept_copy();
433 }
434
435 pub fn present(&self, frame: wgpu::SurfaceTexture) {
442 match self.sync_gpu_renderer() {
443 Some(gpu_renderer) => gpu_renderer.queue.present(frame),
444 None => log::debug!("surface image released: the renderer has no GPU queue"),
445 }
446 }
447
448 #[doc(hidden)]
452 pub fn render_swapchain_image_for_tests(
453 &mut self,
454 texture: &wgpu::Texture,
455 view: &wgpu::TextureView,
456 index: u32,
457 images: u32,
458 kept: bool,
459 ) -> Result<(), WgpuRendererError> {
460 self.render_frame(
461 texture,
462 view,
463 texture.width(),
464 texture.height(),
465 frame::ImageContent::Numbered(frame::PresentedImage {
466 index,
467 kept,
468 images,
469 }),
470 )
471 }
472
473 #[doc(hidden)]
476 pub fn render_cleared_image_for_tests(
477 &mut self,
478 texture: &wgpu::Texture,
479 view: &wgpu::TextureView,
480 ) -> Result<(), WgpuRendererError> {
481 self.render_frame(
482 texture,
483 view,
484 texture.width(),
485 texture.height(),
486 frame::ImageContent::Cleared,
487 )
488 }
489
490 pub fn release_kept_copy(&mut self) {
496 if let PresentBackend::Sync(sync) = &mut self.backend {
497 sync.renderer.release_kept_copy();
498 self.frontend.forget_held();
499 }
500 }
501
502 fn render_frame(
503 &mut self,
504 texture: &wgpu::Texture,
505 view: &wgpu::TextureView,
506 width: u32,
507 height: u32,
508 image: frame::ImageContent,
509 ) -> Result<(), WgpuRendererError> {
510 self.frontend.landings = self.landings();
511 let SyncPresenter {
512 renderer: gpu_renderer,
513 submit,
514 } = self.backend.sync_mut()?;
515 let epochs = (self.renderer_epoch, self.surface_epoch);
516 let output = FrameOutput::display(texture, view, image);
517 let draw = |packet, returns: &mut RenderReturns| {
518 gpu_renderer.render(submit, (width, height), packet, epochs.1, returns, output)
519 };
520 self.frontend
521 .draw_window((width, height), epochs, image, draw)
522 .ok_or_else(|| WgpuRendererError::Wgpu("scene graph is missing".to_string()))?
523 .map_err(WgpuRendererError::Wgpu)
524 }
525
526 pub fn shows_scene(&mut self, width: u32, height: u32) -> bool {
533 self.frontend.landings = self.landings();
534 let PresentBackend::Sync(sync) = &mut self.backend else {
535 return false;
536 };
537 let Some(packet) =
538 self.frontend
539 .take_packet(width, height, self.renderer_epoch, self.surface_epoch)
540 else {
541 return false;
542 };
543 let shown = sync.renderer.shows(&packet, (width, height));
544 if shown {
545 self.frontend.recycle(packet);
546 } else {
547 self.frontend.keep_packet(packet);
548 }
549 shown
550 }
551
552 pub fn capture_frame(
556 &mut self,
557 width: u32,
558 height: u32,
559 ) -> Result<CapturedFrame, WgpuRendererError> {
560 self.capture_frame_with_scale(width, height, self.frontend.root_scale)
561 }
562
563 #[cfg(not(target_arch = "wasm32"))]
571 pub fn prepare_recorded_pipelines(
572 &mut self,
573 timeout: std::time::Duration,
574 stop: &dyn Fn() -> bool,
575 ) -> bool {
576 let PresentBackend::Sync(sync) = &mut self.backend else {
577 return false;
578 };
579 let gpu_renderer = &mut sync.renderer;
580 let deadline = web_time::Instant::now() + timeout;
581 let mut compiling = gpu_renderer.prepare_recorded();
582 while compiling {
583 if web_time::Instant::now() >= deadline || stop() {
584 return false;
585 }
586 std::thread::sleep(std::time::Duration::from_millis(10));
587 compiling = gpu_renderer.pipelines.compiling();
588 }
589 true
590 }
591
592 pub fn capture_frame_with_scale(
597 &mut self,
598 width: u32,
599 height: u32,
600 root_scale: f32,
601 ) -> Result<CapturedFrame, WgpuRendererError> {
602 let SyncPresenter {
603 renderer: gpu_renderer,
604 submit,
605 } = self.backend.sync_mut()?;
606 let packet = self
607 .frontend
608 .build_frame_packet_with_scale(
609 (width, height, root_scale),
610 self.renderer_epoch,
611 self.surface_epoch,
612 frontend::PacketFor::Capture,
613 )
614 .ok_or_else(|| WgpuRendererError::Wgpu("scene graph is missing".to_string()))?;
615 let mut returns = RenderReturns::default();
616 let result = gpu_renderer.render_to_rgba_pixels(
617 submit,
618 (width, height),
619 packet,
620 self.surface_epoch,
621 &mut returns,
622 );
623 self.frontend.apply_returns(returns);
624 let pixels = result.map_err(WgpuRendererError::Wgpu)?;
625 Ok(CapturedFrame {
626 width,
627 height,
628 pixels,
629 stats: gpu_renderer.last_frame_stats(),
630 })
631 }
632
633 #[cfg(not(target_arch = "wasm32"))]
639 pub fn has_frame_credit(&self) -> bool {
640 match &self.backend {
641 PresentBackend::Threaded(handle) => handle.has_credit(),
642 PresentBackend::Sync(_) | PresentBackend::None => true,
643 }
644 }
645
646 #[cfg(not(target_arch = "wasm32"))]
652 pub fn frame_credit_returned(&self) -> bool {
653 match &self.backend {
654 PresentBackend::Threaded(handle) => handle.has_undrained_return(),
655 PresentBackend::Sync(_) | PresentBackend::None => false,
656 }
657 }
658
659 #[cfg(not(target_arch = "wasm32"))]
665 pub fn publish_frame(&mut self, width: u32, height: u32) -> PublishOutcome {
666 self.frontend.landings = self.landings();
667 let PresentBackend::Threaded(handle) = &mut self.backend else {
668 log::error!("publish_frame called without a threaded present runtime");
669 return PublishOutcome::NoCredit;
670 };
671 if !handle.has_credit() {
672 return PublishOutcome::NoCredit;
673 }
674 let Some(packet) = self.frontend.build_frame_packet(
675 width,
676 height,
677 self.renderer_epoch,
678 self.surface_epoch,
679 ) else {
680 return PublishOutcome::NoGraph;
681 };
682 match handle.publish(packet) {
683 Ok(()) => PublishOutcome::Published,
684 Err(packet) => {
685 let mut returns = RenderReturns::default();
686 GpuRenderer::cancel_packet(*packet, CancelReason::SurfaceUnavailable, &mut returns);
687 self.frontend.apply_returns(returns);
688 log::error!("present runtime unavailable; frame recovered, not published");
689 PublishOutcome::NoCredit
690 }
691 }
692 }
693
694 #[cfg(not(target_arch = "wasm32"))]
698 pub fn drain_present_returns(&mut self) -> usize {
699 self.drain_present_returns_with(&mut |_, _, _| {})
700 }
701
702 #[cfg(not(target_arch = "wasm32"))]
706 pub fn drain_present_returns_with(
707 &mut self,
708 on_return: &mut dyn FnMut(u64, PresentOutcome, PresentTimings),
709 ) -> usize {
710 let mut drained = 0;
711 loop {
712 let returns = {
713 let PresentBackend::Threaded(handle) = &mut self.backend else {
714 break;
715 };
716 match handle.try_drain() {
717 Some(returns) => returns,
718 None => break,
719 }
720 };
721 drained += 1;
722 let frame_id = returns.frame_id;
723 let outcome = returns.outcome;
724 let timings = returns.timings;
725 self.frontend.apply_returns(returns);
726 on_return(frame_id, outcome, timings);
727 }
728 drained
729 }
730
731 #[cfg(not(target_arch = "wasm32"))]
735 pub fn present_thread(&mut self) -> Option<PresentThread<'_>> {
736 let PresentBackend::Threaded(handle) = &mut self.backend else {
737 return None;
738 };
739 Some(PresentThread {
740 handle,
741 surface_epoch: &mut self.surface_epoch,
742 })
743 }
744
745 #[cfg(not(target_arch = "wasm32"))]
748 pub fn shutdown_present_runtime(&mut self) {
749 if matches!(self.backend, PresentBackend::Threaded(_)) {
750 self.retire_live_backend();
751 }
752 }
753
754 pub fn present_thread_id(&self) -> Option<i32> {
758 match &self.backend {
759 #[cfg(not(target_arch = "wasm32"))]
760 PresentBackend::Threaded(handle) => {
761 let id = handle
762 .status()
763 .thread_id
764 .load(std::sync::atomic::Ordering::Relaxed);
765 (id != 0).then_some(id)
766 }
767 _ => None,
768 }
769 }
770
771 pub fn last_published_frame_id(&self) -> u64 {
776 self.frontend.frame_sequence
777 }
778
779 pub fn last_frame_stats(&self) -> Option<RenderStatsSnapshot> {
781 match &self.backend {
782 PresentBackend::Sync(sync) => sync.renderer.last_frame_stats(),
783 #[cfg(not(target_arch = "wasm32"))]
784 PresentBackend::Threaded(handle) => *handle
785 .status()
786 .last_frame_stats
787 .lock()
788 .unwrap_or_else(std::sync::PoisonError::into_inner),
789 PresentBackend::None => None,
790 }
791 }
792
793 #[cfg(not(target_arch = "wasm32"))]
799 pub fn first_screen_recorded(&self) -> bool {
800 self.sync_gpu_renderer()
801 .is_some_and(GpuRenderer::first_screen_recorded)
802 }
803
804 pub fn first_screen_pipelines(&self) -> Option<Vec<u8>> {
810 self.sync_gpu_renderer()
811 .and_then(|renderer| renderer.pipelines.first_screen_pipelines())
812 }
813
814 pub fn build_first_screen_pipelines(&mut self, records: &[u8], viewport: (u32, u32)) {
825 if let PresentBackend::Sync(sync) = &mut self.backend {
826 sync.renderer.build_first_screen(records, viewport);
827 }
828 }
829
830 pub fn gpu_pass_timings(&self) -> GpuPassTimingReport {
834 match &self.backend {
835 PresentBackend::Sync(sync) => sync.submit.executor.pass_timing_report(),
836 _ => GpuPassTimingReport::default(),
837 }
838 }
839
840 pub fn debug_cpu_allocation_stats(&self) -> DebugCpuAllocationStats {
844 let mut stats = self
845 .sync_gpu_renderer()
846 .map_or_default(GpuRenderer::debug_cpu_allocation_stats);
847 stats.scene_graph_node_count = self.frontend.scene.store().node_count();
848 stats.scene_graph_heap_bytes = self.frontend.scene.store().heap_bytes();
849 stats.scene_hits = self.frontend.scene.hit_storage();
850 stats
851 }
852
853 #[cfg(target_arch = "wasm32")]
857 pub fn begin_first_frame(&self) {
858 if let Some(gpu_renderer) = self.sync_gpu_renderer() {
859 gpu_renderer.pipelines.compiler.begin_first_frame();
860 }
861 }
862
863 #[cfg(target_arch = "wasm32")]
868 pub fn background_pipelines_landed(&mut self) {
869 if let PresentBackend::Sync(sync) = &mut self.backend {
870 sync.renderer.background_pipelines_landed();
871 }
872 }
873
874 pub fn compile_pipelines_in_background(&mut self) {
881 if let PresentBackend::Sync(sync) = &mut self.backend {
882 sync.renderer.pipelines.compile_pipelines_in_background();
883 }
884 }
885
886 pub fn try_device(&self) -> Option<&wgpu::Device> {
890 self.sync_gpu_renderer().map(|r| &*r.device)
891 }
892
893 #[doc(hidden)]
894 pub fn try_queue_for_tests(&self) -> Option<&wgpu::Queue> {
895 self.sync_gpu_renderer().map(|r| &*r.queue)
896 }
897
898 #[doc(hidden)]
899 pub fn device_error_count_for_tests(&self) -> u64 {
900 self.sync_gpu_renderer()
901 .map_or(0, GpuRenderer::device_error_count)
902 }
903
904 #[doc(hidden)]
905 pub fn build_frame_packet_for_tests(
906 &mut self,
907 width: u32,
908 height: u32,
909 ) -> Option<HeldFramePacket> {
910 self.frontend.landings = self.landings();
911 self.frontend
912 .build_frame_packet(width, height, self.renderer_epoch, self.surface_epoch)
913 .map(HeldFramePacket)
914 }
915
916 fn landings(&mut self) -> Option<u64> {
919 match &mut self.backend {
920 PresentBackend::Sync(sync) => Some(sync.renderer.pipelines.count_landings()),
921 #[cfg(not(target_arch = "wasm32"))]
922 PresentBackend::Threaded(handle) => {
923 handle.status().landing.get().map(|landing| landing.built())
924 }
925 PresentBackend::None => None,
926 }
927 }
928
929 #[doc(hidden)]
942 pub fn return_held_packet_for_tests(&mut self, packet: HeldFramePacket) {
943 self.frontend
944 .apply_returns(RenderReturns::drawn_in_place(packet.0));
945 }
946
947 #[doc(hidden)]
948 pub fn render_held_packet_for_tests(
949 &mut self,
950 texture: &wgpu::Texture,
951 view: &wgpu::TextureView,
952 width: u32,
953 height: u32,
954 packet: HeldFramePacket,
955 ) -> Result<PresentOutcome, WgpuRendererError> {
956 let SyncPresenter {
957 renderer: gpu_renderer,
958 submit,
959 } = self.backend.sync_mut()?;
960 let mut returns = RenderReturns::default();
961 let result = gpu_renderer.render(
962 submit,
963 (width, height),
964 packet.0,
965 self.surface_epoch,
966 &mut returns,
967 FrameOutput::display(texture, view, frame::ImageContent::Untracked),
968 );
969 let outcome = returns.outcome;
970 self.frontend.apply_returns(returns);
971 result.map_err(WgpuRendererError::Wgpu)?;
972 Ok(outcome)
973 }
974}
975
976#[doc(hidden)]
977pub struct HeldFramePacket(frame_packet::FramePacket);
978
979impl Default for WgpuRenderer {
980 fn default() -> Self {
981 Self::new(&[])
982 }
983}
984
985#[cfg(test)]
986#[path = "tests/wgpu_tests.rs"]
987mod tests;