Repository navigation
Shaders: accept loaded buffer descriptors rewritten with base intact (#815) - #2388
fuzeofficlal wants to merge 1 commit into
Conversation
catminou4
left a comment
There was a problem hiding this comment.
Tested locally: merged into main 940d32f, cargo test -p victory-shader --locked on macOS arm64 — 145 passed, 0 failed, 2 ignored (Windows-gated hardware execution tests not run here). Approving — loaded buffer descriptors rewritten with base accepted.
|
First run on NVIDIA hardware here, as far as I can see. RTX 5070 (Blackwell, driver 621.24), Ryzen 7 5700X, Windows 11, Rust 1.98.1 MSVC, no game files. Head The PR's new test(s) pass on this card: One run, unit tests only, title not run. Written with AI help (Claude/Kiro); the numbers are from runs on my machine. |
RomainKH
left a comment
There was a problem hiding this comment.
I read the tracing change and ran a probe on the head (a276e8b) on macOS arm64, CPU tracking only (cargo test -p victory-shader --lib).
derived_from_load accepts any SCC-free rewrite of dword 3, and of dword 1 above bit 15, as the loaded descriptor. Some of those bits change the addresses a MUBUF access reaches. The access then goes through the host view made from the descriptor in memory, which still has the old bits.
Here are four rewrites that main refuses with a descriptor changed after loading and that this head returns as Source::Loaded. Each comes after the test's s_load_dwordx4 s[8:11] and before buffer_store_dwordx4 v[0:3], v7, s[8:11], 0 offen:
| rewrite | field (GFX10 V#) | on hardware |
|---|---|---|
s_or_b32 s11, s11, 0x00800000 |
dword 3 bit 23, ADD_TID_ENABLE |
the lane id is added to the index, so each lane addresses its own record |
s_or_b32 s11, s11, 0x00600000 |
dword 3 bits 22:21, INDEX_STRIDE |
changes how lanes are interleaved under swizzle or TID addressing |
s_or_b32 s9, s9, 0x80000000 |
dword 1 bit 31, SWIZZLE_ENABLE |
the byte offset is interleaved with the index (swizzled addressing) |
s_min_u32 s10, s10, 16 |
dword 2, NUM_RECORDS |
stores past byte 16 are dropped; on the host they land |
I don't know whether any of the 316 programs does this. The patterns the PR targets (stride cleared, records scaled, OOB_SELECT set) don't. Still, the first three now translate into a wrong access where main refuses by name.
A narrow fix: require dword 1 bit 31 and dword 3 bits 23:21 to come through from the load unchanged, as preserves_low16 already does for the base. For example, generalise it to a mask, with 0x8000_FFFF on dword 1 and 0x00E0_0000 on dword 3. The record count could then get a // shortcut: note saying the host view's bound is the one in memory.
The probe below passes on main and fails on this head (accepted [880bff0b, 00800000]), so it can go into resource::tests as is:
#[test]
fn rewrites_that_change_addressing_are_refused() {
let run = |extra: &[u32]| {
let mut w = vec![
0xBE88_0304, // s_mov_b32 s8, s4
0xBE89_0380, // s_mov_b32 s9, 0
0xF408_0204,
0xFA00_0160, // s_load_dwordx4 s[8:11], s[8:9], 0x160
0xBF8C_C07F, // s_waitcnt lgkmcnt(0)
];
w.extend_from_slice(extra);
// buffer_store_dwordx4 v[0:3], v7, s[8:11], 0 offen
w.extend_from_slice(&[0xE078_1000, 0x8002_0007, S_ENDPGM]);
let code: Vec<u8> = w.iter().flat_map(|x| x.to_le_bytes()).collect();
let p = crate::ir::build(&code, false, 256).unwrap();
track(&p, &[param(Table, 4, 1)], HwStage::Cs, lanes(&p).as_ref())
};
for extra in [
[0x880B_FF0B, 0x0080_0000], // s_or_b32 s11, s11, 0x00800000 (ADD_TID_ENABLE)
[0x880B_FF0B, 0x0060_0000], // s_or_b32 s11, s11, 0x00600000 (INDEX_STRIDE)
[0x8809_FF09, 0x8000_0000], // s_or_b32 s9, s9, 0x80000000 (SWIZZLE_ENABLE)
] {
assert!(run(&extra).is_err(), "accepted {extra:08x?}");
}
}Unrelated to the above: this head merges cleanly with #2324, #2046, #2078 and #2342 together on top of main 940d32f. cargo test -p victory-shader --locked on that merge: 158 passed, 0 failed, 2 ignored (macOS, so the Windows-only GPU checks did not run).
AI-assisted (Claude Code); the results are from runs on my machine.
a276e8b to
4e642d2
Compare
|
Thanks @RomainKH — great catch on the MUBUF addressing bits! Rebased onto
|
|
Automated triage for the maintainers. Needs work. What still blocks it is evidence for the semantics. By the PR's own On your reply: understood that you have no shader corpus. Either of these would move it forward:
Generated by Claude Code |
…arvisak#815) Co-authored-by: Machad3x <Machad3x@users.noreply.github.com> Co-authored-by: Romain Khanoyan <32813610+RomainKH@users.noreply.github.com>
|
Rebased onto Regarding the offline |
4e642d2 to
d135178
Compare
…ten with base intact (Marvisak#815)
|
Thanks for the detailed review. I agree that keeping the 48-bit base intact is not sufficient when lowering through the original loaded host view: changes to |
Summary
Allows non-format 4-dword
V#buffer descriptors (Fields::BufferandFields::Smem) whose stride, record-count, or flag fields were rewritten in place via pure SCC-free scalar ALU afters_load_*to resolve toSource::Loaded, provided the 48-bit virtual base address (w0andw1[15:0]) is provably preserved (andw1is untouched whenidxen = true).In the native compute pipeline measurements on
mainreported in #815 (#issuecomment-7160878577world-run breakdown),"a descriptor changed after loading"is the single largest refusal reason (316 distinct compute programs), where the shader compiler converts structured buffer descriptors to raw views or adjusts record counts/flags with scalar ALU sequences outsidemade_raw's single 6-instruction FidelityFX pattern.Soundness Guards
Fields::SmemandFields::Bufferwith!inst.name().contains("format") && dwords == 4(threaded throughclassify,phi,select,per_lane,lane_select, andlane_phi). 8-dwordT#image descriptors, 4-dwordS#samplers, and formattedtbuffer_*_format_*/buffer_*_format_*accesses remain rejected if modified.w0(BASE_ADDRESS[31:0]) must be the unmodifiedValueinst.writes[first].1of thes_load_*.Fields::SmemorFields::Buffer { idxen: false, .. }),preserves_low16provesw1retains bits[15:0](BASE_ADDRESS[47:32]) ofinst.writes[first + 1].1(e.g.s_and_b32withmask & 0xFFFF == 0xFFFF,s_or_b32/s_xor_b32/s_andn2_b32withlow16_is_zero,s_bitset0/1_b32on bit>= 16).Fields::Buffer { idxen: true, .. }),w1must equalinst.writes[first + 1].1unchanged soSTRIDE(w1[29:16]) andSWIZZLE_ENABLEmatch the host view.w1,w2, andw3must derive via pure SCC-free scalar ALU exclusively from constants andinst.writes[first..first + 4]of that descriptor's load (rejecting cross-descriptor dwords from widers_load_dwordx8/x16loads or external SGPRs).Verification
resource::tests::rewritten_loaded_buffer_descriptors_keep_base_and_reject_unsafe_edits: covers valid MUBUF, SMEM,idxenw2/w3, andphi-joined rewrites, and verifies refusals for modifiedw0, modifiedw1[15:0], modifiedw1stride withidxen = true,tbuffer_load_format_x, cross-descriptors_load_dwordx8mixing, and rewritten 4-dword samplers.emit::valu_tests::rewritten_loaded_buffer_descriptor_executes_on_gpu_and_warp: validates DXIL withdxil.dlland executes on both hardware GPU andWARP.cargo clippy -p victory-shader --lib --tests --all-features --locked -- -D warnings&cargo xtask policypass.Refs #815