Commit Graph

33 Commits

Author SHA1 Message Date
9b7af801d9 shader_ir: preserve sign inside lit(-V) instead of turning it into VOP3 neg(V) 2026-11-25 23:40:03 +05:30
39879ce0fd Merge main into RT-PROTON-STORY-LOAD (#984)
Merges main at 1154976d4 into the integration branch at 273b3bdf9 (merge base ece4ba5b3). 42 files conflicted;
this commit is the resolution only. Build and test repairs follow in their own commits.

Rule of resolution: where both sides added different things, both stay; where both made the same change in two
forms, main's reviewed form stays and whatever #984's form did in addition is carried into it; where the two
changed the same code for different purposes, both purposes are kept.

Xbox proxy code (runtime/shims/d3d12_xs_device.cpp, d3d12_xs_device.h, d3d12_xs.cpp, d3d12_xs_alloc_size.h,
d3d12_xs_desc_clean.h, registry.cpp):
- d3d12_xs_device.cpp is #984's file with main's differing pieces ported in: env_slot and the configurable device
  routes, XboxQueueSlotRoutes, PresentationHandler / set_presentation_handler, the console caller rule for device
  slots 61 and 74 (#383, #385), route_xbox_device_slot, slot 81 as GetFrameStatisticsX, create_host_device, the
  console-form rule for slots 25 and 56, the console list IID of #359, and the forms of queue slot 18 (#403) and
  list slot 139 (#396).
- Kept from #984: the list proxy with handle translation, queue slots 16/17 as Signal/Wait, the fence's
  completed-value mirror, the shared FrameTokenSource, PresentX through queue_present_x when no handler is
  attached (slot 30, or 32 on a queue detected as the newer layout), slots 27/53/55/57/70/71/133, the wider
  pc_resource_desc, S_OK for queue slots past the PC table.
- Dropped: #984's GetFrameEventsX and LEONIDA_XS_FRAME_EVENTS_SLOT, its second-word rule for slot 61, its
  undetected-layout rule for queue slot 18, its list IID mapping to GraphicsCommandList6; main's copy of the base
  list proxy, its null-view slot 70 and its refusing slot 133.

Proxy tests (runtime/test/xs_proxy_mock_test.cpp, device_proxy_test.cpp, queue_proxy_test.cpp):
- Checks of both sides, each run once; main's forms of the render-target size and layout checks with #984's extra
  cases added; main's --env-slots-74 and #984's --env-slots-70.
- Adapted to the merged code: the queue tail answers S_OK, slot 73 answers an unknown IID with the list proxy,
  the queue slot 18 case installs a console caller. Dropped: #984's slot 81 GetFrameEventsX cases.

D3D12/Vulkan layer (runtime/shims/d3d12_com.cpp, d3d12_vulkan_device.cpp, runtime/src/command_list.h,
frame_pacer.h, shader_library.h, vulkan_backend.h, vulkan_replay.h, runtime/test/command_list_test.cpp,
d3d12_close_parity_test.cpp, d3d12_execute_indirect_validation_test.cpp, replay_texture_barrier_test.cpp,
vk_pipeline_check.cpp, vk_test_device.h):
- Resource::create_texture: #984's title images (deferred placed, pending streamed, title pool) and main's
  ordinary textures (#1413 shared blocks, #1364 staging fallback) are exclusive branches chosen by the texture's
  origin, so both pools run on disjoint sets of textures.
- frame_pacer.h is main's pacer (#402) with #984's FrameTokenSource as the token counter.
- main's forms kept for ExecuteIndirect (#1066, #377), the barrier into LAYOUT_UNDEFINED (#1055), the B4G4R4A4
  stand-in, per-face stencil masks, the unaligned tile staging (#528) and the device-lost flag (#980).
- shader_library.h: main's block inflate; #984's `bulk` parameter now defaults to true so main's callers keep it.
- Dropped: #984's B8G8R8A8 stand-in for B4G4R4A4 targets, its refusal of separate stencil masks, its zero-count
  refusal in ExecuteIndirect, its wider UNDEFINED -> UNDEFINED release and the test case for it.

Other shims (runtime/shims/dstorage.cpp, file_system.cpp, gameinput.cpp, xgameruntime_offline.cpp,
runtime/test/xgameruntime_offline_test.cpp, xmem_test.cpp):
- ReadFile and DirectStorage reads: #984's pinned kernel_writes read, then main's touch_pages retry on
  ERROR_NOACCESS. main's rt::fs::read_file is folded into #984's read_file.
- gameinput: main's strict LEONIDA_INPUT_SCRIPT parser with #984's rsup/rsdown entries.
- Speech synthesis: main's one silent voice and handle checks; #984's accept-anything form dropped.

Build, tools, docs (runtime/CMakeLists.txt, runtime/cmake/translator_deps.cmake, scripts/build_runtime.ps1,
make_game.py, tools/rdna2spirv.py, shader_disasm.py, shader_ir.py, shader_library.py,
runtime/test/shaders/cs_imgload_tfe.asm, cs_imgload_d16_tfe.asm, docs/README.md, boot.md, d3d12_vulkan.md,
runtime/README.md):
- Unions of the test, target and source lists; spirv_loop_guard.py added to translator_deps.cmake.
- rdna2spirv.py: main's DPP compare rule (#957), SMEM vcc base (#647) and widen_wave64_masks (#1021); #984's
  restore_skipped_instructions and restore_dot4_inline_sel. #984's duplicate widen_wave64_valu_masks dropped.
- shader_disasm.py and shader_ir.py: main's structure with #984's one-line-per-dword llvm-mc input and wave flags.
- shader_library.py: main's structure with #984's --compute-hashes and per-state compute variants.

One file that did not conflict is changed here: tools/rdna2_decode.py. Git kept both sides' decoders for a VOPC
compare with a DPP operand, and #984's narrower one shadowed main's; it is main's file again.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-24 19:38:04 -05:00
273b3bdf9d [integration] Linux/Proton and native Windows: boot through the story load (RT-PROTON-STORY-LOAD)
One squashed commit of a fork that was developed on a Linux/Proton machine and
tested on two native Windows machines. On all of them the retail 1.0.2.1
package now launches, shows its launch movie, first-run pages and landing
prompt, runs the story load to its end with the loading slideshow drawing its
artwork, and enters the world phase. A first world frame is not verified yet.
docs/linux_proton.md has the setup, a healthy boot's timeline, the machines
and where it stops.

Runtime: frames in the title's own window; DirectStorage pinned reads,
page-list scatter/gather, BCPack and unshuffle with a locally generated
predictor file; pooled, device-local and deferred image backing for streamed
and placed textures; enhanced barriers into LAYOUT_UNDEFINED; a bindless table
that degrades instead of refusing a submission; a descriptor hash finalizer
(off until a library carries it); directly indexed heap offsets for compute
dispatches and VS/PS/GS draws; title buffer windows outside a fragmented
arena; opt-in device-local copies of streamed buffer views; write-fault
retries under the tracker lock, shared trackers and write-watched title memory
for native Windows; device-loss, compute-input and memory probes.

Translator: loop bounds at structured exits, the eight FidelityFX programs
that use a packed-dot form the disassembler skips, buffer bounds modes per
view kind, a compaction option, the hash finalizer option.

Tools and scripts: Linux boot scripts (Wine/Proton, no network), a Windows
boot script, the paired compute translation script.

No game data. AI-assisted (Claude Code and Codex agents), reviewed and booted
by people on the machines named in docs/linux_proton.md.

Co-authored-by: Plaaasma <47513553+Plaaasma@users.noreply.github.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-24 11:42:12 -06:00
2f5b49c4e0 rdna2spirv: re-anchor from llvm-mc's own offsets of the rejected words
After undecodable words, translate() put each printed instruction back at its
blob offset by searching forward for its printed bytes. A data word llvm-mc
printed as a copy of a later instruction (printed bytes are not the bytes
read) took that later instruction's place, and every instruction after it
lost its place: "undecodable words (cannot re-anchor)".

shader_ir.parse_file now reads the byte offset of each rejected word from the
llvm-mc messages (shader_disasm.py feeds one line of "0xNN " bytes, five
characters a byte) as info["invalid_at"]. When there is one offset per
rejected word, the translator skips exactly those words and searches nothing;
a listed word whose bytes are the next instruction is not skipped, so a
listing with wrong or hand-written messages reads as before.

On the 1.0.2.1 pipeline library, with #327's vcc-tuple decoding, 36 compute
programs that stopped at "cannot re-anchor" now translate and pass
spirv-val; none that translated before is lost.

AI-assisted (Claude Code).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-24 10:24:48 -06:00
0b69f14d03 rdna2spirv: an f64 literal's printed width picks the one-dword rule
A literal source is one ISA dword (bits 63:32 of the constant) only when its
printed spelling fits one dword. LLVM pads nothing, so such a literal prints in
at most 8 hex digits; a 16-digit spelling is the whole binary64 value. The
magnitude check from the previous commit read 0x0000000012345678 as the high
word 0x12345678 instead of the low one, and tools/f64_diff.py's CPU reference
made the same mistake, so a generated program could agree with the translator on
the wrong operand.

tools/shader_ir.py records the literal's hex-digit count next to f64_literal
(and now marks v_ldexp_f64's sources too); tools/rdna2spirv.py decides with it at
all three literal readers, and tools/f64_diff.py's read_source mirrors the rule.

Tests: tests/semantic/test_f64_literal_whole.py gains the padded-width case
(0x0000000012345678 -> low word 0x12345678, high word 0) next to the 8-digit
control, and tests/test_f64_diff.py checks the reference reads both spellings the
same way.
2026-11-23 21:26:43 +01:00
3d2185263e docs: point shader_ir at its --help usage line (#6629)
Squash-merged after diff review of PR #6629
2026-11-23 11:11:57 -06:00
513294b80b shader_ir: read LLVM 23's lit(V) operand as the constant V (#6808)
Squash-merged after diff review of PR #6808 - shader_ir: read LLVM 23's lit(V) operand as the constant V
2026-11-23 09:56:26 -06:00
fb525dc819 shader_ir: split each named wait counter (#6921)
Squash-merged after diff review of PR #6921 - shader_ir: split each named wait counter
2026-11-23 09:37:57 -06:00
5660afa0bf shader_ir: speed up parse_line, split_args, and operand parsing (#5914)
Squash-merged after review of PR #5914 - shader_ir: speed up parse_line, split_args, and operand parsing (-27.1%)
2026-11-23 08:07:58 -06:00
b08703f7a8 Merge pull request #4595 from tedin7
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

# Conflicts:
#	docs/design.md
2026-11-22 23:16:15 -05:00
18f0b74a6a rdna2spirv: the code ends at the range the listing header declares, so undecodable words after the last printed instruction are caught too (review: Flyander); fspx.md: measured 20/29 2026-11-23 04:22:44 +01:00
edb22940c6 chore(shader): merge upstream main into unary binary64 literal handling
Keep the targeted regression and the intervening upstream changes together for review.
2026-11-22 23:02:05 +01:00
008b999657 Merge pull request #3213 from Leo Leahy 2026-11-22 15:15:46 -05:00
9181d44066 Merge pull request #3134 from Marco Luzzaro 2026-11-22 15:15:01 -05:00
64f178993f rdna2spirv: add binary64 round-to-integral VALU ops (SHADER-379) 2026-11-22 23:03:48 +03:00
4127c9682b shader_ir: keep offset:swizzle(...) modifiers with spaces intact 2026-11-22 16:42:37 -03:00
6c0b310f4b SHADER-584: report operand census input errors 2026-11-22 20:28:37 +01:00
53ce204ee6 fix(shader): decode literal words for unary binary64 operations
GFX10 places the separate literal dword above 32 zero bits for a binary64 source. Use the same source interpretation for reciprocal, square root and exponent decomposition so literal and register-pair forms produce the same color.
2026-11-22 19:32:46 +01:00
d672b19212 Merge pull request #2057 from Vonsek 2026-11-22 11:41:18 -05:00
3e384c2c86 fix(shader): place f64 literal words in the upper half
RDNA2 reads the literal dword of a double as its high word. Preserve LLVM's distinction between a printed literal and an inline integer so conversions and adds receive the encoded value.
2026-11-22 16:48:29 +01:00
bda17759e4 rdna2spirv: VCCTuple scalar lists, src_scc, and image_atomic a16 (FSPX) 2026-11-22 16:26:36 +01:00
aedd73ba37 shader_ir: precompile operand patterns and take plain registers first
operand() runs once per operand of every instruction of every shader. It called re.fullmatch with string
patterns (a cache lookup each time), and a plain register like v3 or s12, the commonest operand, only matched
after failing neg(...), abs(...) and sext(...).

- The 11 patterns are compiled once at module level (the same regex text).
- A token that is a single register (s or v, then digits) returns the same dict _REG builds, before the
  neg/abs/sext forms it can't match.

parse_line over the 2,512 lines of tests/semantic/fixtures/disasm: identical output on every line and on 34
edge tokens; 12.9 -> 8.6 us per line (34% faster).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 12:48:15 +00:00
f698bf2206 tools: a path outside the console's code page no longer crashes a tool's output
On Windows a redirected stdout uses the console's ANSI code page, and python -I ignores PYTHONUTF8 and
PYTHONIOENCODING, so a caller path with a character outside that code page ended a run with
UnicodeEncodeError as soon as a tool printed it. #1406 fixed make_game.py; every CLI tool in tools/ now starts
its __main__ block the same way (stdout errors="replace").

tests/test_tool_stdout_encoding.py checks every tool's __main__ block and reruns two measured crashes
(analyze_4240_full.py, meshlet_page.py) with a private-use-named input. Found by @abilliontokens.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 11:27:00 +00:00
103eeead1d shader_ir: apply the limit only to regular shader files 2026-11-22 05:03:24 -03:00
2ff3e89ee4 Merge pull request #1002 from bbareth 2026-11-22 01:08:17 -05:00
abac6d1572 shader_ir.py: a tab after the mnemonic keeps the destination register
parse_line() split the mnemonic from its operands at the first space, so
"s_mov_b32<TAB>s3, 1" made "s_mov_b32\ts3," the opcode and dropped s3 from
the operands. The split is now on any whitespace.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 06:35:47 +01:00
b7905794d0 shader_ir: preserve VOP3 FP abs/neg modifiers on constant operands
Keep VOP3 FP source modifiers (neg(...), |...|, -|...|, abs(...), and nested combinations) as abs/neg flags on imm and fimm operands instead of applying two's-complement integer negation or folding outer '-' before FAbs, matching LLVM AMDGPUInstPrinter::printOperandAndFPInputMods.

Plain signed numeric literals (-1, -1.0, 0x10) keep their existing dict layout. Also handle -0x... inside modifiers, preserve abs on sext(...), and apply abs then neg in tools/shader_meta.py::_imm_u32.

Verified on CPU with tests/test_shader_ir.py, tests/test_shader_meta.py, tests/test_cpu_ref.py, tools/f32_fuzz.py and the full tests/semantic suite (1,027 tests).
2026-11-22 01:09:48 -04:00
f15ce71faf BUILD: parse leading-zero decimal immediates in shader_ir 2026-11-21 21:16:15 -06:00
025a0ffecf shader_ir.py: parse arguments with argparse instead of indexing sys.argv
Run with no arguments it stopped with IndexError, `--limit x` with ValueError, and a missing path or a file
where a folder was expected with a traceback from os.listdir. It now has a usage line: src must be a folder,
and --limit takes a whole number of at least 1. The documented `shader_ir.py <dir> [--limit N]` form is
unchanged.

Tests: CliInputTest in tests/test_shader_ir.py.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 02:36:38 +03:00
957dfb24bd Fix: stop dropping first instruction in shader_ir.parse_file on LLVM 21+ and un-xfail vcc_half test
- shader_ir.parse_file() unconditionally skipped lines[0] as a comment header,
  while tests/conftest.py wrote raw llvm-mc stdout without a header line.
- On LLVM 14/18/19, llvm-mc emitted a leading '.text' directive on line 0 so
  lines[1:] skipped '.text'. On LLVM 21/22, llvm-mc stopped emitting '.text',
  causing parse_file() to drop the first instruction (s_mov_b64 exec, -1 in
  test_wave64_bfm64_and_half_cmp_emit_wave_ops's vcc_half shader), which left
  g.wave64 = False and made s_bcnt1_i32_b32 count both halves.
- Only skip lines[0] in parse_file() when it is not an instruction line, skip
  assembler '.' directives (like '.text'), prepend a synthetic header in
  tests/conftest.py, and restore the strict assert in tests/test_translate.py.
2026-11-21 16:17:58 -03:00
95447e081e Translator: mesh and geometry shaders, SCC from scalar ALU, general buffer format stores, more CS ops
- Mesh shaders -> VK_EXT_mesh_shader: PSV0 limits/topology/group size, v5 = workgroup index, s3 = wave
  id << 24, NGG exports staged per thread and written after OpSetMeshOutputsEXT (GS_ALLOC_REQ counts).
  GPU-checked (VKH_MESH mode in vk_harness).
- Geometry shaders ($GS_VoxelizeGeneric): LDS-ring inputs/outputs mapped to gl_in / staged slots,
  EMIT/CUT -> OpEmitVertex/OpEndPrimitive. GPU-checked (VKH_GS mode).
- SCC is now set by s_and/or/xor/andn2/orn2/nand/nor/xnor/lshl/lshr_b32 (result != 0),
  s_add/sub_i32 and s_addk_i32 (signed overflow), s_min/max_u32; it was left stale before. GPU-checked.
- buffer_store_format(_d16) encodes every table format (sub-dword elements via atomics); it silently
  stored nothing for most formats before. GPU-checked with vk_compute_test.
- Far branches folded; d16 buffer loads; gather4_l(_o) emulation; gather offsets; 1D/a16 image stores;
  BITMASK_PERM swizzles; f64 add/convert; i24 mul/mad, alignbyte, xnor, ffbh_i32, swap, s_abs, s_bfm,
  64-bit ordered/cmpx compares, 16-bit compares, 8/16-bit global loads, neg() operands.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 21:48:58 -05:00
f1260dcfbf Shader translator: honour SDWA selects; add v_pk_fma_f16, int min3/max3, v_bfe_i32
SDWA src/dst selects were ignored, so 3,826 translated shaders passed
spirv-val but computed wrong values. Sources are now narrowed (with sext())
before neg/abs, and results placed at dst_sel per dst_unused. GPU-checked with
the new synthetic shaders in runtime/test/shaders.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 15:58:36 -05:00
db0dc8bd5e Initial commit: Leonida, build-it-yourself PC port groundwork
Shader pipeline (carve, FSSM unpack, gfx1013 disassembly, RDNA2 to SPIR-V),
asset export via rpf9-explorer's Core (submodule), PE loader and shim
skeleton, and make_game.py, which builds from the user's own copy of the game.
No game data, keys or executables are included.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 15:22:16 -05:00