Repository navigation
Shaders: LDS sub-dword writes, typed buffers at offsets and of some channels, typed loads by index - #1959
Shaders: LDS sub-dword writes, typed buffers at offsets and of some channels, typed loads by index#1959RaghavVijayanand wants to merge 5 commits into
Conversation
|
Automated triage for the maintainers. This pull request no longer merges cleanly into Generated by Claude Code |
888de6c to
40770f9
Compare
catminou4
left a comment
There was a problem hiding this comment.
Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f, cargo test -p victory-shader --locked.
144 passed / 0 failed / 2 ignored. LDS bytes and halves, typed buffers at offsets and of some channels — sub-dword LDS/buffer access completeness; relates to the LDS sub-dword cluster (#632/#116/#101/#571/#996) and #2003's MUBUF d16.
Offline measurement on a retail dumpResult: no count change against I merged head 40770f9 onto No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right. No shader names or data are included, per the asset policy. AI-assisted (Claude Code). |
ds_write_b8/b16 and their d16_hi forms wrote their bits into the dword holding them by an atomic AND, then an atomic OR: lanes writing the same byte or half in one instruction left the OR of their values (the console keeps one), and other lanes could see the part cleared between the two. A write now replaces its bits with a compare-exchange loop on the dword: lanes writing other bytes of the same dword keep theirs, and of lanes writing the same byte one value wins, as on the console. The opcode names of byte and half accesses are decoded in one place for the reads and the writes. Tested by a new module, emit/buffer_lds_tests.rs: a hand-assembled 64-thread (two-wave) program writes bytes and halves of the same dwords from all lanes, every lane a bit into one shared byte, and bytes under an EXEC mask, then reads them back in every width and form. The DXIL passes dxil.dll, and the results match a model of the console's memory on the default hardware adapter and WARP. The test fails with the atomic AND then OR it replaces.
buffer_load_format_* stopped the translation at any offset but 0, and buffer_store_format_xyzw at any instruction or lane offset. The console adds index * stride + offset to the descriptor's base; the host's typed view numbers elements of its format, and DXIL's typed loads and stores take an element, not a byte offset. The access now goes to element index + offset / size, the size the used-resource entry's stride (the console's typed descriptors have their format's size as stride). What stays refused, precisely: a constant offset inside an element, and any offset into a view whose entry has no stride. A computed offset is taken as whole elements (shortcut, in the code). Tested in emit/buffer_lds_tests.rs, with a typed UAV view the host test harness can now start from given data (View::FormatUav): 32 lanes load whole elements of R32G32B32A32_FLOAT and R16G16B16A16_FLOAT views at offsets added the four ways the console adds them (the instruction's to an index, a lane's to an index, a lane's plus a constant SGPR offset, a lane's plus the instruction's), and store elements at an index plus the instruction's offset and at a lane's offset. The DXIL passes dxil.dll and the results match on the default hardware adapter and WARP. The refusals are tested too. The tests fail with the offset ignored and with a computed offset taken as elements.
buffer_store_format_x, _xy and _xyz (and their d16 forms) stopped the translation: DXIL typed stores must write all four channels (dxil.dll refuses a partial write mask on a typed UAV), while the console writes the channels it is given. Such a store now loads the element (a typed UAV load), keeps the channels it is not given, and stores all four, the load and store under the same EXEC guard. Shortcut, in the code: the channels not given are taken to keep what memory holds, which this does not confirm on the console. They round-trip through floats (exact for float and unorm formats), and the load and store are not atomic with other lanes' stores to the same element. Tested in emit/buffer_lds_tests.rs: 32 lanes store x, xy, xyz (even lanes only, by EXEC alone) and two halves (d16_xy) into elements of R32G32B32A32_FLOAT and R16G16B16A16_FLOAT views filled with known data. The DXIL passes dxil.dll and every channel matches on the default hardware adapter and WARP. The test fails with the kept channels zeroed and with the store's EXEC guard dropped.
tbuffer_load_format_* with idxen stopped the translation. The console adds index * stride to the byte offset, the stride the descriptor's; the load now reads its raw view at that byte, as without an index. Typed-format loads read raw views, so they now take the index the way raw buffer accesses do: a descriptor built in the code around a root view has its stride in the bits OR-ed into dword 1 (0 too: the console then ignores the index), and a descriptor taken from the resource heap (no used-resource entry) the view's stride from the host's view-stride table. A built descriptor elsewhere takes its own stride too; one from a table its used-resource entry's (shortcut, in the code: taken to be the descriptor's, as for structured buffers). Refused: an entry without a stride, and a built descriptor with swizzled addressing or the lane index added (dword 1 bits 30-31, dword 3 bit 23; the lane-index refusal now covers raw accesses through a root view too, which read at the wrong bytes with it). Tested in emit/buffer_lds_tests.rs: 32 lanes read 20-byte records of a raw table view by index in 32_32_32_32, 8_8_8_8 (at a lane's offset) and 8 (at byte 3) uint formats, 12-byte records through a descriptor built around a root SRV whose entry says stride 1, and 12-byte records of a buffer through a descriptor taken from the resource heap, the stride the view-stride table's. The DXIL passes dxil.dll and the results match on the default hardware adapter and WARP; the refusals are tested too. The table test fails with the index ignored, and the heap test with typed-format loads left out of the view-stride table's addressing.
|
Rebased onto
Each commit builds. Locally (RTX 5060 Laptop): the buffer/LDS/typed tests pass (14 of 15), and clippy is clean. |
40770f9 to
3cb38f8
Compare
lower.rs grew past the repository's 512 KiB file limit with this branch on top of main; lds_sub_dword and Lower::typed_element move to lower/buffers.rs unchanged, and a comment is shortened. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Buffer and LDS gaps in the translator, in four commits. Each builds and passes tests.
index + offset / element size.tbuffer_load_format_*by index: reads at byteindex * stride + offset, through main's bindless-stride conversions (a root view's built descriptor takes its stride from dword 1, and a heap descriptor from the view-stride table).Tests: the new
emit/buffer_lds_tests.rs(8 tests) and aView::FormatUavin the test host. Every program is hand-assembled, validated with dxil.dll, run on the default hardware adapter and WARP, and checked against a CPU model.A new test,
typed_format_loads_by_index_from_the_heap_take_the_views_stride, covers the heap path. Each change was broken by hand to confirm the tests fail: AND-then-OR instead of compare-exchange, the offset ignored, kept channels zeroed, the index multiply dropped, and typed loads left out of the view-stride table.Rebased onto current main (940d32f). On this machine, 5 tests fail on main itself, with or without this change:
descriptor::host::tests::dynamic_slots_are_held_until_released,memory::tests::lists_share_a_table_and_copies_keep_their_views, the twostride_tests::a_heap_buffer_read_*tests, andsynthetic_tests::gathers_at_a_level_match_the_hardware. Everything else passes, and clippy passes with-D warnings, with and without--all-features.