Repository: bevyengine/bevy
File: crates/bevy_render/src/renderer/mod.rs (Rust)

Code before:
            max_subgroup_size: limits
                .max_subgroup_size
                .min(constrained_limits.max_subgroup_size),
            max_acceleration_structures_per_shader_stage: limits
                .max_acceleration_structures_per_shader_stage
                .min(constrained_limits.max_acceleration_structures_per_shader_stage),
            max_task_workgroup_total_count: limits
                .max_task_workgroup_total_count
                .min(constrained_limits.max_task_workgroup_total_count),
            max_task_workgroups_per_dimension: limits
                .max_task_workgroups_per_dimension
                .min(constrained_limits.max_task_workgroups_per_dimension),
            max_mesh_output_layers: limits
                .max_mesh_output_layers
                .min(constrained_limits.max_mesh_output_layers),
            max_mesh_multiview_count: limits
                .max_mesh_multiview_count
                .min(constrained_limits.max_mesh_multiview_count),
        };
    }

    let device_descriptor = wgpu::DeviceDescriptor {
        label: options.device_label.as_ref().map(AsRef::as_ref),
        required_features: features,
        required_limits: limits,
        // SAFETY: We're ok using experimental wgpu features in Bevy
        experimental_features: unsafe { wgpu::ExperimentalFeatures::enabled() },
        memory_hints: options.memory_hints.clone(),
        // See https://github.com/gfx-rs/wgpu/issues/5974
        trace: Trace::Off,
    };

    #[cfg(not(feature = "raw_vulkan_init"))]
    let (device, queue) = adapter.request_device(&device_descriptor).await.unwrap();

    #[cfg(feature = "raw_vulkan_init")]
    let (device, queue) = raw_vulkan_init::create_raw_device(
        &adapter,
        &device_descriptor,
        &raw_vulkan_init_settings,
        &mut additional_vulkan_features,
    )
    .await
    .unwrap();

    debug!("Configured wgpu adapter Limits: {:#?}", device.limits());
    debug!("Configured wgpu adapter Features: {:#?}", device.features());

    RenderResources(
        RenderDevice::from(device),
        RenderQueue(Arc::new(WgpuWrapper::new(queue))),

Review comment (bug):
Note that experimental features are not just features that may not work properly — they are features that can cause undefined behavior, which is why this is `unsafe`. Consider that a *user of Bevy rendering* might prefer not to enter that territory. Are you sure that you want to enable this unconditionally?

Regardless of the answer to that question, this `// SAFETY` comment could be improved.

Code after:
            max_subgroup_size: limits
                .max_subgroup_size
                .min(constrained_limits.max_subgroup_size),
            max_acceleration_structures_per_shader_stage: limits
                .max_acceleration_structures_per_shader_stage
                .min(constrained_limits.max_acceleration_structures_per_shader_stage),
            max_task_workgroup_total_count: limits
                .max_task_workgroup_total_count
                .min(constrained_limits.max_task_workgroup_total_count),
            max_task_workgroups_per_dimension: limits
                .max_task_workgroups_per_dimension
                .min(constrained_limits.max_task_workgroups_per_dimension),
            max_mesh_output_layers: limits
                .max_mesh_output_layers
                .min(constrained_limits.max_mesh_output_layers),
            max_mesh_multiview_count: limits
                .max_mesh_multiview_count
                .min(constrained_limits.max_mesh_multiview_count),
        };
    }

    let device_descriptor = wgpu::DeviceDescriptor {
        label: options.device_label.as_ref().map(AsRef::as_ref),
        required_features: features,
        required_limits: limits,
        // SAFETY: TODO, see https://github.com/bevyengine/bevy/issues/22082
        experimental_features: unsafe { wgpu::ExperimentalFeatures::enabled() },
        memory_hints: options.memory_hints.clone(),
        // See https://github.com/gfx-rs/wgpu/issues/5974
        trace: Trace::Off,
    };

    #[cfg(not(feature = "raw_vulkan_init"))]
    let (device, queue) = adapter.request_device(&device_descriptor).await.unwrap();

    #[cfg(feature = "raw_vulkan_init")]
    let (device, queue) = raw_vulkan_init::create_raw_device(
        &adapter,
        &device_descriptor,
        &raw_vulkan_init_settings,
        &mut additional_vulkan_features,
    )
    .await
    .unwrap();

    debug!("Configured wgpu adapter Limits: {:#?}", device.limits());
    debug!("Configured wgpu adapter Features: {:#?}", device.features());

    RenderResources(
        RenderDevice::from(device),
        RenderQueue(Arc::new(WgpuWrapper::new(queue))),