Repository navigation
sampler_source_census: where each sampled S# comes from; none found in a driver table (SHADER-735) - #4268
sampler_source_census: where each sampled S# comes from; none found in a driver table (SHADER-735)#4268Roberto0953 wants to merge 3 commits into
Conversation
|
Tested a5b6a12 on Windows, CPython 3.14.7, CPU only (no GPU, no game files). I used synthetic listings only.
One point about time complexity. The census analyzes the same source again for each of the four words of a descriptor that one earlier load made. On a straight chain of loads, the work increases exponentially: each extra load makes four copies of the previous work. Run this script from the repository root: import runpy, sys
t = runpy.run_path("tests/test_sampler_source_census.py")
for depth in (2, 3, 4, 5):
w = t["Work"]()
try:
lines = [("s_buffer_load_dwordx4 s[28:31], s[28:31], 0", 8), ("s_waitcnt lgkmcnt(0)", 4)] * depth
w.add("chain", "ps", lines + [t["SAMPLE"], t["END"]])
calls = [0]
def profile(frame, event, arg):
if event == "call" and frame.f_code.co_name == "load_source":
calls[0] += 1
sys.setprofile(profile)
report = t["ssc"].census(w.disasm)
sys.setprofile(None)
print(depth, calls[0], report["total"]["classes"]["user_pointer"])
finally:
sys.setprofile(None)
w.close()The count applies to this constructed chain. I do not know the depth of the chains in the game's shaders. AI-assisted. |
Kam471
left a comment
There was a problem hiding this comment.
Ran this at a5b6a12e on Windows 11: python -I tests/test_sampler_source_census.py -> 28 tests, OK; compileall and git diff --check clean.
The tool classifies where each sampled S# comes from (descriptor table, immediate, driver table) and the tests use synthetic inputs. The documentation keeps counts and offsets only and leaves the "no driver table" conclusion scoped to the measured corpus. No blocking issue.
|
Thanks @Roberto0953, good find on |
|
Tested
AI-assisted review. |
Flyander
left a comment
There was a problem hiding this comment.
A nested dynamic pointer load is currently counted as a static user-pointer offset, which makes the census's static/runtime split inaccurate for that shape. Please propagate dynamic provenance through nested loads and add a two-level regression fixture.
| return "constant", dyn, k | ||
| if tag[0] == "code": | ||
| return "code", dyn, k | ||
| if tag[0] != "ld" or tag[1] in seen or tag[1] not in loads: |
There was a problem hiding this comment.
[P2] Preserve dynamic provenance through nested loads. In the ld case, this ignores dyn returned by load_source() and returns only the dynamic flag from an outer offset wrapper. For example, an s_load_dwordx2 from a user pointer at dynamic index s5 can produce an intermediate pointer, then an s_load_dwordx4 at constant 0x40 through it. The second load is reported as user_pointer/static even though its effective address depends on s5. Propagate the inner flag and add a synthetic two-level pointer test; otherwise the reported static/runtime counts and docs are wrong for this chain.
|
Correction to my note above: the |
|
Thanks for the reviews. @shdann, you were right about Calls to
Two tests added (30 in all):
The corpus census gives the same JSON field for field, so the counts in the doc stand. The corpus has no deep chains: its run time is not slower (320 s before, 272 s after, one run each), which is not a gain to claim. @rafaelpssz, thanks for taking the AI-assisted (Claude Code). |
… dword Review of ItsNotRexed#4268 (shdann): load_source worked out the source of a load again for every dword that came from it. A descriptor that an earlier load produced has four dwords, so a chain of loads asked for the first one 4**depth times: 5, 21, 85 and 341 load_source calls at depth 2 to 5 (5,592,405 at depth 12, 16 s for one listing), with the class right every time. What load_source finds for a load is now kept by its code offset and asked for once: 2, 3, 4, 5 and 12 calls at those depths, 40 at depth 40. The cycle check stays as it was (a load whose address depends on the load itself is given up), and an answer that ran into a cycle is not kept, because that one depends on where the question started; an answer that met none does not, so the classes cannot change. Tests (30, all pass; the first new one fails on the code before this commit with "5 load_source calls for a chain of 2 loads"): - a chain of s_buffer_load_dwordx4 V#s and one of s_load_dwordx2 pointers, depth 2 to 40: at most two load_source calls per load, counted with sys.setprofile, and the class stays user_pointer; the same chain from a fixed table stays other_base; - a pointer chased in a loop and a V# that is its own source through a loop: both end, both are undetermined, and the load before the loop keeps its class. Corpus (1.0.2.1, 26,503 listings, `--jobs 4 --expect-none other_base`, exit 0): the --json output is equal to the one of the commit before, field by field, so the counts in docs/d3d12_vulkan.md stand. One run each on the same machine: 320 s before, 272 s after; the corpus has no deep chain, so read that as "not slower", not as the gain. Co-Authored-By: Claude <noreply@anthropic.com>
a5b6a12 to
e206f18
Compare
|
Tested The 28 synthetic tests and the documentation links pass here as on the author's machine. I did not have a corpus, so the counts in the description were not re-measured. No GPU, no game data. AI-assisted. |
|
@Roberto0953, small correction: I'm not doing the What I can add here is a second corpus. I'm running |
|
Second corpus, as promised:
Run time was 1,575 s with 2 jobs on a 16 GB machine; peak process memory 780 MiB. So on two independent copies there's no S# read from a driver table. |
…n a driver table (SHADER-735) docs/d3d12_vulkan.md section 3.5 left open whether the console driver hands shaders their static samplers through a fixed table, which the layer would then have to emulate. tools/sampler_source_census.py follows the four SGPRs of the sampler operand of every image_sample*, image_gather4* and image_get_lod back to where their values are made and puts the instruction in one class: held in user SGPRs, loaded through a pointer that starts from user data, built from immediates, held in or loaded through something else (a constant address, a system SGPR, a code-relative address: what a driver table would be), or undetermined, with the reason. It reuses the dataflow of tools/heap_index_census.py and adds what the sampler operands needed: constants built with s_brev_b32, SGPRs spilled to VGPRs and read back, joins that keep the sources of every path, s_getpc_b64, and listings with embedded data words re-anchored the way the translator does. --expect-none CLASS turns the count into a check; --jobs N runs it in parallel. Measured on the 1.0.2.1 corpus (26,503 listings, none skipped; 366,628 sampling instructions in 14,025 shaders): 189,412 loaded through user data, 174,796 literal, 0 in user SGPRs, 0 from another base, 2,420 undetermined (0.66%, MS and VS, plus one CS). The undetermined ones all come from one shape, an S# made or saved inside a region that s_cbranch_execz skips when no lane is active; without the taken edge of those branches the same analysis classes 2,419 as loaded through user data and 1 as literal. The counts, what they do not show and the command are in docs/d3d12_vulkan.md next to the static-sampler paragraph; question 3 of section 8.2 is updated. Tests: tests/test_sampler_source_census.py, 28 cases on hand-written RDNA2 listings, one or more per class, with negative controls (a fixed-table read on one path or in one dword, a clobbered spill, a branch that is not an exec-zero skip, --expect-none failing on a fixed-table shader). Also run: compileall on tools and tests, test_text_write_line_endings, test_docs_cli_flags, test_docs_repo_paths, test_docs_links, test_tool_startup, test_heap_index_census, scripts/check_no_game_data.py. CPU only; no GPU involved. Co-Authored-By: Claude <noreply@anthropic.com>
… dword Review of ItsNotRexed#4268 (shdann): load_source worked out the source of a load again for every dword that came from it. A descriptor that an earlier load produced has four dwords, so a chain of loads asked for the first one 4**depth times: 5, 21, 85 and 341 load_source calls at depth 2 to 5 (5,592,405 at depth 12, 16 s for one listing), with the class right every time. What load_source finds for a load is now kept by its code offset and asked for once: 2, 3, 4, 5 and 12 calls at those depths, 40 at depth 40. The cycle check stays as it was (a load whose address depends on the load itself is given up), and an answer that ran into a cycle is not kept, because that one depends on where the question started; an answer that met none does not, so the classes cannot change. Tests (30, all pass; the first new one fails on the code before this commit with "5 load_source calls for a chain of 2 loads"): - a chain of s_buffer_load_dwordx4 V#s and one of s_load_dwordx2 pointers, depth 2 to 40: at most two load_source calls per load, counted with sys.setprofile, and the class stays user_pointer; the same chain from a fixed table stays other_base; - a pointer chased in a loop and a V# that is its own source through a loop: both end, both are undetermined, and the load before the loop keeps its class. Corpus (1.0.2.1, 26,503 listings, `--jobs 4 --expect-none other_base`, exit 0): the --json output is equal to the one of the commit before, field by field, so the counts in docs/d3d12_vulkan.md stand. One run each on the same machine: 320 s before, 272 s after; the corpus has no deep chain, so read that as "not slower", not as the gain. Co-Authored-By: Claude <noreply@anthropic.com>
…uter load run-time source() dropped the run-time flag of a load it followed, so an S# read at a constant offset through a pointer that was itself loaded at a run-time index was counted as user_pointer/static, although its address depends on the index (review of ItsNotRexed#4268). The flag of the inner load now carries through nested pointers and through a V#. Test: a two-level and a three-level pointer chain and a V# loaded at a run-time index must be dynamic, with the same shapes at a constant inner offset staying static; it fails on the previous code (static for dynamic). The corpus census prints the same output line for line (the corpus has no such shape), so the counts in the doc stand. Co-Authored-By: Claude <noreply@anthropic.com>
|
@Flyander, thanks: you were right, and it is fixed in c33256c (the branch is rebased on The defect. The fix. The inner load's flag now carries through: a run-time offset on any load of the chain makes everything read through its result run-time, through nested pointers and through a V# ( Regression test (
31 tests pass with the fix (30 before, plus this one). Counts. I re-ran the corpus census with the fix: the output is the same line for line as before it, including the static/run-time split (179,602 / 9,810) and the 0x540 largest static offset. The corpus has no S# read through a pointer loaded at a run-time index, so the numbers in the doc stand; the split was wrong for the shape, not for this corpus. Also re-run after the rebase: the docs tests (links, table rows, list items, CLI flags, repo paths), Could you take another look? AI-assisted (Claude Code). |
e206f18 to
c33256c
Compare
|
Tested c33256c merged with main 3faac55 on Linux (WSL2), Python 3.12.16: pass. |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> # Conflicts: # docs/d3d12_vulkan.md
Claimed in #3918 (SHADER-735). @rafaelpssz claimed it seconds later and the coordinator asked us to agree a split: review of the classes and counts is welcome, and the
s_brev_b32finding below touches your #2887, so that follow-up is yours if you want it.Summary
docs/d3d12_vulkan.mdsection 3.5 left one question open about static samplers: the console driver might handthem to shaders through a fixed table of its own, and a shader that expected one would read its S# from an address
the layer never fills. The item asks to count, over the corpus, whether any shader does that.
tools/sampler_source_census.pyfollows the four SGPRs of the sampler operand of everyimage_sample*,image_gather4*andimage_get_lodback to where their values are made and gives the instruction one class:user_sgprsuser_pointerliteralother_baseundeterminedIt reuses the forward dataflow of
tools/heap_index_census.pyand adds what the corpus's sampler operands needed:constants built with
s_brev_b32, SGPRs spilled to a VGPR and read back (v_mov_b32/v_readfirstlane_b32,v_writelane_b32/v_readlane_b32), joins that keep the sources of every path,s_getpc_b64, and listings withembedded data words re-anchored to the FSSM blob the way the translator does (so none is skipped).
--expect-none CLASS...turns the count into a check (exit 1),--jobs Nruns it in parallel,--jsonwritesthe full census. It is a census only: no change to the layer or the translator.
What the census shows (counts only)
1.0.2.1 corpus, 26,503 listings, none skipped; 14,025 shaders sample, 366,628 sampling instructions.
other_baseis 0 in every stage: no sampling instruction was found reading an S# from a constant address, asystem SGPR or a code-relative address. On this evidence the layer has no driver sampler table to emulate; the
2,420 undetermined instructions (0.66%) are the part the conservative reading cannot settle, see below.
user_pointer: 179,602 at a static offset (0x540 at most), 9,810 at a run-time offset. No constant is added toany of these pointers, so
constant table address + user index(the same arithmetic asuser pointer + constant) does not occur either. All 189,412 are in shaders whoseSFI0sets the sampler-heap bit; a shaderwithout the bit samples with literals only.
literal: 105,235 in shaders with the sampler-heap bit, 69,561 in shaders without it.undetermined(0.66%, 300 shaders): with every edge followed, one path brings something else into the S#registers: 2,355 read the S# back from a VGPR spill slot that one path does not save to (a
user_pointerloadwherever it is saved), 64 get a literal on one path and a
user_pointerload on another, 1 gets a value thedataflow does not follow. All of them have the same shape: the S# is made or saved inside a region the compiler
skips with
s_cbranch_execzwhen no lane is active, and sampled after it. Without the taken edge of thosebranches the same analysis classes 2,419 as
user_pointerand 1 asliteral. The tool reports both; the tableand
--expect-noneuse the first, conservative one.What it does not show
s32" (the translator's assumption); only the computecount is measured (
COMPUTE_PGM_RSRC2). Question 3 of section 8.2 stays open for that part.compile time, and half of the sampling instructions build their S# from immediates), but that is a hypothesis
until the root signatures are matched against them. The doc says so.
second reading of the undetermined instructions trusts that nothing samples on the exec-zero path.
so
user_pointerdoes not split them; it is counted by offset kind and by theSFI0bit instead.Found on the way (not fixed here)
finding:28,659 of the literal S# sites, in 6,824 shaders, build one dword withs_brev_b32.tools/shader_meta.py(_step_state) does not fold that instruction, so those S#s are not inliteral_samplersin the index, and a layer that registers literal samplers from the index would miss them. The census folds it and
counts these sites apart (
literal: with s_brev_b32). No game files needed to fix it; a hand-written listing showsit (four immediates, the third through
s_brev_b32:analyse_instructionsreturns no literal sampler).Docs
docs/d3d12_vulkan.md: the static-sampler bullet of section 3.5 now says "measured: no sampling instruction was foundreading an S# from a fixed table (0.66% undetermined under the conservative reading)" and points to a new block right after the list, "Where the sampled S# comes from", with the table
above, what each class means, what is not shown and the command. Row 3 of section 8.2 is updated.
Note for whoever merges: #3494 adds lines right after the same bullet. The two changes touch neighbouring lines, so
the second one to land needs a trivial rebase (keep both).
Tests
tests/test_sampler_source_census.py, standard library only, hand-written RDNA2 listings and containers in atemporary folder (no game files): 28 cases, at least one per class and per form of
other_base, plus negativecontrols that must not pass as user data: a fixed-table read on one path or in one dword, a spill clobbered before
the restore, another lane read back, a branch that is not an exec-zero skip, a join with too many values, and
--expect-none other_base undeterminedfailing on a folder with one fixed-table shader.Run locally (Windows 11, Python 3.13.5, CPU only; no GPU or driver involved):
Reproduce
About five minutes with four workers on the full corpus; exit 0, and the table above is its output (run twice, same counts). Nothing from
the game is in the diff: counts only, no shader names, hashes or disassembly.
AI-assisted (Claude Code).