Skip to content

Commit 96a85b3

Browse files
authored
Add missing validation in copy_texture_to-Buffer. (#2958)
1 parent d655017 commit 96a85b3

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ the same every time it is rendered, we now warn if it is missing.
113113
- Validate the number of color attachments in `create_render_pipeline` by @nical in [#2913](https://github.com/gfx-rs/wgpu/pull/2913)
114114
- Validate against the maximum binding index in `create_bind_group_layout` by @nical in [#2892](https://github.com/gfx-rs/wgpu/pull/2892)
115115
- Validate that map_async's range is not negative by @nical in [#2938](https://github.com/gfx-rs/wgpu/pull/2938)
116+
- Validate the sample count and mip level in `copy_texture_to_buffer` by @nical in [#2958](https://github.com/gfx-rs/wgpu/pull/2958)
116117

117118
#### DX12
118119
- `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)

wgpu-core/src/command/transfer.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ pub enum TransferError {
109109
MemoryInitFailure(#[from] super::ClearError),
110110
#[error("Cannot encode this copy because of a missing downelevel flag")]
111111
MissingDownlevelFlags(#[from] MissingDownlevelFlags),
112+
#[error("Source texture sample count must be 1, got {sample_count}")]
113+
InvalidSampleCount { sample_count: u32 },
114+
#[error("Requested mip level {requested} does no exist (count: {count})")]
115+
InvalidMipLevel { requested: u32, count: u32 },
112116
}
113117

114118
impl PrettyError for TransferError {
@@ -794,6 +798,19 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
794798
if !src_texture.desc.usage.contains(TextureUsages::COPY_SRC) {
795799
return Err(TransferError::MissingCopySrcUsageFlag.into());
796800
}
801+
if src_texture.desc.sample_count != 1 {
802+
return Err(TransferError::InvalidSampleCount {
803+
sample_count: src_texture.desc.sample_count,
804+
}
805+
.into());
806+
}
807+
if source.mip_level >= src_texture.desc.mip_level_count {
808+
return Err(TransferError::InvalidMipLevel {
809+
requested: source.mip_level,
810+
count: src_texture.desc.mip_level_count,
811+
}
812+
.into());
813+
}
797814
let src_barrier = src_pending.map(|pending| pending.into_hal(src_texture));
798815

799816
let (dst_buffer, dst_pending) = cmd_buf

0 commit comments

Comments
 (0)