web: implement queue_validate_write_buffer (#3098)

This commit is contained in:
Jinlei Li
2022-10-13 14:11:31 +08:00
committed by GitHub
parent 42be6f36aa
commit b72bcc54dc
2 changed files with 26 additions and 4 deletions

View File

@@ -47,6 +47,9 @@ Bottom level categories:
- Convert all `Default` Implementations on Enums to `derive(Default)`
- Implement `Default` for `CompositeAlphaMode`
#### WebGPU
- Implement `queue_validate_write_buffer` by @jinleili in [#3098](https://github.com/gfx-rs/wgpu/pull/3098)
### Added/New Features
#### General

View File

@@ -2345,11 +2345,30 @@ impl crate::Context for Context {
fn queue_validate_write_buffer(
&self,
_queue: &Self::QueueId,
_buffer: &Self::BufferId,
_offset: wgt::BufferAddress,
_size: wgt::BufferSize,
buffer: &Self::BufferId,
offset: wgt::BufferAddress,
size: wgt::BufferSize,
) {
// TODO
let usage = wgt::BufferUsages::from_bits_truncate(buffer.0.usage());
if !usage.contains(wgt::BufferUsages::COPY_DST) {
panic!("Destination buffer is missing the `COPY_DST` usage flag");
}
let write_size = u64::from(size);
if write_size % wgt::COPY_BUFFER_ALIGNMENT != 0 {
panic!(
"Copy size {} does not respect `COPY_BUFFER_ALIGNMENT`",
size
);
}
if offset % wgt::COPY_BUFFER_ALIGNMENT != 0 {
panic!(
"Buffer offset {} is not aligned to block size or `COPY_BUFFER_ALIGNMENT`",
offset
);
}
if write_size + offset > buffer.0.size() as u64 {
panic!("copy of {}..{} would end up overrunning the bounds of the destination buffer of size {}", offset, offset + write_size, buffer.0.size());
}
}
fn queue_create_staging_buffer(