shdrlib 0.1.0

A three-tiered Vulkan shader compilation and rendering framework built in pure Rust
Documentation
# shdrlib

- systems for shaders, shaders for systems.”

**A three-tiered Vulkan shader compilation and rendering framework built in pure Rust.**

[![Rust](https://img.shields.io/badge/rust-2024-orange.svg)](https://www.rust-lang.org/)
[![License](https://img.shields.io/badge/license-MIT%2FApache--2.0-blue.svg)](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

πŸ“– **[EZ Tier Guide β†’]docs/guides/ez-tier-guide.md** | 🎨 **[Examples β†’]demos/ez/**

---

### ⭐ 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

πŸ“– **[EX Tier Guide β†’]docs/guides/ex-tier-guide.md** | 🎨 **[Examples β†’]demos/ex/**

---

### πŸ”§ 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

πŸ“– **[CORE Tier Guide β†’]docs/guides/core-tier-guide.md** | 🎨 **[Examples β†’]demos/core/**


---

## οΏ½ 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


| Example | CORE Tier | EX Tier | EZ Tier |
|---------|-----------|---------|---------|
| **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


| Component | Status | LOC | Tests |
|-----------|--------|-----|-------|
| **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


| Resource | Link |
|----------|------|
| πŸ“– **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!

---

**Last Updated:** October 30, 2025 | **Version:** 0.1.0