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
//! Optional GLSL/HLSL -> SPIR-V compilation via the [`shaderc`] crate
//! (Khronos reference glslang).
//!
//! This module is only compiled when the `shaderc` Cargo feature is
//! enabled:
//!
//! ```toml
//! [dependencies]
//! vulkane = { version = "0.4", features = ["shaderc"] }
//! ```
//!
//! # When to use this vs. `naga`
//!
//! The [`naga`](crate::safe::naga) feature is pure Rust and covers a
//! large subset of modern GLSL. `shaderc` wraps Khronos's reference
//! glslang compiler and is the gold standard for GLSL -> SPIR-V —
//! pick it when you need full GLSL support (including `#include`,
//! `GL_*` extensions, legacy shaders, or HLSL via
//! [`shaderc::SourceLanguage::HLSL`]).
//!
//! # Build requirements
//!
//! `shaderc-rs` tries these in order:
//!
//! 1. `SHADERC_LIB_DIR` env var
//! 2. `VULKAN_SDK` env var (set by installing the LunarG Vulkan SDK)
//! 3. `pkg-config` / system libraries
//! 4. Fallback: builds glslang from C++ source (requires CMake, Python,
//! and a working C++ toolchain)
//!
//! The easiest path is to install the Vulkan SDK; `shaderc-rs` will
//! find and link the prebuilt `libshaderc_combined` shipped with it.
use Error;
pub use ;
/// Errors that can occur during shaderc compilation.
/// Compile a GLSL (or HLSL) source string to a SPIR-V word vector.
///
/// * `source` — the shader source text.
/// * `kind` — the shader stage ([`ShaderKind::Vertex`],
/// [`ShaderKind::Fragment`], [`ShaderKind::Compute`], etc.).
/// * `file_name` — a virtual filename used in diagnostic messages
/// and as the base for `#include` resolution. Does not need to
/// exist on disk.
/// * `entry_point` — the entry-point function name (commonly `"main"`
/// for GLSL; varies for HLSL).
///
/// The returned `Vec<u32>` can be passed directly to
/// [`crate::safe::ShaderModule::from_spirv`].
///
/// # Example
///
/// ```ignore
/// use vulkane::safe::shaderc::{compile_glsl, ShaderKind};
///
/// let glsl = r#"
/// #version 450
/// layout(local_size_x = 64) in;
/// layout(set = 0, binding = 0, std430) buffer Data { uint values[]; };
/// void main() { values[gl_GlobalInvocationID.x] *= 2; }
/// "#;
///
/// let spirv = compile_glsl(glsl, ShaderKind::Compute, "doubler.comp", "main")?;
/// # Ok::<(), Box<dyn std::error::Error>>(())
/// ```
/// Compile a source string to SPIR-V with full control over compiler
/// options (optimization level, target environment, macro defines,
/// HLSL vs. GLSL, etc.).
///
/// Use [`compile_glsl`] for the common case; reach for this when you
/// need non-default options.
///
/// The `configure` closure runs before compilation and receives a
/// mutable [`shaderc::CompileOptions`] builder.
///
/// # Example — HLSL input, size-optimized
///
/// ```ignore
/// use vulkane::safe::shaderc::{compile_with_options, ShaderKind, SourceLanguage};
/// use shaderc::OptimizationLevel;
///
/// let spirv = compile_with_options(
/// hlsl_source,
/// ShaderKind::Fragment,
/// "shader.hlsl",
/// "main",
/// |opts| {
/// opts.set_source_language(SourceLanguage::HLSL);
/// opts.set_optimization_level(OptimizationLevel::Size);
/// },
/// )?;
/// # Ok::<(), Box<dyn std::error::Error>>(())
/// ```