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

Unify Arc*Descriptors into *Descriptors #7056

Merged
merged 3 commits into from
Feb 6, 2025
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
2 changes: 1 addition & 1 deletion deno_webgpu/command_encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ pub fn op_webgpu_command_encoder_begin_compute_pass(
let command_encoder = &command_encoder_resource.1;
let descriptor = wgpu_core::command::ComputePassDescriptor {
label: Some(label),
timestamp_writes: timestamp_writes.as_ref(),
timestamp_writes,
};

let (compute_pass, error) =
Expand Down
17 changes: 7 additions & 10 deletions wgpu-core/src/command/compute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl ComputePass {
} = desc;

Self {
base: Some(BasePass::new(label)),
base: Some(BasePass::new(&label)),
parent,
timestamp_writes,

Expand Down Expand Up @@ -95,17 +95,13 @@ impl fmt::Debug for ComputePass {
}

#[derive(Clone, Debug, Default)]
pub struct ComputePassDescriptor<'a> {
pub struct ComputePassDescriptor<'a, PTW = PassTimestampWrites> {
pub label: Label<'a>,
/// Defines where and when timestamp values will be written for this pass.
pub timestamp_writes: Option<&'a PassTimestampWrites>,
pub timestamp_writes: Option<PTW>,
}

struct ArcComputePassDescriptor<'a> {
pub label: &'a Label<'a>,
/// Defines where and when timestamp values will be written for this pass.
pub timestamp_writes: Option<ArcPassTimestampWrites>,
}
type ArcComputePassDescriptor<'a> = ComputePassDescriptor<'a, ArcPassTimestampWrites>;

#[derive(Clone, Debug, Error)]
#[non_exhaustive]
Expand Down Expand Up @@ -292,7 +288,7 @@ impl Global {
let hub = &self.hub;

let mut arc_desc = ArcComputePassDescriptor {
label: &desc.label,
label: desc.label.as_deref().map(std::borrow::Cow::Borrowed),
timestamp_writes: None, // Handle only once we resolved the encoder.
};

Expand All @@ -307,6 +303,7 @@ impl Global {

arc_desc.timestamp_writes = match desc
.timestamp_writes
.as_ref()
.map(|tw| {
Self::validate_pass_timestamp_writes(&cmd_buf.device, &hub.query_sets.read(), tw)
})
Expand Down Expand Up @@ -366,7 +363,7 @@ impl Global {
encoder_id,
&ComputePassDescriptor {
label: label.as_deref().map(std::borrow::Cow::Borrowed),
timestamp_writes,
timestamp_writes: timestamp_writes.cloned(),
},
);
if let Some(err) = encoder_error {
Expand Down
24 changes: 5 additions & 19 deletions wgpu-core/src/command/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,11 @@ impl<V: Copy + Default> ResolvedPassChannel<V> {
#[repr(C)]
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct RenderPassColorAttachment {
pub struct RenderPassColorAttachment<TV = id::TextureViewId> {
/// The view to use as an attachment.
pub view: id::TextureViewId,
pub view: TV,
/// The view that will receive the resolved output if multisampling is used.
pub resolve_target: Option<id::TextureViewId>,
pub resolve_target: Option<TV>,
/// Operation to perform to the output attachment at the start of a
/// renderpass.
///
Expand All @@ -173,22 +173,8 @@ pub struct RenderPassColorAttachment {
pub store_op: StoreOp,
}

/// Describes a color attachment to a render pass.
#[derive(Debug)]
struct ArcRenderPassColorAttachment {
/// The view to use as an attachment.
pub view: Arc<TextureView>,
/// The view that will receive the resolved output if multisampling is used.
pub resolve_target: Option<Arc<TextureView>>,
/// Operation to perform to the output attachment at the start of a
/// renderpass.
///
/// This must be clear if it is the first renderpass rendering to a swap
/// chain image.
pub load_op: LoadOp<Color>,
/// Operation to perform to the output attachment at the end of a renderpass.
pub store_op: StoreOp,
}
pub type ArcRenderPassColorAttachment = RenderPassColorAttachment<Arc<TextureView>>;

impl ArcRenderPassColorAttachment {
fn hal_ops(&self) -> hal::AttachmentOps {
load_hal_ops(self.load_op) | store_hal_ops(self.store_op)
Expand Down
14 changes: 3 additions & 11 deletions wgpu-core/src/command/timestamp_writes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,13 @@ use crate::id;
/// Describes the writing of timestamp values in a render or compute pass.
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct PassTimestampWrites {
pub struct PassTimestampWrites<QS = id::QuerySetId> {
/// The query set to write the timestamps to.
pub query_set: id::QuerySetId,
pub query_set: QS,
/// The index of the query set at which a start timestamp of this pass is written, if any.
pub beginning_of_pass_write_index: Option<u32>,
/// The index of the query set at which an end timestamp of this pass is written, if any.
pub end_of_pass_write_index: Option<u32>,
}

/// Describes the writing of timestamp values in a render or compute pass with the query set resolved.
pub struct ArcPassTimestampWrites {
/// The query set to write the timestamps to.
pub query_set: Arc<crate::resource::QuerySet>,
/// The index of the query set at which a start timestamp of this pass is written, if any.
pub beginning_of_pass_write_index: Option<u32>,
/// The index of the query set at which an end timestamp of this pass is written, if any.
pub end_of_pass_write_index: Option<u32>,
}
pub type ArcPassTimestampWrites = PassTimestampWrites<Arc<crate::resource::QuerySet>>;
2 changes: 1 addition & 1 deletion wgpu/src/backend/wgpu_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2210,7 +2210,7 @@ impl dispatch::CommandEncoderInterface for CoreCommandEncoder {
self.id,
&wgc::command::ComputePassDescriptor {
label: desc.label.map(Borrowed),
timestamp_writes: timestamp_writes.as_ref(),
timestamp_writes,
},
);

Expand Down