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

Timestamp queries in render/compute pass descriptor #296

Merged
merged 7 commits into from
Sep 30, 2023
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
8 changes: 8 additions & 0 deletions src/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,14 @@ pub fn to_native_composite_alpha_mode(
}
}

#[inline]
pub fn map_query_set_index(index: u32) -> Option<u32> {
match index {
native::WGPU_QUERY_SET_INDEX_UNDEFINED => None,
_ => Some(index),
}
}

#[inline]
pub fn map_query_set_descriptor<'a>(
desc: &native::WGPUQuerySetDescriptor,
Expand Down
33 changes: 30 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use conv::{
map_device_descriptor, map_instance_backend_flags, map_instance_descriptor,
map_pipeline_layout_descriptor, map_primitive_state, map_shader_module, map_surface,
map_query_set_index,
CreateSurfaceParams,
};
use parking_lot::{Mutex, RwLock};
Expand Down Expand Up @@ -996,10 +997,24 @@ pub unsafe extern "C" fn wgpuCommandEncoderBeginComputePass(
)
};

let timestamp_writes = descriptor.map(|descriptor| {
descriptor.timestampWrites.as_ref().map(|timestamp_write| {
wgc::command::ComputePassTimestampWrites {
query_set:
timestamp_write.querySet
.as_ref()
.expect("invalid query set in timestamp writes")
.id,
beginning_of_pass_write_index: map_query_set_index(timestamp_write.beginningOfPassWriteIndex),
end_of_pass_write_index: map_query_set_index(timestamp_write.endOfPassWriteIndex),
}
})
}).flatten();

let desc = match descriptor {
Some(descriptor) => wgc::command::ComputePassDescriptor {
label: ptr_into_label(descriptor.label),
timestamp_writes: None,
timestamp_writes: timestamp_writes.as_ref(),
},
None => wgc::command::ComputePassDescriptor::default(),
};
Expand Down Expand Up @@ -1048,6 +1063,18 @@ pub unsafe extern "C" fn wgpuCommandEncoderBeginRenderPass(
}
});

let timestamp_writes = descriptor.timestampWrites.as_ref().map(|timestamp_write| {
wgc::command::RenderPassTimestampWrites {
query_set:
timestamp_write.querySet
.as_ref()
.expect("invalid query set in timestamp writes")
.id,
beginning_of_pass_write_index: map_query_set_index(timestamp_write.beginningOfPassWriteIndex),
end_of_pass_write_index: map_query_set_index(timestamp_write.endOfPassWriteIndex),
}
});

let desc = wgc::command::RenderPassDescriptor {
label: ptr_into_label(descriptor.label),
color_attachments: Cow::Owned(
Expand All @@ -1070,8 +1097,8 @@ pub unsafe extern "C" fn wgpuCommandEncoderBeginRenderPass(
.collect(),
),
depth_stencil_attachment: depth_stencil_attachment.as_ref(),
timestamp_writes: None,
occlusion_query_set: None,
timestamp_writes: timestamp_writes.as_ref(),
occlusion_query_set: None, // TODO:
};

Arc::into_raw(Arc::new(WGPURenderPassEncoderImpl {
Expand Down
Loading