1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
//! # shdrlib - Three-Tier Vulkan Shader Compilation and Rendering Framework
//!
//! **A pure Rust Vulkan rendering library with a unique three-tier architecture** that lets you choose
//! your abstraction level: from bare-metal Vulkan control to high-level one-liners.
//!
//! [](https://crates.io/crates/shdrlib)
//! [](https://docs.rs/shdrlib)
//! [](https://github.com/paulburnettjones-wq/shdrlib)
//!
//! ---
//!
//! ## 🎯 What Makes shdrlib Different?
//!
//! Unlike traditional graphics libraries that force you into one abstraction level, **shdrlib gives you three
//! tiers that work together seamlessly**:
//!
//! | Tier | Abstraction Level | Code Reduction | Use Case |
//! |------|------------------|----------------|----------|
//! | **CORE** | Thin Vulkan wrappers | Baseline (400 LOC) | Engines, frameworks |
//! | **EX** ⭐ | Explicit managers | **4-8x** (100 LOC) | Applications, games |
//! | **EZ** | High-level one-liners | **13x** (30 LOC) | Learning, prototyping |
//!
//! **All three tiers compile to identical machine code** - zero runtime cost!
//!
//! ---
//!
//! ## 🚀 Quick Start
//!
//! ### Installation
//!
//! ```toml
//! [dependencies]
//! shdrlib = "0.1.2"
//! ash = "0.38" # For Vulkan types
//! ```
//!
//! ### Your First Triangle (30 Lines!)
//!
//! ```rust,no_run
//! use shdrlib::ez::*;
//!
//! fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // One-liner setup
//! let mut renderer = EzRenderer::new()?;
//!
//! // One-liner pipeline
//! let pipeline = renderer.quick_pipeline(VERTEX_GLSL, FRAGMENT_GLSL)?;
//!
//! // Render!
//! renderer.render_frame(|frame| {
//! frame.bind_pipeline(pipeline);
//! frame.draw(3, 1, 0, 0);
//! Ok(())
//! })?;
//!
//! Ok(())
//! }
//! # const VERTEX_GLSL: &str = "#version 450\nvoid main() {}";
//! # const FRAGMENT_GLSL: &str = "#version 450\nvoid main() {}";
//! ```
//!
//! **That's it!** You just rendered with Vulkan.
//!
//! ---
//!
//! ## 📚 The Three Tiers
//!
//! ### 🎯 EZ Tier - Perfect for Learning
//!
//! **Best for:** Prototyping, learning Vulkan, quick demos
//!
//! ```rust,no_run
//! use shdrlib::ez::*;
//!
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let mut renderer = EzRenderer::new()?;
//! let pipeline = renderer.quick_pipeline(VERT, FRAG)?;
//! # let vertex_data: Vec<f32> = vec![0.0; 9];
//! let vertices = renderer.create_vertex_buffer(&vertex_data)?;
//!
//! renderer.render_frame(|frame| {
//! frame.bind_pipeline(pipeline);
//! frame.draw(3, 1, 0, 0);
//! Ok(())
//! })?;
//! # const VERT: &str = "#version 450\nvoid main() {}";
//! # const FRAG: &str = "#version 450\nvoid main() {}";
//! # Ok(())
//! # }
//! ```
//!
//! - ✅ **13x less code** than CORE tier
//! - ✅ Intelligent defaults
//! - ✅ Perfect for learning
//! - ✅ Hard to misuse
//!
//! ---
//!
//! ### ⭐ EX Tier - Recommended for Production
//!
//! **Best for:** Real applications, games, production code
//!
//! ```rust,no_run
//! use shdrlib::ex::*;
//! use shdrlib::core::ShaderStage;
//!
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // Explicit but ergonomic
//! let mut runtime = RuntimeManager::new(RuntimeConfig::default())?;
//! let device = runtime.device();
//! let mut shaders = ShaderManager::new(device)?;
//!
//! // Type-safe shader management
//! let vert_id = shaders.add_shader(VERT_SRC, ShaderStage::Vertex, "vert")?;
//! let frag_id = shaders.add_shader(FRAG_SRC, ShaderStage::Fragment, "frag")?;
//!
//! // Build pipeline with fluent API
//! let pipeline_id = shaders.build_pipeline(
//! PipelineBuilder::new()
//! .vertex_shader(shaders.get_shader(vert_id)?.handle(), "main")
//! .fragment_shader(shaders.get_shader(frag_id)?.handle(), "main")
//! .color_attachment_formats(vec![ash::vk::Format::R8G8B8A8_UNORM]),
//! "my_pipeline"
//! )?;
//!
//! // Cleanup is automatic!
//! # const VERT_SRC: &str = "#version 450\nvoid main() {}";
//! # const FRAG_SRC: &str = "#version 450\nvoid main() {}";
//! # Ok(())
//! # }
//! ```
//!
//! - ✅ **4-8x less code** than CORE tier
//! - ✅ Type-safe resource IDs
//! - ✅ Automatic lifetime management
//! - ✅ Zero-cost abstractions
//! - ✅ Production-ready
//!
//! ---
//!
//! ### 🔧 CORE Tier - Maximum Control
//!
//! **Best for:** Engine development, custom frameworks
//!
//! ```rust,no_run
//! use shdrlib::core::*;
//!
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // Direct Vulkan control
//! let instance = Instance::new(InstanceCreateInfo::default())?;
//! let physical_devices = instance.enumerate_physical_devices()?;
//! let device = Device::new(&instance, physical_devices[0], DeviceCreateInfo::default())?;
//! let shader = Shader::from_glsl(&device, GLSL_SOURCE, ShaderStage::Vertex, "main")?;
//!
//! // You manage all lifetimes and resources
//! # const GLSL_SOURCE: &str = "#version 450\nvoid main() {}";
//! # Ok(())
//! # }
//! ```
//!
//! - ✅ Maximum control
//! - ✅ Zero overhead
//! - ✅ Direct Vulkan access
//! - ✅ Perfect for frameworks
//!
//! ---
//!
//! ## ✨ Key Features
//!
//! ### Pure Rust Shader Compilation
//!
//! No external build tools required! shdrlib uses [naga](https://docs.rs/naga) for pure Rust
//! GLSL → SPIR-V compilation:
//!
//! ```rust,no_run
//! use shdrlib::core::{Shader, ShaderStage, Device};
//!
//! # fn example(device: &Device) -> Result<(), Box<dyn std::error::Error>> {
//! let glsl_source = r#"
//! #version 450
//! layout(location = 0) in vec3 position;
//! void main() {
//! gl_Position = vec4(position, 1.0);
//! }
//! "#;
//!
//! let shader = Shader::from_glsl(device, glsl_source, ShaderStage::Vertex, "main")?;
//! // Shader is now compiled to SPIR-V and ready to use!
//! # Ok(())
//! # }
//! ```
//!
//! ### Zero-Cost Abstractions
//!
//! All three tiers compile to **identical machine code**. The high-level abstractions completely
//! inline away - no runtime cost!
//!
//! ### Memory Safety
//!
//! Rust's ownership system prevents:
//! - ✅ Use-after-free bugs
//! - ✅ Double-free errors
//! - ✅ Null pointer dereferences
//! - ✅ Data races
//!
//! ### Progressive Disclosure
//!
//! Start high-level, drop down when you need control:
//!
//! ```rust,no_run
//! use shdrlib::ez::EzRenderer;
//!
//! # fn example() -> Result<(), Box<dyn std::error::Error>> {
//! let mut renderer = EzRenderer::new()?;
//!
//! // Access the EX tier when you need it
//! let runtime = renderer.runtime();
//! let device = runtime.device();
//!
//! // Or even drop to CORE tier
//! let vk_device = device.handle();
//! # Ok(())
//! # }
//! ```
//!
//! ---
//!
//! ## 📖 Documentation Structure
//!
//! - [`core`] - Low-level Vulkan wrappers (Tier 0)
//! - [`core::Instance`] - Vulkan instance management
//! - [`core::Device`] - Logical device operations
//! - [`core::Shader`] - GLSL → SPIR-V compilation
//! - [`core::Pipeline`] - Graphics/compute pipelines
//! - And 8 more modules...
//!
//! - [`ex`] - Explicit managers (Tier 1) ⭐ **Recommended**
//! - [`ex::RuntimeManager`] - Manages Vulkan instance, device, queues
//! - [`ex::ShaderManager`] - Type-safe shader and pipeline management
//! - [`ex::PipelineBuilder`] - Fluent pipeline configuration
//! - [`ex::helpers`] - Buffer, image, and descriptor helpers
//!
//! - [`ez`] - High-level API (Tier 2)
//! - [`ez::EzRenderer`] - All-in-one rendering interface
//!
//! ---
//!
//! ## 🎨 Examples
//!
//! ### Compute Shader (EZ Tier)
//!
//! ```rust,no_run
//! use shdrlib::ez::*;
//!
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let mut renderer = EzRenderer::new()?;
//!
//! // Create compute pipeline
//! let compute = renderer.quick_compute(COMPUTE_SHADER)?;
//!
//! // Create buffers (size in bytes)
//! let input = renderer.create_storage_buffer(1024)?;
//! let output = renderer.create_storage_buffer(1024)?;
//!
//! // Dispatch compute work (implementation depends on your shader bindings)
//! # const COMPUTE_SHADER: &str = "#version 450\nvoid main() {}";
//! # Ok(())
//! # }
//! ```
//!
//! ### Custom Pipeline (EX Tier)
//!
//! ```rust,no_run
//! use shdrlib::ex::*;
//! use shdrlib::core::ShaderStage;
//! use ash::vk;
//!
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let mut runtime = RuntimeManager::new(RuntimeConfig::default())?;
//! let mut shaders = ShaderManager::new(runtime.device())?;
//!
//! // Add shaders
//! let vert = shaders.add_shader(VERT, ShaderStage::Vertex, "vert")?;
//! let frag = shaders.add_shader(FRAG, ShaderStage::Fragment, "frag")?;
//!
//! // Build custom pipeline
//! let pipeline = shaders.build_pipeline(
//! PipelineBuilder::new()
//! .vertex_shader(shaders.get_shader(vert)?.handle(), "main")
//! .fragment_shader(shaders.get_shader(frag)?.handle(), "main")
//! .color_attachment_formats(vec![vk::Format::B8G8R8A8_UNORM])
//! .depth_format(vk::Format::D32_SFLOAT)
//! .cull_mode(vk::CullModeFlags::BACK)
//! .front_face(vk::FrontFace::COUNTER_CLOCKWISE),
//! "my_pipeline"
//! )?;
//! # const VERT: &str = "#version 450\nvoid main() {}";
//! # const FRAG: &str = "#version 450\nvoid main() {}";
//! # Ok(())
//! # }
//! ```
//!
//! ---
//!
//! ## 🔧 Requirements
//!
//! - **Rust:** Edition 2021 (Rust 1.70+)
//! - **Vulkan:** 1.3+ with dynamic rendering support
//! - **OS:** Windows, Linux, or macOS
//!
//! ---
//!
//! ## 📦 Dependencies
//!
//! - [`ash`](https://docs.rs/ash) - Vulkan bindings
//! - [`naga`](https://docs.rs/naga) - Pure Rust shader compilation
//! - [`spirv-reflect`](https://docs.rs/spirv-reflect) - SPIR-V reflection
//! - [`thiserror`](https://docs.rs/thiserror) - Error handling
//!
//! ---
//!
//! ## 📄 License
//!
//! Dual-licensed under MIT or Apache-2.0 (your choice).
//!
//! ---
//!
//! ## 🔗 Links
//!
//! - [GitHub Repository](https://github.com/paulburnettjones-wq/shdrlib)
//! - [Crates.io](https://crates.io/crates/shdrlib)
//! - [Documentation](https://docs.rs/shdrlib)
//!
//! ---
//!
//! **Ready to get started?** Check out the [`ez`], [`ex`], or [`core`] modules depending on your needs!
// Re-export core for convenience
pub use crate*;