• Stars
    star
    515
  • Rank 85,879 (Top 2 %)
  • Language
    Rust
  • License
    Apache License 2.0
  • Created over 3 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Sample code for compute shader 101 training

Sample code for Compute Shader 101

This repo contains sample code to help you get started writing applications using compute shaders. It supplements a presentation including a video and slides.

Compute shaders are a promising approach to tap the power of GPU compute in a portable way, but it's not easy to get started. Most real-world usage of compute shaders today is in the context of games, where they do physics simulation, advanced image effects, and more. Games already have infrastructure to connect to the GPU, detect varying levels of capability at runtime, and abstract away details of graphics drivers and shader language translation.

To some extent compute shaders can be an alternative to CUDA, with a very different set of tradeoffs. The biggest advantage of compute shaders is portability, as they can run on most reasonably recent GPUs and are not tied to a specific hardware architecture. Probably the biggest shortcoming is lack of tool support.

compute-shader-hello

The first subdirectory is a simple command-line application that runs a simple compute shader over a buffer of data. It's very much intended as a starter, as there are many directions it can be made more sophisticated.

Recommended activity: find some algorithm in the literature for which there are efficient GPU implementations (prefix sum, convolution, physics simulation, etc) and adapt it to run as a compute shader. Experiment with different implementation choices and observe the effect on performance.

compute-shader-toy

The second subdirectory is a simple GUI application that runs a compute shader and draws its output in a window. It is intended to fulfill a similar function as Shadertoy by Inigo Quilez, but potentially opens up the full power of compute shaders instead of being limited to WebGL.

Recommended activity: find an existing shadertoy that implements some interesting algorithm or visual effect, and port it to run in a compute shader. Is there some limitation of the original that could be improved by compute capabilities?

A great place to find shaders to adapt is The Book of Shaders.

A note on the choice of runtime

Your compute shader code cannot run on its own, but rather needs a runtime to connect to the GPU, set up resources such as buffers and compiled shader code, and manage the submission of that work to the GPU. There is, as of this writing, no standard runtime for such things, but I hope that will change in time.

The most promising candidate for standard runtime is an implementation of WebGPU. While WebGPU is being developed as a web standard and will allow deployment via web, it is also useful for native applications. This repo uses wgpu-rs, which has a particularly nice Rust API and is also used by several other projects in the Rust GPU ecosystem. Another implementation of WebGPU is Dawn, which is actively developed but primarily being used as the basis for WebGPU in Chromium.

WebGPU has many advantages. It is relatively easy to learn and use, implementations are portable against a wide range of hardware, and there is momentum behind it. The main disadvantage is that it is still work in progress and many parts are not done. There is currently a focus on implementing core functionality, leaving somewhat more advanced compute features to later.

Another alternative is to build your own runtime. This unlocks access to advanced features provided by Vulkan, D3D12, and Metal, but also requires more work. Because I'm actively exploring these more advanced compute features in [piet-gpu], I am also building my own runtime to match. It is possible that this repo will add samples using that runtime as well, depending on feedback from the experience using wgpu.

A note on the choice of shader language

There is not yet a single obvious best choice for shader language. The most mature is GLSL, especially as it provides access to all functionality exposed to shader code by Vulkan, and Vulkan has many advanced features missing from other APIs.

The official shader language for WebGPU is WGSL. It is newer but does not yet have features such as subgroup operations or support for scalars of size other than 32 bits. It will be the required language for web deployments, but for native deployments, wgpu-rs also supports the SPIR-V intermediate representation, which can readily be derived from GLSL (or HLSL) source by compilers such as glslangValidator.

Both of these choices are viable for getting started. More advanced work will require the use of GLSL. There are many tools for converting between different shader languages. In the wgpu-rs ecosystem, the new naga tool shows great promise, but it is still (as with many such things) unfinished.

Both GLSL and WGSL are fairly primitive and low-level, not far removed from their roots in Cg. There are a number of experimental languages intended to deliver a much higher level programming experience, of which the most interesting to me right now is rust-gpu.

There are potentially many other paths to compute shader IR, including IREE which is mostly targeting machine learning applications.

Additional resources

There are some more resources in the docs/ subdirectory, including a glossary.

Contributing

This resource is open source and we welcome contributions to improve it. See [CONTRIBUTING.md] for more details.

License

Licensed under either of

More Repositories

1

roboto

The Roboto family of fonts
Python
3,796
star
2

noto-emoji

Noto Emoji fonts
Python
3,331
star
3

Inconsolata

Development repo of Inconsolata Fonts by Raph Levien
Rust
1,201
star
4

fontmake

Compile fonts from sources (UFO, Glyphs) to binary (OpenType, TrueType).
Python
763
star
5

morisawa-biz-ud-gothic

Python
615
star
6

morisawa-biz-ud-mincho

Python
471
star
7

fontra

A browser-based font editor
JavaScript
463
star
8

roboto-flex

HTML
434
star
9

sfntly

A Library for Using, Editing, and Creating SFNT-based Fonts
Java
432
star
10

amstelvar

a parametric variable font by David Berlow
330
star
11

fontview

Demo app that displays fonts with a free/libre/open-source text rendering stack: FreeType, HarfBuzz and Raqm
C++
321
star
12

spacemono

Original monospace display typeface family
318
star
13

decovar

A multistyle decorative variable font by David Berlow
Python
314
star
14

gftools

Misc tools for working with the Google Fonts library
Python
242
star
15

nanoemoji

A wee tool to build color fonts.
Python
239
star
16

opensans

Open Sans font
Shell
221
star
17

literata

A contemporary serif typeface family for long-form reading
Python
219
star
18

dm-fonts

DM Sans, DM Serif
Shell
190
star
19

rubik

Rubik fonts
Shell
182
star
20

glyphsLib

A bridge from Glyphs source files (.glyphs) to UFOs
Python
181
star
21

korean

Google Fonts Korean showcase
JavaScript
161
star
22

atkinson-hyperlegible

HTML
157
star
23

ufo2ft

A bridge from UFOs to FontTools objects (and therefore, OTFs and TTFs).
Python
151
star
24

roboto-classic

Development of a Roboto Variable font
Python
151
star
25

science-gothic

Science Gothic, a libre variable font
Python
145
star
26

picosvg

Helps simplify SVG files. Intended for use as part of a font build.
Python
137
star
27

fontdiff

tool for finding visual differences between two font versions
C++
135
star
28

fontations

Reading and writing font files
Rust
114
star
29

pyfontaine

Python tool to check font files for language/character set support
Python
100
star
30

gf-docs

Documentation for things related to github.com/google/fonts
99
star
31

color-fonts

Experimental color font builds.
Python
96
star
32

googlefonts-project-template

(DEMO) Repository architecture example for a typeface design project
Python
93
star
33

inter-gf-tight

Specialized version of Inter with tighter spacing, for use by Google Workspace
Python
79
star
34

glyphsets

Python
78
star
35

fontdiffenator

Font comparison tool
Python
76
star
36

dm-mono

DM Mono
Shell
73
star
37

lexend

A variable font family designed to aid in reading proficiency.
Shell
72
star
38

zen-marugothic

ZenFonts.jp Maru Gothic
Python
72
star
39

fontcrunch

Tool to optimize TrueType font splines
C++
70
star
40

RobotoMono

Shell
64
star
41

colr-gradients-spec

HTML
63
star
42

cu2qu

Cubic-to-quadratic bezier curve conversion
Python
62
star
43

fontreport

Tool to create PDF files containing glyph images and information about a font.
Python
62
star
44

googlefonts.github.io

Google Fonts documentation
CSS
57
star
45

robotoslab

Roboto Slab Typeface by Google
Python
57
star
46

roboto-serif

55
star
47

tajawal

Distinctive low contrast Arabic and sans serif Latin typeface family
54
star
48

emoji-metadata

Emoji metadata for the construction of pickers
48
star
49

dosis-vf

Fork of Dosis
Makefile
45
star
50

oxidize

Notes on moving tools and libraries to Rust.
45
star
51

zen-kurenaido

ZenFonts.jp Kurenaido
Python
45
star
52

comfortaa

Open-source font by Johan Aakerlund
HTML
44
star
53

diffenator2

A font comparison tool that will not stop until your fonts are exhaustively compared.
Python
43
star
54

ibarrareal

Ibarra Real Fonts
Shell
40
star
55

zen-kakugothic

ZenFonts.jp Kaku Gothic
Python
40
star
56

Gulzar

Nastaliq font
Python
39
star
57

gulim

Python
39
star
58

how-to-hint-variable-fonts

A how-to guide to TrueType hinting variable fonts, with VTT
38
star
59

NunitoSans

Shell
36
star
60

zen-oldmincho

ZenFonts.jp Old Mincho
Python
36
star
61

fontra-pak

A cross-platform bundled Fontra server for local desktop use
Python
34
star
62

TachyFont

Lazily loaded web fonts.
JavaScript
34
star
63

majormono

Python
32
star
64

josefinsans

Google Improvement Project
HTML
31
star
65

shaperglot

Test font files for language support
Python
30
star
66

EQX

A typographically centric font testing tool.
JavaScript
29
star
67

fontbakery-dashboard

A library-scale web dashboard for Font Bakery, no longer developed
JavaScript
28
star
68

axisregistry

A Python API to access data from the Google Fonts variable fonts Axis Registry.
Python
27
star
69

karla

Python
25
star
70

fontmake-rs

Where in we pursue oxidizing (context: https://github.com/googlefonts/oxidize) fontmake.
Rust
24
star
71

chws_tool

Add OpenType chws/vchw features to fonts.
HTML
23
star
72

lang

A python API for evaluating language support in the Google Fonts collection.
Python
23
star
73

caveat

Caveat handwriting fonts
Shell
23
star
74

compreffor

A CFF table subroutinizer for FontTools
Python
23
star
75

kosugi-maru

Kosugi Maru fonts, originally by Motoya
Python
23
star
76

collidoscope

Brute force detection of glyph collisions
Python
22
star
77

zen-antique

ZenFonts.jp Antique
Python
21
star
78

questrial

A fork of John Prince font Questrial from the old Google font directory
Python
21
star
79

chinese

CSS
20
star
80

gf-glyphs-scripts

Scripts for Glyphs
Python
20
star
81

staatliches

Herbert Bayer’s title lettering for the first Bauhaus exhibition catalogue cover of 1923
Python
18
star
82

batang

Python
18
star
83

changa-vf

Variable font fork of the Changa typeface (Latin, Arabic)
Makefile
17
star
84

Roboto-Delta

Roboto as a “parametric” Variable Font
Python
17
star
85

picosvg-rs

A Rust version of picosvg.
Rust
15
star
86

silkscreen

Classic web design pixel font from Jason Kottke, 2001
Python
15
star
87

gfregression

Test local fonts against fonts host on fonts.google.com
Python
14
star
88

fez

Font Engineering made eaZy
Python
14
star
89

mavenproFont

Maven Pro family by Joe Prince
Makefile
14
star
90

BethEllen

Font project repo for the Beth Ellen font by Rod Jelinski
14
star
91

fontquant

Prove and quantify a font’s technical quality
Python
11
star
92

how-to-hint-complex-script-variable-fonts

A guide to hinting complex script variable fonts with Visual TrueType
11
star
93

ufomerge

ufomerge
Python
11
star
94

dynapuff

Fun blobby display font
Python
10
star
95

kosugi

Kosugi fonts, originally by Motoya
Python
10
star
96

zen-dots

Shell
10
star
97

flowify

Turn a font into a flow font
Python
10
star
98

namecheck

Python
9
star
99

ots-python

Python wheels for the OpenType Sanitizer
Python
9
star
100

variable-components-spec

8
star