Skip to content

Commit

Permalink
Update Limits for WASM and Examples
Browse files Browse the repository at this point in the history
  • Loading branch information
zicklag committed Oct 6, 2021
1 parent c4550e0 commit eab6a3f
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 25 deletions.
5 changes: 5 additions & 0 deletions wgpu-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -692,10 +692,15 @@ impl Limits {
/// These default limits are guarenteed to be compatible with GLES3, and D3D11, and WebGL2
pub fn downlevel_webgl2_defaults() -> Self {
Self {
#[cfg(target_arch = "wasm32")]
max_storage_buffers_per_shader_stage: 0,
#[cfg(target_arch = "wasm32")]
max_storage_textures_per_shader_stage: 0,
#[cfg(target_arch = "wasm32")]
max_dynamic_storage_buffers_per_pipeline_layout: 0,
#[cfg(target_arch = "wasm32")]
max_storage_buffer_binding_size: 0,
#[cfg(target_arch = "wasm32")]
max_vertex_buffer_array_stride: 255,

// Most of the values should be the same as the downlevel defaults
Expand Down
2 changes: 1 addition & 1 deletion wgpu/examples/boids/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct Example {
}

impl framework::Example for Example {
fn required_limits(_: &wgpu::Adapter) -> wgpu::Limits {
fn required_limits() -> wgpu::Limits {
wgpu::Limits::downlevel_defaults()
}

Expand Down
5 changes: 2 additions & 3 deletions wgpu/examples/framework.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ pub trait Example: 'static + Sized {
..wgpu::DownlevelCapabilities::default()
}
}
fn required_limits(adapter: &wgpu::Adapter) -> wgpu::Limits {
let _ = adapter;
fn required_limits() -> wgpu::Limits {
wgpu::Limits::downlevel_webgl2_defaults() // These downlevel limits will allow the code to run on all possible hardware
}
fn init(
Expand Down Expand Up @@ -167,7 +166,7 @@ async fn setup<E: Example>(title: &str) -> Setup {
);

// Make sure we use the texture resolution limits from the adapter, so we can support images the size of the surface.
let needed_limits = E::required_limits(&adapter).using_resolution(adapter.limits());
let needed_limits = E::required_limits().using_resolution(adapter.limits());

let trace_dir = std::env::var("WGPU_TRACE");
let (device, queue) = adapter
Expand Down
22 changes: 2 additions & 20 deletions wgpu/examples/shadow/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,25 +213,6 @@ impl framework::Example for Example {
wgpu::Features::DEPTH_CLAMPING
}

fn required_limits(adapter: &wgpu::Adapter) -> wgpu::Limits {
let downlevel_limits = wgpu::Limits::downlevel_defaults();
let webgl_limits = wgpu::Limits::downlevel_webgl2_defaults();
if adapter
.get_downlevel_properties()
.flags
.contains(wgpu::DownlevelFlags::VERTEX_STORAGE | wgpu::DownlevelFlags::FRAGMENT_STORAGE)
{
wgpu::Limits {
max_storage_buffers_per_shader_stage: downlevel_limits
.max_storage_buffers_per_shader_stage,
max_storage_buffer_binding_size: downlevel_limits.max_storage_buffer_binding_size,
..webgl_limits
}
} else {
webgl_limits
}
}

fn init(
sc_desc: &wgpu::SurfaceConfiguration,
adapter: &wgpu::Adapter,
Expand All @@ -241,7 +222,8 @@ impl framework::Example for Example {
let supports_storage_resources = adapter
.get_downlevel_properties()
.flags
.contains(wgpu::DownlevelFlags::VERTEX_STORAGE);
.contains(wgpu::DownlevelFlags::VERTEX_STORAGE)
&& device.limits().max_storage_buffers_per_shader_stage > 0;

// Create the vertex and index buffers
let vertex_size = mem::size_of::<Vertex>();
Expand Down
2 changes: 1 addition & 1 deletion wgpu/examples/texture-arrays/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl framework::Example for Example {
fn required_features() -> wgpu::Features {
wgpu::Features::TEXTURE_BINDING_ARRAY | wgpu::Features::SPIRV_SHADER_PASSTHROUGH
}
fn required_limits(_: &wgpu::Adapter) -> wgpu::Limits {
fn required_limits() -> wgpu::Limits {
wgpu::Limits {
max_push_constant_size: 4,
..wgpu::Limits::default()
Expand Down

0 comments on commit eab6a3f

Please sign in to comment.