#graphics #glsl #gamedev


Provides data types and traits to build structures ready to upload into UBO

9 unstable releases

0.5.0 Dec 6, 2022
0.4.2 Aug 5, 2022
0.4.1 Jul 25, 2022
0.4.0 Jan 11, 2021
0.1.1 May 17, 2018

#356 in Graphics APIs

Download history 565/week @ 2022-12-01 1536/week @ 2022-12-08 465/week @ 2022-12-15 697/week @ 2022-12-22 927/week @ 2022-12-29 678/week @ 2023-01-05 773/week @ 2023-01-12 1142/week @ 2023-01-19 870/week @ 2023-01-26 1139/week @ 2023-02-02 510/week @ 2023-02-09 1291/week @ 2023-02-16 690/week @ 2023-02-23 680/week @ 2023-03-02 857/week @ 2023-03-09 575/week @ 2023-03-16

3,095 downloads per month
Used in 53 crates (13 directly)


770 lines


This crates provides data types and traits to build structures ready to upload into UBO.


Deriving Uniform with proc-macro will produce associated type Std140 with same data layout as uniform blocks declared with layout(std140). All members of structure that derives Uniform must implement Uniform as well.

Implementing Uniform should be done via deriving. Implementing it manually is possible. It requires to provide associated type Std140 which must implement Std140 trait. But trait Std140 is marked unsafe so be careful.

Trait Uniform also requires Copy.

Typical usage scenario is:

#[derive(Copy, Clone, Uniform)]
struct FragmentArgs {
    pos: vec3,
    dir: vec3,
    count: uint,

write_to_buffer(&FragmentArgs {
    pos: [0.0, 1.0, 2.0].into(),
    dir: [3.0, 4.0, 5.0].into(),
    count: 42,

Data types

There are basic data types from glsl:

  • boolean (name bool is already occupied)
  • int
  • uint
  • float
  • double

Also more complex types:

  • vectors - (vec2, vec3, vec4, bvec2, ivec2, uvec2, dvec2 etc)
  • matrices - (mat2x3, dmat4 etc)
  • arrays -


glsl-layout is free and open source software distributed under the terms of both the MIT License and the Apache License 2.0.


Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Known issues

On MacOS

If uniform block contains array of structures and this array accessed with dynamic index (variable instead of literal) it may load wrong bytes for members not aligned to size of vec4 (16 bytes). In this case manual padding can be the fix.


~52K SLoC