Skip to content

shader: take a descriptor's address however many dwords the load reads - #118

Open
xiaotu030202 wants to merge 1 commit into
Zettrox:mainfrom
xiaotu030202:shader/descriptor-address-any-length
Open

xiaotu030202 wants to merge 1 commit into
Zettrox:mainfrom
xiaotu030202:shader/descriptor-address-any-length

Conversation

@xiaotu030202

Copy link
Copy Markdown

What this fixes

A descriptor read only as data — nothing uses it as a descriptor, the code just wants its address — is answered with the host's USER_VIEW_ADDRESS dwords. That path required count <= 4, so s_load_dwordx8 (8) and s_load_dwordx16 (16) were refused outright:

a descriptor read only as data

That is what five shaders in #38 hit:

shader reason in the log
2fd01fca16993001 a descriptor read only as data
6b6db9f1a526daeb same
abc6a80d46edc294 same
7d0f14ce44746d7e same
ceb5eb68cd99cb07 a descriptor's address or format read as data

Nothing about the host side needs the limit. It fills dwords 0 and 1 from the view at that table offset — draw.rs, USER_VIEW_ADDRESS, descriptor::view(table + dword * 4) — and never looks at how many dwords were read.

What changed

lower.rs — count <= 4 is gone from that branch. The rest of the load's dwords are Missing, exactly as dwords 2 and 3 already were for a s_load_dwordx4, so a program that only takes the address works at any length and one that does arithmetic on the other dwords is refused where it uses them. Same contract at 1, 2, 4, 8 and 16.

view_address also accepted only a 4-dword table entry; it now takes the console's other buffer size, 8. The address is in the same two dwords either way.

intersect_tests.rs — native/build gained dwords variants (native_with, build_with); the existing helpers call them with 4 and behave as before.

The test is checked in both directions

a_descriptor_load_of_eight_dwords_answers_with_the_address — a s_load_dwordx8 s[8:15], s[4:5], 0x0 of a table entry nothing uses, lowered, asserted to ask the host for exactly the two address dwords.

I reverted the count <= 4 line and re-ran, because a test that passes both ways is worth nothing:

before this change:  test result: FAILED. 0 passed; 1 failed
after:               test result: ok. 212 passed; 0 failed; 2 ignored

Getting there took three attempts, which is worth recording because it is the kind of mistake that produces a green test that tests nothing:

  1. First version used dwords: 8 on the existing ray-tracing test. It passed on both trees — that program's descriptor is used, so it never reaches the branch.
  2. Second version wrote s_load_dwordx8 as 0xF408_03C2. The decoder read it as s_load_dwordx4; the test passed on both trees again, for a different wrong reason.
  3. Third version: the opcode sits in the low dword — 0xF40C_0202 for x8 s[8:15] from s[4:5], with 0xFA00_0000 as the offset word. An eprintln on the branch confirmed count=8 reached it before I trusted the result.

Verification

Windows 11, RTX 5070 Ti, Rust 1.98.1 (pinned), MSVC 14.44.35207, Windows SDK 10.0.26100.0, VICTORY_DXIL set. No game files.

$ cargo test -p victory-shader --lib -- --test-threads=1
test result: ok. 212 passed; 0 failed; 2 ignored

$ cargo clippy -p victory-shader --all-targets
clean

$ cargo xtask policy
asset policy: 172 files ok

What is not claimed

I have not seen those five shaders translate. What is established: the length is no longer a reason to refuse, the address path is exercised at 8 by a test that fails without the change, and 212 tests pass. Whether each of the five now lowers, or stops at a later and real limit, is something victory translate --list over shaders.rpf would say — and that needs game files.

Same for the dwords == 8 half: the address path works with it, nothing in the corpus has been run.

If someone can run the census on this branch and paste the refusal list, that turns "no longer refused for this reason" into a number — and if those five move to a different reason, that reason is the next thing worth looking at.

A descriptor read only as data — nothing uses it as a descriptor, the code
just wants its address — is answered with the host's `USER_VIEW_ADDRESS`
dwords. That path required `count <= 4`, so `s_load_dwordx8` (8) and
`s_load_dwordx16` (16) were refused outright:

    a descriptor read only as data

That is what five shaders in Zettrox#38 hit (`2fd01fca16993001`, `6b6db9f1a526daeb`,
`abc6a80d46edc294`, `7d0f14ce44746d7e`, and `ceb5eb68cd99cb07` with the
"address or format" wording). Nothing about the host side needs the limit: it
fills dwords 0 and 1 from the view at that table offset
(`draw.rs`, `USER_VIEW_ADDRESS`, `descriptor::view(table + dword * 4)`) and
never looks at how many dwords were read.

The rest of the load's dwords are `Missing`, exactly as dwords 2 and 3
already were for a `s_load_dwordx4`. So a program that only takes the address
works at any length, and one that does arithmetic on the other dwords is
refused where it uses them — the same contract at 1, 2, 4, 8 and 16.

`view_address` also accepted only a 4-dword table entry; it now takes the
console's other buffer size, 8. The address is in the same two dwords either
way, and the host does not read the entry's length.

## The test, and how it was checked

`a_descriptor_load_of_eight_dwords_answers_with_the_address` is a
`s_load_dwordx8 s[8:15], s[4:5], 0x0` of a table entry that nothing uses,
lowered and asserted to ask the host for exactly the two address dwords.

It **fails on the code before this change** and passes after — I reverted the
`count <= 4` line and re-ran to confirm that, because a test that passes both
ways is worth nothing:

```
before:  thread panicked ... test result: FAILED. 0 passed; 1 failed
after:   test result: ok. 212 passed; 0 failed; 2 ignored
```

Getting there needed the SMEM encoding right on the first try, which I did not
manage: my first attempt was decoded as `s_load_dwordx4` and the test passed
on both trees for the wrong reason. The opcode sits in the low dword
(`0xF40C_0202` for `x8` s[8:15] from s[4:5]; the `0xFA00_0000` word is the
offset). An `eprintln` on the branch confirmed `count=8` reaches it before I
trusted the test.

## Verification

Windows 11, RTX 5070 Ti, Rust 1.98.1 (pinned), MSVC 14.44.35207, Windows SDK
10.0.26100.0, `VICTORY_DXIL` set. No game files.

```
$ cargo test -p victory-shader --lib -- --test-threads=1
test result: ok. 212 passed; 0 failed; 2 ignored

$ cargo clippy -p victory-shader --all-targets
clean

$ cargo xtask policy
asset policy: 172 files ok
```

`native` and `build` in `intersect_tests` gained `dwords` variants
(`native_with`, `build_with`) so a test can state the entry's length; the
existing helpers call them with 4 and are unchanged in behaviour.

## Not claimed

I have not seen those five shaders translate. What is established is that the
length is no longer a reason to refuse, the address path is exercised at 8 by
a test that fails without the change, and 212 tests still pass. Whether each
of the five now lowers or stops at a later, real limit is something the corpus
would say — `victory translate --list` over `shaders.rpf`, which needs game
files.

Same for the `dwords == 8` half: `intersect_tests` passes with `dwords: 8`
where it used to say 4, so the address path works there too, but nothing in
the corpus has been run.
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.

1 participant