Skip to content

Meshes that deform are skinned on the GPU - #181

Merged
yujiaxu-ops merged 6 commits into
mainfrom
gpu-skinning
Nov 21, 2026
Merged

yujiaxu-ops merged 6 commits into
mainfrom
gpu-skinning

Conversation

@yujiaxu-ops

@yujiaxu-ops yujiaxu-ops commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

A new pose of a mesh that deforms was skinned on the CPU and every triangle of it sent again: 180 bytes each (its vertices, its shading attributes, the BLAS's input). Now the CPU sends the pose's matrices and a compute pass skins the mesh where it lies.

  • The pass (shaders/skin.wgsl, Gpu::skin): a triangle an invocation, from its model's corners as the file has them (position, normal, tangent, four matrices and weights; one copy a model, whatever its poses) and the pose's matrices (a skin's joints, and the nodes of primitives beside it), into the triangles, the attributes' normals, tangent and texel density, and the BLAS's input. The commit builds the mesh's BLAS after it, as before.
  • The CPU keeps no triangles of such a pose. A click or a query skins the mesh when it asks.
  • A pose that mirrors other primitives than the one the mesh was made for has its triangles in another order: a rebuild's.
  • An authored tangent of a skinned vertex follows its joints now (it was placed by the object alone).

Still on the CPU: a posed model alone in its pose (world-space triangles: the next step makes it a mesh of its own), and every pose under software traversal.

A fault found on the way, older than this

A posed model the scene did not call movable was moved by skinning it again where it stands, so its move was recorded as a new pose. One that is an instance of a mesh that deforms was then not moved at all: no pose had changed, and nothing rebuilt. A posed model's move is a move now: the renderer moves an instance, and skins world-space triangles again. The test of it was 3.6 steps from a build's picture before.

Measured

A crowd of 150 walkers in 8 shared poses, hardware traversal, the two builds in turn after a run thrown away:

a frame, ms main this
the commit 2.9 2.1
of it the upload 0.82 0.18
of it the skin 0.45 0.30
the trace 4.07, 4.30 4.07, 4.09

With every walker a mesh of its own (a switch of an experiment, not in the tree): the CPU's frame is 24 ms with the CPU skin (15 ms of it upload: 40 fps) and 7.4 ms with the pass (60 fps).

GPU time a frame at 1080p on twelve scenes (the crowd among them), two alternated pairs against main after a run thrown away: all within 0.7 %; the two scenes with posed models again at the last commit: within 0.4 %. The quality figures against the offline references are main's.

Checks

  • New tests: the pass's output read back from the GPU and compared word by word with the CPU skin after each new pose, for two model files in two poses (tests/render/data/skin-blend.glb: more triangles than a block of the pass, vertices two joints hold, weights that do not sum to one, a primitive with tangents, one without normals, a joint turned about an axis that is neither the normals' nor the tangents', a mesh on a node beside the skin that mirrors it, materials in an order the mesh does not keep), with world-space triangles before the meshes'; the previous frame's vertices, the mesh as the CPU has it when asked, the picture against a build's; a model moved alone, posed and moved at once, posed after the scene's buffers grew; a pose that mirrors other primitives, by a rebuild; the corners placed by the palette on the CPU against the model's triangles; the shader valid as WGSL.
  • The unit tests and the render tests, natively and under software traversal, beside main's on the same machine: 209 unit tests pass both ways; 264 render tests natively; under software traversal the 23 that fail on main, and no other.
  • 27 mutations of the new logic (the shader, the palette and corners, the jobs and their offsets, the order of the copy of the previous frame, the move): each fails a test. Two did not at first: a mesh's triangles were in its model's order, and first in the GPU's, in every scene the tests had; the fixture and the scene were made to differ.
  • Not run on Vulkan yet.

🤖 Generated with Claude Code


Note

Medium Risk
Touches live pose updates, GPU buffer layout, and picking correctness on the hardware-RT path, though coverage is strong (GPU vs CPU readback, mutation tests).

Overview
Deforming mesh poses are skinned on the GPU instead of re-skinning on the CPU and re-uploading every triangle (vertices, attributes, BLAS input). Each frame the CPU only uploads joint palette matrices; shaders/skin.wgsl and Gpu::skin run a compute pass (one invocation per triangle) from shared per-model corners (Scene::skin_sources, SkinCorner) into scene verts, TriAttr, and BLAS geometry before BLAS rebuild.

Scene prep adds skin_sources and extends PoseGroup with palette layout and mirror metadata; poses that change triangle order via mirroring still force a rebuild. Picking / node_tris no longer rely on a full CPU copy of posed triangles—they on-demand CPU-skin via new mesh_tris when needed.

Bugfix: moving a non-movable posed model is recorded as moved (instance transform), not as a new pose, so shared deforming instances actually update when only the transform changes. Tangents on skinned vertices now follow joint blending like normals.

Documentation and broad tests compare GPU buffers word-for-word to CPU skin, including move/pose combos and buffer regrowth.

Reviewed by Cursor Bugbot for commit 622bf0f. Bugbot is set up for automated code reviews on this repo. Configure here.

yujiaxu-ops and others added 4 commits November 20, 2026 19:28
…hored tangent follows its joints

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A new shared pose sent every triangle of its mesh: 180 bytes each, skinned on the CPU. Now the CPU sends the pose's
matrices and a compute pass skins the mesh from its model's corners: triangles, shading attributes, BLAS input.
The CPU keeps no triangles of such a pose; a click or a query skins the mesh when it asks.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
yujiaxu-ops and others added 2 commits November 21, 2026 16:15
A posed model the scene did not call movable was moved by skinning it again where it stands. One that is an instance
of a deforming mesh was not moved at all: no pose had changed, and nothing rebuilt. Its move is recorded as a move
now; the renderer moves an instance and skins world-space triangles again.

The test's fixture: 72 triangles (two blocks of the pass), a joint turned about an axis that is neither the
normals' nor the tangents', a node that mirrors its mesh, a clip that turns it back. The test: two model files in
two poses (two sources, two jobs), a model moved alone, posed and moved at once, after the scene's buffers grew,
and a pose that mirrors other primitives.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A mesh's triangles were in its model's order, and first in the GPU's, in every scene the tests had: corners left in
the model's order, and a job counted from the pool's start, passed. The fixture's materials now go light, grey,
light, and the scene has a rect light's card before the meshes.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@yujiaxu-ops
yujiaxu-ops marked this pull request as ready for review November 21, 2026 09:22
@yujiaxu-ops
yujiaxu-ops merged commit 42dbb75 into main Nov 21, 2026
9 checks passed
@yujiaxu-ops
yujiaxu-ops deleted the gpu-skinning branch November 21, 2026 09:31
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