Skip to content

Commit

Permalink
Validate surface against max texture size
Browse files Browse the repository at this point in the history
  • Loading branch information
Wumpf committed Nov 29, 2023
1 parent 4c9f8a0 commit c7d1f04
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
15 changes: 14 additions & 1 deletion wgpu-core/src/device/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1809,10 +1809,19 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
fn validate_surface_configuration(
config: &mut hal::SurfaceConfiguration,
caps: &hal::SurfaceCapabilities,
max_texture_dimension_2d: u32,
) -> Result<(), E> {
let width = config.extent.width;
let height = config.extent.height;

if width > max_texture_dimension_2d || height > max_texture_dimension_2d {
return Err(E::TooLarge {
width,
height,
max_texture_dimension_2d,
});
}

if !caps.present_modes.contains(&config.present_mode) {
let new_mode = 'b: loop {
// Automatic present mode checks.
Expand Down Expand Up @@ -1986,7 +1995,11 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
view_formats: hal_view_formats,
};

if let Err(error) = validate_surface_configuration(&mut hal_config, &caps) {
if let Err(error) = validate_surface_configuration(
&mut hal_config,
&caps,
device.limits.max_texture_dimension_2d,
) {
break error;
}

Expand Down
6 changes: 6 additions & 0 deletions wgpu-core/src/present.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ pub enum ConfigureSurfaceError {
PreviousOutputExists,
#[error("Both `Surface` width and height must be non-zero. Wait to recreate the `Surface` until the window has non-zero area.")]
ZeroArea,
#[error("`Surface` width and height must be within the maximum supported texture size. Requested was ({width}, height), maximum extent is {max_texture_dimension_2d}.")]
TooLarge {
width: u32,
height: u32,
max_texture_dimension_2d: u32,
},
#[error("Surface does not support the adapter's queue family")]
UnsupportedQueueFamily,
#[error("Requested format {requested:?} is not in list of supported formats: {available:?}")]
Expand Down

0 comments on commit c7d1f04

Please sign in to comment.