mirror of
https://git.triforceproject.com/triforce/source
synced 2026-11-29 04:18:49 -04:00
Triforce v0.8.5
A Randomizer page in the launcher, a new title screen with Mods and Save Select tabs, scaling changes applied in game, the Jabu-Jabu bars fixed, renderer frame-time work and the brightness-flash fix, and fixes from the 0.8.4 reports.
This commit is contained in:
464
tests/test_capturepushkeep.py
Normal file
464
tests/test_capturepushkeep.py
Normal file
@@ -0,0 +1,464 @@
|
||||
"""A plain draw's capture push is left out while the command buffer is known to hold zeros there (gpu/vk/
|
||||
capturepushkeep.h, cmd_work.h, vk_work.h, vk_draw.cpp push_capture; no game, no GPU).
|
||||
|
||||
(Triforce, 11-26, the GPU audit's C15.) push_capture pushed 16 bytes (where the vertex stage stores its positions: an
|
||||
address, a first and a count) before every plain draw of every program whose vertex stage captures, and with no temporal
|
||||
upscaler's chain asking for positions those bytes are zeros for every draw: a vkCmdPushConstants a draw, about 2,000 a
|
||||
frame at Lake Hylia, each a packet for the recorder. The zeros are pushed once now and kept, per command buffer, until
|
||||
anything could have changed them. A non-zero address left there would be written through by the next draw, so what
|
||||
forgets is central: every vkCmdPushConstants and every vkCmdBindPipeline of the renderer (vk_work.h's macros), every
|
||||
vkBeginCommandBuffer (cmd_work.h work_begun) and every library's direct recording (the recorder's B_DIRECT boundary),
|
||||
never a list of call sites.
|
||||
|
||||
This compiles the rule and replays recordings through it as vk_work.h and push_capture call it: N plain draws push once;
|
||||
a compute pass's push or bind between two draws, a library's own recording, a new recording of the same command buffer,
|
||||
a program with other push stages, a draw state reset and a non-zero slot each push again; the first zero after a
|
||||
non-zero slot is pushed; a program's full block (zeros in the capture's bytes) keeps the next draw's; a command buffer
|
||||
the table has no room for never keeps; a program with other push stages bound and left without a draw, and a pipeline
|
||||
carried across a new recording, push again. Check mode's own model (what the bytes hold, by the pushes alone) agrees with the rule in all of them, and
|
||||
disagrees when the rule is made to keep across a push (the hole a list of call sites would leave). The header's rules
|
||||
taken out in turn (MUTATIONS) each make it fail.
|
||||
|
||||
And reads the source: both macros and the begin go through the rule, and their wrappers call the recorder's route, not
|
||||
the driver; no file in any folder of gpu/vk pushes or binds past the macros, or above its vk_work.h include (controls:
|
||||
each such text is caught); push_capture asks the rule, pushes through the macro and notes its own push after; the
|
||||
program path's bind is the only one after which the zeros are held again; a direct recording's boundary voids them; the
|
||||
switch, its three values and the log line for any other, the lab knob and the counters (the must-be-0 one exact); the
|
||||
header's account of what check mode sees; the row in the switches table, with the same account.
|
||||
|
||||
python -I -B tests/test_capturepushkeep.py [--cxx clang++]
|
||||
"""
|
||||
import argparse
|
||||
import re
|
||||
import subprocess
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
VK = ROOT / "gpu" / "vk"
|
||||
RUN_ALL_ARGS = ["--cxx", "{cxx}"]
|
||||
|
||||
|
||||
def check(ok, why):
|
||||
if not ok:
|
||||
raise SystemExit("FAIL: " + why)
|
||||
|
||||
|
||||
def block(text, marker):
|
||||
start = text.index(marker)
|
||||
end = text.index("{", start) + 1
|
||||
depth = 1
|
||||
while depth:
|
||||
depth += (text[end] == "{") - (text[end] == "}")
|
||||
end += 1
|
||||
return text[start:end]
|
||||
|
||||
|
||||
def past_macros(name, text):
|
||||
"""What in a renderer file (name: its path under gpu/vk) pushes or binds past vk_work.h's macros, or sets the kept
|
||||
capture push outside the draw: the driver's own call named, a call with no vk_work.h include or above it"""
|
||||
problems = []
|
||||
code = re.sub(r"//[^\n]*", "", re.sub(r"/\*.*?\*/", "", text, flags=re.S))
|
||||
for call in ("vkCmdPushConstants", "vkCmdBindPipeline"):
|
||||
if "rx_" + call in text or "vkx::" + call in text or "pk_" + call in text:
|
||||
problems.append(f"{name}: a {call} past vk_work.h's macro")
|
||||
if re.search(r"\b" + call + r"\s*\(", code):
|
||||
inc = code.find('#include "vk_work.h"')
|
||||
if inc < 0:
|
||||
problems.append(f"{name}: calls {call} without vk_work.h's macro")
|
||||
elif re.search(r"\b" + call + r"\s*\(", code[:inc]):
|
||||
problems.append(f"{name}: calls {call} above its vk_work.h include")
|
||||
if name.rsplit("/", 1)[-1] not in ("vk_draw.cpp", "capturepushkeep.h") and (
|
||||
"program_bound(" in text or "full_pushed(" in text or ".cap.zero_stages" in text):
|
||||
problems.append(f"{name}: the kept capture push is set outside the draw")
|
||||
return problems
|
||||
|
||||
|
||||
PROGRAM = r"""
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <initializer_list>
|
||||
#include "capturepushkeep.h"
|
||||
namespace k = capturepushkeep;
|
||||
static int fails = 0;
|
||||
#define CHECK(x) do { if (!(x)) { std::printf("FAIL:%d %s\n", __LINE__, #x); fails++; } } while (0)
|
||||
|
||||
// one command buffer as the renderer sees it: the rule's state, and what a driver would hold in the capture's bytes
|
||||
struct Cmd {
|
||||
k::State st;
|
||||
bool known = true;
|
||||
uint8_t held[k::kSize];
|
||||
bool defined = false; // (false: undefined, a new recording)
|
||||
uint32_t bound = 0; // (the push stages of the program pipeline bound last; 0: none)
|
||||
int pushes = 0, kept = 0, bad = 0, wrong = 0;
|
||||
};
|
||||
static void begin(Cmd& c) { k::begun(c.st), c.defined = false, c.bound = 0; }
|
||||
// vk_work.h's vkCmdPushConstants: the rule is told, then the driver
|
||||
static void push(Cmd& c, uint32_t offset, uint32_t size, const uint8_t* v) {
|
||||
k::any_push(c.st, offset, size, v);
|
||||
for (uint32_t i = 0; i < size; i++)
|
||||
if (offset + i >= k::kOffset && offset + i < k::kOffset + k::kSize) c.held[offset + i - k::kOffset] = v[i];
|
||||
if (offset <= k::kOffset && offset + size >= k::kOffset + k::kSize) c.defined = true;
|
||||
c.pushes++;
|
||||
}
|
||||
static void bind_other(Cmd& c) { k::any_bind(c.st); } // (vk_work.h's vkCmdBindPipeline)
|
||||
// a library's own recording into it (the recorder's B_DIRECT boundary first): nothing of it is seen, the bytes are anything
|
||||
static void library(Cmd& c) {
|
||||
k::direct_recorded();
|
||||
std::memset(c.held, 0xab, sizeof c.held);
|
||||
}
|
||||
// vk_draw.cpp draw's bind of a program's pipeline: through the macro, then what was held before it taken back or not. A
|
||||
// layout with other push stages is not compatible for push constants: the driver's bytes are undefined after it
|
||||
static void bind_program(Cmd& c, uint32_t stages, bool from_reset) {
|
||||
const uint32_t held = c.st.zero_stages;
|
||||
if (c.bound && c.bound != stages) c.defined = false;
|
||||
c.bound = stages;
|
||||
bind_other(c);
|
||||
k::program_bound(c.st, held, stages, from_reset);
|
||||
}
|
||||
// vk_draw.cpp push_constants: a program's whole block, zeros in the capture's bytes
|
||||
static void full_block(Cmd& c, uint32_t stages) {
|
||||
uint8_t data[k::kOffset + k::kSize] = {};
|
||||
data[0] = 0x3f;
|
||||
push(c, 0, sizeof data, data);
|
||||
k::full_pushed(c.st, stages);
|
||||
}
|
||||
// vk_draw.cpp push_capture, then the draw: what the vertex stage would read must be the slot
|
||||
static void draw(Cmd& c, k::Mode mode, uint32_t stages, uint64_t address, bool lab_old = false) {
|
||||
uint8_t data[k::kSize] = {};
|
||||
std::memcpy(data, &address, 8);
|
||||
bool skip = false;
|
||||
if (mode != k::OFF && k::keep(c.st, c.known, stages, data)) {
|
||||
if (mode == k::CHECK) c.kept++, c.bad += k::check_differs(c.st);
|
||||
else if (!lab_old) c.kept++, skip = true;
|
||||
}
|
||||
if (!skip) {
|
||||
push(c, k::kOffset, k::kSize, data);
|
||||
if (mode != k::OFF) k::pushed(c.st, stages, data);
|
||||
}
|
||||
if (!c.defined || std::memcmp(c.held, data, k::kSize)) c.wrong++;
|
||||
}
|
||||
int main() {
|
||||
const uint32_t VF = 0x11, VGF = 0x19;
|
||||
const uint8_t junk[8] = {1, 2, 3, 4, 5, 6, 7, 8};
|
||||
uint8_t ones[128];
|
||||
std::memset(ones, 0xee, sizeof ones);
|
||||
CHECK(k::kOffset == 88 && k::kSize == 16);
|
||||
// the switch
|
||||
CHECK(k::mode_of(nullptr) == k::KEEP && k::mode_of("") == k::KEEP && k::mode_of("1") == k::KEEP && k::mode_of("on") == k::KEEP);
|
||||
CHECK(k::mode_of("0") == k::OFF && k::mode_of("check") == k::CHECK);
|
||||
for (k::Mode mode : {k::KEEP, k::CHECK, k::OFF}) {
|
||||
const bool on = mode == k::KEEP;
|
||||
Cmd c;
|
||||
begin(c);
|
||||
// N plain draws of programs with one stage mask: one push
|
||||
bind_program(c, VF, true);
|
||||
for (int i = 0; i < 100; i++) {
|
||||
if (i % 7 == 0) bind_program(c, VF, false); // (another program, the same stages)
|
||||
draw(c, mode, VF, 0);
|
||||
}
|
||||
CHECK(c.pushes == (on ? 1 : 100) && c.kept == (mode == k::OFF ? 0 : 99));
|
||||
// a compute pass's push between two draws, over the capture's bytes (byte 88 and on) or not: pushed again
|
||||
int at = c.pushes;
|
||||
push(c, 0, 104, ones);
|
||||
draw(c, mode, VF, 0);
|
||||
CHECK(c.pushes == at + 2);
|
||||
at = c.pushes;
|
||||
push(c, 0, 8, junk);
|
||||
draw(c, mode, VF, 0);
|
||||
CHECK(c.pushes == at + 2);
|
||||
draw(c, mode, VF, 0);
|
||||
CHECK(c.pushes == at + (on ? 2 : 3));
|
||||
// any other bind (a compute pipeline, the clear's, an actor's): pushed again
|
||||
at = c.pushes;
|
||||
bind_other(c);
|
||||
draw(c, mode, VF, 0);
|
||||
CHECK(c.pushes == at + 1);
|
||||
// a program with other push stages: its layout's block is another one
|
||||
at = c.pushes;
|
||||
bind_program(c, VGF, false);
|
||||
draw(c, mode, VGF, 0);
|
||||
CHECK(c.pushes == at + 1);
|
||||
draw(c, mode, VGF, 0);
|
||||
CHECK(c.pushes == at + (on ? 1 : 2));
|
||||
at = c.pushes;
|
||||
bind_program(c, VF, false);
|
||||
draw(c, mode, VF, 0);
|
||||
CHECK(c.pushes == at + 1);
|
||||
// the draw state reset (last_pipeline cleared: something was recorded that the macros did not see)
|
||||
at = c.pushes;
|
||||
bind_program(c, VF, true);
|
||||
draw(c, mode, VF, 0);
|
||||
CHECK(c.pushes == at + 1);
|
||||
// a slot: pushed, every time, and so is the first zero after it
|
||||
at = c.pushes;
|
||||
draw(c, mode, VF, 0x7000000010ull);
|
||||
draw(c, mode, VF, 0x7000000010ull);
|
||||
draw(c, mode, VF, 0x7000000020ull);
|
||||
CHECK(c.pushes == at + 3);
|
||||
draw(c, mode, VF, 0);
|
||||
CHECK(c.pushes == at + 4);
|
||||
draw(c, mode, VF, 0);
|
||||
CHECK(c.pushes == at + (on ? 4 : 5));
|
||||
// a program's full block has zeros there: its capture push is kept
|
||||
at = c.pushes;
|
||||
full_block(c, VF);
|
||||
draw(c, mode, VF, 0);
|
||||
CHECK(c.pushes == at + (on ? 1 : 2));
|
||||
full_block(c, VF);
|
||||
draw(c, mode, VF, 0x7000000030ull);
|
||||
full_block(c, VF);
|
||||
draw(c, mode, VF, 0);
|
||||
// the lab knob: pushed in its phases, kept again after
|
||||
at = c.pushes;
|
||||
draw(c, mode, VF, 0, true);
|
||||
draw(c, mode, VF, 0, true);
|
||||
CHECK(c.pushes == at + 2);
|
||||
draw(c, mode, VF, 0);
|
||||
CHECK(c.pushes == at + (on ? 2 : 3));
|
||||
// a library's recording, with the draw state left as it was: pushed again, and kept after
|
||||
at = c.pushes;
|
||||
library(c);
|
||||
draw(c, mode, VF, 0);
|
||||
CHECK(c.pushes == at + 1);
|
||||
draw(c, mode, VF, 0);
|
||||
CHECK(c.pushes == at + (on ? 1 : 2));
|
||||
// ... into another command buffer: this one's is void as well (the boundary names none)
|
||||
at = c.pushes;
|
||||
k::direct_recorded();
|
||||
bind_program(c, VF, false);
|
||||
draw(c, mode, VF, 0);
|
||||
CHECK(c.pushes == at + 1);
|
||||
// the command buffer recorded again: nothing is held
|
||||
at = c.pushes;
|
||||
begin(c);
|
||||
bind_program(c, VF, true);
|
||||
draw(c, mode, VF, 0);
|
||||
CHECK(c.pushes == at + 1);
|
||||
// a compute pass (bind, push) with the program's pipeline left bound, as the mirror's pass and the write-back's do
|
||||
at = c.pushes;
|
||||
bind_other(c);
|
||||
push(c, 0, 96, ones);
|
||||
draw(c, mode, VF, 0);
|
||||
CHECK(c.pushes == at + 2);
|
||||
// a program with other push stages bound and left without a draw (its draw skipped right after the bind), then one
|
||||
// with the first stages again: the zeros are not taken back across the other layout
|
||||
at = c.pushes;
|
||||
draw(c, mode, VF, 0);
|
||||
bind_program(c, VGF, false);
|
||||
bind_program(c, VF, false);
|
||||
draw(c, mode, VF, 0);
|
||||
CHECK(c.pushes == at + (on ? 1 : 2));
|
||||
// a pipeline carried across a new recording of the command buffer (no bind after the begin): pushed again
|
||||
at = c.pushes;
|
||||
begin(c);
|
||||
draw(c, mode, VF, 0);
|
||||
CHECK(c.pushes == at + 1);
|
||||
// every draw read its own slot, and check mode found nothing
|
||||
CHECK(c.wrong == 0 && c.bad == 0);
|
||||
}
|
||||
// a command buffer the table has no room for: never kept
|
||||
{
|
||||
Cmd c;
|
||||
c.known = false;
|
||||
begin(c);
|
||||
bind_program(c, VF, true);
|
||||
draw(c, k::KEEP, VF, 0), draw(c, k::KEEP, VF, 0), draw(c, k::KEEP, VF, 0);
|
||||
CHECK(c.pushes == 3 && c.kept == 0 && c.wrong == 0);
|
||||
}
|
||||
// the rule's answers one by one: stages 0 is "nothing held", never a key
|
||||
{
|
||||
k::State s;
|
||||
const uint8_t zero[k::kSize] = {};
|
||||
CHECK(!k::keep(s, true, 0, zero) && !k::keep(s, true, VF, zero));
|
||||
k::pushed(s, VF, zero);
|
||||
CHECK(k::keep(s, true, VF, zero) && !k::keep(s, false, VF, zero) && !k::keep(s, true, VGF, zero));
|
||||
uint8_t one[k::kSize] = {};
|
||||
one[15] = 1;
|
||||
CHECK(!k::keep(s, true, VF, one));
|
||||
k::pushed(s, VF, one);
|
||||
CHECK(!k::keep(s, true, VF, zero));
|
||||
k::pushed(s, 0, zero);
|
||||
CHECK(!k::keep(s, true, 0, zero));
|
||||
}
|
||||
// check mode's model is the pushes' own: a keep that did not forget at a push over byte 88 is counted
|
||||
{
|
||||
Cmd c;
|
||||
begin(c);
|
||||
bind_program(c, VF, true);
|
||||
draw(c, k::CHECK, VF, 0);
|
||||
draw(c, k::CHECK, VF, 0);
|
||||
CHECK(c.bad == 0 && c.kept == 1);
|
||||
const uint32_t held = c.st.zero_stages;
|
||||
push(c, 0, 104, ones);
|
||||
CHECK(c.st.zero_stages == 0);
|
||||
c.st.zero_stages = held; // (the hole)
|
||||
draw(c, k::CHECK, VF, 0);
|
||||
CHECK(c.bad == 1 && c.wrong == 0);
|
||||
// what the model takes the bytes for, push by push
|
||||
k::State s;
|
||||
const uint8_t zero[104] = {};
|
||||
CHECK(k::check_differs(s));
|
||||
k::any_push(s, 0, 104, zero);
|
||||
CHECK(!k::check_differs(s));
|
||||
k::any_push(s, 0, 96, zero); // (a part of them: not known)
|
||||
CHECK(k::check_differs(s));
|
||||
k::any_push(s, 88, 16, zero);
|
||||
CHECK(!k::check_differs(s));
|
||||
k::any_push(s, 0, 88, ones); // (short of them: they stay)
|
||||
CHECK(!k::check_differs(s));
|
||||
k::any_push(s, 104, 8, ones);
|
||||
CHECK(!k::check_differs(s));
|
||||
k::any_push(s, 80, 32, ones);
|
||||
CHECK(k::check_differs(s));
|
||||
k::any_push(s, 0, 104, zero);
|
||||
k::begun(s);
|
||||
CHECK(k::check_differs(s));
|
||||
}
|
||||
return fails ? 1 : 0;
|
||||
}
|
||||
"""
|
||||
|
||||
# (a rule of the header, and what it is replaced by: each must make PROGRAM fail; a parameter left unread is named with
|
||||
# (void), the build is -Werror)
|
||||
MUTATIONS = [
|
||||
("the same push stages for the zeros taken back at a program's bind", "s.zero_stages = !from_reset && held == stages ? held : 0;",
|
||||
"s.zero_stages = !from_reset ? held : 0; (void)stages;"),
|
||||
("all the push stages, not one shared", "s.zero_stages = !from_reset && held == stages ? held : 0;",
|
||||
"s.zero_stages = !from_reset && (held & stages) ? held : 0;"),
|
||||
("not across a draw state reset", "s.zero_stages = !from_reset && held == stages ? held : 0;",
|
||||
"s.zero_stages = held == stages ? held : 0; (void)from_reset;"),
|
||||
("a new recording forgets", "inline void begun(State& s) { s.zero_stages = 0, s.shadow_zero = 0; }",
|
||||
"inline void begun(State& s) { s.shadow_zero = 0; }"),
|
||||
("a library's recording voids what is held", "s.zero_stages == stages && s.gen == direct_gen.load(std::memory_order_relaxed) && ",
|
||||
"s.zero_stages == stages && "),
|
||||
]
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--cxx", default="clang++")
|
||||
args = parser.parse_args()
|
||||
check((VK / "capturepushkeep.h").is_file(), "gpu/vk/capturepushkeep.h: there is no rule (every plain draw pushes its capture slot)")
|
||||
rule = (VK / "capturepushkeep.h").read_text(encoding="utf-8")
|
||||
check("#include <vulkan" not in rule and "Vk" not in rule.split("#pragma once")[1], "the rule is not apart from Vulkan")
|
||||
|
||||
# the command buffer's state holds the rule's, and a begin starts it afresh
|
||||
cw = (VK / "cmd_work.h").read_text(encoding="utf-8")
|
||||
check('#include "capturepushkeep.h"' in cw and "capturepushkeep::State cap;" in block(cw, "struct CmdWork {"),
|
||||
"cmd_work.h: the command buffer's state does not hold the kept capture push")
|
||||
check("capturepushkeep::begun(w.cap);" in block(cw, "inline VkCommandBuffer work_begun("),
|
||||
"cmd_work.h work_begun: a new recording does not forget the kept capture push")
|
||||
|
||||
# a library's recording past the macros is told by the recorder's boundary
|
||||
rec = (VK / "vk_recorder.h").read_text(encoding="utf-8")
|
||||
check("if (k == B_DIRECT) ::capturepushkeep::direct_recorded();" in block(rec, "inline void boundary(Bound k)"),
|
||||
"vk_recorder.h boundary: a direct recording does not void the kept capture pushes")
|
||||
|
||||
# every push and every bind of the renderer is told to the rule, in the macros
|
||||
vw = (VK / "vk_work.h").read_text(encoding="utf-8")
|
||||
check("#define vkCmdPushConstants(...) (::mkwvk::capture_keep_vk::push(__VA_ARGS__))" in vw,
|
||||
"vk_work.h: vkCmdPushConstants does not go through the rule")
|
||||
check("#define vkCmdBindPipeline(...) (::mkwvk::capture_keep_vk::bind(__VA_ARGS__))" in vw,
|
||||
"vk_work.h: vkCmdBindPipeline does not go through the rule")
|
||||
push = block(vw, "inline void push(VkCommandBuffer cmd")
|
||||
check(push.index("::capturepushkeep::any_push(::mkwvk::cmd_work(cmd).cap, offset, size, values);") <
|
||||
push.index("::mkwvk::rec::rx_vkCmdPushConstants(cmd, layout, stages, offset, size, values);"),
|
||||
"vk_work.h: a push is not told to the rule before it is recorded")
|
||||
bind = block(vw, "inline void bind(VkCommandBuffer cmd")
|
||||
check(bind.index("::capturepushkeep::any_bind(::mkwvk::cmd_work(cmd).cap);") <
|
||||
bind.index("::mkwvk::rec::rx_vkCmdBindPipeline(cmd, point, pipeline);"), "vk_work.h: a bind is not told to the rule")
|
||||
check("::vkx::" not in push and "::vkx::" not in bind, "vk_work.h: a wrapper calls the driver past the recorder")
|
||||
# no call past the macros: the driver's own push and bind are named by the recorder, the loader and vk_work.h alone, in
|
||||
# every folder of the renderer (reshade/ records into the game's command buffers too); a call above the vk_work.h include
|
||||
# is the loader's own function, past the rule
|
||||
scanned = []
|
||||
for f in sorted(VK.rglob("*.cpp")) + sorted(VK.rglob("*.h")):
|
||||
if f.name in ("vk_recorder.h", "vk_loader.h", "vk_work.h") and f.parent == VK:
|
||||
continue
|
||||
scanned.append(f.relative_to(VK).as_posix())
|
||||
problems = past_macros(scanned[-1], f.read_text(encoding="utf-8", errors="replace"))
|
||||
check(not problems, "; ".join(problems))
|
||||
check(len(scanned) > 100 and "reshade/fx_runtime.cpp" in scanned,
|
||||
"the scan for calls past the macros did not read gpu/vk's subfolders (reshade/fx_runtime.cpp)")
|
||||
for what, name, text in (("the driver's own bind named through vkx::, below the vk_work.h include", "x.cpp",
|
||||
'#include "vk_work.h"\nvoid f() { ::vkx::vkCmdBindPipeline(cmd, bp, pl); }\n'),
|
||||
("a push above the vk_work.h include", "x.cpp",
|
||||
'void f() { vkCmdPushConstants(cmd, l, s, 88, 16, d); }\n#include "vk_work.h"\n'),
|
||||
("a bind with no vk_work.h", "x.cpp", "void f() { vkCmdBindPipeline (cmd, bp, pl); }\n"),
|
||||
("the kept push set outside the draw", "x.cpp", "void f() { capturepushkeep::full_pushed(s, 1); }\n")):
|
||||
check(past_macros(name, text), "the scan for calls past the macros missed " + what)
|
||||
|
||||
src = (VK / "vk_draw.cpp").read_text(encoding="utf-8")
|
||||
check(src.count("capturepushkeep::program_bound(") == 1 and src.count("capturepushkeep::full_pushed(") == 1 and
|
||||
src.count("capturepushkeep::pushed(") == 1, "vk_draw.cpp: more than the program's bind and the draw's two pushes set what is kept")
|
||||
draw = block(src, "void draw(")
|
||||
held = draw.index("const uint32_t cap_held = mkwvk::cmd_work(cmd).cap.zero_stages;")
|
||||
reset = draw.index("const bool cap_reset = last_pipeline == VK_NULL_HANDLE;")
|
||||
bound = draw.index("vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, pl), last_pipeline = pl;")
|
||||
back = draw.index("capturepushkeep::program_bound(mkwvk::cmd_work(cmd).cap, cap_held, p.push_stages, cap_reset);")
|
||||
check(held < bound and reset < bound < back,
|
||||
"vk_draw.cpp draw: what was held and a reset draw state are not read before the program's bind and given to the rule after it")
|
||||
cap = block(src, "static void push_capture(")
|
||||
check("if (!p.captures) return;" in cap, "push_capture: no longer only the capturing programs")
|
||||
check("const int mode = capture_keep_mode();" in cap, "push_capture does not read the switch")
|
||||
ask = cap.index("capturepushkeep::keep(w.cap, w.known, p.push_stages, data)")
|
||||
push_at = cap.index("vkCmdPushConstants(cmd, p.layout, p.push_stages, Shader::Backend::SPIRV::CAPTURE_PUSH_OFFSET, sizeof data, data);")
|
||||
note = cap.index("capturepushkeep::pushed(mkwvk::cmd_work(cmd).cap, p.push_stages, data);")
|
||||
check(ask < push_at < note, "push_capture: not asked, pushed through the macro, then noted")
|
||||
check('lab_ab::on("nocappush")' in cap[ask:push_at], "push_capture: the lab knob nocappush does not push in its phases")
|
||||
check("capturepushkeep::check_differs(w.cap)" in cap[ask:push_at] and "st_cap_bad.fetch_add(1, std::memory_order_relaxed);" in cap[ask:push_at],
|
||||
"push_capture: check mode does not count a kept push whose bytes differ, exactly with the helper threads")
|
||||
doc = src[src.rindex("\n\n", 0, src.index("static void push_capture(")):src.index("static void push_capture(")]
|
||||
check("B_DIRECT" in doc and "same push stages" in doc and "by construction" in doc,
|
||||
"push_capture's comment leaves out the libraries' recordings, the bind's rule or what check mode cannot see")
|
||||
check("st_cap_kept" in cap[ask:push_at] and "st_cap_pushed" in cap[push_at:], "push_capture: kept and pushed are not counted")
|
||||
check("capturepushkeep::kOffset == Shader::Backend::SPIRV::CAPTURE_PUSH_OFFSET" in cap and
|
||||
"capturepushkeep::kSize == sizeof data" in cap, "push_capture: the rule's bytes are not pinned to the shader's")
|
||||
pc = block(src, "void push_constants(")
|
||||
check(pc.index("vkCmdPushConstants(cmd, p.layout, p.push_stages, 0, kPushSize, data);") <
|
||||
pc.index("capturepushkeep::full_pushed(mkwvk::cmd_work(cmd).cap, p.push_stages);"),
|
||||
"push_constants: the whole block's zeros are not noted after its push")
|
||||
mode = block(src, "int capture_keep_mode(")
|
||||
check('getenv("RX_VK_CAPTURE_PUSH_KEEP")' in mode and "capturepushkeep::mode_of(" in mode and "logf(" in mode and
|
||||
"is not 0, 1 or check" in mode, "the switch is not read once by the rule and told when it is not the default")
|
||||
check("0 by construction" in rule and "test_recorder_sync.py" in rule.split("#pragma once")[0] and "ignores binds" in rule,
|
||||
"capturepushkeep.h: the header does not say what check mode can and cannot see")
|
||||
rep = block(src, "void desc_report(")
|
||||
check("st_cap_kept" in rep and "st_cap_pushed" in rep and "st_cap_bad" in rep and "a frame's capture pushes" in rep,
|
||||
"the descriptors' report does not carry the capture pushes kept and made")
|
||||
|
||||
dev = (ROOT / "docs" / "development.md").read_text(encoding="utf-8")
|
||||
row = [line for line in dev.splitlines() if line.startswith("| `RX_VK_CAPTURE_PUSH_KEEP=0` or `check` |")]
|
||||
check(len(row) == 1 and "nocappush" in row[0] and "capturepushkeep.h" in row[0],
|
||||
"docs/development.md: RX_VK_CAPTURE_PUSH_KEEP is not in the switches table")
|
||||
for part in ["0 by construction", "ignores binds", "`tests/test_recorder_sync.py`", "`tests/test_capturepushkeep.py`",
|
||||
"`push_constants`", "Any other value: on (told once)", "neither is v0.8.4's cost"]:
|
||||
check(len(row) == 1 and part in row[0], "docs/development.md: the RX_VK_CAPTURE_PUSH_KEEP row lacks " + part)
|
||||
check(len(row) == 1 and "a second model" not in row[0], "docs/development.md: the row still calls the check a second model")
|
||||
|
||||
with tempfile.TemporaryDirectory(prefix="capturepushkeep-") as tmp:
|
||||
c, exe = Path(tmp) / "keep.cpp", Path(tmp) / "keep.exe"
|
||||
c.write_text(PROGRAM, encoding="utf-8")
|
||||
subprocess.run([args.cxx, "-std=c++20", "-O1", "-Wall", "-Wextra", "-Werror", "-I" + str(VK), str(c), "-o", str(exe)], check=True)
|
||||
r = subprocess.run([str(exe)], capture_output=True, text=True)
|
||||
check(r.returncode == 0, "the rule as made:\n" + r.stdout)
|
||||
# (each rule taken out of the header in turn: the program must fail)
|
||||
for i, (what, old, new) in enumerate(MUTATIONS):
|
||||
check(rule.count(old) == 1, "the mutation's text is not in the header once: %r" % old)
|
||||
inc = Path(tmp) / ("m%d" % i)
|
||||
inc.mkdir()
|
||||
(inc / "capturepushkeep.h").write_text(rule.replace(old, new), encoding="utf-8")
|
||||
mexe = Path(tmp) / ("m%d.exe" % i)
|
||||
b = subprocess.run([args.cxx, "-std=c++20", "-O1", "-Wall", "-Wextra", "-Werror", "-I" + str(inc), str(c), "-o", str(mexe)],
|
||||
capture_output=True, text=True)
|
||||
check(b.returncode == 0, "the mutation does not compile (%s):\n%s" % (what, b.stderr[-2000:]))
|
||||
r = subprocess.run([str(mexe)], capture_output=True, text=True)
|
||||
check(r.returncode != 0, "no check fails without: " + what)
|
||||
print("PASS: a plain draw's capture push is kept while its command buffer holds zeros there, and pushed after anything else "
|
||||
"(%d mutations caught)" % len(MUTATIONS))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user