kig / spirv-wasm

Run SPIR-V shaders in WebAssembly
Apache License 2.0
11 stars 0 forks source link

Compile the compilation toolchain to WebAssembly #6

Open kig opened 4 years ago

kig commented 4 years ago

Running native code is such a bore, let's compile glslangValidator, spirv-cross, ispc and LLVM to WebAssembly.

const src = await (await fetch('my.comp.glsl')).text();
const program = await compile(src);
const result = await program(inputBuffer, outputBuffer);
kig commented 4 years ago

There's https://wapm.io/package/clang and https://github.com/KhronosGroup/glslang/blob/master/README.md#building-to-wasm-for-the-web-and-node

kig commented 4 years ago

For SPIRV-cross, there's https://github.com/grovesNL/spirv_cross/tree/master/wasm

kig commented 3 years ago

GLSL to SPIR-V:

const glslang = require('@webgpu/glslang')();
const src = fs.readFileSync('compute_shader.glsl.comp', 'utf8');
const res = glsl.compileGLSL(src, 'compute', false, '1.3');
// Uint32Array(13615) [ 0x07230203, ...