RT-NULL-BARRIER-CLEAR: console null-resource barriers and null-view clears no longer drop the submission #1504

Closed
github-bot wants to merge 32 commits from gh-pr/1504/head into gh-pr/1504/base
Owner

@⁠ubiquitarianism on GitHub · 2026-11-25 02:32 UTC · original
ubiquitarianism:fix/rt-null-barrier-clear → main · +38445 −2467 · 298 files · 31 commits · closed without merging

Claimed in the coordination issue as: RT-NULL-BARRIER-CLEAR (#14)

Depends on: #1495

The retail title makes two console command-list calls that each put the PC list into its error state. When that happens, Close fails and ExecuteCommandLists drops the whole submission. This PR handles both the way the console does.

List slot 146: Barrier, GCL7 slot 80

The console treats a texture barrier with no resource as a global barrier.

  • Null resource: the barrier is now forwarded as a D3D12_GLOBAL_BARRIER with the same sync and access words.
  • Mixed groups: a group with both kinds is split into texture, global and texture runs, in their original order. The converted barriers are built in storage that lives for the call.
  • Nothing to convert: the call is forwarded unchanged, with the title's own pointer.
  • Unreadable group array: the whole call is refused, nothing is recorded, and each reason is logged once. This covers a null pointer with a nonzero count, an unknown group type and an absurd count.

List slot 52: ClearRenderTargetView, PC slot 48

The title creates some render-target views with no resource and clears them every frame. On the console that clear does nothing.

  • Marking: the device proxy marks the real handle when CreateRenderTargetView gets a null resource.
  • Updating the marks: CopyDescriptors and CopyDescriptorsSimple of RTVs move the marks with the descriptors. A view later re-created with a resource clears the mark.
  • The clear: a clear of a marked view is skipped and logged once. Every other view keeps today's path.

The proxy keeps its own marks because the layer's descriptor state can't tell a null-resource view apart from a view it failed to create.

Known gap: RTV records that the title copies with its own memcpy are not followed.

Tests

  • Mock list: xs_proxy_mock_test now models the PC error state in its mock list, so its Close fails the way the real layer does.
  • New check_console_null_barrier_and_clear cases:
    • the null-resource barrier becomes a global barrier, and the list still closes;
    • a valid texture barrier passes through unchanged;
    • mixed groups split in order;
    • six malformed calls are each refused;
    • a null-view clear is skipped, while a real view is still cleared;
    • re-creating a view, both descriptor-copy forms, and isolation between devices.
  • Changed tests: two older slot-146 cases passed garbage words, which the new check refuses, so they now pass valid ones.

Windows 11, VS 2026, Windows SDK 10.0.26100: ctest has 310 of 312 passing. The two failures, d3d12_texture_tiles and d3d12_clear, also fail on plain main. These cases are confirmed by the mock tests only, not by a retail run. docs/d3d12_vulkan.md §4.9 records both behaviours.

**@⁠ubiquitarianism** on GitHub · 2026-11-25 02:32 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1504) `ubiquitarianism:fix/rt-null-barrier-clear` → `main` · +38445 −2467 · 298 files · 31 commits · closed without merging Claimed in the coordination issue as: RT-NULL-BARRIER-CLEAR (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14) Depends on: #1495 The retail title makes two console command-list calls that each put the PC list into its error state. When that happens, `Close` fails and `ExecuteCommandLists` drops the whole submission. This PR handles both the way the console does. ## List slot 146: `Barrier`, GCL7 slot 80 The console treats a texture barrier with no resource as a global barrier. - **Null resource:** the barrier is now forwarded as a `D3D12_GLOBAL_BARRIER` with the same sync and access words. - **Mixed groups:** a group with both kinds is split into texture, global and texture runs, in their original order. The converted barriers are built in storage that lives for the call. - **Nothing to convert:** the call is forwarded unchanged, with the title's own pointer. - **Unreadable group array:** the whole call is refused, nothing is recorded, and each reason is logged once. This covers a null pointer with a nonzero count, an unknown group type and an absurd count. ## List slot 52: `ClearRenderTargetView`, PC slot 48 The title creates some render-target views with no resource and clears them every frame. On the console that clear does nothing. - **Marking:** the device proxy marks the real handle when `CreateRenderTargetView` gets a null resource. - **Updating the marks:** `CopyDescriptors` and `CopyDescriptorsSimple` of RTVs move the marks with the descriptors. A view later re-created with a resource clears the mark. - **The clear:** a clear of a marked view is skipped and logged once. Every other view keeps today's path. The proxy keeps its own marks because the layer's descriptor state can't tell a null-resource view apart from a view it failed to create. Known gap: RTV records that the title copies with its own `memcpy` are not followed. ## Tests - **Mock list:** `xs_proxy_mock_test` now models the PC error state in its mock list, so its `Close` fails the way the real layer does. - **New `check_console_null_barrier_and_clear` cases:** - the null-resource barrier becomes a global barrier, and the list still closes; - a valid texture barrier passes through unchanged; - mixed groups split in order; - six malformed calls are each refused; - a null-view clear is skipped, while a real view is still cleared; - re-creating a view, both descriptor-copy forms, and isolation between devices. - **Changed tests:** two older slot-146 cases passed garbage words, which the new check refuses, so they now pass valid ones. Windows 11, VS 2026, Windows SDK 10.0.26100: ctest has 310 of 312 passing. The two failures, `d3d12_texture_tiles` and `d3d12_clear`, also fail on plain `main`. These cases are confirmed by the mock tests only, not by a retail run. `docs/d3d12_vulkan.md` §4.9 records both behaviours.
50 of the 2,684 library programs in shaders.rpf (1.0.2.1) start with two VOP3
opcode-0x180 words (words 0 and 3) instead of three, and their code starts at
word 6. code_range only knew the 36-byte form, so it disassembled them from
word 0 and they never decoded: 1 of the 50 translated. With the 24-byte form
all 50 disassemble with 0 invalid words and 49 translate and pass spirv-val.

AI-assisted (Claude Code).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- s_bitreplicate_b64_b32 with a VCC destination: lane L gets S0 bit L // 2,
  stored as mov64 stores a mask into VCC (EXEC already took this path).
- s_flbit_i32_b64 of a lane mask reads the wave's whole mask (wave_mask), as
  s_ff1_i32_b64 does; s_flbit_i32_i64 of a mask stays Unsupported.

Both occur in pipeline-library compute programs that the retail boot creates.
Tests: tests/semantic/test_lane_mask_bitreplicate_flbit.py runs both on every
lane of a wave64 (run_workgroup); docs/design.md contract rows updated.

AI-assisted (Claude Code).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
llvm-mc skips the first word of s_buffer_load_dwordx8 into s[100:107], an image resource in s[100:107] or a buffer resource in s[104:107] and leaves the second word as junk, so translate() refused those shaders (reachable instruction with normalized encoding) or translated them without the load. restore_vcc_tuples reads the uncovered words of the code range with rdna2_decode and keeps only instructions whose operands hold a VCCTuple list, the form the translator already takes. Other undecodable words are unchanged.
Clamp blob[at:at + 20] to min(at + 20, stop) and check at + nbytes <= stop so multi-dword NSA MIMG instructions starting near code_end cannot read trailing bytes past code_end. Adds synthetic 12-byte NSA1 regression test.
llvm-mc rejects a scalar tuple that runs into vcc and prints the second word as
junk. That junk is often longer than the word, so it also covers the instruction
after the tuple, which stayed missing and refused the program with
'fall-through into undecodable words'. The words after a restored tuple are now
decoded from the blob until the stream is back at a printed instruction.

Pipeline library of 1.0.2.1, 2,684 compute programs: 1,816 -> 2,567 translate
and pass spirv-val; the 1,816 modules are byte-identical.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
llvm-mc 21 cannot decode SMEM loads whose SOFFSET is null (0x7D), so whole
pipeline-library compute programs of 1.0.2.1 came out with invalid words
and failed to translate. For compute programs, shader_disasm now falls back
to rdna2_decode when that decodes more of the program, and rdna2_decode
reads VOPC with DPP16/DPP8 as the 8-byte form it is.

rdna2spirv:
- SMEM with vcc as its base reads the vcc_lo/vcc_hi pair.
- s_flbit_i32_b64 of a lane mask reads the wave's 64-bit mask (18 library
  programs), as s_ff1_i32_b64 already does.
- s_bitreplicate_b64_b32 of a lane mask into plain scalar data replicates
  the wave's mask word (6 library programs); into exec/vcc it stays
  Unsupported.

test_salu_flbit_64: the lane-mask case now translates (the subgroup op is
outside the single-invocation interpreter), so the test checks that.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The retail boot reached 50 pipeline-library compute programs that had no
translation. Dumped from the running game, they all translate and pass
spirv-val after these changes:

- fspx_unpack.code_range: some programs carry a 24-byte hash prologue
  (two VOP3 words, then s_inst_prefetch) instead of 36 bytes; two or three
  hash words now count (shader_library uses the same range).
- fspx_unpack --last-endpgm: early exits branch past the first s_endpgm,
  and data after the code can hold s_endpgm words, so a program ends at
  the first s_endpgm whose listing keeps every branch inside the code.
- rdna2spirv: v_cmp_*_dpp into vcc (12 compares in reductions), taken when
  every lane writes (full row/bank masks with bound_ctrl:1, or DPP8).
- rdna2spirv: s_bitreplicate_b64_b32 of a constant into vcc (6 programs),
  as the exec form does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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 <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Do not scan unreachable embedded data words skipped by s_branch or after s_endpgm / s_setpc_b64 in restore_vcc_tuples. Walk only offsets reachable from code_start via matched instructions, fall-through, and direct/folded far branches, and discard any restored instruction whose interior dwords are targeted by a reachable branch.

Fixes the synthetic edge case reported on #596 / #674 by @Snooozs where an unreachable data word equal to the first dword of an 8-byte vcc-tuple load right before a branch target caused restore_vcc_tuples to swallow the target instruction and fail with 'branch into data'.

Adds regression tests covering: skipped data word before a matched branch target, skipped data word before a vcc-tuple load at the branch target, data word after s_endpgm before a branch target, and fall-through into a data word directly before a branch target.
#596 walks only reachable offsets. The resync after a restored tuple now runs inside that walk, follows swallowed
branches, and drops the rest of a run when a branch targets an instruction's interior. decode_bytes gets the
program's wave size, so a swallowed VOP3 compare writes an SGPR pair in wave64 (reported on #674).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The run time finds a pipeline-library compute program by the SHA-256 of
its code and of its record's state blob. shader_library.py kept one
state per program, the last record's, so when two compute records used
one program with different state blobs only one of the two pairs got an
entry and a .state file.

Each distinct state of a program is now written: the first under the
program's name, each further one as <name>_state_<blob index>, with its
own .code, .json, .state, listing and index entry. library.json names
the entry of each record. A program with one state, the case of every
program in the measured 1.0.2.1 library, is written exactly as before.

--compute-hashes FILE writes only the compute programs whose code has
one of the SHA-256 digests listed in FILE, with every state they are
used with. It cannot be combined with --stages, and a digest no compute
program has is an error before anything is written.

tests/test_shader_library.py gets three tests on a synthetic library;
all three fail on the base. The standard-library tests and the
translator suite add no failing file. No retail library was read for
this change.

AI-assisted (Claude Code).

Co-authored-by: Plaaasma <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[email protected]>
The FidelityFX upscaler programs hold 89 such words in 8 programs (docs/fspx.md); the translator already models the form but the listing could not carry it, so the programs were refused as a fall-through into undecodable words.
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Conflict with #583 in tools/shader_library.py: kept #1281's per-state loop and #583's
prologue test (start > 0, so the 24-byte prologue counts too).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Conflicts resolved toward what main and #583/#593 already have: the 24-byte prologue
(#583's code_range), VOPC DPP decode and translation (main's 'DPP on a VOPC compare'),
s_bitreplicate_b64_b32 into VCC and s_flbit_i32_b64 of a lane mask (#593). Kept from
#998: code_range_last / branch_targets_inside / --last-endpgm in fspx_unpack, the
compute fallback to tools/rdna2_decode.py in shader_disasm, and s_bitreplicate_b64_b32
of a lane-mask source into scalar data.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
luizwidmer/palmetto repairs these words outside the translator with tools/widen_smem_decode.py
(the console's 112-SGPR file is wider than llvm-mc's 106). Here restore_vcc_tuples (#674)
already decodes them from the blob; these cases pin the two forms its tests did not cover:
s_buffer_load_dwordx8 into s[100:107] with an SGPR soffset and an immediate offset, and
buffer_store_dword with its resource in s[104:107]. Encodings built from the field layout.

Ported from luizwidmer/palmetto (GPL-3.0): the forms, from its docs/boot_frontier.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
llvm-mc decodes a VOP3P v_dot4_i32_i8 whose op_sel_hi is not [1,1,1] (op_sel bit 1 clear) but
prints and re-encodes it with op_sel 0 / op_sel_hi 7, so translate() refused it as a dropped
field. When those two fields are the only difference between the stored and the printed bytes,
they are now read from the blob, in check_printed_encodings and in both re-anchoring paths, and
the v_dot4_i32_i8 rule applies them as measured on gfx1036 (a non-default S2 half stays
refused). Any other difference is still refused.

Ported from luizwidmer/palmetto (GPL-3.0): its restore_vop3p_dot4. Its console_dot4_word (the
op_sel 2 / op_sel_hi 5 words llvm-mc rejects) is not ported: #1317 prints those in
shader_disasm.py. Test: tests/semantic/test_dot4_printed_op_sel.py, hand-built words.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
#998 added the rule (a 32-bit EXEC/VCC half as S0, read through Gen.wave_mask) without a test
or a design.md entry. test_lane_mask_bitreplicate_flbit.py now runs it on every lane of a
wave64 in the CPU interpreter, from exec_lo/exec_hi and from a compare's vcc_lo/vcc_hi, against
the ISA pseudocode. design.md says it is interpreter-checked only, not measured on hardware.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
41 files conflicted (about 200 hunks). Where main already had a reviewed
version of the same feature, main's was kept and only what #984 adds on
top was re-applied; what #984 adds that main lacks was taken.

- d3d12_xs_device: slot 81 stays main's GetFrameStatisticsX with the
  presentation handler (#984's frame-events slot not taken); the
  presenter routing runs before #984's internal PresentX. Slots 25/26/127
  and route_xbox_device_slot are main's (#984's null-heap check on 127
  re-applied); slots 61/74 keep main's console-caller gating; slot 73 is
  main's (console list IID answered as ID3D12GraphicsCommandList, so
  #984's d3d12_xs_command_list_iid.h is dropped). Taken from #984: the
  console list proxy (slot 12 path, upload arena, tail names), queue
  layout detection, slot 9 allocator callback, slots 55/57/70/71/86/133,
  Vulkan-backed CPU heaps, the frame token source and the lease bias.
  The lease section both sides moved is kept once.
- d3d12_vulkan_device: #984's staged/deferred title images and pool with
  main's create_image lambda and NVIDIA host-transfer retry around the
  final bind; main's B4G4R4A4 and stencil masks.
- vulkan_backend.h / vulkan_replay.h: main's structure (device-lost flag,
  mark_device_lost outside the lock) with #984's observe_result and
  unsupported_at(__LINE__).
- file_system / dstorage: #984's kernel_writes reads, main's touch_pages
  retry kept as the fallback.
- rdna2spirv / shader_disasm / shader_ir: main's DPP compares, s_load VCC
  base and widen_wave64_masks, plus #984's skipped-instruction restore and
  per-line invalid-word offsets. rdna2_decode is main's: #984's f32-only
  DPP-compare block ran before main's general one and broke its decode.
- xgameruntime_offline, d3d12_xs.cpp: main's.
- Tests: main's and #984's checks both kept, adapted to the merged
  behaviour (queue tail S_OK, fence slot 12, slot 127 mask).

Policy: executable-relative addresses that #984 quoted were removed
(docs/fspx.md, docs/movies.md, docs/embedded_shaders.md, d3d12_vulkan.md,
d3d12_xs_alloc_size.h, windows-boot scripts). The hang-watchdog kick in
main.cpp and the transient-pool dump in startup_trace.h now take their
locations from LEONIDA_TITLE_WATCHDOG_KICK / LEONIDA_POOL_DIAG_AT instead
of hard-coded RVAs; the boot script's state peeks come from
LEONIDA_GAME_STATE_RVA / LEONIDA_SESSION_STATE_RVA.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
dxgi_swapchain_count_test: main's failed-resize case passes the
diagnostics argument #984 added to VulkanSwapchain. xs_proxy_mock_test
follows the merge's choices: slot 81 is GetFrameStatisticsX (no frame
events slot 102 in the env mode), slot 73 refuses an IID it does not know
as main's did, and console queue slots the presenter does not route stay
with the queue proxy (S_OK tail) instead of E_NOTIMPL.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The merge kept main's widen_wave64_masks for wave64 lane masks; #984's
variant had no caller left.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
These failed on #984's head as well. The loop guard (spirv_loop_guard.py)
puts OpPhi into every loop, which the branch interpreter of
test_control_flow_branches did not model; it now evaluates a block's phis
together from the predecessor. spirv_mini_interp now models OpSwitch, so
it runs the emulated wave64 scheduler that the ds_swizzle and permlane16
tests expected it to reject: they now compare the 64 lanes with their
reference models.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>

# Conflicts:
#	docs/design.md
#	docs/fspx.md
#	tests/semantic/test_alu_dot4_i8.py
#	tests/semantic/test_salu_flbit_64.py
#	tests/semantic/test_vcc_tuple_fallback.py
#	tools/fspx_unpack.py
#	tools/rdna2spirv.py
#	tools/shader_library.py
List slot 146 (Barrier -> GCL7 80): a texture barrier with no resource, which
the console takes as a global barrier, is forwarded as a D3D12_GLOBAL_BARRIER
with the same sync and access; a mixed texture group is split into runs in
order, in storage that lives for the call. Calls with nothing to convert keep
the title's pointer. A group array that cannot be read safely (null with a
nonzero count, an unknown group type, absurd counts) is refused whole and
logged once per reason.

List slot 52 (ClearRenderTargetView -> PC 48): the device proxy marks the real
handle when CreateRenderTargetView gets no resource (moved by RTV descriptor
copies, cleared by a view made with a resource), and the clear of a marked view
is skipped, as on the console. Other views keep today's path.

Before this, both calls put the PC list in its error state, so Close failed and
ExecuteCommandLists dropped the submission. xs_proxy_mock_test models that
error state in its mock list and covers both paths; the two old slot-146 cases
that passed garbage words now pass valid ones.

The null-resource barrier and null-view clear behaviour were first reported by luizwidmer/palmetto.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:54:31 +00:00
github-bot closed this pull request 2026-11-26 09:54:31 +00:00
Author
Owner

@⁠aslan2142 on GitHub · 2026-11-26 03:09 UTC · original

Closing as included: #2138, merged as 0b11d86bc, carries this PR's commit 1dd7b32c1 (one line wrapped differently). It adds one fix on top: the null-RTV marks are dropped when their heap is released, so a reused address no longer keeps a stale mark (mock test added).

AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠aslan2142** on GitHub · 2026-11-26 03:09 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1504#issuecomment-7181440808) Closing as included: #2138, merged as `0b11d86bc`, carries this PR's commit `1dd7b32c1` (one line wrapped differently). It adds one fix on top: the null-RTV marks are dropped when their heap is released, so a reused address no longer keeps a stale mark (mock test added). AI-assisted (Claude Code, Claude Opus 5.5).

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.