• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# SPIRV-Tools
2
3Wasm (WebAssembly) build of https://github.com/KhronosGroup/SPIRV-Tools
4
5## Usage
6
7```js
8const spirvTools = require("spirv-tools");
9
10const test = async () => {
11  // Load the library
12  const spv = await spirvTools();
13
14  // assemble
15  const source = `
16             OpCapability Linkage
17             OpCapability Shader
18             OpMemoryModel Logical GLSL450
19             OpSource GLSL 450
20             OpDecorate %spec SpecId 1
21      %int = OpTypeInt 32 1
22     %spec = OpSpecConstant %int 0
23    %const = OpConstant %int 42`;
24  const asResult = spv.as(
25    source,
26    spv.SPV_ENV_UNIVERSAL_1_3,
27    spv.SPV_TEXT_TO_BINARY_OPTION_NONE
28  );
29  console.log(`as returned ${asResult.byteLength} bytes`);
30
31  // re-disassemble
32  const disResult = spv.dis(
33    asResult,
34    spv.SPV_ENV_UNIVERSAL_1_3,
35    spv.SPV_BINARY_TO_TEXT_OPTION_INDENT |
36      spv.SPV_BINARY_TO_TEXT_OPTION_FRIENDLY_NAMES |
37      spv.SPV_BINARY_TO_TEXT_OPTION_COLOR
38  );
39  console.log("dis:\n", disResult);
40};
41
42test();
43```
44