### Create BufferSlice instances Source: https://docs.rs/wgpu/latest/wgpu/struct.BufferSlice.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Examples of creating slices from a buffer using range syntax. ```rust let slice = buffer.slice(10..20); ``` ```rust let whole_buffer_slice = buffer.slice(..); ``` -------------------------------- ### Sampler Binding Syntax Source: https://docs.rs/wgpu/latest/wgpu/enum.BindingType.html Shader syntax examples for declaring a sampler binding. ```wgsl @group(0) @binding(0) var s: sampler; ``` ```glsl layout(binding = 0) uniform sampler s; ``` -------------------------------- ### Uint Texture Sampling Syntax Source: https://docs.rs/wgpu/latest/wgpu/enum.TextureSampleType.html Syntax examples for unsigned integer texture sampling in WGSL and GLSL. ```wgsl @group(0) @binding(0) var t: texture_2d; ``` ```glsl layout(binding = 0) uniform utexture2D t; ``` -------------------------------- ### Storage Buffer Syntax Source: https://docs.rs/wgpu/latest/wgpu/enum.BufferBindingType.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Examples of defining a storage buffer in WGSL and GLSL. ```wgsl @group(0) @binding(0) var my_element: array>; ``` ```glsl layout (set=0, binding=0) buffer myStorageBuffer { vec4 myElement[]; }; ``` -------------------------------- ### Texture Binding Syntax Source: https://docs.rs/wgpu/latest/wgpu/enum.BindingType.html Shader syntax examples for declaring a texture binding. ```wgsl @group(0) @binding(0) var t: texture_2d; ``` ```glsl layout(binding = 0) uniform texture2D t; ``` -------------------------------- ### Acceleration Structure Binding Syntax Source: https://docs.rs/wgpu/latest/wgpu/enum.BindingType.html Shader syntax examples for declaring a ray-tracing acceleration structure binding. ```wgsl @group(0) @binding(0) var as: acceleration_structure; ``` ```wgsl @group(0) @binding(0) var as: acceleration_structure; ``` ```glsl layout(binding = 0) uniform accelerationStructureEXT as; ``` -------------------------------- ### Sint Texture Sampling Syntax Source: https://docs.rs/wgpu/latest/wgpu/enum.TextureSampleType.html Syntax examples for signed integer texture sampling in WGSL and GLSL. ```wgsl @group(0) @binding(0) var t: texture_2d; ``` ```glsl layout(binding = 0) uniform itexture2D t; ``` -------------------------------- ### Buffer Binding Array Syntax Source: https://docs.rs/wgpu/latest/wgpu/struct.FeaturesWGPU.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Examples of declaring arrays of buffers in WGSL and GLSL. ```WGSL var buffer_array: array ``` ```GLSL uniform myBuffer { ... } buffer_array[10] ``` ```WGSL var buffer_array: array ``` ```GLSL buffer myBuffer { ... } buffer_array[10] ``` -------------------------------- ### Depth Texture Sampling Syntax Source: https://docs.rs/wgpu/latest/wgpu/enum.TextureSampleType.html Syntax examples for depth texture sampling in WGSL and GLSL. ```wgsl @group(0) @binding(0) var t: texture_depth_2d; ``` ```glsl layout(binding = 0) uniform texture2DShadow t; ``` -------------------------------- ### Storage Texture Binding Syntax Source: https://docs.rs/wgpu/latest/wgpu/enum.BindingType.html Shader syntax examples for declaring a storage texture binding. ```wgsl @group(0) @binding(0) var my_storage_image: texture_storage_2d; ``` ```glsl layout(set=0, binding=0, r32f) writeonly uniform image2D myStorageImage; ``` -------------------------------- ### pub fn get(&self) -> &[Option] Source: https://docs.rs/wgpu/latest/wgpu/struct.Tlas.html?search=std%3A%3Avec Retrieves a reference to all instances contained within the TLAS. ```APIDOC ## pub fn get(&self) -> &[Option] ### Description Returns a reference to the slice of all instances currently held by the TLAS. ### Returns - `&[Option]` - A slice containing the instances. ``` -------------------------------- ### Instance::new Source: https://docs.rs/wgpu/latest/wgpu/struct.Instance.html Creates a new instance of wgpu using the given options and enabled backends. ```APIDOC ## pub fn new(desc: InstanceDescriptor) -> Self ### Description Create an new instance of wgpu using the given options and enabled backends. ### Parameters - **desc** (InstanceDescriptor) - Required - Configuration options for the instance. ### Panics If no backend feature for the active target platform is enabled, this method will panic. ``` -------------------------------- ### NonZero Bit Manipulation Examples Source: https://docs.rs/wgpu/latest/wgpu/type.BufferSize.html?search=std%3A%3Avec Examples demonstrating bit manipulation methods for NonZero. ```rust let n = NonZero::::new(u64::MAX)?; assert_eq!(n.leading_zeros(), 0); ``` ```rust let n = NonZero::::new(0b0101000)?; assert_eq!(n.trailing_zeros(), 3); ``` ```rust let a = NonZero::::new(0b_01100100)?; let b = NonZero::::new(0b_01000000)?; assert_eq!(a.isolate_highest_one(), b); ``` ```rust let a = NonZero::::new(0b_01100100)?; let b = NonZero::::new(0b_00000100)?; assert_eq!(a.isolate_lowest_one(), b); ``` ```rust assert_eq!(NonZero::::new(0b1)?.highest_one(), 0); assert_eq!(NonZero::::new(0b1_0000)?.highest_one(), 4); assert_eq!(NonZero::::new(0b1_1111)?.highest_one(), 4); ``` -------------------------------- ### Instance::new Source: https://docs.rs/wgpu/latest/wgpu/struct.Instance.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Creates a new instance of wgpu using the provided InstanceDescriptor. ```APIDOC ## pub fn new(desc: InstanceDescriptor) -> Self ### Description Creates a new instance of wgpu using the given options and enabled backends. ### Panics If no backend feature for the active target platform is enabled, this method will panic. ``` -------------------------------- ### offset Source: https://docs.rs/wgpu/latest/wgpu/struct.BufferSlice.html?search= Returns the starting offset of the slice. ```APIDOC ## pub fn offset(&self) -> BufferAddress ### Description Returns the byte offset within the parent buffer where this slice begins. ``` -------------------------------- ### HasWindowHandle::window_handle Source: https://docs.rs/wgpu/latest/wgpu/type.ErrorSource.html?search= Get a handle to the window. ```APIDOC ### fn window_handle(&self) -> Result, HandleError> Get a handle to the window. ``` -------------------------------- ### initialize_adapter_from_env_or_default Source: https://docs.rs/wgpu/latest/wgpu/util/fn.initialize_adapter_from_env_or_default.html Initializes the adapter obeying the WGPU_ADAPTER_NAME environment variable and if it doesn’t exist fall back on a default adapter. ```APIDOC ## Function: initialize_adapter_from_env_or_default ### Description Initializes the adapter obeying the `WGPU_ADAPTER_NAME` environment variable and if it doesn’t exist fall back on a default adapter. ### Signature `pub async fn initialize_adapter_from_env_or_default(instance: &Instance, compatible_surface: Option<&Surface<'_>>) -> Result` ### Parameters - **instance** (&Instance) - Required - The wgpu instance to use for adapter creation. - **compatible_surface** (Option<&Surface<'_>>) - Required - An optional surface to ensure the adapter is compatible with. ### Returns - **Result** - Returns an Ok(Adapter) on success, or a RequestAdapterError if the adapter could not be initialized. ``` -------------------------------- ### configure Source: https://docs.rs/wgpu/latest/wgpu/struct.Surface.html Initializes the Surface for presentation. ```APIDOC ## pub fn configure(&self, device: &Device, config: &SurfaceConfiguration) ### Description Initializes Surface for presentation. If already configured, it waits for the GPU to idle before recreating the swapchain. ``` -------------------------------- ### Option::as_ref Example Source: https://docs.rs/wgpu/latest/wgpu/type.Label.html Converts an Option to an Option<&T>. ```rust let text: Option = Some("Hello, world!".to_string()); // First, cast `Option` to `Option<&String>` with `as_ref`, // then consume *that* with `map`, leaving `text` on the stack. let text_length: Option = text.as_ref().map(|s| s.len()); println!("still can print text: {text:?}"); ``` -------------------------------- ### GlBackendOptions Initialization Methods Source: https://docs.rs/wgpu/latest/wgpu/struct.GlBackendOptions.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Methods to configure backend options using environment variables. ```rust pub fn from_env_or_default() -> GlBackendOptions ``` ```rust pub fn with_env(self) -> GlBackendOptions ``` -------------------------------- ### Option::is_none Example Source: https://docs.rs/wgpu/latest/wgpu/type.Label.html Checks if an Option is None. ```rust let x: Option = Some(2); assert_eq!(x.is_none(), false); let x: Option = None; assert_eq!(x.is_none(), true); ``` -------------------------------- ### begin_occlusion_query Source: https://docs.rs/wgpu/latest/wgpu/struct.RenderPass.html Starts an occlusion query on the render pass. ```APIDOC ## pub fn begin_occlusion_query(&mut self, query_index: u32) ### Description Start an occlusion query on this render pass. Occlusion queries may not be nested. ### Parameters - **query_index** (u32) - The index of the query. ``` -------------------------------- ### Default::default() Source: https://docs.rs/wgpu/latest/wgpu/struct.Instance.html Creates a new instance of wgpu with default options, including all backends and default shader compiler settings. ```APIDOC ## fn default() -> Self ### Description Creates a new instance of wgpu with default options. Backends are set to `Backends::all()`, and FXC is chosen as the `dx12_shader_compiler`. ### Panics If no backend feature for the active target platform is enabled, this method will panic. ``` -------------------------------- ### Option::as_mut Example Source: https://docs.rs/wgpu/latest/wgpu/type.Label.html Converts an Option to an Option<&mut T>. ```rust let mut x = Some(2); match x.as_mut() { Some(v) => *v = 42, None => {}, } assert_eq!(x, Some(42)); ``` -------------------------------- ### from_core Source: https://docs.rs/wgpu/latest/wgpu/struct.Instance.html Creates a new instance of wgpu from a wgpu-core instance. ```APIDOC ## pub unsafe fn from_core(core_instance: Instance) -> Self ### Description Create an new instance of wgpu from a wgpu-core instance. ### Safety Refer to the creation of wgpu-core Instance. ``` -------------------------------- ### Option::is_some Example Source: https://docs.rs/wgpu/latest/wgpu/type.Label.html Checks if an Option contains a value. ```rust let x: Option = Some(2); assert_eq!(x.is_some(), true); let x: Option = None; assert_eq!(x.is_some(), false); ``` -------------------------------- ### initialize_adapter_from_env Source: https://docs.rs/wgpu/latest/wgpu/util/fn.initialize_adapter_from_env.html?search=std%3A%3Avec Initializes the adapter obeying the WGPU_ADAPTER_NAME environment variable. ```APIDOC ## Function: initialize_adapter_from_env ### Description Initializes the adapter obeying the `WGPU_ADAPTER_NAME` environment variable. ### Signature `pub async fn initialize_adapter_from_env(instance: &Instance, compatible_surface: Option<&Surface<'_>>) -> Result` ### Parameters - **instance** (&Instance) - The wgpu instance to use for adapter creation. - **compatible_surface** (Option<&Surface<'_>>) - An optional surface to ensure the adapter is compatible with. ### Returns - **Result** - Returns an `Adapter` on success, or a `RequestAdapterError` if initialization fails. ``` -------------------------------- ### starts_with Source: https://docs.rs/wgpu/latest/wgpu/struct.BufferView.html?search= Returns true if the slice starts with the provided needle. ```APIDOC ## pub fn starts_with(&self, needle: &[T]) -> bool ### Description Returns `true` if `needle` is a prefix of the slice or equal to the slice. ``` -------------------------------- ### new_instance_with_webgpu_detection Source: https://docs.rs/wgpu/latest/wgpu/util/fn.new_instance_with_webgpu_detection.html Creates a new instance of wgpu, disabling Backends::BROWSER_WEBGPU if WebGPU support is not detected. ```APIDOC ## pub async fn new_instance_with_webgpu_detection(instance_desc: InstanceDescriptor) -> Instance ### Description Creates a new instance of wgpu, but disables `Backends::BROWSER_WEBGPU` if no WebGPU support is detected. This is the preferred method over `Instance::new` when targeting WebGPU with an automatic fallback to WebGL. ### Parameters - **instance_desc** (InstanceDescriptor) - The descriptor used to configure the wgpu instance. ### Returns - **Instance** - A new wgpu instance configured based on detected WebGPU support. ### Panics - Panics if no backend feature for the active target platform is enabled. ``` -------------------------------- ### begin_pipeline_statistics_query Source: https://docs.rs/wgpu/latest/wgpu/struct.ComputePass.html Starts a pipeline statistics query on the compute pass. ```APIDOC ## pub fn begin_pipeline_statistics_query(&mut self, query_set: &QuerySet, query_index: u32) ### Description Starts a pipeline statistics query. Requires `Features::PIPELINE_STATISTICS_QUERY` to be enabled. Queries may not be nested. ``` -------------------------------- ### initialize_adapter_from_env_or_default function signature Source: https://docs.rs/wgpu/latest/wgpu/util/fn.initialize_adapter_from_env_or_default.html?search=std%3A%3Avec The function signature for initializing a wgpu adapter with an optional surface. ```rust pub async fn initialize_adapter_from_env_or_default( instance: &Instance, compatible_surface: Option<&Surface<'_>>, ) -> Result ``` -------------------------------- ### Map and write to a wgpu buffer Source: https://docs.rs/wgpu/latest/wgpu/struct.Buffer.html Demonstrates how to map a buffer with BufferUsages::MAP_WRITE and fill it with f32 values using a callback. ```rust let capturable = buffer.clone(); buffer.map_async(wgpu::MapMode::Write, .., move |result| { if result.is_ok() { let mut view = capturable.get_mapped_range_mut(..).unwrap(); let mut floats: wgpu::WriteOnly<[[u8; 4]]> = view.slice(..).into_chunks::<4>().0; floats.fill(42.0f32.to_ne_bytes()); drop(view); capturable.unmap(); } }); ``` -------------------------------- ### get Source: https://docs.rs/wgpu/latest/wgpu/struct.ForceShaderModelToken.html Retrieves the shader model version associated with the token. ```APIDOC ## pub fn get(&self) -> Option ### Description Returns the shader model version, if any, in this token. ``` -------------------------------- ### NoopBackendOptions::from_env_or_default Source: https://docs.rs/wgpu/latest/wgpu/struct.NoopBackendOptions.html Creates a NoopBackendOptions instance based on the WGPU_NOOP_BACKEND environment variable. ```APIDOC ## fn from_env_or_default() ### Description Choose whether the noop backend is enabled from the environment. It will be enabled if the environment variable `WGPU_NOOP_BACKEND` has the value `1` and not otherwise. ### Signature `pub fn from_env_or_default() -> NoopBackendOptions` ``` -------------------------------- ### Get Slice Length Source: https://docs.rs/wgpu/latest/wgpu/struct.BufferView.html?search=std%3A%3Avec Returns the number of elements in the slice. ```rust let a = [1, 2, 3]; assert_eq!(a.len(), 3); ``` -------------------------------- ### pub unsafe fn from_core(core_instance: Instance) -> Self Source: https://docs.rs/wgpu/latest/wgpu/struct.Instance.html?search=std%3A%3Avec Creates a new instance of wgpu from a wgpu-core instance. ```APIDOC ## pub unsafe fn from_core(core_instance: Instance) -> Self ### Description Create an new instance of wgpu from a wgpu-core instance. ### Arguments - `core_instance` - wgpu-core instance. ### Safety - Refer to the creation of wgpu-core Instance. ``` -------------------------------- ### as_array Source: https://docs.rs/wgpu/latest/wgpu/struct.BufferView.html Gets a reference to the underlying array if the length matches. ```APIDOC ## pub fn as_array(&self) -> Option<&[T; N]> ### Description Gets a reference to the underlying array. If N is not exactly equal to the length of self, then this method returns None. ### Signature `pub fn as_array(&self) -> Option<&[T; N]>` ``` -------------------------------- ### Option::is_none_or Example Source: https://docs.rs/wgpu/latest/wgpu/type.Label.html Checks if an Option is None or satisfies a predicate. ```rust let x: Option = Some(2); assert_eq!(x.is_none_or(|x| x > 1), true); let x: Option = Some(0); assert_eq!(x.is_none_or(|x| x > 1), false); let x: Option = None; assert_eq!(x.is_none_or(|x| x > 1), true); let x: Option = Some("ownership".to_string()); assert_eq!(x.as_ref().is_none_or(|x| x.len() > 1), true); println!("still alive {:?}", x); ``` -------------------------------- ### Create Device from HAL Source: https://docs.rs/wgpu/latest/wgpu/struct.Adapter.html?search= Creates a wgpu Device and Queue from a wgpu-hal OpenDevice. Available only in wgpu_core. ```rust pub unsafe fn create_device_from_hal( &self, hal_device: OpenDevice, desc: &DeviceDescriptor<'_>, ) -> Result<(Device, Queue), RequestDeviceError> ``` -------------------------------- ### AdapterInfo::new Source: https://docs.rs/wgpu/latest/wgpu/struct.AdapterInfo.html?search=std%3A%3Avec Creates a new instance of AdapterInfo with the specified device type and backend. ```APIDOC ## pub const fn new(device_type: DeviceType, backend: Backend) -> AdapterInfo ### Description Creates a new `AdapterInfo` with the given device type and backend. All other info fields are not populated. ``` -------------------------------- ### Box::into_inner usage Source: https://docs.rs/wgpu/latest/wgpu/custom/type.BoxSubmittedWorkDoneCallback.html?search= Example of extracting the inner value from a Box. ```rust assert_eq!(Box::into_inner(c), 5); ``` -------------------------------- ### start_graphics_debugger_capture Source: https://docs.rs/wgpu/latest/wgpu/struct.Device.html Starts a capture in the attached graphics debugger (Renderdoc or Xcode). ```APIDOC ## pub unsafe fn start_graphics_debugger_capture(&self) ### Description Starts a capture in the attached graphics debugger. This behaves differently depending on the debugger: Renderdoc calls StartFrameCapture, Xcode creates a capture with MTLCaptureManager, and None takes no action. ### Safety There should not be any other captures currently active. Graphics debuggers can easily cause crashes, so this is not guaranteed to be sound. ``` -------------------------------- ### create_adapter_from_hal Source: https://docs.rs/wgpu/latest/wgpu/struct.Instance.html Converts a wgpu-hal ExposedAdapter to a wgpu Adapter. ```APIDOC ## pub unsafe fn create_adapter_from_hal(&self, hal_adapter: ExposedAdapter) -> Adapter ### Description Converts a wgpu-hal `hal::ExposedAdapter` to a wgpu `Adapter`. ### Safety `hal_adapter` must be created from this instance internal handle. ``` -------------------------------- ### Check slice prefix Source: https://docs.rs/wgpu/latest/wgpu/struct.BufferView.html?search=u32+-%3E+bool Verifies if a slice starts with a specific subslice. ```rust let v = [10, 40, 30]; assert!(v.starts_with(&[10])); assert!(v.starts_with(&[10, 40])); assert!(v.starts_with(&v)); assert!(!v.starts_with(&[50])); assert!(!v.starts_with(&[10, 50])); ``` ```rust let v = &[10, 40, 30]; assert!(v.starts_with(&[])); let v: &[u8] = &[]; assert!(v.starts_with(&[])); ``` -------------------------------- ### Verify default wgpu limits Source: https://docs.rs/wgpu/latest/wgpu/struct.Limits.html Use the defaults() method to retrieve and verify the standard resource limits supported across all modern backends. ```rust assert_eq!(Limits::defaults(), Limits { max_texture_dimension_1d: 8192, max_texture_dimension_2d: 8192, max_texture_dimension_3d: 2048, max_texture_array_layers: 256, max_bind_groups: 4, max_bind_groups_plus_vertex_buffers: 24, max_bindings_per_bind_group: 1000, max_dynamic_uniform_buffers_per_pipeline_layout: 8, max_dynamic_storage_buffers_per_pipeline_layout: 4, max_sampled_textures_per_shader_stage: 16, max_samplers_per_shader_stage: 16, max_storage_buffers_per_shader_stage: 8, max_storage_textures_per_shader_stage: 4, max_uniform_buffers_per_shader_stage: 12, max_binding_array_elements_per_shader_stage: 0, max_binding_array_acceleration_structure_elements_per_shader_stage: 0, max_binding_array_sampler_elements_per_shader_stage: 0, max_uniform_buffer_binding_size: 64 << 10, // (64 KiB) max_storage_buffer_binding_size: 128 << 20, // (128 MiB) max_vertex_buffers: 8, max_buffer_size: 256 << 20, // (256 MiB) max_vertex_attributes: 16, max_vertex_buffer_array_stride: 2048, max_inter_stage_shader_variables: 16, min_uniform_buffer_offset_alignment: 256, min_storage_buffer_offset_alignment: 256, max_color_attachments: 8, max_color_attachment_bytes_per_sample: 32, max_compute_workgroup_storage_size: 16384, max_compute_invocations_per_workgroup: 256, max_compute_workgroup_size_x: 256, max_compute_workgroup_size_y: 256, max_compute_workgroup_size_z: 64, max_compute_workgroups_per_dimension: 65535, max_immediate_size: 0, max_non_sampler_bindings: 1_000_000, max_task_workgroup_total_count: 0, max_task_workgroups_per_dimension: 0, max_mesh_workgroup_total_count: 0, max_mesh_workgroups_per_dimension: 0, max_task_invocations_per_workgroup: 0, max_task_invocations_per_dimension: 0, max_mesh_invocations_per_workgroup: 0, max_mesh_invocations_per_dimension: 0, max_task_payload_size: 0, max_mesh_output_vertices: 0, max_mesh_output_primitives: 0, max_mesh_output_layers: 0, max_mesh_multiview_view_count: 0, max_blas_primitive_count: 0, max_blas_geometry_count: 0, max_tlas_instance_count: 0, max_acceleration_structures_per_shader_stage: 0, max_buffers_and_acceleration_structures_per_shader_stage: 28, // sum of storage buffers, uniform buffers and vertex buffers limits max_multiview_view_count: 0, max_ray_dispatch_count: 0, max_ray_recursion_depth: 0, }); ``` -------------------------------- ### offset Source: https://docs.rs/wgpu/latest/wgpu/struct.BufferSlice.html Returns the starting offset of the slice within the parent buffer. ```APIDOC ## pub fn offset(&self) -> BufferAddress ### Description Returns the offset in `Self::buffer()` this slice starts at. ``` -------------------------------- ### HasDisplayHandle::display_handle Source: https://docs.rs/wgpu/latest/wgpu/type.ErrorSource.html?search= Get a handle to the display controller of the windowing system. ```APIDOC ### fn display_handle(&self) -> Result, HandleError> Get a handle to the display controller of the windowing system. ``` -------------------------------- ### prepare_compaction_async() Source: https://docs.rs/wgpu/latest/wgpu/struct.Blas.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Asynchronously prepares the BLAS for compaction, invoking a callback once builds are finished. ```APIDOC ## pub fn prepare_compaction_async(&self, callback: impl FnOnce(Result<(), BlasAsyncError>) + WasmNotSend + 'static) ### Description Prepares this BLAS for compaction asynchronously. The provided callback is executed once all builds using this BLAS are complete and the structure is ready for compaction. ### Parameters - **callback** (impl FnOnce(Result<(), BlasAsyncError>)) - A callback function that receives the result of the compaction preparation. ``` -------------------------------- ### Get Tlas instances Source: https://docs.rs/wgpu/latest/wgpu/struct.Tlas.html?search= Retrieves a reference to all instances contained in the TLAS. ```rust pub fn get(&self) -> &[Option] ``` -------------------------------- ### get_timestamp_period Source: https://docs.rs/wgpu/latest/wgpu/struct.Queue.html Gets the amount of nanoseconds each tick of a timestamp query represents. ```APIDOC ## pub fn get_timestamp_period(&self) -> f32 ### Description Gets the amount of nanoseconds each tick of a timestamp query represents. Returns zero if timestamp queries are unsupported. ``` -------------------------------- ### Blas::prepare_compaction_async Source: https://docs.rs/wgpu/latest/wgpu/struct.Blas.html?search= Asynchronously prepares the BLAS for compaction, triggering a callback once builds are finished. ```APIDOC ## pub fn prepare_compaction_async(&self, callback: impl FnOnce(Result<(), BlasAsyncError>) + WasmNotSend + 'static) ### Description Prepares this BLAS for compaction. The provided callback is invoked once all builds using this BLAS are finished and the structure is ready for compaction. ### Parameters - **callback** (impl FnOnce) - A function called with the result of the preparation process. ``` -------------------------------- ### Get First Element Source: https://docs.rs/wgpu/latest/wgpu/struct.BufferView.html?search=std%3A%3Avec Returns the first element of the slice as an Option. ```rust let v = [10, 40, 30]; assert_eq!(Some(&10), v.first()); let w: &[i32] = &[]; assert_eq!(None, w.first()); ``` -------------------------------- ### from_env() Source: https://docs.rs/wgpu/latest/wgpu/struct.Backends.html Retrieves a set of backends from the WGPU_BACKEND environment variable. ```APIDOC ### pub fn from_env() -> Option ### Description Gets a set of backends from the environment variable `WGPU_BACKEND`. ``` -------------------------------- ### from_dxc_version Source: https://docs.rs/wgpu/latest/wgpu/enum.DxcShaderModel.html Get the shader model supported by a certain DXC version. ```APIDOC ### pub fn from_dxc_version(major: u32, minor: u32) -> DxcShaderModel Returns the DxcShaderModel corresponding to the provided major and minor version numbers. ``` -------------------------------- ### Defining a Vertex Layout Source: https://docs.rs/wgpu/latest/wgpu/struct.VertexBufferLayout.html Example showing how to define a vertex struct and its corresponding VertexBufferLayout using the vertex_attr_array! macro. ```rust #[repr(C, packed)] struct Vertex { foo: [f32; 2], bar: f32, baz: [u16; 4], } impl Vertex { /// Layout to use with a buffer whose contents are a `[Vertex]`. pub const LAYOUT: wgpu::VertexBufferLayout<'static> = wgpu::VertexBufferLayout { array_stride: size_of::() as wgpu::BufferAddress, step_mode: wgpu::VertexStepMode::Vertex, attributes: &wgpu::vertex_attr_array![ 0 => Float32x2, 1 => Float32, 2 => Uint16x4, ], }; } ``` -------------------------------- ### Convert StorageFormat to TextureFormat Source: https://docs.rs/wgpu/latest/wgpu/util/trait.TextureFormatExt.html Example usage of from_storage_format to retrieve the corresponding TextureFormat. ```rust use wgpu::util::TextureFormatExt; assert_eq!(wgpu::TextureFormat::from_storage_format(wgpu::naga::StorageFormat::Bgra8Unorm), wgpu::TextureFormat::Bgra8Unorm); ``` -------------------------------- ### GlBackendOptions::from_env_or_default Source: https://docs.rs/wgpu/latest/wgpu/struct.GlBackendOptions.html Creates a new GlBackendOptions instance by reading configuration from environment variables, falling back to defaults where necessary. ```APIDOC ## pub fn from_env_or_default() -> GlBackendOptions ### Description Choose OpenGL backend options by calling `from_env` on every field. ### Returns - **GlBackendOptions** - A new instance configured from environment variables or defaults. ``` -------------------------------- ### Examples of align_to usage Source: https://docs.rs/wgpu/latest/wgpu/util/fn.align_to.html Demonstrates aligning various values to a 16-byte boundary. ```rust assert_eq!(align_to(253_u32, 16), 256); assert_eq!(align_to(256_u32, 16), 256); assert_eq!(align_to(0_u32, 16), 0); ``` -------------------------------- ### new_instance_with_webgpu_detection function signature Source: https://docs.rs/wgpu/latest/wgpu/util/fn.new_instance_with_webgpu_detection.html The function signature for creating a wgpu instance with automatic WebGPU detection. ```rust pub async fn new_instance_with_webgpu_detection( instance_desc: InstanceDescriptor, ) -> Instance ``` -------------------------------- ### Construct Box from raw pointer Source: https://docs.rs/wgpu/latest/wgpu/custom/type.BlasCompactCallback.html?search= Examples demonstrating how to recreate a Box from a raw pointer or allocate memory manually for a Box. ```rust let x = Box::new(5); let ptr = Box::into_raw(x); let x = unsafe { Box::from_raw(ptr) }; ``` ```rust use std::alloc::{alloc, Layout}; unsafe { let ptr = alloc(Layout::new::()) as *mut i32; // In general .write is required to avoid attempting to destruct // the (uninitialized) previous contents of `ptr`, though for this // simple example `*ptr = 5` would have worked as well. ptr.write(5); let x = Box::from_raw(ptr); } ``` -------------------------------- ### Option::is_some_and Example Source: https://docs.rs/wgpu/latest/wgpu/type.Label.html Checks if an Option contains a value that satisfies a predicate. ```rust let x: Option = Some(2); assert_eq!(x.is_some_and(|x| x > 1), true); let x: Option = Some(0); assert_eq!(x.is_some_and(|x| x > 1), false); let x: Option = None; assert_eq!(x.is_some_and(|x| x > 1), false); let x: Option = Some("ownership".to_string()); assert_eq!(x.as_ref().is_some_and(|x| x.len() > 1), true); println!("still alive {:?}", x); ``` -------------------------------- ### Transition resources in a compute pass Source: https://docs.rs/wgpu/latest/wgpu/struct.ComputePass.html Example of using transition_resources to manually manage resource states for native interoperability. ```rust let buffer_transitions = custom_resources .iter() .map(|resource| wgpu::BufferTransition { buffer: &resource.buffer, state: wgpu::BufferUses::STORAGE_READ_WRITE, }); pass.transition_resources(buffer_transitions, iter::empty()) pass.dispatch_workgroups(x, y, z); ``` -------------------------------- ### Option::cloned Example Source: https://docs.rs/wgpu/latest/wgpu/type.Label.html Demonstrates cloning the contents of an Option containing a reference. ```rust let x = 12; let opt_x = Some(&x); assert_eq!(opt_x, Some(&12)); let cloned = opt_x.cloned(); assert_eq!(cloned, Some(12)); ``` -------------------------------- ### Option::copied Example Source: https://docs.rs/wgpu/latest/wgpu/type.Label.html Demonstrates copying the contents of an Option containing a reference. ```rust let x = 12; let opt_x = Some(&x); assert_eq!(opt_x, Some(&12)); let copied = opt_x.copied(); assert_eq!(copied, Some(12)); ```