mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-21 06:50:59 +01:00
Comments
This commit is contained in:
1 parent
6a986f4bc4
commit
c344bec508
4 files changed
+45
-9
No files matched your search
@@ -120,13 +120,29 @@ fn timestamp_query(ctx: TestingContext) {
|
||||
let query_data: &[u64] = bytemuck::cast_slice(&query_buffer_view);
|
||||
|
||||
for i in 0..ITERATIONS {
|
||||
// The byte and query offset for the current iteration
|
||||
let byte_offset = i as u64 * QUERY_RESOLVE_BUFFER_ALIGNMENT;
|
||||
let query_offset = byte_offset / 8;
|
||||
|
||||
// The byte and query offset for the next iteration
|
||||
let next_byte_offset = (i + 1) as u64 * QUERY_RESOLVE_BUFFER_ALIGNMENT;
|
||||
let next_query_offset = next_byte_offset / 8;
|
||||
|
||||
// The range of queries that should still be the value they were initialized to.
|
||||
let untouched_query_start = query_offset + QUERIES_PER_ITERATION as u64;
|
||||
let untouched_query_end = next_query_offset;
|
||||
|
||||
// WebGPU does not define the value of the timestamp queries. They unfortunately
|
||||
// can be `0` in some situations. However, we should expect that some value
|
||||
// has been written, and the odds of it being exactly `init_constant` are vanishingly low.
|
||||
assert_ne!(query_data[query_offset as usize], init_constant);
|
||||
assert_ne!(query_data[query_offset as usize + 1], init_constant);
|
||||
for query in 0..QUERIES_PER_ITERATION {
|
||||
let query_index = query_offset + query as u64;
|
||||
assert_ne!(query_data[query_index as usize], init_constant);
|
||||
}
|
||||
|
||||
// Validate that the queries that were not written to are still the value they were initialized to.
|
||||
for query in untouched_query_start..untouched_query_end {
|
||||
assert_eq!(query_data[query as usize], init_constant);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -481,7 +481,8 @@ impl Global {
|
||||
.get(&snatch_guard)
|
||||
.unwrap(),
|
||||
&dst_buffer,
|
||||
start_query..end_query,
|
||||
destination_offset,
|
||||
query_count,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -680,6 +680,7 @@ impl Device {
|
||||
self,
|
||||
&*buffer,
|
||||
desc.label.as_deref(),
|
||||
desc.size,
|
||||
desc.usage,
|
||||
)?,
|
||||
);
|
||||
@@ -787,8 +788,13 @@ impl Device {
|
||||
.timestamp_normalizer
|
||||
.get()
|
||||
.unwrap()
|
||||
.create_normalization_bind_group(self, &*hal_buffer, desc.label.as_deref(), desc.usage)
|
||||
{
|
||||
.create_normalization_bind_group(
|
||||
self,
|
||||
&*hal_buffer,
|
||||
desc.label.as_deref(),
|
||||
desc.size,
|
||||
desc.usage,
|
||||
) {
|
||||
Ok(bg) => Snatchable::new(bg),
|
||||
Err(e) => {
|
||||
return (
|
||||
|
||||
@@ -27,6 +27,8 @@
|
||||
//! We then multiply the timestamp by the numerator, and shift it right by the
|
||||
//! denominator. This gives us the normalized timestamp.
|
||||
|
||||
use core::num::NonZeroU64;
|
||||
|
||||
use alloc::{boxed::Box, string::String, string::ToString, sync::Arc};
|
||||
|
||||
use hashbrown::HashMap;
|
||||
@@ -118,7 +120,7 @@ impl TimestampNormalizer {
|
||||
ty: wgt::BindingType::Buffer {
|
||||
ty: wgt::BufferBindingType::Storage { read_only: false },
|
||||
has_dynamic_offset: false,
|
||||
min_binding_size: None,
|
||||
min_binding_size: Some(NonZeroU64::new(8).unwrap()),
|
||||
},
|
||||
count: None,
|
||||
}],
|
||||
@@ -245,6 +247,7 @@ impl TimestampNormalizer {
|
||||
device: &Device,
|
||||
buffer: &dyn hal::DynBuffer,
|
||||
buffer_label: Option<&str>,
|
||||
buffer_size: u64,
|
||||
buffer_usages: wgt::BufferUsages,
|
||||
) -> Result<TimestampNormalizationBindGroup, DeviceError> {
|
||||
unsafe {
|
||||
@@ -256,6 +259,14 @@ impl TimestampNormalizer {
|
||||
return Ok(TimestampNormalizationBindGroup { raw: None });
|
||||
}
|
||||
|
||||
// If this buffer is large enough that we wouldn't be able to bind the entire thing
|
||||
// at once to normalize the timestamps, we can't use it. We force the buffer to fail
|
||||
// to allocate. The lowest max binding size is 128MB, and query sets must be small
|
||||
// (no more than 4096), so this should never be hit in practice by sane programs.
|
||||
if buffer_size > device.adapter.limits().max_storage_buffer_binding_size as u64 {
|
||||
return Err(DeviceError::OutOfMemory);
|
||||
}
|
||||
|
||||
let bg_label_alloc;
|
||||
let label = match buffer_label {
|
||||
Some(label) => {
|
||||
@@ -298,7 +309,8 @@ impl TimestampNormalizer {
|
||||
tracker: &mut BufferTracker,
|
||||
bind_group: &TimestampNormalizationBindGroup,
|
||||
buffer: &Arc<Buffer>,
|
||||
range: core::ops::Range<u32>,
|
||||
buffer_offset_bytes: u64,
|
||||
total_timestamps: u32,
|
||||
) {
|
||||
let Some(ref state) = &self.state else {
|
||||
return;
|
||||
@@ -308,11 +320,12 @@ impl TimestampNormalizer {
|
||||
return;
|
||||
};
|
||||
|
||||
let buffer_offset_timestamps: u32 = (buffer_offset_bytes / 8).try_into().unwrap(); // Unreachable as MAX_QUERIES is way less than u32::MAX
|
||||
|
||||
let pending_barrier = tracker.set_single(buffer, wgt::BufferUses::STORAGE_READ_WRITE);
|
||||
|
||||
let barrier = pending_barrier.map(|pending| pending.into_hal(buffer, snatch_guard));
|
||||
|
||||
let total_timestamps = range.len() as u32;
|
||||
let needed_workgroups = total_timestamps.div_ceil(64);
|
||||
|
||||
unsafe {
|
||||
@@ -327,7 +340,7 @@ impl TimestampNormalizer {
|
||||
&*state.pipeline_layout,
|
||||
wgt::ShaderStages::COMPUTE,
|
||||
0,
|
||||
&[range.start, range.len() as u32],
|
||||
&[buffer_offset_timestamps, total_timestamps],
|
||||
);
|
||||
encoder.dispatch([needed_workgroups, 1, 1]);
|
||||
encoder.end_compute_pass();
|
||||
|
||||
Reference in new issue
Block a user