Skip to content

Commit

Permalink
get_supported_formats: simplify return type
Browse files Browse the repository at this point in the history
  • Loading branch information
victorvde committed Jun 22, 2022
1 parent 9b15b13 commit e4f10f7
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 29 deletions.
2 changes: 0 additions & 2 deletions wgpu-core/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,6 @@ pub enum IsSurfaceSupportedError {

#[derive(Clone, Debug, Error)]
pub enum GetSurfacePreferredFormatError {
#[error("no suitable format found")]
NotFound,
#[error("invalid adapter")]
InvalidAdapter,
#[error("invalid surface")]
Expand Down
6 changes: 1 addition & 5 deletions wgpu/examples/framework.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,7 @@ fn start<E: Example>(
let spawner = Spawner::new();
let mut config = wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
format: *surface
.get_supported_formats(&adapter)
.unwrap()
.first()
.unwrap(),
format: surface.get_supported_formats(&adapter)[0],
width: size.width,
height: size.height,
present_mode: wgpu::PresentMode::Mailbox,
Expand Down
6 changes: 1 addition & 5 deletions wgpu/examples/hello-triangle/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,7 @@ async fn run(event_loop: EventLoop<()>, window: Window) {
push_constant_ranges: &[],
});

let swapchain_format = *surface
.get_supported_formats(&adapter)
.unwrap()
.first()
.unwrap();
let swapchain_format = surface.get_supported_formats(&adapter)[0];

let render_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
label: None,
Expand Down
7 changes: 1 addition & 6 deletions wgpu/examples/hello-windows/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,7 @@ impl ViewportDesc {

let config = wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
format: *self
.surface
.get_supported_formats(adapter)
.unwrap()
.first()
.unwrap(),
format: self.surface.get_supported_formats(adapter)[0],
width: size.width,
height: size.height,
present_mode: wgpu::PresentMode::Fifo,
Expand Down
6 changes: 3 additions & 3 deletions wgpu/src/backend/direct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -962,12 +962,12 @@ impl crate::Context for Context {
&self,
surface: &Self::SurfaceId,
adapter: &Self::AdapterId,
) -> Option<Vec<TextureFormat>> {
) -> Vec<TextureFormat> {
let global = &self.0;
match wgc::gfx_select!(adapter => global.surface_get_supported_formats(surface.id, *adapter))
{
Ok(formats) => Some(formats),
Err(wgc::instance::GetSurfacePreferredFormatError::UnsupportedQueueFamily) => None,
Ok(formats) => formats,
Err(wgc::instance::GetSurfacePreferredFormatError::UnsupportedQueueFamily) => vec![],
Err(err) => self.handle_error_fatal(err, "Surface::get_supported_formats"),
}
}
Expand Down
7 changes: 3 additions & 4 deletions wgpu/src/backend/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1142,14 +1142,13 @@ impl crate::Context for Context {
&self,
_surface: &Self::SurfaceId,
_adapter: &Self::AdapterId,
) -> Option<Vec<wgt::TextureFormat>> {
) -> Vec<wgt::TextureFormat> {
// https://gpuweb.github.io/gpuweb/#supported-context-formats
let formats = vec![
vec![
wgt::TextureFormat::Bgra8Unorm,
wgt::TextureFormat::Rgba8Unorm,
wgt::TextureFormat::Rgba16Float,
];
Some(formats)
]
}

fn surface_configure(
Expand Down
6 changes: 2 additions & 4 deletions wgpu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ trait Context: Debug + Send + Sized + Sync {
&self,
surface: &Self::SurfaceId,
adapter: &Self::AdapterId,
) -> Option<Vec<TextureFormat>>;
) -> Vec<TextureFormat>;
fn surface_configure(
&self,
surface: &Self::SurfaceId,
Expand Down Expand Up @@ -3448,9 +3448,7 @@ impl Drop for SurfaceTexture {
impl Surface {
/// Returns a vec of supported texture formats to use for the [`Surface`] with this adapter.
/// Note: The first format in the vector is preferred
///
/// Returns None if the surface is incompatible with the adapter.
pub fn get_supported_formats(&self, adapter: &Adapter) -> Option<Vec<TextureFormat>> {
pub fn get_supported_formats(&self, adapter: &Adapter) -> Vec<TextureFormat> {
Context::surface_get_supported_formats(&*self.context, &self.id, &adapter.id)
}

Expand Down

0 comments on commit e4f10f7

Please sign in to comment.