### Rust Ecosystem Links Source: https://docs.rs/wgpu-hal/latest/src/wgpu_hal/dynamic/surface Provides links to essential Rust resources, including the Rust website, The Book, Standard Library API Reference, Rust by Example, the Cargo Guide, and Clippy documentation. ```rust Rust website: https://www.rust-lang.org/ The Book: https://doc.rust-lang.org/book/ Standard Library API Reference: https://doc.rust-lang.org/std/ Rust by Example: https://doc.rust-lang.org/rust-by-example/ The Cargo Guide: https://doc.rust-lang.org/cargo/guide/ Clippy Documentation: https://doc.rust-lang.org/nightly/clippy ``` -------------------------------- ### Render Pipeline and Index Buffer Setup Source: https://docs.rs/wgpu-hal/latest/src/wgpu_hal/dynamic/command Methods for setting the render pipeline and configuring the index buffer for rendering operations. ```rust unsafe fn set_render_pipeline(&mut self, pipeline: &dyn DynRenderPipeline) { let pipeline = pipeline.expect_downcast_ref(); unsafe { C::set_render_pipeline(self, pipeline) }; } unsafe fn set_index_buffer<'a>( &mut self, binding: BufferBinding<'a, dyn DynBuffer>, format: wgt::IndexFormat, ) { let binding = BufferBinding { buffer: binding.buffer.expect_downcast_ref(), offset: binding.offset, size: binding.size, }; unsafe { C::set_index_buffer(self, binding, format) }; } ``` -------------------------------- ### Rust Ecosystem Links Source: https://docs.rs/wgpu-hal/latest/src/wgpu_hal/vulkan/adapter A collection of useful links related to the Rust programming language and its ecosystem, including documentation, guides, and tools. ```rust Rust website: https://www.rust-lang.org/ The Book: https://doc.rust-lang.org/book/ Standard Library API Reference: https://doc.rust-lang.org/std/ Rust by Example: https://doc.rust-lang.org/rust-by-example/ The Cargo Guide: https://doc.rust-lang.org/cargo/guide/ Clippy Documentation: https://doc.rust-lang.org/nightly/clippy ``` -------------------------------- ### External Documentation Links Source: https://docs.rs/wgpu-hal/latest/src/wgpu_hal/dynamic/mod Provides links to external resources related to Rust programming, including the official Rust website, The Book, Standard Library API Reference, Rust by Example, The Cargo Guide, and Clippy Documentation. ```Rust * [Rust website](https://www.rust-lang.org/) * [The Book](https://doc.rust-lang.org/book/) * [Standard Library API Reference](https://doc.rust-lang.org/std/) * [Rust by Example](https://doc.rust-lang.org/rust-by-example/) * [The Cargo Guide](https://doc.rust-lang.org/cargo/guide/) * [Clippy Documentation](https://doc.rust-lang.org/nightly/clippy) ``` -------------------------------- ### wgpu-hal Vulkan Instance Management Source: https://docs.rs/wgpu-hal/latest/src/wgpu_hal/gles/mod Documentation for managing Vulkan instances and related setup within the wgpu-hal crate. ```rust https://docs.rs/wgpu-hal/latest/src/wgpu_hal/vulkan/instance.rs.html ``` -------------------------------- ### Vulkan Queue Initialization Source: https://docs.rs/wgpu-hal/latest/src/wgpu_hal/vulkan/adapter This snippet demonstrates the setup of a Vulkan queue, linking it to the created device and configuring its associated swapchain and semaphore handling. It includes the initialization of relay semaphores for inter-queue communication. ```rust let queue = super::Queue { raw: raw_queue, swapchain_fn, device: Arc::clone(&shared), family_index, relay_semaphores: Mutex::new(relay_semaphores), signal_semaphores: Default::default(), }; ``` -------------------------------- ### Option::zip Example Source: https://docs.rs/wgpu-hal/latest/wgpu_hal/type Demonstrates the usage of the `zip` method for `Option` types. It pairs `Some` values from two Options and returns `None` if either Option is `None`. ```rust let x = Some(1); let y = Some("hi"); let z = None::; assert_eq!(x.zip(y), Some((1, "hi"))); assert_eq!(x.zip(z), None); ``` -------------------------------- ### Related Resources Source: https://docs.rs/wgpu-hal/latest/src/wgpu_hal/vulkan/drm This snippet provides links to various resources related to Rust and its ecosystem, including The Book, Standard Library API Reference, and Rust by Example. ```rust Rust website The Book Standard Library API Reference Rust by Example The Cargo Guide Clippy Documentation ``` -------------------------------- ### Option::zip_with Example Source: https://docs.rs/wgpu-hal/latest/wgpu_hal/type Illustrates the `zip_with` method, which combines two `Option` values using a provided function. If both Options are `Some`, the function is applied to their values; otherwise, `None` is returned. This is a nightly-only experimental API. ```rust #![feature(option_zip)] #[derive(Debug, PartialEq)] struct Point { x: f64, y: f64, } impl Point { fn new(x: f64, y: f64) -> Self { Self { x, y } } } let x = Some(17.5); let y = Some(42.7); assert_eq!(x.zip_with(y, Point::new), Some(Point { x: 17.5, y: 42.7 })); assert_eq!(x.zip_with(None, Point::new), None); ``` -------------------------------- ### wgpu-hal Adapter and Instance Structs Source: https://docs.rs/wgpu-hal/latest/wgpu_hal/constant Documentation for structs related to adapter discovery and instance creation, including capabilities and error handling. ```rust struct Capabilities; struct DynExposedAdapter; struct DynOpenDevice; struct ExposedAdapter; struct InstanceDescriptor; struct InstanceError; ``` -------------------------------- ### wgpu-hal Vulkan Backend Source: https://docs.rs/wgpu-hal/latest/src/wgpu_hal/gles/device Documentation for the Vulkan backend implementation in wgpu-hal, including adapter, command, conv, device, drm, instance, sampler, and semaphore_list. ```rust adapter.rs command.rs conv.rs device.rs drm.rs instance.rs mod.rs sampler.rs semaphore_list.rs ``` -------------------------------- ### Rust Option IntoIterator Examples Source: https://docs.rs/wgpu-hal/latest/wgpu_hal/type Provides usage examples for the `into_iter` method on Rust's `Option` type, demonstrating iteration over `Some` and `None` variants. ```rust let x = Some("string"); let v: Vec<&str> = x.into_iter().collect(); assert_eq!(v, ["string"]); let x = None; let v: Vec<&str> = x.into_iter().collect(); assert!(v.is_empty()); ``` -------------------------------- ### wgpu-hal Adapter and Instance Structs Source: https://docs.rs/wgpu-hal/latest/wgpu_hal/noop/index Documentation for structs related to adapter discovery and instance creation, including capabilities and error handling. ```rust struct Capabilities; struct DynExposedAdapter; struct DynOpenDevice; struct ExposedAdapter; struct InstanceDescriptor; struct InstanceError; ``` -------------------------------- ### unwrap_unchecked Example Source: https://docs.rs/wgpu-hal/latest/wgpu_hal/type Shows an example of using unwrap_unchecked to retrieve the value from a Some variant without checking if it's None. This is unsafe and can lead to undefined behavior if called on None. ```rust let x = Some("air"); assert_eq!(unsafe { x.unwrap_unchecked() }, "air"); ``` -------------------------------- ### wgpu-hal Adapter and Instance Structs Source: https://docs.rs/wgpu-hal/latest/wgpu_hal/auxil/index Documentation for structs related to adapter discovery and instance creation, including capabilities and error handling. ```rust struct Capabilities; struct DynExposedAdapter; struct DynOpenDevice; struct ExposedAdapter; struct InstanceDescriptor; struct InstanceError; ``` -------------------------------- ### wgpu-hal Dynamic Backend Source: https://docs.rs/wgpu-hal/latest/src/wgpu_hal/gles/device Documentation for the dynamic backend implementation in wgpu-hal, covering adapter, command, device, instance, queue, and surface. ```rust adapter.rs command.rs device.rs instance.rs mod.rs queue.rs surface.rs ``` -------------------------------- ### Get Buffer Device Address Source: https://docs.rs/wgpu-hal/latest/src/wgpu_hal/vulkan/command This code defines a closure to safely get the device address of a Vulkan buffer. It handles cases where the buffer might be None, panicking if a buffer is required but not provided. It uses `vk::BufferDeviceAddressInfo` to query the address. ```rust let get_device_address = |buffer: Option<&super::Buffer>| unsafe { match buffer { Some(buffer) => ray_tracing_functions .buffer_device_address .get_buffer_device_address( &vk::BufferDeviceAddressInfo::default().buffer(buffer.raw), ), None => panic!("Buffers are required to build acceleration structures"), } }; ``` -------------------------------- ### wgpu-hal Dynamic Backend Files Source: https://docs.rs/wgpu-hal/latest/src/wgpu_hal/vulkan/instance This snippet outlines the files associated with the dynamic backend implementation in the wgpu-hal crate, covering adapters, commands, devices, instances, queues, and surfaces. ```rust dynamic [adapter.rs](https://docs.rs/wgpu-hal/latest/src/wgpu_hal/dynamic/adapter.rs.html)[command.rs](https://docs.rs/wgpu-hal/latest/src/wgpu_hal/dynamic/command.rs.html)[device.rs](https://docs.rs/wgpu-hal/latest/src/wgpu_hal/dynamic/device.rs.html)[instance.rs](https://docs.rs/wgpu-hal/latest/src/wgpu_hal/dynamic/instance.rs.html)[mod.rs](https://docs.rs/wgpu-hal/latest/src/wgpu_hal/dynamic/mod.rs.html)[queue.rs](https://docs.rs/wgpu-hal/latest/src/wgpu_hal/dynamic/queue.rs.html)[surface.rs](https://docs.rs/wgpu-hal/latest/src/wgpu_hal/dynamic/surface.rs.html) ``` -------------------------------- ### Draw Vertices Source: https://docs.rs/wgpu-hal/latest/src/wgpu_hal/dynamic/command Draws a specified number of vertices starting from a given vertex. Supports instancing. ```rust unsafe fn draw( &mut self, first_vertex: u32, vertex_count: u32, first_instance: u32, instance_count: u32, ) { unsafe { C::draw( self, first_vertex, vertex_count, first_instance, instance_count, ) }; } ``` -------------------------------- ### wgpu-hal Adapter and Instance Structs Source: https://docs.rs/wgpu-hal/latest/wgpu_hal/vulkan/index Documentation for structs related to adapter discovery and instance creation, including capabilities and error handling. ```rust struct Capabilities; struct DynExposedAdapter; struct DynOpenDevice; struct ExposedAdapter; struct InstanceDescriptor; struct InstanceError; ``` -------------------------------- ### Get Internal Counters Source: https://docs.rs/wgpu-hal/latest/src/wgpu_hal/vulkan/device Retrieves the internal hardware counters for the Vulkan device. This includes memory allocation statistics. ```rust fn get_internal_counters(&self) -> wgt::HalCounters { self.counters .memory_allocations .set(self.shared.memory_allocations_counter.read()); self.counters.as_ref().clone() } ``` -------------------------------- ### unwrap_or_default Example Source: https://docs.rs/wgpu-hal/latest/wgpu_hal/type Demonstrates the use of unwrap_or_default to provide a default value when an Option is None. This method consumes the Option. ```rust let k = 10; assert_eq!(Some(4).unwrap_or_else(|| 2 * k), 4); assert_eq!(None.unwrap_or_else(|| 2 * k), 20); ``` -------------------------------- ### docs.rs Information Source: https://docs.rs/wgpu-hal/latest/src/wgpu_hal/vulkan/adapter Links to various informational pages on docs.rs, the official Rust documentation hosting service. ```rust docs.rs: about about/badges about/builds about/metadata about/redirections about/download about/rustdoc-json releases/queue about/rust-lang-org/policies/privacy-policy/#docs.rs ``` -------------------------------- ### Get Presentation Timestamp Source: https://docs.rs/wgpu-hal/latest/src/wgpu_hal/gles/adapter Retrieves the presentation timestamp for the GLES adapter. This function currently returns an invalid timestamp. ```rust unsafe fn get_presentation_timestamp(&self) -> wgt::PresentationTimestamp { wgt::PresentationTimestamp::INVALID_TIMESTAMP } ``` -------------------------------- ### wgpu-hal Adapter and Instance Structs Source: https://docs.rs/wgpu-hal/latest/wgpu_hal/api/index Documentation for structs related to adapter discovery and instance creation, including capabilities and error handling. ```rust struct Capabilities; struct DynExposedAdapter; struct DynOpenDevice; struct ExposedAdapter; struct InstanceDescriptor; struct InstanceError; ``` -------------------------------- ### wgpu-hal Adapter and Instance Structs Source: https://docs.rs/wgpu-hal/latest/wgpu_hal/gles/index Documentation for structs related to adapter discovery and instance creation, including capabilities and error handling. ```rust struct Capabilities; struct DynExposedAdapter; struct DynOpenDevice; struct ExposedAdapter; struct InstanceDescriptor; struct InstanceError; ``` -------------------------------- ### Get EGL Context Source: https://docs.rs/wgpu-hal/latest/src/wgpu_hal/gles/egl Retrieves a reference to the underlying EGL context from a wgpu-hal Device. This is useful for direct interaction with EGL functionalities. ```rust impl super::Device { /// Returns the underlying EGL context. pub fn context(&self) -> &AdapterContext { &self.shared.context } } ``` -------------------------------- ### Get Internal Counters Source: https://docs.rs/wgpu-hal/latest/src/wgpu_hal/dynamic/device Retrieves the internal hardware performance counters for the device. This method is part of the dynamic dispatch for device operations. ```rust fn get_internal_counters(&self) -> wgt::HalCounters { D::get_internal_counters(self) } ``` -------------------------------- ### wgpu-hal Adapter and Instance Structs Source: https://docs.rs/wgpu-hal/latest/wgpu_hal/enum Documentation for structs related to adapter discovery and instance creation, including capabilities and error handling. ```rust struct Capabilities; struct DynExposedAdapter; struct DynOpenDevice; struct ExposedAdapter; struct InstanceDescriptor; struct InstanceError; ``` -------------------------------- ### wgpu-hal Adapter and Instance Structs Source: https://docs.rs/wgpu-hal/latest/wgpu_hal/type Documentation for structs related to adapter discovery and instance creation, including capabilities and error handling. ```rust struct Capabilities; struct DynExposedAdapter; struct DynOpenDevice; struct ExposedAdapter; struct InstanceDescriptor; struct InstanceError; ``` -------------------------------- ### Draw Indexed Vertices Source: https://docs.rs/wgpu-hal/latest/src/wgpu_hal/dynamic/command Draws a specified number of indices starting from a given index. Supports instancing and base vertex offset. ```rust unsafe fn draw_indexed( &mut self, first_index: u32, index_count: u32, base_vertex: i32, first_instance: u32, instance_count: u32, ) { unsafe { C::draw_indexed( self, first_index, index_count, base_vertex, first_instance, instance_count, ) }; } ``` -------------------------------- ### wgpu-hal Vulkan Backend Files Source: https://docs.rs/wgpu-hal/latest/src/wgpu_hal/vulkan/instance This snippet lists the files associated with the Vulkan backend implementation in the wgpu-hal crate, including adapter, command, conversion, device, DRM, instance, sampler, and semaphore list functionalities. ```rust vulkan [adapter.rs](https://docs.rs/wgpu-hal/latest/src/wgpu_hal/vulkan/adapter.rs.html)[command.rs](https://docs.rs/wgpu-hal/latest/src/wgpu_hal/vulkan/command.rs.html)[conv.rs](https://docs.rs/wgpu-hal/latest/src/wgpu_hal/vulkan/conv.rs.html)[device.rs](https://docs.rs/wgpu-hal/latest/src/wgpu_hal/vulkan/device.rs.html)[drm.rs](https://docs.rs/wgpu-hal/latest/src/wgpu_hal/vulkan/drm.rs.html)[instance.rs](https://docs.rs/wgpu-hal/latest/src/wgpu_hal/vulkan/instance.rs.html)[mod.rs](https://docs.rs/wgpu-hal/latest/src/wgpu_hal/vulkan/mod.rs.html)[sampler.rs](https://docs.rs/wgpu-hal/latest/src/wgpu_hal/vulkan/sampler.rs.html)[semaphore_list.rs](https://docs.rs/wgpu-hal/latest/src/wgpu_hal/vulkan/semaphore_list.rs.html) ``` -------------------------------- ### Checked Addition Example Source: https://docs.rs/wgpu-hal/latest/wgpu_hal/type Demonstrates incrementing integers in a vector using `checked_add`. It returns `Some(Vec)` if no overflow occurs, otherwise `None`. ```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])); ``` -------------------------------- ### Checked Subtraction (No Further Elements) Source: https://docs.rs/wgpu-hal/latest/wgpu_hal/type Shows that iteration stops after the first `None` result from `checked_sub`. This example verifies that `shared` is not updated with elements after the underflow. ```rust let items = vec![3_u16, 2, 1, 10]; let mut shared = 0; let res: Option> = items .iter() .map(|x| { shared += x; x.checked_sub(2) }) .collect(); assert_eq!(res, None); assert_eq!(shared, 6); ```