From adcd708cf16247f2468f5337c91d3860f174678b Mon Sep 17 00:00:00 2001 From: Connor Fitzgerald Date: Tue, 13 Jul 2021 00:07:10 -0400 Subject: [PATCH] Fix example limits --- wgpu-types/src/lib.rs | 14 ++++++++++++++ wgpu/examples/framework.rs | 8 +++----- wgpu/examples/hello-triangle/main.rs | 3 ++- wgpu/tests/common/mod.rs | 2 +- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index 3b17b82be6..51ed60c4b4 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -631,6 +631,20 @@ impl Limits { max_push_constant_size: 0, } } + + /// Modify the current limits to use the resolution limits of the other. + /// + /// This is useful because the swapchain might need to be larger than any other image in the application. + /// + /// If your application only needs 512x512, you might be running on a 4k display and need extremely high resolution limits. + pub fn using_resolution(self, other: Self) -> Self { + Self { + max_texture_dimension_1d: other.max_texture_dimension_1d, + max_texture_dimension_2d: other.max_texture_dimension_2d, + max_texture_dimension_3d: other.max_texture_dimension_3d, + ..self + } + } } /// Represents the sets of additional limits on an adapter, diff --git a/wgpu/examples/framework.rs b/wgpu/examples/framework.rs index f55d3b25e3..a45308ebbd 100644 --- a/wgpu/examples/framework.rs +++ b/wgpu/examples/framework.rs @@ -137,7 +137,8 @@ async fn setup(title: &str) -> Setup { required_features - adapter_features ); - let needed_limits = E::required_limits(); + // Make sure we use the texture resolution limits from the adapter, so we can support images the size of the swapchain. + let needed_limits = E::required_limits().using_resolution(adapter.limits()); let trace_dir = std::env::var("WGPU_TRACE"); let (device, queue) = adapter @@ -396,10 +397,7 @@ pub fn test(mut params: FrameworkRefTest) { assert_eq!(params.width % 64, 0, "width needs to be aligned 64"); let features = E::required_features() | params.optional_features; - let mut limits = E::required_limits(); - if limits == wgpu::Limits::default() { - limits = test_common::lowest_reasonable_limits(); - } + let limits = E::required_limits(); test_common::initialize_test( mem::take(&mut params.base_test_parameters) diff --git a/wgpu/examples/hello-triangle/main.rs b/wgpu/examples/hello-triangle/main.rs index 8823138911..cbd20f508c 100644 --- a/wgpu/examples/hello-triangle/main.rs +++ b/wgpu/examples/hello-triangle/main.rs @@ -24,7 +24,8 @@ async fn run(event_loop: EventLoop<()>, window: Window) { &wgpu::DeviceDescriptor { label: None, features: wgpu::Features::empty(), - limits: wgpu::Limits::downlevel_defaults(), + // Make sure we use the texture resolution limits from the adapter, so we can support images the size of the swapchain. + limits: wgpu::Limits::downlevel_defaults().using_resolution(adapter.limits()), }, None, ) diff --git a/wgpu/tests/common/mod.rs b/wgpu/tests/common/mod.rs index d365caf6a2..90288d5a88 100644 --- a/wgpu/tests/common/mod.rs +++ b/wgpu/tests/common/mod.rs @@ -91,7 +91,7 @@ impl Default for TestParameters { fn default() -> Self { Self { required_features: Features::empty(), - required_limits: lowest_reasonable_limits(), + required_limits: Limits::downlevel_defaults(), required_downlevel_properties: lowest_downlevel_properties(), failures: Vec::new(), }