Repository navigation
Shaders: DXIL structure statistics for compile-cost reports - #1954
Draft
sombraSoft wants to merge 2 commits into
Draft
sombraSoft wants to merge 2 commits into
sombraSoft wants to merge 2 commits into
Conversation
A compile-cost report needs to read the DXIL that DXC emits, and the only reader in the tree (bitreader_tests.rs) handles the unabbreviated records our own writer produces. DXC's LLVM 3.7 writer uses abbreviations defined in BLOCKINFO and locally, char6 arrays and blobs. BitReader walks the bitstream one entry at a time (enter block, end block, record) with the block stack on the heap, so nesting depth costs no recursion. BLOCKINFO is consumed internally; skip_block jumps over blocks a caller does not need. Every count read from the stream (operands, array elements, blob bytes, block lengths) is checked against the bits left in its block before anything is read or allocated, and bitcode that is not whole 32-bit words is refused, so corrupt input is an Err, not a panic or a large allocation. Tested: a hand-assembled stream with a BLOCKINFO abbreviation (literal code, fixed, VBR, char6 array) and a local one (fixed code, blob) decodes to the expected records; every prefix and every single-bit flip of it reads without a panic.
To explain why a shader is expensive for the driver's compiler, a report needs the shape of its DXIL: functions and declarations, basic blocks, instructions and SSA values, phis and their incoming edges, branches, switches and back edges, selects, memory operations, and calls per callee (dx.op.* name). container_stats reads the DXIL part of a DXBC container, bitcode_stats raw bitcode (optionally in the 0x0B17C0DE wrapper). One pass over the bitstream: the type table, global, function and constant records give the module-level value ids; function arguments, function constants and value-producing instructions continue them per body, so the relative callee operand of a call resolves to its function and name. A call produces a value when its function type (explicit in the call or the callee's) returns non-void. Metadata, attributes, use lists and function symbol tables are skipped by block length. Output maps are BTreeMaps, so identical input gives identical stats and JSON. Tested: - two modules built with our writer (branches, a loop with a forward- referencing phi, select, calls to a value and a void dx.op; a switch, global, alloca, gep, load, stores) give exactly the expected stats; - three DXC 1.8.2502.11 compute shaders (a loop, nested branches with a three-way phi, a switch with buffer loads/stores) match counts read from DXC's disassembly: functions, declarations, blocks, instructions, values, phis, phi edges, br/cond br, switch cases, back edges, select, loads, stores, allocas, calls per callee; - every prefix and 3000 byte-flipped copies of a DXC bitcode, its container and a writer module return Ok or Err without a panic; - release build: 20.6 MB of writer bitcode (3M instructions) reads in 86 ms; a 1.5 KB DXC module 10000 times in 97 ms.
Contributor
|
Verification on RTX 3060 Ti (Windows 11), branch merged with current
Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #1953; only the top commit belongs here. Part of #1269.
Structure statistics of a DXIL module from one pass over its bitcode: functions, blocks, instructions, SSA values, phis and their incoming edges, branches, switches, backward branches, selects, loads, stores, calls by callee.
--explain(#1955) prints them for both translation paths.What is in it
Shaders: DXIL structure statistics for compile-cost reports–crates/xcl/src/gpu/dxil/stats.rs(container_stats,bitcode_stats,DxilStats::to_json) andstats_tests.rs. Value ids are tracked exactly (relative operands, explicit call types), so calls resolve to their callee.About 415 lines of code and 273 of tests: the statistics are one walk over the module, and the tests are mostly the DXC cross-check below, so I did not split it further.
Tested
cargo test --workspace --no-fail-fast -- --test-threads=4on e7097e2: 981 passed, 0 failed, 45 ignoredSKIPPED(all from existing tests): 18 × no wave64, 1 × no heap windows, 1 × cannot disable the driver cache (Developer Mode off), 3 × per-lane form refused (f16 / VOP3 modifiers)validate::disassemble) of three compiled compute shaders (a loop, nested branches with a three-way phi, a switch with buffer loads and stores), and check two modules built with XCL's writer exactly; truncated and bit-flipped bitcode returns Ok or Err without panickingRegression run
main:
this PR (e7097e2):
Not tested
AI use