Fix lowering of swizzled lvalues - #12769
Conversation
kmshanah
commented
Aug 26, 2026
- Set the size of the elementIndices instead of adding the size as a value
- Fix backpermute lambda to modify the passed in indicies (was working on a copy)
|
Automated notice (PR board sync) — do not reply to this comment. Auto-assigned @jhelferty-nv as shepherd for this Community PR. |
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 8 included reviews per hour; 3 remain after this review. 📝 WalkthroughWalkthroughNested l-value swizzle lowering now preserves remapped element indices and correctly sizes the destination index list. A compute shader regression test validates nested vector swizzle writes across supported backends. ChangesNested swizzle lowering
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Full details: Docstring CoverageExplanation No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0 files. (1 skipped: 1 too large.) Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Thanks for the quick fix — the 2-line change matches the root cause of #12768 exactly: Two small follow-ups would let this PR fully close the loop on the issue:
🤖 Generated by an automated Slang coworker — may be inaccurate. A human maintainer should verify. |
b5d2bfe to
70d5cd0
Compare
ef6a9a0 to
6abab25
Compare
6abab25 to
75ecfe6
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 80fd7193-7593-4e61-ab80-d1be82dfe5db
📒 Files selected for processing (2)
source/slang/slang-lower-to-ir.cpptests/language-feature/swizzles/vector-swizzle-write-swizzle.slang
Included review availability: Your plan provides up to 8 included reviews per hour; 4 remain after this review.
75ecfe6 to
dbcf890
Compare
- Set the size of the elementIndices instead of adding the size as a value - Fix backpermute lambda to modify the passed in indicies (was working on a copy) Closes shader-slang#12768
dbcf890 to
b84affd
Compare
|
Fixes #12768 |
Head branch was pushed to by a user without write access
|
PR looks good to me. I retriggered the failed aarch64-windows tests. |
There was a problem hiding this comment.
*.expected.txt is a less preferred way to check the result due to its lower readability.
And it looks like this file is redundant to what we already have:
// CHECK: 2.0
// CHECK-NEXT: 1.0
// CHECK-NEXT: 0.0
// CHECK-NEXT: 9.0
Please delete this file.
There was a problem hiding this comment.
Verdict: ✅ Clean — no significant issues found
Fixes two defects in visitSwizzleExpr when lowering a swizzle-of-swizzle lvalue write (e.g. a.zw.y = 9.0, a.xyzw.yx = float2(...)): (1) elementIndices.add((uint32_t)elementCount) appended the count as a value (leaving getCount() == 1) rather than sizing the list, and (2) the backpermute lambda took its output list by value, so the remapped indices were written to a discarded copy. Both are corrected (setCount + pass-by-reference), and a regression test is added.
Changes Overview
Nested vector swizzle lvalue lowering (source/slang/slang-lower-to-ir.cpp)
- In the
SwizzledLValuecollapse branch,swizzledLValue->elementIndicesis now sized withsetCount((uint32_t)elementCount)instead ofadd(...), and thebackpermutelambda takesresultElementsby reference (auto&) so the permuted indices land in the real list. ThesourceElements/indices/resultElementsrenames make the gather explicit. This matches the existingsetCount+fill-loop idiom already used on the assign path (slang-lower-to-ir.cpp:10174-10176). TheSwizzledMatrixLValuebranch was unaffected functionally (itsMatrixCoord[4]C array decayed to a pointer under pass-by-value) but is now uniform.
Regression test (tests/language-feature/swizzles/vector-swizzle-write-swizzle.slang)
- New compute test (d3d/vk/mtl/cpu) exercising a single-element (
a.zw.y) and a multi-element (a.xyzw.yx) outer swizzle write; the multi-element case is exactly what the oldadd(...)shape mishandled. Expected buffer[2,1,0,9].
reviewed: 93438cc · diff sha256 1c8f977d08b1