Skip to content

gpu test: cs_code_base reads a constant table through the code base (code-embedded data) - #5204

Closed
searyecheesepeaceful wants to merge 3 commits into
ProjectLeonida:mainfrom
searyecheesepeaceful:fix-contract-code-embedded-data
Closed

searyecheesepeaceful wants to merge 3 commits into
ProjectLeonida:mainfrom
searyecheesepeaceful:fix-contract-code-embedded-data

Conversation

@searyecheesepeaceful

Copy link
Copy Markdown

Add a hand-written GPU fixture cs_code_base.asm for the translator contract row "Code-embedded data" (docs/design.md). One thread stores a four-word table at Xbox VA 0x880 with the code base at 0x800 and reads it back through s_getpc_b64 + s_add_u32/s_addc_u32 + s_load_dwordx4, plus one word from a second s_getpc_b64 site, so a next-instruction offset that is not the assembler's lands off the table.

vk_compute_test gains VKC_CODE_BASE to set the code base push constant (dwords 34-35), which was always 0 before; scripts/run_gpu_tests.py and runtime/test/shaders/check.py run the fixture and judge its five words. The branch changes no translator file: the bytes under test are main's translator.

Tested on main's translator: 5/5 words exact on NVIDIA GeForce RTX 5080 (Linux, driver 620.70.06) and on AMD Radeon 610M (Mesa RADV 26.2.6, Linux). Negative control, with the translator patched to drop the code base, reads the 0xEE fill in all five words.

The carry into the high half is 0 at these addresses, so the carry itself is covered only by the CPU tests.

AI-assisted.

@shdann

shdann commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested b2458f7 on Windows 11 with NVIDIA GeForce RTX 4090 (driver 32.0.16.2101) and AMD Radeon Graphics (driver 32.0.21043.5001): pass. AI-assisted.

I set VK_DRIVER_FILES to one driver per run. I set LEONIDA_W64_EMULATE=1. I built vk_compute_test in RelWithDebInfo.

py -3.14 -I scripts/run_gpu_tests.py --build E:/Leonida-review-work-build/RelWithDebInfo --work E:/Leonida-review-work-build/gpu --filter cs_code_base --require-pass

The shader passed spirv-val. Each GPU returned the five expected words: CAFE0F00 1234ABCD 5EED0001 9E3779B9 9E3779B9.

For the control, I built vk_compute_test from parent 3faac55. I ran the same SPIR-V file with VKC_CODE_BASE=0x800 and VKC_OUT_WORDS=552. Both GPUs returned EEEEEEEE in all five positions. This check covers the low code-base word.

@soldsawn

Copy link
Copy Markdown

Independent Windows 11 GPU check at exact head \�2458f7c7568478317c6caf0640b9700c80c443c\ (GPU: NVIDIA GeForce RTX 4060 Laptop GPU, driver \32.0.16.1714; claim: #5156 (comment)):

  • Built \�k_compute_test\ (\RelWithDebInfo, MSVC 2022) and ran \python -I scripts/run_gpu_tests.py --build runtime/build --filter cs_code_base --require-pass:
    • \1 shaders: 1 translated, 1 pass spirv-val\
    • \PASS cs_code_base 5/5 words exact\ (1/1 passed).

Synthetic fixtures only, no game data. AI-assisted.

@Kam471 Kam471 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.

Built and ran at b2458f7c7 on Windows 11, RTX 5070 Ti: run_gpu_tests.py --filter cs_code_base -> 1/1 passed, cs_code_base -> 5/5 words exact; translator 1/1 + spirv-val; git diff --check clean.

The fixture reads a constant table embedded in the shader's own code (at Xbox VA 0x880) through the code base, which is how the game's shaders reach code-embedded data; the runner and check.py expect the five words. This pins the code-base path separately from the per-stage user-data slots. No blocking issue.

@Atomic258

Copy link
Copy Markdown
Contributor

Independent check — PASS (Windows 11, NVIDIA RTX 5090, driver 617.42, Vulkan SDK 1.4.363.0).

run_gpu_tests.py --filter cs_code_base: 1/1 — 5/5 words exact. The compute fixture reads the code-embedded constant table through the code base end-to-end (PR also adds the vk_compute_test.cpp plumbing for it).

Note: this is a coverage fixture — the underlying code-base feature is already on main (#5128 lineage), so the value is locking code-embedded-data reads into the GPU regression suite.

AI-assisted (Devin); no game files.

@justr4mzi

Copy link
Copy Markdown
Contributor

Tested b2458f7c on Windows 11 (build 26200.9974), AMD Radeon RX 6700 XT (driver 26.11.2, Vulkan SDK 1.4.363.0, llvm-mc 21.1.8, MSVC 19.44.35230.0, RelWithDebInfo):

GPU checks (RX 6700 XT, LEONIDA_VK_VALIDATION=1): pass

  • python -I scripts/run_gpu_tests.py --build ... --filter cs_code_base --require-pass:
    • standard -> 1/1 passed (5/5 words exact)
    • LEONIDA_VK_VALIDATION=1 -> 1/1 passed (5/5 words exact, 0 validation errors)
    • LEONIDA_PC_TAIL_UBO=1 + LEONIDA_VK_VALIDATION=1 -> 1/1 passed (5/5 words exact, 0 validation errors)
  • python -I scripts/run_gpu_tests.py --build ... --filter cs_w32 --require-pass (VAL=1) -> 13/13 passed.
  • Direct VKC_CODE_BASE control on compiled cs_code_base.spv (VKC_OUT_WORDS=552): VKC_CODE_BASE=0x800 -> 3405647616 305441741 1592590337 2654435769 2654435769 (CAFE0F00 1234ABCD 5EED0001 9E3779B9 9E3779B9); VKC_CODE_BASE=0 -> all 4008636142 (0xEEEEEEEE); VKC_CODE_BASE=bogus -> exit 2.

Regression found in tests/test_shader_checks.py: 14 failures / 79 tests

python -I tests/test_shader_checks.py fails 14/79 (Wave64Checks: test_ballot_mismatches_and_harness_errors_fail, test_emulated_wave64_runs_without_a_64_wide_subgroup, test_fmt_1010102_child_env_is_private, test_fmt_1010102_compares_the_whole_dump, test_full_wave_checks_pass_with_expected_results, test_wave32_only_device_skips_full_wave_checks):

  1. runtime/test/shaders/check.py:1561 adds the standalone cs_code_base compute_test(...) case (bumping check.main() total from 188 to 189), while TOTAL in tests/test_shader_checks.py:34-39 still adds + 13 (= 188) instead of + 14.
  2. Wave64Checks.run_checks's mock harness (tests/test_shader_checks.py:62-105) does not handle name == "cs_code_base" (checking VKC_CODE_BASE / VKC_OUT_WORDS and returning CODE_BASE_WORDS, like cs_heap_init and cs_user_sgprs above it), so cs_code_base receives "0 mismatches\n", fails inside run_checks (155 of 189 pass, 33 skipped), and causes every Wave64Checks assertion to fail.

Other Python/hygiene checks passed: test_run_gpu_tests.py (41/41), test_ctest_registration.py (4/4), test_docs_*.py (30/30), check_no_game_data.py (0), git diff --check (0).

AI-assisted (Gemini, Antigravity).

@searyecheesepeaceful

Copy link
Copy Markdown
Author

Tested b2458f7 on Intel UHD 630 (CFL GT2, subgroup 8..32): run_gpu_tests.py --filter cs_code_base with LEONIDA_VK_DEVICE=Intel passes, "PASS cs_code_base 5/5 words exact", and a nonexistent device name fails with "no Vulkan physical device matches". Dispatching it directly with VKC_CODE_BASE=0x800 VKC_OUT_WORDS=552 prints out[0..7] = 3405647616 305441741 1592590337 2654435769 2654435769 4008636142 4008636142 4008636142, the five expected words (0xCAFE0F00, 0x1234ABCD, 0x5EED0001, 0x9E3779B9, 0x9E3779B9) followed by the 0xEEEEEEEE fill. The full suite gives 155/218 passed, 61 skipped, with FAIL cs_fmt_int_narrow and cs_signed_zero_nan, and tests/test_run_gpu_tests.py passes (41 tests). A run with the code base unset and a negative control on the translator were not part of this check.

AI-assisted.

@dandasma

Copy link
Copy Markdown
Contributor

Tested b2458f7c on main 3faac55 on an AMD Radeon RX 9070 (RDNA4, discrete), AMD driver 26.10.1, Windows 11: pass, cs_code_base 5/5 words exact; whole suite 203/218, 15 skipped (same skips as main). Runtime-side negative control: the same fixture run with main's vk_compute_test (no VKC_CODE_BASE) reads 0xeeeeeeee in all five words.

AI-assisted (Claude Code).

@lunarminus

Copy link
Copy Markdown

Tested b2458f7c merged onto d0835dd9 (an older main commit) on an AMD Radeon 760M (RDNA3 iGPU, gfx1103, subgroup 32..64), RADV Mesa 26.3.1, CachyOS Linux: fail. The GPU checks pass; tests/test_shader_checks.py fails 14/79.

d0835dd9 is an ancestor of the PR's parent 3faac557, so the merge fast-forwarded and the tree tested is exactly b2458f7c.

  • Build: rebuilt runtime/ (RelWithDebInfo) with the PR's vk_compute_test.cpp; it builds cleanly.
  • Full GPU suite (scripts/run_gpu_tests.py): native 203/218 passed, 15 skipped, and LEONIDA_W64_EMULATE=1 203/218 passed, 15 skipped. Neither mode has a FAIL. The new fixture gives PASS cs_code_base 5/5 words exact in both.
  • Per-test comparison with d0835dd9 without the PR (196/210, 14 skipped, both modes): no test changed its PASS/FAIL/SKIP result.
    • Eight tests are new: cs_code_base (this PR); cs_smem_sconst_off, ps_far_branch, ps_sample_c, ps_sample_c_b, ps_texture_b_cl and ps_texture_cl (PASS); and ps_m2_literal (SKIP).
    • The last seven come from main between d0835dd9 and 3faac557. Against a control run on 3faac557 (202/217, 15 skipped, both modes), the only difference is the added cs_code_base PASS.
  • Direct dispatch of cs_code_base.spv (native and --wave64-emulate SPIR-V):
    • VKC_CODE_BASE=0x800 VKC_OUT_WORDS=552 prints out[0..7] = 3405647616 305441741 1592590337 2654435769 2654435769 4008636142 4008636142 4008636142 (CAFE0F00 1234ABCD 5EED0001 9E3779B9 9E3779B9, then the EEEEEEEE fill).
    • VKC_CODE_BASE=0 gives all 4008636142, and VKC_CODE_BASE=bogus exits 2.
    • 3faac557's vk_compute_test, which has no VKC_CODE_BASE, also gives all 4008636142 with VKC_CODE_BASE=0x800.
  • Python tests that pass: tests/test_run_gpu_tests.py 41/41, tests/test_ctest_registration.py 4/4, all 10 tests/test_docs_*.py, tests/test_check_no_game_data.py 5/5; git diff --check is clean.
  • Regression, reproducing @justr4mzi's report: python -I tests/test_shader_checks.py fails 14 of 79 (all in Wave64Checks). The same file passes 79/79 at 3faac557 and 75/75 at d0835dd9. Two causes:
    • TOTAL in tests/test_shader_checks.py:34-39 still adds + 13, so it expects 188 cases while check.main() now runs 189.
    • The mock harness has no cs_code_base branch, so it returns "0 mismatches" and the check fails. The output reads 184 of 189 pass, 3 skipped, or 155 of 189 pass, 33 skipped in the emulated case.
    • Adding a cs_code_base branch to the mock (checking VKC_CODE_BASE/VKC_OUT_WORDS and returning CODE_BASE_WORDS) and bumping TOTAL by one should fix it.

Synthetic fixtures only, no game files. AI-assisted (Claude Code).

@searyecheesepeaceful

Copy link
Copy Markdown
Author

Thanks @justr4mzi and @lunarminus. Both causes you named were real: TOTAL in tests/test_shader_checks.py still added 13 after this PR added cs_code_base to check.main(), and the mock harness in Wave64Checks.run_checks had no cs_code_base branch, so the fixture got a failing dump.

5c98cae counts the fixture and adds the branch. The branch returns the five table words only when the call carries the VKC_CODE_BASE and VKC_OUT_WORDS values from CODE_BASE_ENV, so the mock still checks that check.py passes the code base.

I also merged main (merge commit 5efc84b). Two conflicts: the TOTAL line, where main added cs_fmt_all and this PR cs_code_base, so it is now + 15; and the Code-embedded data row in docs/design.md, where main's new fall-through paragraph is kept and the cs_code_base GPU note follows it.

python3 -I tests/test_shader_checks.py: 14 failures of 79 tests at b2458f7, 82 tests OK at 5efc84b (main added three). Each of these edits makes it fail again at 5efc84b: dropping env=CODE_BASE_ENV from the cs_code_base call in check.py (14 failures), TOTAL left at + 14 (13 failures), the harness branch keyed on a misspelled cs_codebase (14 failures), and VKC_CODE_BASE passed as 0x400 instead of 0x800 (14 failures). At 5efc84b the semantic tests (python3 -I -m unittest discover -s tests/semantic) pass 6150 tests, tests/test_run_gpu_tests.py 47 and tests/test_ci_registration.py 14. These are CPU-only runs; the merge changes nothing the GPU fixture runs.

AI-assisted.

@Nithin1777

Copy link
Copy Markdown

Tested 5efc84b9692a6e236003d1555919368d076bd579 on an NVIDIA GeForce RTX 3050 6GB Laptop GPU, NVIDIA driver 620.70.06, Bazzite 45 (Kinoite). The targeted GPU test passed.

  • LEONIDA_VK_DEVICE=3050 python3 -I scripts/run_gpu_tests.py --build ../build --work ../gpu-run --filter cs_code_base --require-pass — 1/1 passed, with all five readback words matching exactly. The generated SPIR-V passed Vulkan 1.2 validation.
  • python3 -I tests/test_shader_checks.py — 82/82 passed.
  • python3 -I tests/test_run_gpu_tests.py — 47/47 passed.

I built the three Vulkan test harnesses with GCC 16.2.1 and the Vulkan headers pinned by the project. The run used only the synthetic fixture and was AI-assisted with Codex.

@LukeOsland1

Copy link
Copy Markdown
Contributor

Tested 5efc84b969 on Windows 11 build 26300, NVIDIA RTX 4070 Ti SUPER, driver 610.88. I used the PR’s GPU runner with LLVM 23.1.6 and the MSVC-built harness from the tested sources. The Vulkan loader was restricted to the NVIDIA ICD.

  • cs_code_base — 5/5 words exact.

Xbox 1.0.2.1 coverage: 25,706 of 26,503 local shaders.rpf listings contain at least one of the following mnemonics. Static instruction counts (combining e32/e64 spellings): s_getpc_b64 5,581, s_load_dwordx4 930,037. The counts describe opcode presence. The GPU readback above uses the hand-written fixture. AI-assisted with Codex.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.