1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use crate::{
frame_graph::{WgpuFrameGraph, WgpuFrameGraphExecutor},
render::CLEAR_COLOR,
};
/// Clears `view` to the framework's default background; see
/// [`clear_to_background`].
pub fn clear_to_default_background(
device: &wgpu::Device,
queue: &wgpu::Queue,
view: &wgpu::TextureView,
) {
clear_to_background(device, queue, view, CLEAR_COLOR);
}
/// Clears `view` to `color` and submits the
/// work, through the same `WgpuFrameGraph` every other command encoder
/// and submission in this crate is required to go through (enforced by
/// `render_contract.rs`'s `wgpu_command_buffers_are_owned_by_frame_graph_executor`)
/// — a fresh, one-shot `WgpuFrameGraphExecutor`, since a placeholder
/// clear has no frame-to-frame state worth pooling. Does not present or
/// acquire anything itself — callers that mean to show the clear on
/// screen still acquire a frame and call `wgpu::SurfaceTexture::present`
/// themselves, exactly as a real content frame would.
pub fn clear_to_background(
device: &wgpu::Device,
queue: &wgpu::Queue,
view: &wgpu::TextureView,
color: wgpu::Color,
) {
let mut graph = WgpuFrameGraph::new(Some("Cranpose Initial Present Clear"));
let target = graph.import_surface("initial-present-clear-target");
graph.add_fallible_command_pass(Some("Initial Present Clear"), &[], &[target], |context| {
let _pass = context
.encoder
.begin_render_pass(&wgpu::RenderPassDescriptor {
label: Some("Cranpose Initial Present Clear"),
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view,
resolve_target: None,
depth_slice: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Clear(color),
store: wgpu::StoreOp::Store,
},
})],
depth_stencil_attachment: None,
timestamp_writes: None,
occlusion_query_set: None,
multiview_mask: None,
});
Ok(())
});
if let Err(error) = WgpuFrameGraphExecutor::new().execute_recorded_graph(device, queue, graph) {
log::error!("[initial-present] placeholder clear failed: {error:?}");
}
}