Files
craft-libs/crates/gpu/src/chunk.rs
T
William Dunn ba866e1e45 craft-gpu: add the GPU job traits and the shared providers.
This carries over crates/gpu, crates/gpu-wgpu, crates/gpu-null, and crates/gpu-providers from the cut-down #160 branch, with minimal workspace wiring.

None of these crates names a vendor or any app. craft-gpu defines GpuJob and ProviderRegistry. craft-gpu-null is an in-memory context for tests. craft-gpu-providers holds the shared craft.* WGSL providers. craft-gpu-wgpu is the wgpu backend, native and WebGPU.
2026-11-15 20:35:22 -05:00

12 lines
578 B
Rust

use crate::{DeviceCaps, GpuFault};
/// Split `data` into contiguous slices no larger than [`DeviceCaps::max_storage_buffer_binding_size`].
pub fn chunk_buffer<'a>(caps: &DeviceCaps, data: &'a [u8]) -> Result<Vec<&'a [u8]>, GpuFault> {
let max = usize::try_from(caps.max_storage_buffer_binding_size)
.map_err(|_| GpuFault::Operation("max_storage_buffer_binding_size exceeds host address space".into()))?;
if max == 0 {
return Err(GpuFault::Operation("max_storage_buffer_binding_size must be non-zero".into()));
}
Ok(data.chunks(max).collect())
}