pub struct WgpuBackendReal {
pub device_info: WgpuDeviceInfo,
/* private fields */
}Expand description
Real GPU compute backend backed by wgpu 29.
Obtain an instance via WgpuBackendReal::try_new (synchronous,
blocks the thread) or WgpuBackendReal::try_new_async from within
an async context.
Fields§
§device_info: WgpuDeviceInfoDevice information (name, backend, driver).
Implementations§
Source§impl WgpuBackendReal
impl WgpuBackendReal
Sourcepub fn try_new() -> Result<Self, WgpuInitError>
pub fn try_new() -> Result<Self, WgpuInitError>
Create a real GPU backend, blocking the calling thread.
Returns Err if no compatible GPU adapter is found or if device
creation fails. Prefer try_new_async from
within an async context.
Sourcepub async fn try_new_async() -> Result<Self, WgpuInitError>
pub async fn try_new_async() -> Result<Self, WgpuInitError>
Create a real GPU backend asynchronously.
This is the preferred entry point from async contexts (tokio,
wasm-bindgen-futures, etc.).
Sourcepub fn is_available(&self) -> bool
pub fn is_available(&self) -> bool
Return true — this struct always wraps a real GPU device.
Sourcepub fn create_buffer_storage(&mut self, size_bytes: u64) -> WgpuBufferHandle
pub fn create_buffer_storage(&mut self, size_bytes: u64) -> WgpuBufferHandle
Allocate a GPU storage buffer of size_bytes bytes.
The buffer is created with STORAGE | COPY_SRC | COPY_DST usage
flags so that it can be used as a shader binding and for staged
CPU read/write.
Sourcepub fn create_buffer_f64(&mut self, len: usize) -> WgpuBufferHandle
pub fn create_buffer_f64(&mut self, len: usize) -> WgpuBufferHandle
Allocate a GPU buffer sized for len f64 values.
Internally the data is stored as f32 on the GPU (8 bytes per
element to maintain the same stride).
Sourcepub fn write_buffer_f64(&self, handle: WgpuBufferHandle, data: &[f64])
pub fn write_buffer_f64(&self, handle: WgpuBufferHandle, data: &[f64])
Upload data to the GPU buffer at handle, casting f64 → f32.
§Panics
Does nothing (silently returns) if handle is out of range.
Sourcepub fn read_buffer_f64(&self, handle: WgpuBufferHandle) -> Vec<f64>
pub fn read_buffer_f64(&self, handle: WgpuBufferHandle) -> Vec<f64>
Download data from the GPU buffer at handle, casting f32 → f64.
This blocks the calling thread until the GPU has finished all outstanding work and the readback mapping is complete.
Returns an empty Vec if the handle is invalid or the readback fails.
Sourcepub fn queue_write_buffer_raw(&self, handle: &WgpuBufferHandle, data: &[u8])
pub fn queue_write_buffer_raw(&self, handle: &WgpuBufferHandle, data: &[u8])
Upload raw bytes to the GPU buffer at handle.
The byte slice must fit within the buffer’s allocated size.
Does nothing (silently returns) if handle is out of range.
Sourcepub fn queue_write_buffer_f32(&self, handle: &WgpuBufferHandle, data: &[f32])
pub fn queue_write_buffer_f32(&self, handle: &WgpuBufferHandle, data: &[f32])
Upload f32 data directly to the GPU buffer at handle (no f64→f32 cast).
Does nothing (silently returns) if handle is out of range.
Sourcepub fn read_buffer_f32(&self, handle: WgpuBufferHandle) -> Vec<f32>
pub fn read_buffer_f32(&self, handle: WgpuBufferHandle) -> Vec<f32>
Download raw f32 values from the GPU buffer at handle.
Returns an empty Vec if the handle is invalid or the readback fails.
Sourcepub fn dispatch_count_for(n_items: usize, workgroup_size: u32) -> [u32; 3]
pub fn dispatch_count_for(n_items: usize, workgroup_size: u32) -> [u32; 3]
Compute the 3-D workgroup dispatch counts for n_items elements.
Returns [0, 1, 1] for n_items == 0 (no-op dispatch).
Sourcepub fn dispatch_wgsl(
&self,
wgsl_src: &str,
entry_point: &str,
buffers: &[(WgpuBufferHandle, BufferBindingType)],
workgroups: [u32; 3],
) -> Result<(), WgpuInitError>
pub fn dispatch_wgsl( &self, wgsl_src: &str, entry_point: &str, buffers: &[(WgpuBufferHandle, BufferBindingType)], workgroups: [u32; 3], ) -> Result<(), WgpuInitError>
Compile and dispatch a WGSL compute shader.
The pipeline is compiled lazily and cached by a hash of
(wgsl_src, entry_point), so repeated calls with the same shader
do not recompile.
§Parameters
wgsl_src— WGSL shader source code.entry_point— Name of the@computeentry point function.buffers— Ordered list of(handle, binding_type)pairs. Binding index in the WGSL shader corresponds to the position in this slice (binding 0 =buffers[0], etc.).workgroups—[x, y, z]dispatch counts.
§Errors
Returns Err(WgpuInitError::InvalidHandle) if any buffer handle is
out of range. Returns Err(WgpuInitError::PoisonedLock) if the
shader-cache mutex is poisoned (should not occur in practice).
Auto Trait Implementations§
impl !Freeze for WgpuBackendReal
impl !RefUnwindSafe for WgpuBackendReal
impl Send for WgpuBackendReal
impl Sync for WgpuBackendReal
impl Unpin for WgpuBackendReal
impl UnsafeUnpin for WgpuBackendReal
impl !UnwindSafe for WgpuBackendReal
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more