Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exceeded max_storage_buffer_binding_size Limit Causes Panic #9

Open
EtaCassiopeia opened this issue Jun 30, 2024 · 0 comments
Open

Comments

@EtaCassiopeia
Copy link
Contributor

EtaCassiopeia commented Jun 30, 2024

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,
        }
    }
}
EtaCassiopeia added a commit to EtaCassiopeia/web-splat that referenced this issue Jun 30, 2024
… limits

Query adapter limits and set max_storage_buffer_binding_size to the maximum
supported value to prevent runtime panics due to exceeded limits.

Addresses issue KeKsBoTer#9.
KeKsBoTer pushed a commit that referenced this issue Jul 1, 2024
… limits

Query adapter limits and set max_storage_buffer_binding_size to the maximum
supported value to prevent runtime panics due to exceeded limits.

Addresses issue #9.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant