shader: run translated compute shaders on the CPU in tests (opt + lli) #62
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/uiliannn--VItoriaBr!62
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-62"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@lcg007xd-c on GitHub · 2026-11-25 21:26 UTC · original
lcg007xd-c:shader-cpu-exec→main· +1068 −1 · 2 files · 4 commits · openWhat this adds
Today a lowered instruction's arithmetic is only checked by
valu_tests.rs, which needs Windows, a GPU (or WARP) anddxil.dll. On Linux, the tests can only see that a program translates, not what it computes.The DXIL in a translated container is LLVM bitcode, so LLVM's own tools can run it on the CPU:
opt -data-layout=<host> -mtriple=x86_64-unknown-linux-gnureads the DXIL bitcode and retargets it (DXIL's pointers are 32 bits).llvm-linkadds a small IR runtime (theRUNTIMEstring incpu_tests.rs) that defines thedx.opintrinsics these programs call: handles,cbufferLoadLegacy,rawBufferStore,unary/binary/tertiaryfloat ops, bit scans,dot4AddPacked, f16 conversions, thread ids. An opcode it does not know stops the run and names the opcode.lliruns it, and the test reads back the UAV dwords the shader stored.The change
emit/cpu_tests.rs(new,#[cfg(test)]): programs have the same shape asvalu_tests.rs'build_valu_cs. Four root constants arrive ins0..s3and are copied tov1..v4, the body leaves its result inv0, andv0is stored to dword 0. So an expectation written for the CPU also holds for the GPU tests, and the reverse.expect(name, body, &[(inputs, want)])is all a new case needs.fptosi/fptouibecomesllvm.fpto[su]i.sat. In LLVM IR an out-of-range conversion is poison (x86 gives0x80000000). In DXIL it has D3D's meaning, which the translation relies on (see the comment atv_cvt_i32_f32): it saturates, and NaN gives 0.VICTORY_LLVM_BIN, thenPATH, then the newest/usr/lib/llvm-N/bin(Debian/Ubuntu layout). If they are missing, or on a host other than x86-64 Linux, each test reportsVICTORY TEST SKIPPED: …throughtest_skip, and fails underVICTORY_STRICT_TESTS=1.test_skipis now compiled on every host (it wascfg(windows)).xtaskadmits only listed text extensions) is unchanged.First cases (all pass on main)
Float add/mul/clamp/neg, integer add/shift/
mul_hi/bfe/med3,v_ffbh_u32/v_ffbl_b32/v_ffbh_i32(including 0 and −1),v_cvt_i32_f32/v_cvt_u32_f32(saturation and NaN),v_rndne_f32ties,v_cvt_f16_f32rounding to nearest even (and overflow to inf), andv_med3_f32with NaN. The NaN cases are copied fromvalu_tests.rs' hardware cases. It also covers the packed dot products, including #44'sv_dot8_i32_i4cases and clampedv_dot4_i32_i8saturating both ways.It catches wrong lowerings. I changed
v_bfe_i32to extract unsigned, andinteger_operations_compute_what_they_shouldfailed:v_bfe_i32 case 0 [abcd1234, 0000001c, 00000004, 00000000]: got 0x0000000a, want 0xfffffffa.What this cannot check
v_fma_f32(documented as a shortcut to FMad) is not checked here.valu_tests.rs.Tests run (Linux, Rust 1.98.1, LLVM 23.1.5)
cargo test -p victory-shader --lib --locked: 198 passed, 0 failed, 2 ignored (11 of them new).VICTORY_LLVM_BIN=/nonexistent, the CPU cases printVICTORY TEST SKIPPED: LLVM's opt, llvm-link and lli were not found (set VICTORY_LLVM_BIN); CPU run skipped.-p victory-core -p victory-pe -p victory-pipeline -p victory-shader -p victory-formats -p victory-game -p xtask --all-targets -- -D warnings): clean.CARGO_FEATURE_PURE=1 cargo clippy -p victory-shader --all-targets --target x86_64-pc-windows-msvc -- -D warnings: clean.Not run here: Windows itself, where these tests skip by design. I also did not check whether the GitHub Ubuntu runner has
/usr/lib/llvm-N/bin. If it does, the Linux CI job runs these cases; otherwise they skip there.🤖 Generated with Claude Code
@lcg007xd-c on GitHub · 2026-11-25 22:41 UTC · original
Added a third commit: the runtime now also defines
MakeDouble/SplitDoubleand the f64Fma/DMax/DMin, so translations that compute in doubles run on the CPU too (used to check #99's f64 arithmetic). Tests:cargo test -p victory-shader --lib --locked198 passed.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.