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

Add missing validation in copy_texture_to-Buffer. #2958

Merged
merged 2 commits into from
Aug 13, 2022
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ the same every time it is rendered, we now warn if it is missing.
- Validate the number of color attachments in `create_render_pipeline` by @nical in [#2913](https://github.com/gfx-rs/wgpu/pull/2913)
- Validate against the maximum binding index in `create_bind_group_layout` by @nical in [#2892](https://github.com/gfx-rs/wgpu/pull/2892)
- Validate that map_async's range is not negative by @nical in [#2938](https://github.com/gfx-rs/wgpu/pull/2938)
- Validate the sample count and mip level in `copy_texture_to_buffer` by @nical in [#2958](https://github.com/gfx-rs/wgpu/pull/2958)

#### DX12
- `DownlevelCapabilities::default()` now returns the `ANISOTROPIC_FILTERING` flag set to true so DX12 lists `ANISOTROPIC_FILTERING` as true again by @cwfitzgerald in [#2851](https://github.com/gfx-rs/wgpu/pull/2851)
Expand Down
17 changes: 17 additions & 0 deletions wgpu-core/src/command/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ pub enum TransferError {
MemoryInitFailure(#[from] super::ClearError),
#[error("Cannot encode this copy because of a missing downelevel flag")]
MissingDownlevelFlags(#[from] MissingDownlevelFlags),
#[error("Source texture sample count must be 1, got {sample_count}")]
InvalidSampleCount { sample_count: u32 },
#[error("Requested mip level {requested} does no exist (count: {count})")]
InvalidMipLevel { requested: u32, count: u32 },
}

impl PrettyError for TransferError {
Expand Down Expand Up @@ -794,6 +798,19 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
if !src_texture.desc.usage.contains(TextureUsages::COPY_SRC) {
return Err(TransferError::MissingCopySrcUsageFlag.into());
}
if src_texture.desc.sample_count != 1 {
return Err(TransferError::InvalidSampleCount {
sample_count: src_texture.desc.sample_count,
}
.into());
}
if source.mip_level >= src_texture.desc.mip_level_count {
return Err(TransferError::InvalidMipLevel {
requested: source.mip_level,
count: src_texture.desc.mip_level_count,
}
.into());
}
let src_barrier = src_pending.map(|pending| pending.into_hal(src_texture));

let (dst_buffer, dst_pending) = cmd_buf
Expand Down