Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix staging buffer ID allocation mismatch #5309

Merged
merged 2 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 29 additions & 9 deletions wgpu-core/src/command/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,24 +350,44 @@ impl RenderBundleEncoder {
) -> Result<RenderBundle<A>, RenderBundleError> {
let bind_group_guard = hub.bind_groups.read();
let pipeline_guard = hub.render_pipelines.read();
let query_set_guard = hub.query_sets.read();
let buffer_guard = hub.buffers.read();
let texture_guard = hub.textures.read();

let mut state = State {
trackers: RenderBundleScope::new(
&*buffer_guard,
&*texture_guard,
&*bind_group_guard,
&*pipeline_guard,
&*query_set_guard,
),
trackers: RenderBundleScope::new(),
pipeline: None,
bind: (0..hal::MAX_BIND_GROUPS).map(|_| None).collect(),
vertex: (0..hal::MAX_VERTEX_BUFFERS).map(|_| None).collect(),
index: None,
flat_dynamic_offsets: Vec::new(),
};

let indices = &device.tracker_indices;
state
.trackers
.buffers
.write()
.set_size(indices.buffers.size());
state
.trackers
.textures
.write()
.set_size(indices.textures.size());
state
.trackers
.bind_groups
.write()
.set_size(indices.bind_groups.size());
state
.trackers
.render_pipelines
.write()
.set_size(indices.render_pipelines.size());
state
.trackers
.query_sets
.write()
.set_size(indices.query_sets.size());

let mut commands = Vec::new();
let mut buffer_memory_init_actions = Vec::new();
let mut texture_memory_init_actions = Vec::new();
Expand Down
6 changes: 1 addition & 5 deletions wgpu-core/src/device/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ impl Global {
mapped_at_creation: false,
};
let stage = match device.create_buffer(&stage_desc, true) {
Ok(stage) => stage,
Ok(stage) => Arc::new(stage),
Err(e) => {
to_destroy.push(buffer);
break e;
Expand All @@ -230,14 +230,10 @@ impl Global {
Ok(mapping) => mapping,
Err(e) => {
to_destroy.push(buffer);
to_destroy.push(stage);
break CreateBufferError::Device(e.into());
}
};

let stage_fid = hub.buffers.request();
let stage = stage_fid.init(stage);

assert_eq!(buffer.size % wgt::COPY_BUFFER_ALIGNMENT, 0);
// Zero initialize memory and then mark both staging and buffer as initialized
// (it's guaranteed that this is the case by the time the buffer is usable)
Expand Down
24 changes: 3 additions & 21 deletions wgpu-core/src/track/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ mod texture;

use crate::{
binding_model, command, conv, hal_api::HalApi, id, pipeline, resource, snatch::SnatchGuard,
storage::Storage,
};

use parking_lot::{Mutex, RwLock};
Expand Down Expand Up @@ -479,31 +478,14 @@ pub(crate) struct RenderBundleScope<A: HalApi> {

impl<A: HalApi> RenderBundleScope<A> {
/// Create the render bundle scope and pull the maximum IDs from the hubs.
pub fn new(
buffers: &Storage<resource::Buffer<A>>,
textures: &Storage<resource::Texture<A>>,
bind_groups: &Storage<binding_model::BindGroup<A>>,
render_pipelines: &Storage<pipeline::RenderPipeline<A>>,
query_sets: &Storage<resource::QuerySet<A>>,
) -> Self {
let value = Self {
pub fn new() -> Self {
Self {
buffers: RwLock::new(BufferUsageScope::new()),
textures: RwLock::new(TextureUsageScope::new()),
bind_groups: RwLock::new(StatelessTracker::new()),
render_pipelines: RwLock::new(StatelessTracker::new()),
query_sets: RwLock::new(StatelessTracker::new()),
};

value.buffers.write().set_size(buffers.len());
value.textures.write().set_size(textures.len());
value.bind_groups.write().set_size(bind_groups.len());
value
.render_pipelines
.write()
.set_size(render_pipelines.len());
value.query_sets.write().set_size(query_sets.len());

value
}
}

/// Merge the inner contents of a bind group into the render bundle tracker.
Expand Down
Loading