Skip to main content

Device

Struct Device 

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

Implementations§

Source§

impl Device

Source

pub fn create_buffer(&self, desc: &BufferDesc<'_>) -> Result<Buffer, Error>

Creates an uninitialized GPU Buffer according to BufferDesc.

§Example
use lgpu::{BufferDesc, BufferUsage, Device, MemoryLocation};

let desc = BufferDesc {
    label: Some("StorageBuffer"),
    size: 1024,
    usage: BufferUsage::STORAGE,
    memory_location: MemoryLocation::GpuOnly,
};
let buffer = device.create_buffer(&desc).expect("Failed to create buffer");
Source

pub fn create_buffer_init( &self, desc: &BufferDesc<'_>, data: &[u8], ) -> Result<Buffer, Error>

Creates a host-mapped GPU Buffer initialized with the provided byte slice.

§Example
use lgpu::{BufferDesc, BufferUsage, Device, MemoryLocation};

let desc = BufferDesc {
    label: Some("InitBuffer"),
    size: 64,
    usage: BufferUsage::STORAGE,
    memory_location: MemoryLocation::CpuToGpu,
};
let initial_bytes = [1u8, 2, 3, 4];
let buffer = device.create_buffer_init(&desc, &initial_bytes).unwrap();
Source

pub fn create_buffer_init_slice<T: NoUninit>( &self, desc: &BufferDesc<'_>, data: &[T], ) -> Result<Buffer, Error>

Creates a host-mapped GPU Buffer initialized with a typed slice implementing bytemuck::NoUninit.

§Example
use lgpu::{BufferDesc, BufferUsage, Device, MemoryLocation};

let desc = BufferDesc {
    label: Some("FloatBuffer"),
    size: 16,
    usage: BufferUsage::STORAGE,
    memory_location: MemoryLocation::CpuToGpu,
};
let floats = [1.0f32, 2.0, 3.0, 4.0];
let buffer = device.create_buffer_init_slice(&desc, &floats).unwrap();
Source

pub fn create_shader_spirv(&self, spirv_words: &[u32]) -> Result<Shader, Error>

Source

pub fn create_compute_pipeline( &self, shader: &Shader, buffer_count: u32, ) -> Result<ComputePipeline, Error>

Source

pub fn create_bindless_compute_pipeline( &self, shader: &Shader, ) -> Result<BindlessComputePipeline, Error>

Source

pub fn create_texture(&self, desc: &TextureDesc<'_>) -> Result<Texture, Error>

Creates a GPU Texture according to TextureDesc.

§Example
use lgpu::{Device, TextureDesc, TextureFormat, TextureUsage};

let desc = TextureDesc::new_2d(
    512,
    512,
    TextureFormat::Rgba8Unorm,
    TextureUsage::TEXTURE_BINDING | TextureUsage::COPY_DST,
);
let texture = device.create_texture(&desc).expect("Failed to create texture");
Source

pub fn create_sampler(&self, desc: &SamplerDesc<'_>) -> Result<Sampler, Error>

Source

pub fn write_buffer_descriptors_batch( &self, writes: &[(u32, &Buffer)], ) -> Result<(), Error>

Performs a batched update of bindless buffer descriptors in a single driver call.

Source

pub fn create_graphics_pipeline( &self, shader: &Shader, vs_entry: &str, fs_entry: &str, color_format: TextureFormat, ) -> Result<GraphicsPipeline, Error>

Source

pub fn create_graphics_pipeline_with_depth( &self, shader: &Shader, vs_entry: &str, fs_entry: &str, color_format: TextureFormat, depth_format: Option<TextureFormat>, depth_test: bool, depth_write: bool, ) -> Result<GraphicsPipeline, Error>

Source

pub fn create_graphics_pipeline_with_desc( &self, shader: &Shader, desc: &GraphicsPipelineDesc<'_>, ) -> Result<GraphicsPipeline, Error>

Source

pub fn create_command_encoder(&self) -> Result<CommandEncoder, Error>

Creates a new CommandEncoder for recording graphics and compute commands.

§Example
use lgpu::Device;

let mut encoder = device.create_command_encoder().expect("Failed to create encoder");
// Record barriers, clear passes, or dispatches...
let command_buffer = encoder.finish();
Source

pub fn create_timeline_semaphore( &self, initial_value: u64, ) -> Result<TimelineSemaphore, Error>

Source

pub fn wait_idle(&self) -> Result<(), Error>

Source

pub fn write_texture(&self, texture: &Texture, data: &[u8]) -> Result<(), Error>

Auto Trait Implementations§

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> 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, 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.