
A Guide to Rust Graphics Libraries as of 2019 - pplonski86
https://wiki.alopex.li/AGuideToRustGraphicsLibraries2019
======
sandov
>OpenGL: Basically Javascript for GPU’s.

Everyday we stray further from god's light.

~~~
jjtheblunt
Yeah, that comment you cited is unbelievably misinformed.

~~~
rossy
I had a visceral reaction to that sentence too, but read the rest of the
paragraph. It's not wrong in the way the author meant it. The author is saying
that OpenGL is like JavaScript because it's high level, it's open and
supported everywhere, it was designed in the 90s in a very different ecosystem
to what we have today, and even though it's been updated and the old versions
are no longer worth using (ECMAScript 3 and OpenGL 2.1,) the new versions
still have a bunch of weird historical baggage. I don't see anything wrong
with that.

------
mikekchar
BTW, I just wanted to give a shout out to ggez (the author's game library).
I've been playing with it and it's quite a lot of fun to use. I'm a novice in
Rust and I found it to be quite a nice introduction to the language. There are
a couple of bugs here and there, but pretty much it does what's printed on the
box. Very nice documentation and lots of examples to work with too. And the
cherry on the cake is raising an issue is a welcoming rather than harrowing
experience. You get the feeling that whatever issues might crop up, you can
work your way through them.

Edit: grammar

~~~
shepmaster
If you are interested in hearing more from the author of ggez, check out their
talk from Rust Belt Rust 2018:

\- Evolving API design in Rust — Simon Nicholas Heath
([https://www.youtube.com/watch?v=Xt1JOVeQ5hw](https://www.youtube.com/watch?v=Xt1JOVeQ5hw))

------
icefoxen
Hi, author here, happy to answer any questions people have.

------
chubs
Great write-up! I'd really like to know how gfx-hal handles shaders. Do you
write shaders in some high-level language, and gfx translates them
appropriately for the vulkan/metal/dx backends, and send them off to the GPU
driver? If so, is this transpiling slow? Do you get slightly different visuals
on different backends? Or even glitches on some? Thanks for the write-up :)

~~~
robmaister
I'm not familiar with the specifics within gfx-hal, but it's most likely
taking in SPIR-V and translating as needed.

AFAIK DX12 still requires DXIL so it might be saving both SPIR-V and DXIL, or
taking in HLSL and compiling/translating as needed.

Microsoft has generally gotten a lot friendlier in the last decade, they have
tools to compile HLSL down to SPIR-V, if you want to support everything
including DX12 you'll probably be writing HLSL. Otherwise you can pick any
language that compiles down to SPIR-V.

[https://github.com/Microsoft/ShaderConductor](https://github.com/Microsoft/ShaderConductor)

[https://github.com/KhronosGroup/SPIRV-
Cross](https://github.com/KhronosGroup/SPIRV-Cross)

~~~
chubs
So from what I can find, it seems gfx-hal works with GLSL, compiles it to
SPIRV, and then uses that (somehow). I'm just not sure how it uses the SPIRV
for each backend.

~~~
robmaister
The first link I included has a wonderful diagram of this (but from the
perspective of HLSL instead of GLSL), the gist of it is:

GLSL gets compiled to SPIR-V ahead of time by a compiler of your choice
(probably glslangValidator). You can take that binary blob and feed it into
Vulkan (vkCreateShaderModule) or OpenGL (glShaderBinary as long as you have
the right extension).

For everything else, Khronos has a tool called SPIRV-Cross (second link),
which reads the SPIR-V binary data and emits a text file/string in ESSL for
OpenGL ES, MSL for Metal, or HLSL for DirectX <=11. Those all go through the
"normal" paths for loading shader code in their own APIs.

~~~
chubs
Thanks so much for explaining how that works :)

Is it just me or does decompiling the binary SPIR-V to ESL/HLSL source code
then recompiling sound like a recipe for massive inefficiency? Or in practice
does it work out pretty nicely?

~~~
robmaister
Yes, it's absolutely inefficient but for those platforms it's the only way to
execute your own code on the GPU. Metal has a bitcode format that I know
nothing about and I believe older DirectX had some intermediate format that
was binary. Both are proprietary and only documented via reverse-engineering,
so they're not great targets.

Most of the extra cost of feeding in SPIR-V could also be offset if you
generate the text shader code at compile/packaging time so that those builds
don't have the original SPIR-V in them.

~~~
kvark
It's not absolutely impossible. DXBC was well reverse engineered, and DXIL
could also be a direct target for translation. It's up to future work, which
for us also includes writing an in house shader converter as a substitute to
SPIRV-Cross.

This isn't a big concern at the moment though, since most of the shader
loading/compiling time is spent by the driver receiving the result, not us
translating it.

Generating a text shader at packaging time is certainly an option to explore,
especially for self-contained users like WebRender. The trouble here is that
we adjust the shader code based on the pipeline and pipeline layout, so we can
only really start translation at the run/init time, unless we start pre-
packaging a set of "popular" configurations (which is feasible for WebRender).

------
_bxg1
Very good deep-dive, but I'm surprised there was little mention of the higher-
level libraries that do exist already. I've found kiss3d and three-rs, both of
which seem pretty early but appear to let you "load a model you made in
Blender and show it on screen".

~~~
rezeroed
Kiss3d is great. It has some rendering issues on mac, but a great level of
abstraction.

~~~
_bxg1
Is it featured/mature enough for a full game?

~~~
termhn
Depends on the kind of game, but probably not. That's not really the purpose
it's meant for, so it will probably never get to that state.

------
Shikadi
>OpenGL: Basically the Javascript of graphics API’s.

Not trying to be rude, but I'd just like to point out the apostrophe on API's
indicates ownership, as in "John's dog jumped". APIs is fine, as in "John has
two dogs".

------
YohAsakura
Thank you very much for such detailed explanation of what is what in the world
of graphics, now I understand the basics and what all the cool words (metal,
gfx-hal, opengl, etc.) mean.

