pub struct GpuContextConfig {
pub backend: BackendPreference,
pub power_preference: GpuPowerPreference,
pub required_features: Features,
pub required_limits: Option<Limits>,
pub debug: bool,
pub label: Option<String>,
}Expand description
Configuration for GPU context initialization.
Fields§
§backend: BackendPreferenceBackend preference for adapter selection.
power_preference: GpuPowerPreferencePower preference for GPU selection.
required_features: FeaturesRequired GPU features.
required_limits: Option<Limits>Required GPU limits.
debug: boolEnable debug mode (validation layers).
label: Option<String>Label for the device (for debugging).
Implementations§
Source§impl GpuContextConfig
impl GpuContextConfig
Sourcepub fn with_backend(self, backend: BackendPreference) -> Self
pub fn with_backend(self, backend: BackendPreference) -> Self
Set backend preference.
Sourcepub fn with_power_preference(self, power: GpuPowerPreference) -> Self
pub fn with_power_preference(self, power: GpuPowerPreference) -> Self
Set power preference.
Sourcepub fn with_features(self, features: Features) -> Self
pub fn with_features(self, features: Features) -> Self
Set required features.
Sourcepub fn with_limits(self, limits: Limits) -> Self
pub fn with_limits(self, limits: Limits) -> Self
Set required limits.
Sourcepub fn with_debug(self, debug: bool) -> Self
pub fn with_debug(self, debug: bool) -> Self
Enable debug mode.
Sourcepub fn with_label(self, label: impl Into<String>) -> Self
pub fn with_label(self, label: impl Into<String>) -> Self
Set device label.
Sourcepub fn with_f16_support(self) -> Self
pub fn with_f16_support(self) -> Self
Request SHADER_F16 GPU feature support.
When this flag is set the context will require the adapter to expose
wgpu::Features::SHADER_F16, which enables the enable f16;
directive in WGSL shaders and allows native half-precision arithmetic
on the GPU.
§Availability
Not all adapters support this feature. Check with
GpuContext::supports_feature after context creation. If the
adapter lacks support, context creation will fail — consider first
checking via wgpu::Adapter::features or falling back to the
widening path provided by crate::buffer::from_f16_slice_widening.
Sourcepub fn with_push_constants(self) -> Self
pub fn with_push_constants(self) -> Self
Request IMMEDIATES GPU feature support (push constants).
When this flag is set the context will require the adapter to expose
wgpu::Features::IMMEDIATES, which enables:
var<immediate>variables in WGSL shaders.wgpu::PipelineLayoutDescriptor::immediate_size> 0.wgpu::ComputePass::set_immediates/wgpu::RenderPass::set_immediates.
This corresponds to Vulkan push constants and is available on Vulkan, Metal, DX12, and WebGPU (as a proposal).
§Availability
Check adapter support before requesting this feature. If unsupported, use a uniform buffer to pass small per-dispatch constants instead.
Sourcepub fn with_cooperative_matrix(self) -> Self
pub fn with_cooperative_matrix(self) -> Self
Request cooperative-matrix and subgroup GPU features.
When this flag is set the context will attempt to request:
wgpu::Features::EXPERIMENTAL_COOPERATIVE_MATRIX— hardware tile MMA (WMMA / tensor-core) support.wgpu::Features::SUBGROUP— subgroup intrinsics in compute and fragment shaders (required by the cooperative-matrix extension).
Both flags are added to GpuContextConfig::required_features.
If the adapter does not expose these features, context creation will
fail. Use crate::cooperative_matrix::supports_cooperative_matrix
after creating a context without this method to check availability
before upgrading.
§Fallback
The workgroup-tiled GEMM path in
crate::cooperative_matrix::build_cooperative_matrix_gemm_pipeline
is correct on all adapters regardless of this flag. Requesting
cooperative-matrix features is only necessary when the shader code
explicitly uses subgroupMatrix* builtins.
Sourcepub async fn build(self) -> GpuResult<GpuContext>
pub async fn build(self) -> GpuResult<GpuContext>
Build a GpuContext from this configuration.
Convenience async builder that calls GpuContext::with_config.
§Errors
Returns an error if no suitable GPU adapter is found or device request fails (e.g., a required feature is unsupported).
Trait Implementations§
Source§impl Clone for GpuContextConfig
impl Clone for GpuContextConfig
Source§fn clone(&self) -> GpuContextConfig
fn clone(&self) -> GpuContextConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more