"""The size of a submission's parts: RX_VK_CHUNK, the lab's knob, the driver's default (gpu/vk/barrier_rules.h part_draws, vk_replay.cpp part_draws and maybe_split; no game, no GPU). (Triforce, 11-22, the performance audit's SYNC-66, after Source B's.) A long submission goes to the GPU in parts of 120 draws and dispatches on every card, read once into a static of maybe_split, so nothing could compare sizes inside a run. The size is now RX_VK_CHUNK when set, else the RX_VK_LAB_AB knob chunk: in its phases, else the driver's default: 120 for every driver until the lab picks one. (11-26) The lab picked NVIDIA's: 240 (measured in the benchmark's four scenes); every other driver keeps 120. NVIDIA's driver is the device's driver id (VK_DRIVER_ID_NVIDIA_PROPRIETARY, one id on Windows and Linux), not the card's vendor: NVK, Dozen and Venus on an NVIDIA card keep 120. Compiles a driver against barrier_rules.h, lab_ab.h and the Vulkan headers and checks: the default is 240 for NVIDIA's driver, and 120 for NVK, Dozen, Venus, RADV, AMD's, Intel's, any other driver id and none; the rule's id for NVIDIA's driver is Vulkan's; with no knob the size is what the old read gave, for 100,000 random texts of the variable (unset, 0, 120, negative, words, any number) on random drivers, except unset on NVIDIA's driver (240): the default path splits where it split elsewhere; RX_VK_CHUNK beats the knob and the default; 0 stays 0 (never split); the knob beats the default only in its own phases (lab_ab.h's value_of with the phase's knob set, another knob's phase, and no phase), with NVIDIA's 240 and NVK's 120 as the default beside the measured knob chunk:120, and the pass-end parts' test (value_of("chunk", -1) < 0) true only outside it. And reads vk_replay.cpp: maybe_split has no static size and asks part_draws() at each call, still returns for a size of 0 or less and still counts ++part_work against it after the tail's test, and takes Threaded rendering's pass-end parts only outside the knob's phases; part_draws reads the variable once and the knob at each call, asks the rule with the device's driver id (no platform test) and says when Threaded rendering's parts decide instead; barrier_rules.h's comment names NVK, Threaded rendering's parts and both measurements; the switches table has the row, with NVK, the measured PC, where the size applies under Threaded rendering and a lab example against 120, and no longer says the in-pass split is on with NVIDIA's driver. python -I -B tests/test_chunk_default.py --headers [--cxx clang++] """ import argparse import subprocess import tempfile from pathlib import Path ROOT = Path(__file__).resolve().parents[1] RUN_ALL_ARGS = ["--cxx", "{cxx}", "--headers", "{vulkan_headers}"] DRIVER = r''' #include "barrier_rules.h" #include "lab_ab.h" #include #include namespace br = mkwvk::barrier_rules; namespace lab = mkwvk::lab_ab; static int checks, fails; #define CHECK(what, cond) do { checks++; if (!(cond)) fails++, printf("FAIL %s (line %d)\n", what, __LINE__); } while (0) int main() { // the device's driver id (dev.driver_id): NVIDIA's own driver has one on Windows and Linux; the drivers that run on NVIDIA's // cards beside it (NVK, Dozen, Venus) report its vendor, 0x10de, and keep 120 until the lab has measured them static const struct { const char* what; uint32_t driver; int64_t want; } kDrivers[] = { {"NVIDIA's driver (one id on Windows and Linux): 240", VK_DRIVER_ID_NVIDIA_PROPRIETARY, 240}, {"NVK on an NVIDIA card: 120", VK_DRIVER_ID_MESA_NVK, 120}, {"Dozen on an NVIDIA card: 120", VK_DRIVER_ID_MESA_DOZEN, 120}, {"Venus on an NVIDIA card: 120", VK_DRIVER_ID_MESA_VENUS, 120}, {"RADV: 120", VK_DRIVER_ID_MESA_RADV, 120}, {"AMD's driver: 120", VK_DRIVER_ID_AMD_PROPRIETARY, 120}, {"AMDVLK: 120", VK_DRIVER_ID_AMD_OPEN_SOURCE, 120}, {"Intel's Windows driver: 120", VK_DRIVER_ID_INTEL_PROPRIETARY_WINDOWS, 120}, {"Intel's Mesa driver: 120", VK_DRIVER_ID_INTEL_OPEN_SOURCE_MESA, 120}, {"llvmpipe: 120", VK_DRIVER_ID_MESA_LLVMPIPE, 120}, {"MoltenVK: 120", VK_DRIVER_ID_MOLTENVK, 120}, {"no driver id (0): 120", 0, 120}, {"an id from a later header: 120", 0x7fffffffu, 120}, }; constexpr size_t kN = sizeof kDrivers / sizeof *kDrivers; for (const auto& d : kDrivers) CHECK(d.what, br::part_draws_default(d.driver) == d.want); static_assert(br::kDriverNvidiaProprietary == VK_DRIVER_ID_NVIDIA_PROPRIETARY, "the rule's id for NVIDIA's driver is Vulkan's"); CHECK("the constants", br::kPartDraws == 120 && br::kPartDrawsNvidia == 240); // with no knob: the old read, whatever the variable says uint64_t rng = 0xD1B54A32D192ED03ull; const auto rnd = [&](uint64_t n) { rng ^= rng << 13, rng ^= rng >> 7, rng ^= rng << 17; return rng % n; }; static const char* const kTexts[] = {nullptr, "", "0", "120", "480", "4096", "-5", "junk", "12x", " 64", "1", "999999999999"}; for (int i = 0; i < 100000; i++) { char num[32]; const char* env = kTexts[rnd(sizeof kTexts / sizeof *kTexts)]; if (rnd(3) == 0) snprintf(num, sizeof num, "%lld", (long long)rnd(5000) - 500), env = num; const uint32_t driver = kDrivers[rnd(kN)].driver; const int64_t now = br::part_draws(env != nullptr, env ? atoll(env) : 0, br::part_draws_default(driver)); const int64_t was = !env && driver == VK_DRIVER_ID_NVIDIA_PROPRIETARY ? 240 : br::part_draws_before(env); CHECK("with no knob the size is the old read's (unset on NVIDIA's driver: 240)", now == was); if (fails) break; } const int64_t nvidia = br::part_draws_default(VK_DRIVER_ID_NVIDIA_PROPRIETARY), nvk = br::part_draws_default(VK_DRIVER_ID_MESA_NVK); CHECK("unset on NVIDIA's driver: 240", br::part_draws(false, 0, nvidia) == 240); CHECK("unset on NVK: 120", br::part_draws(false, 0, nvk) == 120); CHECK("unset on AMD's: 120", br::part_draws(false, 0, br::part_draws_default(VK_DRIVER_ID_AMD_PROPRIETARY)) == 120); CHECK("unset on RADV: 120", br::part_draws(false, 0, br::part_draws_default(VK_DRIVER_ID_MESA_RADV)) == 120); CHECK("unset on Intel's: 120", br::part_draws(false, 0, br::part_draws_default(VK_DRIVER_ID_INTEL_PROPRIETARY_WINDOWS)) == 120); CHECK("RX_VK_CHUNK=120 on NVIDIA's driver: 120", br::part_draws(true, 120, nvidia) == 120); CHECK("RX_VK_CHUNK beats the knob", br::part_draws(true, 240, 480) == 240); CHECK("RX_VK_CHUNK=0 stays 0 under a knob", br::part_draws(true, 0, 480) == 0); CHECK("the knob beats the default", br::part_draws(false, 0, 480) == 480); // the knob through lab_ab.h, as vk_replay.cpp's part_draws asks it (the driver's default beside it): only in its own // phases. The measured A/B, chunk:120 against NVIDIA's 240; and maybe_split's pass-end parts step aside in its phases alone CHECK("no RX_VK_LAB_AB: the default", (lab::n_knobs = 0, lab::value_of("chunk", nvidia)) == 240); CHECK("no RX_VK_LAB_AB: the pass-end parts' test passes", lab::value_of("chunk", -1) < 0); lab::n_knobs = 2; snprintf(lab::knobs[0].name, sizeof lab::knobs[0].name, "chunk"), lab::knobs[0].value = 120; snprintf(lab::knobs[1].name, sizeof lab::knobs[1].name, "rblate"), lab::knobs[1].value = 1; lab::active.store(0); CHECK("a phase with no knob on NVIDIA's driver: 240", br::part_draws(false, 0, lab::value_of("chunk", nvidia)) == 240); CHECK("a phase with no knob on NVK: 120", br::part_draws(false, 0, lab::value_of("chunk", nvk)) == 120); CHECK("a phase with no knob: the pass-end parts' test passes", lab::value_of("chunk", -1) < 0); lab::active.store(1); CHECK("the knob chunk:120's phase on NVIDIA's driver: 120", br::part_draws(false, 0, lab::value_of("chunk", nvidia)) == 120); CHECK("the knob's phase on NVK: its number", br::part_draws(false, 0, lab::value_of("chunk", nvk)) == 120); CHECK("the knob's phase, the variable set: the variable", br::part_draws(true, 480, lab::value_of("chunk", nvidia)) == 480); CHECK("the knob's phase: the pass-end parts step aside", lab::value_of("chunk", -1) == 120); lab::active.store(2); CHECK("another knob's phase: the default", br::part_draws(false, 0, lab::value_of("chunk", nvidia)) == 240); CHECK("another knob's phase: the pass-end parts' test passes", lab::value_of("chunk", -1) < 0); if (fails) printf("chunk default: FAILED (%d of %d checks)\n", fails, checks); else printf("chunk default: all %d checks passed\n", checks); return fails != 0; } ''' def check(ok, what): if not ok: raise SystemExit("FAIL: " + what) def function(text, head): at = text.index(head) return text[at:text.index("\n}\n", at)] def check_source(): replay = (ROOT / "gpu/vk/vk_replay.cpp").read_text(encoding="utf-8") split = function(replay, "void maybe_split(VkCommandBuffer& cmd) {") check("static const int64_t every" not in replay, "maybe_split still reads the size once into a static") check(split.startswith("void maybe_split(VkCommandBuffer& cmd) {\n const int64_t every = part_draws();\n"), "maybe_split does not ask part_draws() at each call") check('getenv("RX_VK_CHUNK")' not in split, "maybe_split reads RX_VK_CHUNK itself") check('if (pe.on && !part_end_now && lab_ab::value_of("chunk", -1) < 0) {' in split, "maybe_split's pass-end parts are no longer left in the knob's phases alone (the docs' Threaded rendering note)") check("if (tail_on()) return;" in split and "if (!rec_cur || every <= 0 || ++part_work < every || rec_parts + 1 >= kMaxParts || dump_on()) return;" in split and split.index("if (tail_on()) return;") < split.index("++part_work < every"), "maybe_split's test changed: a size of 0 or less must never split, and the count comes after the tail's test") part = function(replay, "int64_t part_draws() {") check('static const char* const env = getenv("RX_VK_CHUNK");' in part and "static const int64_t env_value = env ? atoll(env) : 0;" in part, "part_draws does not read RX_VK_CHUNK once") check("barrier_rules::part_draws_default((uint32_t)dev.driver_id);" in part and "#if" not in part and "vendorID" not in part, "the default is not asked of the rule with the device's driver id alone (NVK reports NVIDIA's vendor)") check("pass_end_parts_on()" in part and "not in force" in part, "part_draws' line does not say when Threaded rendering's pass-end parts decide instead of the size") # (with those parts on and RX_VK_CHUNK unset the printed default is never in force: the knob's number decides in its phases) check("env ? \"; not in force outside the knob's phases: " in part and '"; not in force: a part ends where' in part, "part_draws' line says the driver's default is in force in the knob's phases under Threaded rendering's parts") check(part.rstrip().endswith('return barrier_rules::part_draws(env != nullptr, env_value, lab_ab::value_of("chunk", by_driver));'), "part_draws does not ask the knob at each call, behind the variable") # ((Triforce) and once by Threaded rendering's parts, only to step aside when it is set: pass_end_parts) ends = function(replay, "PassEndParts& pass_end_parts() {") check(replay.count('getenv("RX_VK_CHUNK")') == 2 and ends.count('getenv("RX_VK_CHUNK")') == 1, "RX_VK_CHUNK is read somewhere else") check('v.on = e && *e ? atoi(e) != 0 : threaded_on() && !getenv("RX_VK_CHUNK");' in ends, "pass_end_parts' switch changed: the docs say any RX_VK_CHUNK turns Threaded rendering's parts off") check("every RX_VK_CHUNK, as before" not in ends and "default 120;" not in replay, "vk_replay.cpp still says the counted size is 120 as before") rules = (ROOT / "gpu/vk/barrier_rules.h").read_text(encoding="utf-8") at = rules.index("RX_VK_CHUNK: how many draws") note = rules[at:rules.index("constexpr int64_t kPartDraws", at)] for need in ("NVK", "Threaded rendering", "RX_VK_PART_PASS_END not 1", "RX_VK_PART_PASS_END=0", "v0.8.3", "v0.8.4"): check(need in note, "barrier_rules.h's part-size comment does not name " + need) check("a few more reports keep" not in note, "barrier_rules.h's part-size comment still gives the occlusion counts a direction") dev = (ROOT / "docs/development.md").read_text(encoding="utf-8") row = [line for line in dev.splitlines() if line.startswith("| `RX_VK_CHUNK=` |")] check(len(row) == 1 and "**240 on NVIDIA's driver**" in row[0] and "**120 on every other driver**" in row[0] and "`chunk:`" in row[0], "docs/development.md: no row for RX_VK_CHUNK with its defaults") check("NVK" in row[0] and "measured only on" in row[0], "the RX_VK_CHUNK row does not say NVK keeps 120 or where 240 was measured") check("Threaded rendering" in row[0] and "`RX_VK_PART_PASS_END=0`" in row[0] and "leave `RX_VK_CHUNK` unset" in row[0], "the RX_VK_CHUNK row does not say its size and its switch back are for parts cut by count, not Threaded rendering's") check("`RX_VK_LAB_AB=chunk:120,chunk:480`" in row[0] and "chunk:480,chunk:240" not in row[0], "the RX_VK_CHUNK row's lab example does not compare against the old size") there = row[0][row[0].index("leave `RX_VK_CHUNK` unset"):row[0].index("The size was read once")] check("(the first part from 32)" in row[0] and "whole submissions" in there, "the RX_VK_CHUNK row does not say Threaded rendering's first part is from 32 draws, or that RX_VK_CHUNK=0 there gives " "whole submissions") check("parts of 120 draws" not in dev, "docs/development.md still says a part is 120 draws on every card") check("Unset: `pass` with NVIDIA's driver" not in dev, "docs/development.md still says the in-pass split is on with NVIDIA's driver") def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("--headers", type=Path, required=True) parser.add_argument("--cxx", default="clang++") args = parser.parse_args() check_source() with tempfile.TemporaryDirectory(prefix="chunk-default-") as tmp: src = Path(tmp) / "driver.cpp" src.write_text(DRIVER, encoding="utf-8") exe = Path(tmp) / "driver.exe" subprocess.run([args.cxx, "-std=c++20", "-Wall", "-Wextra", "-Werror", "-I", str(ROOT / "gpu/vk"), "-I", str(args.headers), str(src), "-o", str(exe)], check=True) out = subprocess.run([str(exe)], capture_output=True, text=True) print(out.stdout, end="") check(out.returncode == 0, "the rule's checks failed") print("PASS: a part's size: RX_VK_CHUNK, then the lab knob, then the driver's default, 240 on NVIDIA's and 120 for the rest (NVK too)") if __name__ == "__main__": main()