Skip to content

Commit

Permalink
web: implement queue_validate_write_buffer (#3098)
Browse files Browse the repository at this point in the history
  • Loading branch information
jinleili authored Oct 13, 2022
1 parent 42be6f3 commit b72bcc5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 23 additions & 4 deletions wgpu/src/backend/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit b72bcc5

Please sign in to comment.