Skip to content

fix(WebGPU): apply projection once in ImageMapper and refresh imageData textures#3547

Open
sedghi wants to merge 2 commits into
Kitware:masterfrom
sedghi:webgpu-image-mapper-fixes
Open

fix(WebGPU): apply projection once in ImageMapper and refresh imageData textures#3547
sedghi wants to merge 2 commits into
Kitware:masterfrom
sedghi:webgpu-image-mapper-fixes

Conversation

@sedghi

@sedghi sedghi commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Context

The WebGPU ImageMapper vertex shader applies rendererUBO.SCPCMatrix twice (regression from 7fbc87a). With close-in cameras — e.g. a parallel camera one unit in front of the slice, as medical viewers set up — the doubly-projected quad falls outside the clip volume and the slice silently renders nothing. The same commit also stores a clip-space position in vertexSC, which the clip-plane code expects in stabilized coordinates.

Separately, TextureManager.getTextureForImageData keys its texture cache on the scalar array mtime alone, so writing scalars in place and signaling with imageData.modified() (the invalidation the OpenGL backend keys texture rebuilds on) keeps returning the stale texture.

Both were found while rendering image stacks on the WebGPU view API from Cornerstone3D.

Results

  • Image slices render again with offset parallel cameras (before: nothing drawn; reproducible with the ImageMapper example and ?viewAPI=WebGPU).
  • Clip planes on ImageMapper are evaluated in stabilized coordinates again.
  • Textures refresh when scalars are updated in place and only imageData.modified() is called.

Changes

  • WebGPU/ImageMapper: capture vertexSC before projecting, apply SCPCMatrix once (matches ImageResliceMapper/ImageCPRMapper).
  • WebGPU/TextureManager: key the getTextureForImageData cache on the newest of the imageData and scalar array mtimes.
  • vitest.config.js: pass --enable-unsafe-webgpu to headless Chromium for WEBGPU=1 runs (plus the SwiftShader WebGPU adapter on CI) so the WebGPU tests can acquire an adapter.
  • No public API changes.
  • Documentation and TypeScript definitions were updated to match those changes (none needed — no API changes)

PR and Code Checklist

  • semantic-release commit messages
  • Run npm run reformat to have correctly formatted code

Testing

Two regression tests, one per fix; both fail without the fixes:

WEBGPU=1 NO_WEBGL=1 npx vitest run \
  Sources/Rendering/WebGPU/ImageMapper/test/testImageMapperCameraProjection.js \
  Sources/Rendering/WebGPU/TextureManager/test/testImageDataTextureCacheInvalidation.js
  • This change adds or fixes unit tests
  • Tested environment:
    • vtk.js: master (07c3e9a)
    • OS: macOS 15
    • Browser: Chromium (Playwright, headless) and Chrome, Apple Metal adapter

sedghi added 2 commits July 9, 2026 23:07
The generated vertex shader multiplied by rendererUBO.SCPCMatrix twice
(regression from 7fbc87a), pushing the doubly-projected slice quad
outside the clip volume for close-in cameras, and stored a clip-space
position in vertexSC, which clip planes expect in stabilized
coordinates. Capture vertexSC before projecting and project once.

Adds a WebGPU regression test and enables the WebGPU adapter for
headless Chromium test runs.
getTextureForImageData keyed the texture cache on the scalar array
mtime alone, so consumers that write scalars in place and signal the
change with imageData.modified() (the pattern the OpenGL backend keys
its texture rebuilds on) kept getting the stale texture. Key the cache
on the newest of the imageData and scalar array mtimes.

Adds a WebGPU regression test.
@finetjul finetjul requested a review from sankhesh July 10, 2026 06:57

@daker daker left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 it will fix MultiSliceImageMapper example

@sedghi

sedghi commented Jul 10, 2026

Copy link
Copy Markdown
Contributor Author

if you run the example in main it will be for webgpu view

CleanShot 2026-07-10 at 09 17 48@2x

but in this branch will become

CleanShot 2026-07-10 at 09 18 33@2x

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.

2 participants