Repository navigation
Experimental: direct RDNA2 → SPIR-V shader emitter (not wired in) - #87
pablogonz12 wants to merge 2 commits into
Conversation
First end-to-end direct path for compute: the decoder and SSA IR feed a hand-written SPIR-V writer, every register dword is a function variable and the CFG is one dispatcher loop, so no structuriser or SSA plumbing is needed for a valid module. Memory is the console's own address space through physical_storage_buffer (buffer device address): the module has no descriptors or heaps at all, root arguments are push constants. Offline, on the 442 compute programs of the dump: 94 translate, 93 pass spirv-val and create a real RADV compute pipeline (0 pipeline failures). Gaps and the estimate to parity: xcl-bin/notes/spirv-spike.md (local).
The carry-in of s_addc_u32/s_subb_u32 is SCC, an i1 in the module: widen
it with OpSelect before it is added, which is what spirv-val refused
("OpBitwiseAnd operand index 2 expects int") on compute-7bb5b1b91d283a28.
Tests for the newer families, built from hand-assembled GFX10 words only
(crates/victory-shader/src/emit/spirv_tests.rs): the SCC carry chain,
64-bit shifts, both-halves popcount, first/last bit, v_med3, VOP3
neg/abs, SDWA, DPP and one image sample, plus a generic check that no
operand of an arithmetic op is another type than its result (the class of
the bug above) and spirv-val when the tool is installed.
spirv-check.sh: 223 of 442 compute programs emit, validate and create a
RADV compute pipeline, 0 validation and 0 pipeline failures (93 before
images, 167 after, 200 after source modifiers). DXIL path on the same
dump: 707 translated, unchanged.
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
|
|
Superseded by #120, which is this branch's emitter rebuilt on the unified core ( Closing this one rather than rebasing it: the port needed the old branch's IR/API assumptions fixed |
|
Superseded by #120 (same emitter on the unified core, 232/442 compute, DXIL unchanged); branch spike/spirv-emit kept. |
|
Restack note (25 Nov): this draft is still on the old shader core. Merging main (#88, #99) today conflicts in |
What
An experimental direct RDNA2 ISA → SPIR-V emitter for
victory-shader: our own code from thedecoded ISA to a SPIR-V module (a hand-written SPIR-V binary writer), with no DXIL and no
dxil-spirv in between.
This is a spike branch. Nothing calls it at runtime: no pipeline path, no translation entry
point that runs by default; only the crate's own spike example binaries and the new tests touch it.
It is here to answer one question with numbers: can our decoder/IR produce valid SPIR-V that Mesa
accepts, and how much of the dump does that cover?
Coverage (offline: emit →
spirv-val --target-env vulkan1.3→ realvkCreateComputePipelineson RADV)image_sample*/image_load/image_store/image_gather*v_fma_mixs_add*/s_sub*with SCC,s_*_b64shifts,s_bcnt1_i32_b64,s_ff1/s_flbit,v_med3223 of 442 compute programs (50 %), 0 validation failures, 0 pipeline failures, 0 hangs.
The remaining 219 stop on a named gap each (compare kinds 41,
s_getpc_b6430,v_permlane*27,v_perm_b3227, LDS shuffles 25, …), not on a failure of the approach.The DXIL path on the same dump is unchanged: 707 translated of 751 (measured with the same
offline runner before and after).
How it works, in short
OpVariable; each machine instruction isload → op → store. No phis, no dominance, no structuriser: the whole CFG is one
OpLoopMerge+OpSwitchdispatcher on apcvariable, which is valid structured SPIR-V forany program. Deliberately bad code quality; this measures coverage, not speed.
s_load_*,buffer_*,global_*,flat_*becomeOpLoad/OpStorethrough 64-bit addresses the program computes itself(
PhysicalStorageBuffer+ BDA); root arguments arrive as push constants. No descriptor heaps.UniformConstantbinding per static image site(
set 0, binding = site index),OpTypeImagewithImageFormat Unknownfor sampled andStorageImage*WithoutFormatfor storage, the sampler as the binding after the images, joined withOpSampledImage. The layout follows from the module's decorations alone; nothing reads the consoledescriptor words.
Approximations (deliberate, and listed so nobody mistakes this for a working shader path)
wave emits valid modules that compute wrong values.
image_gather4: the level is dropped (SPIR-V's gather takes no Lod operand)._bsample bias is ignored rather than added to the level.v_readlane/v_writelane/v_readfirstlaneread this lane;s_wqmandv_mbcntare approximated;s_setreg_imm32_b32(rounding/denorm mode) is a no-op.Tests
cargo test -p victory-shader→emit::spirv_tests: each family above is built fromhand-assembled GFX10 instruction words only (no game data, nothing derived from the dump), plus a
generic check that no operand of an arithmetic op has a different type than its result — the class of
the bug this round fixed (an
i1SCC reachingOpBitwiseAnd, whichspirv-valrejects with"operand index 2 expects int") — and
spirv-valon every emitted module when the tool is installed.cargo clippy -p victory-shader --all-targetsis clean,cargo xtask policypasses.Next
Main's shader core is being replaced by the fork line's in a unification PR, so the emitter will be
ported onto that core next rather than developed against code that is on its way out. After the
port, by expected coverage: compare kinds, lane permutes and LDS shuffles, the
s_getpc_b64constanttable, typed buffer formats, then per-lane EXEC and numeric diffs against the DXIL output as the
acceptance test.
No
.spvfiles and no dumps are committed: the tests use hand-built words, and the numbers above arecounts from a local run.