Skip to content

Commit

Permalink
[wgpu] Remove unused ObjectId field of SubmissionIndex. (gfx-rs#5780
Browse files Browse the repository at this point in the history
)

Drop the first field of `wgpu::SubmissionIndex`, as it is unused.
Adjust uses of the types' other field.

Delete the `wgpu::context::Context` trait's `SubmissionIndex`
associated type. Remove it from implementations.

Drop the first field of the `Context` trait's `queue_submit` method's
return value. Adjust implementations.
  • Loading branch information
jimblandy authored Jun 10, 2024
1 parent eb24be4 commit 6c37052
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 22 deletions.
5 changes: 1 addition & 4 deletions wgpu/src/backend/webgpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,6 @@ impl crate::context::Context for ContextWebGpu {
type SurfaceData = Sendable<(Canvas, webgpu_sys::GpuCanvasContext)>;

type SurfaceOutputDetail = SurfaceOutputDetail;
type SubmissionIndex = Unused;
type SubmissionIndexData = ();
type PipelineCacheId = Unused;
type PipelineCacheData = ();
Expand Down Expand Up @@ -2950,14 +2949,12 @@ impl crate::context::Context for ContextWebGpu {
_queue: &Self::QueueId,
queue_data: &Self::QueueData,
command_buffers: I,
) -> (Self::SubmissionIndex, Self::SubmissionIndexData) {
) -> Self::SubmissionIndexData {
let temp_command_buffers = command_buffers
.map(|(_, data)| data.0)
.collect::<js_sys::Array>();

queue_data.0.submit(&temp_command_buffers);

(Unused, ())
}

fn queue_get_timestamp_period(
Expand Down
12 changes: 4 additions & 8 deletions wgpu/src/backend/wgpu_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,6 @@ impl crate::Context for ContextWgpuCore {
type SurfaceId = wgc::id::SurfaceId;
type SurfaceData = Surface;
type SurfaceOutputDetail = SurfaceOutputDetail;
type SubmissionIndex = Unused;
type SubmissionIndexData = wgc::device::queue::WrappedSubmissionIndex;

type RequestAdapterFuture = Ready<Option<(Self::AdapterId, Self::AdapterData)>>;
Expand Down Expand Up @@ -1525,7 +1524,7 @@ impl crate::Context for ContextWgpuCore {
_device_data: &Self::DeviceData,
maintain: crate::Maintain,
) -> wgt::MaintainResult {
let maintain_inner = maintain.map_index(|i| *i.1.as_ref().downcast_ref().unwrap());
let maintain_inner = maintain.map_index(|i| *i.0.as_ref().downcast_ref().unwrap());
match wgc::gfx_select!(device => self.0.device_poll(
*device,
maintain_inner
Expand Down Expand Up @@ -2322,18 +2321,15 @@ impl crate::Context for ContextWgpuCore {
queue: &Self::QueueId,
_queue_data: &Self::QueueData,
command_buffers: I,
) -> (Self::SubmissionIndex, Self::SubmissionIndexData) {
) -> Self::SubmissionIndexData {
let temp_command_buffers = command_buffers
.map(|(i, _)| i)
.collect::<SmallVec<[_; 4]>>();

let index = match wgc::gfx_select!(*queue => self.0.queue_submit(*queue, &temp_command_buffers))
{
match wgc::gfx_select!(*queue => self.0.queue_submit(*queue, &temp_command_buffers)) {
Ok(index) => index,
Err(err) => self.handle_error_fatal(err, "Queue::submit"),
};

(Unused, index)
}
}

fn queue_get_timestamp_period(
Expand Down
12 changes: 5 additions & 7 deletions wgpu/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ pub trait Context: Debug + WasmNotSendSync + Sized {
type SurfaceData: ContextData;

type SurfaceOutputDetail: WasmNotSendSync + 'static;
type SubmissionIndex: ContextId + Clone + Copy + WasmNotSendSync;
type SubmissionIndexData: ContextData + Copy;

type RequestAdapterFuture: Future<Output = Option<(Self::AdapterId, Self::AdapterData)>>
Expand Down Expand Up @@ -597,7 +596,7 @@ pub trait Context: Debug + WasmNotSendSync + Sized {
queue: &Self::QueueId,
queue_data: &Self::QueueData,
command_buffers: I,
) -> (Self::SubmissionIndex, Self::SubmissionIndexData);
) -> Self::SubmissionIndexData;
fn queue_get_timestamp_period(
&self,
queue: &Self::QueueId,
Expand Down Expand Up @@ -1593,7 +1592,7 @@ pub(crate) trait DynContext: Debug + WasmNotSendSync {
queue: &ObjectId,
queue_data: &crate::Data,
command_buffers: &mut dyn Iterator<Item = (ObjectId, Box<crate::Data>)>,
) -> (ObjectId, Arc<crate::Data>);
) -> Arc<crate::Data>;
fn queue_get_timestamp_period(&self, queue: &ObjectId, queue_data: &crate::Data) -> f32;
fn queue_on_submitted_work_done(
&self,
Expand Down Expand Up @@ -3039,16 +3038,15 @@ where
queue: &ObjectId,
queue_data: &crate::Data,
command_buffers: &mut dyn Iterator<Item = (ObjectId, Box<crate::Data>)>,
) -> (ObjectId, Arc<crate::Data>) {
) -> Arc<crate::Data> {
let queue = <T::QueueId>::from(*queue);
let queue_data = downcast_ref(queue_data);
let command_buffers = command_buffers.map(|(id, data)| {
let command_buffer_data: <T as Context>::CommandBufferData = *data.downcast().unwrap();
(<T::CommandBufferId>::from(id), command_buffer_data)
});
let (submission_index, data) =
Context::queue_submit(self, &queue, queue_data, command_buffers);
(submission_index.into(), Arc::new(data) as _)
let data = Context::queue_submit(self, &queue, queue_data, command_buffers);
Arc::new(data) as _
}

fn queue_get_timestamp_period(&self, queue: &ObjectId, queue_data: &crate::Data) -> f32 {
Expand Down
6 changes: 3 additions & 3 deletions wgpu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ static_assertions::assert_impl_all!(Device: Send, Sync);
/// This type is unique to the Rust API of `wgpu`.
/// There is no analogue in the WebGPU specification.
#[derive(Debug, Clone)]
pub struct SubmissionIndex(ObjectId, Arc<crate::Data>);
pub struct SubmissionIndex(Arc<crate::Data>);
#[cfg(send_sync)]
static_assertions::assert_impl_all!(SubmissionIndex: Send, Sync);

Expand Down Expand Up @@ -5397,14 +5397,14 @@ impl Queue {
.into_iter()
.map(|mut comb| (comb.id.take().unwrap(), comb.data.take().unwrap()));

let (raw, data) = DynContext::queue_submit(
let data = DynContext::queue_submit(
&*self.context,
&self.id,
self.data.as_ref(),
&mut command_buffers,
);

SubmissionIndex(raw, data)
SubmissionIndex(data)
}

/// Gets the amount of nanoseconds each tick of a timestamp query represents.
Expand Down

0 comments on commit 6c37052

Please sign in to comment.