Skip to main content

Device

Struct Device 

Source
pub struct Device { /* private fields */ }
Expand description

Handle to the GPU. Cheap to clone and safe to share across threads. Clones submit to the same queue; Device::fork makes a handle with its own queue, so renderers on several threads run side by side on the GPU instead of waiting on each other’s barriers.

Implementations§

Source§

impl Device

Source

pub fn new() -> Result<Self, GpuError>

The GPU with one queue: what a renderer on one thread submits to.

Source

pub fn with_lanes(lanes: usize) -> Result<Self, GpuError>

The GPU with up to lanes queues (as many as its compute family has, at most 8), for that many renderers made with Device::fork to run side by side. Each queue costs start-up and teardown time (on NVIDIA a channel, about 25 ms each), so only callers that fork ask for more than one.

Source

pub fn fork(&self) -> Result<Device, GpuError>

A handle to the same GPU that submits to its own queue (the next one round-robin): for a renderer on another thread.

Source

pub fn name(&self) -> String

Source

pub fn backend(&self) -> &'static str

Source

pub fn memory_in_use(&self) -> u64

Device-local memory this process uses (driver-reported with VK_EXT_memory_budget; otherwise the allocator’s blocks).

Source

pub fn memory_breakdown(&self, top: usize) -> String

The largest groups of live allocations by label, for debugging.

Source

pub fn memory_allocated(&self) -> (u64, u64)

(bytes in live allocations, bytes of memory blocks holding them).

Source

pub fn memory_bytes(&self) -> u64

Size of the largest device-local heap.

Source

pub fn stats(&self) -> TransferStats

Source

pub fn note_upload(&self, bytes: usize)

Counts bytes the CPU wrote into GPU-visible memory directly (Buffer::mapped) as an upload.

Source

pub fn library(&self, spirv: &[u8]) -> Result<Library, GpuError>

Creates a library from a SPIR-V module (as produced by Slang).

Source

pub fn create_texture(&self, desc: TextureDesc) -> Texture

Source

pub fn reclaim(&self)

Waits for this handle’s frames in flight and lets go of the resources they kept alive. Frames normally release them only when their ring slot is reused; under memory pressure that delay is several frames’ worth of replaced textures.

Source

pub fn upload_texture_from(&self, desc: TextureDesc, buffer: &Buffer) -> Texture

Creates a GPU texture filled with bytes (tightly packed rows). Counted as an upload. The copy is recorded at the front of this lane’s next command list (no wait here). Like upload_texture from bytes already in a host-visible buffer (filled through Buffer::mapped by a decoder thread): no copy on this thread, the GPU reads the buffer. The buffer must hold the texture’s rows tightly packed.

Source

pub fn upload_texture(&self, desc: TextureDesc, bytes: &[u8]) -> Texture

Source

pub fn create_buffer(&self, len: usize, init: Option<&[u8]>) -> Buffer

Source

pub fn pipeline_stats(&self) -> (u64, u64, f64)

Pipelines created so far: (loaded from stored binaries, compiled by the driver, seconds spent compiling).

Source

pub fn uuid(&self) -> [u8; 16]

The device’s UUID (matches CUDA’s cuDeviceGetUuid for the same GPU).

Source

pub fn create_exported_buffer( &self, len: usize, ) -> Result<(Buffer, ExportedMemory, u64), GpuError>

A device-local storage buffer whose memory is exported for CUDA to import, so NVENC can read what kernels write without a copy: as an opaque file descriptor (VK_KHR_external_memory_fd; the importer takes ownership), or on Windows an opaque NT handle (VK_KHR_external_memory_win32; the importer must close it). Returns the buffer, the descriptor or handle, and the size of the memory behind it.

Source

pub fn create_private_buffer(&self, len: usize) -> Buffer

A buffer only the GPU reads and writes (accumulators, simulation state): device-local, never mapped. read_buffer / write_buffer must not be used on it.

Source

pub fn read_buffer(&self, buf: &Buffer, len: usize) -> Vec<u8> ⓘ

Copies the first len bytes of a buffer to the CPU (the GPU must be done writing it). Counted as a readback.

Source

pub fn write_buffer(&self, buf: &Buffer, data: &[u8])

Source

pub fn begin(&self) -> CommandList

Starts recording a frame. Blocks only if the frame that last used this ring slot is still executing. Threads recording at once each get a slot of their own (the ring grows when more record than it has).

Source

pub fn readback(&self, tex: &Texture) -> Vec<u8> ⓘ

Copies a CPU-readable texture to CPU memory, tightly packed. Counted as a readback.

Source§

impl Device

Source

pub fn draw_pipeline( &self, library: &Library, vertex: &str, fragment: &str, samples: u32, depth: bool, blend: Blend, color: PixelFormat, ) -> Result<DrawPipeline, GpuError>

Source

pub fn create_attachment( &self, width: u32, height: u32, format: PixelFormat, samples: u32, ) -> Texture

A render attachment: multisampled color, or depth.

Trait Implementations§

Source§

impl Clone for Device

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl Forget for Device

§

impl Freeze for Device

§

impl Move for Device

§

impl RefUnwindSafe for Device

§

impl Send for Device

§

impl Sync for Device

§

impl Unpin for Device

§

impl UnsafeUnpin for Device

§

impl UnwindSafe for Device

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.