### Example Searches Source: https://docs.rs/wgpu/29.0.3/wgpu/struct.InstanceDescriptor.html?search= These are example searches that demonstrate how to find InstanceDescriptors. ```APIDOC ## Example Searches These are example searches that demonstrate how to find InstanceDescriptors. ### Example 1 ``` std::vec ``` ### Example 2 ``` u32 -> bool ``` ### Example 3 ``` Option, (T -> U) -> Option ``` ``` -------------------------------- ### Immediate Transfer Example Source: https://docs.rs/wgpu/29.0.3/wgpu/struct.Queue.html Demonstrates how to ensure scheduled transfers start immediately by calling `submit` with no command buffers. This is useful when `write_buffer` has been called and you want the data transfer to begin. ```rust queue.write_buffer(&buffer, 0, &data); queue.submit([]); ``` -------------------------------- ### WGSL Acceleration Structure with Vertex Return Example Source: https://docs.rs/wgpu/29.0.3/wgpu/enum.BindingType.html?search= WGSL example for an acceleration structure binding that enables vertex return functionality. ```wgsl @group(0) @binding(0) var as: acceleration_structure; ``` -------------------------------- ### IMMEDIATES Feature and WGSL Example Source: https://docs.rs/wgpu/29.0.3/wgpu/struct.Features.html Enables immediate data for `RenderPass`, allowing small, fast memory updates. Includes a WGSL example for declaring immediate variables. ```rust pub const IMMEDIATES: Features ``` ```wgsl struct Immediates { example: f32, } var c: Immediates; ``` -------------------------------- ### Example Search Query: Option, (T -> U) -> Option Source: https://docs.rs/wgpu/29.0.3/wgpu/custom/trait.RequestDeviceFuture.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E An example search query demonstrating a common pattern for transforming Option types in Rust. ```rust Option, (T -> U) -> Option ``` -------------------------------- ### Get Element Offset in Slice Source: https://docs.rs/wgpu/29.0.3/wgpu/struct.BufferView.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Use `element_offset` to find the index of an element reference within a slice. Returns `None` if the reference is not aligned to the start of an element. ```rust let nums: &[u32] = &[1, 7, 1, 1]; let num = &nums[2]; assert_eq!(num, &1); assert_eq!(nums.element_offset(num), Some(2)); ``` ```rust let arr: &[[u32; 2]] = &[[0, 1], [2, 3]]; let flat_arr: &[u32] = arr.as_flattened(); let ok_elm: &[u32; 2] = flat_arr[0..2].try_into().unwrap(); let weird_elm: &[u32; 2] = flat_arr[1..3].try_into().unwrap(); assert_eq!(ok_elm, &[0, 1]); assert_eq!(weird_elm, &[1, 2]); assert_eq!(arr.element_offset(ok_elm), Some(0)); assert_eq!(arr.element_offset(weird_elm), None); ``` -------------------------------- ### Instance::new Source: https://docs.rs/wgpu/29.0.3/wgpu/struct.Instance.html 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. ```APIDOC ## Instance::new ### Description Create an 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; see `Instance::enabled_backend_features()`. ``` -------------------------------- ### Create a BufferSlice with a specific range Source: https://docs.rs/wgpu/29.0.3/wgpu/struct.BufferSlice.html Create a BufferSlice referring to a specific byte range within a buffer. This example shows how to get a slice of the second ten bytes. ```rust let slice = buffer.slice(10..20); ``` -------------------------------- ### Instance::default Source: https://docs.rs/wgpu/29.0.3/wgpu/struct.Instance.html?search=std%3A%3Avec Creates a new instance of wgpu with default options. ```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`. ### Method default ### Panics If no backend feature for the active target platform is enabled, this method will panic, see `Instance::enabled_backend_features()`. ``` -------------------------------- ### Instance::new Source: https://docs.rs/wgpu/29.0.3/wgpu/struct.Instance.html?search=u32+-%3E+bool Creates a new wgpu Instance with the given descriptor, enabling specific backends. Panics if no backend feature for the active platform is enabled. ```APIDOC ## Instance::new ### Description Create a new instance of wgpu using the given options and enabled backends. ### Method `pub fn new(desc: InstanceDescriptor) -> Self` ### Panics If no backend feature for the active target platform is enabled, this method will panic; see `Instance::enabled_backend_features()`. ``` -------------------------------- ### Get wgpu_hal Texture (Vulkan Example) Source: https://docs.rs/wgpu/29.0.3/wgpu/struct.Texture.html Retrieves the wgpu_hal texture for the Vulkan backend. This method is unsafe and requires careful handling of the returned guard to avoid deadlocks and ensure resource safety. ```rust pub unsafe fn as_hal(&self) -> Option> ``` -------------------------------- ### initialize_adapter_from_env_or_default Source: https://docs.rs/wgpu/29.0.3/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 ```rust pub async fn initialize_adapter_from_env_or_default( instance: &Instance, compatible_surface: Option<&Surface<'_>>, ) -> Result ``` ### Parameters * `instance`: A reference to the wgpu `Instance`. * `compatible_surface`: An optional reference to a `Surface` for which the adapter should be compatible. ``` -------------------------------- ### Get the index of an element reference Source: https://docs.rs/wgpu/29.0.3/wgpu/struct.BufferView.html Use `element_offset` to find the index of a given element reference within a slice. It returns `None` if the reference is not aligned to the start of an element. This method uses pointer arithmetic and does not compare elements. ```rust let nums: &[u32] = &[1, 7, 1, 1]; let num = &nums[2]; assert_eq!(num, &1); assert_eq!(nums.element_offset(num), Some(2)); ``` ```rust let arr: &[[u32; 2]] = &[[0, 1], [2, 3]]; let flat_arr: &[u32] = arr.as_flattened(); let ok_elm: &[u32; 2] = flat_arr[0..2].try_into().unwrap(); let weird_elm: &[u32; 2] = flat_arr[1..3].try_into().unwrap(); assert_eq!(ok_elm, &[0, 1]); assert_eq!(weird_elm, &[1, 2]); assert_eq!(arr.element_offset(ok_elm), Some(0)); // Points to element 0 assert_eq!(arr.element_offset(weird_elm), None); // Points between element 0 and 1 ``` -------------------------------- ### Instance::default Source: https://docs.rs/wgpu/29.0.3/wgpu/struct.Instance.html Creates a new instance of wgpu with default options. Backends are set to `Backends::all()`, and FXC is chosen as the `dx12_shader_compiler`. ```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, see `Instance::enabled_backend_features()`. ### Method default ``` -------------------------------- ### Example: Using pipeline_cache_key for PipelineCache management Source: https://docs.rs/wgpu/29.0.3/wgpu/util/fn.pipeline_cache_key.html?search= Demonstrates how to use `pipeline_cache_key` to manage `PipelineCache`s. It attempts to load a cache from disk, creates a new one if it doesn't exist or fails to load, and then shows how to save the cache after pipeline initialization. ```rust use wgpu::PipelineCacheDescriptor; let cache_dir: PathBuf = unimplemented!("Some reasonable platform-specific cache directory for your app."); let filename = wgpu::util::pipeline_cache_key(&adapter_info); let (pipeline_cache, cache_file) = if let Some(filename) = filename { let cache_path = cache_dir.join(&filename); // If we failed to read the cache, for whatever reason, treat the data as lost. // In a real app, we'd probably avoid caching entirely unless the error was "file not found". let cache_data = std::fs::read(&cache_path).ok(); let pipeline_cache = unsafe { device.create_pipeline_cache(&PipelineCacheDescriptor { data: cache_data.as_deref(), label: None, fallback: true }) }; (Some(pipeline_cache), Some(cache_path)) } else { (None, None) }; // Run pipeline initialisation, making sure to set the `cache` // fields of your `*PipelineDescriptor` to `pipeline_cache` // And then save the resulting cache (probably off the main thread). if let (Some(pipeline_cache), Some(cache_file)) = (pipeline_cache, cache_file) { let data = pipeline_cache.get_data(); if let Some(data) = data { let temp_file = cache_file.with_extension("temp"); std::fs::write(&temp_file, &data)?; std::fs::rename(&temp_file, &cache_file)?; } } ``` -------------------------------- ### Get wgpu-hal Surface (Vulkan Example) Source: https://docs.rs/wgpu/29.0.3/wgpu/struct.Surface.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Safely retrieves the underlying wgpu-hal surface for a specific backend, such as Vulkan. This is only available on `wgpu_core`. The returned guard dereferences to the HAL backend's surface type. Returns None if the surface is not from the specified backend or is from the webgpu/custom backend. Safety requires upholding all wgpu-hal safety requirements. ```rust pub unsafe fn as_hal( &self, ) -> Option + WasmNotSendSync> ``` -------------------------------- ### Features Search Examples Source: https://docs.rs/wgpu/29.0.3/wgpu/struct.Features.html?search= Examples of how to perform feature searches. ```APIDOC ## Example Searches ### Search for a specific feature: ``` std::vec ``` ### Search for type conversions: ``` u32 -> bool ``` ### Search for generic type transformations: ``` Option, (T -> U) -> Option ``` ``` -------------------------------- ### Create wgpu Instance with WebGPU Detection Source: https://docs.rs/wgpu/29.0.3/wgpu/util/fn.new_instance_with_webgpu_detection.html?search= Use this function to create a wgpu Instance. It checks for WebGPU support and disables it if not available, falling back to WebGL. Prefer this over `Instance::new` for WebGPU targeting with fallback. ```rust pub async fn new_instance_with_webgpu_detection( instance_desc: InstanceDescriptor, ) -> Instance ``` -------------------------------- ### from_env_or_default Source: https://docs.rs/wgpu/29.0.3/wgpu/struct.NoopBackendOptions.html Initializes NoopBackendOptions by checking the WGPU_NOOP_BACKEND environment variable. ```APIDOC ## impl NoopBackendOptions ### pub fn from_env_or_default() -> NoopBackendOptions 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. Future versions may assign other meanings to other values. ``` -------------------------------- ### Example Searches Source: https://docs.rs/wgpu/29.0.3/wgpu/enum.Backend.html?search= Provides examples of search queries that can be performed. ```APIDOC Example searches: * std::vec * u32 -> bool * Option, (T -> U) -> Option ``` -------------------------------- ### Instance::default Source: https://docs.rs/wgpu/29.0.3/wgpu/struct.Instance.html?search= Creates a new Instance with default options. ```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`. ### Method default ### Returns - `Self`: A new Instance with default configuration. ### Panics If no backend feature for the active target platform is enabled, this method will panic, see `Instance::enabled_backend_features()`. ``` -------------------------------- ### Start Graphics Debugger Capture Source: https://docs.rs/wgpu/29.0.3/wgpu/custom/trait.DeviceInterface.html Starts capturing graphics debugger information (unsafe). ```APIDOC ## unsafe fn start_graphics_debugger_capture(&self) ### Description Starts capturing graphics debugger information. This method is unsafe and should be used with caution. ``` -------------------------------- ### Example Usage of VertexBufferLayout Source: https://docs.rs/wgpu/29.0.3/wgpu/struct.VertexBufferLayout.html?search=u32+-%3E+bool An example demonstrating how to define a VertexBufferLayout for a custom Vertex struct using the vertex_attr_array! macro. ```APIDOC ## Example The following example defines a `struct` with three fields, and a `VertexBufferLayout` that contains `VertexAttribute`s for each field, using the `vertex_attr_array!` macro to compute attribute offsets: ```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, ], }; } ``` ``` -------------------------------- ### take Source: https://docs.rs/wgpu/29.0.3/wgpu/custom/type.BlasCompactCallback.html Creates an adapter which will read at most `limit` bytes from it. ```APIDOC ## fn take(self, limit: u64) -> Take ### Description Creates an adapter which will read at most `limit` bytes from it. ### Signature ```rust fn take(self, limit: u64) -> Take where Self: Sized, ``` ``` -------------------------------- ### Surface::configure Source: https://docs.rs/wgpu/29.0.3/wgpu/struct.Surface.html Initializes Surface for presentation. If the surface is already configured, this will wait for the GPU to come idle before recreating the swapchain to prevent race conditions. ```APIDOC ## Surface::configure ### Description Initializes `Surface` for presentation. If the surface is already configured, this will wait for the GPU to come idle before recreating the swapchain to prevent race conditions. ### Method POST ### Endpoint `/wgpu/Surface/configure` ### Parameters #### Path Parameters - **self** (Surface<'_>) - Required - The surface instance. - **device** (Device) - Required - The device to configure the surface with. - **config** (SurfaceConfiguration) - Required - The surface configuration. ### Validation Errors - Submissions that happen _during_ the configure may cause the internal wait-for-idle to fail, raising a validation error. ### Panics - A old `SurfaceTexture` is still alive referencing an old surface. - Texture format requested is unsupported on the surface. - `config.width` or `config.height` is zero. ``` -------------------------------- ### Non-uniform Constructor GLSL Example Source: https://docs.rs/wgpu/29.0.3/wgpu/struct.FeaturesWGPU.html?search=u32+-%3E+bool Example of using the 'nonuniformEXT' constructor in GLSL for non-uniform indexing of texture arrays. ```glsl texture_array[nonuniformEXT(vertex_data)] ``` -------------------------------- ### Instance::from_core Source: https://docs.rs/wgpu/29.0.3/wgpu/struct.Instance.html?search= Creates a new wgpu Instance from a wgpu-core instance. ```APIDOC ## Instance::from_core ### Description Create a new instance of wgpu from a wgpu-core instance. ### Arguments - `core_instance` - wgpu-core instance. ### Safety Refer to the creation of wgpu-core Instance. ``` -------------------------------- ### WGSL Storage Texture Binding Example Source: https://docs.rs/wgpu/29.0.3/wgpu/enum.BindingType.html?search= Example of declaring a storage texture in WGSL, specifying format and access mode. ```wgsl @group(0) @binding(0) var my_storage_image: texture_storage_2d; ``` -------------------------------- ### Example Usage of VertexBufferLayout Source: https://docs.rs/wgpu/29.0.3/wgpu/struct.VertexBufferLayout.html An example demonstrating how to define a Vertex struct and its corresponding VertexBufferLayout using the `vertex_attr_array!` macro for use in a RenderPipelineDescriptor. ```APIDOC ## §Example ```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, ], }; } ``` ``` -------------------------------- ### from_env Source: https://docs.rs/wgpu/29.0.3/wgpu/enum.Dx12SwapchainKind.html?search= Chooses the presentation system based on the WGPU_DX12_PRESENTATION_SYSTEM environment variable. ```APIDOC ## pub fn from_env() -> Option Choose which presentation system to use from the environment variable `WGPU_DX12_PRESENTATION_SYSTEM`. Valid values, case insensitive: * `DxgiFromVisual` or `Visual` * `DxgiFromHwnd` or `Hwnd` for `Self::DxgiFromHwnd` ``` -------------------------------- ### Get WriteOnly slice length Source: https://docs.rs/wgpu/29.0.3/wgpu/struct.WriteOnly.html Use the `len()` method to get the number of elements that can be written to in a slice. This is similar to slice references. ```rust let example_slice: &mut [u8] = &mut [0; 10]; assert_eq!(wgpu::WriteOnly::from_mut(example_slice).len(), example_slice.len()); ``` -------------------------------- ### Dx12BackendOptions Initialization Source: https://docs.rs/wgpu/29.0.3/wgpu/struct.Dx12BackendOptions.html Methods for creating and configuring Dx12BackendOptions. `from_env_or_default` initializes options based on environment variables or defaults, while `with_env` modifies existing options using environment variables. ```APIDOC ## pub fn from_env_or_default() -> Dx12BackendOptions ### Description Choose DX12 backend options by calling `from_env` on every field. See those methods for more information. ### Method `from_env_or_default` ### Returns `Dx12BackendOptions` ## pub fn with_env(self) -> Dx12BackendOptions ### Description Takes the given options, modifies them based on the environment variables, and returns the result. This is equivalent to calling `with_env` on every field. ### Method `with_env` ### Parameters - **self** (Dx12BackendOptions) - The current Dx12BackendOptions instance. ### Returns `Dx12BackendOptions` ``` -------------------------------- ### initialize_adapter_from_env Source: https://docs.rs/wgpu/29.0.3/wgpu/util/fn.initialize_adapter_from_env.html Initializes the adapter obeying the `WGPU_ADAPTER_NAME` environment variable. ```APIDOC ## initialize_adapter_from_env ### Description Initialize the adapter obeying the `WGPU_ADAPTER_NAME` environment variable. ### Signature ```rust pub async fn initialize_adapter_from_env( instance: &Instance, compatible_surface: Option<&Surface<'_>>, ) -> Result ``` ### Parameters * `instance`: A reference to the wgpu `Instance`. * `compatible_surface`: An optional reference to a `Surface` for compatibility checks. ### Returns A `Result` containing the `Adapter` if successful, or a `RequestAdapterError` if initialization fails. ### Availability Available on `wgpu_core` only. ``` -------------------------------- ### Example of internal draw usage Source: https://docs.rs/wgpu/29.0.3/wgpu/struct.RenderPass.html Illustrates the internal loop structure for drawing primitives based on vertex ranges. This is a conceptual example of how drawing commands are processed. ```rust for instance_id in instance_range { for vertex_id in vertex_range { let vertex = vertex[vertex_id]; vertex_shader(vertex, vertex_id, instance_id); } } ``` -------------------------------- ### Create a new wgpu Instance Source: https://docs.rs/wgpu/29.0.3/wgpu/struct.Instance.html Use this function to create a new instance of wgpu. It takes an InstanceDescriptor to configure the instance. Panics if no backend feature for the active target platform is enabled. ```rust pub fn new(desc: InstanceDescriptor) -> Self ``` -------------------------------- ### Start Graphics Debugger Capture Source: https://docs.rs/wgpu/29.0.3/wgpu/struct.Device.html?search=std%3A%3Avec Starts a capture in an attached graphics debugger. The behavior varies depending on the debugger (e.g., RenderDoc, Xcode). This is an unsafe operation. ```rust pub unsafe fn start_graphics_debugger_capture(&self) ``` -------------------------------- ### take Source: https://docs.rs/wgpu/29.0.3/wgpu/custom/type.BlasCompactCallback.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Creates an adapter that reads at most a specified number of bytes from Box. ```APIDOC ## fn take(self, limit: u64) -> Take ### Description Creates an adapter which will read at most `limit` bytes from it. ### Parameters - `limit`: The maximum number of bytes to read. ### Returns A `Take` adapter that limits the number of bytes read. ``` -------------------------------- ### Get Reference to Underlying Array Source: https://docs.rs/wgpu/29.0.3/wgpu/struct.BufferView.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Attempt to get a reference to the underlying array if its length exactly matches the specified size `N`. Returns `None` otherwise. ```rust let slice: &[i32] = &[1, 2, 3]; let array_ref: Option<&[i32; 3]> = slice.as_array(); assert!(array_ref.is_some()); let array_ref_wrong_size: Option<&[i32; 2]> = slice.as_array(); assert!(array_ref_wrong_size.is_none()); ``` -------------------------------- ### Create NoopBackendOptions from Environment Source: https://docs.rs/wgpu/29.0.3/wgpu/struct.NoopBackendOptions.html Initializes NoopBackendOptions based on the WGPU_NOOP_BACKEND environment variable. The noop backend is enabled if the variable is set to '1'. ```rust pub fn from_env_or_default() -> NoopBackendOptions ``` -------------------------------- ### Instance from custom backend Source: https://docs.rs/wgpu/29.0.3/wgpu/struct.Instance.html Creates a wgpu Instance from a custom context implementation. This allows for integration with custom graphics backends. ```APIDOC ## pub fn from_custom(instance: T) -> Self ### Description Creates instance from custom context implementation ``` -------------------------------- ### Option::from_iter Example (Checked Sub) Source: https://docs.rs/wgpu/29.0.3/wgpu/type.Label.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Collects an iterator of Options into an Option of a collection. If any element is None, the entire result is None. This example demonstrates checked subtraction. ```rust let items = vec![2_u16, 1, 0]; let res: Option> = items .iter() .map(|x| x.checked_sub(1)) .collect(); ``` -------------------------------- ### Requesting a Device and Queue Source: https://docs.rs/wgpu/29.0.3/wgpu/struct.Adapter.html?search= Requests a connection to a physical device, creating a logical device and a queue for command execution. An adapter can only be used once to create a device according to the WebGPU spec, though wgpu does not currently enforce this. ```rust pub fn request_device( &self, desc: &DeviceDescriptor<'_>, ) -> impl Future> + WasmNotSend ``` -------------------------------- ### Option::from_iter Example (Checked Add) Source: https://docs.rs/wgpu/29.0.3/wgpu/type.Label.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Collects an iterator of Options into an Option of a collection. If any element is None, the entire result is None. This example demonstrates checked addition. ```rust let items = vec![0_u16, 1, 2]; let res: Option> = items .iter() .map(|x| x.checked_add(1)) .collect(); assert_eq!(res, Some(vec![1, 2, 3])); ``` -------------------------------- ### take Source: https://docs.rs/wgpu/29.0.3/wgpu/custom/type.BufferMapCallback.html?search=std%3A%3Avec Creates an adapter that reads at most a specified limit of bytes from a Box. ```APIDOC ## fn take(self, limit: u64) -> Take ### Description Creates an adapter which will read at most `limit` bytes from it. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **Take**: An adapter that limits the number of bytes read. ### Response Example None ``` -------------------------------- ### Initialize GlBackendOptions from Environment or Defaults Source: https://docs.rs/wgpu/29.0.3/wgpu/struct.GlBackendOptions.html?search= Use this function to choose OpenGL backend options by calling `from_env` on each field. Refer to individual field methods for more details. ```rust pub fn from_env_or_default() -> GlBackendOptions ``` -------------------------------- ### Start and Stop Debug Groups in RenderPass Source: https://docs.rs/wgpu/29.0.3/wgpu/struct.RenderPass.html?search= Use `push_debug_group` to start a labeled debug group for command recording and `pop_debug_group` to end it. This helps in organizing and identifying commands in debugging tools. ```rust pub fn push_debug_group(&mut self, label: &str) Start record commands and group it into debug marker group. ``` ```rust pub fn pop_debug_group(&mut self) Stops command recording and creates debug group. ``` -------------------------------- ### Example of internal draw_indexed usage Source: https://docs.rs/wgpu/29.0.3/wgpu/struct.RenderPass.html Shows the internal logic for drawing indexed primitives, including index buffer lookups and base vertex adjustments. This is a conceptual example of how indexed drawing commands are processed. ```rust for instance_id in instance_range { for index_index in index_range { let vertex_id = index_buffer[index_index]; let adjusted_vertex_id = vertex_id + base_vertex; let vertex = vertex[adjusted_vertex_id]; vertex_shader(vertex, adjusted_vertex_id, instance_id); } } ``` -------------------------------- ### Instance::create_adapter_from_hal Source: https://docs.rs/wgpu/29.0.3/wgpu/struct.Instance.html?search= Converts a wgpu-hal `hal::ExposedAdapter` to a wgpu `Adapter`. ```APIDOC ## Instance::create_adapter_from_hal ### Description Converts a wgpu-hal `hal::ExposedAdapter` to a wgpu `Adapter`. ### Safety `hal_adapter` must be created from this instance internal handle. ### Types The type of `hal_adapter.adapter` depends on the backend: - `hal::api::Vulkan` uses `hal::vulkan::Adapter` - `hal::api::Metal` uses `hal::metal::Adapter` - `hal::api::Dx12` uses `hal::dx12::Adapter` - `hal::api::Gles` uses `hal::gles::Adapter` ``` -------------------------------- ### type_id Source: https://docs.rs/wgpu/29.0.3/wgpu/struct.TexelCopyBufferLayout.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Gets the `TypeId` of `self`. ```APIDOC ## fn type_id(&self) -> TypeId ### Description Gets the `TypeId` of `self`. ### Returns The `TypeId` of the object. ``` -------------------------------- ### initialize_adapter_from_env Source: https://docs.rs/wgpu/29.0.3/wgpu/util/fn.initialize_adapter_from_env.html?search=std%3A%3Avec Initializes the adapter obeying the `WGPU_ADAPTER_NAME` environment variable. This function is available on `wgpu_core` only. ```APIDOC ## initialize_adapter_from_env ### Description Initializes the adapter obeying the `WGPU_ADAPTER_NAME` environment variable. This function is available on `wgpu_core` only. ### Signature ```rust pub async fn initialize_adapter_from_env( instance: &Instance, compatible_surface: Option<&Surface<'_>>, ) -> Result ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Response #### Success Response - **Adapter**: The initialized adapter. - **RequestAdapterError**: An error occurred during adapter initialization. ``` -------------------------------- ### TypeId Source: https://docs.rs/wgpu/29.0.3/wgpu/struct.BufferSlice.html Gets the `TypeId` of `self`. ```APIDOC ## fn type_id(&self) -> TypeId ### Description Gets the `TypeId` of `self`, which can be used for runtime type identification. ### Returns The `TypeId` of the object. ``` -------------------------------- ### Initialize Adapter from Environment or Default Source: https://docs.rs/wgpu/29.0.3/wgpu/util/fn.initialize_adapter_from_env_or_default.html Use this function to initialize a wgpu adapter. It respects the `WGPU_ADAPTER_NAME` environment variable for specific adapter selection. If the environment variable is not set, it falls back to selecting a default adapter. ```rust pub async fn initialize_adapter_from_env_or_default( instance: &Instance, compatible_surface: Option<&Surface<'_>>, ) -> Result ``` -------------------------------- ### Any::type_id Source: https://docs.rs/wgpu/29.0.3/wgpu/enum.Dx12Compiler.html?search=u32+-%3E+bool Gets the `TypeId` of the value. ```APIDOC ## fn type_id(&self) -> TypeId Gets the `TypeId` of `self`. Read more ``` -------------------------------- ### new_instance_with_webgpu_detection Source: https://docs.rs/wgpu/29.0.3/wgpu/util/fn.new_instance_with_webgpu_detection.html?search=std%3A%3Avec Creates a new wgpu instance, disabling `Backends::BROWSER_WEBGPU` if no WebGPU support is detected. It forwards the descriptor to `Instance::new`, optionally removing `Backends::BROWSER_WEBGPU` if unsupported. This is the preferred method for targeting WebGPU with a fallback to WebGL. ```APIDOC ## Function new_instance_with_webgpu_detection ### Description Create an new instance of wgpu, but disabling `Backends::BROWSER_WEBGPU` if no WebGPU support was detected. If the instance descriptor enables `Backends::BROWSER_WEBGPU`, this checks via `is_browser_webgpu_supported` for WebGPU support before forwarding the descriptor with or without `Backends::BROWSER_WEBGPU` respectively to `Instance::new`. You should prefer this method over `Instance::new` if you want to target WebGPU and automatically fall back to WebGL if WebGPU is not available. This is because WebGPU support has to be decided upon instance creation and `Instance::new` (being a `sync` function) can’t establish WebGPU support (details see `is_browser_webgpu_supported`). ### Signature ```rust pub async fn new_instance_with_webgpu_detection( instance_desc: InstanceDescriptor, ) -> Instance ``` ### Panics If no backend feature for the active target platform is enabled, this method will panic, see `Instance::enabled_backend_features()`. ``` -------------------------------- ### window_handle Source: https://docs.rs/wgpu/29.0.3/wgpu/custom/type.BoxDeviceLostCallback.html?search= Get a handle to the window. ```APIDOC ## fn window_handle(&self) -> Result, HandleError> ### Description Get a handle to the window. ### Signature ```rust fn window_handle(&self) -> Result, HandleError> ``` ``` -------------------------------- ### FeaturesWebGPU Initialization Methods Source: https://docs.rs/wgpu/29.0.3/wgpu/struct.FeaturesWebGPU.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Methods for creating and initializing FeaturesWebGPU flag values. ```APIDOC ## FeaturesWebGPU Initialization Methods ### `empty()` Get a flags value with all bits unset. ### `all()` Get a flags value with all known bits set. ### `from_bits(bits: u64) -> Option` Convert from a bits value. This method will return `None` if any unknown bits are set. ### `from_bits_truncate(bits: u64) -> FeaturesWebGPU` Convert from a bits value, unsetting any unknown bits. ### `from_bits_retain(bits: u64) -> FeaturesWebGPU` Convert from a bits value exactly. ### `from_name(name: &str) -> Option` Get a flags value with the bits of a flag with the given name set. This method will return `None` if `name` is empty or doesn’t correspond to any named flag. ``` -------------------------------- ### Any::type_id Source: https://docs.rs/wgpu/29.0.3/wgpu/enum.QueryType.html?search=u32+-%3E+bool Gets the `TypeId` of the implementing type. ```APIDOC ## fn type_id(&self) -> TypeId ### Description Gets the `TypeId` of `self`. ### Method type_id ### Parameters * `&self` - The instance to get the type ID from. ### Returns * `TypeId` - The unique type identifier. ``` -------------------------------- ### WGSL Acceleration Structure with Vertex Return Example Source: https://docs.rs/wgpu/29.0.3/wgpu/enum.BindingType.html?search=std%3A%3Avec Demonstrates the WGSL syntax for an acceleration structure binding with vertex return enabled. This requires specific feature flags. ```wgsl @group(0) @binding(0) var as: acceleration_structure; ``` -------------------------------- ### T::type_id Source: https://docs.rs/wgpu/29.0.3/wgpu/enum.ShaderSource.html?search=u32+-%3E+bool Gets the `TypeId` of a generic type `T`. ```APIDOC ## fn type_id(&self) -> TypeId Gets the `TypeId` of `self`. Read more Source ``` -------------------------------- ### Configure Surface for Presentation Source: https://docs.rs/wgpu/29.0.3/wgpu/struct.Surface.html?search=std%3A%3Avec Initializes the Surface for presentation. If already configured, it waits for the GPU to become idle before recreating the swapchain to prevent race conditions. Panics can occur due to old SurfaceTexture references, unsupported texture formats, or zero width/height. ```rust pub fn configure(&self, device: &Device, config: &SurfaceConfiguration) ``` -------------------------------- ### Features::bits Source: https://docs.rs/wgpu/29.0.3/wgpu/struct.Features.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Get the underlying bits value. ```APIDOC ## Features::bits ### Description Get the underlying bits value. ### Source `fn bits(&self) -> FeatureBits` ``` -------------------------------- ### create_device_from_hal Source: https://docs.rs/wgpu/29.0.3/wgpu/struct.Adapter.html?search=std%3A%3Avec Creates a wgpu `Device` and `Queue` from a wgpu-hal `hal::OpenDevice`. This is an unsafe operation. ```APIDOC ## create_device_from_hal ### Description Create a wgpu `Device` and `Queue` from a wgpu-hal `hal::OpenDevice`. ### Method `Adapter::create_device_from_hal` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **hal_device** (`OpenDevice`) - Required - The `hal::OpenDevice` to create the wgpu device from. - **desc** (`&DeviceDescriptor<'_>`) - Required - A descriptor for the device to be created. ### Request Example ```rust // This is an unsafe function and requires a valid hal_device and descriptor. // Example usage would depend on how hal_device is obtained. ``` ### Response #### Success Response (200) - **Device**: A logical device handle. - **Queue**: A queue for executing command buffers. #### Response Example ```rust // Successful response is represented by the returned tuple (Device, Queue) ``` ### Safety - `hal_device` must be created from this adapter internal handle. - `desc.features` must be a subset of `hal_device`’s supported features. ``` -------------------------------- ### BufferUses::bits Source: https://docs.rs/wgpu/29.0.3/wgpu/struct.BufferUses.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Get the underlying bits value. ```APIDOC ## BufferUses::bits ### Description Get the underlying bits value. The returned value is exactly the bits set in this flags value. ### Returns - u16: The underlying bits value. ``` -------------------------------- ### Getting Adapter Info Source: https://docs.rs/wgpu/29.0.3/wgpu/struct.Adapter.html?search= Retrieves information about the adapter itself. ```rust pub fn get_info(&self) -> AdapterInfo ``` -------------------------------- ### Immediate Transfer with write_buffer_with Example Source: https://docs.rs/wgpu/29.0.3/wgpu/struct.Queue.html Shows how to trigger immediate transfer for data prepared with `write_buffer_with` by calling `submit` with an empty command buffer. The transfer begins on the next `submit` call after the view is dropped. ```rust queue.submit([]) ``` -------------------------------- ### Instance::default Source: https://docs.rs/wgpu/29.0.3/wgpu/struct.Instance.html?search=u32+-%3E+bool Creates a new Instance with default options. Backends are set to `Backends::all()`, and FXC is chosen as the `dx12_shader_compiler`. ```APIDOC ## fn default() -> Self 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, see `Instance::enabled_backend_features`. ``` -------------------------------- ### stream_position Source: https://docs.rs/wgpu/29.0.3/wgpu/type.ErrorSource.html?search=u32+-%3E+bool Returns the current seek position from the start of the stream. ```APIDOC ## stream_position ### Description Returns the current seek position from the start of the stream. ### Method `stream_position` ### Returns - `Result` - The current stream position on success, or an `Error`. ``` -------------------------------- ### FeaturesWebGPU Construction Methods Source: https://docs.rs/wgpu/29.0.3/wgpu/struct.FeaturesWebGPU.html Methods for creating and initializing FeaturesWebGPU instances. ```APIDOC ## FeaturesWebGPU Construction ### `empty()` Get a flags value with all bits unset. ### `all()` Get a flags value with all known bits set. ### `from_bits(bits: u64) -> Option` Convert from a bits value. This method will return `None` if any unknown bits are set. ### `from_bits_truncate(bits: u64) -> FeaturesWebGPU` Convert from a bits value, unsetting any unknown bits. ### `from_bits_retain(bits: u64) -> FeaturesWebGPU` Convert from a bits value exactly. ### `from_name(name: &str) -> Option` Get a flags value with the bits of a flag with the given name set. This method will return `None` if `name` is empty or doesn’t correspond to any named flag. ``` -------------------------------- ### start_graphics_debugger_capture Source: https://docs.rs/wgpu/29.0.3/wgpu/custom/trait.DeviceInterface.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Starts capturing graphics debugger information (unsafe). ```APIDOC ## start_graphics_debugger_capture ### Description Starts capturing graphics debugger information. This method is unsafe and should be used with caution. ### Method `unsafe fn start_graphics_debugger_capture()` ``` -------------------------------- ### Example Search Queries Source: https://docs.rs/wgpu/29.0.3/wgpu/struct.PipelineCacheDescriptor.html?search= Illustrative search queries for exploring Rust code, demonstrating patterns for vectors, type conversions, and Option transformations. ```text std::vec ``` ```text u32 -> bool ``` ```text Option, (T -> U) -> Option ``` -------------------------------- ### Tlas::get Source: https://docs.rs/wgpu/29.0.3/wgpu/struct.Tlas.html?search=std%3A%3Avec Get a reference to all instances within the Tlas. ```APIDOC ## Tlas::get ### Description Retrieves a reference to a slice containing all `TlasInstance` objects within the `Tlas`. ### Method `pub fn get(&self) -> &[Option]` ### Returns A slice of `Option` representing all instances in the `Tlas`. ``` -------------------------------- ### TextureFormatFeatureFlags::empty Source: https://docs.rs/wgpu/29.0.3/wgpu/struct.TextureFormatFeatureFlags.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Get a flags value with all bits unset. ```APIDOC ## TextureFormatFeatureFlags::empty ### Description Get a flags value with all bits unset. ### Signature `pub const fn empty() -> TextureFormatFeatureFlags` ``` -------------------------------- ### WGSL Acceleration Structure Binding Example Source: https://docs.rs/wgpu/29.0.3/wgpu/enum.BindingType.html?search= Shows the WGSL syntax for binding a ray-tracing acceleration structure. ```wgsl @group(0) @binding(0) var as: acceleration_structure; ``` -------------------------------- ### fn type_id(&self) -> TypeId Source: https://docs.rs/wgpu/29.0.3/wgpu/struct.RenderPassTimestampWrites.html?search=std%3A%3Avec Gets the TypeId of self. ```APIDOC ## fn type_id(&self) -> TypeId ### Description Gets the `TypeId` of `self`. ### Method `type_id` ### Parameters None ### Return Value `TypeId` - The unique identifier for the type of `self`. ``` -------------------------------- ### Functions Source: https://docs.rs/wgpu/29.0.3/wgpu/all.html Utility functions for wgpu initialization and operations. ```APIDOC ## Functions This section lists utility functions available in the wgpu API. ### util::align_to Aligns a value to a specified boundary. ### util::initialize_adapter_from_env Initializes an adapter from environment variables. ### util::initialize_adapter_from_env_or_default Initializes an adapter from environment variables or uses a default. ### util::is_browser_webgpu_supported Checks if WebGPU is supported in the browser. ### util::make_spirv Creates SPIR-V bytecode. ### util::make_spirv_raw Creates raw SPIR-V bytecode. ### util::new_instance_with_webgpu_detection Creates a new wgpu instance with WebGPU detection. ### util::pipeline_cache_key Generates a key for pipeline caching. ``` -------------------------------- ### Features::unknown_bits Source: https://docs.rs/wgpu/29.0.3/wgpu/struct.Features.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Get the unknown bits from a flags value. ```APIDOC ## Features::unknown_bits ### Description Get the unknown bits from a flags value. ### Source `fn unknown_bits(&self) -> Self::Bits` ``` -------------------------------- ### Features::known_bits Source: https://docs.rs/wgpu/29.0.3/wgpu/struct.Features.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Get the known bits from a flags value. ```APIDOC ## Features::known_bits ### Description Get the known bits from a flags value. ### Source `fn known_bits(&self) -> Self::Bits` ``` -------------------------------- ### Instance from wgpu-core Source: https://docs.rs/wgpu/29.0.3/wgpu/struct.Instance.html Creates a new wgpu Instance from a wgpu-core instance. This is useful for interoperation between wgpu-core and wgpu-hal. ```APIDOC ## pub unsafe fn from_core(core_instance: Instance) -> Self ### Description Create a new instance of wgpu from a wgpu-core instance. ### Arguments * `core_instance` - wgpu-core instance. ### Safety Refer to the creation of wgpu-core Instance. ``` -------------------------------- ### Features::empty Source: https://docs.rs/wgpu/29.0.3/wgpu/struct.Features.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Get a flags value with all bits unset. ```APIDOC ## Features::empty ### Description Get a flags value with all bits unset. ### Source `fn empty() -> Features` ``` -------------------------------- ### from_custom Source: https://docs.rs/wgpu/29.0.3/wgpu/struct.Adapter.html?search=std%3A%3Avec Creates an Adapter from a custom implementation. ```APIDOC ## from_custom ### Description Creates Adapter from custom implementation. ### Method `Adapter::from_custom` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **adapter** (`T`) - Required - The custom adapter implementation. ### Request Example ```rust // Example usage (assuming 'my_custom_adapter' is an instance of a type implementing AdapterInterface) // let adapter = Adapter::from_custom(my_custom_adapter); ``` ### Response #### Success Response (200) - **Adapter**: An instance of the Adapter struct wrapping the custom implementation. #### Response Example ```rust // Returns a new Adapter instance. ``` ``` -------------------------------- ### Device::adapter_info Source: https://docs.rs/wgpu/29.0.3/wgpu/struct.Device.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Gets information about the adapter from which this device was created. ```APIDOC ## Device::adapter_info ### Description Get info about the adapter that this device was created from. ### Parameters - `self`: A reference to the `Device` instance. ### Returns - `AdapterInfo`: Information about the adapter. ``` -------------------------------- ### Getting Data into a Buffer Source: https://docs.rs/wgpu/29.0.3/wgpu/struct.Buffer.html Explains various methods for loading data into a wgpu Buffer, including during creation, mapping, copying, and using staging belts. ```APIDOC ## §How to get your data into a buffer Every `Buffer` starts with all bytes zeroed. There are many ways to load data into a `Buffer`: * When creating a buffer, you may set the `mapped_at_creation` flag, then write to its `get_mapped_range_mut()`. This only works when the buffer is created and has not yet been used by the GPU, but it is all you need for buffers whose contents do not change after creation. * You may use `DeviceExt::create_buffer_init()` as a convenient way to do that and copy data from a `&[u8]` you provide. * After creation, you may use `Buffer::map_async()` to map it again; however, you then need to wait until the GPU is no longer using the buffer before you begin writing. * You may use `CommandEncoder::copy_buffer_to_buffer()` to copy data into this buffer from another buffer. * You may use `Queue::write_buffer()` to copy data into the buffer from a `&[u8]`. This uses a temporary “staging” buffer managed by `wgpu` to hold the data. * `Queue::write_buffer_with()` allows you to write directly into temporary storage instead of providing a slice you already prepared, which may allow _your_ code to save the allocation of a `Vec` or such. * You may use `util::StagingBelt` to manage a set of temporary buffers. This may be more efficient than `Queue::write_buffer_with()` when you have many small copies to perform, but requires more steps to use, and tuning of the belt buffer size. * You may write your own staging buffer management customized to your application, based on mapped buffers and `CommandEncoder::copy_buffer_to_buffer()`. * A GPU computation’s results can be stored in a buffer: * A compute shader may write to a buffer bound as a storage buffer. * A render pass may render to a texture which is then copied to a buffer using `CommandEncoder::copy_texture_to_buffer()`. ```