pub struct Device { /* private fields */ }Implementations§
Source§impl Device
impl Device
Sourcepub fn create_buffer(&self, desc: &BufferDesc<'_>) -> Result<Buffer, Error>
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");Sourcepub fn create_buffer_init(
&self,
desc: &BufferDesc<'_>,
data: &[u8],
) -> Result<Buffer, Error>
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();Sourcepub fn create_buffer_init_slice<T: NoUninit>(
&self,
desc: &BufferDesc<'_>,
data: &[T],
) -> Result<Buffer, Error>
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();pub fn create_shader_spirv(&self, spirv_words: &[u32]) -> Result<Shader, Error>
pub fn create_compute_pipeline( &self, shader: &Shader, buffer_count: u32, ) -> Result<ComputePipeline, Error>
pub fn create_bindless_compute_pipeline( &self, shader: &Shader, ) -> Result<BindlessComputePipeline, Error>
Sourcepub fn create_texture(&self, desc: &TextureDesc<'_>) -> Result<Texture, Error>
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");pub fn create_sampler(&self, desc: &SamplerDesc<'_>) -> Result<Sampler, Error>
Sourcepub fn write_buffer_descriptors_batch(
&self,
writes: &[(u32, &Buffer)],
) -> Result<(), Error>
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.
pub fn create_graphics_pipeline( &self, shader: &Shader, vs_entry: &str, fs_entry: &str, color_format: TextureFormat, ) -> Result<GraphicsPipeline, Error>
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>
pub fn create_graphics_pipeline_with_desc( &self, shader: &Shader, desc: &GraphicsPipelineDesc<'_>, ) -> Result<GraphicsPipeline, Error>
Sourcepub fn create_command_encoder(&self) -> Result<CommandEncoder, Error>
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();pub fn create_timeline_semaphore( &self, initial_value: u64, ) -> Result<TimelineSemaphore, Error>
pub fn wait_idle(&self) -> Result<(), Error>
pub fn write_texture(&self, texture: &Texture, data: &[u8]) -> Result<(), Error>
Auto Trait Implementations§
impl Freeze 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> 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
Mutably borrows from an owned value. Read more