Skip to content

Fix lowering of swizzled lvalues - #12769

Open
kmshanah wants to merge 4 commits into
shader-slang:masterfrom
kmshanah:feature/fix-lowering-swizzled-lvalues
Open

Fix lowering of swizzled lvalues#12769
kmshanah wants to merge 4 commits into
shader-slang:masterfrom
kmshanah:feature/fix-lowering-swizzled-lvalues

Conversation

@kmshanah

Copy link
Copy Markdown
Contributor
  • 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)

@kmshanah
kmshanah requested a review from a team as a code owner August 26, 2026 09:25
@kmshanah
kmshanah requested review from bmillsNV and removed request for a team August 26, 2026 09:25
@jhelferty-nv
jhelferty-nv requested review from jhelferty-nv and removed request for bmillsNV August 26, 2026 09:25
@jhelferty-nv

Copy link
Copy Markdown
Contributor

Automated notice (PR board sync) — do not reply to this comment.

Auto-assigned @jhelferty-nv as shepherd for this Community PR.

@coderabbitai

coderabbitai Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 476e5f20-587c-4ffb-921c-a33c6779c085

📥 Commits

Reviewing files that changed from the base of the PR and between 75ecfe6 and dbcf890.

📒 Files selected for processing (1)
  • source/slang/slang-lower-to-ir.cpp

Included review availability: Your plan provides up to 8 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

Nested 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.

Changes

Nested swizzle lowering

Layer / File(s) Summary
Fix nested swizzle index remapping
source/slang/slang-lower-to-ir.cpp
backpermute now receives the destination array by reference. SwizzledLValueInfo::elementIndices is pre-sized with setCount(elementCount).
Add nested swizzle write regression test
tests/language-feature/swizzles/vector-swizzle-write-swizzle.slang, tests/language-feature/swizzles/vector-swizzle-write-swizzle.slang.expected.txt
The compute shader writes through nested vector swizzles. The expected output records the resulting float values.

Suggested reviewers: jhelferty-nv, csyonghe, saipraveenb25

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: fixing the lowering of swizzled l-values.
Description check ✅ Passed The description directly explains both implementation fixes in the changeset.
Docstring Coverage ✅ Passed 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…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

github-actions[bot]

This comment was marked as outdated.

@nv-slang-bot

nv-slang-bot Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Thanks for the quick fix — the 2-line change matches the root cause of #12768 exactly: .add((uint32_t)elementCount).setCount(...) sizes the composed index list correctly (the old form produced a length-1 list holding the count 3), and auto bsauto& bs makes backpermute write through the real ShortList instead of a discarded copy.

Two small follow-ups would let this PR fully close the loop on the issue:

  1. Add Closes #12768 to the description — the description has no closing keyword, so the issue won't auto-close when this merges.
  2. A regression test — the github-actions[bot] review above (the "No regression test for the fixed nested-swizzle l-value path" comment) already lays out a good GPU-free approach. A CPU COMPARE_COMPUTE that writes through a nested vector swizzle and reads the components back would lock in the exact wrong-component store this fixes; tests/language-feature/swizzles/matrix-swizzle-write-swizzle.slang is the matrix analogue to model it on.

🤖 Generated by an automated Slang coworker — may be inaccurate. A human maintainer should verify.

@kmshanah
kmshanah force-pushed the feature/fix-lowering-swizzled-lvalues branch from b5d2bfe to 70d5cd0 Compare August 26, 2026 10:04
github-actions[bot]

This comment was marked as outdated.

@kmshanah
kmshanah force-pushed the feature/fix-lowering-swizzled-lvalues branch 2 times, most recently from ef6a9a0 to 6abab25 Compare August 26, 2026 10:19
github-actions[bot]

This comment was marked as outdated.

@kmshanah
kmshanah force-pushed the feature/fix-lowering-swizzled-lvalues branch from 6abab25 to 75ecfe6 Compare August 26, 2026 10:47

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6abab25 and 75ecfe6.

📒 Files selected for processing (2)
  • source/slang/slang-lower-to-ir.cpp
  • tests/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.

Comment thread source/slang/slang-lower-to-ir.cpp Outdated
@kmshanah
kmshanah force-pushed the feature/fix-lowering-swizzled-lvalues branch from 75ecfe6 to dbcf890 Compare August 26, 2026 10:52
github-actions[bot]

This comment was marked as outdated.

- 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
@kmshanah
kmshanah force-pushed the feature/fix-lowering-swizzled-lvalues branch from dbcf890 to b84affd Compare August 26, 2026 11:17
github-actions[bot]

This comment was marked as outdated.

jkwak-work
jkwak-work previously approved these changes Aug 27, 2026

@jkwak-work jkwak-work 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.

Looks good to me

@jkwak-work
jkwak-work enabled auto-merge August 27, 2026 01:19
@jkwak-work jkwak-work self-assigned this Aug 27, 2026
@jkwak-work

Copy link
Copy Markdown
Collaborator

Fixes #12768

@jkwak-work jkwak-work added the pr: non-breaking PRs without breaking changes label Aug 27, 2026
auto-merge was automatically disabled August 27, 2026 03:47

Head branch was pushed to by a user without write access

github-actions[bot]

This comment was marked as outdated.

@kmshanah
kmshanah deployed to falcor-ci August 27, 2026 22:23 — with GitHub Actions Active
Comment thread source/slang/slang-lower-to-ir.cpp Outdated
@jkwak-work

Copy link
Copy Markdown
Collaborator

PR looks good to me.

I retriggered the failed aarch64-windows tests.

github-actions[bot]

This comment was marked as outdated.

@jkwak-work jkwak-work Aug 28, 2026

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.

*.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.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 SwizzledLValue collapse branch, swizzledLValue->elementIndices is now sized with setCount((uint32_t)elementCount) instead of add(...), and the backpermute lambda takes resultElements by reference (auto&) so the permuted indices land in the real list. The sourceElements/indices/resultElements renames make the gather explicit. This matches the existing setCount+fill-loop idiom already used on the assign path (slang-lower-to-ir.cpp:10174-10176). The SwizzledMatrixLValue branch was unaffected functionally (its MatrixCoord[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 old add(...) shape mishandled. Expected buffer [2,1,0,9].

reviewed: 93438cc · diff sha256 1c8f977d08b1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr: non-breaking PRs without breaking changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants