Skip to content
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
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion wgpu-core-remote/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,5 @@ serde = ["dep:serde", "wgpu-types/serde", "wgpu-core/serde"]
wgpu-core = { workspace = true, default-features = false }
wgpu-hal = { workspace = true, default-features = false }
wgpu-types.workspace = true
parking_lot.workspace = true
raw-window-handle.workspace = true
serde = { workspace = true, optional = true }
72 changes: 12 additions & 60 deletions wgpu-core-remote/src/global/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ impl crate::global::Global {
bind_group_id: Option<id::BindGroupId>,
offsets: &[wgt::DynamicOffset],
) -> Result<(), PassStateError> {
let bundle_encoder = self.hub.render_bundle_encoders.get(bundle_encoder);

let mut bundle_encoder = bundle_encoder
.try_lock()
.expect("RenderBundleEncoders should not be accessed concurrently");
let mut bundle_encoder = self.hub.render_bundle_encoders.get_mut(bundle_encoder);

bundle_encoder.set_bind_group(
index,
Expand All @@ -27,11 +23,7 @@ impl crate::global::Global {
bundle_encoder: id::RenderBundleEncoderId,
pipeline_id: id::RenderPipelineId,
) -> Result<(), PassStateError> {
let bundle_encoder = self.hub.render_bundle_encoders.get(bundle_encoder);

let mut bundle_encoder = bundle_encoder
.try_lock()
.expect("RenderBundleEncoders should not be accessed concurrently");
let mut bundle_encoder = self.hub.render_bundle_encoders.get_mut(bundle_encoder);

bundle_encoder.set_pipeline(self.hub.render_pipelines.get(pipeline_id))
}
Expand All @@ -44,11 +36,7 @@ impl crate::global::Global {
offset: wgt::BufferAddress,
size: Option<wgt::BufferSize>,
) -> Result<(), PassStateError> {
let bundle_encoder = self.hub.render_bundle_encoders.get(bundle_encoder);

let mut bundle_encoder = bundle_encoder
.try_lock()
.expect("RenderBundleEncoders should not be accessed concurrently");
let mut bundle_encoder = self.hub.render_bundle_encoders.get_mut(bundle_encoder);

bundle_encoder.set_vertex_buffer(
slot,
Expand All @@ -66,11 +54,7 @@ impl crate::global::Global {
offset: wgt::BufferAddress,
size: Option<wgt::BufferSize>,
) -> Result<(), PassStateError> {
let bundle_encoder = self.hub.render_bundle_encoders.get(bundle_encoder);

let mut bundle_encoder = bundle_encoder
.try_lock()
.expect("RenderBundleEncoders should not be accessed concurrently");
let mut bundle_encoder = self.hub.render_bundle_encoders.get_mut(bundle_encoder);

bundle_encoder.set_index_buffer(self.hub.buffers.get(buffer), index_format, offset, size)
}
Expand All @@ -81,11 +65,7 @@ impl crate::global::Global {
offset: u32,
data: &[u8],
) -> Result<(), PassStateError> {
let bundle_encoder = self.hub.render_bundle_encoders.get(bundle_encoder);

let mut bundle_encoder = bundle_encoder
.try_lock()
.expect("RenderBundleEncoders should not be accessed concurrently");
let mut bundle_encoder = self.hub.render_bundle_encoders.get_mut(bundle_encoder);

bundle_encoder.set_immediates(offset, data)
}
Expand All @@ -98,11 +78,7 @@ impl crate::global::Global {
first_vertex: u32,
first_instance: u32,
) -> Result<(), PassStateError> {
let bundle_encoder = self.hub.render_bundle_encoders.get(bundle_encoder);

let mut bundle_encoder = bundle_encoder
.try_lock()
.expect("RenderBundleEncoders should not be accessed concurrently");
let mut bundle_encoder = self.hub.render_bundle_encoders.get_mut(bundle_encoder);

bundle_encoder.draw(vertex_count, instance_count, first_vertex, first_instance)
}
Expand All @@ -116,11 +92,7 @@ impl crate::global::Global {
base_vertex: i32,
first_instance: u32,
) -> Result<(), PassStateError> {
let bundle_encoder = self.hub.render_bundle_encoders.get(bundle_encoder);

let mut bundle_encoder = bundle_encoder
.try_lock()
.expect("RenderBundleEncoders should not be accessed concurrently");
let mut bundle_encoder = self.hub.render_bundle_encoders.get_mut(bundle_encoder);

bundle_encoder.draw_indexed(
index_count,
Expand All @@ -137,11 +109,7 @@ impl crate::global::Global {
buffer_id: id::BufferId,
offset: wgt::BufferAddress,
) -> Result<(), PassStateError> {
let bundle_encoder = self.hub.render_bundle_encoders.get(bundle_encoder);

let mut bundle_encoder = bundle_encoder
.try_lock()
.expect("RenderBundleEncoders should not be accessed concurrently");
let mut bundle_encoder = self.hub.render_bundle_encoders.get_mut(bundle_encoder);

bundle_encoder.draw_indirect(self.hub.buffers.get(buffer_id), offset)
}
Expand All @@ -152,11 +120,7 @@ impl crate::global::Global {
buffer_id: id::BufferId,
offset: wgt::BufferAddress,
) -> Result<(), PassStateError> {
let bundle_encoder = self.hub.render_bundle_encoders.get(bundle_encoder);

let mut bundle_encoder = bundle_encoder
.try_lock()
.expect("RenderBundleEncoders should not be accessed concurrently");
let mut bundle_encoder = self.hub.render_bundle_encoders.get_mut(bundle_encoder);

bundle_encoder.draw_indexed_indirect(self.hub.buffers.get(buffer_id), offset)
}
Expand All @@ -166,11 +130,7 @@ impl crate::global::Global {
bundle_encoder: id::RenderBundleEncoderId,
label: &str,
) -> Result<(), PassStateError> {
let bundle_encoder = self.hub.render_bundle_encoders.get(bundle_encoder);

let mut bundle_encoder = bundle_encoder
.try_lock()
.expect("RenderBundleEncoders should not be accessed concurrently");
let mut bundle_encoder = self.hub.render_bundle_encoders.get_mut(bundle_encoder);

bundle_encoder.push_debug_group(label)
}
Expand All @@ -179,11 +139,7 @@ impl crate::global::Global {
&self,
bundle_encoder: id::RenderBundleEncoderId,
) -> Result<(), PassStateError> {
let bundle_encoder = self.hub.render_bundle_encoders.get(bundle_encoder);

let mut bundle_encoder = bundle_encoder
.try_lock()
.expect("RenderBundleEncoders should not be accessed concurrently");
let mut bundle_encoder = self.hub.render_bundle_encoders.get_mut(bundle_encoder);

bundle_encoder.pop_debug_group()
}
Expand All @@ -193,11 +149,7 @@ impl crate::global::Global {
bundle_encoder: id::RenderBundleEncoderId,
label: &str,
) -> Result<(), PassStateError> {
let bundle_encoder = self.hub.render_bundle_encoders.get(bundle_encoder);

let mut bundle_encoder = bundle_encoder
.try_lock()
.expect("RenderBundleEncoders should not be accessed concurrently");
let mut bundle_encoder = self.hub.render_bundle_encoders.get_mut(bundle_encoder);

bundle_encoder.insert_debug_marker(label)
}
Expand Down
2 changes: 1 addition & 1 deletion wgpu-core-remote/src/global/command_encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl Global {
&self,
encoder_id: CommandEncoderId,
desc: &wgt::CommandBufferDescriptor<Label>,
id_in: Option<id::CommandBufferId>,
id_in: id::CommandBufferId,
) -> (id::CommandBufferId, Option<(String, CommandEncoderError)>) {
let hub = &self.hub;
let cmd_enc = hub.command_encoders.get(encoder_id);
Expand Down
70 changes: 14 additions & 56 deletions wgpu-core-remote/src/global/compute_pass.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use alloc::sync::Arc;

use alloc::borrow::Cow;

use parking_lot::Mutex;
use wgpu_core::command::{
CommandEncoderError, ComputePassDescriptor, EncoderStateError, PassStateError,
PassTimestampWrites,
Expand All @@ -27,7 +24,7 @@ impl Global {
&self,
encoder_id: id::CommandEncoderId,
desc: &ComputePassDescriptor<'_, PassTimestampWrites<id::QuerySetId>>,
id_in: Option<id::ComputePassEncoderId>,
id_in: id::ComputePassEncoderId,
) -> (id::ComputePassEncoderId, Option<CommandEncoderError>) {
let fid = self.hub.compute_passes.prepare(id_in);

Expand All @@ -47,10 +44,7 @@ impl Global {

let (pass, err) = cmd_enc.begin_compute_pass(&desc);

// no lock rank here because only one thread should be using compute pass
// and it's only used by id variants of compute pass methods on global
// so no deadlock (or concurrent lock) should happen in practise
let id = fid.assign(Arc::new(Mutex::new(pass)));
let id = fid.assign(pass);

(id, err)
}
Expand All @@ -59,10 +53,7 @@ impl Global {
&self,
pass_id: id::ComputePassEncoderId,
) -> Result<(), EncoderStateError> {
let pass = self.hub.compute_passes.get(pass_id);
let mut pass = pass
.try_lock()
.expect("ComputePasses should not be accessed concurrently");
let mut pass = self.hub.compute_passes.get_mut(pass_id);
pass.end()
}

Expand All @@ -87,10 +78,7 @@ impl Global {
bind_group_id: Option<id::BindGroupId>,
offsets: &[DynamicOffset],
) -> Result<(), PassStateError> {
let pass = self.hub.compute_passes.get(pass_id);
let mut pass = pass
.try_lock()
.expect("ComputePasses should not be accessed concurrently");
let mut pass = self.hub.compute_passes.get_mut(pass_id);
pass.set_bind_group(
index,
bind_group_id.map(|bind_group_id| self.hub.bind_groups.get(bind_group_id)),
Expand All @@ -103,10 +91,7 @@ impl Global {
pass_id: id::ComputePassEncoderId,
pipeline_id: id::ComputePipelineId,
) -> Result<(), PassStateError> {
let pass = self.hub.compute_passes.get(pass_id);
let mut pass = pass
.try_lock()
.expect("ComputePasses should not be accessed concurrently");
let mut pass = self.hub.compute_passes.get_mut(pass_id);
let pipeline = self.hub.compute_pipelines.get(pipeline_id);
pass.set_pipeline(pipeline)
}
Expand All @@ -117,10 +102,7 @@ impl Global {
offset: u32,
data: &[u8],
) -> Result<(), PassStateError> {
let pass = self.hub.compute_passes.get(pass_id);
let mut pass = pass
.try_lock()
.expect("ComputePasses should not be accessed concurrently");
let mut pass = self.hub.compute_passes.get_mut(pass_id);
pass.set_immediates(offset, data)
}

Expand All @@ -131,10 +113,7 @@ impl Global {
groups_y: u32,
groups_z: u32,
) -> Result<(), PassStateError> {
let pass = self.hub.compute_passes.get(pass_id);
let mut pass = pass
.try_lock()
.expect("ComputePasses should not be accessed concurrently");
let mut pass = self.hub.compute_passes.get_mut(pass_id);
pass.dispatch_workgroups(groups_x, groups_y, groups_z)
}

Expand All @@ -144,10 +123,7 @@ impl Global {
buffer_id: id::BufferId,
offset: BufferAddress,
) -> Result<(), PassStateError> {
let pass = self.hub.compute_passes.get(pass_id);
let mut pass = pass
.try_lock()
.expect("ComputePasses should not be accessed concurrently");
let mut pass = self.hub.compute_passes.get_mut(pass_id);
pass.dispatch_workgroups_indirect(self.hub.buffers.get(buffer_id), offset)
}

Expand All @@ -157,21 +133,15 @@ impl Global {
label: &str,
color: u32,
) -> Result<(), PassStateError> {
let pass = self.hub.compute_passes.get(pass_id);
let mut pass = pass
.try_lock()
.expect("ComputePasses should not be accessed concurrently");
let mut pass = self.hub.compute_passes.get_mut(pass_id);
pass.push_debug_group(label, color)
}

pub fn compute_pass_pop_debug_group(
&self,
pass_id: id::ComputePassEncoderId,
) -> Result<(), PassStateError> {
let pass = self.hub.compute_passes.get(pass_id);
let mut pass = pass
.try_lock()
.expect("ComputePasses should not be accessed concurrently");
let mut pass = self.hub.compute_passes.get_mut(pass_id);
pass.pop_debug_group()
}

Expand All @@ -181,10 +151,7 @@ impl Global {
label: &str,
color: u32,
) -> Result<(), PassStateError> {
let pass = self.hub.compute_passes.get(pass_id);
let mut pass = pass
.try_lock()
.expect("ComputePasses should not be accessed concurrently");
let mut pass = self.hub.compute_passes.get_mut(pass_id);
pass.insert_debug_marker(label, color)
}

Expand All @@ -194,10 +161,7 @@ impl Global {
query_set_id: id::QuerySetId,
query_index: u32,
) -> Result<(), PassStateError> {
let pass = self.hub.compute_passes.get(pass_id);
let mut pass = pass
.try_lock()
.expect("ComputePasses should not be accessed concurrently");
let mut pass = self.hub.compute_passes.get_mut(pass_id);
let query_set = self.hub.query_sets.get(query_set_id);
pass.write_timestamp(query_set, query_index)
}
Expand All @@ -208,10 +172,7 @@ impl Global {
query_set_id: id::QuerySetId,
query_index: u32,
) -> Result<(), PassStateError> {
let pass = self.hub.compute_passes.get(pass_id);
let mut pass = pass
.try_lock()
.expect("ComputePasses should not be accessed concurrently");
let mut pass = self.hub.compute_passes.get_mut(pass_id);
let query_set = self.hub.query_sets.get(query_set_id);
pass.begin_pipeline_statistics_query(query_set, query_index)
}
Expand All @@ -220,10 +181,7 @@ impl Global {
&self,
pass_id: id::ComputePassEncoderId,
) -> Result<(), PassStateError> {
let pass = self.hub.compute_passes.get(pass_id);
let mut pass = pass
.try_lock()
.expect("ComputePasses should not be accessed concurrently");
let mut pass = self.hub.compute_passes.get_mut(pass_id);
pass.end_pipeline_statistics_query()
}
}
Loading
Loading