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
146
147
148
149
150
151
152
153
154
155
156
157
//! Command recording traits.
//!
//! Pass encoders borrow the command encoder for their lifetime (generic
//! associated types), matching how every modern API scopes a pass.
use crate::descriptors::{ComputePassDesc, RenderPassDesc};
use crate::device::{Device, RayQueryDevice};
use crate::{BlasBuildDesc, GpuError, PassTimestampCapture};
use std::ops::Range;
/// Records passes and copies into one submission.
pub trait CommandEncoder<D: Device>: Sized {
/// The recording handle of an open render pass.
type RenderPass<'e>: RenderPassEncoder<D>
where
Self: 'e;
/// The recording handle of an open compute pass.
type ComputePass<'e>: ComputePassEncoder<D>
where
Self: 'e;
/// Installs opt-in capture or takes it back with None.
/// The previous capture retains its query resource and preallocated metadata.
/// Disabled recording does not allocate or collect pass metadata.
fn set_timestamp_capture(
&mut self,
capture: Option<PassTimestampCapture<D::QuerySet>>,
) -> Option<PassTimestampCapture<D::QuerySet>>;
/// Tags subsequent actual pass occurrences when capture is enabled.
fn set_timestamp_sample(&mut self, sample: Option<u32>);
/// Begins a render pass over the given attachments.
fn begin_render_pass<'e>(&'e mut self, desc: &RenderPassDesc<'_, D>) -> Self::RenderPass<'e>;
/// Begins a compute pass.
fn begin_compute_pass<'e>(&'e mut self, desc: &ComputePassDesc<'_, D>)
-> Self::ComputePass<'e>;
/// GPU-to-GPU buffer copy; how indirect-argument templates reset
/// per-frame counts without a host write.
fn copy_buffer_to_buffer(
&mut self,
src: &D::Buffer,
src_offset: u64,
dst: &D::Buffer,
dst_offset: u64,
size: u64,
);
/// Copies one texture's contents into a buffer, tightly packed rows.
/// Off the frame path except for picking's few-texel read.
fn copy_texture_to_buffer(
&mut self,
src: &D::Texture,
origin: (u32, u32),
size: (u32, u32),
bytes_per_row: u32,
destination_offset: u64,
dst: &D::Buffer,
);
/// GPU-to-GPU copy of the whole of one texture's first mip into another of
/// the same format and size.
fn copy_texture_to_texture(&mut self, src: &D::Texture, dst: &D::Texture, size: (u32, u32));
/// Resolves query values into a GPU buffer for later copy/readback.
fn resolve_query_set(
&mut self,
queries: &D::QuerySet,
range: Range<u32>,
dst: &D::Buffer,
offset: u64,
);
/// Records one BLAS build.
///
/// # Errors
///
/// Returns a capability, validation or backend recording failure.
fn build_blas(&mut self, _desc: &BlasBuildDesc<'_, D>) -> Result<(), GpuError> {
Err(GpuError::Capability { name: "ray query" })
}
/// Records one TLAS build.
///
/// # Errors
///
/// Returns a capability, validation or backend recording failure.
fn build_tlas(&mut self, _tlas: &D::Tlas) -> Result<(), GpuError> {
Err(GpuError::Capability { name: "ray query" })
}
}
/// Command-encoder extension for acceleration-structure builds.
pub trait RayQueryCommandEncoder<D: RayQueryDevice>: CommandEncoder<D> {
/// Records one BLAS build.
///
/// # Errors
///
/// Returns capability, validation or backend recording failures.
fn build_blas(&mut self, desc: &BlasBuildDesc<'_, D>) -> Result<(), GpuError> {
CommandEncoder::build_blas(self, desc)
}
/// Records one TLAS build after its referenced BLAS builds.
///
/// # Errors
///
/// Returns capability, validation or backend recording failures.
fn build_tlas(&mut self, tlas: &D::Tlas) -> Result<(), GpuError> {
CommandEncoder::build_tlas(self, tlas)
}
}
impl<D, E> RayQueryCommandEncoder<D> for E
where
D: RayQueryDevice,
E: CommandEncoder<D>,
{
}
/// Records draws inside an open render pass.
pub trait RenderPassEncoder<D: Device> {
/// Sets the active pipeline.
fn set_pipeline(&mut self, pipeline: &D::Pipeline);
/// Binds a group at an index (0 frame / 1 pass / 2 representation /
/// 3 material), with dynamic offsets where the layout declared them.
fn set_bind_group(&mut self, index: u32, group: &D::BindGroup, dynamic_offsets: &[u32]);
/// Binds the complete index buffer for subsequent indexed draws.
fn set_index_buffer(&mut self, indices: &D::Buffer, format: crate::IndexFormat);
/// Records an indexed draw from the five-field indirect argument record.
fn draw_indexed_indirect(&mut self, args: &D::Buffer, offset: u64);
/// Direct draw; used only for fullscreen passes whose vertex count is a
/// constant, never per scene primitive.
fn draw(&mut self, vertices: Range<u32>, instances: Range<u32>);
/// Indirect draw against arguments a compute pass wrote; the only draw
/// the scene-geometry path uses.
fn draw_indirect(&mut self, args: &D::Buffer, offset: u64);
}
/// Records dispatches inside an open compute pass.
pub trait ComputePassEncoder<D: Device> {
/// Sets the active pipeline.
fn set_pipeline(&mut self, pipeline: &D::Pipeline);
/// Binds a group at an index.
fn set_bind_group(&mut self, index: u32, group: &D::BindGroup, dynamic_offsets: &[u32]);
/// Dispatches workgroups.
fn dispatch(&mut self, x: u32, y: u32, z: u32);
}