Review of #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>
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>