#vulkan #spirv

vk-shader-macros

Procedural macros for working with Vulkan shaders

7 releases

0.2.6 Jun 8, 2020
0.2.5 Jun 5, 2020
0.2.4 May 24, 2020
0.2.2 Aug 18, 2019
0.1.0 Feb 26, 2019

#17 in Rendering

Download history 85/week @ 2020-08-11 60/week @ 2020-08-18 83/week @ 2020-08-25 113/week @ 2020-09-01 149/week @ 2020-09-08 106/week @ 2020-09-15 67/week @ 2020-09-22 159/week @ 2020-09-29 122/week @ 2020-10-06 99/week @ 2020-10-13 47/week @ 2020-10-20 64/week @ 2020-10-27 57/week @ 2020-11-03 52/week @ 2020-11-10 32/week @ 2020-11-17 44/week @ 2020-11-24

363 downloads per month
Used in 2 crates

MIT/Apache

5KB

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);

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

~23MB
~528K SLoC