Skip to content

Commit 7aa5753

Browse files
committed
Re-architecture the bundles using normalized command streams.
This is a major change in how the bundles are implemented. Instead of transparently injecting them into the pass command stream, we are now treating bundles as first-class API objects and API tracing them accordingly. The bundle contains a normalized command stream that is very easy to inject into a native command buffer multiple times.
1 parent afc4517 commit 7aa5753

File tree

13 files changed

+907
-231
lines changed

13 files changed

+907
-231
lines changed

player/src/main.rs

+30-24
Original file line numberDiff line numberDiff line change
@@ -143,19 +143,8 @@ impl GlobalExt for wgc::hub::Global<IdentityPassThroughFactory> {
143143
commands,
144144
dynamic_offsets,
145145
} => unsafe {
146-
let mut offsets = &dynamic_offsets[..];
147146
let mut pass = wgc::command::RawPass::new_compute(encoder);
148-
for com in commands {
149-
pass.encode(&com);
150-
if let wgc::command::ComputeCommand::SetBindGroup {
151-
num_dynamic_offsets,
152-
..
153-
} = com
154-
{
155-
pass.encode_slice(&offsets[..num_dynamic_offsets as usize]);
156-
offsets = &offsets[num_dynamic_offsets as usize..];
157-
}
158-
}
147+
pass.fill_compute_commands(&commands, &dynamic_offsets);
159148
let (data, _) = pass.finish_compute();
160149
self.command_encoder_run_compute_pass::<B>(encoder, &data);
161150
},
@@ -165,7 +154,6 @@ impl GlobalExt for wgc::hub::Global<IdentityPassThroughFactory> {
165154
commands,
166155
dynamic_offsets,
167156
} => unsafe {
168-
let mut offsets = &dynamic_offsets[..];
169157
let mut pass = wgc::command::RawPass::new_render(
170158
encoder,
171159
&wgc::command::RenderPassDescriptor {
@@ -174,17 +162,7 @@ impl GlobalExt for wgc::hub::Global<IdentityPassThroughFactory> {
174162
depth_stencil_attachment: target_depth_stencil.as_ref(),
175163
},
176164
);
177-
for com in commands {
178-
pass.encode(&com);
179-
if let wgc::command::RenderCommand::SetBindGroup {
180-
num_dynamic_offsets,
181-
..
182-
} = com
183-
{
184-
pass.encode_slice(&offsets[..num_dynamic_offsets as usize]);
185-
offsets = &offsets[num_dynamic_offsets as usize..];
186-
}
187-
}
165+
pass.fill_render_commands(&commands, &dynamic_offsets);
188166
let (data, _) = pass.finish_render();
189167
self.command_encoder_run_render_pass::<B>(encoder, &data);
190168
},
@@ -408,6 +386,34 @@ impl GlobalExt for wgc::hub::Global<IdentityPassThroughFactory> {
408386
A::DestroyRenderPipeline(id) => {
409387
self.render_pipeline_destroy::<B>(id);
410388
}
389+
A::CreateRenderBundle {
390+
id,
391+
desc,
392+
commands,
393+
dynamic_offsets,
394+
} => {
395+
let label = Label::new(&desc.label);
396+
let mut bundle_encoder = wgc::command::RenderBundleEncoder::new(
397+
&wgt::RenderBundleEncoderDescriptor {
398+
label: None,
399+
color_formats: &desc.color_formats,
400+
depth_stencil_format: desc.depth_stencil_format,
401+
sample_count: desc.sample_count,
402+
},
403+
device,
404+
);
405+
bundle_encoder.fill_commands(&commands, &dynamic_offsets);
406+
self.render_bundle_encoder_finish::<B>(
407+
bundle_encoder,
408+
&wgt::RenderBundleDescriptor {
409+
label: label.as_ptr(),
410+
},
411+
id,
412+
);
413+
}
414+
A::DestroyRenderBundle(id) => {
415+
self.render_bundle_destroy::<B>(id);
416+
}
411417
A::WriteBuffer {
412418
id,
413419
data,

wgpu-core/src/command/bind.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@ use crate::{
66
binding_model::BindGroup,
77
hub::GfxBackend,
88
id::{BindGroupId, BindGroupLayoutId, PipelineLayoutId},
9-
Stored,
9+
Stored, MAX_BIND_GROUPS,
1010
};
1111

12-
use smallvec::{smallvec, SmallVec};
12+
use arrayvec::ArrayVec;
1313
use std::slice;
1414
use wgt::DynamicOffset;
1515

16-
pub const DEFAULT_BIND_GROUPS: usize = 4;
1716
type BindGroupMask = u8;
1817

1918
#[derive(Clone, Debug)]
@@ -134,14 +133,16 @@ impl BindGroupEntry {
134133
#[derive(Debug)]
135134
pub struct Binder {
136135
pub(crate) pipeline_layout_id: Option<PipelineLayoutId>, //TODO: strongly `Stored`
137-
pub(crate) entries: SmallVec<[BindGroupEntry; DEFAULT_BIND_GROUPS]>,
136+
pub(crate) entries: ArrayVec<[BindGroupEntry; MAX_BIND_GROUPS]>,
138137
}
139138

140139
impl Binder {
141140
pub(crate) fn new(max_bind_groups: u32) -> Self {
142141
Self {
143142
pipeline_layout_id: None,
144-
entries: smallvec![Default::default(); max_bind_groups as usize],
143+
entries: (0..max_bind_groups)
144+
.map(|_| BindGroupEntry::default())
145+
.collect(),
145146
}
146147
}
147148

0 commit comments

Comments
 (0)