• Stars
    star
    497
  • Rank 86,623 (Top 2 %)
  • Language
    Rust
  • License
    Apache License 2.0
  • Created about 3 years ago
  • Updated 5 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
738
star
5

morisawa-biz-ud-gothic

Python
605
star
6

morisawa-biz-ud-mincho

Python
461
star
7

roboto-flex

HTML
434
star
8

sfntly

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

fontra

A browser-based font editor
JavaScript
398
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++
319
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
241
star
15

nanoemoji

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

literata

A contemporary serif typeface family for long-form reading
Python
210
star
17

opensans

Open Sans font
Shell
209
star
18

dm-fonts

DM Sans, DM Serif
Shell
187
star
19

rubik

Rubik fonts
Shell
182
star
20

glyphsLib

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

korean

Google Fonts Korean showcase
JavaScript
160
star
22

atkinson-hyperlegible

HTML
157
star
23

ufo2ft

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

roboto-classic

Development of a Roboto Variable font
Python
146
star
25

picosvg

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

fontdiff

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

science-gothic

Science Gothic, a libre variable font
Python
134
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

googlefonts-project-template

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

color-fonts

Experimental color font builds.
Python
91
star
33

inter-gf-tight

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

fontdiffenator

Font comparison tool
Python
76
star
35

dm-mono

DM Mono
Shell
73
star
36

glyphsets

Python
73
star
37

lexend

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

fontcrunch

Tool to optimize TrueType font splines
C++
68
star
39

zen-marugothic

ZenFonts.jp Maru Gothic
Python
66
star
40

RobotoMono

Shell
64
star
41

cu2qu

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

fontreport

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

colr-gradients-spec

HTML
61
star
44

robotoslab

Roboto Slab Typeface by Google
Python
57
star
45

googlefonts.github.io

Google Fonts documentation
CSS
54
star
46

tajawal

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

roboto-serif

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

comfortaa

Open-source font by Johan Aakerlund
HTML
44
star
52

zen-kurenaido

ZenFonts.jp Kurenaido
Python
44
star
53

ibarrareal

Ibarra Real Fonts
Shell
39
star
54

diffenator2

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

Gulzar

Nastaliq font
Python
38
star
56

zen-kakugothic

ZenFonts.jp Kaku Gothic
Python
36
star
57

zen-oldmincho

ZenFonts.jp Old Mincho
Python
36
star
58

how-to-hint-variable-fonts

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

TachyFont

Lazily loaded web fonts.
JavaScript
34
star
60

NunitoSans

Shell
33
star
61

majormono

Python
32
star
62

josefinsans

Google Improvement Project
HTML
31
star
63

fontra-pak

A cross-platform bundled Fontra server for local desktop use
Python
30
star
64

EQX

A typographically centric font testing tool.
JavaScript
29
star
65

fontbakery-dashboard

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

shaperglot

Test font files for language support
Python
27
star
67

axisregistry

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

fontmake-rs

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

caveat

Caveat handwriting fonts
Shell
23
star
70

compreffor

A CFF table subroutinizer for FontTools
Python
23
star
71

lang

A python API for evaluating language support in the Google Fonts collection.
Python
22
star
72

collidoscope

Brute force detection of glyph collisions
Python
22
star
73

karla

Python
22
star
74

chws_tool

Add OpenType chws/vchw features to fonts.
HTML
21
star
75

chinese

CSS
20
star
76

gf-glyphs-scripts

Scripts for Glyphs
Python
20
star
77

zen-antique

ZenFonts.jp Antique
Python
20
star
78

questrial

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

kosugi-maru

Kosugi Maru fonts, originally by Motoya
Python
19
star
80

staatliches

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

changa-vf

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

Roboto-Delta

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

picosvg-rs

A Rust version of picosvg.
Rust
15
star
84

silkscreen

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

gfregression

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

fez

Font Engineering made eaZy
Python
14
star
87

mavenproFont

Maven Pro family by Joe Prince
Makefile
14
star
88

BethEllen

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

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

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

ufomerge

ufomerge
Python
11
star
91

dynapuff

Fun blobby display font
Python
10
star
92

fontquant

Prove and quantify a font’s technical quality
Python
10
star
93

kosugi

Kosugi fonts, originally by Motoya
Python
10
star
94

flowify

Turn a font into a flow font
Python
10
star
95

namecheck

Python
9
star
96

zen-dots

Shell
9
star
97

ots-python

Python wheels for the OpenType Sanitizer
Python
9
star
98

variable-components-spec

8
star
99

mekorot

Hebrew Rashi Typeface
Python
8
star
100

Signika

Making a variable version of Signika, from Google Fonts
Python
8
star