Skip to content

Commit

Permalink
Merge branch 'trunk' into ray-tracing-compaction
Browse files Browse the repository at this point in the history
  • Loading branch information
Vecvec authored Feb 7, 2025
2 parents 604fbef + 4675393 commit 926c6b6
Show file tree
Hide file tree
Showing 10 changed files with 146 additions and 184 deletions.
2 changes: 1 addition & 1 deletion deno_webgpu/binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ pub fn op_webgpu_create_bind_group(
.get::<super::buffer::WebGpuBuffer>(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)),
},
Expand Down
2 changes: 1 addition & 1 deletion deno_webgpu/surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ pub fn op_webgpu_surface_get_current_texture(

match output.status {
wgpu_types::SurfaceStatus::Good | wgpu_types::SurfaceStatus::Suboptimal => {
let id = output.texture_id.unwrap();
let id = output.texture.unwrap();
let rid = state.resource_table.add(crate::texture::WebGpuTexture {
instance: instance.clone(),
id,
Expand Down
2 changes: 1 addition & 1 deletion player/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ impl GlobalPlay for wgc::global::Global {
Action::GetSurfaceTexture { id, parent_id } => {
self.surface_get_current_texture(parent_id, Some(id))
.unwrap()
.texture_id
.texture
.unwrap();
}
Action::CreateBindGroupLayout(id, desc) => {
Expand Down
2 changes: 1 addition & 1 deletion player/tests/data/bind-group.ron
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
(
binding: 0,
resource: Buffer((
buffer_id: Id(0, 1),
buffer: Id(0, 1),
offset: 0,
size: None,
)),
Expand Down
2 changes: 1 addition & 1 deletion player/tests/data/zero-init-buffer.ron
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
(
binding: 0,
resource: Buffer((
buffer_id: Id(3, 1),
buffer: Id(3, 1),
offset: 0,
size: Some(16),
)),
Expand Down
171 changes: 94 additions & 77 deletions wgpu-core/src/binding_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,50 +439,73 @@ impl BindingTypeMaxCountValidator {
/// Bindable resource and the slot to bind it to.
#[derive(Clone, Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct BindGroupEntry<'a> {
pub struct BindGroupEntry<'a, B = BufferId, S = SamplerId, TV = TextureViewId, TLAS = TlasId>
where
[BufferBinding<B>]: ToOwned,
[S]: ToOwned,
[TV]: ToOwned,
<[BufferBinding<B>] as ToOwned>::Owned: std::fmt::Debug,
<[S] as ToOwned>::Owned: std::fmt::Debug,
<[TV] as ToOwned>::Owned: std::fmt::Debug,
{
/// Slot for which binding provides resource. Corresponds to an entry of the same
/// binding index in the [`BindGroupLayoutDescriptor`].
pub binding: u32,
#[cfg_attr(
feature = "serde",
serde(bound(deserialize = "BindingResource<'a, B, S, TV, TLAS>: Deserialize<'de>"))
)]
/// Resource to attach to the binding
pub resource: BindingResource<'a>,
pub resource: BindingResource<'a, B, S, TV, TLAS>,
}

/// Bindable resource and the slot to bind it to.
#[derive(Clone, Debug)]
pub struct ResolvedBindGroupEntry<'a> {
/// Slot for which binding provides resource. Corresponds to an entry of the same
/// binding index in the [`BindGroupLayoutDescriptor`].
pub binding: u32,
/// Resource to attach to the binding
pub resource: ResolvedBindingResource<'a>,
}
pub type ResolvedBindGroupEntry<'a> =
BindGroupEntry<'a, Arc<Buffer>, Arc<Sampler>, Arc<TextureView>, Arc<Tlas>>;

/// Describes a group of bindings and the resources to be bound.
#[derive(Clone, Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct BindGroupDescriptor<'a> {
pub struct BindGroupDescriptor<
'a,
BGL = BindGroupLayoutId,
B = BufferId,
S = SamplerId,
TV = TextureViewId,
TLAS = TlasId,
> where
[BufferBinding<B>]: ToOwned,
[S]: ToOwned,
[TV]: ToOwned,
<[BufferBinding<B>] as ToOwned>::Owned: std::fmt::Debug,
<[S] as ToOwned>::Owned: std::fmt::Debug,
<[TV] as ToOwned>::Owned: std::fmt::Debug,
[BindGroupEntry<'a, B, S, TV, TLAS>]: ToOwned,
<[BindGroupEntry<'a, B, S, TV, TLAS>] as ToOwned>::Owned: std::fmt::Debug,
{
/// Debug label of the bind group.
///
/// This will show up in graphics debuggers for easy identification.
pub label: Label<'a>,
/// The [`BindGroupLayout`] that corresponds to this bind group.
pub layout: BindGroupLayoutId,
pub layout: BGL,
#[cfg_attr(
feature = "serde",
serde(bound(
deserialize = "<[BindGroupEntry<'a, B, S, TV, TLAS>] as ToOwned>::Owned: Deserialize<'de>"
))
)]
/// The resources to bind to this bind group.
pub entries: Cow<'a, [BindGroupEntry<'a>]>,
pub entries: Cow<'a, [BindGroupEntry<'a, B, S, TV, TLAS>]>,
}

/// Describes a group of bindings and the resources to be bound.
#[derive(Clone, Debug)]
pub struct ResolvedBindGroupDescriptor<'a> {
/// Debug label of the bind group.
///
/// This will show up in graphics debuggers for easy identification.
pub label: Label<'a>,
/// The [`BindGroupLayout`] that corresponds to this bind group.
pub layout: Arc<BindGroupLayout>,
/// The resources to bind to this bind group.
pub entries: Cow<'a, [ResolvedBindGroupEntry<'a>]>,
}
pub type ResolvedBindGroupDescriptor<'a> = BindGroupDescriptor<
'a,
Arc<BindGroupLayout>,
Arc<Buffer>,
Arc<Sampler>,
Arc<TextureView>,
Arc<Tlas>,
>;

/// Describes a [`BindGroupLayout`].
#[derive(Clone, Debug)]
Expand Down Expand Up @@ -641,14 +664,23 @@ pub enum PushConstantUploadError {
/// A `PipelineLayoutDescriptor` can be used to create a pipeline layout.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct PipelineLayoutDescriptor<'a> {
#[cfg_attr(feature = "serde", serde(bound = "BGL: Serialize"))]
pub struct PipelineLayoutDescriptor<'a, BGL = BindGroupLayoutId>
where
[BGL]: ToOwned,
<[BGL] as ToOwned>::Owned: std::fmt::Debug,
{
/// Debug label of the pipeline layout.
///
/// This will show up in graphics debuggers for easy identification.
pub label: Label<'a>,
/// Bind groups that this pipeline uses. The first entry will provide all the bindings for
/// "set = 0", second entry will provide all the bindings for "set = 1" etc.
pub bind_group_layouts: Cow<'a, [BindGroupLayoutId]>,
#[cfg_attr(
feature = "serde",
serde(bound(deserialize = "<[BGL] as ToOwned>::Owned: Deserialize<'de>"))
)]
pub bind_group_layouts: Cow<'a, [BGL]>,
/// Set of push constant ranges this pipeline uses. Each shader stage that
/// uses push constants must define the range in push constant memory that
/// corresponds to its single `layout(push_constant)` uniform block.
Expand All @@ -659,27 +691,7 @@ pub struct PipelineLayoutDescriptor<'a> {
pub push_constant_ranges: Cow<'a, [wgt::PushConstantRange]>,
}

/// Describes a pipeline layout.
///
/// A `PipelineLayoutDescriptor` can be used to create a pipeline layout.
#[derive(Debug)]
pub struct ResolvedPipelineLayoutDescriptor<'a> {
/// Debug label of the pipeline layout.
///
/// This will show up in graphics debuggers for easy identification.
pub label: Label<'a>,
/// Bind groups that this pipeline uses. The first entry will provide all the bindings for
/// "set = 0", second entry will provide all the bindings for "set = 1" etc.
pub bind_group_layouts: Cow<'a, [Arc<BindGroupLayout>]>,
/// Set of push constant ranges this pipeline uses. Each shader stage that
/// uses push constants must define the range in push constant memory that
/// corresponds to its single `layout(push_constant)` uniform block.
///
/// If this array is non-empty, the
/// [`Features::PUSH_CONSTANTS`](wgt::Features::PUSH_CONSTANTS) feature must
/// be enabled.
pub push_constant_ranges: Cow<'a, [wgt::PushConstantRange]>,
}
pub type ResolvedPipelineLayoutDescriptor<'a> = PipelineLayoutDescriptor<'a, Arc<BindGroupLayout>>;

#[derive(Debug)]
pub struct PipelineLayout {
Expand Down Expand Up @@ -801,45 +813,50 @@ 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<B = BufferId> {
pub buffer: B,
pub offset: wgt::BufferAddress,
pub size: Option<wgt::BufferSize>,
}

#[derive(Clone, Debug)]
pub struct ResolvedBufferBinding {
pub buffer: Arc<Buffer>,
pub offset: wgt::BufferAddress,
pub size: Option<wgt::BufferSize>,
}
pub type ResolvedBufferBinding = BufferBinding<Arc<Buffer>>;

// Note: Duplicated in `wgpu-rs` as `BindingResource`
// They're different enough that it doesn't make sense to share a common type
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum BindingResource<'a> {
Buffer(BufferBinding),
BufferArray(Cow<'a, [BufferBinding]>),
Sampler(SamplerId),
SamplerArray(Cow<'a, [SamplerId]>),
TextureView(TextureViewId),
TextureViewArray(Cow<'a, [TextureViewId]>),
AccelerationStructure(TlasId),
pub enum BindingResource<'a, B = BufferId, S = SamplerId, TV = TextureViewId, TLAS = TlasId>
where
[BufferBinding<B>]: ToOwned,
[S]: ToOwned,
[TV]: ToOwned,
<[BufferBinding<B>] as ToOwned>::Owned: std::fmt::Debug,
<[S] as ToOwned>::Owned: std::fmt::Debug,
<[TV] as ToOwned>::Owned: std::fmt::Debug,
{
Buffer(BufferBinding<B>),
#[cfg_attr(
feature = "serde",
serde(bound(deserialize = "<[BufferBinding<B>] as ToOwned>::Owned: Deserialize<'de>"))
)]
BufferArray(Cow<'a, [BufferBinding<B>]>),
Sampler(S),
#[cfg_attr(
feature = "serde",
serde(bound(deserialize = "<[S] as ToOwned>::Owned: Deserialize<'de>"))
)]
SamplerArray(Cow<'a, [S]>),
TextureView(TV),
#[cfg_attr(
feature = "serde",
serde(bound(deserialize = "<[TV] as ToOwned>::Owned: Deserialize<'de>"))
)]
TextureViewArray(Cow<'a, [TV]>),
AccelerationStructure(TLAS),
}

// Note: Duplicated in `wgpu-rs` as `BindingResource`
// They're different enough that it doesn't make sense to share a common type
#[derive(Debug, Clone)]
pub enum ResolvedBindingResource<'a> {
Buffer(ResolvedBufferBinding),
BufferArray(Cow<'a, [ResolvedBufferBinding]>),
Sampler(Arc<Sampler>),
SamplerArray(Cow<'a, [Arc<Sampler>]>),
TextureView(Arc<TextureView>),
TextureViewArray(Cow<'a, [Arc<TextureView>]>),
AccelerationStructure(Arc<Tlas>),
}
pub type ResolvedBindingResource<'a> =
BindingResource<'a, Arc<Buffer>, Arc<Sampler>, Arc<TextureView>, Arc<Tlas>>;

#[derive(Clone, Debug, Error)]
#[non_exhaustive]
Expand Down
2 changes: 1 addition & 1 deletion wgpu-core/src/device/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading

0 comments on commit 926c6b6

Please sign in to comment.