From c0688b6de7059ff5d7f7de8a4da3a5b923b4af11 Mon Sep 17 00:00:00 2001 From: sagudev <16504129+sagudev@users.noreply.github.com> Date: Fri, 7 Feb 2025 08:25:21 +0100 Subject: [PATCH] Unify `ResolvedBufferBinding` into `BufferBinding` Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> --- deno_webgpu/binding.rs | 2 +- player/tests/data/bind-group.ron | 2 +- player/tests/data/zero-init-buffer.ron | 2 +- wgpu-core/src/binding_model.rs | 11 +++-------- wgpu-core/src/device/global.rs | 2 +- wgpu/src/backend/wgpu_core.rs | 4 ++-- 6 files changed, 9 insertions(+), 14 deletions(-) diff --git a/deno_webgpu/binding.rs b/deno_webgpu/binding.rs index c16171e2b..6d9ba92a0 100644 --- a/deno_webgpu/binding.rs +++ b/deno_webgpu/binding.rs @@ -284,7 +284,7 @@ pub fn op_webgpu_create_bind_group( .get::(entry.resource)?; wgpu_core::binding_model::BindingResource::Buffer( wgpu_core::binding_model::BufferBinding { - buffer_id: buffer_resource.1, + buffer: buffer_resource.1, offset: entry.offset.unwrap_or(0), size: std::num::NonZeroU64::new(entry.size.unwrap_or(0)), }, diff --git a/player/tests/data/bind-group.ron b/player/tests/data/bind-group.ron index bcc127b97..5b3a256d3 100644 --- a/player/tests/data/bind-group.ron +++ b/player/tests/data/bind-group.ron @@ -27,7 +27,7 @@ ( binding: 0, resource: Buffer(( - buffer_id: Id(0, 1), + buffer: Id(0, 1), offset: 0, size: None, )), diff --git a/player/tests/data/zero-init-buffer.ron b/player/tests/data/zero-init-buffer.ron index e8a1761e8..143f91f51 100644 --- a/player/tests/data/zero-init-buffer.ron +++ b/player/tests/data/zero-init-buffer.ron @@ -112,7 +112,7 @@ ( binding: 0, resource: Buffer(( - buffer_id: Id(3, 1), + buffer: Id(3, 1), offset: 0, size: Some(16), )), diff --git a/wgpu-core/src/binding_model.rs b/wgpu-core/src/binding_model.rs index 3ab652abc..ad5c906e3 100644 --- a/wgpu-core/src/binding_model.rs +++ b/wgpu-core/src/binding_model.rs @@ -801,18 +801,13 @@ crate::impl_storage_item!(PipelineLayout); #[repr(C)] #[derive(Clone, Debug, Hash, Eq, PartialEq)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -pub struct BufferBinding { - pub buffer_id: BufferId, +pub struct BufferBinding { + pub buffer: B, pub offset: wgt::BufferAddress, pub size: Option, } -#[derive(Clone, Debug)] -pub struct ResolvedBufferBinding { - pub buffer: Arc, - pub offset: wgt::BufferAddress, - pub size: Option, -} +pub type ResolvedBufferBinding = BufferBinding>; // Note: Duplicated in `wgpu-rs` as `BindingResource` // They're different enough that it doesn't make sense to share a common type diff --git a/wgpu-core/src/device/global.rs b/wgpu-core/src/device/global.rs index eff2e811b..f18ad71f8 100644 --- a/wgpu-core/src/device/global.rs +++ b/wgpu-core/src/device/global.rs @@ -734,7 +734,7 @@ impl Global { { let resolve_buffer = |bb: &BufferBinding| { buffer_storage - .get(bb.buffer_id) + .get(bb.buffer) .get() .map(|buffer| ResolvedBufferBinding { buffer, diff --git a/wgpu/src/backend/wgpu_core.rs b/wgpu/src/backend/wgpu_core.rs index b2e242b6b..5c27be4f2 100644 --- a/wgpu/src/backend/wgpu_core.rs +++ b/wgpu/src/backend/wgpu_core.rs @@ -1121,7 +1121,7 @@ impl dispatch::DeviceInterface for CoreDevice { for entry in desc.entries.iter() { if let BindingResource::BufferArray(array) = entry.resource { arrayed_buffer_bindings.extend(array.iter().map(|binding| bm::BufferBinding { - buffer_id: binding.buffer.inner.as_core().id, + buffer: binding.buffer.inner.as_core().id, offset: binding.offset, size: binding.size, })); @@ -1141,7 +1141,7 @@ impl dispatch::DeviceInterface for CoreDevice { offset, size, }) => bm::BindingResource::Buffer(bm::BufferBinding { - buffer_id: buffer.inner.as_core().id, + buffer: buffer.inner.as_core().id, offset, size, }),