Skip to content

Add test coverage for 8/16/64-bit types and vectors in dynamic dispatch#10475

Open
jvepsalainen-nv wants to merge 6 commits intoshader-slang:masterfrom
jvepsalainen-nv:dyn-dispatch-test-N-bit-types-vectors
Open

Add test coverage for 8/16/64-bit types and vectors in dynamic dispatch#10475
jvepsalainen-nv wants to merge 6 commits intoshader-slang:masterfrom
jvepsalainen-nv:dyn-dispatch-test-N-bit-types-vectors

Conversation

@jvepsalainen-nv
Copy link
Contributor

No existing test covers 64-bit scalar types (double, int64_t, uint64_t) or vectors of non-32-bit types as fields in interface implementations dispatched through dynamic dispatch. The AnyValue marshalling code has explicit alignment and packing logic for each bit width, but these paths lacked runtime dispatch coverage.

Tests added:

  • layout-64bit-scalar.slang: double, int64_t, uint64_t as impl fields, verifying 8-byte aligned two-uint32 split-and-reconstruct
  • layout-64bit-vector.slang: double2, vector<int64_t, 2> as impl fields, testing element-by-element 64-bit vector marshalling
  • layout-mixed-bitwidths.slang: int8_t, half, float, double, uint8_t together in one impl, exercising all alignment transitions
  • layout-8bit-vectors.slang: vector<int8_t, 4>, vector<uint8_t, 2>, vector<int8_t, 3> as impl fields, testing bitfield insert packing with different element counts including negative values
  • layout-16bit-vectors.slang: half4, int16_t2, vector<uint16_t, 3>
    as impl fields, testing 2-byte aligned packing

All tests use a runtime-loaded kind buffer to force genuine dynamic dispatch. Backend coverage varies by type support: cpu and cuda for all; vk with render-feature flags; metal for 8/16-bit; dx12 for 16-bit.

Closes #10470

No existing test covers 64-bit scalar types (double, int64_t, uint64_t)
or vectors of non-32-bit types as fields in interface implementations
dispatched through dynamic dispatch. The AnyValue marshalling code has
explicit alignment and packing logic for each bit width, but these
paths lacked runtime dispatch coverage.

Tests added:
- layout-64bit-scalar.slang: double, int64_t, uint64_t as impl fields,
  verifying 8-byte aligned two-uint32 split-and-reconstruct
- layout-64bit-vector.slang: double2, vector<int64_t, 2> as impl
  fields, testing element-by-element 64-bit vector marshalling
- layout-mixed-bitwidths.slang: int8_t, half, float, double, uint8_t
  together in one impl, exercising all alignment transitions
- layout-8bit-vectors.slang: vector<int8_t, 4>, vector<uint8_t, 2>,
  vector<int8_t, 3> as impl fields, testing bitfield insert packing
  with different element counts including negative values
- layout-16bit-vectors.slang: half4, int16_t2, vector<uint16_t, 3>
  as impl fields, testing 2-byte aligned packing

All tests use a runtime-loaded kind buffer to force genuine dynamic
dispatch. Backend coverage varies by type support: cpu and cuda for
all; vk with render-feature flags; metal for 8/16-bit; dx12 for
16-bit.

Closes shader-slang#10470
@jvepsalainen-nv jvepsalainen-nv self-assigned this Mar 10, 2026
@jvepsalainen-nv jvepsalainen-nv requested a review from a team as a code owner March 10, 2026 10:14
@jvepsalainen-nv jvepsalainen-nv requested review from bmillsNV and removed request for a team March 10, 2026 10:14
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 10, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 22849713-d698-4f84-8d8b-80c4a7ea4cb4

📥 Commits

Reviewing files that changed from the base of the PR and between de3d3fc and 8cef899.

📒 Files selected for processing (2)
  • tests/language-feature/dynamic-dispatch/layout-16bit-vectors.slang
  • tests/language-feature/dynamic-dispatch/layout-64bit-scalar.slang
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/language-feature/dynamic-dispatch/layout-64bit-scalar.slang

📝 Walkthrough

Walkthrough

Adds five new Slang shader tests and updates test expectations: tests that exercise dynamic-dispatch marshalling for 8-bit, 16-bit, 64-bit scalar, 64-bit vector, and mixed-bitwidth fields via interfaces, implementations, factories, and single-thread compute kernels with inline CHECK validations.

Changes

Cohort / File(s) Summary
Dynamic Dispatch — 8-bit vectors
tests/language-feature/dynamic-dispatch/layout-8bit-vectors.slang
New test: adds I8BitVec, implementations (Vec4i8Impl, Vec2u8Impl, Vec3i8Impl), make8BitVec, outputBuffer/kindBuffer, and a kernel verifying 8-bit packing/marshalling (sums/first elements, CHECKs).
Dynamic Dispatch — 16-bit vectors
tests/language-feature/dynamic-dispatch/layout-16bit-vectors.slang
New test: adds I16BitVec, implementations (Half4Impl, Int16_2Impl, Uint16_3Impl), make16BitVec, outputBuffer/kindBuffer, and a kernel validating 2-byte alignment and packing for 16-bit vectors (CHECKs).
Dynamic Dispatch — 64-bit scalars
tests/language-feature/dynamic-dispatch/layout-64bit-scalar.slang
New test: adds IValue with DoubleImpl/Int64Impl/Uint64Impl, makeValue, and a kernel that verifies splitting/reconstructing 64-bit scalars into two uint32 fields with 8-byte alignment (CHECKs).
Dynamic Dispatch — 64-bit vectors
tests/language-feature/dynamic-dispatch/layout-64bit-vector.slang
New test: adds IVec with double2 and vector<int64_t, 2> implementations, makeVec, and a kernel validating element-wise marshalling for 64-bit vector fields and repeated reads (CHECKs).
Dynamic Dispatch — Mixed bit-widths
tests/language-feature/dynamic-dispatch/layout-mixed-bitwidths.slang
New test: adds IMixed with MixedImpl (fields: int8_t, half, float, double, uint8_t) and SimpleImpl, makeMixed, outputBuffer/kindBuffer, and a kernel checking alignment transitions and mixed-field marshalling (CHECKs).
Test expectations list
tests/expected-failure-via-glsl.txt
Appends three expected-failure entries for layout-64bit-scalar.slang.2, layout-64bit-vector.slang.2, and layout-mixed-bitwidths.slang.2 under the vk group (test list additions only).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐇
I hop through bytes both wide and thin,
pack and sum, then leap again.
A half, a double, a tiny bite,
CHECKs applaud my midnight flight — 🥕

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Add test coverage for 8/16/64-bit types and vectors in dynamic dispatch' clearly and concisely summarizes the main change—adding new test files for previously untested bit-width scenarios in dynamic dispatch marshalling.
Description check ✅ Passed The description is directly related to the changeset, explaining the gap in test coverage and detailing the specific test files added with their purposes.
Linked Issues check ✅ Passed All five test files added directly address the identified objectives from #10470: 64-bit scalars, 64-bit vectors, mixed bit-widths, 8-bit vectors, and 16-bit vectors in dynamic dispatch with proper marshalling validation.
Out of Scope Changes check ✅ Passed All changes are in-scope: five new test files for dynamic dispatch marshalling and three entries in expected-failure-via-glsl.txt correlating to the new tests. No unrelated modifications detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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 and usage tips.

github-actions[bot]

This comment was marked as outdated.

@jvepsalainen-nv jvepsalainen-nv removed the request for review from bmillsNV March 10, 2026 10:21
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (4)
tests/language-feature/dynamic-dispatch/layout-64bit-scalar.slang (1)

60-62: Use a uint64_t test value with non-zero upper 32 bits.

99 still passes if the unsigned 64-bit path is accidentally truncated to 32 bits, so this branch doesn't really prove the split/reconstruct logic for uint64_t. A power-of-two like uint64_t(1) << 40 would keep the float check exact while forcing the high word to matter.

Also applies to: 78-82

tests/language-feature/dynamic-dispatch/layout-mixed-bitwidths.slang (1)

65-70: Aggregate-only checks can miss edge-byte mispacking.

getSum() plus getDoubleVal() doesn't pin down the placement of a and e: swapping those 1-byte fields still yields 15.0. Please add at least one order-sensitive assertion for the narrow edge fields so this test can catch byte-slot placement bugs, not just gross corruption.

tests/language-feature/dynamic-dispatch/layout-8bit-vectors.slang (1)

85-89: Exercise Vec2u8Impl.getFirst() too.

The 300 sum alone won't catch a lane swap or a broken first-element extraction on the 2-byte packing path. Since getFirst() already exists, adding a CHECK: 100 here would make this case as strong as the Vec4i8Impl and Vec3i8Impl coverage.

tests/language-feature/dynamic-dispatch/layout-16bit-vectors.slang (1)

86-89: Add a first-lane assertion for Int16_2Impl.

The 10.0 sum still passes if (-10, 20) is unpacked as (20, -10), so this doesn't fully pin down the 16-bit lane layout. Writing i2.getFirst() with CHECK: -10.0 would close that gap.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: ebed0433-77e2-473b-9f3d-461d299384a0

📥 Commits

Reviewing files that changed from the base of the PR and between b389635 and ff06665.

📒 Files selected for processing (5)
  • tests/language-feature/dynamic-dispatch/layout-16bit-vectors.slang
  • tests/language-feature/dynamic-dispatch/layout-64bit-scalar.slang
  • tests/language-feature/dynamic-dispatch/layout-64bit-vector.slang
  • tests/language-feature/dynamic-dispatch/layout-8bit-vectors.slang
  • tests/language-feature/dynamic-dispatch/layout-mixed-bitwidths.slang

@github-actions github-actions bot dismissed their stale review March 10, 2026 10:23

Automated review dismissed: bot reviews must use COMMENT only, not APPROVE or REQUEST_CHANGES.

- Trim output buffer to match actual usage in layout-64bit-scalar
- Make DoubleImpl::lowBits() use bitmask consistent with Int64/Uint64
- Add highBits() to IValue interface; use uint64_t with non-zero upper
  32 bits to prove AnyValue marshalling preserves the full 64-bit value
- Remove stray -slang flag from layout-16bit-vectors dx12 test line
- Add getFirst() checks for Vec2u8Impl and Int16_2Impl to pin down
  lane ordering through dynamic dispatch
- Add getByteFields() to IMixed interface for order-sensitive assertion
  of byte-sized field placement in layout-mixed-bitwidths

Made-with: Cursor
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 4e602af2-1de4-4579-abf6-f3152f53c71d

📥 Commits

Reviewing files that changed from the base of the PR and between ff06665 and 48783de.

📒 Files selected for processing (4)
  • tests/language-feature/dynamic-dispatch/layout-16bit-vectors.slang
  • tests/language-feature/dynamic-dispatch/layout-64bit-scalar.slang
  • tests/language-feature/dynamic-dispatch/layout-8bit-vectors.slang
  • tests/language-feature/dynamic-dispatch/layout-mixed-bitwidths.slang

@jvepsalainen-nv jvepsalainen-nv added dynamic_dispatch pr: non-breaking PRs without breaking changes labels Mar 10, 2026
github-actions[bot]

This comment was marked as outdated.

@github-actions github-actions bot dismissed their stale review March 10, 2026 11:07

Automated review dismissed: bot reviews must use COMMENT only, not APPROVE or REQUEST_CHANGES.

The GLSL emitter is missing bitCast from UInt64/Int64 to Double (tracked in shader-slang#10505), causing these tests to fail when run through the CI Test Slang via glsl step. They pass with direct SPIR-V emission.
github-actions[bot]

This comment was marked as outdated.

@github-actions github-actions bot dismissed their stale review March 11, 2026 13:28

Automated review dismissed: bot reviews must use COMMENT only, not APPROVE or REQUEST_CHANGES.

- Fix dx12 flag order in layout-16bit-vectors to match repo convention
- Widen lowBits() mask from 0xFFFF to 0xFFFFFFFF to exercise full
  lower word of the two-uint32 split in layout-64bit-scalar
github-actions[bot]
github-actions bot previously approved these changes Mar 11, 2026
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Review: Add test coverage for 8/16/64-bit types and vectors in dynamic dispatch

Verdict: APPROVE

Summary

Clean, test-only PR (zero production code changes) that fills important gaps in AnyValue marshalling coverage for non-32-bit types through dynamic dispatch. All 5 test files address the coverage gaps identified in #10470.

What's tested

Test file Types covered AnyValue path exercised
layout-64bit-scalar.slang double, int64_t, uint64_t 8-byte aligned two-uint32 split/reconstruct
layout-64bit-vector.slang double2, vector<int64_t, 2> Element-by-element 64-bit vector marshalling
layout-mixed-bitwidths.slang int8_t + half + float + double + uint8_t All alignment transitions (1/2/4/8-byte) in one struct
layout-8bit-vectors.slang vector<int8_t,4>, vector<uint8_t,2>, vector<int8_t,3> Bitfield insert packing with varying element counts
layout-16bit-vectors.slang half4, int16_t2, vector<uint16_t,3> 2-byte aligned packing with even/odd element counts

Correctness checks performed

  • All CHECK values verified mathematically — sums, sign extensions, bit extractions are correct
  • Output buffer sizes match usage — no over/under-allocation in any test
  • Expected via-GLSL failure entries are correct.slang.2 suffix correctly maps to the 3rd (0-indexed) Vulkan TEST directive in each 64-bit test; 8-bit/16-bit tests correctly omitted (GLSL has extension support)
  • Render-feature flags follow conventionsint16 for 8-bit types on Vulkan (consistent with pack-any-value-8bit.slang and layout-enum-underlying-types.slang), double,int64 for 64-bit, int16,half for 16-bit
  • Float precision safe — all int values stored in float buffers are within exact representability range (< 2^24)
  • Filecheck pattern ordering is sound — sequential CHECK directives match output lines in correct order without false-positive substring collisions

Strengths

  • kindBuffer pattern: Using StructuredBuffer<int> to select implementations guarantees genuine dynamic dispatch — the compiler cannot specialize at compile time. More robust than the SV_DispatchThreadID approach in some older tests.
  • Re-read verification: Each test re-reads a previously constructed implementation after constructing others, catching potential AnyValue storage corruption.
  • Signed/unsigned coverage: Tests include negative values (int8_t(-1), int16_t(-10), int64_t(-42)) alongside unsigned, exercising sign extension paths.
  • getByteFields() in mixed test: The float(a) * 1000.0 + float(e) encoding pins down individual byte-field placement, not just aggregate correctness.
  • Backend coverage is well-chosen: DX12 only for 16-bit (sm_6_2), Metal for 8/16-bit, no 8-bit/64-bit on DX12, Vulkan with appropriate render-feature flags. All makes sense.

Minor notes (non-blocking, see inline)

  1. DoubleImpl::lowBits() tests double→int64 conversion rather than raw bit extraction — acceptable since asFloat() already validates the double round-trip
  2. Future maintainers should be aware that the float output buffer limits testable int ranges to < 2^24

Solid addition to the test suite.

@github-actions github-actions bot dismissed their stale review March 11, 2026 13:57

Automated review dismissed: bot reviews must use COMMENT only, not APPROVE or REQUEST_CHANGES.

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

Labels

dynamic_dispatch pr: non-breaking PRs without breaking changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test coverage: 8/16/32/64-bit types and vectors in dynamic dispatch

1 participant