From 6e94a643df030127416b9852978dc0315a3a1407 Mon Sep 17 00:00:00 2001 From: Ryan Andersen Date: Thu, 28 Apr 2022 22:35:54 -0700 Subject: [PATCH 1/2] Disallow dispatch calls with dimensions of length of zero --- .../src/command_buffer/commands/pipeline.rs | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/vulkano/src/command_buffer/commands/pipeline.rs b/vulkano/src/command_buffer/commands/pipeline.rs index 8b3a0ac0b5..676ba42157 100644 --- a/vulkano/src/command_buffer/commands/pipeline.rs +++ b/vulkano/src/command_buffer/commands/pipeline.rs @@ -1611,6 +1611,10 @@ fn check_dispatch(device: &Device, dimensions: [u32; 3]) -> Result<(), CheckDisp }); } + if dimensions.contains(&0) { + return Err(CheckDispatchError::ZeroLengthDimensions); + } + Ok(()) } @@ -1624,6 +1628,9 @@ pub enum CheckDispatchError { /// The actual supported dimensions. max_supported: [u32; 3], }, + + /// At least one of the dimensions requested were zero. + ZeroLengthDimensions, } impl error::Error for CheckDispatchError {} @@ -1638,6 +1645,9 @@ impl fmt::Display for CheckDispatchError { CheckDispatchError::UnsupportedDimensions { .. } => { "the dimensions are too large for the device's limits" } + CheckDispatchError::ZeroLengthDimensions => { + "at least one of the dimensions requested were 0" + } } ) } @@ -2365,4 +2375,26 @@ mod tests { _ => panic!(), } } + + #[test] + fn zero_dimension_checked() { + let (device, _) = gfx_dev_and_queue!(); + + let attempted = [128, 1, 0]; + + // Just in case the device is some kind of software implementation. + if device + .physical_device() + .properties() + .max_compute_work_group_count + == attempted + { + return; + } + + match check_dispatch(&device, attempted) { + Err(CheckDispatchError::ZeroLengthDimensions) => {} + _ => panic!(), + } + } } From 20b57fcfbff1f6d976a41e6e0529ec81e5becf2c Mon Sep 17 00:00:00 2001 From: Ryan Andersen Date: Thu, 28 Apr 2022 23:08:47 -0700 Subject: [PATCH 2/2] Improvements to phrasing and unit test --- vulkano/src/command_buffer/commands/pipeline.rs | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/vulkano/src/command_buffer/commands/pipeline.rs b/vulkano/src/command_buffer/commands/pipeline.rs index 676ba42157..d14418892d 100644 --- a/vulkano/src/command_buffer/commands/pipeline.rs +++ b/vulkano/src/command_buffer/commands/pipeline.rs @@ -1629,7 +1629,7 @@ pub enum CheckDispatchError { max_supported: [u32; 3], }, - /// At least one of the dimensions requested were zero. + /// At least one of the requested dimensions were zero. ZeroLengthDimensions, } @@ -1646,7 +1646,7 @@ impl fmt::Display for CheckDispatchError { "the dimensions are too large for the device's limits" } CheckDispatchError::ZeroLengthDimensions => { - "at least one of the dimensions requested were 0" + "at least one of the requested dimensions were zero" } } ) @@ -2382,16 +2382,6 @@ mod tests { let attempted = [128, 1, 0]; - // Just in case the device is some kind of software implementation. - if device - .physical_device() - .properties() - .max_compute_work_group_count - == attempted - { - return; - } - match check_dispatch(&device, attempted) { Err(CheckDispatchError::ZeroLengthDimensions) => {} _ => panic!(),