jit_spirv/lib.rs
1//! # jit-spirv
2//!
3//! The first parameter is a slice of string that contains the textual shader
4//! source. Other following parameters give you finer control over the generated
5//! code to compile your shaders.
6//!
7//! ## Source Language
8//!
9//! `jit-spirv` currently support three source languages:
10//!
11//! - `glsl`: The shader source is in GLSL (enabled by default);
12//! - `hlsl`: The shader source is in HLSL (enabled by default);
13//! - `wgsl`: The shader source is in WGSL.
14//!
15//! The experimental WGSL support for WebGPU is available when `wgsl` feature is
16//! enabled, but currently you have to compile with a nightly toolchain. Limited
17//! by the `naga` backend, most of the extra parameters won't be effective and
18//! only the first entry point is generated in SPIR-V.
19//!
20//! ## Shader Stages
21//!
22//! The following shader stages are supported:
23//!
24//! - `vert`: Vertex shader;
25//! - `tesc`: Tessellation control shader (Hull shader);
26//! - `tese`: Tessellation evaluation shader (Domain shader);
27//! - `geom`: Geometry shader;
28//! - `frag`: Fragment shader (Pixel shader);
29//! - `comp`: Compute shader;
30//! - `mesh`: (Mesh shading) Mesh shader;
31//! - `task`: (Mesh shading) Task shader;
32//! - `rgen`: (Raytracing) ray-generation shader;
33//! - `rint`: (Raytracing) intersection shader;
34//! - `rahit`: (Raytracing) any-hit shader;
35//! - `rchit`: (Raytracing) closest-hit shader;
36//! - `rmiss`: (Raytracing) miss shader;
37//! - `rcall`: (Raytracing) callable shader;
38//!
39//! ## Specify Entry Function
40//!
41//! By default the compiler seeks for an entry point function named `main`. You
42//! can also explicitly specify the entry function name:
43//!
44//! ```ignore
45//! jit_spirv!(hlsl_source, hlsl, vert, entry="very_main");
46//! ```
47//!
48//! ## Optimization Preference
49//!
50//! To decide how much you want the SPIR-V to be optimized:
51//!
52//! - `min_size`: Optimize for the minimal output size;
53//! - `max_perf`: Optimize for the best performance;
54//! - `no_debug`: Strip off all the debug information (don't do this if you want
55//! to reflect the SPIR-V and get variable names).
56//!
57//! ## Compiler Definition
58//!
59//! You can also define macro substitutions:
60//!
61//! ```ignore
62//! jit_spirv!(glsl_source, vert,
63//! D USE_LIGHTMAP,
64//! D LIGHTMAP_COUNT="2");
65//! ```
66//!
67//! You can request a specific version of target environment:
68//! - `vulkan1_0` for Vulkan 1.0 (default, supports SPIR-V 1.0);
69//! - `vulkan1_1` for Vulkan 1.1 (supports SPIR-V 1.3);
70//! - `vulkan1_2` for Vulkan 1.2 (supports SPIR-V 1.5).
71//! - `opengl4_5` for OpenGL 4.5 core profile.
72//! - `webgpu` for WebGPU.
73//!
74//! Of course once you started to use macro is basically means that you are
75//! getting so dynamic that this little crate might not be enough. Then it might
76//! be a good time to build your own shader compilation pipeline!
77//!
78//! ## Descriptor Auto-binding
79//!
80//! If you are just off your work being tooooo tired to specify the descriptor
81//! binding points yourself, you can switch on `auto_bind`:
82//!
83//! ```ignore
84//! jit_spirv!(r#"
85//! #version 450 core
86//! uniform sampler2D limap;
87//! uniform sampler2D emit_map;
88//! void main() {}
89//! "#, glsl, frag, auto_bind);
90//! ```
91//!
92//! However, if you don't have any automated reflection tool to get the actual
93//! binding points, it's not recommended to use this.
94//!
95//! ## Flip-Y for WebGPU
96//!
97//! If you intend to compile WGSL for a WebGPU backend, `naga` by default
98//! inverts the Y-axis due to the discrepancy in NDC (Normalized Device
99//! Coordinates) between WebGPU and Vulkan. If such correction is undesired, you
100//! can opt out with `no_y_flip`.
101pub mod dep;
102pub use jit_spirv_impl::jit_spirv;
103
104pub struct CompilationFeedback {
105 pub spv: Vec<u32>,
106 pub dep_paths: Vec<String>,
107}