# shdrlib
- systems for shaders, shaders for systems.β
**A three-tiered Vulkan shader compilation and rendering framework built in pure Rust.**
[](https://www.rust-lang.org/)
[](LICENSE)
---
## π― What is shdrlib?
**shdrlib** is a backend Vulkan rendering library with a unique three-tier architecture that lets you choose your abstraction level:
```
βββββββββββββββββββββββββββββββββββββββββββββββββββ
β EZ TIER β One-liners with smart defaults β 13x code reduction
β (Easy) β Perfect for learning & prototyping β ~30 lines
ββββββββββββββΌββββββββββββββββββββββββββββββββββββββ€
β EX TIER β β Explicit control, ergonomic APIs β 4-8x code reduction
β (Explicit)β Production-ready, type-safe β ~100 lines
ββββββββββββββΌββββββββββββββββββββββββββββββββββββββ€
β CORE TIER β Thin Vulkan wrappers β Maximum control
β (Control) β For frameworks and engines β ~400 lines
βββββββββββββββββββββββββββββββββββββββββββββββββββ
```
**Key Features:**
- β
**Pure Rust** - No external build tools (uses naga for shader compilation)
- β
**Zero-cost abstractions** - All tiers compile to identical machine code
- β
**Memory safe** - Rust's ownership prevents use-after-free
- β
**Progressive disclosure** - Drop to lower tiers anytime for more control
- β
**All three tiers complete** - CORE, EX, and EZ are production-ready!
**This is NOT a game engine** - it's a backend library. You bring your own windowing (winit, sdl2, etc.).
---
## π Quick Start
### Installation
```toml
[dependencies]
shdrlib = "0.1.0"
ash = "0.38" # For Vulkan types
```
### Your First Triangle (EZ Tier)
Just **30 lines** to render with Vulkan:
```rust
use shdrlib::ez::*;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut renderer = EzRenderer::new()?;
let pipeline = renderer.quick_pipeline(VERTEX_GLSL, FRAGMENT_GLSL)?;
renderer.render_frame(|frame| {
frame.bind_pipeline(pipeline)?;
frame.set_viewport(0.0, 0.0, 800.0, 600.0);
frame.set_scissor(0, 0, 800, 600);
frame.draw(3, 1, 0, 0);
Ok(())
})?;
Ok(())
}
```
**That's it!** You just rendered a triangle with Vulkan.
π **[Read the full Quick Start Guide β](QUICKSTART.md)**
---
## π Choose Your Tier
### π― EZ Tier - Perfect for Learning
**Best for:** Prototyping, learning Vulkan, quick demos
```rust
// One-liner setup
let mut renderer = EzRenderer::new()?;
// One-liner pipelines
let graphics = renderer.quick_pipeline(VERTEX, FRAGMENT)?;
let compute = renderer.quick_compute(COMPUTE)?;
// One-liner buffers
let vertices = renderer.create_vertex_buffer(&data)?;
```
**Pros:**
- β
13x less code than CORE (30 lines vs 400)
- β
Perfect for learning Vulkan
- β
Intelligent defaults
- β
Hard to misuse
**Use when:** Learning, prototyping, teaching, demos
---
### β EX Tier - Recommended for Production
**Best for:** Real applications, games, production code
```rust
// Explicit but ergonomic
let mut runtime = RuntimeManager::new(RuntimeConfig::default())?;
let mut shaders = ShaderManager::new(runtime.device())?;
let shader_id = shaders.add_shader(source, stage, "name")?;
let pipeline_id = shaders.build_pipeline(
PipelineBuilder::new()
.vertex_shader(vert_module, "main")
.fragment_shader(frag_module, "main")
.color_attachment_formats(vec![Format::R8G8B8A8_UNORM]),
"my_pipeline"
)?;
```
**Pros:**
- β
4-8x less code than CORE (100 lines vs 400)
- β
Type-safe (ShaderId, PipelineId)
- β
Zero-cost abstractions
- β
Memory safe
- β
Production-ready
**Use when:** Building apps/games, need safety + control
---
### π§ CORE Tier - Maximum Control
**Best for:** Engine development, custom frameworks
```rust
// Direct Vulkan control
let instance = Instance::new(&entry, &instance_info)?;
let device = Device::new(&instance, physical_device, &device_info)?;
let shader = Shader::from_glsl(&device, source, ShaderStage::Vertex)?;
```
**Pros:**
- β
Maximum control
- β
Zero overhead
- β
Drop down anytime from higher tiers
- β
Direct Vulkan access
**Use when:** Building frameworks, need absolute control
---
## οΏ½ Documentation
### π Getting Started
- **[Quick Start](QUICKSTART.md)** - Your first triangle in 5 minutes
- **[Installation](docs/getting-started/installation.md)** - Set up your environment
- **[Choosing a Tier](docs/getting-started/choosing-a-tier.md)** - Which tier is right for you?
- **[FAQ](docs/getting-started/faq.md)** - Common questions answered
- **[Troubleshooting](docs/getting-started/troubleshooting.md)** - Fix common issues
### π Guides
- **[EZ Tier Guide](docs/guides/ez-tier-guide.md)** - High-level API guide
- **[EX Tier Guide](docs/guides/ex-tier-guide.md)** - Production tier guide β
- **[CORE Tier Guide](docs/guides/core-tier-guide.md)** - Low-level API guide
- **[Migration Guide](docs/guides/migration-guide.md)** - Moving between tiers
### ποΈ Architecture
- **[Overview](docs/architecture/overview.md)** - Design philosophy
- **[Three-Tier Design](docs/architecture/three-tier-design.md)** - Why three tiers?
- **[Zero-Cost Abstractions](docs/architecture/zero-cost-abstractions.md)** - Performance details
### π API Reference
- **[Complete Index](docs/INDEX.md)** - Full documentation map
- **Run `cargo doc --open`** for detailed API docs
---
## π¨ Examples
### Run Examples
```bash
# EZ tier (learning & prototyping)
cargo run --bin ez_01_hello_triangle
cargo run --bin ez_02_compute_multiply
# EX tier (production) β Recommended
cargo run --bin ex_01_triangle_100_lines
cargo run --bin ex_03_textured_quad
# CORE tier (advanced)
cargo run --bin 01_triangle_raw
```
### Example Comparison
| **Triangle** | 400 lines | 100 lines | 30 lines |
| **Textured Quad** | 400 lines | 50 lines | 35 lines |
| **Compute Shader** | 300 lines | 75 lines | 25 lines |
**Code reduction: 4x to 13x** while maintaining identical performance!
---
## π§ͺ Testing
```bash
# Run all tests
cargo test
# Run tier-specific tests
cargo test --lib core::
cargo test --lib ex::
# Run with output
cargo test -- --nocapture
```
**Status:** 73 tests passing β
(48 CORE + 25 EX)
---
## ποΈ Project Status
| **CORE Tier** | β
Complete | ~3,440 | 48 β
|
| **EX Tier** | β
Complete | ~3,000 | 25 β
|
| **EZ Tier** | β
Complete | ~600 | 3 demos β
|
| **Documentation** | π§ In Progress | - | - |
**All three tiers are production-ready!** π
---
## πΊοΈ Roadmap
### Current Release (v0.1) - Q4 2025
- β
CORE tier complete (12 modules)
- β
EX tier complete (6 components)
- β
EZ tier complete
- β
9 working demos
- π§ Documentation overhaul
### Next Release (v0.2) - Q1 2026
- π Performance benchmarks
- π Texture loading from files
- π Enhanced EZ tier features
- π More advanced examples
### Future (v0.3+)
- π Ray tracing support
- π Render graph system
- π Multi-threaded recording
- π Advanced profiling
---
## π€ Contributing
We welcome contributions! Please read:
1. **[CONTRIBUTING.md](CONTRIBUTING.md)** - Contribution guidelines
2. **[Code of Conduct](CONTRIBUTING.md#code-of-conduct)** - Be respectful
3. **[Development Workflow](CONTRIBUTING.md#development-workflow)** - How to contribute
**Areas we need help:**
- π Documentation improvements
- π§ͺ More test coverage
- π¨ Additional examples
- π Bug fixes
---
## οΏ½ Dependencies
- **ash** 0.38 - Vulkan bindings
- **naga** 22 - Pure Rust GLSLβSPIR-V compiler
- **spirv-reflect** 0.2 - SPIR-V reflection
- **thiserror** 1.0 - Error handling
**No external build tools required!** Pure Rust shader compilation.
---
## π§ Requirements
- **Rust:** Edition 2024 (Rust 1.82+)
- **Vulkan:** 1.3+ with dynamic rendering support
- **OS:** Windows, Linux, or macOS
---
## π License
Dual-licensed under MIT or Apache-2.0 (your choice).
See [LICENSE-MIT](LICENSE-MIT) and [LICENSE-APACHE](LICENSE-APACHE).
---
## π Acknowledgments
- **ash** - Excellent Vulkan bindings for Rust
- **naga** - Pure Rust shader compilation
- **Vulkan** - Powerful graphics API
---
## οΏ½ Quick Links
| π **Quick Start** | [QUICKSTART.md](QUICKSTART.md) |
| π **Documentation** | [docs/README.md](docs/README.md) |
| π¨ **Examples** | [demos/](demos/) |
| π€ **Contributing** | [CONTRIBUTING.md](CONTRIBUTING.md) |
| π **Roadmap** | [CHANGELOG.md](CHANGELOG.md) |
| οΏ½ **Issues** | [GitHub Issues](https://github.com/paulburnettjones-wq/shdrlib/issues) |
| π¬ **Discussions** | [GitHub Discussions](https://github.com/paulburnettjones-wq/shdrlib/discussions) |
---
**Ready to render?**
```bash
cargo add shdrlib ash
```
Then follow the **[Quick Start Guide](QUICKSTART.md)** to render your first triangle!
---