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