third_party_spirv-tools/source/wasm
huruitao e8ad9735b1 update to vulkan-sdk-1.3.275.0
Signed-off-by: huruitao <huruitao@kaihong.com>
2024-05-21 14:26:42 +08:00
..
build.sh update to vulkan-sdk-1.3.275.0 2024-05-21 14:26:42 +08:00
docker-compose.yml update to vulkan-sdk-1.3.275.0 2024-05-21 14:26:42 +08:00
package.json update to v2022.4 2023-07-11 10:14:11 +08:00
README.md update to v2022.4 2023-07-11 10:14:11 +08:00
spirv-tools.cpp update to v2022.4 2023-07-11 10:14:11 +08:00
spirv-tools.d.ts update to v2022.4 2023-07-11 10:14:11 +08:00

SPIRV-Tools

Wasm (WebAssembly) build of https://github.com/KhronosGroup/SPIRV-Tools

Usage

const spirvTools = require("spirv-tools");

const test = async () => {
  // Load the library
  const spv = await spirvTools();

  // assemble
  const source = `
             OpCapability Linkage 
             OpCapability Shader 
             OpMemoryModel Logical GLSL450 
             OpSource GLSL 450 
             OpDecorate %spec SpecId 1 
      %int = OpTypeInt 32 1 
     %spec = OpSpecConstant %int 0 
    %const = OpConstant %int 42`;
  const asResult = spv.as(
    source,
    spv.SPV_ENV_UNIVERSAL_1_3,
    spv.SPV_TEXT_TO_BINARY_OPTION_NONE
  );
  console.log(`as returned ${asResult.byteLength} bytes`);

  // re-disassemble
  const disResult = spv.dis(
    asResult,
    spv.SPV_ENV_UNIVERSAL_1_3,
    spv.SPV_BINARY_TO_TEXT_OPTION_INDENT |
      spv.SPV_BINARY_TO_TEXT_OPTION_FRIENDLY_NAMES |
      spv.SPV_BINARY_TO_TEXT_OPTION_COLOR
  );
  console.log("dis:\n", disResult);
};

test();