# memkit-gpu
<div align="center">
**High-Performance GPU Memory Management for the Memkit Ecosystem.**
[](https://crates.io/crates/memkit-gpu)
[](https://docs.rs/memkit-gpu)
[](https://opensource.org/licenses/MPL-2.0)
</div>
---
## ๐ Overview
`memkit-gpu` provides a **backend-agnostic** GPU memory management layer that bridges the gap between high-level intent and low-level hardware constraints. It allows you to write graphics-heavy applications once and target Vulkan, Metal, or DX12 with minimal changes.
## ๐ The GPU Advantage
| **Latency** | Non-deterministic | Deterministic & Predictable |
| **Backend** | Native-only | Multi-backend Abstraction |
| **Safety** | Manual pointer math | Type-safe Staging/Device buffers |
| **Efficiency** | Ad-hoc transfers | Coalesced & Batched transfers |
## โจ Features
- ๐๏ธ **Backend-Agnostic** โ Write once, run on Vulkan, Metal (WIP), or DX12 (WIP).
- ๐ฆ **Staging/Device Split** โ Explicit management of CPU-visible and GPU-local memory.
- โก **Batch Transfers** โ Optimized transfer queues to minimize command buffer overhead.
- ๐๏ธ **Smart Pooling** โ Reusable buffer pools to eliminate allocation judder.
- ๐งช **Dummy Backend** โ Full CPU-based GPU simulation for testing without hardware.
## ๐ ๏ธ Quick Start
```rust
use memkit_gpu::{MkGpu, MkBufferUsage, DummyBackend};
// Initialize with the Dummy backend for testing
let gpu = MkGpu::new(DummyBackend::new());
// Create a staging buffer (CPU-visible)
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 a device-local buffer (GPU-fast)
let device = gpu.create_device_buffer(
std::mem::size_of_val(vertices),
MkBufferUsage::VERTEX | MkBufferUsage::TRANSFER_DST,
).unwrap();
// Efficiently transfer data from Staging to Device
gpu.transfer(&staging, &device).unwrap();
```
## ๐ Supported Backends
`memkit-gpu` is designed as a trait-based system. Enable your preferred backend via features:
| **Vulkan** | `vulkan` | โ
Production Ready |
| **Dummy** | (default) | โ
Test/Debug Ready |
| **Metal** | `metal` | ๐ง Coming Soon |
| **DirectX 12** | `dx12` | ๐ง Coming Soon |
### Vulkan Setup
```toml
[dependencies]
memkit-gpu = { version = "0.1.1-beta.1", features = ["vulkan"] }
```
## ๐๏ธ Architecture
```mermaid
graph TD
A[User Code] --> B[MkGpu]
B --> C{MkGpuBackend}
C -->|vulkan| D[VulkanBackend]
C -->|dummy| E[DummyBackend]
D --> F[Hardware GPU]
E --> G[CPU Simulation]
```
## โ๏ธ License
Licensed under the **Mozilla Public License 2.0**. See [LICENSE.md](../LICENSE.md) for details.