web-splat
web-splat copied to clipboard
Exceeded max_storage_buffer_binding_size Limit Causes Panic
Description
The viewer encounters an error where the max_storage_buffer_binding_size
limit is exceeded, causing a panic. The current setup requests a buffer size that surpasses the allowed limit of the GPU, resulting in a runtime panic.
Error Message
thread 'main' panicked at /home/mohsen/code/gs-viewer/web-splat/src/lib.rs:123:14:
called `Result::unwrap()` on an `Err` value: RequestDeviceError { inner: Core(LimitsExceeded(FailedLimit { name: "max_storage_buffer_binding_size", requested: 1073741823, allowed: 134217728 })) }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Proposed Solution
Modify the WGPUContext
setup to dynamically query the adapter limits and set the maximum values supported by the GPU. This approach ensures that the application respects the hardware capabilities and avoids exceeding the limits.
impl WGPUContext {
pub async fn new(instance: &wgpu::Instance, surface: Option<&wgpu::Surface<'static>>) -> Self {
let adapter = wgpu::util::initialize_adapter_from_env_or_default(instance, surface)
.await
.unwrap();
log::info!("using {}", adapter.get_info().name);
#[cfg(target_arch = "wasm32")]
let required_features = wgpu::Features::default();
#[cfg(not(target_arch = "wasm32"))]
let required_features = wgpu::Features::TIMESTAMP_QUERY
| wgpu::Features::TEXTURE_FORMAT_16BIT_NORM
| wgpu::Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES;
let adapter_limits = adapter.limits();
let (device, queue) = adapter
.request_device(
&wgpu::DeviceDescriptor {
required_features,
required_limits: wgpu::Limits {
max_storage_buffer_binding_size: adapter_limits.max_storage_buffer_binding_size,
max_buffer_size: adapter_limits.max_buffer_size,
max_storage_buffers_per_shader_stage: adapter_limits.max_storage_buffers_per_shader_stage,
max_compute_workgroup_storage_size: adapter_limits.max_compute_workgroup_storage_size,
..adapter_limits
},
label: None,
},
None,
)
.await
.unwrap();
Self {
device,
queue,
adapter,
}
}
}