Skip to content

Shaders: texel offsets, comparison and gather forms of image samples - #160

Closed
r4tedx wants to merge 6 commits into
Marvisak:mainfrom
r4tedx:shader/image-sampling-family
Closed

r4tedx wants to merge 6 commits into
Marvisak:mainfrom
r4tedx:shader/image-sampling-family

Conversation

@r4tedx

@r4tedx r4tedx commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Rebased onto main 58fed37 (head 3ef252e, 2026-11-24). #634 (image_sample_o with constant offsets) merged and conflicted with this branch in emit/lower.rs. This branch already lowers that form: constant offsets in -8..7 become the same immediates #634 emits, and it also takes offsets past that range or per lane at a known level, which #634 refuses. So the rebase keeps this branch's offset code and uses #634's Module::int_value to read the constant. Its offset test (texel_offsets_and_levels_sample_the_texels_they_name) passes on the RTX 5070. cargo test -p victory-shader at 3ef252e: 97 passed, 1 ignored. The measurements below were taken at 25e917b, before the rebase.

The last commit (3ef252e) is not part of this change: on main the test target of victory-shader does not compile (issue #719; #117's test calls #612's changed helper with one argument). It passes the missing argument so this branch's tests can run, and goes away when main has the fix.

What

fn image accepted a fixed list of sample and gather opcodes; every other MIMG form failed the whole shader. Samples and gathers now lower by their form (comparison, derivatives, coarse or 16-bit derivatives, level, level 0, bias, level clamp, texel offset). The address dwords follow LLVM's ImageDimIntrinsics / SITargetLowering::lowerImage and Mesa's ac_build_image_opcode: offset, bias, reference, derivatives, coordinates, level or clamp.

Newly lowered:

  • Texel offsets (_o) on image_sample, _lz, _l, _b, _d, _c, _c_lz: DXIL immediates when the offset word is a constant in -8..7; otherwise the coordinates move by offset / size, only at a level known at translation.
  • _cl (the DXIL clamp argument), _cd (as _d, marked as a shortcut), _g16.
  • Gradient samples of cubes (image_sample_d, _d_cl, _cd, _g16 forms): two derivatives per direction, those of the face coordinates, turned into the direction's derivatives for SampleGrad.
  • Comparisons: image_sample_c, _c_cl (and _o) in compute as well as pixel shaders; image_sample_c_l(_o) at a level known to be 0; image_sample_c_b(_cl)(_o) with a bias known to be 0.
  • Gathers: image_gather4_l(_o) at any level. A level known to be 0 is a real gather; a run-time level is four samples at the footprint's texel centres at that level, so the sampler's own address mode and level range apply. image_gather4_c_lz(_o) and image_gather4_c_l(_o) at level 0 through textureGatherCmp.
  • a16: the bias as an f16 in the low half of its dword, and comparisons. a16 packs the coordinates and the level, not the derivatives (only _g16 opcodes have 16-bit derivatives); the decoder on main counted them packed, fixed here.
  • image_store of some channels: the data VGPRs are the dmask's channels in order; the others are written as 0.

Still refused, each with its own reason: gathers at an implicit level or with a bias; comparison gathers and cube gathers at a level not known to be 0; comparisons with derivatives, or at a level or with a bias not known to be 0 (SampleCmpLevel is SM 6.7, SampleCmpBias/Grad 6.8); offsets past -8..7 or per lane at a level not known here; offsets, texel coordinates and level queries on cubes.

Measured on the title's shaders

By @EduAzevedo (comments below), victory translate --jobs 8 --list over the retail 1.0.2.1 shaders, main d2a4bae against this PR at 25e917b:

main this PR
Vertex and pixel programs emitted 12,284 12,357
Refused for image_sample_d_cl (all on cubes) 27 4 (they stop at a cross-lane operation outside compute)
Refused for image_gather4_l (compute) 12 0
a biased image sample with 16-bit coordinates 108 0
image_sample_o 4 0
Programs that translated on main and no longer do 0

Validated, by TrashTalker3460 (comment): victory translate --validate --list over the 1.0.2.1 shaders.rpf alone (26,084 programs, so the baselines are 12 lower than above), with DXC 1.9.2609's validator, main d2a4bae against 25e917b:

Emitted / validated main this PR
Vertex and pixel 12,272 / 12,172 12,345 / 12,237
Compute 1,693 / 1,670 1,705 / 1,682
Mesh 8,191 / 8,129 8,191 / 8,129
Programs that validated on main and no longer do 0

All 12 image_gather4_l programs and the 23 image_sample_d_cl programs that emit also validate. Of the 108 programs freed from a biased image sample with 16-bit coordinates, 36 validate, 48 stop next at a scalar memory read as data, 16 at a lane mask read as data, and 8 emit but fail validation with Container part 'Program Input Signature' does not match expected for module. Those 8 are pixel shaders of one family (three distinct programs). #201 counts 21 input-signature mismatches of that kind on main, so they may be that existing problem reached for the first time; whether this PR's sampling path plays a part is not established.

With host pipelines, by adnanoos (comment): victory translate --list --pipelines over shaders.rpf on an RTX 5060 Laptop, main ffe310e against 5ce85c5. That run counts 16 image_gather4_l programs where the table above has 12: 10 meshlet-culling compute programs, which all translate and get host pipelines, and 6 water_micro_geom_renderer ones, which translate and whose pipelines the NVIDIA driver refuses with E_INVALIDARG, as it refuses about 320 compute pipelines on main. Vertex and pixel modules with pipelines: 12,231 to 12,300. One title run each: the world is black with audio on both; main ended in a device removal and this PR did not, with a warm pipeline library, so that difference is not established.

In the title, by nullmarsh (details): on an RX 9060 XT, d2a4bae + #135 + #365 + #500 with and without this PR at 25e917b, 12 traced world frames per run, 2 runs each. Without it, #293's top G-buffer pixel shader 7bdefdfde461f6e3 is refused for image_sample_d_cl and every ExecuteIndirect on its pipelines is dropped (692 and 1,017 in the two runs). With it the shader translates and all of them run, none dropped; the run-time image_sample_d_cl refusals go from 3 programs to 0. There was no visible change (the frames are still black apart from the title card) and no device loss in those four runs.

What those draws write, same tester (target dumps, one run per arm): the pipelines of 7bdefdfde461f6e3 (mesh 792314eae4f7da77) write six 2560x1440 colour targets and the depth target. Without this PR, and with it but that shader skipped, 5 to 6% of depth is non-background. With this PR, depth is 94% covered with only 6 distinct levels and the colour targets 100% with 1 to 4 levels: the draws now run and cover the screen with near-constant values, not a scene. With #587 on top the targets look like the run without this PR. So a build that takes this PR without a fix for what that mesh program emits (#586 / #587 work on that) gets screen-covering output from these draws. Whether the near-constant colour comes from the geometry alone or also from this PR's sampling is not established.

These are two rows of #293's ranking (image_sample_d_cl, image_gather4_l). The cube gradient and run-time-level gather support were added because of the first run: every image_sample_d_cl in the title is on a cube, and no image_gather4_l has a provably zero level. Not measured: whether the translated programs compute the right result in the title, and whether these cubes are cube arrays (the lowering treats the view as a cube; for an array the face operand adds 8 x the slice, a shortcut: already on main).

Checked against the references

Known limits

  • Non-immediate texel offsets and run-time-level gathers work on the level the instruction asks for. If the sampler's own LOD bias or range moves the sampled level, they read another level's grid; a probe with requested level 0 and sampler MinLOD 1 shows it. Marked as shortcut: in the code.
  • Implicit-derivative samples in compute fail the 1.6 validator we declare, as the plain image_sample in compute on main already does; the tests accept that one error for those forms.
  • Whether the texel offset applies before the address mode is not confirmed.

Overlap

Tested

Windows 11, NVIDIA RTX 5070, hand-assembled programs:

  • GPU, every lane against values worked out on the CPU: offsets (known, past -8..7, per lane), levels, gradients, g16, a16 with 32-bit gradients, bias and clamp through compute quads; cube gradients on every face along s and along t, with and without a clamp; gathers at levels 0-2 passed per lane, with per-lane offsets, through a clamp and a wrap sampler; comparisons and comparison gathers per texel; partial stores.
  • Every newly accepted form translates and passes dxil.dll; refusal reasons are checked; the decoder's address counts are checked against LLVM's.
  • Each new test fails without its change (and the cube and gather tests fail with a wrong scale or a permuted order).
  • cargo test -p victory-shader: 77 passed. clippy: nothing new. cargo xtask policy: ok.

The title was not used in my tests; the title measurements above are the named testers'. AI-assisted.

🤖 Generated with Claude Code

@DaviTostes

Copy link
Copy Markdown

Tested be7369a on Arch Linux x86_64, rustc 1.98.1: pass.

No game data used.

@r4tedx

r4tedx commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Pushed one more commit (7265593) after checking the open points in the description against AMD's ISA reference and LLVM. One was a mistake of mine, two are now settled:

Fixed: a16 does not make derivatives 16-bit. The decoder (already on main) and my lowering took a16 to pack the derivatives too. On GFX10.3 the two are independent: derivatives are 16-bit only in the _g16 opcodes, a16 packs the coordinates and the level. LLVM's SITargetLowering::lowerImage does it that way where hasG16, and its MC test gfx10_asm_mimg.s has

image_sample_d    v[0:3], v[0:4], s[0:7], s[8:11] dmask:0xf dim:SQ_RSRC_IMG_2D a16    ; 5 address dwords
image_sample_d_cl v[0:3], [v0, v1, v2, v3, v4, v6], ... dim:SQ_RSRC_IMG_2D a16        ; 6

i.e. four 32-bit derivatives plus the packed coordinates (and clamp). The decoder test now checks 5, 6, 3 and 7 address dwords for image_sample_d, _d_cl, _d_g16 and _d_cl_o with a16, and a GPU case samples with a16 and 32-bit derivatives; with the old sizing that case reads level 3 at texel 0 where it should read level 0.

Settled: the a16 bias. lowerImage has "Special handling of bias when A16 is on. Bias is of type half but occupies full 32-bit" and builds {bias, poison} as a v2f16, so the bias is an f16 in the low half of its own dword, as this PR reads it. #73 and #136 read that dword as an f32; I left a note on both.

Settled: partial stores. RDNA 2 ISA, MIMG DMASK: "Writes: defines which components are written with data from VGPRs (missing components get 0). Enabled components come from consecutive VGPRs." That is what this PR does, alpha included.

Still open: whether the texel offset applies before the address mode. cargo test -p victory-shader: 75 passed on the RTX 5070. No game data used.

@r4tedx

r4tedx commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

A limit of this PR, confirmed by a probe while reviewing the other image PRs with the same scrutiny (RTX 5070): the fallback for texel offsets that are not immediates (past -8..7, or per lane) shifts the coordinates by offset / size of the level the instruction asks for. If the sampler's own LOD range moves the sampled level (probe: requested level 0, sampler MinLOD 1, x offset +1), the immediate form reads x = 1 at level 1 and the shifted form reads x = 0. The code comment already says this case differs; it is silent, not refused, so it belongs here too. An exact form would need the level the sampler actually uses, which the shader cannot know; refusing non-immediate offsets unless the sampler is known not to clamp the level is the conservative alternative if anyone sees it matter in the title.

From synthetic probes only; I have no copy of the title.

@EduAzevedo

Copy link
Copy Markdown

Follow-up on the 25 image_sample_d_cl programs that stop at an image address with this PR: every image_sample_d_cl in those programs is on a cube (dim:SQ_RSRC_IMG_CUBE), NSA with 8 address VGPRs, no a16. That is two gradients per direction + three coordinates + the clamp; the translator expects three gradients per direction on a cube (10 dwords), runs past the operand list and refuses.

#138 handles exactly this (a cube's gradients are its two face coordinates'). #318 (1d7bf9b) gives the same result as this PR here: the same 25 stop at an image address, 12,328 vertex and pixel programs emitted. So those draws need #138's cube rule on top of whichever _d_cl lowering is merged.

AI-assisted.

r4tedx added a commit to r4tedx/VIctory that referenced this pull request Nov 24, 2026
A cube's derivatives are those of its two face coordinates: two per
direction, then s, t and the face (and the clamp), eight address dwords
for image_sample_d_cl. The lowering took three per direction as for a 3-D
image, ran past the instruction's addresses and refused the program with
"an image address" (and refused cube gradients by name after that).

The face coordinates' derivatives become the direction's for DXIL's
SampleGrad: cube_direction is linear in s and t on a face (u = 2s - 3,
v = 2t - 3), so the direction's derivative is the same per-face table with
2 ds for u, 2 dt for v and 0 for the constant axis. image_sample_d, _d_cl,
_cd and their _g16 forms now lower on cubes; texel coordinates, level
queries and texel offsets on cubes stay refused.

Reported from the title by a tester on PR Marvisak#160: every image_sample_d_cl
in the 25 programs that stopped at "an image address" is on a cube, with
eight address dwords and no a16.

Test (RTX 5070): a cube whose every face and level holds its own value,
sampled at each face's centre with derivatives of 1, 2 and 4 texels along
s or along t, with and without a clamp: the texel read names the face and
the level. Without the change the programs stop at "an image address";
with the direction's derivative scaled by 1 instead of 2 they read one
level too fine. The test host gains a cube view with mip levels.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@r4tedx

r4tedx commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

@EduAzevedo thank you, that is exactly the information this PR was missing, and it reproduces here: a hand-assembled image_sample_d_cl on a cube with eight address dwords stopped at an image address on this branch.

Fixed in b540f51 (pushed). A cube's derivatives are those of its two face coordinates, two per direction, then s, t, the face and the clamp. They become the direction's derivatives for SampleGrad: cube_direction is linear in s and t on a face (u = 2s - 3, v = 2t - 3), so the derivative is the same per-face table with 2 ds for u, 2 dt for v and 0 for the constant axis. image_sample_d, _d_cl, _cd and the _g16 forms now lower on cubes.

Test on an RTX 5070: a cube whose every face and level holds its own value, sampled at each face's centre with derivatives of 1, 2 and 4 texels along s or along t, with and without a clamp; the texel read names the face and the level. With the scale wrong (1 instead of 2) it reads one level too fine, so the test does check the mapping, at face centres. cargo test -p victory-shader: 76 passed.

If you can rerun on b540f51, three things would tell me whether it is right for the title:

  1. Do the 25 programs translate now, and if not, what reason do they stop at next (counts per reason)?
  2. Are those cubes plain cubes or cube arrays? The lowering treats the view as a cube; for a cube array the face operand adds 8 x the slice, which is a shortcut: already on main and would read the wrong slice. Yes/no is enough.
  3. For the image_gather4_l shaders of World: which untranslated shaders cost the most draws (ranked from two runs) #293: do they translate here (level known to be 0), or stop at a gather at a level not known to be 0?

On #138: its cube rule is the same idea. The difference between the two PRs is the a16 layout (#138 packs derivatives under a16, which LLVM's gfx10_asm_mimg.s does not; noted there). Since your programs have no a16, that part does not matter for these 25.

No game data used on my side.

@EduAzevedo

Copy link
Copy Markdown

@EduAzevedo thank you, that is exactly the information this PR was missing, and it reproduces here: a hand-assembled image_sample_d_cl on a cube with eight address dwords stopped at an image address on this branch.

Fixed in b540f51 (pushed). A cube's derivatives are those of its two face coordinates, two per direction, then s, t, the face and the clamp. They become the direction's derivatives for SampleGrad: cube_direction is linear in s and t on a face (u = 2s - 3, v = 2t - 3), so the derivative is the same per-face table with 2 ds for u, 2 dt for v and 0 for the constant axis. image_sample_d, _d_cl, _cd and the _g16 forms now lower on cubes.

Test on an RTX 5070: a cube whose every face and level holds its own value, sampled at each face's centre with derivatives of 1, 2 and 4 texels along s or along t, with and without a clamp; the texel read names the face and the level. With the scale wrong (1 instead of 2) it reads one level too fine, so the test does check the mapping, at face centres. cargo test -p victory-shader: 76 passed.

If you can rerun on b540f51, three things would tell me whether it is right for the title:

  1. Do the 25 programs translate now, and if not, what reason do they stop at next (counts per reason)?
  2. Are those cubes plain cubes or cube arrays? The lowering treats the view as a cube; for a cube array the face operand adds 8 x the slice, which is a shortcut: already on main and would read the wrong slice. Yes/no is enough.
  3. For the image_gather4_l shaders of World: which untranslated shaders cost the most draws (ranked from two runs) #293: do they translate here (level known to be 0), or stop at a gather at a level not known to be 0?

On #138: its cube rule is the same idea. The difference between the two PRs is the a16 layout (#138 packs derivatives under a16, which LLVM's gfx10_asm_mimg.s does not; noted there). Since your programs have no a16, that part does not matter for these 25.

No game data used on my side.

Reran on b540f51, same setup (retail v1.0.2.1 shaders, victory translate --jobs 8 --list against main d2a4bae):

Vertex and pixel programs emitted: 12,284 → 12,357 (12,332 on 7265593).

  1. The cube image_sample_d_cl programs: of the 27 refused for image_sample_d_cl on main, 23 translate; the other 4 stop at a cross-lane operation outside compute (2 of them already did on 7265593). The two programs that hit an image address on main itself translate too: that reason goes 2 → 0.
  2. Cube or cube array: I can't tell offline. The instruction is dim:SQ_RSRC_IMG_CUBE in all of them, which GFX10 also uses for cube arrays; the array size is in the descriptor, which only exists at run time. If it matters I can log the bound views' dimensions in a game run.
  3. image_gather4_l: all 12 stop at a gather at a level not known to be 0; none have a level the translator can prove is 0.

Everything else versus main: a biased image sample with 16-bit coordinates 108 → 0, image_sample_o 4 → 0, v_swap_b32 11 → 0 and v_xnor_b32 1 → 0; the programs that get further now stop at a scalar memory read as data (573 → 621), a lane mask read as data (206 → 222), a descriptor read only as data (179 → 183) and a cross-lane operation outside compute (46 → 50). Nothing that translated on main stopped translating.

r4tedx added a commit to r4tedx/VIctory that referenced this pull request Nov 24, 2026
image_gather4_l and _l_o lowered only when the level was a known 0,
since DXIL's gathers read level 0. A tester's run over the title's
shaders (PR Marvisak#160) found all 12 programs with image_gather4_l stop there:
none has a level the translator can prove is 0.

Such a gather is now four samples: the footprint's four texels, in the
gather's order, each sampled at its centre at that level. At a texel's
centre every filter returns that texel, and the sampler applies its own
address mode and level range, as it does for the console's gather. The
footprint is floor(u * size - 0.5) and the next texel in each direction,
moved by the texel offsets (any offsets, per lane too), on the level
rounded to the nearest whole one and clamped to the view's levels.
Marked as a shortcut: a sampler whose LOD bias or range moves the
sampled level off that one reads another grid. A gather at a level
known to be 0 stays a real gather. Comparison gathers (the function is
in the sampler) and cube gathers at an unknown level stay refused.

Test (RTX 5070): on a mipmapped texture whose texels name themselves,
lanes gather at levels 0, 1 and 2 passed per lane, with and without
per-lane offsets past -8..7, through a clamp sampler and a wrap sampler;
each lane's four values are the footprint's, clamped or wrapped. With the
gather order permuted the test fails.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@r4tedx

r4tedx commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

@EduAzevedo thank you, this is the first measurement of this PR on the title's shaders, and "nothing that translated on main stopped translating" is the line I most wanted to see.

The 12 image_gather4_l programs. Since none has a level the translator can prove is 0, I have added the general case in 25e917b (pushed): a gather at a run-time level becomes four samples, the footprint's four texels in the gather's order, each sampled at its centre at that level. At a texel's centre every filter returns that texel, and the sampler applies its own address mode and level range, as it does for the console's gather (this is why I did not use textureLoads, which would ignore a wrap or border sampler). A level known to be 0 stays a real gather. Still refused: comparison gathers and cube gathers at an unknown level.

Test on an RTX 5070: a mipmapped texture whose texels name themselves; lanes gather at levels 0, 1 and 2 passed per lane, with and without per-lane offsets, through a clamp and a wrap sampler; each lane's four values are that level's footprint. cargo test -p victory-shader: 77 passed.

One shortcut: to know about: the footprint is that of the level rounded to the nearest whole one. A sampler whose LOD bias or range moves the sampled level off that one would read another grid.

The rest of your numbers, as I read them:

If you rerun on 25e917b: do the 12 gather programs translate, and what do they stop at next?

No game data used on my side.

@EduAzevedo

Copy link
Copy Markdown

@EduAzevedo thank you, this is the first measurement of this PR on the title's shaders, and "nothing that translated on main stopped translating" is the line I most wanted to see.

The 12 image_gather4_l programs. Since none has a level the translator can prove is 0, I have added the general case in 25e917b (pushed): a gather at a run-time level becomes four samples, the footprint's four texels in the gather's order, each sampled at its centre at that level. At a texel's centre every filter returns that texel, and the sampler applies its own address mode and level range, as it does for the console's gather (this is why I did not use textureLoads, which would ignore a wrap or border sampler). A level known to be 0 stays a real gather. Still refused: comparison gathers and cube gathers at an unknown level.

Test on an RTX 5070: a mipmapped texture whose texels name themselves; lanes gather at levels 0, 1 and 2 passed per lane, with and without per-lane offsets, through a clamp and a wrap sampler; each lane's four values are that level's footprint. cargo test -p victory-shader: 77 passed.

One shortcut: to know about: the footprint is that of the level rounded to the nearest whole one. A sampler whose LOD bias or range moves the sampled level off that one would read another grid.

The rest of your numbers, as I read them:

If you rerun on 25e917b: do the 12 gather programs translate, and what do they stop at next?

No game data used on my side.

Reran on 25e917b, same setup:

  • The 12 image_gather4_l programs (all compute) translate now; none stops at anything next.
  • The 27 cube image_sample_d_cl programs are as before: 23 translate, 4 stop at a cross-lane operation outside compute.
  • Vertex and pixel programs emitted: 12,357 (gathers are compute, so that count does not move). No program that translated on main stops translating.

A correction to my two earlier comments: my main binary had been built before I updated to d2a4bae. Rebuilt and rerun, main itself already has v_swap_b32 0, v_xnor_b32 0 and a descriptor read only as data at 183, so those three lines are not effects of this PR. The 12,284 for main, and everything else I reported for this PR, hold against the rebuilt main. Sorry for the noise.

Cube vs. cube array: not done yet; it needs a game run with a small local logging change, so I'll only do it if you think it is worth it.

@r4tedx

r4tedx commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

@EduAzevedo thank you for the rerun and for the correction; I have put your numbers, with the correction applied, into the PR description under "Measured on the title's shaders" and credited them to you. Tell me if I have misread anything: 12,284 to 12,357 vertex and pixel programs, the 12 gather programs translating, 23 of 27 cube image_sample_d_cl, 108 to 0 biased a16 samples, and nothing lost.

Cube vs. cube array: not worth a run on its own. If you (or anyone) are logging bound views in a world run for another reason, the dimension of the views these 23 programs sample would settle it; until then the description says it is unmeasured.

The 4 left at a cross-lane operation outside compute belong to the SGPR-spill PRs (#54 / #309). If you ever run this PR together with one of those, whether those 4 then translate would be a useful line for that PR's thread.

@EduAzevedo

Copy link
Copy Markdown

@EduAzevedo thank you for the rerun and for the correction; I have put your numbers, with the correction applied, into the PR description under "Measured on the title's shaders" and credited them to you. Tell me if I have misread anything: 12,284 to 12,357 vertex and pixel programs, the 12 gather programs translating, 23 of 27 cube image_sample_d_cl, 108 to 0 biased a16 samples, and nothing lost.

Cube vs. cube array: not worth a run on its own. If you (or anyone) are logging bound views in a world run for another reason, the dimension of the views these 23 programs sample would settle it; until then the description says it is unmeasured.

The 4 left at a cross-lane operation outside compute belong to the SGPR-spill PRs (#54 / #309). If you ever run this PR together with one of those, whether those 4 then translate would be a useful line for that PR's thread.

Yes, that's all correct against the rebuilt main

@Yaekai

Yaekai commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Independent verification on Windows 11 + NVIDIA RTX 3070 (Rust 1.98.1) at head 5ce85c5:

  • cargo test -p victory-shader --lib -- --skip valu_tests --skip waterfall_tests: 110 passed, 0 failed.
  • cargo clippy -p victory-shader -- -D warnings: 0 warnings.
  • Live GTA VI (1.0.2.1, --console series-s, 19-min world run): no regressions. Ready to merge!

edsuuu referenced this pull request in edsuuu/VI-BR-PORT Nov 24, 2026
The tester tree (upstream main ffe310e plus its PRs, update 8; see its
INTEGRATION.md) ran 11-25 minutes in the world on an RTX 5070 without a
device removal. Where both sides carry the same PR (the wave64 stack
#223/#233/#320 with #439 and #180, #454, #336, #259, #331 and others), the
tester tree's newer head is taken; our own work and the PRs only we
merged are kept.

Conflicts, file by file:

- descriptor/host.rs: the tester layout (`spare`, the guard slot after the
  dynamic slots, `free_table`, the capped sampler heap). A capped view
  heap keeps `capped_reserve()` dynamic slots, now 2^18 by default (the
  tester measurement, and our 91fed158), still `VICTORY_DYNAMIC_SLOTS` in
  diagnostics builds; uncapped hosts keep our 2^19. Our slot statistics
  (TAKEN/PEAK/SHORT), the bindless plan cache (`CommittedRegions`,
  `timed_valid_title_address`, `timed_find`, `title_bounds`) and the
  revision triple are kept beside the tester's `guard_slot`.
- Buffer states: the tester tree's buffer-state tracker (#334: every list
  moves host copies of title memory between GENERIC_READ and
  UNORDERED_ACCESS and back to common before it closes) and depth twins
  (#469) are taken. #40's enhanced/legacy indirect barriers (the indirect
  prelude, `use_indirect_buffers`, the title buffer handoff mirrored in
  `host_barrier`) cannot share buffers with that tracker and are dropped;
  #40's argument checks (`byte_len`, exact spans, overflow-safe clamp
  shader, aligned counts) stay. `indirect::bound` and #282's
  `rectangles` go through `buffer_state`, and `indirect::execute` (#334)
  replaces `done`. #178's DXC fallback compiles both of our passes.
  Our segments (#387: `close` ends the segment, `close_native` closes a
  native list) carry the tracker: each native list returns its buffers
  to common and its twins to their depth targets, and each prelude also
  holds our texture uploads.
- shadow.rs: our write flow (`queue_write`, one `snapshot` after the
  batch's refreshes, `finish_writes`, the unchanged-page cache) with
  #261's copy-back that also gives the snapshot the title's bytes; its
  tests run through our flow.
- pipeline/make.rs: #275's per-frame budget and per-pipeline wake pair,
  with our compute waits (a dispatch waits for its pipeline, up to 20 s).
- pipeline/library.rs: the tester version (#347, #275's saver thread);
  our concurrent-write test kept. shader_cache.rs: our byte-returning
  cache API with #358's "translated, only not kept".
- draw.rs: #493's root SRV tables; where no table can stand in, our
  drop of a draw whose root view is unset or outside title buffers. Our
  refusal of a table offset past the capped heap stays.
- resource.rs: `HostTexture` has both our `staged` generation and the
  depth twin.
- Shaders: the tester's lower.rs for the wave64 stack, #160's image
  sampling (it covers our #73 and #136 sample forms) and #453/#587; kept
  from our side: #136's preference for an image or buffer use of a
  descriptor read as data and its `s_buffer_` arm, #422's nearest-even
  narrowing (also for #169's d16 loads and #453's interpolation), #452's
  spin-wait limit, #391's LDS limit, #302's spilled root arguments (now in
  `NativeProgram::translation_ir`), #136's PSV0 interpolation beside the
  tester's row harmonisation. split_tests.rs, lane_read_loop_tests.rs and
  docs/wave64-on-wave32.md are the tester versions (the same PRs at newer
  heads).
- Tests: #483's heap guard dwords filled in our GPU tests of #200
  (v_div_scale) and #437 (scalar loads from a raw view), which read
  through the guard slot otherwise; #334's debug-layer test passes an
  offset to our `indirect::bound`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
edsuuu referenced this pull request in edsuuu/VI-BR-PORT Nov 24, 2026
Two testers bisected #136 as making every frame black on RTX 5080 and
4080, loading screens included (upstream issue #71); the tester tree
leaves it out. A plain revert of 5254cfa conflicts with #160, #437 and
the tester merge, so each of #136's constructs is set to the tester
tree's form:

- s_load through a tracked descriptor: SRV only, as before #136 (no UAV
  raw reads); #437's byte offsets and its test stay.
- A descriptor read as data: the first use found, not #136's preference
  for an image or vector buffer use; #136's s_buffer_ arm is gone.
- PSV0 interpolation modes (psv_interp) are no longer read; the
  conservative-depth centroid and the row harmonisation stay (tester).
- calculateLOD passes cs[0..2] as the tester tree does.
- Dead descriptor dwords at data joins: the tester's undef arm
  (descriptor_dword) only, not #136's zero for has_data joins.

Kept because the tester tree has the same form: the signature sort by
row, barycentrics (23 => 28), the comparison-sample check, and #160's
gather and a16 sampling.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
simnJS pushed a commit to MiamiGame/XTP that referenced this pull request Nov 24, 2026
Image samples and gathers now lower by their form (comparison,
derivatives, coarse or 16-bit derivatives, level, level 0, bias, level
clamp, texel offset) instead of a fixed list of opcodes. The address
dwords follow LLVM's ImageDimIntrinsics and Mesa's ac_build_image_opcode:
offset, bias and reference a dword each, then the derivatives (16-bit
ones two per dword in the _g16 opcodes, each direction its own), the
coordinates and the level or clamp (a16 packs those, not the
derivatives). The decoder counted 32-bit derivatives for the _g16 forms
and took a16 to pack the derivatives; it now sizes them by the opcode.

Newly lowered:
- every texel-offset form; DXIL immediates when the offset word is a
  constant in -8..7, else (past -8..7, or per lane) the coordinates move
  by offset / size at a level known at translation;
- _cl (the DXIL clamp argument), _cd (as _d), _g16;
- image_sample_c, _c_cl and their _o forms in compute as well as pixel
  shaders; image_sample_c_l(_o) at level 0, image_sample_c_b(_cl)(_o)
  with a bias known to be 0;
- image_gather4_l(_o) (at a level known to be 0 a gather, at a level
  known only at run time four samples of the footprint's texels at their
  centres), image_gather4_c_lz(_o), image_gather4_c_l(_o) at level 0
  (textureGatherCmp);
- cube samples with gradients (image_sample_d, _d_cl, _cd and the _g16
  forms): a cube's derivatives are those of its two face coordinates,
  which become the direction's through the face's linear part of
  cube_direction;
- a16 biased samples and a16 comparisons;
- image_store of some channels: the data VGPRs are the dmask's channels,
  the others are written as 0.
Still refused, each with its reason: gathers at an implicit level or with
a bias, comparisons with derivatives, at a level or with a bias not known
to be 0 (SM 6.7/6.8 operations), offsets past -8..7 or per lane at a
level not known at translation, comparison and cube gathers at a level
not known to be 0.

XTP adaptation: emit/lower/image.rs (S0b) takes the PR's image function
as is (XTP's equalled upstream ffe310e, the PR's base) with the 64-bit
atomic branch of the #539 port put back; `Module::known` (bitcode.rs) is
not taken, the existing `int_value` reads the constants (XTP holds every
register dword as an i32). The test host gains textures with mip levels,
cube textures with mip levels and R32F textures (emit/host.rs); the
decoder fix and its test are in gfx10. emit/image_tests.rs takes the
PR's tests; the #539 port's atomic tests become its module `atomic64`
and now take the GPU one at a time with the others (the PR's last
commit: XTP's VALU tests already share that lock).

Review notes, kept as shortcuts in the code: the four-sample gather at
a run-time level reads the footprint of the level rounded to the nearest
and clamped (a sampler bias or range that moves the level reads another
grid); offsets emulated by moving coordinates assume the sampler keeps
that level; partial stores write 0 to the channels the dmask leaves out
(the PR's model, checked on the host, not on the console). Comparison
samples with implicit derivatives in compute are sampleCmp, which
validator 1.6 refuses there and the drivers run (the test lets that
error through).

Survey (shaders.rpf, any host, every translation validated): 23,387 ->
23,472 translated, 85 new: 44 a16 biased samples, 25 image_sample_d_cl
(all on cubes: #563's 25), 16 image_gather4_l (at a run-time level);
77 accepted by dxil.dll, 8 stop at "Container part 'Program Input
Signature' does not match", a class the pack had before (15 programs).
None lost, no translation that existed changed. 68 programs past these
blockers stop at the next one (48 scalar memory read as data).

This covers Marvisak/VIctory#563 (head 10ac6ceac9284caa6dd5d4bad3166687f8d0c1ac) by SAitken91:
the same cube gradients (the same table) and image_sample_d_cl, written
independently; the PR's own commit 2cf3ccd says the 25 programs are the
title's. Nothing of #563 is left to port after this.

Ported from Marvisak/VIctory#160 (head 5ce85c5e70878e9208a1cc02c2b65966a1316653) by r4tedx
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
Co-authored-by: Saitken91 <98485913+SAitken91@users.noreply.github.com>
@adnanoos

Copy link
Copy Markdown

Tested this PR (5ce85c5, merged with main ffe310e) on an NVIDIA GeForce RTX 5060 Laptop GPU (driver 32.0.16.2124, Intel Core 7 240H, Windows 11 Pro 26200), title files version 1.0.2.1 (title exe BLAKE3 b99f876b…239e93).

cargo test --release -p victory-shader: 128 passed, 0 failed, 1 ignored (GPU tests on the RTX 5060).

victory translate --list --pipelines on shaders.rpf (26,084 programs), main vs this PR:

main this PR
VS/PS DXIL emitted (and host pipelines created) 12231 12300
image_gather4_l 16 0
a biased image sample with 16-bit coordinates 108 0
image_sample_d_cl 29 0
a scalar memory read as data 771 819
a lane mask read as data 250 266
a cross-lane operation outside compute 46 50
pipeline: The parameter is incorrect. 320 326

Nothing else changed. On this build there are 16 image_gather4_l programs (the description counts 12):

In the title (one run each, Series X mode, GpuPreference=2 so the dGPU is used):

  • main: world black with audio; world frames 265–3380 ms per submission (avg ~794); ended in DXGI_ERROR_DEVICE_REMOVED / 0x887A0006 (device removed after a submission of 11 lists; no breadcrumbs).
  • this PR: world still black with audio; slow submissions avg ~436 ms, max 548; no device removal, exited cleanly when the window was closed.

Caveat: one run each, and the PR run had a warm pipeline library, so the timing and the missing hang are not conclusive. Happy to run more passes or a diag build with VICTORY_D3D12_DEBUG=1 if that helps.

@r4tedx

r4tedx commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

@adnanoos thank you. This adds the one thing the earlier counts did not have, host pipelines, and it corrects a number: your run finds 16 image_gather4_l programs where the description's table had 12. I have put your result in the description next to that table, with the split you give (the 10 meshlet-culling programs translate and get pipelines; the 6 water ones translate and the driver refuses their pipelines with E_INVALIDARG).

On those 6: I read them as you do. The translation is accepted by the validator and refused at pipeline creation, like the roughly 320 compute pipelines main already loses on NVIDIA, so they belong with that class and not with this PR's lowering. If your --list output names the same refusal text for them as for the 320, that settles it; if theirs differs, I would like to know.

On the title runs: agreed that one run each with a warm pipeline library does not establish the missing hang, and you say so yourself. No need for more passes on this PR's account. If you do run again, the comparison worth having is both builds on a cold cache.

@Yaekai thank you as well for the run on the RTX 3070, here and on #265.

The title was not used in my tests. AI-assisted.

@adnanoos

Copy link
Copy Markdown

Checked the saved --list output. The 6 water_micro_geom_renderer programs (CS_GenerateWaterPatches, CS_GenerateWaterPatches_WithLODStitching, CS_GenerateWaterPatchWritingJobs, CS_GenerateWaterPatchWritingJobs_WithLODStitching, CS_CullWaterPatches, CS_CullWaterPatchesUsingCalmingInfo) report exactly pipeline: The parameter is incorrect., the same text as all 320 on main (all Cs). A set diff of the refused programs: this PR adds exactly those 6 and removes none, so 320 becomes 326 with no other change.

One limit: the listing records only the HRESULT text, not the driver's reason, so this shows the same error code rather than the same cause. If it would help, I can rerun those 6 with the debug layer on and post the messages next to a few of the 320.

On the title: noted. If I run it again, it will be both builds on a cold cache.

r4tedx added a commit to r4tedx/VIctory that referenced this pull request Nov 24, 2026
The two reference draws create a host and draw on the hardware adapter
and WARP without `valu_tests::ONE_AT_A_TIME`, so on CI's WARP adapter
they could dispatch at the same time as the other GPU tests; the run on
6ddbdfc ended with the victory-shader test process dying with
STATUS_ACCESS_VIOLATION and no failing test named, the crash seen before
on Marvisak#704, Marvisak#160 and Marvisak#265 for that reason.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@r4tedx

r4tedx commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

@adnanoos thank you, that settles it as far as a listing can: the same text for the 6 as for the 320, and a set difference of exactly those 6. The description already says they are refused the way main's are, so nothing to change there.

On your offer: the debug-layer messages for those 6 next to a few of the 320 would be useful, but for the issue that tracks those refusals (#71's class) rather than for this PR, which only moves the 6 from "refused by the translator" to "refused by the driver". If you do run it, that is where I would post it.

AI-assisted.

@upipibi

upipibi commented Nov 24, 2026

Copy link
Copy Markdown

In-world evidence for the explicit-level gathers here, from a fork that runs main + its own changes into the world: fxceless/victory-gta6 (README, "Gathers at a named mip level read level 0"; the comment at its image_gather4_l lowering).

The fork found that a host gather (DXIL op 73, no level) reading level 0 where the title names one broke the title's meshlet occlusion culling. The culling gathers a 4×4 block of the depth pyramid at a named level: one image_gather4_l and three image_gather4_l_o with offsets (2,0), (0,2) and (2,2). Read at level 0, "most of the world was culled against the wrong depths". The fork reads the four texels at the named level instead, with the offset in texels of that level.

That is what gathers_at_a_run_time_level_read_that_levels_footprint checks here (gather4_l_o at a per-lane level included). It also means #694, which maps image_gather4_l to op 73 and so reads level 0, would translate those programs but cull most of the world.

AI-assisted (Claude Code).

KainanP added a commit to KainanP/VIctory that referenced this pull request Nov 24, 2026
…sak#704 + Marvisak#1511

Conflicts in crates/victory-shader/src/emit/lower.rs, resolved by hand:

1. descriptor_data: the bundle (Marvisak#953 s_buffer_load uses, Marvisak#1067 "read only as data"
   from the table's range) and Marvisak#180 (twin loads of the same dwords) both rewrote how
   the view's kind is found. Kept Marvisak#180's lookup (own uses, else a twin load's) and the
   bundle's handling of the use and of the unused case, plus the one case Marvisak#180 accepted
   that the bundle did not: an 8-dword load outside a table/heap range, taken as a 2D
   image (Marvisak#180's "image the program only measures"). Where both accepted a descriptor
   they built the same view.
2. phi joins: the bundle's arm (Marvisak#1073, a mask dword joined by ballot) and Marvisak#180's arm
   (a descriptor dword at a data join is undef) were inserted at the same place. Both
   kept, bundle first; the first needs a tracked lane mask, which a descriptor dword
   is not, so they do not overlap.
3. No textual conflict, did not compile: the bundle (Marvisak#306) gave `addr_val` a start
   position (`addr_val(l, start, k)`); Marvisak#180's compute image_sample_b arm read the bias
   with the old form at dword 0 through `as_float`. It now reads it as the bundle's
   sampleBias does: after the offset word when there is one, an f16 with a16
   (`to_float`). This is the bias half of the Marvisak#160/Marvisak#180 interaction described in
   Marvisak#160 (comment) , which the
   bundle's offset forms already expose.
KainanP added a commit to KainanP/VIctory that referenced this pull request Nov 24, 2026
…ge samples) onto Marvisak#309 + Marvisak#180 + Marvisak#704 + Marvisak#1511

PR Marvisak#160 head 5ce85c5, merged onto integ/next-v3 (0bb7335). The bundle
(Marvisak#1511) already carries Marvisak#306 (a16 bias as f16, a16 derivatives 32-bit),
10ac6ce (cube gradient samples, image_sample_d_cl) and cbc8c33 (image_get_lod
on cubes); Marvisak#180 adds compute image_sample/_b as sampleGrad with quad gradients.
Where Marvisak#160 and the bundle implement the same thing, they read the same address
layout: offset, bias and reference a full dword each (a16 bias an f16 in the low
half), derivatives 32-bit unless _g16, a16 packing only coordinates and level or
clamp. The bundle's Marvisak#306 layout is kept as the base and Marvisak#160's forms are added
to it.

gfx10/fields.rs (image_addr_dwords): both sides size derivatives by _g16 and
pack only coordinates and levels with a16. Kept the bundle's Marvisak#306 version (a g16
token rather than Marvisak#160's ends_with("_g16"), which gives the same count for every
opcode name) together with its a16_keeps_derivatives_32bit_outside_g16 test.

emit/host.rs (1 hunk): Marvisak#160 adds a test-host arm for Levels/CubeLevels/Depth
SRVs; the bundle (Marvisak#704) extended the UAV arm to BufferUav with a stride column.
Both arms kept: Marvisak#160's arm first, then the bundle's UAV arm unchanged.

emit/lower.rs:
1. Free functions after half_outputs: the bundle added half_inputs and Marvisak#160
   added SampleForm/sample_form/GATHER_AT_LEVEL in the same place. Kept both.
2. Opcode match: the bundle added "image_sample_d" | "image_sample_d_cl" to the
   fixed list, and Marvisak#160 replaced the list with the parsed form (_ if form.is_some()).
   Took Marvisak#160's. d_cl is the form {d, cl}, so it still lowers to SampleGrad with
   its clamp.
3-4. Address layout: the bundle had (Marvisak#306) first = offset + bias + cmp
   full dwords, 32-bit derivatives (2 per direction on a cube, 10ac6ce), and
   `at` = first + grads, from which the a16-packed coordinates and level start.
   Marvisak#160 had the same layout as whole/per_direction/first, plus _g16 derivatives and
   _cl. Kept the bundle's names and layout (first, graded, at, addr_dword) and put
   Marvisak#160's pieces on them: first is now o + b + c from the form (it was
   offset_word + (name == image_sample_b) + cmp); per_direction halves the
   derivative dwords for _g16 only; grad_at, coord_at, bias_at, float and known
   (Marvisak#160) read through the bundle's addr_dword in place of Marvisak#160's duplicate `raw`.
   Marvisak#306's to_float/addr_val pair for coordinates and Marvisak#160's float(coord_at(k))
   compute the same thing; the latter is kept because the level, clamp and known
   checks use it. The a16 refusal of comparisons in the bundle's code is
   dropped, as in Marvisak#160 (the reference is a full dword).
   Also, without a textual conflict: Marvisak#160 refused level queries on cubes
   ("... or a level query"), but the bundle lowers image_get_lod on cubes
   (cbc8c33). That refusal is dropped and only texel coordinates (both sides)
   and texel offsets (Marvisak#160) are refused on cubes. The bundle's `face` variable is
   kept in place of Marvisak#160's `cube_face`.
5. sample (60): the bundle's constant-offset code is the base code with
   addr_dword. Marvisak#160 moved offsets before the match (immediates in -8..7, otherwise
   a coordinate shift at a level known here) and added the clamp. Took Marvisak#160's
   version, reading the word with addr_dword.
6. sampleBias (61): bundle addr_val(offset_word, 0) + to_float, Marvisak#160
   float(bias_at). Both read the same position, an f16 low half with a16. Kept the
   bundle's comment and Marvisak#160's reader, plus Marvisak#160's clamp.
7. sampleGrad (63): the bundle reads `graded` 32-bit derivatives per direction,
   turns cube face derivatives into direction derivatives after reading, and
   reads its own _cl clamp. Marvisak#160 reads through grad_at (g16 too) with a per-face
   branch. Kept the bundle's structure (loop over `graded`, then the cube
   conversion) reading through Marvisak#160's grad_at, so _g16 works. The bundle's inner
   clamp is dropped for Marvisak#160's clamp, which comes from the same position
   (coordinate `coords`) and now covers every _cl form. Marvisak#160's `_cd` shortcut
   comment is kept.
8. sampleCmp/LevelZero (64/65): the bundle reads addr_dword(first - 1) and Marvisak#160
   reads float((o + b, None)). These are the same dword, since first = o + b + c
   and c is set. Kept the bundle's line. Marvisak#160's clamp is pushed for SampleCmp.
9. sampleLevel (62): bundle name == "image_sample_l" with addr_val(at,
   coords), Marvisak#160 f.l with float(coord_at(coords)). These are the same position.
   Took the form test so that _l_o and the others are covered.
10. gather (default arm): the bundle's checks and per-lane offsets are the base
    code with addr_dword. Marvisak#160 moved the checks into the op choice (level 0,
    comparison gathers, GATHER_AT_LEVEL) and the offsets ahead of the match.
    Took Marvisak#160's.
Duplicate method: 10ac6ce (bundle) and Marvisak#160 both add Lower::cube_gradient with
the same table (u, v move by 2 ds, 2 dt, the major axis by 0). With no conflict
git kept both. Kept Marvisak#160's, which shares by_face with cube_direction, and
removed the bundle's.

Marvisak#180 interaction (integration fix from
Marvisak#160 (comment), r4tedx):
Marvisak#180's compute image_sample/_b arm (sampleGrad from quad gradients) dropped the
level clamp, and before 5703405 it also read the bias at dword 0. With Marvisak#160,
_b_o, _cl and _b_cl_o reach that arm. The arm now reads the bias with
float(self, bias_at) (after the offset word, an f16 with a16; this is the same
position 5703405's addr_val(offset_word, 0) + to_float read) and pushes Marvisak#160's
level clamp instead of undef.

Marvisak#160 x Marvisak#306 interaction (no textual conflict; emit/shader.rs, lower.rs):
Marvisak#306 declares dx.valver 1.8 for a compute module with an implicit-derivative
sample (cs_derivatives, which Marvisak#180's sampleGrad arm also sets). Validator 1.8
counts a sample's level clamp (a non-undef clamp operand) as TiledResources use,
and 1.6 does not. Marvisak#160's _cl forms in compute (Marvisak#180's arm with the clamp above,
and SampleCmp for _c_cl) therefore failed "Flags must match usage" in
sample_and_gather_forms_lower_to_valid_dxil, comparisons_and_comparison_gathers_
match_per_texel_comparisons and texel_offsets_and_levels_sample_the_texels_they_name
(declared and actual flags differ by exactly 1 << 12). Marvisak#160 alone declares 1.6,
where this does not apply. Added flags::TILED_RESOURCES (bit 12, SFI0 0x100). It is
set when a sample takes a level clamp (Shader::lod_clamp) and the module declares
valver 1.8. Still needed on this Marvisak#1511 head: its Marvisak#1402 (119b763) only skips two
of Marvisak#306's own tests when dxil.dll is older than validator 1.8 and does not change
what Marvisak#306 declares.

Checked (on the previous Marvisak#1511 head, 289f241, which also carried Marvisak#98; this
replay was checked with cargo check --workspace --all-targets --all-features and
the full suite at the end of the line): cargo build --workspace --all-targets, clippy -D warnings, xtask
policy. cargo test --workspace on an RTX: 427 passed, 0 failed, 6 ignored. With
VICTORY_WARP=1 --no-fail-fast: 426 passed, 1 failed (valu_tests::
v_cndmask_on_an_untracked_mask_tests_this_lanes_bit, which also fails on the base),
6 ignored. #[test] count: base 424 + 8 from Marvisak#160 = 432 in the tree; the
victory-shader lib lists all 204 of its own.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
KainanP added a commit to KainanP/VIctory that referenced this pull request Nov 24, 2026
…, Marvisak#320, Marvisak#439) onto Marvisak#160 + Marvisak#309 + Marvisak#180 + Marvisak#704 + Marvisak#1511

PR Marvisak#439 head 28aca3b (46 commits over main: Marvisak#223 wave-range targets, Marvisak#233
split halves and the console flow, Marvisak#320 lane reads where lanes branch,
Marvisak#439 LDS in one console wave, whole-wave sections across the halves,
ds_bpermute, numeric selects), merged onto the Marvisak#160 merge (b821b31), as the wave64 line of integ/next-v3.

emit/wave.rs: no conflict on this Marvisak#1511 head. The previous head carried
Marvisak#98 (f468457, v_permlane16 modelled next to v_permlanex16, only with every
lane active), which conflicted with Marvisak#439's a31c82e (an inactive lane also
accepted when fi, opsel bit 0, is set). Marvisak#98 is no longer in the bundle, so
the whole-wave simulation is Marvisak#439's: v_permlanex16 only, under
`exec == all || v.opsel & 1 != 0`.

structure.rs (1 hunk): the bundle only reformatted `paired_masks`; Marvisak#439
moved it after the new `execs`/`others`/`pairs` fields because `pairs`
borrows `self.masks` before `paired_masks` moves it. Kept Marvisak#439's order with
the bundle's formatting.

emit/waterfall_tests.rs (3 hunks):
1-2. The bundle split `build` into `build_with(words, buffers, nonuniform)`
   (a program with no per-lane handle, whose first-lane read is a wave
   operation); Marvisak#439 split the same function into `native`, `lower_as`
   (per-lane or console flow) and `host_shader`. Kept Marvisak#439's helpers and
   the bundle's `build_with` on top of them (lower_as(.., false), the
   bundle's two asserts, host_shader). host_shader keeps the stride_table
   field (Marvisak#704), which git merged outside the hunk.
3. Tests at the end of the file: the bundle's side ends inside the `for`
   loop of a_descriptor_only_read_as_data_gives_its_views_size, Marvisak#439's
   inside the `for target` loop of its last test. The bundle's test is
   closed before Marvisak#439's tests, so none is nested in another.

emit/lower.rs (6 hunks):
1, 3. Lower fields and their initializers: the bundle's `mask_scc` (Marvisak#309,
   SCC of a mask operation read as data) and Marvisak#439's `opaque_open` (stops
   the recursion of a mask copied dword by dword). Both kept.
2. Which compute programs need the console's lanes. The bundle (Marvisak#309) counts
   only live instructions (`sgpr_spill::dead`: lane moves forwarding left
   unread are not lowered); Marvisak#439 split the test into in-half reads, whole
   reads and masks held as numbers and added the split/console-flow choice.
   Kept Marvisak#439's structure, reading `live()` for reads_whole and in_half, and
   for lane_access_outside_sections (the console-flow trigger for lane reads
   where lanes branch differently). 1ca87f7 (in Marvisak#439) notes that the tester
   tree's `live()` filter belongs here once Marvisak#309 is in.
4-5. Selects on masks the structure does not follow. The bundle (48a41fb,
   from Marvisak#585) added `mask_cond` for v_cndmask_b32 and the v_*_co_ci_u32
   carry-ins: inline 0/-1 constants, the tracked boolean, else with console
   lanes this lane's bit of the register's number (pair in wave64). Marvisak#439
   (e461457, 1ca87f7, ccd9c44) takes, for v_cndmask only, the structure's
   boolean for masks held as numbers (`Structured::others`, which also finds
   the high word written by another instruction), only where the host lane
   is the console lane (not split in halves without the console flow), and
   declares console lanes for them only on a second lowering after the
   first stops on such a select (`lower`). Combined in `mask_cond`: tracked
   boolean, then Marvisak#439's `others` boolean, then the bundle's register number,
   both under Marvisak#439's condition (console lanes and not split without the
   console flow; the bundle's number path called lane_bit, which is wrong in
   a split program, where Marvisak#439 asserts it is never called). Both instructions
   use it; v_cndmask now also takes the bundle's inline constants.
   Without a textual conflict git had also kept the bundle's unconditional
   rule (any untracked select or carry-in declares console lanes) inside
   Marvisak#439's masks_held, which undid 1ca87f7 (a select nothing reads made a
   wave64 program in a group of more than 64 threads untranslatable on a
   32-lane host). The rule now counts live instructions and applies only on
   Marvisak#439's second lowering, which now also follows an untracked carry-in
   ("a carry-in from an untracked mask", UNTRACKED_CARRY). It covers every
   untracked selector, not only Marvisak#439's held masks with an opaque or constant
   atom, since the bundle's number path needs console lanes for selectors
   outside `others` too; on the first lowering nothing changes.
6. lower.rs test helper: Marvisak#439's three new Parts fields with the bundle's
   formatting.

Not textual, did not compile (test code only): Marvisak#439 gives `emit` a Target
and `lower::Parts` target/console_cf/per_lane_only. Tests that came with
the bundle, Marvisak#704, Marvisak#309 and Marvisak#160 used the old forms: image_tests.rs `lower`,
emit/mod.rs (3 emit calls, the stride-table Parts), lower.rs (2 Parts in
the int64 atomics tests), root_view_tests.rs, sgpr_spill.rs tests and
victory-gpu raw_view_tests.rs. They pass Target::ANY, console_cf false and
per_lane_only false, as Marvisak#439 did for the upstream tests.

Not textual, test-only (split_tests.rs): with Marvisak#309 a v_readlane whose
result nothing reads is dead (not lowered and, above, not counted).
saveexec_scc_tests_new_exec_not_saved_exec and
loops_leave_on_the_new_exec_of_saveexec used `v_readlane_b32 s14, v0, 10`
with s14 unread only to take the console flow. After the merge the loop
test failed on the RTX (per-lane form, lane t counted t + 1 iterations
where the console counts 64; it passes on Marvisak#439 alone), and the saveexec
test passed without taking the console flow (its per-lane result is also
42). Both now read s14 once (`s_mov_b32 s15, s14`, the branch over the
body +4), and a first lowering of each was checked to ask for the console
flow again on a 32..32 target.

Marvisak#180 interaction: r4tedx's integration (24b3bcc, from Marvisak#180 5ff639e) put
`implicit_derivatives` among the in-half reads that make a program need
console lanes. The Marvisak#180 merged here is aa69258, whose last commit takes
quad gradients out of the console-lanes test altogether ("a quad's four
lanes share a host wave of any size"), so there is no such term to place.
The quad reads stay inside one host wave in both Marvisak#439 forms (each half is a
host wave in the split and in the console flow, and in the console flow
samples run in every lane and are kept by a select on EXEC).

Checked on the previous Marvisak#1511 head (289f241, with Marvisak#98; this replay was
checked with cargo check --workspace --all-targets --all-features and the
full suite at the end of the line), on an RTX 4060 Laptop (32..32): cargo test --workspace --locked:
468 passed, 0 failed, 6 ignored (base 427 + 41). The 41 tests Marvisak#439 adds all
pass; the GPU ones ran on the RTX in two 32-lane halves ("split true").
VICTORY_WARP=1: 467 passed, 1 failed, 6 ignored; the failure is
valu_tests::v_cndmask_on_an_untracked_mask_tests_this_lanes_bit, which
fails on the base too (a fixed-WaveSize pipeline on WARP). victory-shader
lib tests listed: 204 -> 244 (Marvisak#439 adds 40 there and 1 in victory-gpu).
cargo clippy --workspace --all-targets -D warnings and cargo xtask policy
clean.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
KainanP added a commit to KainanP/VIctory that referenced this pull request Nov 24, 2026
…visak#320, Marvisak#439) with the GPU line

Both lines start from the Marvisak#160 merge (b821b31). One conflict, in
crates/victory-gpu/src/shader_cache.rs tests: the GPU line (Marvisak#1439) adds
`a_cache_that_cannot_keep_an_entry_still_gives_the_translation`, the wave64 line (Marvisak#439)
adds `keys_tell_hosts_wave_sizes_apart`, at the same place. Both kept as separate
tests (the shared text holds the closing brace and the `#[test]` attribute).

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Needs rebase. This PR does not merge cleanly into current main (ac2525d). Conflicting files: crates/victory-shader/src/emit/host.rs, crates/victory-shader/src/emit/lower.rs, crates/victory-shader/src/emit/mod.rs.

The content has not been reviewed yet; it will be once the branch is rebased onto main.


Generated by Claude Code

r4tedx added a commit to r4tedx/VIctory that referenced this pull request Nov 25, 2026
The two reference draws create a host and draw on the hardware adapter
and WARP without `valu_tests::ONE_AT_A_TIME`, so on CI's WARP adapter
they could dispatch at the same time as the other GPU tests; the run on
6ddbdfc ended with the victory-shader test process dying with
STATUS_ACCESS_VIOLATION and no failing test named, the crash seen before
on Marvisak#704, Marvisak#160 and Marvisak#265 for that reason.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@r4tedx

r4tedx commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Closing this rather than rebasing it. main moved 319 commits on and got its own lowering of the image forms this title uses from other PRs; what is left of this one is unused by the title. The change is not wrong.

By count. Local title data (v1.0.2.1, the main shader archive), offline, CPU only; counts and reasons only.

  • Offline count on main 940d32f (translate --validate --list, 25,889 programs counted): 23,918 validate; the translator refuses 298, under 10 reasons. None names an image instruction.
  • Disassembly passes by main's own binary over the archive's 26,503 containers (all 26,084 programs decode): every image sample, gather, load and store instruction the title uses occurs in programs that validate on main, the 16 containers with image_gather4_l and the 16 with image_gather4_l_o included. The forms this PR adds beyond that do not occur: no offset form other than image_sample_o (4 containers), image_gather4_lz_o (6) and image_gather4_l_o, no comparison form other than image_sample_c_lz, no _cd, no _g16, no level clamp without derivatives, and every image_store writes all four channels.

By what is read. A count cannot show whether main reads the right texels, so this PR's GPU tests were ported onto main 940d32f without its lowering and run on WARP (one test thread; no hardware GPU):

  • The forms the title uses read the texels this PR's tests expect: image_sample_b, _l at per-lane levels, _lz, _d, _d_cl, _c_lz, image_gather4_lz and image_gather4_lz_o (offset known and per lane), 9 of 9 cases; and gathers at a level in the form main takes (immediate border sampler, whole level), gather4_l_o per lane and gather4_l at levels past the last, 2 of 2.
  • 80 cases are refused by main, each with a reason (<mnemonic> is not supported, a gather at a level through a sampler from memory, an image store of some channels). Refused, not mis-read; and per the count the title has none of them.
  • One form reads wrong on main: image_sample_d with 16-bit addresses (a16). main packs the derivatives two per register along with the coordinates; this PR keeps derivatives as 32-bit floats and packs only coordinates and level, which is what LLVM's assembler tests have for GFX10 (image_sample_d … dim:SQ_RSRC_IMG_2D a16 takes five address registers, and the _g16 opcodes exist for 16-bit derivatives). On main the test reads level 3's texel (0,0) in 32 of 32 lanes where the footprint's texel is expected, and the decoder counts 3 address dwords for 5. The title does not use it: none of its 2,901 containers with image_sample_d and none of the 29 with image_sample_d_cl has a16. So I am not opening a PR for it. The ported tests and a 35-line fix are on the fork, branch check/image-tests-on-main (4467705 tests on main as it is, f85e0ab the fix, 63c2d06 the gather test); with the fix the case passes. If a maintainer wants that as a PR, say so here and I will send it. Not checked against the console's own compiler or hardware.

@upipibi thank you for the in-world evidence. The case you describe, the culling's 4×4 block of the depth pyramid read with one image_gather4_l and three image_gather4_l_o at a named level, is what main's own gather at a level now covers: the 16 containers with those instructions validate on main, and this PR's footprint test, adapted to main's form, passes there. So that fix no longer needs this PR. What main still refuses is a gather at a level through a sampler read from memory, which the title does not have.

Limits. The count and the passes cover one archive, not shaders elsewhere in the title. A refused program reports only its first reason, so a refused image form could still sit behind another reason in the programs main refuses at emit; by instruction name there is none. All test results are from WARP.

The branch shader/image-sampling-family stays on the fork at 5ce85c5; if a program turns up that needs one of its forms, I will reopen this on current main.

Thank you to everyone who tested and measured this head.

AI-assisted

@r4tedx r4tedx closed this Nov 25, 2026
alex3112 pushed a commit to alex3112/VIctory that referenced this pull request Nov 25, 2026
…IL validator failures) into the integration

Its fixes are already here (a16 biased samples from Marvisak#138/Marvisak#160, the centroid position under conservative depth, one interpolation mode per packed row, signature parts in the validator's order), and compute samples take quad gradients (Marvisak#180) instead of validator 1.8. The code stays ours; three of the PR's tests are taken (conservative depth, signature order within a row, the a16 biased sample) and pass. Its tests of harmonize_row_interp and of dx.valver 1.8 test code that is not taken.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.