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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
//! Backend trait and error types.
use crateColor;
use crateSceneBuilder;
/// Owns backend resources (GPU device, pipelines, etc.) and rasterizes a scene
/// to an RGBA8 buffer.
///
/// `SceneBuilder` is the authoring surface; this trait is the "produce output"
/// step. Split into two traits because authoring is pure CPU/infallible and
/// rasterization is fallible/resource-owning — and the recording backend only
/// needs `SceneBuilder`.
/// Optional extension for wgpu-backed renderers: rasterise directly into a
/// host-owned texture, bypassing the CPU readback that
/// [`Renderer::render_to_buffer`] uses.
///
/// This is the path for showing a scene in a window. A host that owns its own
/// wgpu device, queue, and presentation surface constructs the backend with a
/// `with_device`-style constructor so all GPU work shares a single device,
/// then calls [`render_to_texture`](Self::render_to_texture) each frame. The
/// `window` feature is this crate's own implementation of that host; see
/// [`crate::window`].
///
/// **Target constraints.** The supplied `view` must wrap a texture with
/// format `Rgba8Unorm` and usage including [`Self::REQUIRED_TARGET_USAGE`],
/// which the backend states because backends differ: a compute-shader
/// rasteriser writes through `STORAGE_BINDING`, a render-pipeline one needs
/// `RENDER_ATTACHMENT`. Either way a swap-chain texture cannot serve as the
/// direct target, since it carries neither the right format nor, for the
/// compute path, the right usage. Whatever the host does with the result adds
/// its own flag: `TEXTURE_BINDING` to blit the view onto a surface,
/// `COPY_SRC` to copy it back. Hosts whose presentation surface uses a
/// different format (typical for swap chains) are responsible for blitting
/// from this view to the surface.
///
/// **Alpha.** Which convention the view receives is backend-defined and
/// stated by [`Self::TARGET_IS_PREMULTIPLIED`]; unlike
/// [`Renderer::render_to_buffer`], this path does not normalise it. A host
/// presenting translucent content, or blending the view through a SrcOver
/// pipeline, has to consult that flag and convert in its blit shader. Opaque
/// content is unaffected — the two conventions coincide at alpha 255.
///
/// **Picking.** Picking (when enabled at construction) still rasterises the
/// parallel pick scene into the backend's own pick target and reads it back
/// to CPU, so [`pick_at`](crate::backend::vello::VelloRenderer::pick_at)
/// remains valid after a `render_to_texture` call.