Skip to content

Commit

Permalink
add validate_texture_view_plane
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaopengli89 committed Nov 17, 2023
1 parent 317b832 commit 9c2a1b9
Showing 1 changed file with 25 additions and 27 deletions.
52 changes: 25 additions & 27 deletions wgpu-core/src/device/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1055,33 +1055,7 @@ impl<A: HalApi> Device<A> {
});
};

match (texture.desc.format, resolved_format, desc.plane) {
(
wgt::TextureFormat::NV12,
wgt::TextureFormat::R8Unorm | wgt::TextureFormat::R8Uint,
Some(0),
) => {}
(
wgt::TextureFormat::NV12,
wgt::TextureFormat::Rg8Unorm | wgt::TextureFormat::Rg8Uint,
Some(1),
) => {}
(wgt::TextureFormat::NV12, _, _) => {
return Err(resource::CreateTextureViewError::InvalidTextureViewPlane {
plane: desc.plane,
view_format: resolved_format,
});
}
(_, _, Some(_)) => {
return Err(
resource::CreateTextureViewError::InvalidTextureViewPlaneOnNonplanarTexture {
plane: desc.plane,
texture_format: texture.desc.format,
},
);
}
_ => {}
}
validate_texture_view_plane(texture.desc.format, resolved_format, desc.plane)?;

// https://gpuweb.github.io/gpuweb/#abstract-opdef-renderable-texture-view
let render_extent = 'b: loop {
Expand Down Expand Up @@ -3491,3 +3465,27 @@ fn check_texture_view_format_compatible(
_ => texture_format.remove_srgb_suffix() == view_format.remove_srgb_suffix(),
}
}

fn validate_texture_view_plane(
texture_format: TextureFormat,
view_format: TextureFormat,
plane: Option<u32>,
) -> Result<(), resource::CreateTextureViewError> {
use TextureFormat::*;

match (texture_format, view_format, plane) {
(NV12, R8Unorm | R8Uint, Some(0)) => Ok(()),
(NV12, Rg8Unorm | Rg8Uint, Some(1)) => Ok(()),
(NV12, _, _) => {
Err(resource::CreateTextureViewError::InvalidTextureViewPlane { plane, view_format })
}

(_, _, Some(_)) => Err(
resource::CreateTextureViewError::InvalidTextureViewPlaneOnNonplanarTexture {
plane,
texture_format,
},
),
_ => Ok(()),
}
}

0 comments on commit 9c2a1b9

Please sign in to comment.