Crate wgpu_conveyor

Crate wgpu_conveyor 

Source
Expand description

Buffer belt abstraction for wgpu supporting UMA optimization, automatic resizing, and a bind group cache.

§Example

use wgpu_conveyor::{AutomatedBuffer, AutomatedBufferManager, UploadStyle, BindGroupCache};
use wgpu::*;

// Create wgpu instance, adapter, device, queue, and bind_group_layout.

let device_type = adapter.get_info().device_type;

// Create a single buffer manager.
let mut manager = AutomatedBufferManager::new(UploadStyle::from_device_type(&device_type));

// Create a buffer from that manager
let mut buffer = manager.create_new_buffer(&device, 128, BufferUsage::UNIFORM, Some("label"));

/////////////////////////////////////
// -- Below happens every frame -- //
/////////////////////////////////////

// Write to that buffer
let mut command_encoder = device.create_command_encoder(&CommandEncoderDescriptor::default());
buffer.write_to_buffer(
    &device,
    &mut command_encoder,
    128,
    |_encoder: &mut CommandEncoder, buffer: &mut [u8]| {
        for (idx, byte) in buffer.iter_mut().enumerate() {
            *byte = idx as u8;
        }
    }
);

// Use buffer in bind group
let mut bind_group_cache = BindGroupCache::new();
let bind_group_key = bind_group_cache.create_bind_group(&buffer, true, |raw_buf| {
    device.create_bind_group(&BindGroupDescriptor {
        label: None,
        layout: &bind_group_layout,
        entries: &[BindGroupEntry {
            binding: 0,
            resource: raw_buf.inner.as_entire_binding()
        }]
    })
});

// Use bind group
renderpass.set_bind_group(0, bind_group_cache.get(&bind_group_key).unwrap(), &[]);

// Submit copies
queue.submit(Some(command_encoder.finish()));

// Pump buffers
let futures = manager.pump();

// Run futures async
for fut in futures {
    spawn(fut);
}

// Loop back to beginning of frame

§MSRV

Rust 1.47

Structs§

AutomatedBuffer
A buffer which automatically uses either staging buffers or direct mapping to write to its internal buffer based on the provided UploadStyle.
AutomatedBufferManager
Creates and manages all running AutomatedBuffers.
AutomatedBufferStats
Statistics about current buffers.
BindGroupCache
Bind group cache. Corresponds to a single bind group.
IdBuffer
A buffer plus an id, internal size, and dirty flag.

Enums§

UploadStyle
Method of upload used by all automated buffers.

Traits§

AutomatedBufferSet
Values that can be used with BindGroupCache.

Functions§

write_to_buffer1
Write to a single AutomatedBuffer.
write_to_buffer2
Write to a two AutomatedBuffers at the same time.
write_to_buffer3
Write to a three AutomatedBuffers at the same time.
write_to_buffer4
Write to a four AutomatedBuffers at the same time.

Type Aliases§

BeltBufferId
BufferCache1
Key type for a single buffer.
BufferCache2
Key type for two buffers.
BufferCache3
Key type for three buffers.
BufferCache4
Key type for four buffers.