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
impl Device
Sourcepub fn new() -> Result<Self, GpuError>
pub fn new() -> Result<Self, GpuError>
The GPU with one queue: what a renderer on one thread submits to.
Sourcepub fn with_lanes(lanes: usize) -> Result<Self, GpuError>
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.
Sourcepub fn fork(&self) -> Result<Device, GpuError>
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.
pub fn name(&self) -> String
pub fn backend(&self) -> &'static str
Sourcepub fn memory_in_use(&self) -> u64
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).
Sourcepub fn memory_breakdown(&self, top: usize) -> String
pub fn memory_breakdown(&self, top: usize) -> String
The largest groups of live allocations by label, for debugging.
Sourcepub fn memory_allocated(&self) -> (u64, u64)
pub fn memory_allocated(&self) -> (u64, u64)
(bytes in live allocations, bytes of memory blocks holding them).
Sourcepub fn memory_bytes(&self) -> u64
pub fn memory_bytes(&self) -> u64
Size of the largest device-local heap.
pub fn stats(&self) -> TransferStats
Sourcepub fn note_upload(&self, bytes: usize)
pub fn note_upload(&self, bytes: usize)
Counts bytes the CPU wrote into GPU-visible memory directly
(Buffer::mapped) as an upload.
Sourcepub fn library(&self, spirv: &[u8]) -> Result<Library, GpuError>
pub fn library(&self, spirv: &[u8]) -> Result<Library, GpuError>
Creates a library from a SPIR-V module (as produced by Slang).
pub fn create_texture(&self, desc: TextureDesc) -> Texture
Sourcepub fn reclaim(&self)
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.
Sourcepub fn upload_texture_from(&self, desc: TextureDesc, buffer: &Buffer) -> Texture
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.
pub fn upload_texture(&self, desc: TextureDesc, bytes: &[u8]) -> Texture
pub fn create_buffer(&self, len: usize, init: Option<&[u8]>) -> Buffer
Sourcepub fn pipeline_stats(&self) -> (u64, u64, f64)
pub fn pipeline_stats(&self) -> (u64, u64, f64)
Pipelines created so far: (loaded from stored binaries, compiled by the driver, seconds spent compiling).
Sourcepub fn uuid(&self) -> [u8; 16]
pub fn uuid(&self) -> [u8; 16]
The device’s UUID (matches CUDA’s cuDeviceGetUuid for the same GPU).
Sourcepub fn create_exported_buffer(
&self,
len: usize,
) -> Result<(Buffer, ExportedMemory, u64), GpuError>
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.
Sourcepub fn create_private_buffer(&self, len: usize) -> Buffer
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.
Sourcepub fn read_buffer(&self, buf: &Buffer, len: usize) -> Vec<u8> ⓘ
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.
pub fn write_buffer(&self, buf: &Buffer, data: &[u8])
Sourcepub fn begin(&self) -> CommandList
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§impl Device
impl Device
pub fn draw_pipeline( &self, library: &Library, vertex: &str, fragment: &str, samples: u32, depth: bool, blend: Blend, color: PixelFormat, ) -> Result<DrawPipeline, GpuError>
Sourcepub fn create_attachment(
&self,
width: u32,
height: u32,
format: PixelFormat,
samples: u32,
) -> Texture
pub fn create_attachment( &self, width: u32, height: u32, format: PixelFormat, samples: u32, ) -> Texture
A render attachment: multisampled color, or depth.