Repository navigation
Shaders, GPU: unknown-stride buffers are read through a raw view of the same bytes (stacked on #193) - #704
Shaders, GPU: unknown-stride buffers are read through a raw view of the same bytes (stacked on #193)#704r4tedx wants to merge 13 commits into
Conversation
… names A buffer read whose element stride is not known at translation takes a raw handle and a byte offset from the runtime stride table. The handle was of the slot the title's view is in, and a raw handle over a structured or typed view is undefined in D3D12: for the load of [index 2, offset 4] an RTX 5070 reads dword 21 of a structured view of 12 bytes (dword 7 asked for) and dword 36 of one of 16 bytes or a typed RGBA32F one (dword 9 asked for), where a Radeon and WARP read the bytes asked for. No handle of another kind is right everywhere either: with a structured handle whose declared stride differs from the view's, the RTX 5070 addresses by the view's stride and the Radeon and WARP by the declared one. The table's entry per slot is now a StrideEntry of two dwords: the stride, and the heap slot holding a raw view of the bytes the slot's view reads (none: the slot's own view is raw), with the bytes from that raw view's start to the view's first byte (raw views start on 16 bytes on the host). The shader reads, stores and runs atomics through a raw handle of the slot named, so the handle's kind always matches the view. RawWindow gives the host the raw view for a byte range. The GPU side writes the new entries without raw slots yet, which reads as before. The test binds raw, structured (12, 16, 20 bytes) and typed (RGBA32F, R32_UINT) views, as shader views for the load and as unordered access views for the store and the atomics, with their raw views beside them, on the hardware adapter and WARP; a second one takes the descriptor from a join of two loads. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The programs that read a buffer without a known stride pick its heap slot at run time, so the runtime stride table has to be looked up by the slot the shader computes, and the view in it can differ from one thread group to the next. A new test loads the heap slot from a buffer per thread group (a scalar load whose offset is the loaded value), with a structured view of 12 bytes in one slot and one of 16 bytes in the other: the four lanes of each group read the bytes of the view their group chose, in one dispatch and again with the choice swapped. A lane reading past the three elements of the first view reads zero, not the buffer's next bytes. The test host's raw views now cover a window of the buffer (as RawWindow gives the host for a view's elements) rather than all of it, which is what ends the read there; the view kinds test takes its raw views and entries from the same function, with views starting 4 and 12 bytes into their raw views. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ide reads A shader that reads a buffer without knowing its stride takes a raw handle of the slot the runtime stride table names. The host heap now makes that slot: when it makes a structured or typed buffer view (for a shader or for unordered access), it also makes a raw view of the same bytes of the same host copy in a pool of 65,536 slots after the dynamic ones, and writes the slot, the stride and the bytes from the raw view's start to the view's first byte (raw views start on 16 bytes) into the slot's entry. A raw view keeps its own slot. The raw view ends with the view's last element, so reads past it give zeros. The entry and the raw view are written wherever the slot's descriptor is (tables made for a draw, title slots a draw reads through a table, slots made null), so they are as current as the descriptor; a slot made again reuses its raw view slot, and one made null, raw or constant, or a dynamic slot given back, returns it to the pool. Views the host cannot make raw (starting off a dword of the copy, or with the pool full) point at a null raw view and are logged once. The test makes placed structured, typed and raw views in a host heap and runs the translated program of victory-shader's run-time slot test on it: each thread group reads the bytes of the view in the slot it chose, zeros past the view's end, and the new view's bytes after the slots are made again. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
LAKSHYA-cmd-tech
left a comment
There was a problem hiding this comment.
Tested and verified on Windows 11 MSVC (Rust 1.98.1).
- \unknown_stride_reads_reach_the_bytes_of_the_view_in_the_slot\ passes on hardware D3D12 and WARP.
- 3/3 unknown stride tests pass in \�ictory-shader\ (\unknown_stride_views_chosen_by_a_loaded_heap_index, \unknown_stride_descriptor_chosen_by_control_flow, \structured_buffer_unknown_stride_uses_runtime_stride_table).
- Pairing structured/typed buffer views with dedicated raw views resolves the Nvidia DXIL driver discrepancy where raw handles previously read stride-scaled or out-of-bounds offsets.
- Verified release order fix (\4e03086) ensuring table entries and raw views are wiped prior to freeing dynamic descriptor slots.
- Fully compliant with asset policy (\cargo xtask policy\ ok: 152 files).
main moved under Marvisak#193 and this branch. One conflict, in HostHeap::new (descriptor/host.rs): Marvisak#336 tries the heap with DYNAMIC dynamic slots, then with MIN_DYNAMIC, then capped, and records the range it got in `dynamic`; this branch puts ALIASES raw-view slots after the dynamic ones. Both kept: each attempt asks for the alias slots too, the capped count leaves room for them, the lease bitmap has `extra` entries as on main, and `alias_base` stays `count + extra`. A merge rather than a rebase so Marvisak#193's commits keep their ids. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
catminou4
left a comment
There was a problem hiding this comment.
Merges cleanly with current main (7374bfb) — verified locally.
cargo test -p victory-shader --locked on macOS 26 arm64 / rustc 1.98.1 after merging main: 68 passed / 0 failed / 1 ignored (+4 ungated shader tests vs main's 64). The unknown-stride raw-view path compiles and the portable lowering tests pass here.
The bulk of the change is GPU-side (descriptor.rs, descriptor/host.rs, raw_view_tests.rs, draw.rs, pipeline/host.rs — +1872), which I can't build or run on macOS; the new raw_view_tests need the Windows D3D12 backend. Not approving a mostly-GPU PR on shader-crate evidence alone, but the portable part is verified green.
|
Measured offline against main
AI-assisted. |
|
Re:
We investigated the resulting GPU hangs in #619 and #625 (where pixel shaders \633c1f8872ed8c6d\ and \ef9b757c9c1e4b26\ hit [heap 330192: null]\ via dynamically indexed root constants \u8 = 0xa13a00). We have solved this in branch \ix/mirror-buffer-views-for-dynamic-indexing: Combined with your raw-view aliasing for unknown strides in this PR, dynamically indexed structured buffer loads will resolve to valid descriptors rather than null slots! |
|
@iurysf thank you, that is the first count of this branch over the title's shaders: all 71 @LAKSHYA-cmd-tech thank you for following the null slot down to
There is a branch for this gap on top of this PR:
If you can run the title with diagnostics, the useful numbers would be, for The title was not used in these tests. AI-assisted. |
…clamps, and non-multiple-of-4 stride refusal
main now has CI (clippy with -D warnings, then the workspace's tests). No conflict; both of CI's clippy commands are clean on the result. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ew-kinds Marvisak#193 moved: buffer views are clamped to what is left of the host copy, a shader that reads the stride table without a host view heap is not run, and a known stride that is no multiple of four is refused. Conflicts were with main, not with this branch's change: `bind` already returns whether the draw may run (Marvisak#336), with its doc comment and the dropped counter, and main already renamed the second test module in host.rs. main's side kept in all three; Marvisak#193's `return false` in the stride-table branch is in. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
Tested this branch ( A buffer view of zero elements removes the device. About a minute in, still in the loading screens, the device was removed with A guard in if buffer.NumElements == 0 {
once!("unordered buffer view of no elements made null");
return None;
}(same in Results with the guard:
A merge note with #483: #483's guard slot and this branch's alias pool both start at I haven't tried I'm testing with Claude's help, and Claude drafted this comment. |
# Conflicts: # crates/victory-gpu/src/descriptor/host.rs # crates/victory-shader/src/emit/mod.rs
Brings in Marvisak#704/Marvisak#193 raw-view stride table and VSH3 cache, Marvisak#329 PSV record counts, and precise copy invalidation. Kept Marvisak#54's host wave range and Marvisak#298's spilled-mask resolution; Parts now carries psv, options and host_waves, and test initializers cover all three.
|
Measured on the full retail shader pack (26,503 containers) with
|
|
Correction and disclosure for my three comments above (1, 2, 3) They end with "AI-assisted (Claude Code)", but HY4 Flash (
The follow-up and combined runs had translate processes competing for the CPU, so treat their times as upper bounds. The counts are not affected by that.
This correction: Claude Code (Claude Opus 5.5); every figure was recomputed from the original files on my machine. |
…arvisak#1511 - emit/mod.rs: both sides append tests after the end of `mod tests`; the bundle also closes `mod tests` and adds `mod barycentric_tests` there. Resolved as: the bundle's tests, then Marvisak#704's tests, then the end of `mod tests`, then `mod barycentric_tests`. No shared function names. - Marvisak#704 adds `HostShader::stride_table`. Two test-only initializers that came with the bundle had no such field (git saw no conflict there): `shader.rs` tests (hand-built DXIL, no stride table: `false`) and `root_view_tests.rs` (a translated program: `lowered.stride_table`, as Marvisak#704's own code does).
…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.
Marvisak#704 + Marvisak#1511 - emit/mod.rs: the bundle structures the program before tracking resources (resource::track takes the structure since the bundle); Marvisak#309 forwards spilled SGPRs, which rewrites the IR. Order kept: forward, then structure, then track. - emit/wave.rs: no conflict on this Marvisak#1511 head. On the previous bundle (which carried Marvisak#98's v_permlane16 tests) both sides added tests at the end of the module and the bundle's side was closed before Marvisak#309's tests; without Marvisak#98 git merges the two test lists itself, with Marvisak#309's tests as separate items of `mod tests` (not nested). - sgpr_spill.rs (new in Marvisak#309, no textual conflict): its test helper called resource::track with the old 3-argument signature; adapted to the bundle's (structure first, passed to track). Test-only change.
…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>
…ps, footprints) onto Marvisak#1418 + shader stack Conflicts in crates/victory-gpu/src/descriptor/host.rs: 1. `dynamic`: the warning for a full dynamic-slot heap; Marvisak#1426 adds the free-slot counts (`free_space`, which it brings). Took Marvisak#1426's. 2. buffer SRV views off a host copy: the stack (Marvisak#704) clamps NumElements to what the host copy holds and refuses an empty view; Marvisak#1426 refuses a raw view whose first element is not on 16 bytes. Independent guards: both kept, clamp first. The UAV function, merged without conflict, already has both.
…, 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>
…6B16A16_FLOAT) onto Marvisak#211 + Marvisak#1024 + Marvisak#346 + Marvisak#334 + integ/next Conflicts, both in tests: 1. crates/victory-gpu/src/descriptor/host.rs: the stack's tests (`raw_views_start_on_16_bytes` and the raw/structured view tests after it, from Marvisak#1426/Marvisak#704) and Marvisak#492's four `rgb9e5_srv_*` tests at the same place; git interleaved them over shared lines (a resource description's `SampleDesc`, a closing brace), so the two hunks are not separable texts. Resolved by keeping the stack's tests exactly as they were and adding Marvisak#492's four tests whole, as Marvisak#492 has them, before `dynamic_slots_are_held_until_released` (where Marvisak#492 put them). The resulting diff of the file against the previous head equals Marvisak#492's own (+235/-5 against main). 2. crates/victory-gpu/src/resource.rs: the stack's `get_desc_reports_the_allocated_mip_chain` and Marvisak#492's `r9g9b9e5_target_format_substitutes_rgba16f` / `r9g9b9e5_render_target_and_uav_textures_create_on_host` at the end of the module. The shared text holds the `#[test]` before and the closing braces after: the stack's test is closed in the hunk and Marvisak#492's follow as separate tests (not nested). The non-test changes (`target_format`, `fits` taking a resource description, `fits_texture_srv`, RTV and pipeline formats) merged without conflict. `fits` has no other caller in the stack. Uploads from title memory still skip render-target/UAV textures (`texture::title_written`), so no 4-byte RGB9E5 rows are detiled into a substituted 8-byte texture. Known open point from the review, not fixed by Marvisak#492: a copy between a substituted target and a sampled-only RGB9E5 texture would mismatch formats on the host; no report shows the title doing that. No non-textual fix needed (cargo check --all-targets --all-features).
…sak#709 on Marvisak#1077's root UAVs Marvisak#709's test used Marvisak#294's Root::Uav; this host binds a zeroed root UAV (SetComputeRootUnorderedAccessView) and reads it back after the views' UAVs. Also the fork's track() signature, and stride-0 structured accesses keep the fork's runtime stride-table view (Marvisak#193/Marvisak#704) after Marvisak#709's structured(). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@r4tedx, here are the raw rows you asked for in item 3: https://gist.github.com/PigBun-AI/6d0fb698dd5dfb3d62c83b4dbc723533. Start with README.md. On the RTX 5090, a raw declaration with no index (buffer_load ... offen) over a structured SRV view reads wrong at strides 8, 12, 16, 24, 32, 48 and 64 and right at 4, 20 and 2044 (stride 16 stays wrong with the buffer in a default heap, with a view starting at element 4, and with a view shorter than the buffer); with a raw view every stride reads right. Controls (WARP, Radeon iGPU) are in the gist. These are synthetic probes, one run per case, one machine (driver version not recorded). We have not yet tested scalar s_buffer_load of a structured SRV, the other form you named; we will add that to the gist when we have it. AI-assisted comment (PigBun-AI). |
|
@r4tedx, follow-up: we added the scalar form to the gist (table-5090-scalar-smem.csv and scalar-smem-addendum.md). On the RTX 5090, a scalar s_buffer_load (immediate offset, x4, and SGPR-offset forms) with a raw declaration over a structured SRV view reads wrong at the same strides as the unindexed buffer_load: 8, 12, 16, 24, 32, 48, 64, and right at 4, 20, 2044, with the same apparent multipliers; with a raw view every case is right; Radeon iGPU and WARP controls are right everywhere. Synthetic probes, one run, one machine; we have not tested unaligned or loop-computed offsets. AI-assisted comment (PigBun-AI). |
|
RTX 5060 Ti (32-lane waves), offline over the retail shaders at
Per program, no compute program that had a working pipeline on
Not tested: the title with this PR (on this card AI use: Claude Code (Claude Opus 5.5) built, measured and wrote this; checked by mrejecutor. |
…, bounded (VIctory #193, #704)
A program that reads a buffer by element (idxen) without a stride known
at translation was refused ("a structured buffer of unknown stride",
three sites in emit/lower/buffer.rs): 179 programs of the pack (177
compute, 2 pixel), 210 draws and dispatches a frame in the Series S
world. With XTP_STRIDE_TABLE=1 they translate and read the view the
title binds at run time.
Shader side: Target.stride_table (off in Target::ANY, in Target::key);
the host's table at t0/space2 (STRIDE_SPACE), one StrideEntry of 8 bytes
per view-heap slot; RawWindow::covering; stride_entry and runtime_view
in descriptor.rs; loads, stores and atomics by element read the entry of
the slot they compute and access the raw view it names.
GPU side: each view heap keeps the table (upload memory) and 2^16 more
slots for raw views, counted in NVIDIA's 1,000,000 (taken from the
title's part of a capped heap); every descriptor write writes the
slot's entry with it, a structured or typed buffer view gets a raw view
of the same bytes; a root SRV at t0/space2 in each stage that reads it;
draw.rs binds it at each bind and drops the draw or dispatch when the
view heap has no table; shader cache VSH2 with the field.
Critical review (what was changed, not ported as is):
- An entry of zeros meant "the slot itself" upstream: a null, texture or
constant slot (and every slot of a table of zeros) was read through a
raw handle, a kind mismatch the hardware does not survive in general.
Here zeros hold no view: the access is not made (loads 0, stores and
atomics dropped). Raw views name their own slot.
- Bounds (producers' item 1, watch.md item 84): upstream accessed
index*stride + off + bias unchecked, so an index whose product wraps,
or off + width > stride, reached the bytes the raw view holds before
the view (up to 12) or the next element. The entry now carries the
view's element count (low dword: count, bias/4; high dword: stride/4,
raw slot), and an access is made only at an element below it and
inside the element (a raw view: inside its bytes), as the console's
range checks do.
- Table races (item 2): upstream wrote the two dwords of an entry apart
from the CPU while lists read them, and remade a raw view in place or
for another slot at once. Here an entry is one 64-bit store, a changed
view gets a raw view in another pool slot, and a raw view given back
waits (with its host buffer held) until every recording that read the
table before has gone, after its submissions (StrideHold, per heap,
taken at the first bind). The slot's own descriptor and entry are
rewritten in place, as the title's descriptor is.
- Release order: entries and raw views of dynamic slots are cleared
before the slots are free (#704, 4e03086 by MichaelSmithAI).
- Buffer views are cut to their host copy and refused when the host
would refuse them (past its end, no elements, a stride over 2048 or
off 4, typeless without the raw flag): VIctory #193's f99b792 clamp,
whose remaining count ignored the title's first element, and the
buffer_view_ok of fxceless's VIctory fork (commit 578d459).
- #704 logged and ran a draw without the table; dropped here, as #193's
head does.
- A raw view in the slot reads at the offset alone (stride 0: the
console's descriptor of no stride), not index * 4.
- Switch off by default (item 4): no upstream run was safe (DEVICE_HUNG
after 111 s; zeros on NVIDIA with #193 alone).
- Not fixed here: slots reached only by an index loaded at run time
stay null views until a draw names them through a table (mirror zeros,
item 3; r4tedx's gpu/run-time-indexed-views); the PCIe cost of reading
the table from upload memory is not measured yet.
Tests (WARP): emit/stride_tests.rs (strides 4, 12, 16, 20, typed, raw,
views off 16 bytes, range checks with a wrapping index and the next
element, an entry of zeros, a slot loaded at run time, the switch);
descriptor/host.rs (entries follow the views, raw views kept while a
list may read them, views cut to their copy, a translated program run
through a real heap's table); draw.rs (a missing table drops the draw).
Mechanical fixes outside the task's files: the new Target field in
literals of apps/xtp/src/survey.rs, apps/xtp/src/translate.rs,
emit/lane_read_loop_tests.rs, emit/loop_limit_tests.rs,
emit/lower/tests.rs, emit/lower/uniform.rs, emit/mesh_tests.rs,
emit/split_tests.rs; the new HostShader field in emit/valu_tests.rs and
emit/waterfall_tests.rs.
Ported from Marvisak/VIctory#193 (head f99b792) by n-romanovich
Ported from Marvisak/VIctory#704 (head 1f3c184) by r4tedx, with its
release-order fix 4e03086 by MichaelSmithAI (its test, fb8ea43, is not
ported: here the entries are cleared in release_all itself, before the
slots' lock, so no other list can lease them in between)
Ported from fxceless's VIctory fork (commit 578d459) by fxceless (its
buffer_view_ok's checks, in fit_view)
|
@r4tedx, one more data set added to the gist (table-5090-more-strides.csv and more-strides-addendum.md): the same raw-declared / structured-view probe at strides 28, 44, 76, 100, 772 and 1580 on the RTX 5090. These read right, like strides 4, 20 and 2044; strides 8, 12, 16, 24, 32, 36, 40, 48 and 64 read wrong, all five read forms (scalar immediate / x4 / SGPR offset, MUBUF with and without index) agree, and a raw view is right everywhere. So the unindexed/scalar fix may only need to touch the strides that read wrong, though we only tested the listed strides. Synthetic probes, one run, one machine; Radeon iGPU and WARP controls are right everywhere. AI-assisted comment (PigBun-AI). |
Where a fork-only change duplicates upstream's own version of a feature, upstream's is kept and the fork's dropped: - victory-shader is upstream's crate with the fork-only merges replayed onto it oldest first; those that do not apply onto upstream are dropped (37 of 63: among them Marvisak#704/raw views, gather4_l, the lane-mask and Marvisak#308 ports, Marvisak#947, Marvisak#1022, Marvisak#1112, Marvisak#1090, Marvisak#1182). Marvisak#284 (legacy fused madds) and Marvisak#98 (permlane16 in whole-wave sections) are dropped too: the first disagrees with upstream's hardware-checked model, the second refused 46 programs upstream translates. - translate: upstream's --cache replaces Marvisak#254's write-cache and work queue; Marvisak#378, Marvisak#517, Marvisak#673 and the victory.toml console are re-applied. - victory-gpu: upstream's stride table, page table and heap views replace the fork's Marvisak#704/stride-table wiring; fork-only fixes re-applied on top. Package (shaders.rpf, translate --validate --list, counts): vertex/pixel emitted 12559 -> 14295 of 14337, compute 2359 -> 2628 validated, mesh 2730 -> 2811 validated. Tests: the failures left (rect fourth corner, two stride tests, row order, gather4 at a level, memory table, dynamic heap slots) fail on upstream main as well on this host. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Automated triage for the maintainers. Closing because this change is already in Unknown-stride buffers are read through a host stride table in main (emit::VIEW_STRIDES, root SRV t255, HostHeap strides; commit 0b35b7f); this 1,921-line stack on #193 does the same another way. If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution. |
|
Automated triage for the maintainers. Needs rebase. This PR does not merge cleanly into current The content has not been reviewed yet; it will be once the branch is rebased onto Generated by Claude Code |
|
Thanks for the triage.
Byte B reads as byte B × 3, then past the view's end it reads 0. That's the same pattern as this PR's table ("structured, 12: expected 107, RTX 5070 121") and what testers reported here on an RTX 3080 (justlovett0: "without [the raw alias views] the ByteAddressBuffer reads return 0 against structured host views"), an RTX 5090 (PigBun-AI's gist: strides 8, 12, 16, 24, 32, 48 and 64 wrong, 4, 20 and 2044 right) and a 4070 Ti. WARP and AMD read the bytes asked for, which is why the test passes there. What this PR adds on top of a stride table is the fix: a raw view of the same bytes for every structured or typed buffer view, with the read going through that view, so the handle's kind matches the view it resolves to. I'm happy to redo it on current The title was not used for this check; it's AI-assisted (Claude Code). |
|
Follow-up: the structured-view half of this is now in #1762 (structured buffer views made raw on the host), on current AI-assisted (Claude Code). |
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>
Current head
1f3c184, integrated withmainatffe310e.1f3c184makes the three unknown-stride GPU tests take the shared one-at-a-time lock. Without it,VICTORY_WARP=1 cargo test -p victory-shader --libcrashed with an access violation in 2 of 4 local runs, as CI did on505d5b1. With it, 6 of 6 runs passed.505d5b1is the same tree as7f77cca, re-authored with the GitHub no-reply address. When a waterfall descriptor load selects a different raw alias per lane, the generated heap handle now carries the nonuniform flag. The stride table on this branch still uses register space 2. Downstream stacks that also use space 2 for root addresses need the remapping described in the comments. Local Windows verification:cargo test --workspace --locked(348 passed, 6 ignored) and all-target, all-feature Clippy with warnings denied. No title run for this update. AI-assisted (Codex).Stacked on #193 (its head
4322b61, merged withmaind2a4bae). Five commits on top are the change:fc07d59,5708fa1,30a93f9, and4e03086andfb8ea43by MichaelSmithAI (a release-order fix and its test, below). If #193 is merged first this rebases to those five; its author is welcome to take them into #193 instead.Merged with
main7374bfb(headd5b23e1, 2026-11-24). #336 landed and conflicted with #193 and this branch inHostHeap::new:mainnow tries the heap withDYNAMICdynamic slots, thenMIN_DYNAMIC, then capped. The merge keeps that and asks for the alias (raw-view) slots on top in each attempt; the capped count leaves room for them. It is a merge commit so #193's commits keep their ids. Atd5b23e1:cargo test -p victory-gpu50 passed, 1 ignored;cargo test -p victory-shader82 passed, 1 ignored (RTX 5070). Not exercised: theMIN_DYNAMICand capped paths, which need a title-sized heap.What
#193 lets a program whose structured buffer has no stride known at translation read it through a raw (
ByteAddressBuffer) handle, at a byte offset computed from a run-time stride table. Four reviewers showed that this returns wrong data on NVIDIA whenever the heap slot holds a structured or typed view, which is what a title's structured buffer is: the raw handle resolves to the view the title made, not to a raw view.This PR makes the read go through a raw view of the same bytes, so the handle's kind always matches the view it resolves to.
StrideEntry): the stride, then the heap slot that holds a raw view of the same bytes (plus one; 0 means the slot itself is raw), with a 4-bit byte bias on top.index * stride + offset + bias. Loads, stores and atomics share the path.HostHeapmakes a structured or typed buffer view (SRV or UAV), it also makes a raw view of the same bytes in a pool of 65,536 slots after the dynamic ones, and writes the entry. Raw views keep their own slot. Remaking a slot reuses its pool slot; a null, raw or constant view, or a released dynamic slot, returns it. The entry is written wherever the slot's descriptor is written, so it is as current as the descriptor.4e03086, from Clear retired view metadata before reusing descriptor slots r4tedx/VIctory#7): when a list gives its dynamic slots back, their table entries and raw views are cleared before the slots are marked free.30a93f9did it the other way round, in two separate lock scopes, so another list could lease a slot, write its entry, and have it wiped by the retiring list.fb8ea43(from Test dynamic slot reuse during alias retirement r4tedx/VIctory#8) tests it without a scheduler race: it leases the whole dynamic pool, then asks the allocator for a slot at the start of the last slot's cleanup, which must fail until the cleanup is done. With the old order restored the test fails here (the slot is leased during cleanup); with the fix it passes.Why not pick the handle kind in the shader
That was the first design tried, and it does not hold. Probed here with
dxil.dllvalidating, on a buffer whose dword i holds 100 + i:0the reviewers reported.Values loaded:
[index 2, offset 4]"Before" is #193's lowering with only the view changed. Stores and atomics through a UAV of each kind were already right on all three adapters and still are; they are now asserted. The Radeon column comes from a local patch that runs the tests on every adapter; this base has no adapter switch, so it is not in the commits.
Measured on the title's shaders (by a tester)
iurysf ran
victory translate --list --validateover the title'sshaders.rpfand executable (26,096 programs, dxil.dll 1.9.2602.17),mainc2e7254against this branch, program by program (comment): translation failures 3,734 to 3,663. All 71a structured buffer of unknown strideprograms translate; 70 validate, and one compute module is rejected withincompatible with the shader stage, the implicit-derivative case #306 fixes. No program that emitted or validated onmaingets worse. This counts translation only: it says nothing about what the programs read when they run.elamriz ran an in-game A/B on an RTX 4070 Ti (driver 621.14), comparing #439
c153b21+ #322 with and without this PR's delta at7f77cca, under D3D12 Debug and DRED (comment). With the baseline, all seven compute producers from their #638 report stopped on the unknown-stride refusal. With this PR, all seven loggedshader translated. Both runs ended inDEVICE_HUNGinsideDispatchMesh, as the baseline did. This verifies translation only. What the programs read is still unverified.On h0useadv's #293 stack (
ffe310e+ #180 + the lane-mask branch + #305 + #160), this PR adds 116 validated programs (113 compute) and loses none.a structured buffer of unknown stridegoes from 174 to 0. This was an offline census of the title'sshaders.rpfwith local title data. The merged branch istesters/293-stack-with-704(comment).Cecerw ran
cargo test --workspaceon an RTX 3060 Ti at1f3c184: 348 passed, 0 failed, 6 ignored, against 342 / 0 / 6 onmain(comment). bittertea0323's offline count onffe310efounda structured buffer of unknown stride148 → 0 and +39 programs emitting DXIL, 36 of them compute.NuraadGit ran 12-minute title runs on an RTX 2080 (JMAN730's fork + #493 + #189 + #206 + #667; three runs without this PR, one with it) (comment). Title memory copied per frame was 203 MB with this PR against 215–238 MB without it. Draws and dispatches dropped for lack of a host pipeline fell from 845–891 to 704 per frame, and programs refused from 383–390 to 343. Frame time was 7–11% higher in the one run with it. The four instance-culling programs stay refused in that stack (by #189), so this doesn't measure their bindings.
justlovett0 checked it on an RTX 3080 (Windows 10, driver 621.24) with and without the raw-alias slots (comment, details on #193). Without them, #193's
ByteAddressBufferreads return 0 against structured host views. With them, the unknown-stride class is gone at runtime.Slots reached only by a run-time index (below) have a follow-up branch that is not part of this PR:
gpu/run-time-indexed-views.Not verified, and what this does not fix
make's shadow and skipping unchanged aliases would remove most of it (details).d5b23e1) onto the tester tree at update 5 plus fork PR loader: emulate AMD-only instructions on Intel CPUs #10 and ran it in the title on an RTX 5060 Ti (comment). All four runtime-identified instance-culling programs translated and got host pipelines, and the device then hung on a compute dispatch after 111 s. The same tree without this PR has run 10+ minutes on other cards. That is one run, on another card and heap layout, and from before Shaders, GPU: add runtime stride table for structured buffers #193's zero-element guard, so it does not show that this PR causes a hang. A run withVICTORY_SKIP_PIPELINESset to those four hashes would separate it. Until then, translating these programs should not be read as their running correctly. notquiteog later skipped producers one at a time on the tester tree's update 9 (RTX 5060 Ti) (comment). TheDEVICE_HUNGmoved to the next of the seven producers each time, always a ~5 s single-list compute submission with the same root layout. So the hang follows what that family shares, such as a buffer it reads or a slot reached only by a run-time index, not one program's code.HostHeap::mirrormakes buffer views only for draws, that is, for slots a dispatch names through its tables. A buffer view the title writes into a slot that a shader reaches only through an index it loads at run time stays a null view with a zero entry, and its data is not refreshed (shadow.rssays so in ashortcut:). That is the state ofmain, not something this PR changes, and it matters: testers report that the instance-culling compute programs behind the world's geometry pick their structured buffer exactly that way. This PR is necessary for them, not sufficient.a structured buffer of unknown stride117 → 0, 71 programs translating (EduAzevedo); the lowering here refuses nothing Shaders, GPU: add runtime stride table for structured buffers #193 accepted, as far as the tests show.1f3c184: victory-shader 124 passed and victory-gpu 55 passed, includingraw_view_tests, with no debug-layer errors or warnings (comment). Not exercised: GPU-based validation; views on buffer resource objects (the GPU test uses placed views); pool exhaustion; a view that starts off a dword of its host copy; a heap capped at 1,000,000 views (the pool takes 65,536 more slots there); stages other than compute; the cost of one more table read per access and one more view per structured or typed buffer view.draw.rsstill logs and continues when the table cannot be bound, as in Shaders, GPU: add runtime stride table for structured buffers #193.shortcut:comments added: an access whose offset plus width passes the element's end reaches the next element, where the console reads zeros; the pool size is a guess, and views beyond it read zeros with a one-time warning; a view starting off a dword gets a null raw view; the raw view starts up to 12 bytes early and ends on the dword holding the last byte.Tested
Windows 11, NVIDIA RTX 5070 and WARP, hand-assembled programs only:
structured_buffer_unknown_stride_uses_runtime_stride_table(Shaders, GPU: add runtime stride table for structured buffers #193's test, rewritten): raw, structured 12 / 16 / 20 and typed views in the slot each load the expected value, on the hardware adapter and WARP; stores and atomics through UAVs of each kind. With the raw views switched off it fails on the RTX 5070 with 121 for 107.unknown_stride_views_chosen_by_a_loaded_heap_index: the heap slot is loaded from a buffer per thread group, with a 12-byte structured view in one slot and a 16-byte one in the other; each group's lanes read the bytes of the view their group chose, and a lane past the chosen view's elements reads zero.unknown_stride_descriptor_chosen_by_control_flow, and unit tests of the entry and window arithmetic.victory-gpu:unknown_stride_reads_reach_the_bytes_of_the_view_in_the_slotmakes placed structured, typed and raw views in a realHostHeap, runs the translated run-time-index program on it, and rebinds slots.cargo test -p victory-shader: 73 passed.cargo test -p victory-gpu: 44 passed, 1 ignored. In full-workspace runsframe::tests::waits_end_on_ticks_and_count_frames, a frame-clock timing test this PR does not touch, fails intermittently here; it also fails on plainmainin full runs and passes alone.cargo clippy -p victory-shader -p victory-gpu --all-targets: one warning, invictory-gpu/src/host.rs, which is onmain.cargo xtask policy: ok.AI-assisted.
🤖 Generated with Claude Code