mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-29 17:55:45 +01:00
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.
12 lines
578 B
Rust
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())
|
|
}
|