Skip to content

Commit

Permalink
Disallow dispatch calls with dimensions of zero-length (#1886)
Browse files Browse the repository at this point in the history
* Disallow dispatch calls with dimensions of length of zero

* Improvements to phrasing and unit test
  • Loading branch information
Ryan Andersen authored Apr 29, 2022
1 parent ac3e431 commit f1cce25
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions vulkano/src/command_buffer/commands/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1611,6 +1611,10 @@ fn check_dispatch(device: &Device, dimensions: [u32; 3]) -> Result<(), CheckDisp
});
}

if dimensions.contains(&0) {
return Err(CheckDispatchError::ZeroLengthDimensions);
}

Ok(())
}

Expand All @@ -1624,6 +1628,9 @@ pub enum CheckDispatchError {
/// The actual supported dimensions.
max_supported: [u32; 3],
},

/// At least one of the requested dimensions were zero.
ZeroLengthDimensions,
}

impl error::Error for CheckDispatchError {}
Expand All @@ -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 requested dimensions were zero"
}
}
)
}
Expand Down Expand Up @@ -2365,4 +2375,16 @@ mod tests {
_ => panic!(),
}
}

#[test]
fn zero_dimension_checked() {
let (device, _) = gfx_dev_and_queue!();

let attempted = [128, 1, 0];

match check_dispatch(&device, attempted) {
Err(CheckDispatchError::ZeroLengthDimensions) => {}
_ => panic!(),
}
}
}

0 comments on commit f1cce25

Please sign in to comment.