wgpu_core/command/encoder.rs
1use alloc::{sync::Arc, vec::Vec};
2
3use crate::{
4 command::memory_init::CommandBufferTextureMemoryActions,
5 device::{queue::TempResource, Device},
6 init_tracker::BufferInitTrackerAction,
7 ray_tracing::AsAction,
8 snatch::SnatchGuard,
9 track::Tracker,
10};
11
12/// State applicable when encoding commands onto a compute pass, render pass, or
13/// directly to a command encoder.
14///
15/// Most encoding routines just want to receive an open encoder, write
16/// command(s) to it, and leave it open for whatever is next. In this case the
17/// `E` type parameter has the default value of `dyn hal::DynCommandEncoder`. To
18/// avoid confusion about encoder state, we set the convention that _the encoder
19/// in an `EncodingState` holding a bare HAL reference must always be open_.
20///
21/// Compute and render passes are more complicated. Because they record a
22/// command buffer for a housekeeping pre-pass which is inserted before the pass
23/// itself, the first thing they will do is close and reopen the encoder if it
24/// is already open. Unnecessary empty HAL passes can be avoided by passing them
25/// the encoder in whatever state it happens to be. In this case, `E` is
26/// `InnerCommandEncoder`, which tracks the state of the encoder. The callee
27/// (the render or compute pass) will open and close the encoder as necessary.
28///
29/// This structure is not supported by cbindgen because it contains a trait
30/// object reference.
31///
32/// cbindgen:ignore
33pub(crate) struct EncodingState<'snatch_guard, 'cmd_enc, E: ?Sized = dyn hal::DynCommandEncoder> {
34 pub(crate) device: &'cmd_enc Arc<Device>,
35
36 pub(crate) raw_encoder: &'cmd_enc mut E,
37
38 pub(crate) tracker: &'cmd_enc mut Tracker,
39 pub(crate) buffer_memory_init_actions: &'cmd_enc mut Vec<BufferInitTrackerAction>,
40 pub(crate) texture_memory_actions: &'cmd_enc mut CommandBufferTextureMemoryActions,
41 pub(crate) as_actions: &'cmd_enc mut Vec<AsAction>,
42 pub(crate) temp_resources: &'cmd_enc mut Vec<TempResource>,
43 pub(crate) indirect_draw_validation_resources:
44 &'cmd_enc mut crate::indirect_validation::DrawResources,
45
46 pub(crate) snatch_guard: &'snatch_guard SnatchGuard<'snatch_guard>,
47
48 /// Current debug scope nesting depth.
49 ///
50 /// When encoding a compute or render pass, this is the depth of debug
51 /// scopes in the pass, not the depth of debug scopes in the parent encoder.
52 pub(crate) debug_scope_depth: &'cmd_enc mut u32,
53}