Offline compilation of Vulkan compute shaders

28 views
Skip to first unread message

Elias Naur

unread,
Jun 28, 2020, 4:18:50 PM6/28/20
to swift...@googlegroups.com
CC: Viktor Ogeman <viktor...@gmail.com>

Hi,

Can SwiftShader compile Vulkan compute shaders offline, allowing
one to statically link them into a program, without embedding
SwiftShader?

We'd like to render 2D graphics on the GPU using techniques from
piet-gpu,

https://raphlinus.github.io/rust/graphics/gpu/2020/06/13/fast-2d-rendering.html

in the Gio project (https://gioui.org). However, for compatibility and
low maintenance we also want the same compute shaders to run on the CPU
on devices that don't support vulkan compute shaders.

Embedding the entire SwiftShader is overkill when we only need compute
and have a static set of shaders. LLVM can compile OpenCL shaders for
CPUs, but not Vulkan compute shaders.

Thank you,
-- elias

Nicolas Capens

unread,
Jun 29, 2020, 10:20:34 AM6/29/20
to Elias Naur, swiftshader
Hi Elias,

No, sorry, such a feature is not available. To keep our scope focused, we only implement things which are also (widely) supported by GPU drivers.

Note that we compile and optimize shaders specifically for the CPU microarchitecture it is running on. Vulkan pipeline caches for the GPU also don't typically allow reuse across devices or driver versions.

Why does integrating all of SwiftShader not work for you? Note that its binary size is significantly smaller when using the Subzero JIT instead of LLVM.

Cheers,
Nicolas

--
You received this message because you are subscribed to the Google Groups "swiftshader" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swiftshader...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/swiftshader/C3T06XPIL47C.UG0ERWOBXKTR%40testmac.

Elias Naur

unread,
Jun 29, 2020, 11:27:43 AM6/29/20
to Nicolas Capens, swiftshader
Hi Nicolas,

Thank you for your swift response :)

On Mon Jun 29, 2020 at 10:20, Nicolas Capens wrote:
> No, sorry, such a feature is not available. To keep our scope focused, we
> only implement things which are also (widely) supported by GPU drivers.
>
> Note that we compile and optimize shaders specifically for the CPU
> microarchitecture it is running on. Vulkan pipeline caches for the GPU also
> don't typically allow reuse across devices or driver versions.
>

Makes sense. That description matches what I had expected.

> Why does integrating all of SwiftShader not work for you? Note that its
> binary size is significantly smaller when using the Subzero JIT instead of
> LLVM.
>

Good question. Binary size is one thing, I'm also wary of bringing in a complex
dependency "just" to compile and execute a static set of compute shaders. For
example, building a Gio program for Windows require nothing else than the Go
toolchain, can be done from any supported platform with a single command, and
results in a self-contained .exe file.

I suppose I could prebuild a static version of SwiftShader and add it to the
repository, but then there's a licensing mismatch (Gio is dual-licensed under
the UNLICENSE) and the usual trouble of build artifacts in a source repository.

-- elias

Jeff Muizelaar

unread,
Jun 29, 2020, 2:43:10 PM6/29/20
to Elias Naur, Nicolas Capens, swiftshader
We solved a similar problem for WebRender by writing a translator for WebRender's shaders to C++: https://github.com/servo/webrender/tree/master/glsl-to-cxx. It doesn't support compute shaders but could be adapted to do so.

-Jeff

--
You received this message because you are subscribed to the Google Groups "swiftshader" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swiftshader...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages