#spir-v #vulkan #proc-macro

macro vk-shader-macros

Procedural macros for working with Vulkan shaders

10 releases

0.2.9 Sep 20, 2023
0.2.8 Mar 28, 2022
0.2.7 May 5, 2021
0.2.6 Jun 8, 2020
0.1.0 Feb 26, 2019

#188 in Rendering

Download history 17/week @ 2023-12-04 28/week @ 2023-12-11 65/week @ 2023-12-18 23/week @ 2023-12-25 2/week @ 2024-01-01 112/week @ 2024-01-08 62/week @ 2024-01-15 65/week @ 2024-01-22 22/week @ 2024-01-29 33/week @ 2024-02-05 46/week @ 2024-02-12 156/week @ 2024-02-19 97/week @ 2024-02-26 81/week @ 2024-03-04 78/week @ 2024-03-11 56/week @ 2024-03-18

368 downloads per month
Used in 4 crates

MIT/Apache

17KB
292 lines

vk-shader-macros

Documentation Crates.io License: MIT License: Apache 2.0

A procedural macro for compiling GLSL into SPIR-V constants.

Unlike the standard include_bytes macro, paths are currently resolved relative to crate root. This is due to a temporary limitation in the procedural macro API.

Examples

const VERT: &[u32] = include_glsl!("shaders/example.vert");
const FRAG: &[u32] = include_glsl!("shaders/example.glsl", kind: frag);
const RGEN: &[u32] = include_glsl!("shaders/example.rgen", target: vulkan1_2); // vulkan1_2 is required to build with GL_EXT_ray_tracing

Debug info is generated by default; pass strip to the macro to omit it, or build the crate with the strip feature enabled.

Why [u32]?

SPIR-V is a stream of 32-bit words, not bytes, and this is reflected in APIs that consume it. In particular, passing a [u8] of SPIR-V that is not 4-byte-aligned to Vulkan is undefined behavior. Storing SPIR-V in its native format guarantees that this will never occur, without requiring copying or unsafe code.

Dependencies

This crate currently depends on the foreign shaderc library. By default, it will attempt to use an installed shaderc library. However if it does not exist, it will fall back to building from source, requiring git, cmake, python 3, and a supported C++ compiler to be available in the build environment. When using a pre-compiled shaderc, care must be taken to use a version that is binary-compatible with the one checked out by the shaderc crate. You can force shaderc to be built from source by enabling the build-from-source feature on vk-shader-macros.

Dependencies

~28MB
~628K SLoC