gpu-dawn: reduce Dawn build and iteration times #124
Labels
No labels
CI
all
basisu
blog
bug
build
contributor-friendly
core
correctness
deferred
dev
direct3d-headers
docs
driver-os-issue
duplicate
dxcompiler
editor
examples
experiment
feature-idea
feedback
flac
freetype
gamemode
gkurve
glfw
gpu
gpu-dawn
harfbuzz
help welcome
in-progress
infrastructure
invalid
libmach
linux-audio-headers
long-term
mach
mach.gfx
mach.math
mach.physics
mach.testing
model3d
needs-triage
object
opengl-headers
opus
os/linux
os/macos
os/wasm
os/windows
package-manager
priority
proposal
proposal-accepted
question
roadmap
slipped
stability
sysaudio
sysgpu
sysjs
validating-fix
vulkan-zig-generated
wayland-headers
website
wontfix
wrench
www
x11-headers
xcode-frameworks
zig-update
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
hexops/mach#124
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Update: Before I opened this issue, build and iteration times were quite slow. We've made good progress, keeping this issue open for further improvements. Results so far:
macOS M1 (original chipset) w/16GB RAM:
zig buildactionlibgpu.asizedawn-examplesizeAfter the changes above, we see some great gains:
zig buildactionAdditionally I tracked down where time is spent:
parseObjectsIntoAtomscalcAdhocSignatureAfter discussion with Jakub (zld author) it seems highly likely link time/perf can be improved esp. in those two functions above.
Comparing build times on a really beefy Linux gaming laptop laptop (i7-10875H, 8 core 5.1ghz w/32GB RAM) vs. macOS M1 (original chipset, 16GB RAM):
zig buildactionReally interesting numbers here:
Why is building on Linux from scratch so much slower? Maybe opengl+vulkan backend really takes that much longer to compile than metal backend?
Why are iteration times on macOS so much worse? Guessing zld perf just isn't there yet, but that gives us an idea of how much room for improvement we can expect in zld in the future I guess!
Investigating from-scratch build times, on M1 macOS:
Collected by swapping the end of
lib/zig/std/build.zig:makeOneStepwith:We could eliminate SPIRV support on macOS (would require contributing a change upstream to Dawn) which, from experiments, would reduce build times on macOS from 2m38s -> 1m57s (26% reduction.)
We could also eliminate it on Windows if we only target DirectX. Linux would require it as both Vulkan and OpenGL backends require it.
It's been pointed out in the dawn issues that abseil's use is trivial (just an overpowered string format), but an outsized part of the build for its contribution.
The push back was that abseil has fast hashing and containers that maybe could be used in the future.
In the mean time, the formatting routines rope in nearly the entire abseil library, spiraling down into time zones, language localizations, and so much more.
Might be worth dropping more notes on the issue, highlighting that abseil is one of the larger time consuming build components.
https://bugs.chromium.org/p/dawn/issues/detail?id=1148&q=abseil&can=2
@meshula thanks, and will do!
Even if we eliminated abseil entirely, though, I still think build times here are kinda unacceptable.
Almost all of the build time seems to come from spirv-tools, tint, DirectXShaderCompiler, and spirv-cross. I want to dig more into why these are so slow to compile, but I fear the real answer is just shader compilation + translation requires 2-4 different compilers":
I suspect that this amount of indirections is one of the reasons Dawn is likely to be so mature / less buggy, but also quite heavy.
Exploring whether or not we can reduce the amount of spirv-tools code that gets pulled in:
Building spirv-tools goes from 84s -> 30s if we eliminate Tint's SPIRV reader and the spirv-tools optimizer, nice!
Building spirv-tools goes from 30s->6s if we eliminate the dependency on the SPIRV validator (easy for macOS, probably doable on others)
My current approach is native-as-possible; so Metal/DX/Vk as appropriate - the sad thing is Vk is most useful to me on the slowest platform, rpi, where I am stubbornly building natively rather than cross compiling from desktop. That said, I love the speed gains implied for Metal/DX platforms at least. Maybe the thing to do there is to have an explicit but optional cross-platform build for rpi, so that eating the Khronos tool chain build-pain is an optional choice?
@meshula I am actually thinking we can have a build config option which is maybe on-by-default and fetches/uses prebuilt binaries for the target. You'd be able to toggle it off with the flip of a switch and get the build from source using just Zig, though (that's how the binaries would be produced)
Thoughts on that?
Also see #133 for another idea I have going on.
Cached binaries makes a ton of sense for first time, and iteration purposes. A locally reproducible build can be used for air-gapped systems that can't pull binaries from the internet for whatever reason, and security audits.
I looked into why gfx-rs/wgpu may be faster to compile than Dawn, some key differences I noticed:
Great news, Dawn no longer requires spirv-cross for OpenGL backends. This should speed up Linux compilation significantly, and reduce binary sizes a bit!
github.com/hexops/dawn@a52abab38cThere's an upcoming demo about this, but
mach/gpu-dawnnow builds binary releases for every target and thebuild.zigmakes using them a magical experience so that by default you get pretty instant binary downloads, and just add-Ddawn-from-source=trueto build Dawn 100% from source using the Zig compiler.