| Crates.io | memkit-gpu |
| lib.rs | memkit-gpu |
| version | 0.1.0-alpha.1 |
| created_at | 2025-12-27 00:39:29.942119+00 |
| updated_at | 2025-12-27 00:39:29.942119+00 |
| description | Backend-agnostic GPU memory management for memkit |
| homepage | |
| repository | https://github.com/YelenaTor/memkit |
| max_upload_size | |
| id | 2006493 |
| size | 56,715 |
Backend-agnostic GPU memory management for the memkit ecosystem.
Version: 0.1.0-alpha.1
memkit-gpu provides a unified GPU memory management API that works across different graphics backends. Write your code once, run it on Vulkan, Metal, or DirectX 12.
use memkit_gpu::{MkGpu, MkBufferUsage, DummyBackend};
// Create GPU allocator (using dummy backend for testing)
let gpu = MkGpu::new(DummyBackend::new());
// Create staging buffer and upload data
let vertices: &[f32] = &[0.0, 1.0, 0.0, 1.0, 0.0, 0.0];
let staging = gpu.staging_buffer_with_data(vertices).unwrap();
// Create device-local buffer
let device = gpu.create_device_buffer(
std::mem::size_of_val(vertices),
MkBufferUsage::VERTEX | MkBufferUsage::TRANSFER_DST,
).unwrap();
// Transfer data
gpu.transfer(&staging, &device).unwrap();
use memkit_gpu::{MkGpu, MkGpuBackend, MkBufferUsage};
// Generic function works with ANY backend
fn upload_mesh<B: MkGpuBackend>(
gpu: &MkGpu<B>,
vertices: &[Vertex],
) -> Result<MkDeviceBuffer<B>, B::Error> {
let staging = gpu.staging_buffer_with_data(vertices)?;
let device = gpu.create_device_buffer(
std::mem::size_of_val(vertices),
MkBufferUsage::VERTEX | MkBufferUsage::TRANSFER_DST,
)?;
gpu.transfer(&staging, &device)?;
Ok(device)
}
| Backend | Feature Flag | Status |
|---|---|---|
| Dummy (CPU simulation) | (default) | ✅ Ready |
| Vulkan | vulkan |
✅ Ready |
| Metal | metal |
🚧 Planned |
| DirectX 12 | dx12 |
🚧 Planned |
The dummy backend simulates GPU operations in CPU memory. Useful for:
use memkit_gpu::{DummyBackend, DummyBackendConfig};
// Default config
let backend = DummyBackend::new();
// Custom config
let config = DummyBackendConfig {
max_buffer_size: 64 * 1024 * 1024, // 64 MB
simulate_device_local: true, // Device-local buffers not mappable
transfer_delay_us: 0, // Simulate transfer latency
};
let backend = DummyBackend::with_config(config);
Requires the vulkan feature flag. Uses ash and gpu-allocator.
[dependencies]
memkit-gpu = { version = "0.1.0-alpha.1", features = ["vulkan"] }
use memkit_gpu::{MkGpu, VulkanBackend, VulkanConfig};
let config = VulkanConfig {
app_name: "My App".to_string(),
validation: cfg!(debug_assertions),
..Default::default()
};
let backend = VulkanBackend::new(config)?;
let gpu = MkGpu::new(backend);
| Type | Description |
|---|---|
MkGpu<B> |
Main GPU allocator, generic over backend |
MkDeviceBuffer<B> |
Device-local buffer |
MkStagingBuffer<B> |
CPU-accessible staging buffer |
MkGpuTransfer |
Pending transfer operation |
MkGpuPool<B> |
Buffer pool for reuse |
MkMemoryType |
Memory type classification |
MkBufferUsage |
Buffer usage flags |
This project is licensed under the Mozilla Public License 2.0 - see the LICENSE.md file for details.