Skip to content

feat(raster): composite a layer through an affine matrix - #603

Merged
github-actions[bot] merged 1 commit into
devfrom
lead/affine-composite-ac-5
Oct 19, 2026
Merged

github-actions[bot] merged 1 commit into
devfrom
lead/affine-composite-ac-5

Conversation

@prakashUXtech

@prakashUXtech prakashUXtech commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

What

PixelBuffer.composite(_:through:mode:opacity:filter:) and AffineMatrix.bounds(of:_:) in
Sources/CoreRaster/Compositing/CompositeAffine.swift replace the AC-0 stubs (AC-5).

  • bounds(of:_:) maps all four corners of a width x height image, floors the least x/y and
    ceils the greatest. It returns nil when an entry or a corner isn't finite. Edges are clamped to ±2^52 in
    Double before the Int conversion, so a huge matrix can't overflow and x + width always fits.
  • composite(through:) checks the opacity (0...1, finite) and the matrix (finite, invertible) before
    it changes anything. It then clips the bounds to the backdrop and resamples the layer into a buffer
    the size of that clipped rectangle. To do that it calls the merged AC-3 transformed with the matrix
    moved by the rectangle's origin, so each backdrop pixel samples the same source point it would in a
    full-size copy. Last, it composites that piece at the origin with the existing
    composite(_:x:y:mode:opacity:) row blend. Sampling and blending are reused, not copied, and
    AffineTransform.swift is unchanged (no visibility change needed). No full-size intermediate is
    built, and rows outside the bounds are never written.
  • CompositeAffineTests is turned on (no assertion changed). It gains badInputThrowsAndLeavesBackdrop:
    NaN/infinite entries, singular matrices, and opacities 1.5, -0.1, NaN and infinity, including a bad
    opacity with an off-backdrop matrix. Each throws RasterError and leaves the backdrop == to a copy
    taken before.
  • AffineStubTests.swift is deleted: its only two cases were the composite and bounds stubs, so
    removing them left an empty suite.
  • Two mutation entries in Tests/mutations/CoreRaster.CompositeAffine.json.

Why

Packet docs/blueprints/core/features/affine-composite.md, slice AC-comp, task AC-5. A moved, scaled
or rotated layer now composites onto a backdrop in place, equal to transform-then-composite, without
building a full-size copy. AC-6's CPU affine call and the KJ-AC walk build on this.

Packet ambiguities resolved

  • Touched region = the corners' integer bounds, as the pseudocode says. A kernel's fringe can reach
    just past the corners: bilinear at 0.5 reaches about 0.75 output px, and Lanczos-3 reaches further.
    Those fringe pixels are not drawn, which matches "for each backdrop pixel in them" and
    rowsOutsideBoundsAreUntouched. Equality with transform-then-composite holds for layers whose edge
    pixels are transparent, as the fixtures' layers are. A borderless layer's fringe past the integer
    bounds is clipped.
  • Validation order. The opacity is checked first, then the matrix, before the off-backdrop early
    return. So bad input always throws, even when nothing would be drawn.
  • Overflow mid-composite. A non-finite blend result still throws as the offset composite does: rows
    above it are already written. Only the validation failures promise an unchanged backdrop.
  • Huge matrices. bounds clamps to ±2^52 rather than returning nil, so nil keeps the packet's
    meaning: non-finite only.

Proof

  • swift test --filter CompositeAffineTests: 6/6 pass (equalsTransformThenComposite,
    wholePixelTranslationsAreExact, rotatedBoundsCoverCorners, rowsOutsideBoundsAreUntouched,
    offBackdropChangesNothing, badInputThrowsAndLeavesBackdrop).
  • scripts/mutate --validate: OK. scripts/mutate --run --plan CoreRaster.CompositeAffine: 2/2 caught.
    "bounds from two corners only" is caught by rotatedBoundsCoverCorners. "Opacity applied twice" is
    caught first by wholePixelTranslationsAreExact; equalsTransformThenComposite covers it too.
  • scripts/ci: CI: PASS on the head below, rebased on origin/dev.

Docs MCP: apple-docs was used to check FloatingPoint.rounded(_:) and FloatingPointRoundingRule
(.down/.up). No other new platform or library API is used.

Part of #434

Belt-Lead: act-1a150bfbcf7-sfwy
Feature: affine-composite
Slice: AC-comp
Mutate: 2/2 CoreRaster.CompositeAffine
Fast-Check: pass
Head: 8446798


@prakashUXtech prakashUXtech added the fast-lane Small green PR, auto-merge when eligible label Oct 19, 2026 — with Claude
prakashUXtech added a commit that referenced this pull request Oct 19, 2026
@github-actions
github-actions Bot merged commit ae66640 into dev Oct 19, 2026
1 check passed
@github-actions github-actions Bot added the fast-lane-merged Merged by the fast lane; review after the fact label Oct 19, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Fast lane: merged into dev (146 lines, 4 files, Fast-Check marker).

@github-actions github-actions Bot mentioned this pull request Oct 19, 2026
prakashUXtech added a commit to qbtrix/creative-apps that referenced this pull request Oct 19, 2026
…rallel (#3126)

Moves the creative-core pin from bf5426e to 0de5687, the head of core
`main` (green, promoted from dev). The range has the resident-rendering
speedups from qbtrix/creative-core#620: the batched composite commits
without waiting, the resident dirty check is storage identity instead of
a pixel compare, and the Float16 tile upload vectorizes. It also has
qbtrix/creative-core#626, which repoints the mutation anchor #620 moved.

Core range (58 commits):
qbtrix/creative-core@bf5426e...0de5687

Core PRs in the range: qbtrix/creative-core#567 qbtrix/creative-core#568
qbtrix/creative-core#569 qbtrix/creative-core#570
qbtrix/creative-core#571 qbtrix/creative-core#573
qbtrix/creative-core#574 qbtrix/creative-core#575
qbtrix/creative-core#576 qbtrix/creative-core#577
qbtrix/creative-core#578 qbtrix/creative-core#579
qbtrix/creative-core#580 qbtrix/creative-core#581
qbtrix/creative-core#582 qbtrix/creative-core#583
qbtrix/creative-core#584 qbtrix/creative-core#585
qbtrix/creative-core#586 qbtrix/creative-core#587
qbtrix/creative-core#588 qbtrix/creative-core#589
qbtrix/creative-core#590 qbtrix/creative-core#591
qbtrix/creative-core#592 qbtrix/creative-core#593
qbtrix/creative-core#594 qbtrix/creative-core#595
qbtrix/creative-core#596 qbtrix/creative-core#597
qbtrix/creative-core#598 qbtrix/creative-core#599
qbtrix/creative-core#600 qbtrix/creative-core#601
qbtrix/creative-core#602 qbtrix/creative-core#603
qbtrix/creative-core#605 qbtrix/creative-core#606
qbtrix/creative-core#607 qbtrix/creative-core#608
qbtrix/creative-core#609 qbtrix/creative-core#612
qbtrix/creative-core#613 qbtrix/creative-core#614
qbtrix/creative-core#615 qbtrix/creative-core#616
qbtrix/creative-core#617 qbtrix/creative-core#618
qbtrix/creative-core#619 qbtrix/creative-core#620
qbtrix/creative-core#621 qbtrix/creative-core#622
qbtrix/creative-core#623 qbtrix/creative-core#625
qbtrix/creative-core#626

Besides the pin:
- `project.yml` gets the same revision, as in #3023.
- `PhotoWorkspace.residentComposited` syncs a region's layer tiles
across the cores (through `PhotoLayerComposite.inParallel`), as the CPU
route renders its tiles. Steps keep their order. On a brush frame that
crosses two tiles the sync went from about 0.73 ms to 0.39 ms.
- `Tests/render-budgets.md` has the new 8K table and says where a
resident brush frame's time goes.

8K brush frame, release on the M2 Pro (median of three runs; the Mac was
loaded, with another Photo running): CPU 1.0 ms, GPU-resident 1.4 ms
(was 1.7). The GPU route is still behind the CPU. Most of what's left is
the display into the presenter's texture, which waits about 0.55 ms for
the GPU because the presenter draws from its own queue. Full redraw on
the resident route is 31 ms (was 35) and the first picture 166 ms (was
192).

Checked locally on macOS: `scripts/bump-core`'s steps at 0de5687. `swift
build --build-tests` passed. Every `*ModelTests` target passed except
four Library wall-clock budget tests
(`oneEditOnSixtyPhotosStaysInBudget`, `cullOneWithinBudget`,
`beginImportWithinBudget`, `orderRebuildWithinBudget`), which went over
in the parallel run on the loaded Mac and pass when run alone. The brush
perf suites (PhotoBrushDisplayTests, PhotoBrushLatencyTests,
PhotoBrushInkLatencyTests) passed. With the parallel sync on top,
`PhotoModelTests` and `PhotoRenderBackendTests` passed (647 tests), and
`PhotoRenderBudgetTests` ran in release with
`Tests/SuiteUITests/SegmentedTabsTests.swift` set aside, since it
doesn't link in release on SDK 27.
prakashUXtech added a commit that referenced this pull request Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fast-lane Small green PR, auto-merge when eligible fast-lane-merged Merged by the fast lane; review after the fact

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant