Skip to content

feat: Add C++ and WASI WebGPU#33

Open
cdmurph32 wants to merge 23 commits intoadobe:mainfrom
cdmurph32:cpp_wasi
Open

feat: Add C++ and WASI WebGPU#33
cdmurph32 wants to merge 23 commits intoadobe:mainfrom
cdmurph32:cpp_wasi

Conversation

@cdmurph32
Copy link
Copy Markdown

Description

Related Issue

Motivation and Context

How Has This Been Tested?

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • I have signed the Adobe Open Source CLA.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

MLAS wasn't using SIMD. the configuration in cma/onnxruntime_mlas.cmake was only checking for emscripten
Two bugs in trustmark_wasm_image.cpp:

1. BGR conversion was wrong — stb_image loads as RGB; the model was trained
   on PIL RGB images. The rgbToBgr call swapped R↔B channels feeding
   incorrect data to the model. Removed entirely.

2. Output was wrong — encoder returns a raw stego tensor, not the final
   watermarked image. Correct pipeline (matching Python and native C++):
     residual = clamp(stego, -1, 1) - input_normalized
     residual *= WM_STRENGTH (1.25 for P variant)
     residual = clamp(residual, -0.2, 0.2)
     final = clamp(input_normalized + residual, -1, 1)
     output_uint8 = (final + 1) * 0.5 * 255

Also simplify imageToTensor/tensorToImage helpers and make USE_WEBGPU
conditional (env var) instead of always-on.
Fixes several incorrect/stale details:
- Graphtime repo: cdmurph32/graphtime (not bytecodealliance/wasi-gfx)
- Build script: build_wasi.sh (not build_wasi_minimal_with_config.sh)
- Build output: build_wasi/ (not build_wasi_minimal_config/)
- WebGPU: now fully working (f16 fix applied to wasi-gfx-runtime)
- Remove stale BGR conversion step from example output
- Fix --dir syntax examples to match what actually works
- Add key repositories table and fixes-applied section
trustmark_wasm_image.cpp:
- WM_STRENGTH: 1.25 -> 0.95*1.25=1.1875 (matches Rust CLI strength=0.95)
- Add optional argv[3] bits_arg for custom 100-bit BCH watermark string
- DEFAULT_BITS: BCH-Bch5 encoded test watermark verified to roundtrip

WASM_BUILD.md:
- Decoder: use decoder_P.with_runtime_opt.ort for WebGPU (plain .ort
  triggers InsertedPrecisionFreeCast nodes that corrupt decoder input)
- Encoder: use encoder_P.with_runtime_opt.ort for 0 bit-flip roundtrip
- Add wasm-tools component new step (required after build_wasi.sh)
- Update decoder example output (now shows correct decoded bits)
- Fix build flags: -Donnxruntime_EXTENDED_MINIMAL_BUILD=ON and
  -Donnxruntime_WGSL_TEMPLATE=static required
I need to put back the onnxruntime submodule which I removed to same
harddrive space.
@cdmurph32 cdmurph32 marked this pull request as ready for review April 28, 2026 16:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant