The last of the Winlator lineage rewritten out; rumble on the phone

The five files the audit measured as Winlator's are replaced: a one-method callback interface by
java.util.function.Consumer, the component base by SessionPart (attach an application context,
start, stop), the environment list by HostEnvironment, the process starter by HostProcess, and
the pad's state holder by PadState with named sticks, triggers, directions and buttons. The
frame-generation tree is framegen/ (its contents were never Winlator's: lsfg-vk's port and
Bannerlator's Win-FG), the log tags are the app's, and the fake pad's rumble socket is now one
the app actually serves: RumbleComponent turns a game's force-feedback effects into the phone's
vibrator, which used to go nowhere. The two design notes describing Bannerlator's X11 path are
gone, and the README and credits say what is whose.
This commit is contained in:
The412Banner committed 2026-09-23 09:12:14 -04:00
1 parent 35dbef0536
commit a604dce6cb
84 files changed
+493 -1771

No files matched your search

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2026 The412Banner
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
@@ -0,0 +1,47 @@
# NOTICE - FidelityFX Optical Flow (model 3)
win-fg "model 3" (FSR3 Optical Flow) embeds compute shaders that are an
adaptation of the **AMD FidelityFX SDK FSR3 Optical Flow** algorithm.
Source passes adapted (FidelityFX-SDK, branch `main`):
- `Kits/FidelityFX/framegeneration/fsr3/include/gpu/opticalflow/ffx_opticalflow_prepare_luma.h`
→ `of3_luma.comp` (Rec.709 LDR luminance extraction)
- `Kits/FidelityFX/framegeneration/fsr3/include/gpu/opticalflow/ffx_opticalflow_compute_luminance_pyramid.h`
→ `of3_downsample.comp` (4-tap box / SPD-equivalent mip reduce)
- `Kits/FidelityFX/framegeneration/fsr3/include/gpu/opticalflow/ffx_opticalflow_compute_optical_flow_v5.h`
→ `of3_flow.comp` (SAD block-match search with coarse-level prediction)
- `Kits/FidelityFX/framegeneration/fsr3/include/gpu/opticalflow/ffx_opticalflow_scale_optical_flow_advanced_v5.h`
→ `of3_expand.comp` (bilinear upscale of coarse flow to display resolution)
The GLSL adaptations are subgroup-free / SPD-library-free re-implementations so
they compile with `glslangValidator` for Vulkan 1.1 (Adreno/Turnip-safe). They
intentionally drop the SDK's HDR transfer-function handling, wave intrinsics
(`ffxWaveSum`), `msad4`, packed-uint luma and groupshared SAD maps, none of
which are portable to bare GLSL on this stack. See per-shader DEVIATION comments.
FidelityFX SDK is distributed under the MIT License:
```
This file is part of the FidelityFX SDK.
Copyright (C) Advanced Micro Devices, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files(the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and /or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions :
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
```
+357
View File
@@ -0,0 +1,357 @@
// win-fg - runtime config: enable gate, model, multiplier, and the synthesis
// tuning parameters. Sourced from environment variables and an optional
// conf.toml (a config file, when present, wins over the env defaults).
#pragma once
#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <string>
#include <fstream>
#include <sstream>
namespace winfg {
struct Config {
bool enabled = false; // gate; loader also honours the manifest enable var
// GRANULAR PRESENT-PATH DEBUG TRACE. Default OFF. When ON, winfg_QueuePresentKHR
// emits a per-frame, step-by-step trail (logcat tag "win-fg") so a freeze/
// crash-on-enable leaves an obvious LAST line at the exact stage that hung or
// faulted (acquire-spare, compute-submit, present-generated/real, fence wait,
// fallback). Zero behaviour change and effectively zero cost when off - one
// predicted-not-taken bool test per step, no logcat writes.
// WIN_FG_DEBUG=1|0 / conf.toml debug=on|off.
bool debug = false;
// ── EVEN-CADENCE FRAME PACING ─────────────────────────────────────────────
// Default ON. The 2x insert path presents the GENERATED frame then the REAL
// frame back-to-back in one vkQueuePresentKHR hook call, so on Mailbox/
// Immediate both land in ~one instant followed by a full frame-interval gap
// until the next pair - uneven in time → judder ("slows down to catch up").
// With pacing on, the layer measures the real-frame interval (EMA of a
// monotonic clock) and holds the REAL present to its scheduled beat so the
// generated frame lands near the temporal MIDPOINT between consecutive real
// frames (even gen,real,gen,real cadence). Pure bounded CPU sleep - no GPU
// wait added; if a frame is already behind schedule the wait is SKIPPED
// (present immediately) so worst case is one un-paced pair, never a hitch.
// FIFO self-paces so the waits collapse to ~0 there. Off ⇒ byte-identical
// back-to-back behaviour. WIN_FG_PACING=on|off / conf.toml pacing=on|off.
// ISOLATION BUILD: default flipped to OFF to A/B the AYANEO-750 post-setting-change
// flicker regression against the pacing feature (everything else byte-identical).
bool pacing = false;
int model = 4; // 3 = symmetric flow, 4 = bidir + occlusion gate
int multiplier = 2; // generated presents per real present + 1
// EXTRA SWAPCHAIN IMAGE HEADROOM (device-freeze fix). On top of the +1 spare the
// insert path needs, request this many ADDITIONAL images at swapchain creation:
// requested minImageCount = app_min + 1 (spare) + extra_images,
// clamped to surfaceCaps.maxImageCount (0 = unlimited -> no clamp), never below
// app_min+1. The extra headroom stops the guest's NEXT vkAcquireNextImageKHR from
// starving while win-fg holds a spare + a real frame in flight to the AHB-backed
// host compositor. Some SoCs (Adreno 840 / Turnip) recycle displayed AHBs too
// slowly to tolerate the extra present with only the +1 spare and freeze on the
// first inserted frame; the AYANEO (Adreno 750) recycles fast enough to tolerate
// it. Default 2 (a few MB VRAM), applied on all devices. On a device that already
// works this only grows the pool - no FPS/quality change; the pool-headroom guard
// in QueuePresentKHR stays a no-op when headroom is adequate.
// WIN_FG_EXTRA_IMAGES / conf.toml extra_images.
int extraImages = 2;
// ── FLOW-RESOLUTION PERFORMANCE PRESET ────────────────────────────────────
// Trades base-FPS-drop against optical-flow quality by selecting the FINEST
// pyramid level the dense flow is solved at (FrameGen::kFlowFinest):
// 0 = Quality -> kFlowFinest = 1 (~1/2-res flow; best motion, biggest FG cost)
// 1 = Balanced -> kFlowFinest = 2 (~1/4-res; TODAY's behaviour) [DEFAULT]
// 2 = Performance -> kFlowFinest = 3 (~1/8-res; cheapest -> smallest base-FPS drop)
// Out-of-range clamps to Balanced (1), so an unset/older conf.toml is byte-
// identical to today. Changing this LIVE rebuilds the affected per-size flow
// images (like a resize) inside the layer and resets the flow predictor, so a
// preset change is fully hot - no FG toggle needed. See FrameGen::configure /
// FrameGen::flowFinestForPreset. WIN_FG_PERF_PRESET / conf.toml perf_preset.
int perfPreset = 1; // 0 quality, 1 balanced (default), 2 performance
float flowScale = 1.0f; // scales solved flow magnitude
// C1 GLOBAL-MOTION PRE-WARP. Estimate the per-frame camera affine (LK) and
// remove it before the dense SAD flow search so the search only sees coherent
// object-only residual motion (kills fast-pan "melt"). 0 = auto (engage only
// when the LK solve is stable), 1 = on (force-engage once a solve exists),
// 2 = off (never pre-warp; identity affine → pipeline == pre-C1 exactly).
// WIN_FG_GM=auto|on|off / conf.toml global_motion=auto|on|off.
int gmMode = 0; // 0 auto, 1 on, 2 off
// C2 FLOW REGULARIZATION (TV-L1 smoothness prior). After C1 removes the camera
// motion, the dense flow (flowLvl_ at kFlowFinest, 1/4-res) is the OBJECT-only
// residual; it still carries spurious per-block vectors. C2 runs N semi-implicit
// TV-L1 denoising iterations on that field - an L1 data term + edge-aware Total-
// Variation regularizer - to kill incoherent vectors while KEEPING true motion
// discontinuities (object edges) sharp. Solved in-place; expand's median + C1
// add-back consume the cleaned field unchanged. 0 iterations ⇒ byte-identical to
// pre-C2. See shaders/of3_flowreg.comp.
// WIN_FG_FLOWREG=auto|on|off / conf.toml flow_reg=auto|on|off.
int frMode = 0; // 0 auto (engaged), 1 on (engaged), 2 off
int frIters = 4; // TV-L1 iterations at kFlowFinest (0 ⇒ off)
float frLambda = 2.0f; // L1 data-fidelity weight (higher ⇒ trust SAD flow)
float frDt = 0.25f; // semi-implicit smoothing step (higher ⇒ smoother)
float frEdge = 8.0f; // luma-gradient edge sensitivity for the TV weight g
float frEps = 0.05f; // Charbonnier epsilon (px) for the TV diffusivity
// synthesis (wfg_synth) tuning
float beta = 8.0f; // softmax sharpness on importance Z
float lambda = 0.6f; // FB-consistency vs photometric weight
// Tightened 2026-08-17 to prioritise "no ghost" over max sharpness - the
// remaining single-frame ghosts came from pixels that the previous defaults
// still trusted with warp when they should have cross-faded. Raising both
// pushes borderline pixels toward the safe cross-fade path (softer, but no
// smear). Prewarp will lift the ceiling further; this is the "safety net"
// knob change until then.
// Walked back from (0.10, 9.0) tighten after user reported softening. The
// real fix for the residual ghosts is the 3a-fallback path change in
// layer.cpp (present real curr on fallback instead of blitting synth over);
// the gate can stay closer to the original values now.
float epsilon = 0.07f; // disocclusion floor (0.05 -> 0.10 -> 0.07)
float photoScale = 7.5f; // photometric residual scale into Z (6.0 -> 9.0 -> 7.5)
// HUD exclusion rect in pixel coords (x0,y0,x1,y1). Fragments inside are
// passed through as the real current frame (no warp, no synth) so text /
// overlays don't ghost. Disabled when x0 >= x1 or y0 >= y1 (the default).
// Sourced from WIN_FG_HUD_RECT="x0,y0,x1,y1" env var or conf.toml
// (hudRect="x0,y0,x1,y1"). Pattern is Isygold's Vegas DXVK framegen -
// host knows where the HUD is, tell the shader to skip it.
float hudX0 = 0.0f;
float hudY0 = 0.0f;
float hudX1 = 0.0f;
float hudY1 = 0.0f;
// ── TRAINING-DATA CAPTURE MODE (Route-B VFI dataset collection) ───────────
// A dev-only gate. When OFF (default) the present path is byte-identical to a
// build without this feature - a single bool test and nothing else. When ON,
// every real present is downscaled on the GPU, read back async, and written to
// disk as lossless QOI (motion-rich 256² triplet patches by default, or full
// downscaled frames) plus a JSONL manifest, for offline (i-1,i+1)->i training.
// NEVER captures win-fg's generated frames - capture reads the real swapchain
// image at the TOP of QueuePresentKHR, before any interpolation.
// WIN_FG_CAPTURE=on|off / conf.toml capture=on|off.
bool capture = false;
// Downscale target box (aspect-preserving, never upscales). WIN_FG_CAPTURE_W/H,
// conf capture_width/capture_height.
int captureW = 1280;
int captureH = 720;
// 0 = patch (self-contained aligned triplets, DEFAULT), 1 = frame (full
// downscaled frames in order). WIN_FG_CAPTURE_MODE=patch|frame.
int capMode = 0;
int capPatches = 3; // patches per triplet in patch mode (WIN_FG_CAPTURE_PATCHES)
int capPatchSize = 256; // patch edge in downscaled px (WIN_FG_CAPTURE_PATCH)
// Skip a unit whose inter-frame motion (mean per-pixel luma abs-diff, 0..255)
// is below this. WIN_FG_CAPTURE_MOTION / conf capture_motion.
float capMotion = 2.0f;
// Output dir; empty => $HOME/.cache/winfg-capture. WIN_FG_CAPTURE_DIR /
// conf capture_dir. A per-run session subdir is created under it.
std::string capDir;
// Rolling-shard size cap (MiB). Output is a small number of large packed
// .wfgcap containers, not thousands of loose files; a new shard opens when the
// current one passes this. WIN_FG_CAPTURE_SHARD_MB / conf capture_shard_mb.
int capShardMB = 1024;
void sanitize() {
if (model < 3) model = 3; if (model > 4) model = 4;
if (multiplier < 2) multiplier = 2; if (multiplier > 4) multiplier = 4;
if (extraImages < 0) extraImages = 0; if (extraImages > 8) extraImages = 8;
if (perfPreset < 0 || perfPreset > 2) perfPreset = 1; // clamp out-of-range -> Balanced
if (gmMode < 0) gmMode = 0; if (gmMode > 2) gmMode = 2;
if (frMode < 0) frMode = 0; if (frMode > 2) frMode = 2;
if (frIters < 0) frIters = 0; if (frIters > 16) frIters = 16;
if (frLambda < 0.0f) frLambda = 0.0f;
if (frDt < 0.01f) frDt = 0.01f; if (frDt > 4.0f) frDt = 4.0f;
if (frEdge < 0.0f) frEdge = 0.0f;
if (frEps < 1e-3f) frEps = 1e-3f;
if (flowScale < 0.05f) flowScale = 0.05f; if (flowScale > 4.0f) flowScale = 4.0f;
if (beta < 0.0f) beta = 0.0f; if (lambda < 0.0f) lambda = 0.0f;
// capture knobs
if (captureW < 16) captureW = 16; if (captureW > 7680) captureW = 7680;
if (captureH < 16) captureH = 16; if (captureH > 4320) captureH = 4320;
if (capMode < 0) capMode = 0; if (capMode > 1) capMode = 1;
if (capPatches < 1) capPatches = 1; if (capPatches > 16) capPatches = 16;
if (capPatchSize < 16) capPatchSize = 16; if (capPatchSize > 1024) capPatchSize = 1024;
if (capMotion < 0.0f) capMotion = 0.0f;
if (capShardMB < 16) capShardMB = 16; if (capShardMB > 65536) capShardMB = 65536;
}
};
static inline float envf(const char* k, float d) {
const char* v = std::getenv(k); return v ? std::strtof(v, nullptr) : d;
}
static inline int envi(const char* k, int d) {
const char* v = std::getenv(k); return v ? std::atoi(v) : d;
}
// "auto"/"on"/"off" (also true/false/on/off numerics) -> {0 auto, 1 on, 2 off}.
static inline int parse_tristate(const std::string& v, int dflt) {
if (v.empty()) return dflt;
if (v == "auto") return 0;
if (v == "on" || v == "1" || v == "force" || v == "true" || v == "yes") return 1;
if (v == "off" || v == "0" || v == "false" || v == "no") return 2;
return dflt;
}
// "on"/"off"/"1"/"true"/... -> bool.
static inline bool parse_bool(const std::string& v, bool dflt) {
int t = parse_tristate(v, dflt ? 1 : 2);
return t == 1;
}
// "patch"|"frame" -> {0 patch, 1 frame}.
static inline int parse_capmode(const std::string& v, int dflt) {
if (v == "patch" || v == "patches" || v == "0") return 0;
if (v == "frame" || v == "frames" || v == "1") return 1;
return dflt;
}
// key=value TOML-lite reader (flat keys, '#' comments) - enough for our knobs.
static inline void apply_toml(Config& c, const std::string& path) {
std::ifstream f(path);
if (!f) return;
std::string line;
while (std::getline(f, line)) {
auto h = line.find('#'); if (h != std::string::npos) line = line.substr(0, h);
auto eq = line.find('='); if (eq == std::string::npos) continue;
auto trim = [](std::string s){
size_t a = s.find_first_not_of(" \t\r\n"); size_t b = s.find_last_not_of(" \t\r\n");
return (a == std::string::npos) ? std::string() : s.substr(a, b - a + 1); };
std::string k = trim(line.substr(0, eq)), v = trim(line.substr(eq + 1));
if (k.empty() || v.empty()) continue;
if (k == "enabled") c.enabled = (v == "1" || v == "true");
else if (k == "debug") c.debug = parse_bool(v, c.debug);
else if (k == "pacing") c.pacing = parse_bool(v, c.pacing);
else if (k == "model") c.model = std::atoi(v.c_str());
else if (k == "multiplier") c.multiplier = std::atoi(v.c_str());
else if (k == "extra_images") c.extraImages = std::atoi(v.c_str());
else if (k == "perf_preset") c.perfPreset = std::atoi(v.c_str());
else if (k == "global_motion") c.gmMode = parse_tristate(v, c.gmMode);
else if (k == "flow_reg") c.frMode = parse_tristate(v, c.frMode);
else if (k == "fr_iters") c.frIters = std::atoi(v.c_str());
else if (k == "fr_lambda") c.frLambda = std::strtof(v.c_str(), nullptr);
else if (k == "fr_dt") c.frDt = std::strtof(v.c_str(), nullptr);
else if (k == "fr_edge") c.frEdge = std::strtof(v.c_str(), nullptr);
else if (k == "fr_eps") c.frEps = std::strtof(v.c_str(), nullptr);
else if (k == "flowScale") c.flowScale = std::strtof(v.c_str(), nullptr);
else if (k == "beta") c.beta = std::strtof(v.c_str(), nullptr);
else if (k == "lambda") c.lambda = std::strtof(v.c_str(), nullptr);
else if (k == "epsilon") c.epsilon = std::strtof(v.c_str(), nullptr);
else if (k == "photoScale") c.photoScale = std::strtof(v.c_str(), nullptr);
// ── capture-mode knobs ────────────────────────────────────────────────
else if (k == "capture") c.capture = parse_bool(v, c.capture);
else if (k == "capture_dir") c.capDir = v;
else if (k == "capture_width") c.captureW = std::atoi(v.c_str());
else if (k == "capture_height") c.captureH = std::atoi(v.c_str());
else if (k == "capture_mode") c.capMode = parse_capmode(v, c.capMode);
else if (k == "capture_patches") c.capPatches = std::atoi(v.c_str());
else if (k == "capture_patch_size") c.capPatchSize = std::atoi(v.c_str());
else if (k == "capture_motion") c.capMotion = std::strtof(v.c_str(), nullptr);
else if (k == "capture_shard_mb") c.capShardMB = std::atoi(v.c_str());
else if (k == "hudRect") {
// "x0,y0,x1,y1" in pixel coords
float r[4] = {0,0,0,0}; int n = 0;
size_t start = 0; std::string s = v;
for (; n < 4; ++n) {
size_t comma = s.find(',', start);
std::string tok = s.substr(start, comma == std::string::npos ? std::string::npos : comma - start);
r[n] = std::strtof(tok.c_str(), nullptr);
if (comma == std::string::npos) break;
start = comma + 1;
}
c.hudX0 = r[0]; c.hudY0 = r[1]; c.hudX1 = r[2]; c.hudY1 = r[3];
}
}
}
// Path of the conf.toml the app writes (used for hot-reload mtime checks).
static inline std::string conf_path() {
if (const char* p = std::getenv("WIN_FG_CONF")) return p;
const char* home = std::getenv("HOME");
return home ? std::string(home) + "/.config/win-fg/conf.toml" : std::string();
}
// Resolve the capture output root: explicit override, else $HOME/.cache/winfg-capture,
// else a /tmp fallback so a HOME-less prefix still writes somewhere pullable.
static inline std::string capture_root(const Config& c) {
if (!c.capDir.empty()) return c.capDir;
if (const char* home = std::getenv("HOME")) return std::string(home) + "/.cache/winfg-capture";
return std::string("/tmp/winfg-capture");
}
// env defaults first, then conf.toml overrides (file wins when present).
static inline Config load_config() {
Config c;
c.enabled = envi("WIN_FG_ENABLE", 0) != 0;
if (const char* d = std::getenv("WIN_FG_DEBUG")) c.debug = parse_bool(d, c.debug);
if (const char* pc = std::getenv("WIN_FG_PACING")) c.pacing = parse_bool(pc, c.pacing);
c.model = envi("WIN_FG_MODEL", c.model);
c.multiplier = envi("WIN_FG_MULT", c.multiplier);
c.extraImages = envi("WIN_FG_EXTRA_IMAGES", c.extraImages);
c.perfPreset = envi("WIN_FG_PERF_PRESET", c.perfPreset);
if (const char* g = std::getenv("WIN_FG_GM")) c.gmMode = parse_tristate(g, c.gmMode);
if (const char* r = std::getenv("WIN_FG_FLOWREG")) c.frMode = parse_tristate(r, c.frMode);
c.frIters = envi("WIN_FG_FR_ITERS", c.frIters);
c.frLambda = envf("WIN_FG_FR_LAMBDA", c.frLambda);
c.frDt = envf("WIN_FG_FR_DT", c.frDt);
c.frEdge = envf("WIN_FG_FR_EDGE", c.frEdge);
c.frEps = envf("WIN_FG_FR_EPS", c.frEps);
c.flowScale = envf("WIN_FG_FLOWSCALE", c.flowScale);
c.beta = envf("WIN_FG_BETA", c.beta);
c.lambda = envf("WIN_FG_LAMBDA", c.lambda);
c.epsilon = envf("WIN_FG_EPSILON", c.epsilon);
c.photoScale = envf("WIN_FG_PHOTOSCALE", c.photoScale);
// ── capture-mode env (conf.toml still wins below) ─────────────────────────
if (const char* cc = std::getenv("WIN_FG_CAPTURE")) c.capture = parse_bool(cc, c.capture);
c.captureW = envi("WIN_FG_CAPTURE_W", c.captureW);
c.captureH = envi("WIN_FG_CAPTURE_H", c.captureH);
if (const char* cm = std::getenv("WIN_FG_CAPTURE_MODE")) c.capMode = parse_capmode(cm, c.capMode);
c.capPatches = envi("WIN_FG_CAPTURE_PATCHES", c.capPatches);
c.capPatchSize = envi("WIN_FG_CAPTURE_PATCH", c.capPatchSize);
c.capMotion = envf("WIN_FG_CAPTURE_MOTION", c.capMotion);
c.capShardMB = envi("WIN_FG_CAPTURE_SHARD_MB", c.capShardMB);
if (const char* cd = std::getenv("WIN_FG_CAPTURE_DIR")) c.capDir = cd;
if (const char* h = std::getenv("WIN_FG_HUD_RECT")) {
// "x0,y0,x1,y1" - pixel coords; disabled when x0>=x1 or y0>=y1
float r[4] = {0,0,0,0}; int n = 0;
std::string s = h; size_t start = 0;
for (; n < 4; ++n) {
size_t comma = s.find(',', start);
r[n] = std::strtof(s.substr(start, comma == std::string::npos ? std::string::npos : comma - start).c_str(), nullptr);
if (comma == std::string::npos) break;
start = comma + 1;
}
c.hudX0 = r[0]; c.hudY0 = r[1]; c.hudX1 = r[2]; c.hudY1 = r[3];
}
const char* home = std::getenv("HOME");
if (home) apply_toml(c, std::string(home) + "/.config/win-fg/conf.toml");
if (const char* p = std::getenv("WIN_FG_CONF")) apply_toml(c, p);
c.sanitize();
return c;
}
// UBO layout - MUST match wfg_synth.comp binding 0.
// The vec4 hudRect is 16-byte aligned in std140, sits at offset 32 (after the
// 8 leading floats which naturally occupy 32B). Disabled when hudX0>=hudX1.
struct SynthUBO {
float flowScale, alpha, beta, lambda, epsilon, photoScale, pad0, pad1;
float hudX0, hudY0, hudX1, hudY1;
};
// UBO layout - MUST match of3_flow / of3_expand_m4 binding 0 (Model3UBO).
struct FlowUBO { float flowScale; uint32_t level; float occlLo; float occlHi; };
// C1 global-motion UBO - MUST match binding 1 in of3_gm_reduce / of3_gm_prewarp /
// of3_expand(_m4). std140: four vec4 = 64 bytes. The affine is in centered-UV
// space: P = [[p1,p3],[p2,p4]], translation (tx,ty); warp uvSrc = uv + P*(uv-0.5)
// + t maps a prev(template) coord to the curr(image) coord it samples (prev→curr).
// lin[] = running LK estimate (linearization point fed to of3_gm_reduce)
// app[] = APPLIED affine (of3_gm_prewarp + expand add-back); identity when
// disengaged so the pipeline is byte-identical to pre-C1.
struct GMUBO {
float lin[4]; // p1,p2,p3,p4
float linT[4]; // tx,ty, engaged, pad
float app[4]; // p1,p2,p3,p4
float appT[4]; // tx,ty, pad, pad
};
// C2 flow-regularization UBO - MUST match binding 0 (vec4 params) in
// of3_flowreg.comp. std140: one vec4 = 16 bytes. See Config::fr* fields.
struct FlowRegUBO {
float dt; // params.x - semi-implicit smoothing step
float lambda; // params.y - L1 data-fidelity weight (θ = dt·lambda)
float edgeAlpha; // params.z - luma-gradient edge sensitivity for g
float epsTV; // params.w - Charbonnier epsilon (px) for the TV diffusivity
};
} // namespace winfg
@@ -0,0 +1,44 @@
// GENERATED by tools/embed_spv.py - do not edit by hand.
// win-fg embedded SPIR-V: our optical-flow front end + synthesis only.
#pragma once
#include <cstdint>
#include <cstddef>
namespace winfg { namespace embedded {
static const uint32_t OF3_LUMA_SPV[] = {0x07230203u,0x00010300u,0x0008000bu,0x00000054u,0x00000000u,0x00020011u,0x00000001u,0x00020011u,0x00000032u,0x0006000bu,0x00000001u,0x4c534c47u,0x6474732eu,0x3035342eu,0x00000000u,0x0003000eu,0x00000000u,0x00000001u,0x0006000fu,0x00000005u,0x00000004u,0x6e69616du,0x00000000u,0x0000000du,0x00060010u,0x00000004u,0x00000011u,0x00000010u,0x00000010u,0x00000001u,0x00030003u,0x00000002u,0x000001c2u,0x00040005u,0x00000004u,0x6e69616du,0x00000000u,0x00030005u,0x00000009u,0x00646967u,0x00080005u,0x0000000du,0x475f6c67u,0x61626f6cu,0x766e496cu,0x7461636fu,0x496e6f69u,0x00000044u,0x00030005u,0x00000012u,0x006d6964u,0x00040005u,0x00000016u,0x74734475u,0x00000000u,0x00030005u,0x00000030u,0x00007675u,0x00030005u,0x0000003bu,0x00626772u,0x00040005u,0x0000003fu,0x63725375u,0x00000000u,0x00030005u,0x00000047u,0x00005966u,0x00040047u,0x0000000du,0x0000000bu,0x0000001cu,0x00030047u,0x00000016u,0x00000019u,0x00040047u,0x00000016u,0x00000021u,0x00000030u,0x00040047u,0x00000016u,0x00000022u,0x00000000u,0x00040047u,0x0000003fu,0x00000021u,0x00000020u,0x00040047u,0x0000003fu,0x00000022u,0x00000000u,0x00040047u,0x00000053u,0x0000000bu,0x00000019u,0x00020013u,0x00000002u,0x00030021u,0x00000003u,0x00000002u,0x00040015u,0x00000006u,0x00000020u,0x00000001u,0x00040017u,0x00000007u,0x00000006u,0x00000002u,0x00040020u,0x00000008u,0x00000007u,0x00000007u,0x00040015u,0x0000000au,0x00000020u,0x00000000u,0x00040017u,0x0000000bu,0x0000000au,0x00000003u,0x00040020u,0x0000000cu,0x00000001u,0x0000000bu,0x0004003bu,0x0000000cu,0x0000000du,0x00000001u,0x00040017u,0x0000000eu,0x0000000au,0x00000002u,0x00030016u,0x00000013u,0x00000020u,0x00090019u,0x00000014u,0x00000013u,0x00000001u,0x00000000u,0x00000000u,0x00000000u,0x00000002u,0x00000003u,0x00040020u,0x00000015u,0x00000000u,0x00000014u,0x0004003bu,0x00000015u,0x00000016u,0x00000000u,0x00020014u,0x00000019u,0x0004002bu,0x0000000au,0x0000001au,0x00000000u,0x00040020u,0x0000001bu,0x00000007u,0x00000006u,0x0004002bu,0x0000000au,0x00000024u,0x00000001u,0x00040017u,0x0000002eu,0x00000013u,0x00000002u,0x00040020u,0x0000002fu,0x00000007u,0x0000002eu,0x0004002bu,0x00000013u,0x00000033u,0x3f000000u,0x00040017u,0x00000039u,0x00000013u,0x00000003u,0x00040020u,0x0000003au,0x00000007u,0x00000039u,0x00090019u,0x0000003cu,0x00000013u,0x00000001u,0x00000000u,0x00000000u,0x00000000u,0x00000001u,0x00000000u,0x0003001bu,0x0000003du,0x0000003cu,0x00040020u,0x0000003eu,0x00000000u,0x0000003du,0x0004003bu,0x0000003eu,0x0000003fu,0x00000000u,0x0004002bu,0x00000013u,0x00000042u,0x00000000u,0x00040017u,0x00000043u,0x00000013u,0x00000004u,0x00040020u,0x00000046u,0x00000007u,0x00000013u,0x0004002bu,0x00000013u,0x00000049u,0x3e59b3d0u,0x0004002bu,0x00000013u,0x0000004au,0x3f371759u,0x0004002bu,0x00000013u,0x0000004bu,0x3d93dd98u,0x0006002cu,0x00000039u,0x0000004cu,0x00000049u,0x0000004au,0x0000004bu,0x0004002bu,0x0000000au,0x00000052u,0x00000010u,0x0006002cu,0x0000000bu,0x00000053u,0x00000052u,0x00000052u,0x00000024u,0x00050036u,0x00000002u,0x00000004u,0x00000000u,0x00000003u,0x000200f8u,0x00000005u,0x0004003bu,0x00000008u,0x00000009u,0x00000007u,0x0004003bu,0x00000008u,0x00000012u,0x00000007u,0x0004003bu,0x0000002fu,0x00000030u,0x00000007u,0x0004003bu,0x0000003au,0x0000003bu,0x00000007u,0x0004003bu,0x00000046u,0x00000047u,0x00000007u,0x0004003du,0x0000000bu,0x0000000fu,0x0000000du,0x0007004fu,0x0000000eu,0x00000010u,0x0000000fu,0x0000000fu,0x00000000u,0x00000001u,0x0004007cu,0x00000007u,0x00000011u,0x00000010u,0x0003003eu,0x00000009u,0x00000011u,0x0004003du,0x00000014u,0x00000017u,0x00000016u,0x00040068u,0x00000007u,0x00000018u,0x00000017u,0x0003003eu,0x00000012u,0x00000018u,0x00050041u,0x0000001bu,0x0000001cu,0x00000009u,0x0000001au,0x0004003du,0x00000006u,0x0000001du,0x0000001cu,0x00050041u,0x0000001bu,0x0000001eu,0x00000012u,0x0000001au,0x0004003du,0x00000006u,0x0000001fu,0x0000001eu,0x000500afu,0x00000019u,0x00000020u,0x0000001du,0x0000001fu,0x000400a8u,0x00000019u,0x00000021u,0x00000020u,0x000300f7u,0x00000023u,0x00000000u,0x000400fau,0x00000021u,0x00000022u,0x00000023u,0x000200f8u,0x00000022u,0x00050041u,0x0000001bu,0x00000025u,0x00000009u,0x00000024u,0x0004003du,0x00000006u,0x00000026u,0x00000025u,0x00050041u,0x0000001bu,0x00000027u,0x00000012u,0x00000024u,0x0004003du,0x00000006u,0x00000028u,0x00000027u,0x000500afu,0x00000019u,0x00000029u,0x00000026u,0x00000028u,0x000200f9u,0x00000023u,0x000200f8u,0x00000023u,0x000700f5u,0x00000019u,0x0000002au,0x00000020u,0x00000005u,0x00000029u,0x00000022u,0x000300f7u,0x0000002cu,0x00000000u,0x000400fau,0x0000002au,0x0000002bu,0x0000002cu,0x000200f8u,0x0000002bu,0x000100fdu,0x000200f8u,0x0000002cu,0x0004003du,0x00000007u,0x00000031u,0x00000009u,0x0004006fu,0x0000002eu,0x00000032u,0x00000031u,0x00050050u,0x0000002eu,0x00000034u,0x00000033u,0x00000033u,0x00050081u,0x0000002eu,0x00000035u,0x00000032u,0x00000034u,0x0004003du,0x00000007u,0x00000036u,0x00000012u,0x0004006fu,0x0000002eu,0x00000037u,0x00000036u,0x00050088u,0x0000002eu,0x00000038u,0x0Line truncated
static const size_t OF3_LUMA_LEN = 481;
static const uint32_t OF3_DOWNSAMPLE_SPV[] = {0x07230203u,0x00010300u,0x0008000bu,0x0000008au,0x00000000u,0x00020011u,0x00000001u,0x00020011u,0x00000032u,0x0006000bu,0x00000001u,0x4c534c47u,0x6474732eu,0x3035342eu,0x00000000u,0x0003000eu,0x00000000u,0x00000001u,0x0006000fu,0x00000005u,0x00000004u,0x6e69616du,0x00000000u,0x0000000du,0x00060010u,0x00000004u,0x00000011u,0x00000010u,0x00000010u,0x00000001u,0x00030003u,0x00000002u,0x000001c2u,0x00040005u,0x00000004u,0x6e69616du,0x00000000u,0x00030005u,0x00000009u,0x00646967u,0x00080005u,0x0000000du,0x475f6c67u,0x61626f6cu,0x766e496cu,0x7461636fu,0x496e6f69u,0x00000044u,0x00030005u,0x00000012u,0x006d6964u,0x00040005u,0x00000016u,0x74734475u,0x00000000u,0x00040005u,0x00000030u,0x44637273u,0x00006d69u,0x00040005u,0x00000034u,0x63725375u,0x00000000u,0x00040005u,0x0000003au,0x65736162u,0x00000000u,0x00030005u,0x00000044u,0x00000068u,0x00030005u,0x0000004au,0x00000061u,0x00030005u,0x00000059u,0x00000062u,0x00030005u,0x00000065u,0x00000063u,0x00030005u,0x00000071u,0x00000064u,0x00040047u,0x0000000du,0x0000000bu,0x0000001cu,0x00030047u,0x00000016u,0x00000019u,0x00040047u,0x00000016u,0x00000021u,0x00000030u,0x00040047u,0x00000016u,0x00000022u,0x00000000u,0x00040047u,0x00000034u,0x00000021u,0x00000020u,0x00040047u,0x00000034u,0x00000022u,0x00000000u,0x00040047u,0x00000089u,0x0000000bu,0x00000019u,0x00020013u,0x00000002u,0x00030021u,0x00000003u,0x00000002u,0x00040015u,0x00000006u,0x00000020u,0x00000001u,0x00040017u,0x00000007u,0x00000006u,0x00000002u,0x00040020u,0x00000008u,0x00000007u,0x00000007u,0x00040015u,0x0000000au,0x00000020u,0x00000000u,0x00040017u,0x0000000bu,0x0000000au,0x00000003u,0x00040020u,0x0000000cu,0x00000001u,0x0000000bu,0x0004003bu,0x0000000cu,0x0000000du,0x00000001u,0x00040017u,0x0000000eu,0x0000000au,0x00000002u,0x00030016u,0x00000013u,0x00000020u,0x00090019u,0x00000014u,0x00000013u,0x00000001u,0x00000000u,0x00000000u,0x00000000u,0x00000002u,0x00000003u,0x00040020u,0x00000015u,0x00000000u,0x00000014u,0x0004003bu,0x00000015u,0x00000016u,0x00000000u,0x00020014u,0x00000019u,0x0004002bu,0x0000000au,0x0000001au,0x00000000u,0x00040020u,0x0000001bu,0x00000007u,0x00000006u,0x0004002bu,0x0000000au,0x00000024u,0x00000001u,0x00040017u,0x0000002eu,0x00000013u,0x00000002u,0x00040020u,0x0000002fu,0x00000007u,0x0000002eu,0x00090019u,0x00000031u,0x00000013u,0x00000001u,0x00000000u,0x00000000u,0x00000000u,0x00000001u,0x00000000u,0x0003001bu,0x00000032u,0x00000031u,0x00040020u,0x00000033u,0x00000000u,0x00000032u,0x0004003bu,0x00000033u,0x00000034u,0x00000000u,0x0004002bu,0x00000006u,0x00000036u,0x00000000u,0x0004002bu,0x00000013u,0x0000003du,0x40000000u,0x0004002bu,0x00000013u,0x0000003fu,0x3f800000u,0x0004002bu,0x00000013u,0x00000045u,0x3f000000u,0x00040020u,0x00000049u,0x00000007u,0x00000013u,0x0004002bu,0x00000013u,0x00000055u,0x00000000u,0x00040017u,0x00000056u,0x00000013u,0x00000004u,0x0004002bu,0x00000013u,0x00000085u,0x3e800000u,0x0004002bu,0x0000000au,0x00000088u,0x00000010u,0x0006002cu,0x0000000bu,0x00000089u,0x00000088u,0x00000088u,0x00000024u,0x00050036u,0x00000002u,0x00000004u,0x00000000u,0x00000003u,0x000200f8u,0x00000005u,0x0004003bu,0x00000008u,0x00000009u,0x00000007u,0x0004003bu,0x00000008u,0x00000012u,0x00000007u,0x0004003bu,0x0000002fu,0x00000030u,0x00000007u,0x0004003bu,0x0000002fu,0x0000003au,0x00000007u,0x0004003bu,0x0000002fu,0x00000044u,0x00000007u,0x0004003bu,0x00000049u,0x0000004au,0x00000007u,0x0004003bu,0x00000049u,0x00000059u,0x00000007u,0x0004003bu,0x00000049u,0x00000065u,0x00000007u,0x0004003bu,0x00000049u,0x00000071u,0x00000007u,0x0004003du,0x0000000bu,0x0000000fu,0x0000000du,0x0007004fu,0x0000000eu,0x00000010u,0x0000000fu,0x0000000fu,0x00000000u,0x00000001u,0x0004007cu,0x00000007u,0x00000011u,0x00000010u,0x0003003eu,0x00000009u,0x00000011u,0x0004003du,0x00000014u,0x00000017u,0x00000016u,0x00040068u,0x00000007u,0x00000018u,0x00000017u,0x0003003eu,0x00000012u,0x00000018u,0x00050041u,0x0000001bu,0x0000001cu,0x00000009u,0x0000001au,0x0004003du,0x00000006u,0x0000001du,0x0000001cu,0x00050041u,0x0000001bu,0x0000001eu,0x00000012u,0x0000001au,0x0004003du,0x00000006u,0x0000001fu,0x0000001eu,0x000500afu,0x00000019u,0x00000020u,0x0000001du,0x0000001fu,0x000400a8u,0x00000019u,0x00000021u,0x00000020u,0x000300f7u,0x00000023u,0x00000000u,0x000400fau,0x00000021u,0x00000022u,0x00000023u,0x000200f8u,0x00000022u,0x00050041u,0x0000001bu,0x00000025u,0x00000009u,0x00000024u,0x0004003du,0x00000006u,0x00000026u,0x00000025u,0x00050041u,0x0000001bu,0x00000027u,0x00000012u,0x00000024u,0x0004003du,0x00000006u,0x00000028u,0x00000027u,0x000500afu,0x00000019u,0x00000029u,0x00000026u,0x00000028u,0x000200f9u,0x00000023u,0x000200f8u,0x00000023u,0x000700f5u,0x00000019u,0x0000002au,0x00000020u,0x00000005u,0x00000029u,0x00000022u,0x000300f7u,0x0000002cu,0x00000000u,0x000400fau,0x0000002au,0x0000002bu,0x0000002cu,0x000200f8u,0x0000002bu,0x000100fdu,0x000200f8u,0x0000002cu,0x0004003du,0x00000032u,0x00000035u,0x00000034u,0x00040064u,0x00000031u,0x00000037u,0x00000035u,0x0005006Line truncated
static const size_t OF3_DOWNSAMPLE_LEN = 753;
static const uint32_t OF3_FLOW_SPV[] = {0x07230203u,0x00010300u,0x0008000bu,0x00000185u,0x00000000u,0x00020011u,0x00000001u,0x00020011u,0x00000032u,0x0006000bu,0x00000001u,0x4c534c47u,0x6474732eu,0x3035342eu,0x00000000u,0x0003000eu,0x00000000u,0x00000001u,0x0006000fu,0x00000005u,0x00000004u,0x6e69616du,0x00000000u,0x0000000du,0x00060010u,0x00000004u,0x00000011u,0x00000010u,0x00000010u,0x00000001u,0x00030003u,0x00000002u,0x000001c2u,0x00040005u,0x00000004u,0x6e69616du,0x00000000u,0x00030005u,0x00000009u,0x00646967u,0x00080005u,0x0000000du,0x475f6c67u,0x61626f6cu,0x766e496cu,0x7461636fu,0x496e6f69u,0x00000044u,0x00030005u,0x00000012u,0x006d6964u,0x00040005u,0x00000016u,0x6f6c4675u,0x00000077u,0x00040005u,0x00000030u,0x44766e69u,0x00006d69u,0x00030005u,0x00000036u,0x00007675u,0x00040005u,0x0000003fu,0x654c6f74u,0x006c6576u,0x00030005u,0x00000040u,0x00000055u,0x00060006u,0x00000040u,0x00000000u,0x776f6c66u,0x6c616353u,0x00000065u,0x00050006u,0x00000040u,0x00000001u,0x6576656cu,0x0000006cu,0x00050006u,0x00000040u,0x00000002u,0x30646170u,0x00000000u,0x00050006u,0x00000040u,0x00000003u,0x31646170u,0x00000000u,0x00030005u,0x00000042u,0x00000000u,0x00050005u,0x0000004au,0x64657270u,0x6c6c7546u,0x00000000u,0x00050005u,0x0000004eu,0x65725075u,0x74636964u,0x0000726fu,0x00050005u,0x00000055u,0x64657270u,0x6576654cu,0x0000006cu,0x00040005u,0x00000059u,0x74736562u,0x00646153u,0x00050005u,0x0000005bu,0x74736562u,0x70736944u,0x00000000u,0x00030005u,0x0000005du,0x00007973u,0x00030005u,0x00000067u,0x00007873u,0x00040005u,0x0000006fu,0x646e6163u,0x00000000u,0x00030005u,0x00000077u,0x00646173u,0x00030005u,0x00000078u,0x00007962u,0x00030005u,0x00000081u,0x00007862u,0x00030005u,0x00000089u,0x00006f62u,0x00030005u,0x0000008fu,0x00000070u,0x00050005u,0x00000090u,0x6d754c75u,0x65725061u,0x00000076u,0x00030005u,0x00000099u,0x00000063u,0x00050005u,0x0000009au,0x6d754c75u,0x72754361u,0x00000072u,0x00040005u,0x000000cau,0x43646173u,0x00000000u,0x00040005u,0x000000ccu,0x58646173u,0x0000006du,0x00040005u,0x000000cdu,0x58646173u,0x00000070u,0x00040005u,0x000000ceu,0x59646173u,0x0000006du,0x00040005u,0x000000cfu,0x59646173u,0x00000070u,0x00030005u,0x000000d0u,0x00007962u,0x00030005u,0x000000d8u,0x00007862u,0x00030005u,0x000000e0u,0x00006f62u,0x00030005u,0x000000e6u,0x00000070u,0x00040005u,0x000000efu,0x646e6163u,0x00006d58u,0x00040005u,0x000000f4u,0x646e6163u,0x00007058u,0x00040005u,0x000000f8u,0x646e6163u,0x00006d59u,0x00040005u,0x000000fcu,0x646e6163u,0x00007059u,0x00030005u,0x00000148u,0x00007864u,0x00030005u,0x00000149u,0x00007964u,0x00040005u,0x0000014au,0x6f6e6564u,0x0000586du,0x00040005u,0x00000152u,0x6f6e6564u,0x0000596du,0x00050005u,0x00000176u,0x776f6c66u,0x6c6c7546u,0x00000000u,0x00040047u,0x0000000du,0x0000000bu,0x0000001cu,0x00030047u,0x00000016u,0x00000019u,0x00040047u,0x00000016u,0x00000021u,0x00000030u,0x00040047u,0x00000016u,0x00000022u,0x00000000u,0x00030047u,0x00000040u,0x00000002u,0x00050048u,0x00000040u,0x00000000u,0x00000023u,0x00000000u,0x00050048u,0x00000040u,0x00000001u,0x00000023u,0x00000004u,0x00050048u,0x00000040u,0x00000002u,0x00000023u,0x00000008u,0x00050048u,0x00000040u,0x00000003u,0x00000023u,0x0000000cu,0x00040047u,0x00000042u,0x00000021u,0x00000000u,0x00040047u,0x00000042u,0x00000022u,0x00000000u,0x00040047u,0x0000004eu,0x00000021u,0x00000022u,0x00040047u,0x0000004eu,0x00000022u,0x00000000u,0x00040047u,0x00000090u,0x00000021u,0x00000020u,0x00040047u,0x00000090u,0x00000022u,0x00000000u,0x00040047u,0x0000009au,0x00000021u,0x00000021u,0x00040047u,0x0000009au,0x00000022u,0x00000000u,0x00040047u,0x00000184u,0x0000000bu,0x00000019u,0x00020013u,0x00000002u,0x00030021u,0x00000003u,0x00000002u,0x00040015u,0x00000006u,0x00000020u,0x00000001u,0x00040017u,0x00000007u,0x00000006u,0x00000002u,0x00040020u,0x00000008u,0x00000007u,0x00000007u,0x00040015u,0x0000000au,0x00000020u,0x00000000u,0x00040017u,0x0000000bu,0x0000000au,0x00000003u,0x00040020u,0x0000000cu,0x00000001u,0x0000000bu,0x0004003bu,0x0000000cu,0x0000000du,0x00000001u,0x00040017u,0x0000000eu,0x0000000au,0x00000002u,0x00030016u,0x00000013u,0x00000020u,0x00090019u,0x00000014u,0x00000013u,0x00000001u,0x00000000u,0x00000000u,0x00000000u,0x00000002u,0x00000002u,0x00040020u,0x00000015u,0x00000000u,0x00000014u,0x0004003bu,0x00000015u,0x00000016u,0x00000000u,0x00020014u,0x00000019u,0x0004002bu,0x0000000au,0x0000001au,0x00000000u,0x00040020u,0x0000001bu,0x00000007u,0x00000006u,0x0004002bu,0x0000000au,0x00000024u,0x00000001u,0x00040017u,0x0000002eu,0x00000013u,0x00000002u,0x00040020u,0x0000002fu,0x00000007u,0x0000002eu,0x0004002bu,0x00000013u,0x00000031u,0x3f800000u,0x0004002bu,0x00000013u,0x00000039u,0x3f000000u,0x00040020u,0x0000003eu,0x00000007u,0x00000013u,0x0006001eu,0x00000040u,0x00000013u,0x0000000au,0x0000000au,0x0000000au,0x00040020u,0x00000041u,0x00000002u,0x00000040u,0x0004003bu,0x00000041u,0x00000042u,0x00000002u,0x0004002bu,0x00000006u,0x00000043u,0x00000001u,0x00040020u,0x00000044u,0x00000002u,0x0000000au,0x00090019u,0x0000004bu,0x00000013u,0x00000001u,0x0Line truncated
static const size_t OF3_FLOW_LEN = 2253;
static const uint32_t OF3_EXPAND_SPV[] = {0x07230203u,0x00010300u,0x0008000bu,0x00000124u,0x00000000u,0x00020011u,0x00000001u,0x00020011u,0x00000032u,0x0006000bu,0x00000001u,0x4c534c47u,0x6474732eu,0x3035342eu,0x00000000u,0x0003000eu,0x00000000u,0x00000001u,0x0006000fu,0x00000005u,0x00000004u,0x6e69616du,0x00000000u,0x00000049u,0x00060010u,0x00000004u,0x00000011u,0x00000010u,0x00000010u,0x00000001u,0x00030003u,0x00000002u,0x000001c2u,0x00040005u,0x00000004u,0x6e69616du,0x00000000u,0x00080005u,0x0000000eu,0x3564656du,0x3b316628u,0x663b3166u,0x31663b31u,0x3b31663bu,0x00000000u,0x00030005u,0x00000009u,0x00000061u,0x00030005u,0x0000000au,0x00000062u,0x00030005u,0x0000000bu,0x00000063u,0x00030005u,0x0000000cu,0x00000064u,0x00030005u,0x0000000du,0x00000065u,0x00030005u,0x00000010u,0x00000078u,0x00030005u,0x00000034u,0x00000079u,0x00030005u,0x00000045u,0x00646967u,0x00080005u,0x00000049u,0x475f6c67u,0x61626f6cu,0x766e496cu,0x7461636fu,0x496e6f69u,0x00000044u,0x00030005u,0x0000004eu,0x006d6964u,0x00040005u,0x00000051u,0x64774675u,0x00000000u,0x00030005u,0x0000006bu,0x00007675u,0x00030005u,0x00000074u,0x00007366u,0x00050005u,0x00000079u,0x6f6c4675u,0x6e694677u,0x00000065u,0x00030005u,0x00000081u,0x00000063u,0x00030005u,0x00000088u,0x00006d78u,0x00030005u,0x00000091u,0x00007078u,0x00030005u,0x0000009au,0x00006d79u,0x00030005u,0x000000a3u,0x00007079u,0x00030005u,0x000000acu,0x00000064u,0x00040005u,0x000000adu,0x61726170u,0x0000006du,0x00040005u,0x000000b0u,0x61726170u,0x0000006du,0x00040005u,0x000000b3u,0x61726170u,0x0000006du,0x00040005u,0x000000b6u,0x61726170u,0x0000006du,0x00040005u,0x000000b9u,0x61726170u,0x0000006du,0x00040005u,0x000000bdu,0x61726170u,0x0000006du,0x00040005u,0x000000c0u,0x61726170u,0x0000006du,0x00040005u,0x000000c3u,0x61726170u,0x0000006du,0x00040005u,0x000000c6u,0x61726170u,0x0000006du,0x00040005u,0x000000c9u,0x61726170u,0x0000006du,0x00030005u,0x000000ceu,0x00000071u,0x00030005u,0x000000d2u,0x00787067u,0x00030005u,0x000000d3u,0x00004d47u,0x00050006u,0x000000d3u,0x00000000u,0x694c6d67u,0x0000006eu,0x00050006u,0x000000d3u,0x00000001u,0x694c6d67u,0x0000546eu,0x00050006u,0x000000d3u,0x00000002u,0x70416d67u,0x00000070u,0x00050006u,0x000000d3u,0x00000003u,0x70416d67u,0x00005470u,0x00030005u,0x000000d5u,0x00000000u,0x00030005u,0x000000fdu,0x00003241u,0x00040005u,0x0000010bu,0x6c6c7566u,0x00000000u,0x00040005u,0x00000117u,0x64774275u,0x00000000u,0x00030005u,0x00000121u,0x00000055u,0x00060006u,0x00000121u,0x00000000u,0x776f6c66u,0x6c616353u,0x00000065u,0x00050006u,0x00000121u,0x00000001u,0x6576656cu,0x0000006cu,0x00050006u,0x00000121u,0x00000002u,0x30646170u,0x00000000u,0x00050006u,0x00000121u,0x00000003u,0x31646170u,0x00000000u,0x00030005u,0x00000123u,0x00000000u,0x00040047u,0x00000049u,0x0000000bu,0x0000001cu,0x00030047u,0x00000051u,0x00000019u,0x00040047u,0x00000051u,0x00000021u,0x00000030u,0x00040047u,0x00000051u,0x00000022u,0x00000000u,0x00040047u,0x00000079u,0x00000021u,0x00000020u,0x00040047u,0x00000079u,0x00000022u,0x00000000u,0x00030047u,0x000000d3u,0x00000002u,0x00050048u,0x000000d3u,0x00000000u,0x00000023u,0x00000000u,0x00050048u,0x000000d3u,0x00000001u,0x00000023u,0x00000010u,0x00050048u,0x000000d3u,0x00000002u,0x00000023u,0x00000020u,0x00050048u,0x000000d3u,0x00000003u,0x00000023u,0x00000030u,0x00040047u,0x000000d5u,0x00000021u,0x00000001u,0x00040047u,0x000000d5u,0x00000022u,0x00000000u,0x00030047u,0x00000117u,0x00000019u,0x00040047u,0x00000117u,0x00000021u,0x00000031u,0x00040047u,0x00000117u,0x00000022u,0x00000000u,0x00040047u,0x00000120u,0x0000000bu,0x00000019u,0x00030047u,0x00000121u,0x00000002u,0x00050048u,0x00000121u,0x00000000u,0x00000023u,0x00000000u,0x00050048u,0x00000121u,0x00000001u,0x00000023u,0x00000004u,0x00050048u,0x00000121u,0x00000002u,0x00000023u,0x00000008u,0x00050048u,0x00000121u,0x00000003u,0x00000023u,0x0000000cu,0x00040047u,0x00000123u,0x00000021u,0x00000000u,0x00040047u,0x00000123u,0x00000022u,0x00000000u,0x00020013u,0x00000002u,0x00030021u,0x00000003u,0x00000002u,0x00030016u,0x00000006u,0x00000020u,0x00040020u,0x00000007u,0x00000007u,0x00000006u,0x00080021u,0x00000008u,0x00000006u,0x00000007u,0x00000007u,0x00000007u,0x00000007u,0x00000007u,0x00040015u,0x00000042u,0x00000020u,0x00000001u,0x00040017u,0x00000043u,0x00000042u,0x00000002u,0x00040020u,0x00000044u,0x00000007u,0x00000043u,0x00040015u,0x00000046u,0x00000020u,0x00000000u,0x00040017u,0x00000047u,0x00000046u,0x00000003u,0x00040020u,0x00000048u,0x00000001u,0x00000047u,0x0004003bu,0x00000048u,0x00000049u,0x00000001u,0x00040017u,0x0000004au,0x00000046u,0x00000002u,0x00090019u,0x0000004fu,0x00000006u,0x00000001u,0x00000000u,0x00000000u,0x00000000u,0x00000002u,0x00000002u,0x00040020u,0x00000050u,0x00000000u,0x0000004fu,0x0004003bu,0x00000050u,0x00000051u,0x00000000u,0x00020014u,0x00000054u,0x0004002bu,0x00000046u,0x00000055u,0x00000000u,0x00040020u,0x00000056u,0x00000007u,0x00000042u,0x0004002bu,0x00000046u,0x0000005fu,0x00000001u,0x00040017u,0x00000069u,0x00000006u,0x00000002u,0x00040020u,0x0000006au,0x00000007u,0Line truncated
static const size_t OF3_EXPAND_LEN = 1798;
static const uint32_t OF3_FLOW_M4_SPV[] = {0x07230203u,0x00010300u,0x0008000bu,0x00000151u,0x00000000u,0x00020011u,0x00000001u,0x00020011u,0x00000032u,0x0006000bu,0x00000001u,0x4c534c47u,0x6474732eu,0x3035342eu,0x00000000u,0x0003000eu,0x00000000u,0x00000001u,0x0006000fu,0x00000005u,0x00000004u,0x6e69616du,0x00000000u,0x000000f6u,0x00060010u,0x00000004u,0x00000011u,0x00000010u,0x00000010u,0x00000001u,0x00030003u,0x00000002u,0x000001c2u,0x00040005u,0x00000004u,0x6e69616du,0x00000000u,0x00080005u,0x00000010u,0x636f6c62u,0x6461536bu,0x31327328u,0x3132733bu,0x3266763bu,0x0000003bu,0x00030005u,0x0000000du,0x00000061u,0x00030005u,0x0000000eu,0x00000062u,0x00040005u,0x0000000fu,0x646e6163u,0x00000000u,0x00070005u,0x00000016u,0x766c6f73u,0x32732865u,0x32733b31u,0x66763b31u,0x00003b32u,0x00030005u,0x00000013u,0x00000061u,0x00030005u,0x00000014u,0x00000062u,0x00040005u,0x00000015u,0x64657270u,0x00000000u,0x00030005u,0x00000019u,0x00646173u,0x00030005u,0x0000001du,0x00007962u,0x00030005u,0x00000028u,0x00007862u,0x00030005u,0x00000030u,0x00006f62u,0x00030005u,0x00000036u,0x00006170u,0x00030005u,0x00000039u,0x00765567u,0x00050005u,0x0000003cu,0x766e4967u,0x616d754cu,0x00000000u,0x00030005u,0x00000045u,0x00006270u,0x00040005u,0x0000005du,0x74736562u,0x00646153u,0x00050005u,0x0000005fu,0x74736562u,0x70736944u,0x00000000u,0x00030005u,0x00000061u,0x00007973u,0x00030005u,0x0000006bu,0x00007873u,0x00040005u,0x00000073u,0x646e6163u,0x00000000u,0x00030005u,0x0000007bu,0x00646173u,0x00040005u,0x0000007cu,0x61726170u,0x0000006du,0x00030005u,0x00000095u,0x00000055u,0x00060006u,0x00000095u,0x00000000u,0x776f6c66u,0x6c616353u,0x00000065u,0x00050006u,0x00000095u,0x00000001u,0x6576656cu,0x0000006cu,0x00050006u,0x00000095u,0x00000002u,0x6c63636fu,0x00006f4cu,0x00050006u,0x00000095u,0x00000003u,0x6c63636fu,0x00006948u,0x00030005u,0x00000097u,0x00000000u,0x00040005u,0x0000009eu,0x43646173u,0x00000000u,0x00040005u,0x000000a1u,0x58646173u,0x0000006du,0x00040005u,0x000000a6u,0x61726170u,0x0000006du,0x00040005u,0x000000a9u,0x58646173u,0x00000070u,0x00040005u,0x000000aeu,0x61726170u,0x0000006du,0x00040005u,0x000000b1u,0x59646173u,0x0000006du,0x00040005u,0x000000b5u,0x61726170u,0x0000006du,0x00040005u,0x000000b8u,0x59646173u,0x00000070u,0x00040005u,0x000000bcu,0x61726170u,0x0000006du,0x00030005u,0x000000bfu,0x00007864u,0x00030005u,0x000000c0u,0x00007964u,0x00040005u,0x000000c1u,0x6f6e6564u,0x0000586du,0x00040005u,0x000000c9u,0x6f6e6564u,0x0000596du,0x00030005u,0x000000f3u,0x00646967u,0x00080005u,0x000000f6u,0x475f6c67u,0x61626f6cu,0x766e496cu,0x7461636fu,0x496e6f69u,0x00000044u,0x00030005u,0x000000fbu,0x006d6964u,0x00040005u,0x000000feu,0x6f6c4675u,0x00000077u,0x00050005u,0x0000011au,0x6d754c75u,0x72754361u,0x00000072u,0x00040005u,0x00000122u,0x654c6f74u,0x006c6576u,0x00040005u,0x00000129u,0x64657270u,0x00000000u,0x00050005u,0x0000012au,0x65725075u,0x74636964u,0x0000726fu,0x00030005u,0x0000012eu,0x00647766u,0x00050005u,0x0000012fu,0x6d754c75u,0x65725061u,0x00000076u,0x00040005u,0x00000134u,0x61726170u,0x0000006du,0x00030005u,0x00000136u,0x00647762u,0x00040005u,0x0000013bu,0x61726170u,0x0000006du,0x00040005u,0x0000013du,0x75466f74u,0x00006c6cu,0x00030047u,0x00000095u,0x00000002u,0x00050048u,0x00000095u,0x00000000u,0x00000023u,0x00000000u,0x00050048u,0x00000095u,0x00000001u,0x00000023u,0x00000004u,0x00050048u,0x00000095u,0x00000002u,0x00000023u,0x00000008u,0x00050048u,0x00000095u,0x00000003u,0x00000023u,0x0000000cu,0x00040047u,0x00000097u,0x00000021u,0x00000000u,0x00040047u,0x00000097u,0x00000022u,0x00000000u,0x00040047u,0x000000f6u,0x0000000bu,0x0000001cu,0x00030047u,0x000000feu,0x00000019u,0x00040047u,0x000000feu,0x00000021u,0x00000030u,0x00040047u,0x000000feu,0x00000022u,0x00000000u,0x00040047u,0x0000011au,0x00000021u,0x00000021u,0x00040047u,0x0000011au,0x00000022u,0x00000000u,0x00040047u,0x0000012au,0x00000021u,0x00000022u,0x00040047u,0x0000012au,0x00000022u,0x00000000u,0x00040047u,0x0000012fu,0x00000021u,0x00000020u,0x00040047u,0x0000012fu,0x00000022u,0x00000000u,0x00040047u,0x00000150u,0x0000000bu,0x00000019u,0x00020013u,0x00000002u,0x00030021u,0x00000003u,0x00000002u,0x00030016u,0x00000006u,0x00000020u,0x00090019u,0x00000007u,0x00000006u,0x00000001u,0x00000000u,0x00000000u,0x00000000u,0x00000001u,0x00000000u,0x0003001bu,0x00000008u,0x00000007u,0x00040020u,0x00000009u,0x00000000u,0x00000008u,0x00040017u,0x0000000au,0x00000006u,0x00000002u,0x00040020u,0x0000000bu,0x00000007u,0x0000000au,0x00060021u,0x0000000cu,0x00000006u,0x00000009u,0x00000009u,0x0000000bu,0x00060021u,0x00000012u,0x0000000au,0x00000009u,0x00000009u,0x0000000bu,0x00040020u,0x00000018u,0x00000007u,0x00000006u,0x0004002bu,0x00000006u,0x0000001au,0x00000000u,0x00040015u,0x0000001bu,0x00000020u,0x00000001u,0x00040020u,0x0000001cu,0x00000007u,0x0000001bu,0x0004002bu,0x0000001bu,0x0000001eu,0xffffffffu,0x0004002bu,0x0000001bu,0x00000025u,0x00000001u,0x00020014u,0x00000026u,0x00040020u,0x00000038u,0x00000006u,0x0000000au,0x0004003bu,0x00000038u,0x00000039u,0x00000006u,0x0004003bu,Line truncated
static const size_t OF3_FLOW_M4_LEN = 2005;
static const uint32_t OF3_EXPAND_M4_SPV[] = {0x07230203u,0x00010300u,0x0008000bu,0x00000169u,0x00000000u,0x00020011u,0x00000001u,0x00020011u,0x00000032u,0x0006000bu,0x00000001u,0x4c534c47u,0x6474732eu,0x3035342eu,0x00000000u,0x0003000eu,0x00000000u,0x00000001u,0x0006000fu,0x00000005u,0x00000004u,0x6e69616du,0x00000000u,0x00000049u,0x00060010u,0x00000004u,0x00000011u,0x00000010u,0x00000010u,0x00000001u,0x00030003u,0x00000002u,0x000001c2u,0x00040005u,0x00000004u,0x6e69616du,0x00000000u,0x00080005u,0x0000000eu,0x3564656du,0x3b316628u,0x663b3166u,0x31663b31u,0x3b31663bu,0x00000000u,0x00030005u,0x00000009u,0x00000061u,0x00030005u,0x0000000au,0x00000062u,0x00030005u,0x0000000bu,0x00000063u,0x00030005u,0x0000000cu,0x00000064u,0x00030005u,0x0000000du,0x00000065u,0x00030005u,0x00000010u,0x00000078u,0x00030005u,0x00000034u,0x00000079u,0x00030005u,0x00000045u,0x00646967u,0x00080005u,0x00000049u,0x475f6c67u,0x61626f6cu,0x766e496cu,0x7461636fu,0x496e6f69u,0x00000044u,0x00030005u,0x0000004eu,0x006d6964u,0x00040005u,0x00000051u,0x64774675u,0x00000000u,0x00030005u,0x0000006bu,0x00007675u,0x00030005u,0x00000074u,0x00007366u,0x00050005u,0x00000079u,0x6f6c4675u,0x6e694677u,0x00000065u,0x00030005u,0x00000083u,0x00003463u,0x00030005u,0x00000088u,0x00006d78u,0x00030005u,0x00000090u,0x00007078u,0x00030005u,0x00000098u,0x00006d79u,0x00030005u,0x000000a0u,0x00007079u,0x00030005u,0x000000a8u,0x00000066u,0x00040005u,0x000000a9u,0x61726170u,0x0000006du,0x00040005u,0x000000acu,0x61726170u,0x0000006du,0x00040005u,0x000000afu,0x61726170u,0x0000006du,0x00040005u,0x000000b2u,0x61726170u,0x0000006du,0x00040005u,0x000000b5u,0x61726170u,0x0000006du,0x00040005u,0x000000b9u,0x61726170u,0x0000006du,0x00040005u,0x000000bcu,0x61726170u,0x0000006du,0x00040005u,0x000000bfu,0x61726170u,0x0000006du,0x00040005u,0x000000c2u,0x61726170u,0x0000006du,0x00040005u,0x000000c5u,0x61726170u,0x0000006du,0x00040005u,0x000000c9u,0x61726170u,0x0000006du,0x00040005u,0x000000cdu,0x61726170u,0x0000006du,0x00040005u,0x000000d0u,0x61726170u,0x0000006du,0x00040005u,0x000000d3u,0x61726170u,0x0000006du,0x00040005u,0x000000d6u,0x61726170u,0x0000006du,0x00040005u,0x000000dau,0x61726170u,0x0000006du,0x00040005u,0x000000deu,0x61726170u,0x0000006du,0x00040005u,0x000000e1u,0x61726170u,0x0000006du,0x00040005u,0x000000e4u,0x61726170u,0x0000006du,0x00040005u,0x000000e7u,0x61726170u,0x0000006du,0x00030005u,0x000000ecu,0x00647766u,0x00030005u,0x000000efu,0x00647762u,0x00030005u,0x000000f2u,0x0067616du,0x00030005u,0x000000fau,0x006c6572u,0x00040005u,0x00000101u,0x666e6f63u,0x00000000u,0x00030005u,0x00000102u,0x00000055u,0x00060006u,0x00000102u,0x00000000u,0x776f6c66u,0x6c616353u,0x00000065u,0x00050006u,0x00000102u,0x00000001u,0x6576656cu,0x0000006cu,0x00050006u,0x00000102u,0x00000002u,0x6c63636fu,0x00006f4cu,0x00050006u,0x00000102u,0x00000003u,0x6c63636fu,0x00006948u,0x00030005u,0x00000104u,0x00000000u,0x00030005u,0x0000010fu,0x00000071u,0x00030005u,0x00000113u,0x00787067u,0x00030005u,0x00000114u,0x00004d47u,0x00050006u,0x00000114u,0x00000000u,0x694c6d67u,0x0000006eu,0x00050006u,0x00000114u,0x00000001u,0x694c6d67u,0x0000546eu,0x00050006u,0x00000114u,0x00000002u,0x70416d67u,0x00000070u,0x00050006u,0x00000114u,0x00000003u,0x70416d67u,0x00005470u,0x00030005u,0x00000116u,0x00000000u,0x00030005u,0x00000139u,0x00003241u,0x00040005u,0x00000147u,0x6c6c7566u,0x00647746u,0x00040005u,0x0000014fu,0x6c6c7566u,0x00647742u,0x00040005u,0x0000015fu,0x64774275u,0x00000000u,0x00040047u,0x00000049u,0x0000000bu,0x0000001cu,0x00030047u,0x00000051u,0x00000019u,0x00040047u,0x00000051u,0x00000021u,0x00000030u,0x00040047u,0x00000051u,0x00000022u,0x00000000u,0x00040047u,0x00000079u,0x00000021u,0x00000020u,0x00040047u,0x00000079u,0x00000022u,0x00000000u,0x00030047u,0x00000102u,0x00000002u,0x00050048u,0x00000102u,0x00000000u,0x00000023u,0x00000000u,0x00050048u,0x00000102u,0x00000001u,0x00000023u,0x00000004u,0x00050048u,0x00000102u,0x00000002u,0x00000023u,0x00000008u,0x00050048u,0x00000102u,0x00000003u,0x00000023u,0x0000000cu,0x00040047u,0x00000104u,0x00000021u,0x00000000u,0x00040047u,0x00000104u,0x00000022u,0x00000000u,0x00030047u,0x00000114u,0x00000002u,0x00050048u,0x00000114u,0x00000000u,0x00000023u,0x00000000u,0x00050048u,0x00000114u,0x00000001u,0x00000023u,0x00000010u,0x00050048u,0x00000114u,0x00000002u,0x00000023u,0x00000020u,0x00050048u,0x00000114u,0x00000003u,0x00000023u,0x00000030u,0x00040047u,0x00000116u,0x00000021u,0x00000001u,0x00040047u,0x00000116u,0x00000022u,0x00000000u,0x00030047u,0x0000015fu,0x00000019u,0x00040047u,0x0000015fu,0x00000021u,0x00000031u,0x00040047u,0x0000015fu,0x00000022u,0x00000000u,0x00040047u,0x00000168u,0x0000000bu,0x00000019u,0x00020013u,0x00000002u,0x00030021u,0x00000003u,0x00000002u,0x00030016u,0x00000006u,0x00000020u,0x00040020u,0x00000007u,0x00000007u,0x00000006u,0x00080021u,0x00000008u,0x00000006u,0x00000007u,0x00000007u,0x00000007u,0x00000007u,0x00000007u,0x00040015u,0x00000042u,0x00000020u,0x00000001u,0x00040017u,0x00000043u,0x00000042u,0x00000002u,0x00040020u,0x00000044Line truncated
static const size_t OF3_EXPAND_M4_LEN = 2217;
static const uint32_t OF3_GM_REDUCE_SPV[] = {0x07230203u,0x00010300u,0x0008000bu,0x000001d7u,0x00000000u,0x00020011u,0x00000001u,0x00020011u,0x00000032u,0x0006000bu,0x00000001u,0x4c534c47u,0x6474732eu,0x3035342eu,0x00000000u,0x0003000eu,0x00000000u,0x00000001u,0x0006000fu,0x00000005u,0x00000004u,0x6e69616du,0x00000000u,0x0000000bu,0x00060010u,0x00000004u,0x00000011u,0x00000040u,0x00000001u,0x00000001u,0x00030003u,0x00000002u,0x000001c2u,0x00040005u,0x00000004u,0x6e69616du,0x00000000u,0x00040005u,0x00000008u,0x64697467u,0x00000000u,0x00080005u,0x0000000bu,0x475f6c67u,0x61626f6cu,0x766e496cu,0x7461636fu,0x496e6f69u,0x00000044u,0x00030005u,0x0000001au,0x006d6964u,0x00040005u,0x0000001fu,0x65725075u,0x00000076u,0x00040005u,0x00000024u,0x61746f74u,0x0000006cu,0x00040005u,0x00000030u,0x44766e69u,0x00006d69u,0x00040005u,0x00000036u,0x6c6f6370u,0x00000030u,0x00030005u,0x00000038u,0x00004d47u,0x00050006u,0x00000038u,0x00000000u,0x694c6d67u,0x0000006eu,0x00050006u,0x00000038u,0x00000001u,0x694c6d67u,0x0000546eu,0x00050006u,0x00000038u,0x00000002u,0x70416d67u,0x00000070u,0x00050006u,0x00000038u,0x00000003u,0x70416d67u,0x00005470u,0x00030005u,0x0000003au,0x00000000u,0x00040005u,0x00000041u,0x6c6f6370u,0x00000031u,0x00030005u,0x00000049u,0x00000074u,0x00030005u,0x0000004fu,0x0000006bu,0x00030005u,0x0000005au,0x00636361u,0x00030005u,0x00000061u,0x00000069u,0x00030005u,0x0000006bu,0x00007870u,0x00030005u,0x0000009au,0x00007675u,0x00030005u,0x000000a2u,0x00000071u,0x00040005u,0x000000a6u,0x72537675u,0x00000063u,0x00030005u,0x000000cfu,0x00000054u,0x00030005u,0x000000d4u,0x00000049u,0x00040005u,0x000000d5u,0x72754375u,0x00000072u,0x00030005u,0x000000dau,0x00000065u,0x00030005u,0x000000deu,0x006d7854u,0x00030005u,0x000000e7u,0x00707854u,0x00030005u,0x000000f0u,0x006d7954u,0x00030005u,0x000000f9u,0x00707954u,0x00030005u,0x00000102u,0x00007854u,0x00030005u,0x0000010au,0x00007954u,0x00030005u,0x00000112u,0x00006561u,0x00030005u,0x00000115u,0x00000077u,0x00030005u,0x00000125u,0x00006473u,0x00030005u,0x00000142u,0x00786469u,0x00030005u,0x00000143u,0x00000072u,0x00030005u,0x0000014bu,0x00000063u,0x00040005u,0x000001bcu,0x65736162u,0x00000000u,0x00030005u,0x000001bfu,0x0000006bu,0x00050005u,0x000001c8u,0x74726150u,0x736c6169u,0x00000000u,0x00050006u,0x000001c8u,0x00000000u,0x74726170u,0x00000000u,0x00030005u,0x000001cau,0x00000000u,0x00040047u,0x0000000bu,0x0000000bu,0x0000001cu,0x00040047u,0x0000001fu,0x00000021u,0x00000020u,0x00040047u,0x0000001fu,0x00000022u,0x00000000u,0x00030047u,0x00000038u,0x00000002u,0x00050048u,0x00000038u,0x00000000u,0x00000023u,0x00000000u,0x00050048u,0x00000038u,0x00000001u,0x00000023u,0x00000010u,0x00050048u,0x00000038u,0x00000002u,0x00000023u,0x00000020u,0x00050048u,0x00000038u,0x00000003u,0x00000023u,0x00000030u,0x00040047u,0x0000003au,0x00000021u,0x00000001u,0x00040047u,0x0000003au,0x00000022u,0x00000000u,0x00040047u,0x000000d5u,0x00000021u,0x00000021u,0x00040047u,0x000000d5u,0x00000022u,0x00000000u,0x00040047u,0x000001c7u,0x00000006u,0x00000004u,0x00030047u,0x000001c8u,0x00000002u,0x00050048u,0x000001c8u,0x00000000u,0x00000023u,0x00000000u,0x00040047u,0x000001cau,0x00000021u,0x00000010u,0x00040047u,0x000001cau,0x00000022u,0x00000000u,0x00040047u,0x000001d6u,0x0000000bu,0x00000019u,0x00020013u,0x00000002u,0x00030021u,0x00000003u,0x00000002u,0x00040015u,0x00000006u,0x00000020u,0x00000000u,0x00040020u,0x00000007u,0x00000007u,0x00000006u,0x00040017u,0x00000009u,0x00000006u,0x00000003u,0x00040020u,0x0000000au,0x00000001u,0x00000009u,0x0004003bu,0x0000000au,0x0000000bu,0x00000001u,0x0004002bu,0x00000006u,0x0000000cu,0x00000000u,0x00040020u,0x0000000du,0x00000001u,0x00000006u,0x0004002bu,0x00000006u,0x00000011u,0x00000200u,0x00020014u,0x00000012u,0x00040015u,0x00000017u,0x00000020u,0x00000001u,0x00040017u,0x00000018u,0x00000017u,0x00000002u,0x00040020u,0x00000019u,0x00000007u,0x00000018u,0x00030016u,0x0000001bu,0x00000020u,0x00090019u,0x0000001cu,0x0000001bu,0x00000001u,0x00000000u,0x00000000u,0x00000000u,0x00000001u,0x00000000u,0x0003001bu,0x0000001du,0x0000001cu,0x00040020u,0x0000001eu,0x00000000u,0x0000001du,0x0004003bu,0x0000001eu,0x0000001fu,0x00000000u,0x0004002bu,0x00000017u,0x00000021u,0x00000000u,0x00040020u,0x00000025u,0x00000007u,0x00000017u,0x0004002bu,0x00000006u,0x00000029u,0x00000001u,0x00040017u,0x0000002eu,0x0000001bu,0x00000002u,0x00040020u,0x0000002fu,0x00000007u,0x0000002eu,0x0004002bu,0x0000001bu,0x00000031u,0x3f800000u,0x00040017u,0x00000037u,0x0000001bu,0x00000004u,0x0006001eu,0x00000038u,0x00000037u,0x00000037u,0x00000037u,0x00000037u,0x00040020u,0x00000039u,0x00000002u,0x00000038u,0x0004003bu,0x00000039u,0x0000003au,0x00000002u,0x00040020u,0x0000003bu,0x00000002u,0x0000001bu,0x0004002bu,0x00000006u,0x00000042u,0x00000002u,0x0004002bu,0x00000006u,0x00000045u,0x00000003u,0x0004002bu,0x00000017u,0x0000004au,0x00000001u,0x00040020u,0x0000004bu,0x00000002u,0x00000037u,0x0004002bu,0x00000006u,0x00000056u,0x00000020u,0x0004001cu,0x00000058u,0x0000001bu,0x00000056u,0x00040020u,0x00000059Line truncated
static const size_t OF3_GM_REDUCE_LEN = 2584;
static const uint32_t OF3_GM_PREWARP_SPV[] = {0x07230203u,0x00010300u,0x0008000bu,0x00000074u,0x00000000u,0x00020011u,0x00000001u,0x00020011u,0x00000032u,0x0006000bu,0x00000001u,0x4c534c47u,0x6474732eu,0x3035342eu,0x00000000u,0x0003000eu,0x00000000u,0x00000001u,0x0006000fu,0x00000005u,0x00000004u,0x6e69616du,0x00000000u,0x0000000du,0x00060010u,0x00000004u,0x00000011u,0x00000010u,0x00000010u,0x00000001u,0x00030003u,0x00000002u,0x000001c2u,0x00040005u,0x00000004u,0x6e69616du,0x00000000u,0x00030005u,0x00000009u,0x00646967u,0x00080005u,0x0000000du,0x475f6c67u,0x61626f6cu,0x766e496cu,0x7461636fu,0x496e6f69u,0x00000044u,0x00030005u,0x00000012u,0x006d6964u,0x00040005u,0x00000016u,0x74734475u,0x00000000u,0x00030005u,0x00000030u,0x00007675u,0x00030005u,0x00000039u,0x00000071u,0x00040005u,0x0000003du,0x6c6f6370u,0x00000030u,0x00030005u,0x0000003fu,0x00004d47u,0x00050006u,0x0000003fu,0x00000000u,0x694c6d67u,0x0000006eu,0x00050006u,0x0000003fu,0x00000001u,0x694c6d67u,0x0000546eu,0x00050006u,0x0000003fu,0x00000002u,0x70416d67u,0x00000070u,0x00050006u,0x0000003fu,0x00000003u,0x70416d67u,0x00005470u,0x00030005u,0x00000041u,0x00000000u,0x00040005u,0x00000049u,0x6c6f6370u,0x00000031u,0x00040005u,0x00000051u,0x72537675u,0x00000063u,0x00030005u,0x00000064u,0x00000076u,0x00040005u,0x00000068u,0x72754375u,0x00000072u,0x00040047u,0x0000000du,0x0000000bu,0x0000001cu,0x00030047u,0x00000016u,0x00000019u,0x00040047u,0x00000016u,0x00000021u,0x00000030u,0x00040047u,0x00000016u,0x00000022u,0x00000000u,0x00030047u,0x0000003fu,0x00000002u,0x00050048u,0x0000003fu,0x00000000u,0x00000023u,0x00000000u,0x00050048u,0x0000003fu,0x00000001u,0x00000023u,0x00000010u,0x00050048u,0x0000003fu,0x00000002u,0x00000023u,0x00000020u,0x00050048u,0x0000003fu,0x00000003u,0x00000023u,0x00000030u,0x00040047u,0x00000041u,0x00000021u,0x00000001u,0x00040047u,0x00000041u,0x00000022u,0x00000000u,0x00040047u,0x00000068u,0x00000021u,0x00000020u,0x00040047u,0x00000068u,0x00000022u,0x00000000u,0x00040047u,0x00000073u,0x0000000bu,0x00000019u,0x00020013u,0x00000002u,0x00030021u,0x00000003u,0x00000002u,0x00040015u,0x00000006u,0x00000020u,0x00000001u,0x00040017u,0x00000007u,0x00000006u,0x00000002u,0x00040020u,0x00000008u,0x00000007u,0x00000007u,0x00040015u,0x0000000au,0x00000020u,0x00000000u,0x00040017u,0x0000000bu,0x0000000au,0x00000003u,0x00040020u,0x0000000cu,0x00000001u,0x0000000bu,0x0004003bu,0x0000000cu,0x0000000du,0x00000001u,0x00040017u,0x0000000eu,0x0000000au,0x00000002u,0x00030016u,0x00000013u,0x00000020u,0x00090019u,0x00000014u,0x00000013u,0x00000001u,0x00000000u,0x00000000u,0x00000000u,0x00000002u,0x00000003u,0x00040020u,0x00000015u,0x00000000u,0x00000014u,0x0004003bu,0x00000015u,0x00000016u,0x00000000u,0x00020014u,0x00000019u,0x0004002bu,0x0000000au,0x0000001au,0x00000000u,0x00040020u,0x0000001bu,0x00000007u,0x00000006u,0x0004002bu,0x0000000au,0x00000024u,0x00000001u,0x00040017u,0x0000002eu,0x00000013u,0x00000002u,0x00040020u,0x0000002fu,0x00000007u,0x0000002eu,0x0004002bu,0x00000013u,0x00000033u,0x3f000000u,0x00040017u,0x0000003eu,0x00000013u,0x00000004u,0x0006001eu,0x0000003fu,0x0000003eu,0x0000003eu,0x0000003eu,0x0000003eu,0x00040020u,0x00000040u,0x00000002u,0x0000003fu,0x0004003bu,0x00000040u,0x00000041u,0x00000002u,0x0004002bu,0x00000006u,0x00000042u,0x00000002u,0x00040020u,0x00000043u,0x00000002u,0x00000013u,0x0004002bu,0x0000000au,0x0000004au,0x00000002u,0x0004002bu,0x0000000au,0x0000004du,0x00000003u,0x00040020u,0x00000054u,0x00000007u,0x00000013u,0x0004002bu,0x00000006u,0x0000005eu,0x00000003u,0x00040020u,0x0000005fu,0x00000002u,0x0000003eu,0x00090019u,0x00000065u,0x00000013u,0x00000001u,0x00000000u,0x00000000u,0x00000000u,0x00000001u,0x00000000u,0x0003001bu,0x00000066u,0x00000065u,0x00040020u,0x00000067u,0x00000000u,0x00000066u,0x0004003bu,0x00000067u,0x00000068u,0x00000000u,0x0004002bu,0x00000013u,0x0000006bu,0x00000000u,0x0004002bu,0x0000000au,0x00000072u,0x00000010u,0x0006002cu,0x0000000bu,0x00000073u,0x00000072u,0x00000072u,0x00000024u,0x00050036u,0x00000002u,0x00000004u,0x00000000u,0x00000003u,0x000200f8u,0x00000005u,0x0004003bu,0x00000008u,0x00000009u,0x00000007u,0x0004003bu,0x00000008u,0x00000012u,0x00000007u,0x0004003bu,0x0000002fu,0x00000030u,0x00000007u,0x0004003bu,0x0000002fu,0x00000039u,0x00000007u,0x0004003bu,0x0000002fu,0x0000003du,0x00000007u,0x0004003bu,0x0000002fu,0x00000049u,0x00000007u,0x0004003bu,0x0000002fu,0x00000051u,0x00000007u,0x0004003bu,0x00000054u,0x00000064u,0x00000007u,0x0004003du,0x0000000bu,0x0000000fu,0x0000000du,0x0007004fu,0x0000000eu,0x00000010u,0x0000000fu,0x0000000fu,0x00000000u,0x00000001u,0x0004007cu,0x00000007u,0x00000011u,0x00000010u,0x0003003eu,0x00000009u,0x00000011u,0x0004003du,0x00000014u,0x00000017u,0x00000016u,0x00040068u,0x00000007u,0x00000018u,0x00000017u,0x0003003eu,0x00000012u,0x00000018u,0x00050041u,0x0000001bu,0x0000001cu,0x00000009u,0x0000001au,0x0004003du,0x00000006u,0x0000001du,0x0000001cu,0x00050041u,0x0000001bu,0x0000001eu,0x00000012u,0x0000001au,0x0004003du,0x00000006u,0x0000001fu,0x0000001Line truncated
static const size_t OF3_GM_PREWARP_LEN = 706;
static const uint32_t OF3_FLOWREG_SPV[] = {0x07230203u,0x00010300u,0x0008000bu,0x00000144u,0x00000000u,0x00020011u,0x00000001u,0x00020011u,0x00000032u,0x0006000bu,0x00000001u,0x4c534c47u,0x6474732eu,0x3035342eu,0x00000000u,0x0003000eu,0x00000000u,0x00000001u,0x0006000fu,0x00000005u,0x00000004u,0x6e69616du,0x00000000u,0x00000037u,0x00060010u,0x00000004u,0x00000011u,0x00000010u,0x00000010u,0x00000001u,0x00030003u,0x00000002u,0x000001c2u,0x00040005u,0x00000004u,0x6e69616du,0x00000000u,0x00060005u,0x0000000eu,0x63746566u,0x76285568u,0x763b3269u,0x003b3269u,0x00030005u,0x0000000cu,0x00000070u,0x00030005u,0x0000000du,0x006d6964u,0x00060005u,0x00000013u,0x63746566u,0x76284c68u,0x763b3269u,0x003b3269u,0x00030005u,0x00000011u,0x00000070u,0x00030005u,0x00000012u,0x006d6964u,0x00040005u,0x00000018u,0x6f6c4675u,0x006e4977u,0x00040005u,0x00000026u,0x6d754c75u,0x00000061u,0x00030005u,0x00000034u,0x00646967u,0x00080005u,0x00000037u,0x475f6c67u,0x61626f6cu,0x766e496cu,0x7461636fu,0x496e6f69u,0x00000044u,0x00030005u,0x0000003cu,0x006d6964u,0x00030005u,0x00000055u,0x00007464u,0x00030005u,0x00000056u,0x00000055u,0x00050006u,0x00000056u,0x00000000u,0x61726170u,0x0000736du,0x00030005u,0x00000058u,0x00000000u,0x00040005u,0x0000005cu,0x626d616cu,0x00006164u,0x00050005u,0x0000005fu,0x65676465u,0x68706c41u,0x00000061u,0x00040005u,0x00000063u,0x54737065u,0x00000056u,0x00030005u,0x00000068u,0x00004375u,0x00040005u,0x00000069u,0x61726170u,0x0000006du,0x00040005u,0x0000006bu,0x61726170u,0x0000006du,0x00030005u,0x0000006eu,0x00004c75u,0x00040005u,0x00000073u,0x61726170u,0x0000006du,0x00040005u,0x00000074u,0x61726170u,0x0000006du,0x00030005u,0x00000077u,0x00005275u,0x00040005u,0x0000007bu,0x61726170u,0x0000006du,0x00040005u,0x0000007cu,0x61726170u,0x0000006du,0x00030005u,0x0000007fu,0x00005575u,0x00040005u,0x00000083u,0x61726170u,0x0000006du,0x00040005u,0x00000084u,0x61726170u,0x0000006du,0x00030005u,0x00000087u,0x00004475u,0x00040005u,0x0000008bu,0x61726170u,0x0000006du,0x00040005u,0x0000008cu,0x61726170u,0x0000006du,0x00040005u,0x0000008fu,0x6d69646cu,0x00000000u,0x00030005u,0x00000093u,0x00004c6cu,0x00040005u,0x00000096u,0x61726170u,0x0000006du,0x00040005u,0x00000097u,0x61726170u,0x0000006du,0x00030005u,0x0000009au,0x0000526cu,0x00040005u,0x0000009du,0x61726170u,0x0000006du,0x00040005u,0x0000009eu,0x61726170u,0x0000006du,0x00030005u,0x000000a1u,0x0000556cu,0x00040005u,0x000000a4u,0x61726170u,0x0000006du,0x00040005u,0x000000a5u,0x61726170u,0x0000006du,0x00030005u,0x000000a8u,0x0000446cu,0x00040005u,0x000000abu,0x61726170u,0x0000006du,0x00040005u,0x000000acu,0x61726170u,0x0000006du,0x00040005u,0x000000afu,0x67616d67u,0x00000000u,0x00030005u,0x000000bbu,0x00000067u,0x00030005u,0x000000c4u,0x00004c64u,0x00030005u,0x000000c8u,0x00005264u,0x00030005u,0x000000ccu,0x00005564u,0x00030005u,0x000000d0u,0x00004464u,0x00030005u,0x000000d4u,0x00003265u,0x00030005u,0x000000d8u,0x00004c77u,0x00030005u,0x000000e1u,0x00005277u,0x00030005u,0x000000eau,0x00005577u,0x00030005u,0x000000f3u,0x00004477u,0x00040005u,0x000000fcu,0x576d7573u,0x00000000u,0x00040005u,0x00000104u,0x576d7573u,0x00000055u,0x00040005u,0x00000114u,0x66694475u,0x00000066u,0x00030005u,0x00000120u,0x00003066u,0x00050005u,0x00000121u,0x6f6c4675u,0x73624f77u,0x00000000u,0x00040005u,0x0000012au,0x74656874u,0x00000061u,0x00030005u,0x0000012eu,0x00000072u,0x00040005u,0x00000132u,0x77654e75u,0x00000000u,0x00050005u,0x0000013eu,0x6f6c4675u,0x74754f77u,0x00000000u,0x00040047u,0x00000018u,0x00000021u,0x00000020u,0x00040047u,0x00000018u,0x00000022u,0x00000000u,0x00040047u,0x00000026u,0x00000021u,0x00000022u,0x00040047u,0x00000026u,0x00000022u,0x00000000u,0x00040047u,0x00000037u,0x0000000bu,0x0000001cu,0x00030047u,0x00000056u,0x00000002u,0x00050048u,0x00000056u,0x00000000u,0x00000023u,0x00000000u,0x00040047u,0x00000058u,0x00000021u,0x00000000u,0x00040047u,0x00000058u,0x00000022u,0x00000000u,0x00040047u,0x00000121u,0x00000021u,0x00000021u,0x00040047u,0x00000121u,0x00000022u,0x00000000u,0x00030047u,0x0000013eu,0x00000019u,0x00040047u,0x0000013eu,0x00000021u,0x00000030u,0x00040047u,0x0000013eu,0x00000022u,0x00000000u,0x00040047u,0x00000143u,0x0000000bu,0x00000019u,0x00020013u,0x00000002u,0x00030021u,0x00000003u,0x00000002u,0x00040015u,0x00000006u,0x00000020u,0x00000001u,0x00040017u,0x00000007u,0x00000006u,0x00000002u,0x00040020u,0x00000008u,0x00000007u,0x00000007u,0x00030016u,0x00000009u,0x00000020u,0x00040017u,0x0000000au,0x00000009u,0x00000004u,0x00050021u,0x0000000bu,0x0000000au,0x00000008u,0x00000008u,0x00050021u,0x00000010u,0x00000009u,0x00000008u,0x00000008u,0x00090019u,0x00000015u,0x00000009u,0x00000001u,0x00000000u,0x00000000u,0x00000000u,0x00000001u,0x00000000u,0x0003001bu,0x00000016u,0x00000015u,0x00040020u,0x00000017u,0x00000000u,0x00000016u,0x0004003bu,0x00000017u,0x00000018u,0x00000000u,0x0004002bu,0x00000006u,0x0000001bu,0x00000000u,0x0005002cu,0x00000007u,0x0000001cu,0x0000001bu,0x0000001bu,0x0004002bu,0x00000006u,0x0000001eu,0x00000001u,0x0004003bu,0x00000017u,0x00000026u,0x00000000u,Line truncated
static const size_t OF3_FLOWREG_LEN = 1936;
static const uint32_t WFG_SYNTH_SPV[] = {0x07230203u,0x00010300u,0x0008000bu,0x00000208u,0x00000000u,0x00020011u,0x00000001u,0x00020011u,0x00000032u,0x0006000bu,0x00000001u,0x4c534c47u,0x6474732eu,0x3035342eu,0x00000000u,0x0003000eu,0x00000000u,0x00000001u,0x0006000fu,0x00000005u,0x00000004u,0x6e69616du,0x00000000u,0x0000001cu,0x00060010u,0x00000004u,0x00000011u,0x00000010u,0x00000010u,0x00000001u,0x00030003u,0x00000002u,0x000001c2u,0x00040005u,0x00000004u,0x6e69616du,0x00000000u,0x00050005u,0x0000000bu,0x616d756cu,0x33667628u,0x0000003bu,0x00030005u,0x0000000au,0x00000063u,0x00030005u,0x00000018u,0x00646967u,0x00080005u,0x0000001cu,0x475f6c67u,0x61626f6cu,0x766e496cu,0x7461636fu,0x496e6f69u,0x00000044u,0x00030005u,0x00000021u,0x006d6964u,0x00040005u,0x00000024u,0x74754f75u,0x00000000u,0x00040005u,0x0000003eu,0x44766e69u,0x00006d69u,0x00030005u,0x00000044u,0x00007675u,0x00030005u,0x0000004du,0x00000055u,0x00060006u,0x0000004du,0x00000000u,0x776f6c66u,0x6c616353u,0x00000065u,0x00050006u,0x0000004du,0x00000001u,0x68706c61u,0x00000061u,0x00050006u,0x0000004du,0x00000002u,0x61746562u,0x00000000u,0x00050006u,0x0000004du,0x00000003u,0x626d616cu,0x00006164u,0x00050006u,0x0000004du,0x00000004u,0x69737065u,0x006e6f6cu,0x00060006u,0x0000004du,0x00000005u,0x746f6870u,0x6163536fu,0x0000656cu,0x00050006u,0x0000004du,0x00000006u,0x30646170u,0x00000000u,0x00050006u,0x0000004du,0x00000007u,0x31646170u,0x00000000u,0x00050006u,0x0000004du,0x00000008u,0x52647568u,0x00746365u,0x00030005u,0x0000004fu,0x00000000u,0x00040005u,0x0000008cu,0x72754375u,0x00000072u,0x00030005u,0x00000098u,0x00676264u,0x00030005u,0x0000009fu,0x00007366u,0x00040005u,0x000000a9u,0x64774273u,0x00000000u,0x00050005u,0x000000aau,0x6f6c4675u,0x64774277u,0x00000000u,0x00040005u,0x000000aeu,0x64774673u,0x00000000u,0x00050005u,0x000000afu,0x6f6c4675u,0x64774677u,0x00000000u,0x00030005u,0x000000b3u,0x00313046u,0x00030005u,0x000000bau,0x00303146u,0x00040005u,0x000000c1u,0x31306663u,0x00000000u,0x00040005u,0x000000c5u,0x30316663u,0x00000000u,0x00030005u,0x000000c9u,0x0031306du,0x00030005u,0x000000d5u,0x0030316du,0x00030005u,0x000000e0u,0x00004170u,0x00030005u,0x000000e8u,0x00004270u,0x00030005u,0x000000f0u,0x00003043u,0x00040005u,0x000000f1u,0x65725075u,0x00000076u,0x00030005u,0x000000f6u,0x00003143u,0x00030005u,0x000000fbu,0x00004165u,0x00040005u,0x000000fcu,0x61726170u,0x0000006du,0x00040005u,0x0000010cu,0x61726170u,0x0000006du,0x00030005u,0x00000111u,0x00004265u,0x00040005u,0x00000112u,0x61726170u,0x0000006du,0x00040005u,0x00000122u,0x61726170u,0x0000006du,0x00040005u,0x00000127u,0x76556266u,0x00000000u,0x00040005u,0x0000012bu,0x65526266u,0x00646973u,0x00040005u,0x00000138u,0x736e6f63u,0x00747369u,0x00030005u,0x00000149u,0x0000305au,0x00030005u,0x00000157u,0x0000315au,0x00040005u,0x00000163u,0x30756174u,0x00000000u,0x00040005u,0x00000167u,0x31756174u,0x00000000u,0x00040005u,0x0000016au,0x78616d7au,0x00000000u,0x00030005u,0x0000016eu,0x00003057u,0x00030005u,0x00000179u,0x00003157u,0x00040005u,0x00000183u,0x6d757357u,0x00000000u,0x00040005u,0x00000187u,0x70726177u,0x00006465u,0x00050005u,0x000001a0u,0x736f7263u,0x64616673u,0x00000065u,0x00050005u,0x000001adu,0x746f6870u,0x7272456fu,0x00000000u,0x00050005u,0x000001b1u,0x746f6870u,0x7572546fu,0x00007473u,0x00040005u,0x000001b7u,0x73757274u,0x00000074u,0x00040005u,0x000001c3u,0x76657270u,0x00000043u,0x00040005u,0x000001c8u,0x72727563u,0x00000043u,0x00050005u,0x000001cdu,0x746e6f63u,0x44746e65u,0x00666669u,0x00050005u,0x000001d2u,0x72746e75u,0x65747375u,0x00000064u,0x00040005u,0x000001d7u,0x44676962u,0x00666669u,0x00050005u,0x000001dcu,0x70616e73u,0x75436f54u,0x00007272u,0x00040005u,0x000001e5u,0x6374756fu,0x00000000u,0x00030005u,0x000001eeu,0x0067616du,0x00030005u,0x000001f2u,0x0000006eu,0x00030005u,0x000001f6u,0x00746173u,0x00040047u,0x0000001cu,0x0000000bu,0x0000001cu,0x00030047u,0x00000024u,0x00000019u,0x00040047u,0x00000024u,0x00000021u,0x00000030u,0x00040047u,0x00000024u,0x00000022u,0x00000000u,0x00030047u,0x0000004du,0x00000002u,0x00050048u,0x0000004du,0x00000000u,0x00000023u,0x00000000u,0x00050048u,0x0000004du,0x00000001u,0x00000023u,0x00000004u,0x00050048u,0x0000004du,0x00000002u,0x00000023u,0x00000008u,0x00050048u,0x0000004du,0x00000003u,0x00000023u,0x0000000cu,0x00050048u,0x0000004du,0x00000004u,0x00000023u,0x00000010u,0x00050048u,0x0000004du,0x00000005u,0x00000023u,0x00000014u,0x00050048u,0x0000004du,0x00000006u,0x00000023u,0x00000018u,0x00050048u,0x0000004du,0x00000007u,0x00000023u,0x0000001cu,0x00050048u,0x0000004du,0x00000008u,0x00000023u,0x00000020u,0x00040047u,0x0000004fu,0x00000021u,0x00000000u,0x00040047u,0x0000004fu,0x00000022u,0x00000000u,0x00040047u,0x0000008cu,0x00000021u,0x00000021u,0x00040047u,0x0000008cu,0x00000022u,0x00000000u,0x00040047u,0x000000aau,0x00000021u,0x00000023u,0x00040047u,0x000000aau,0x00000022u,0x00000000u,0x00040047u,0x000000afu,0x00000021u,0x00000022u,0x00040047u,0x000000afu,0x00000022u,0x00000000u,0x00040047u,0x000000f1u,0x00000021u,0x00000020u,0x00040047u,0x000000f1u,0xLine truncated
static const size_t WFG_SYNTH_LEN = 3082;
struct Blob { const uint32_t* code; size_t words; };
enum Shader { OF3_LUMA, OF3_DOWNSAMPLE, OF3_FLOW, OF3_EXPAND, OF3_FLOW_M4, OF3_EXPAND_M4, OF3_GM_REDUCE, OF3_GM_PREWARP, OF3_FLOWREG, WFG_SYNTH, SHADER_COUNT };
static inline Blob blob(Shader s) {
switch (s) {
case OF3_LUMA: return { OF3_LUMA_SPV, OF3_LUMA_LEN };
case OF3_DOWNSAMPLE: return { OF3_DOWNSAMPLE_SPV, OF3_DOWNSAMPLE_LEN };
case OF3_FLOW: return { OF3_FLOW_SPV, OF3_FLOW_LEN };
case OF3_EXPAND: return { OF3_EXPAND_SPV, OF3_EXPAND_LEN };
case OF3_FLOW_M4: return { OF3_FLOW_M4_SPV, OF3_FLOW_M4_LEN };
case OF3_EXPAND_M4: return { OF3_EXPAND_M4_SPV, OF3_EXPAND_M4_LEN };
case OF3_GM_REDUCE: return { OF3_GM_REDUCE_SPV, OF3_GM_REDUCE_LEN };
case OF3_GM_PREWARP: return { OF3_GM_PREWARP_SPV, OF3_GM_PREWARP_LEN };
case OF3_FLOWREG: return { OF3_FLOWREG_SPV, OF3_FLOWREG_LEN };
case WFG_SYNTH: return { WFG_SYNTH_SPV, WFG_SYNTH_LEN };
default: return { nullptr, 0 };
}
}
} } // namespace winfg::embedded
@@ -0,0 +1,269 @@
// win-fg - compute frame-generation engine implementation.
#include "framegen.hpp"
#include "embedded_shaders.hpp"
#include "log.hpp"
#include <cmath>
#include <cstdio>
namespace winfg {
#define VKOK(x) do { if ((x) != VK_SUCCESS) { WFG_LOGE("vk fail: %s", #x); return false; } } while (0)
uint32_t FrameGen::findMemType(uint32_t bits, VkMemoryPropertyFlags props) const {
for (uint32_t i = 0; i < memProps_.memoryTypeCount; ++i)
if ((bits & (1u << i)) && (memProps_.memoryTypes[i].propertyFlags & props) == props)
return i;
return 0;
}
bool FrameGen::makeImage(Img& out, VkExtent2D ext, VkFormat fmt, VkImageUsageFlags usage) {
out.extent = ext; out.fmt = fmt;
VkImageCreateInfo ci{VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO};
ci.imageType = VK_IMAGE_TYPE_2D;
ci.format = fmt;
ci.extent = {ext.width, ext.height, 1};
ci.mipLevels = 1; ci.arrayLayers = 1;
ci.samples = VK_SAMPLE_COUNT_1_BIT;
ci.tiling = VK_IMAGE_TILING_OPTIMAL;
ci.usage = usage;
ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
VKOK(dd_->CreateImage(device_, &ci, nullptr, &out.image));
VkMemoryRequirements mr; dd_->GetImageMemoryRequirements(device_, out.image, &mr);
VkMemoryAllocateInfo ai{VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO};
ai.allocationSize = mr.size;
ai.memoryTypeIndex = findMemType(mr.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
VKOK(dd_->AllocateMemory(device_, &ai, nullptr, &out.mem));
VKOK(dd_->BindImageMemory(device_, out.image, out.mem, 0));
VkImageViewCreateInfo vi{VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO};
vi.image = out.image; vi.viewType = VK_IMAGE_VIEW_TYPE_2D; vi.format = fmt;
vi.subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1};
VKOK(dd_->CreateImageView(device_, &vi, nullptr, &out.view));
return true;
}
void FrameGen::destroyImage(Img& i) {
if (i.view) dd_->DestroyImageView(device_, i.view, nullptr);
if (i.image) dd_->DestroyImage(device_, i.image, nullptr);
if (i.mem) dd_->FreeMemory(device_, i.mem, nullptr);
i = Img{};
}
// C1: allocate the per-slot host-visible SSBOs the LK reduce writes partials into.
// Host-visible + coherent so the CPU can read them back after the owning frame's
// fence signals (no staging copy needed; the buffers are tiny - kGmThreads*kGmStride
// floats each, ~64 KB). Persistently mapped.
bool FrameGen::makeGmBuffers() {
const VkDeviceSize sz = (VkDeviceSize)kGmThreads * kGmStride * sizeof(float);
const VkMemoryPropertyFlags want = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
for (int s = 0; s < kGmSlots; ++s) {
VkBufferCreateInfo bi{VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO};
bi.size = sz; bi.usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT; bi.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
VKOK(dd_->CreateBuffer(device_, &bi, nullptr, &gmSsbo_[s]));
VkMemoryRequirements mr; dd_->GetBufferMemoryRequirements(device_, gmSsbo_[s], &mr);
VkMemoryAllocateInfo ai{VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO};
ai.allocationSize = mr.size; ai.memoryTypeIndex = findMemType(mr.memoryTypeBits, want);
VKOK(dd_->AllocateMemory(device_, &ai, nullptr, &gmSsboMem_[s]));
VKOK(dd_->BindBufferMemory(device_, gmSsbo_[s], gmSsboMem_[s], 0));
VKOK(dd_->MapMemory(device_, gmSsboMem_[s], 0, sz, 0, &gmSsboPtr_[s]));
std::memset(gmSsboPtr_[s], 0, (size_t)sz);
gmSlotValid_[s] = false;
}
gmBuffersReady_ = true;
return true;
}
bool FrameGen::makePipe(Pipe& p, int shaderId,
const std::vector<VkDescriptorType>&) {
// binding layout is derived per shader below in init(); here we only build
// the module + a generic layout supplied by caller via setLayout already set.
embedded::Blob b = embedded::blob((embedded::Shader)shaderId);
VkShaderModuleCreateInfo mi{VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO};
mi.codeSize = b.words * 4; mi.pCode = b.code;
VKOK(dd_->CreateShaderModule(device_, &mi, nullptr, &p.module));
VkPipelineLayoutCreateInfo li{VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO};
li.setLayoutCount = 1; li.pSetLayouts = &p.setLayout;
VKOK(dd_->CreatePipelineLayout(device_, &li, nullptr, &p.layout));
VkComputePipelineCreateInfo pi{VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO};
pi.stage.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
pi.stage.stage = VK_SHADER_STAGE_COMPUTE_BIT;
pi.stage.module = p.module; pi.stage.pName = "main";
pi.layout = p.layout;
VKOK(dd_->CreateComputePipelines(device_, VK_NULL_HANDLE, 1, &pi, nullptr, &p.pipeline));
return true;
}
void FrameGen::destroyPipe(Pipe& p) {
if (p.pipeline) dd_->DestroyPipeline(device_, p.pipeline, nullptr);
if (p.layout) dd_->DestroyPipelineLayout(device_, p.layout, nullptr);
if (p.setLayout) dd_->DestroyDescriptorSetLayout(device_, p.setLayout, nullptr);
if (p.module) dd_->DestroyShaderModule(device_, p.module, nullptr);
p = Pipe{};
}
// Build a descriptor-set layout from an explicit (binding, type) list.
static bool buildSetLayout(const DeviceDispatch* dd, VkDevice dev,
const std::vector<std::pair<uint32_t, VkDescriptorType>>& binds,
VkDescriptorSetLayout& out) {
std::vector<VkDescriptorSetLayoutBinding> b;
for (auto& kv : binds)
b.push_back({kv.first, kv.second, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr});
VkDescriptorSetLayoutCreateInfo ci{VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO};
ci.bindingCount = (uint32_t)b.size(); ci.pBindings = b.data();
return dd->CreateDescriptorSetLayout(dev, &ci, nullptr, &out) == VK_SUCCESS;
}
bool FrameGen::init(const DeviceDispatch* dd, const InstanceDispatch* id,
VkPhysicalDevice phys, VkDevice dev, uint32_t queueFamily, VkQueue queue) {
dd_ = dd; id_ = id; phys_ = phys; device_ = dev; queueFamily_ = queueFamily; queue_ = queue;
id_->GetPhysicalDeviceMemoryProperties(phys_, &memProps_);
VkSamplerCreateInfo si{VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO};
si.magFilter = si.minFilter = VK_FILTER_LINEAR;
si.addressModeU = si.addressModeV = si.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
VKOK(dd_->CreateSampler(device_, &si, nullptr, &linear_));
// descriptor pool sized generously for our per-frame sets.
VkDescriptorPoolSize sizes[] = {
{VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 256},
{VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 256},
{VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 64},
{VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 16}, // C1 LK-reduce SSBOs
};
VkDescriptorPoolCreateInfo pci{VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO};
pci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
pci.maxSets = 256; pci.poolSizeCount = 4; pci.pPoolSizes = sizes;
VKOK(dd_->CreateDescriptorPool(device_, &pci, nullptr, &descPool_));
using B = std::pair<uint32_t, VkDescriptorType>;
const auto S = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
const auto W = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
const auto U = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
const auto SB = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
// per-shader binding sets (match the GLSL layout(binding=...) declarations)
if (!buildSetLayout(dd_, dev, {B{32,S},B{48,W}}, pLuma_.setLayout)) return false;
if (!buildSetLayout(dd_, dev, {B{32,S},B{48,W}}, pDown_.setLayout)) return false;
if (!buildSetLayout(dd_, dev, {B{0,U},B{32,S},B{33,S},B{34,S},B{48,W}}, pFlow_.setLayout)) return false;
if (!buildSetLayout(dd_, dev, {B{0,U},B{32,S},B{33,S},B{34,S},B{48,W}}, pFlowM4_.setLayout)) return false;
// C1: expand sets gain a second UBO (binding 1 = GMUBO) for the global-motion add-back.
if (!buildSetLayout(dd_, dev, {B{0,U},B{1,U},B{32,S},B{48,W},B{49,W}}, pExpand_.setLayout)) return false;
if (!buildSetLayout(dd_, dev, {B{0,U},B{1,U},B{32,S},B{48,W},B{49,W}}, pExpandM4_.setLayout)) return false;
if (!buildSetLayout(dd_, dev, {B{0,U},B{32,S},B{33,S},B{34,S},B{35,S},B{48,W}}, pSynth_.setLayout)) return false;
// C1: LK-reduce (UBO, SSBO, prev, curr) and curr-luma stabilization prewarp (UBO, src, dst).
if (!buildSetLayout(dd_, dev, {B{1,U},B{16,SB},B{32,S},B{33,S}}, pGmReduce_.setLayout)) return false;
if (!buildSetLayout(dd_, dev, {B{1,U},B{32,S},B{48,W}}, pGmPrewarp_.setLayout)) return false;
// C2: flow-reg (UBO, u_in, f0_obs, luma, out).
if (!buildSetLayout(dd_, dev, {B{0,U},B{32,S},B{33,S},B{34,S},B{48,W}}, pFlowReg_.setLayout)) return false;
std::vector<VkDescriptorType> unused;
if (!makePipe(pLuma_, embedded::OF3_LUMA, unused)) return false;
if (!makePipe(pDown_, embedded::OF3_DOWNSAMPLE, unused)) return false;
if (!makePipe(pFlow_, embedded::OF3_FLOW, unused)) return false;
if (!makePipe(pFlowM4_, embedded::OF3_FLOW_M4, unused)) return false;
if (!makePipe(pExpand_, embedded::OF3_EXPAND, unused)) return false;
if (!makePipe(pExpandM4_, embedded::OF3_EXPAND_M4, unused)) return false;
if (!makePipe(pGmReduce_, embedded::OF3_GM_REDUCE, unused)) return false;
if (!makePipe(pGmPrewarp_, embedded::OF3_GM_PREWARP, unused)) return false;
if (!makePipe(pFlowReg_, embedded::OF3_FLOWREG, unused)) return false;
if (!makePipe(pSynth_, embedded::WFG_SYNTH, unused)) return false;
if (!makeGmBuffers()) { WFG_LOGE("framegen: GM SSBO alloc failed - C1 disabled"); }
WFG_LOGI("framegen init ok (queueFamily=%u, 10 pipelines, model=%d, C1 gm=%d, C2 flow_reg=%d iters=%d)",
queueFamily_, cfg_.model, cfg_.gmMode, cfg_.frMode, cfg_.frIters);
return true;
}
static VkExtent2D levelExtent(VkExtent2D e, int l) {
return { e.width >> l ? e.width >> l : 1u, e.height >> l ? e.height >> l : 1u };
}
bool FrameGen::onResize(VkExtent2D extent, VkFormat /*colorFormat*/, bool force) {
// force skips the same-extent early-out so a perf_preset change (which alters
// flowFinest_ and therefore the per-size flow-image resolutions) rebuilds them.
if (!force && ready_ && extent.width == extent_.width && extent.height == extent_.height) return true;
// tear down previous size
for (auto& i : pyrA_) destroyImage(i); pyrA_.clear();
for (auto& i : pyrB_) destroyImage(i); pyrB_.clear();
for (auto& i : pyrAs_) destroyImage(i); pyrAs_.clear();
for (auto& i : flowLvl_) destroyImage(i); flowLvl_.clear();
destroyImage(flowExpA_); destroyImage(flowExpB_);
destroyImage(flowRegA_); destroyImage(flowRegB_); // C2
extent_ = extent; ready_ = false;
const VkImageUsageFlags lumaUsage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT;
// flowLvl_ is cleared every frame (per-frame reset) and C2 copies the cleaned
// finest level back into it - both need TRANSFER_DST. The C2 ping-pong images
// are the copy SOURCE (TRANSFER_SRC).
const VkImageUsageFlags flowUsage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
const VkImageUsageFlags regUsage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
pyrA_.resize(kLevels); pyrB_.resize(kLevels); flowLvl_.resize(kLevels);
for (int l = 0; l < kLevels; ++l) {
VkExtent2D e = levelExtent(extent, l);
if (!makeImage(pyrA_[l], e, VK_FORMAT_R32_SFLOAT, lumaUsage)) return false;
if (!makeImage(pyrB_[l], e, VK_FORMAT_R32_SFLOAT, lumaUsage)) return false;
if (!makeImage(flowLvl_[l], e, VK_FORMAT_R16G16B16A16_SFLOAT, flowUsage)) return false;
}
// C1: stabilized curr luma - only the levels the dense flow reads (finest..coarsest).
pyrAs_.resize(kLevels);
for (int l = flowFinest_; l < kLevels; ++l)
if (!makeImage(pyrAs_[l], levelExtent(extent, l), VK_FORMAT_R32_SFLOAT, lumaUsage)) return false;
if (!makeImage(flowExpA_, extent, VK_FORMAT_R16G16B16A16_SFLOAT, flowUsage)) return false;
if (!makeImage(flowExpB_, extent, VK_FORMAT_R16G16B16A16_SFLOAT, flowUsage)) return false;
// C2: TV-L1 ping-pong scratch at the finest solved flow level (perf_preset-driven res).
if (!makeImage(flowRegA_, levelExtent(extent, flowFinest_), VK_FORMAT_R16G16B16A16_SFLOAT, regUsage)) return false;
if (!makeImage(flowRegB_, levelExtent(extent, flowFinest_), VK_FORMAT_R16G16B16A16_SFLOAT, regUsage)) return false;
ready_ = true;
WFG_LOGI("framegen resized to %ux%u (%d pyramid levels, kFlowFinest=%d perf_preset=%d)",
extent.width, extent.height, kLevels, flowFinest_, cfg_.perfPreset);
return true;
}
void FrameGen::barrier(VkCommandBuffer cmd, VkImage img, VkImageLayout from, VkImageLayout to) {
VkImageMemoryBarrier b{VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER};
b.oldLayout = from; b.newLayout = to;
b.srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT;
b.dstAccessMask = VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT;
b.image = img; b.subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1};
b.srcQueueFamilyIndex = b.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
dd_->CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &b);
}
// NOTE: descriptor-set allocation/update per record() and the exact per-level
// flow wiring are implemented in record_impl.inc for readability; the graph is:
// luma(curr)->pyrA[0], luma(prev)->pyrB[0]
// downsample pyrA/pyrB to kLevels
// coarse->fine flow (per level) into flowLvl
// expand flowLvl[0] -> flowExpA/flowExpB
// synth(prev,curr,flowExpA,flowExpB, alpha) -> out
void FrameGen::destroy() {
if (!device_) return;
dd_->DeviceWaitIdle(device_);
for (auto& i : pyrA_) destroyImage(i); pyrA_.clear();
for (auto& i : pyrB_) destroyImage(i); pyrB_.clear();
for (auto& i : pyrAs_) destroyImage(i); pyrAs_.clear();
for (auto& i : flowLvl_) destroyImage(i); flowLvl_.clear();
destroyImage(flowExpA_); destroyImage(flowExpB_);
destroyImage(flowRegA_); destroyImage(flowRegB_); // C2
destroyPipe(pLuma_); destroyPipe(pDown_); destroyPipe(pFlow_); destroyPipe(pFlowM4_);
destroyPipe(pExpand_); destroyPipe(pExpandM4_); destroyPipe(pSynth_);
destroyPipe(pGmReduce_); destroyPipe(pGmPrewarp_);
destroyPipe(pFlowReg_); // C2
for (int s = 0; s < kGmSlots; ++s) {
if (gmSsboMem_[s]) dd_->UnmapMemory(device_, gmSsboMem_[s]);
if (gmSsbo_[s]) dd_->DestroyBuffer(device_, gmSsbo_[s], nullptr);
if (gmSsboMem_[s]) dd_->FreeMemory(device_, gmSsboMem_[s], nullptr);
gmSsbo_[s] = VK_NULL_HANDLE; gmSsboMem_[s] = VK_NULL_HANDLE; gmSsboPtr_[s] = nullptr;
}
gmBuffersReady_ = false;
if (descPool_) dd_->DestroyDescriptorPool(device_, descPool_, nullptr);
if (linear_) dd_->DestroySampler(device_, linear_, nullptr);
descPool_ = VK_NULL_HANDLE; linear_ = VK_NULL_HANDLE; device_ = VK_NULL_HANDLE; ready_ = false;
}
} // namespace winfg
// record() + its scratch helpers reopen namespace winfg themselves, so include
// this OUTSIDE the namespace block above (keeps FrameGen:: members attached).
#include "record_impl.inc"
@@ -0,0 +1,151 @@
// win-fg - compute frame-generation engine.
// Owns the compute pipelines (our of3_* optical flow + wfg_synth) and the
// per-resolution intermediate images, and records the flow+synth graph that
// turns (prev, curr) into an interpolated frame. Written for win-fg; no code
// from bionic-fg / lsfg / GameScope.
#pragma once
#include "vk_dispatch.hpp"
#include "config.hpp"
#include <vector>
namespace winfg {
class FrameGen {
public:
bool init(const DeviceDispatch* dd, const InstanceDispatch* id,
VkPhysicalDevice phys, VkDevice dev, uint32_t queueFamily, VkQueue queue);
// Applies a new config. Recomputes the active finest flow level from
// cfg_.perfPreset; if it changed while resources are live, safely rebuilds the
// affected per-size flow images (like a resize) and resets the flow predictor,
// so a perf_preset change is FULLY LIVE - no FG toggle needed. Defined in
// record_impl.inc (needs the scratch-state teardown). See flowFinestForPreset.
void configure(const Config& c);
// (Re)build per-resolution resources for a swapchain of the given size/format.
// force=true rebuilds even when the extent is unchanged (used by configure()
// when a perf_preset change alters the finest solved flow level).
bool onResize(VkExtent2D extent, VkFormat colorFormat, bool force = false);
// Record the whole flow+synth graph into cmd. prevView/currView are SAMPLED
// views of the two real frames; outView is a STORAGE view of the target
// image the generated frame is written into. alpha in (0,1).
// gmSlot selects which C1 global-motion SSBO to reduce into / read back; the
// caller MUST pass the ring-slot index of the FrameCtx it just fence-waited
// (that guarantees this slot's PREVIOUS reduce has completed and is safe to
// read on the host - see the decoupled-LK note in record_impl.inc).
void record(VkCommandBuffer cmd, VkImageView prevView, VkImageView currView,
VkImageView outView, float alpha, uint32_t gmSlot = 0);
void destroy();
bool valid() const { return device_ != VK_NULL_HANDLE && ready_; }
const Config& config() const { return cfg_; }
// public so the record_impl.inc free helpers can reference them
struct Img { VkImage image = VK_NULL_HANDLE; VkDeviceMemory mem = VK_NULL_HANDLE;
VkImageView view = VK_NULL_HANDLE; VkExtent2D extent{}; VkFormat fmt{}; };
struct Pipe { VkPipeline pipeline = VK_NULL_HANDLE; VkPipelineLayout layout = VK_NULL_HANDLE;
VkDescriptorSetLayout setLayout = VK_NULL_HANDLE; VkShaderModule module = VK_NULL_HANDLE; };
// ── C1 GLOBAL-MOTION PRE-WARP constants (public so record_impl.inc's free
// helpers can size/index the SSBO pool). See of3_gm_reduce/of3_gm_prewarp. ──
static constexpr int kGmSlots = 3; // >= present ring size; one SSBO per in-flight ctx
static constexpr int kGmLevel = 3; // 1/8-res luma pyramid level for the LK estimate
static constexpr int kGmThreads = 512; // fixed reduce threads (8 groups * local_size_x 64)
static constexpr int kGmStride = 32; // floats/thread: 21 H + 6 b + coverage + resid + pad
// Finest pyramid level the dense flow is solved at (0 = full res). This is now
// RUNTIME-SELECTABLE via conf.toml perf_preset (0 Quality=1 / 1 Balanced=2 /
// 2 Performance=3). kFlowFinestDefault is the Balanced value (today's behaviour);
// the ACTIVE level lives in flowFinest_ and is read through flowFinest(). onResize
// sizes the stabilized-curr pyramid + C2 scratch from it, and record_impl.inc
// wires the flow/expand inputs to it - both must agree, so they all read
// flowFinest()/flowFinest_ (never a hard-coded 2). (Was a static constexpr = 2.)
static constexpr int kFlowFinestDefault = 2; // Balanced (perf_preset=1)
// Map perf_preset -> finest solved level. Out-of-range -> Balanced. A higher
// level = coarser (cheaper) flow = smaller base-FPS drop. configure() clamps the
// result against kLevels so at least two solved levels always remain.
static int flowFinestForPreset(int preset) {
switch (preset) {
case 0: return 1; // Quality ~1/2-res
case 2: return 3; // Performance ~1/8-res
case 1: default: return kFlowFinestDefault; // Balanced ~1/4-res (today)
}
}
// The ACTIVE finest solved flow level (set by configure() from perf_preset).
int flowFinest() const { return flowFinest_; }
private:
uint32_t findMemType(uint32_t bits, VkMemoryPropertyFlags props) const;
bool makeImage(Img& out, VkExtent2D ext, VkFormat fmt, VkImageUsageFlags usage);
void destroyImage(Img& i);
bool makeGmBuffers(); // allocate the kGmSlots host-visible LK-reduce SSBOs
// Read back one reduce SSBO, solve the 6x6 inverse-compositional LK step, and
// update the running/applied global affine. Returns true if it engaged this
// frame. Implemented in record_impl.inc (has the ScratchState/UBO context).
bool updateGlobalMotion(uint32_t gmSlot, VkExtent2D fullExtent);
bool makePipe(Pipe& p, int shaderId,
const std::vector<VkDescriptorType>& bindings);
void destroyPipe(Pipe& p);
void barrier(VkCommandBuffer cmd, VkImage img, VkImageLayout from, VkImageLayout to);
const DeviceDispatch* dd_ = nullptr;
const InstanceDispatch* id_ = nullptr;
VkPhysicalDevice phys_ = VK_NULL_HANDLE;
VkDevice device_ = VK_NULL_HANDLE;
VkQueue queue_ = VK_NULL_HANDLE;
uint32_t queueFamily_ = 0;
VkPhysicalDeviceMemoryProperties memProps_{};
VkSampler linear_ = VK_NULL_HANDLE;
VkDescriptorPool descPool_ = VK_NULL_HANDLE;
Config cfg_;
VkExtent2D extent_{};
bool ready_ = false;
// ACTIVE finest solved flow level (perf_preset). Default = Balanced (today's 2)
// so an unconfigured engine and an unset conf.toml are byte-identical to before.
int flowFinest_ = kFlowFinestDefault;
// pipelines
Pipe pLuma_, pDown_, pFlow_, pFlowM4_, pExpand_, pExpandM4_, pSynth_;
// C1: LK normal-equation reduce + curr-luma stabilization pre-warp
Pipe pGmReduce_, pGmPrewarp_;
// C2: TV-L1 flow-regularization iteration (one dispatch per iteration)
Pipe pFlowReg_;
// per-resolution resources
// 7 levels (was 5): the coarsest levels set the max motion the solver can track.
// At 5 levels the reach was only ~±84px/frame at 720p, so fast camera motion
// (150-300px/frame at the periphery) saturated the search -> incoherent vectors
// -> oil-paint melt. Two more (tiny) coarse levels push the reach to ~±300px so
// large global motion is captured coherently instead of smeared. Near-zero cost:
// the extra levels are 40x22 and 20x11 images.
static const int kLevels = 7;
std::vector<Img> pyrA_, pyrB_; // luma pyramids for curr / prev
std::vector<Img> pyrAs_; // C1: STABILIZED curr luma (flow levels only)
std::vector<Img> flowLvl_; // per-level flow scratch
Img flowExpA_, flowExpB_; // fwd / bwd expanded flow (+conf)
// C2: TV-L1 ping-pong scratch at kFlowFinest res. flowLvl_[kFlowFinest] holds
// the fixed observation f0 (never written during the iterations); u ping-pongs
// between these two; the final iterate is copied back into flowLvl_[kFlowFinest]
// so of3_expand consumes the cleaned field with no binding change (⇒ skipping
// C2 leaves flowLvl_ byte-identical to pre-C2).
Img flowRegA_, flowRegB_;
// ── C1 global-motion state ────────────────────────────────────────────────
// Host-visible SSBOs the reduce shader writes per-thread partials into; the
// CPU sums + solves them. One per ring slot so a readback never races a live
// submission (the caller fence-waited its slot before calling record()).
VkBuffer gmSsbo_[kGmSlots] {};
VkDeviceMemory gmSsboMem_[kGmSlots]{};
void* gmSsboPtr_[kGmSlots]{};
bool gmBuffersReady_ = false;
// running affine params p1..p6 in centered-UV space (see GMUBO in config.hpp);
// identity = all zero. gmLinAt_ records the linearization params in effect when
// each slot's reduce was dispatched (the correct IC-update base for that slot).
double gmRun_[6] {};
double gmLinAt_[kGmSlots][6] {};
bool gmSlotValid_[kGmSlots]{};
bool gmHaveEst_ = false; // at least one good solve so far
int gmStableCount_ = 0; // consecutive good solves (auto-engage threshold)
bool gmEngaged_ = false; // is the affine being APPLIED this frame
float gmLastTransPx_ = 0.0f; // estimated global translation magnitude (full-res px), for logging
unsigned long long gmFrames_ = 0;
};
} // namespace winfg
+20
View File
@@ -0,0 +1,20 @@
// win-fg - logging. On Android goes to logcat (tag "win-fg") so device bring-up
// can trace the layer; elsewhere falls back to stderr.
#pragma once
#if defined(__ANDROID__)
#include <android/log.h>
#define WFG_LOGI(...) __android_log_print(ANDROID_LOG_INFO, "win-fg", __VA_ARGS__)
#define WFG_LOGE(...) __android_log_print(ANDROID_LOG_ERROR, "win-fg", __VA_ARGS__)
#else
#include <cstdio>
#define WFG_LOGI(...) do { std::fprintf(stderr, "[win-fg] " __VA_ARGS__); std::fprintf(stderr, "\n"); } while(0)
#define WFG_LOGE(...) do { std::fprintf(stderr, "[win-fg][E] " __VA_ARGS__); std::fprintf(stderr, "\n"); } while(0)
#endif
// Runtime-gated granular debug trace. The gate is a RUNTIME bool (Config::debug),
// not a compile-time switch - a shipping .so carries the full trail but pays only
// a predicted-not-taken bool test per step when debug is off (no logcat write, no
// arg evaluation of the message). Same "win-fg" tag so the app captures it under
// its own UID. Used to step the present path so a freeze leaves an obvious last
// line at the stage that hung. Usage: WFG_LOGD(dbg, "P#%llu step ...", n);
#define WFG_LOGD(cond, ...) do { if (cond) WFG_LOGI(__VA_ARGS__); } while(0)
@@ -0,0 +1,649 @@
// win-fg - FrameGen::record() and its lazy per-size descriptor/UBO setup.
// Included from framegen.cpp (has access to FrameGen privates). Written for
// win-fg; standard Vulkan compute wiring, no third-party code.
//
// ── C1 GLOBAL-MOTION PRE-WARP (this file wires it end to end) ─────────────────
// The dense SAD flow search melts on fast camera pans because the global motion
// saturates its window. C1 estimates the per-frame camera affine with a cheap
// inverse-compositional Lucas-Kanade solve (of3_gm_reduce accumulates the 6x6
// normal equations at 1/8 res → CPU 6x6 Cholesky here), then of3_gm_prewarp
// removes it from the curr luma pyramid BEFORE the search, so the search only
// sees small, coherent, object-only residual motion. of3_expand(_m4) composes
// the global affine back so wfg_synth is unchanged and the final warp is correct.
//
// DECOUPLED (stall-free) SCHEDULING: a true in-frame CPU solve would need a
// mid-frame GPU submit+readback stall - unacceptable on a GPU-bound title. So we
// read back the reduce SSBO the caller ALREADY fence-waited (its ring slot from a
// couple of presents ago) and run ONE Gauss-Newton step per frame, warm-started
// from the running estimate. Camera motion is temporally smooth, so a ~1-2 frame
// old affine is an excellent predictor; and because the SAME affine is removed
// (prewarp) and added back (expand), the result is EXACT for any affine we pick -
// an approximate/stale one only changes how much residual the search must absorb,
// never correctness. Identity affine ⇒ byte-identical to the pre-C1 pipeline, so
// the bail-to-identity safety path can never be worse than "no pre-warp".
namespace {
struct ScratchState {
// host-visible UBO buffers
VkBuffer synthUbo = VK_NULL_HANDLE; VkDeviceMemory synthUboMem = VK_NULL_HANDLE; void* synthUboPtr = nullptr;
std::vector<VkBuffer> flowUbo; std::vector<VkDeviceMemory> flowUboMem; std::vector<void*> flowUboPtr;
VkBuffer expandUbo = VK_NULL_HANDLE; VkDeviceMemory expandUboMem = VK_NULL_HANDLE; void* expandUboPtr = nullptr;
// C2: flow-regularization UBO (shared by all iterations; refreshed per frame).
VkBuffer flowRegUbo = VK_NULL_HANDLE; VkDeviceMemory flowRegUboMem = VK_NULL_HANDLE; void* flowRegUboPtr = nullptr;
// C1: per-slot global-motion UBO (double-buffered by ring slot so a live GPU
// read is never overwritten by the next frame - see the header note).
VkBuffer gmUbo[winfg::FrameGen::kGmSlots]{};
VkDeviceMemory gmUboMem[winfg::FrameGen::kGmSlots]{};
void* gmUboPtr[winfg::FrameGen::kGmSlots]{};
// persistent descriptor sets
VkDescriptorSet sLumaCurr = VK_NULL_HANDLE, sLumaPrev = VK_NULL_HANDLE;
std::vector<VkDescriptorSet> sDownA, sDownB, sFlow;
VkDescriptorSet sExpand[winfg::FrameGen::kGmSlots]{}; // per-slot (binds gmUbo[slot])
// C2: three flow-reg sets covering every (u_in → u_out) pairing of the
// ping-pong. sFlowReg0: in=flowLvl_[F] (=f0), out=A. sFlowRegAB: in=A, out=B.
// sFlowRegBA: in=B, out=A. f0 (binding 33) = flowLvl_[F] in all three.
VkDescriptorSet sFlowReg0 = VK_NULL_HANDLE, sFlowRegAB = VK_NULL_HANDLE, sFlowRegBA = VK_NULL_HANDLE;
VkDescriptorSet sSynth = VK_NULL_HANDLE;
// C1: per-slot reduce set + per-slot per-level prewarp sets
VkDescriptorSet sGmReduce[winfg::FrameGen::kGmSlots]{};
std::vector<VkDescriptorSet> sGmPrewarp[winfg::FrameGen::kGmSlots]; // sized kLevels; [flowFinest()..) used
VkExtent2D builtFor{0,0};
bool built = false;
bool flowInited = false; // flow images laid out once, then persist (temporal predictor)
};
ScratchState g_scratch; // one swapchain in flight in this first-draft engine
}
static bool makeUbo(const winfg::DeviceDispatch* dd, VkDevice dev,
const VkPhysicalDeviceMemoryProperties& mp,
VkDeviceSize size, VkBuffer& buf, VkDeviceMemory& mem, void*& ptr) {
VkBufferCreateInfo bi{VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO};
bi.size = size; bi.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; bi.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
if (dd->CreateBuffer(dev, &bi, nullptr, &buf) != VK_SUCCESS) return false;
VkMemoryRequirements mr; dd->GetBufferMemoryRequirements(dev, buf, &mr);
uint32_t idx = 0; VkMemoryPropertyFlags want = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
for (uint32_t i = 0; i < mp.memoryTypeCount; ++i)
if ((mr.memoryTypeBits & (1u<<i)) && (mp.memoryTypes[i].propertyFlags & want) == want) { idx = i; break; }
VkMemoryAllocateInfo ai{VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO}; ai.allocationSize = mr.size; ai.memoryTypeIndex = idx;
if (dd->AllocateMemory(dev, &ai, nullptr, &mem) != VK_SUCCESS) return false;
if (dd->BindBufferMemory(dev, buf, mem, 0) != VK_SUCCESS) return false;
return dd->MapMemory(dev, mem, 0, size, 0, &ptr) == VK_SUCCESS;
}
static VkDescriptorSet allocSet(const winfg::DeviceDispatch* dd, VkDevice dev,
VkDescriptorPool pool, VkDescriptorSetLayout layout) {
VkDescriptorSetAllocateInfo ai{VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO};
ai.descriptorPool = pool; ai.descriptorSetCount = 1; ai.pSetLayouts = &layout;
VkDescriptorSet s = VK_NULL_HANDLE; dd->AllocateDescriptorSets(dev, &ai, &s); return s;
}
// write helpers
static void wImg(const winfg::DeviceDispatch* dd, VkDevice dev, VkDescriptorSet set, uint32_t binding,
VkDescriptorType type, VkImageView view, VkSampler samp, VkImageLayout layout) {
VkDescriptorImageInfo ii{}; ii.imageView = view; ii.sampler = samp; ii.imageLayout = layout;
VkWriteDescriptorSet w{VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET};
w.dstSet = set; w.dstBinding = binding; w.descriptorCount = 1; w.descriptorType = type; w.pImageInfo = &ii;
dd->UpdateDescriptorSets(dev, 1, &w, 0, nullptr);
}
static void wUbo(const winfg::DeviceDispatch* dd, VkDevice dev, VkDescriptorSet set, uint32_t binding,
VkBuffer buf, VkDeviceSize range) {
VkDescriptorBufferInfo bi{}; bi.buffer = buf; bi.range = range;
VkWriteDescriptorSet w{VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET};
w.dstSet = set; w.dstBinding = binding; w.descriptorCount = 1;
w.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; w.pBufferInfo = &bi;
dd->UpdateDescriptorSets(dev, 1, &w, 0, nullptr);
}
static void wSsbo(const winfg::DeviceDispatch* dd, VkDevice dev, VkDescriptorSet set, uint32_t binding,
VkBuffer buf, VkDeviceSize range) {
VkDescriptorBufferInfo bi{}; bi.buffer = buf; bi.range = range;
VkWriteDescriptorSet w{VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET};
w.dstSet = set; w.dstBinding = binding; w.descriptorCount = 1;
w.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER; w.pBufferInfo = &bi;
dd->UpdateDescriptorSets(dev, 1, &w, 0, nullptr);
}
// ── C1 CPU-side linear algebra (clean-room, textbook) ────────────────────────
// 6x6 symmetric positive-definite solve via Cholesky. Returns false if not PD
// (a bad/ill-conditioned frame → caller bails to identity). Damped by the caller.
static bool cholSolve6(double A[6][6], const double b[6], double x[6]) {
double L[6][6] = {{0}};
for (int i = 0; i < 6; ++i) {
for (int j = 0; j <= i; ++j) {
double s = A[i][j];
for (int k = 0; k < j; ++k) s -= L[i][k] * L[j][k];
if (i == j) {
if (s <= 1e-20) return false; // not positive-definite
L[i][j] = std::sqrt(s);
} else {
L[i][j] = s / L[j][j];
}
}
}
double y[6];
for (int i = 0; i < 6; ++i) { double s = b[i]; for (int k = 0; k < i; ++k) s -= L[i][k]*y[k]; y[i] = s / L[i][i]; }
for (int i = 5; i >= 0; --i) { double s = y[i]; for (int k = i+1; k < 6; ++k) s -= L[k][i]*x[k]; x[i] = s / L[i][i]; }
return true;
}
// affine <-> params. params p=(p1,p2,p3,p4,p5,p6); M = I + [[p1,p3,p5],[p2,p4,p6]].
static void affFromParams(const double p[6], double M[3][3]) {
M[0][0]=1.0+p[0]; M[0][1]=p[2]; M[0][2]=p[4];
M[1][0]=p[1]; M[1][1]=1.0+p[3]; M[1][2]=p[5];
M[2][0]=0.0; M[2][1]=0.0; M[2][2]=1.0;
}
static void paramsFromAff(const double M[3][3], double p[6]) {
p[0]=M[0][0]-1.0; p[2]=M[0][1]; p[4]=M[0][2];
p[1]=M[1][0]; p[3]=M[1][1]-1.0; p[5]=M[1][2];
}
static bool invAff(const double M[3][3], double out[3][3]) {
double a=M[0][0], b=M[0][1], tx=M[0][2], c=M[1][0], d=M[1][1], ty=M[1][2];
double det = a*d - b*c;
if (std::fabs(det) < 1e-12) return false;
double id = 1.0/det;
out[0][0]= d*id; out[0][1]= -b*id; out[0][2]= (b*ty - d*tx)*id;
out[1][0]= -c*id; out[1][1]= a*id; out[1][2]= (c*tx - a*ty)*id;
out[2][0]=0.0; out[2][1]=0.0; out[2][2]=1.0;
return true;
}
static void mulAff(const double A[3][3], const double B[3][3], double out[3][3]) {
for (int i = 0; i < 2; ++i)
for (int j = 0; j < 3; ++j)
out[i][j] = A[i][0]*B[0][j] + A[i][1]*B[1][j] + A[i][2]*B[2][j];
out[2][0]=0.0; out[2][1]=0.0; out[2][2]=1.0;
}
namespace winfg {
// Lazily allocate per-size UBOs + descriptor sets and wire the fixed (internal-
// resource) bindings once. External views (prev/curr/out) are wired per frame.
static bool ensureScratch(FrameGen* fg, const DeviceDispatch* dd, VkDevice dev,
const VkPhysicalDeviceMemoryProperties& mp, VkDescriptorPool pool,
VkSampler samp, VkExtent2D ext,
std::vector<FrameGen::Img>& pyrA, std::vector<FrameGen::Img>& pyrB,
std::vector<FrameGen::Img>& pyrAs,
std::vector<FrameGen::Img>& flowLvl, FrameGen::Img& expA, FrameGen::Img& expB,
const FrameGen::Pipe& pLuma, const FrameGen::Pipe& pDown,
const FrameGen::Pipe& pFlow, const FrameGen::Pipe& pExpand,
const FrameGen::Pipe& pSynth, const FrameGen::Pipe& pGmReduce,
const FrameGen::Pipe& pGmPrewarp, const FrameGen::Pipe& pFlowReg,
FrameGen::Img& flowRegA, FrameGen::Img& flowRegB, VkBuffer* gmSsbo,
int kLevels, const Config& cfg);
// Tear down the lazily-built scratch (all UBO buffers + every descriptor set) so a
// live perf_preset rebuild neither leaks them nor exhausts the descriptor pool.
// The CALLER must have made the device idle first - no in-flight command buffer may
// still reference these. Resetting the pool frees every set FrameGen allocated (all
// sets come from this pool); the mapped UBO memory is unmapped + freed explicitly.
static void destroyScratch(const DeviceDispatch* dd, VkDevice dev, VkDescriptorPool pool) {
auto freeUbo = [&](VkBuffer& b, VkDeviceMemory& m, void*& p) {
if (m) dd->UnmapMemory(dev, m);
if (b) dd->DestroyBuffer(dev, b, nullptr);
if (m) dd->FreeMemory(dev, m, nullptr);
b = VK_NULL_HANDLE; m = VK_NULL_HANDLE; p = nullptr;
};
auto& S = g_scratch;
freeUbo(S.synthUbo, S.synthUboMem, S.synthUboPtr);
freeUbo(S.expandUbo, S.expandUboMem, S.expandUboPtr);
freeUbo(S.flowRegUbo, S.flowRegUboMem, S.flowRegUboPtr);
for (size_t i = 0; i < S.flowUbo.size(); ++i) freeUbo(S.flowUbo[i], S.flowUboMem[i], S.flowUboPtr[i]);
for (int s = 0; s < FrameGen::kGmSlots; ++s) freeUbo(S.gmUbo[s], S.gmUboMem[s], S.gmUboPtr[s]);
if (pool && dd->ResetDescriptorPool) dd->ResetDescriptorPool(dev, pool, 0); // reclaim all sets at once
S = ScratchState{}; // built=false -> next record() rebuilds via ensureScratch
}
// ── perf_preset apply / live rebuild ─────────────────────────────────────────
// Sets the config, resolves the perf_preset -> finest-solved-level, and - when
// that level changed while resources are already live - safely rebuilds the
// affected per-size flow images (a resize) + scratch descriptor sets and resets
// the flow predictor. This makes a perf_preset change FULLY LIVE per-present (the
// conf.toml hot-reload path calls this), so no FG toggle / bg-fg cycle is needed.
void FrameGen::configure(const Config& c) {
cfg_ = c; cfg_.sanitize();
// Map preset -> finest level, clamped so at least TWO solved levels always
// remain (coarse->fine needs a range). With kLevels=7 the presets (1/2/3) never
// hit the clamp; the guard is defensive for future level/preset tuning.
int want = flowFinestForPreset(cfg_.perfPreset);
const int maxFinest = kLevels - 2; // keep >= 2 solved levels
if (want > maxFinest) {
WFG_LOGE("perf-preset=%d wants kFlowFinest=%d but only %d pyramid levels exist "
"(need >=2 solved) - clamping to %d", cfg_.perfPreset, want, kLevels, maxFinest);
want = maxFinest;
}
if (want < 1) want = 1; // never solve full-res (level 0)
const int prevFinest = flowFinest_;
flowFinest_ = want;
const bool live = (flowFinest_ != prevFinest) && ready_;
WFG_LOGI("perf-preset=%d -> kFlowFinest=%d (was %d) live-rebuild=%d ready=%d",
cfg_.perfPreset, flowFinest_, prevFinest, live ? 1 : 0, ready_ ? 1 : 0);
if (!live) return; // unchanged, or not yet built (initial configure before onResize)
// The per-size flow images (pyrAs_/flowReg*/flowLvl_ wiring) and the scratch
// descriptor sets were built for the OLD finest level. Rebuild them so record()
// never reads/writes mismatched-size images.
dd_->DeviceWaitIdle(device_); // no in-flight cmd buf may touch these
destroyScratch(dd_, device_, descPool_); // free old scratch (UBOs + all sets)
if (!onResize(extent_, VK_FORMAT_UNDEFINED, /*force=*/true))
WFG_LOGE("perf-preset live rebuild: onResize FAILED at %ux%u - FG disabled until next resize",
extent_.width, extent_.height);
// Reset the persistent flow predictor so stale, differently-scaled state never
// feeds the new resolution (avoids a melt/garbage frame on switch). The per-frame
// flow field (flowLvl_) is already cleared every frame; the cross-frame state is
// the C1 global-motion estimate + its per-slot reduce partials (dispatched against
// the old pyramid) - drop both back to identity.
for (int i = 0; i < 6; ++i) gmRun_[i] = 0.0;
for (int s = 0; s < kGmSlots; ++s) { gmSlotValid_[s] = false; for (int i = 0; i < 6; ++i) gmLinAt_[s][i] = 0.0; }
gmHaveEst_ = false; gmEngaged_ = false; gmStableCount_ = 0; gmLastTransPx_ = 0.0f;
WFG_LOGI("perf-preset live rebuild DONE (kFlowFinest=%d, flow predictor reset)", flowFinest_);
}
// ── C1: read back one reduce SSBO, run one inverse-compositional LK step ──────
// Updates the running/applied global affine. Returns whether GM engages this frame.
bool FrameGen::updateGlobalMotion(uint32_t gmSlot, VkExtent2D fullExtent) {
++gmFrames_;
if (!gmBuffersReady_ || cfg_.gmMode == 2 /*off*/) {
// off: keep identity applied; keep estimating cheaply is pointless when off.
gmEngaged_ = false; gmStableCount_ = 0;
// still refresh the linearization record so a live switch to auto starts clean
for (int i = 0; i < 6; ++i) gmRun_[i] = 0.0;
for (int i = 0; i < 6; ++i) gmLinAt_[gmSlot][i] = gmRun_[i];
gmLastTransPx_ = 0.0f;
return false;
}
bool good = false;
if (gmSlotValid_[gmSlot]) {
const float* pt = (const float*)gmSsboPtr_[gmSlot];
double sums[32]; for (int k = 0; k < 32; ++k) sums[k] = 0.0;
for (int t = 0; t < kGmThreads; ++t) {
const float* row = pt + (size_t)t * kGmStride;
for (int k = 0; k < kGmStride; ++k) sums[k] += (double)row[k];
}
double coverage = sums[27];
// require a few percent of the level's pixels as inliers
double lvlpx = double((fullExtent.width >> kGmLevel) * (fullExtent.height >> kGmLevel));
double minCov = 0.03 * (lvlpx > 0 ? lvlpx : 1.0);
if (coverage > minCov && coverage > 64.0) {
double H[6][6]; int idx = 0;
for (int r = 0; r < 6; ++r) for (int c = r; c < 6; ++c) { H[r][c] = H[c][r] = sums[idx]; ++idx; }
double b[6]; for (int i = 0; i < 6; ++i) b[i] = sums[21 + i];
// Levenberg damping for conditioning (relative + tiny absolute).
for (int i = 0; i < 6; ++i) H[i][i] += 1e-3 * H[i][i] + 1e-9;
double dp[6];
if (cholSolve6(H, b, dp)) {
// reject wild steps (something non-affine / a scene cut)
bool bounded = std::fabs(dp[0]) < 0.5 && std::fabs(dp[1]) < 0.5 &&
std::fabs(dp[2]) < 0.5 && std::fabs(dp[3]) < 0.5 &&
std::fabs(dp[4]) < 0.25 && std::fabs(dp[5]) < 0.25;
if (bounded) {
// IC update: M_new = M_lin ∘ W(dp)^-1 (compose onto the SLOT's
// linearization base, which is what this reduce linearized around).
double Mlin[3][3], Md[3][3], Mdi[3][3], Mnew[3][3];
affFromParams(gmLinAt_[gmSlot], Mlin);
affFromParams(dp, Md);
if (invAff(Md, Mdi)) {
mulAff(Mlin, Mdi, Mnew);
double pnew[6]; paramsFromAff(Mnew, pnew);
// final sanity clamp on the composed estimate
bool sane = std::fabs(pnew[0]) < 0.6 && std::fabs(pnew[1]) < 0.6 &&
std::fabs(pnew[2]) < 0.6 && std::fabs(pnew[3]) < 0.6 &&
std::fabs(pnew[4]) < 0.5 && std::fabs(pnew[5]) < 0.5;
if (sane) { for (int i = 0; i < 6; ++i) gmRun_[i] = pnew[i]; good = true; gmHaveEst_ = true; }
}
}
}
}
}
if (good) ++gmStableCount_; else gmStableCount_ = 0;
// engage policy
switch (cfg_.gmMode) {
case 1: gmEngaged_ = gmHaveEst_; break; // on
case 2: gmEngaged_ = false; break; // off (unreachable; handled above)
default: gmEngaged_ = (gmStableCount_ >= 3); break; // auto: 3 consecutive good solves
}
// record the linearization base for the reduce we are about to dispatch into
// this slot this frame (i.e. the current running estimate).
for (int i = 0; i < 6; ++i) gmLinAt_[gmSlot][i] = gmRun_[i];
gmSlotValid_[gmSlot] = true; // this frame's reduce will (re)write it
gmLastTransPx_ = (float)std::sqrt(
(gmRun_[4]*fullExtent.width) * (gmRun_[4]*fullExtent.width) +
(gmRun_[5]*fullExtent.height) * (gmRun_[5]*fullExtent.height));
return gmEngaged_;
}
void FrameGen::record(VkCommandBuffer cmd, VkImageView prevView, VkImageView currView,
VkImageView outView, float alpha, uint32_t gmSlot) {
if (!valid()) return;
if (gmSlot >= (uint32_t)kGmSlots) gmSlot = 0;
const bool m4 = (cfg_.model == 4);
const Pipe& flowP = m4 ? pFlowM4_ : pFlow_;
const Pipe& expandP = m4 ? pExpandM4_ : pExpand_;
if (!g_scratch.built || g_scratch.builtFor.width != extent_.width || g_scratch.builtFor.height != extent_.height) {
ensureScratch(this, dd_, device_, memProps_, descPool_, linear_, extent_,
pyrA_, pyrB_, pyrAs_, flowLvl_, flowExpA_, flowExpB_,
pLuma_, pDown_, flowP, expandP, pSynth_, pGmReduce_, pGmPrewarp_,
pFlowReg_, flowRegA_, flowRegB_, gmSsbo_, kLevels, cfg_);
}
// ── C1: solve the global-motion affine (reads the SSBO the caller fence-waited) ──
bool gmEngaged = updateGlobalMotion(gmSlot, extent_);
// Build this slot's GMUBO from the running / applied affine.
if (g_scratch.gmUboPtr[gmSlot]) {
GMUBO g{};
g.lin[0]=(float)gmRun_[0]; g.lin[1]=(float)gmRun_[1]; g.lin[2]=(float)gmRun_[2]; g.lin[3]=(float)gmRun_[3];
g.linT[0]=(float)gmRun_[4]; g.linT[1]=(float)gmRun_[5]; g.linT[2]=gmEngaged?1.0f:0.0f; g.linT[3]=0.0f;
if (gmEngaged) {
g.app[0]=(float)gmRun_[0]; g.app[1]=(float)gmRun_[1]; g.app[2]=(float)gmRun_[2]; g.app[3]=(float)gmRun_[3];
g.appT[0]=(float)gmRun_[4]; g.appT[1]=(float)gmRun_[5];
} // else app/appT stay 0 -> identity -> prewarp/expand are pre-C1 no-ops
std::memcpy(g_scratch.gmUboPtr[gmSlot], &g, sizeof(g));
}
// Log engage state + estimated global translation periodically (tag win-fg).
{
static int lastEng = -1;
if (gmEngaged != (lastEng == 1) || (gmFrames_ % 300ull) == 0) {
WFG_LOGI("C1 global-motion: engaged=%d mode=%d stable=%d transPx=%.1f (model=%d)",
gmEngaged ? 1 : 0, cfg_.gmMode, gmStableCount_, gmLastTransPx_, cfg_.model);
lastEng = gmEngaged ? 1 : 0;
}
}
// update UBOs for this frame
SynthUBO su{cfg_.flowScale, alpha, cfg_.beta, cfg_.lambda, cfg_.epsilon, cfg_.photoScale, 0, 0,
cfg_.hudX0, cfg_.hudY0, cfg_.hudX1, cfg_.hudY1};
if (g_scratch.synthUboPtr) std::memcpy(g_scratch.synthUboPtr, &su, sizeof(su));
// wire per-frame external views
wImg(dd_, device_, g_scratch.sLumaCurr, 32, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, currView, linear_, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
wImg(dd_, device_, g_scratch.sLumaPrev, 32, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, prevView, linear_, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
wImg(dd_, device_, g_scratch.sSynth, 32, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, prevView, linear_, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
wImg(dd_, device_, g_scratch.sSynth, 33, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, currView, linear_, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
wImg(dd_, device_, g_scratch.sSynth, 48, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, outView, VK_NULL_HANDLE, VK_IMAGE_LAYOUT_GENERAL);
auto disp = [&](const Pipe& p, VkDescriptorSet set, VkExtent2D e) {
dd_->CmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_COMPUTE, p.pipeline);
dd_->CmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_COMPUTE, p.layout, 0, 1, &set, 0, nullptr);
dd_->CmdDispatch(cmd, (e.width + 15) / 16, (e.height + 15) / 16, 1);
};
auto bar = [&](FrameGen::Img& i){ barrier(cmd, i.image, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL); };
// Internal images are created UNDEFINED and fully recomputed every frame, so
// discard-transition them all to GENERAL up front (all descriptors use GENERAL
// for these). This also fixes the first-frame layout (storage writes require
// GENERAL, not UNDEFINED).
for (auto& i : pyrA_) barrier(cmd, i.image, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_GENERAL);
for (auto& i : pyrB_) barrier(cmd, i.image, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_GENERAL);
for (int l = flowFinest_; l < kLevels; ++l) barrier(cmd, pyrAs_[l].image, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_GENERAL);
barrier(cmd, flowExpA_.image, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_GENERAL);
barrier(cmd, flowExpB_.image, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_GENERAL);
// C2: ping-pong scratch to GENERAL (storage writes require it; contents discarded).
barrier(cmd, flowRegA_.image, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_GENERAL);
barrier(cmd, flowRegB_.image, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_GENERAL);
// Reset the flow field to zero every frame. The coarsest level uses it as its
// search predictor; carrying it across frames lets a spurious vector feed
// forward until it diverges and melts the image (the bg/fg pause was resetting
// it - that's why artifacts vanished on resume). Fresh zero every frame =
// stable, standard pyramid flow, no feedback loop.
{
VkClearColorValue zero{};
VkImageSubresourceRange rng{VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1};
for (int l = flowFinest_; l < kLevels; ++l) {
VkImageMemoryBarrier b{VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER};
b.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED; b.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
b.srcAccessMask = 0; b.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
b.image = flowLvl_[l].image; b.subresourceRange = rng;
b.srcQueueFamilyIndex = b.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
dd_->CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, nullptr, 0, nullptr, 1, &b);
dd_->CmdClearColorImage(cmd, flowLvl_[l].image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &zero, 1, &rng);
b.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; b.newLayout = VK_IMAGE_LAYOUT_GENERAL;
b.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; b.dstAccessMask = VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT;
dd_->CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &b);
}
}
// 1) luma of curr/prev at full res
disp(pLuma_, g_scratch.sLumaCurr, levelExtent(extent_, 0));
disp(pLuma_, g_scratch.sLumaPrev, levelExtent(extent_, 0));
bar(pyrA_[0]); bar(pyrB_[0]);
// 2) downsample pyramids
for (int l = 1; l < kLevels; ++l) {
disp(pDown_, g_scratch.sDownA[l - 1], levelExtent(extent_, l));
disp(pDown_, g_scratch.sDownB[l - 1], levelExtent(extent_, l));
bar(pyrA_[l]); bar(pyrB_[l]);
}
// 2b) C1: LK normal-equation reduce (fixed grid, 1/8-res) → this slot's SSBO.
// Reads raw prev/curr luma at kGmLevel; writes per-thread partials. A
// compute→host barrier makes the write visible to the CPU readback that
// happens when this slot comes round again (~1-2 frames later).
if (gmBuffersReady_ && g_scratch.sGmReduce[gmSlot]) {
dd_->CmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_COMPUTE, pGmReduce_.pipeline);
dd_->CmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_COMPUTE, pGmReduce_.layout, 0, 1, &g_scratch.sGmReduce[gmSlot], 0, nullptr);
dd_->CmdDispatch(cmd, (uint32_t)(kGmThreads / 64), 1, 1);
VkMemoryBarrier mb{VK_STRUCTURE_TYPE_MEMORY_BARRIER};
mb.srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT; mb.dstAccessMask = VK_ACCESS_HOST_READ_BIT;
dd_->CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_HOST_BIT,
0, 1, &mb, 0, nullptr, 0, nullptr);
}
// 2c) C1: pre-warp curr luma pyramid by the applied affine → stabilized pyramid
// (identity affine ⇒ exact copy, so the flow below is unchanged when
// disengaged). The dense flow reads pyrAs from here on.
for (int l = flowFinest_; l < kLevels; ++l) {
disp(pGmPrewarp_, g_scratch.sGmPrewarp[gmSlot][l], levelExtent(extent_, l));
bar(pyrAs_[l]);
}
// 3) coarse->fine flow (only down to flowFinest_ - reduced res for perf; the
// finest level is perf_preset-selectable). Curr input is now the STABILIZED
// pyramid (pyrAs), wired in ensureScratch.
for (int l = kLevels - 1; l >= flowFinest_; --l) {
disp(flowP, g_scratch.sFlow[l], levelExtent(extent_, l));
bar(flowLvl_[l]);
}
// 3b) ── C2: TV-L1 flow regularization on the finest residual field ──────────
// Run frIters semi-implicit TV-L1 denoising iterations on flowLvl_[flowFinest_]
// (the object-only residual left by C1). flowLvl_[F] is the fixed data term f0
// (read, never written here); u ping-pongs A<->B; the final iterate is copied
// back into flowLvl_[F] so of3_expand consumes the cleaned field unchanged.
// Disengaged (frMode==off or frIters==0) ⇒ flowLvl_[F] untouched ⇒ byte-identical
// to pre-C2. Identity/zero iterations is therefore never worse than "no reg".
const bool frEngaged = (cfg_.frMode != 2) && (cfg_.frIters > 0);
if (frEngaged) {
const int F = flowFinest_;
const VkExtent2D fe = levelExtent(extent_, F);
if (g_scratch.flowRegUboPtr) {
FlowRegUBO fu{cfg_.frDt, cfg_.frLambda, cfg_.frEdge, cfg_.frEps};
std::memcpy(g_scratch.flowRegUboPtr, &fu, sizeof(fu));
}
FrameGen::Img* last = nullptr;
for (int it = 0; it < cfg_.frIters; ++it) {
VkDescriptorSet set; FrameGen::Img* outImg;
if (it == 0) { set = g_scratch.sFlowReg0; outImg = &flowRegA_; }
else if (it % 2 == 1) { set = g_scratch.sFlowRegAB; outImg = &flowRegB_; }
else { set = g_scratch.sFlowRegBA; outImg = &flowRegA_; }
dd_->CmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_COMPUTE, pFlowReg_.pipeline);
dd_->CmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_COMPUTE, pFlowReg_.layout, 0, 1, &set, 0, nullptr);
dd_->CmdDispatch(cmd, (fe.width + 15) / 16, (fe.height + 15) / 16, 1);
bar(*outImg);
last = outImg;
}
// Copy the cleaned finest flow back into flowLvl_[F] (GENERAL->GENERAL).
// Barrier: C2's f0 reads (SHADER_READ of flowLvl_[F]) and the last iterate
// write must complete before the transfer overwrites/reads.
VkMemoryBarrier mb{VK_STRUCTURE_TYPE_MEMORY_BARRIER};
mb.srcAccessMask = VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT;
mb.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_TRANSFER_WRITE_BIT;
dd_->CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT,
0, 1, &mb, 0, nullptr, 0, nullptr);
VkImageCopy region{};
region.srcSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1};
region.dstSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1};
region.extent = {fe.width, fe.height, 1};
dd_->CmdCopyImage(cmd, last->image, VK_IMAGE_LAYOUT_GENERAL,
flowLvl_[F].image, VK_IMAGE_LAYOUT_GENERAL, 1, &region);
VkMemoryBarrier mb2{VK_STRUCTURE_TYPE_MEMORY_BARRIER};
mb2.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
mb2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
dd_->CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
0, 1, &mb2, 0, nullptr, 0, nullptr);
}
{ // periodic C2 status (tag win-fg), mirrors the C1 log cadence
static int lastFr = -1;
int fe = frEngaged ? 1 : 0;
if (fe != lastFr || (gmFrames_ % 300ull) == 0) {
WFG_LOGI("C2 flow-reg: engaged=%d mode=%d iters=%d lambda=%.2f dt=%.2f edge=%.1f eps=%.3f (model=%d)",
fe, cfg_.frMode, cfg_.frIters, cfg_.frLambda, cfg_.frDt, cfg_.frEdge, cfg_.frEps, cfg_.model);
lastFr = fe;
}
}
// 4) expand finest solved flow -> fwd/bwd (+conf), + C1 global-motion add-back.
disp(expandP, g_scratch.sExpand[gmSlot], levelExtent(extent_, 0));
bar(flowExpA_); bar(flowExpB_);
// 5) synthesise interpolated frame
disp(pSynth_, g_scratch.sSynth, levelExtent(extent_, 0));
}
// ---- lazy scratch builder ----
static bool ensureScratch(FrameGen* fg, const DeviceDispatch* dd, VkDevice dev,
const VkPhysicalDeviceMemoryProperties& mp, VkDescriptorPool pool,
VkSampler samp, VkExtent2D ext,
std::vector<FrameGen::Img>& pyrA, std::vector<FrameGen::Img>& pyrB,
std::vector<FrameGen::Img>& pyrAs,
std::vector<FrameGen::Img>& flowLvl, FrameGen::Img& expA, FrameGen::Img& expB,
const FrameGen::Pipe& pLuma, const FrameGen::Pipe& pDown,
const FrameGen::Pipe& pFlow, const FrameGen::Pipe& pExpand,
const FrameGen::Pipe& pSynth, const FrameGen::Pipe& pGmReduce,
const FrameGen::Pipe& pGmPrewarp, const FrameGen::Pipe& pFlowReg,
FrameGen::Img& flowRegA, FrameGen::Img& flowRegB, VkBuffer* gmSsbo,
int kLevels, const Config& cfg) {
auto& S = g_scratch;
S = ScratchState{};
const auto GEN = VK_IMAGE_LAYOUT_GENERAL;
makeUbo(dd, dev, mp, sizeof(SynthUBO), S.synthUbo, S.synthUboMem, S.synthUboPtr);
makeUbo(dd, dev, mp, sizeof(FlowUBO), S.expandUbo, S.expandUboMem, S.expandUboPtr);
if (S.expandUboPtr) { FlowUBO u{cfg.flowScale, 0, 0.6f, 1.6f}; std::memcpy(S.expandUboPtr, &u, sizeof(u)); }
// C2: flow-reg UBO (params refreshed each frame in record() for hot-reload).
makeUbo(dd, dev, mp, sizeof(FlowRegUBO), S.flowRegUbo, S.flowRegUboMem, S.flowRegUboPtr);
if (S.flowRegUboPtr) { FlowRegUBO fu{cfg.frDt, cfg.frLambda, cfg.frEdge, cfg.frEps}; std::memcpy(S.flowRegUboPtr, &fu, sizeof(fu)); }
S.flowUbo.resize(kLevels); S.flowUboMem.resize(kLevels); S.flowUboPtr.resize(kLevels);
for (int l = 0; l < kLevels; ++l) {
makeUbo(dd, dev, mp, sizeof(FlowUBO), S.flowUbo[l], S.flowUboMem[l], S.flowUboPtr[l]);
if (S.flowUboPtr[l]) { FlowUBO u{cfg.flowScale, (uint32_t)l, 0.6f, 1.6f}; std::memcpy(S.flowUboPtr[l], &u, sizeof(u)); }
}
// C1: per-slot GMUBO (initialised to identity)
for (int s = 0; s < FrameGen::kGmSlots; ++s) {
makeUbo(dd, dev, mp, sizeof(GMUBO), S.gmUbo[s], S.gmUboMem[s], S.gmUboPtr[s]);
if (S.gmUboPtr[s]) { GMUBO g{}; std::memcpy(S.gmUboPtr[s], &g, sizeof(g)); }
}
// luma sets (external src wired per frame; dst is pyramid[0])
S.sLumaCurr = allocSet(dd, dev, pool, pLuma.setLayout);
S.sLumaPrev = allocSet(dd, dev, pool, pLuma.setLayout);
wImg(dd, dev, S.sLumaCurr, 48, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, pyrA[0].view, VK_NULL_HANDLE, GEN);
wImg(dd, dev, S.sLumaPrev, 48, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, pyrB[0].view, VK_NULL_HANDLE, GEN);
// downsample sets (fixed)
S.sDownA.resize(kLevels - 1); S.sDownB.resize(kLevels - 1);
for (int l = 1; l < kLevels; ++l) {
S.sDownA[l-1] = allocSet(dd, dev, pool, pDown.setLayout);
S.sDownB[l-1] = allocSet(dd, dev, pool, pDown.setLayout);
wImg(dd, dev, S.sDownA[l-1], 32, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, pyrA[l-1].view, samp, GEN);
wImg(dd, dev, S.sDownA[l-1], 48, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, pyrA[l].view, VK_NULL_HANDLE, GEN);
wImg(dd, dev, S.sDownB[l-1], 32, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, pyrB[l-1].view, samp, GEN);
wImg(dd, dev, S.sDownB[l-1], 48, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, pyrB[l].view, VK_NULL_HANDLE, GEN);
}
// flow sets (fixed): predictor = coarser flow level, or self at coarsest.
// C1: the CURR input (binding 33) is the STABILIZED pyramid pyrAs for the
// solved flow levels; prev stays raw. Below kFlowFinest the level is never
// dispatched, so leaving those at raw curr is harmless.
S.sFlow.resize(kLevels);
for (int l = 0; l < kLevels; ++l) {
S.sFlow[l] = allocSet(dd, dev, pool, pFlow.setLayout);
int pred = (l + 1 < kLevels) ? l + 1 : l;
VkImageView currLvl = (l >= fg->flowFinest()) ? pyrAs[l].view : pyrA[l].view;
wUbo(dd, dev, S.sFlow[l], 0, S.flowUbo[l], sizeof(FlowUBO));
wImg(dd, dev, S.sFlow[l], 32, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, pyrB[l].view, samp, GEN);
wImg(dd, dev, S.sFlow[l], 33, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, currLvl, samp, GEN);
wImg(dd, dev, S.sFlow[l], 34, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, flowLvl[pred].view, samp, GEN);
wImg(dd, dev, S.sFlow[l], 48, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, flowLvl[l].view, VK_NULL_HANDLE, GEN);
}
// C1: reduce sets (one per slot) - prev/curr raw luma at kGmLevel + SSBO + GMUBO.
if (gmSsbo) {
for (int s = 0; s < FrameGen::kGmSlots; ++s) {
if (!gmSsbo[s]) continue;
S.sGmReduce[s] = allocSet(dd, dev, pool, pGmReduce.setLayout);
wUbo (dd, dev, S.sGmReduce[s], 1, S.gmUbo[s], sizeof(GMUBO));
wSsbo(dd, dev, S.sGmReduce[s], 16, gmSsbo[s], VK_WHOLE_SIZE);
wImg (dd, dev, S.sGmReduce[s], 32, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, pyrB[FrameGen::kGmLevel].view, samp, GEN); // prev = template
wImg (dd, dev, S.sGmReduce[s], 33, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, pyrA[FrameGen::kGmLevel].view, samp, GEN); // curr = image
}
}
// C1: prewarp sets (one per slot, per solved flow level) - raw curr in, stabilized out.
for (int s = 0; s < FrameGen::kGmSlots; ++s) {
S.sGmPrewarp[s].assign(kLevels, VK_NULL_HANDLE);
for (int l = fg->flowFinest(); l < kLevels; ++l) {
S.sGmPrewarp[s][l] = allocSet(dd, dev, pool, pGmPrewarp.setLayout);
wUbo(dd, dev, S.sGmPrewarp[s][l], 1, S.gmUbo[s], sizeof(GMUBO));
wImg(dd, dev, S.sGmPrewarp[s][l], 32, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, pyrA[l].view, samp, GEN);
wImg(dd, dev, S.sGmPrewarp[s][l], 48, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, pyrAs[l].view, VK_NULL_HANDLE, GEN);
}
}
// expand sets (one per slot): flow inputs fixed; binding 1 = that slot's GMUBO.
for (int s = 0; s < FrameGen::kGmSlots; ++s) {
S.sExpand[s] = allocSet(dd, dev, pool, pExpand.setLayout);
wUbo(dd, dev, S.sExpand[s], 0, S.expandUbo, sizeof(FlowUBO));
wUbo(dd, dev, S.sExpand[s], 1, S.gmUbo[s], sizeof(GMUBO));
wImg(dd, dev, S.sExpand[s], 32, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, flowLvl[fg->flowFinest()].view, samp, GEN);
wImg(dd, dev, S.sExpand[s], 48, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, expA.view, VK_NULL_HANDLE, GEN);
wImg(dd, dev, S.sExpand[s], 49, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, expB.view, VK_NULL_HANDLE, GEN);
}
// C2: flow-reg sets. F = kFlowFinest. f0 (binding 33) = flowLvl_[F] in all; luma
// (binding 34) = prev luma at F (pyrB) for the edge-aware weight. u_in (32) and
// u_out (48) alternate to realize the ping-pong (see ScratchState comment).
{
const int F = fg->flowFinest();
S.sFlowReg0 = allocSet(dd, dev, pool, pFlowReg.setLayout);
S.sFlowRegAB = allocSet(dd, dev, pool, pFlowReg.setLayout);
S.sFlowRegBA = allocSet(dd, dev, pool, pFlowReg.setLayout);
VkDescriptorSet all3[3] = {S.sFlowReg0, S.sFlowRegAB, S.sFlowRegBA};
for (VkDescriptorSet s : all3) {
wUbo(dd, dev, s, 0, S.flowRegUbo, sizeof(FlowRegUBO));
wImg(dd, dev, s, 33, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, flowLvl[F].view, samp, GEN); // f0
wImg(dd, dev, s, 34, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, pyrB[F].view, samp, GEN); // luma
}
// iter0: in=flowLvl_[F] (=f0), out=A
wImg(dd, dev, S.sFlowReg0, 32, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, flowLvl[F].view, samp, GEN);
wImg(dd, dev, S.sFlowReg0, 48, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, flowRegA.view, VK_NULL_HANDLE, GEN);
// odd iters: in=A, out=B
wImg(dd, dev, S.sFlowRegAB, 32, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, flowRegA.view, samp, GEN);
wImg(dd, dev, S.sFlowRegAB, 48, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, flowRegB.view, VK_NULL_HANDLE, GEN);
// even iters (>0): in=B, out=A
wImg(dd, dev, S.sFlowRegBA, 32, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, flowRegB.view, samp, GEN);
wImg(dd, dev, S.sFlowRegBA, 48, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, flowRegA.view, VK_NULL_HANDLE, GEN);
}
// synth set: external prev/curr/out wired per frame; flow inputs fixed
S.sSynth = allocSet(dd, dev, pool, pSynth.setLayout);
wUbo(dd, dev, S.sSynth, 0, S.synthUbo, sizeof(SynthUBO));
// GENERAL (not SR): these internal flow images stay in GENERAL across the whole
// record() (written as storage by expand, sampled here) - see the discard
// transition at the top of record().
wImg(dd, dev, S.sSynth, 34, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, expA.view, samp, GEN);
wImg(dd, dev, S.sSynth, 35, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, expB.view, samp, GEN);
S.builtFor = ext; S.built = true;
return true;
}
} // namespace winfg
@@ -0,0 +1,123 @@
// win-fg - minimal Vulkan layer dispatch tables.
// Structure follows the public Khronos loader/layer interface and the
// renderdoc "Vulkan layer guide" skeleton (learning references, Apache-2.0 /
// CC-BY). No code from bionic-fg / lsfg / GameScope.
#pragma once
#include <vulkan/vulkan.h>
#include <vulkan/vk_layer.h>
#include <cstring>
namespace winfg {
// The loader sets the first pointer-sized word of a dispatchable handle to the
// dispatch table pointer; layers key their own maps on that value so that all
// handles sharing a chain resolve to the same table.
static inline void* dispatch_key(void* handle) { return *reinterpret_cast<void**>(handle); }
// Instance-level functions we call from the layer.
struct InstanceDispatch {
PFN_vkGetInstanceProcAddr GetInstanceProcAddr = nullptr;
PFN_vkDestroyInstance DestroyInstance = nullptr;
PFN_vkGetPhysicalDeviceMemoryProperties GetPhysicalDeviceMemoryProperties = nullptr;
PFN_vkGetPhysicalDeviceQueueFamilyProperties GetPhysicalDeviceQueueFamilyProperties = nullptr;
// Device-context logging (affected-device fingerprint). Properties2 is core 1.1;
// may be null on a 1.0 instance - always null-check before calling.
PFN_vkGetPhysicalDeviceProperties GetPhysicalDeviceProperties = nullptr;
PFN_vkGetPhysicalDeviceProperties2 GetPhysicalDeviceProperties2 = nullptr;
// Surface caps - used to clamp the extra-image-headroom request to the surface's
// maxImageCount so the bump never exceeds what the driver can grant.
PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR GetPhysicalDeviceSurfaceCapabilitiesKHR = nullptr;
};
// Device-level functions we call. Populated by walking vkGetDeviceProcAddr on
// the next layer down at device-create time.
struct DeviceDispatch {
PFN_vkGetDeviceProcAddr GetDeviceProcAddr = nullptr;
PFN_vkDestroyDevice DestroyDevice = nullptr;
PFN_vkGetDeviceQueue GetDeviceQueue = nullptr;
PFN_vkQueueSubmit QueueSubmit = nullptr;
// Synchronization2 submit path (core 1.3 + KHR alias). DXVK may use either the
// legacy QueueSubmit or QueueSubmit2/2KHR; both are hooked for the guest-submit
// diagnostic. May be null if the device did not enable them - always null-check.
PFN_vkQueueSubmit2 QueueSubmit2 = nullptr;
PFN_vkQueueSubmit2KHR QueueSubmit2KHR = nullptr;
PFN_vkQueueWaitIdle QueueWaitIdle = nullptr;
PFN_vkDeviceWaitIdle DeviceWaitIdle = nullptr;
// swapchain / present
PFN_vkCreateSwapchainKHR CreateSwapchainKHR = nullptr;
PFN_vkDestroySwapchainKHR DestroySwapchainKHR = nullptr;
PFN_vkGetSwapchainImagesKHR GetSwapchainImagesKHR = nullptr;
PFN_vkAcquireNextImageKHR AcquireNextImageKHR = nullptr;
// Alternate acquire entry (VK_KHR_swapchain 1.1+ / device-group). DXVK may use
// either AcquireNextImageKHR or AcquireNextImage2KHR - both hooked for the
// guest-acquire diagnostic. May be null - always null-check.
PFN_vkAcquireNextImage2KHR AcquireNextImage2KHR = nullptr;
PFN_vkQueuePresentKHR QueuePresentKHR = nullptr;
// resources
PFN_vkCreateImage CreateImage = nullptr;
PFN_vkDestroyImage DestroyImage = nullptr;
PFN_vkCreateImageView CreateImageView = nullptr;
PFN_vkDestroyImageView DestroyImageView = nullptr;
PFN_vkAllocateMemory AllocateMemory = nullptr;
PFN_vkFreeMemory FreeMemory = nullptr;
PFN_vkBindImageMemory BindImageMemory = nullptr;
PFN_vkGetImageMemoryRequirements GetImageMemoryRequirements = nullptr;
PFN_vkCreateBuffer CreateBuffer = nullptr;
PFN_vkDestroyBuffer DestroyBuffer = nullptr;
PFN_vkGetBufferMemoryRequirements GetBufferMemoryRequirements = nullptr;
PFN_vkBindBufferMemory BindBufferMemory = nullptr;
PFN_vkMapMemory MapMemory = nullptr;
PFN_vkUnmapMemory UnmapMemory = nullptr;
PFN_vkCreateSampler CreateSampler = nullptr;
PFN_vkDestroySampler DestroySampler = nullptr;
// pipeline / descriptors
PFN_vkCreateShaderModule CreateShaderModule = nullptr;
PFN_vkDestroyShaderModule DestroyShaderModule = nullptr;
PFN_vkCreateDescriptorSetLayout CreateDescriptorSetLayout = nullptr;
PFN_vkDestroyDescriptorSetLayout DestroyDescriptorSetLayout = nullptr;
PFN_vkCreatePipelineLayout CreatePipelineLayout = nullptr;
PFN_vkDestroyPipelineLayout DestroyPipelineLayout = nullptr;
PFN_vkCreateComputePipelines CreateComputePipelines = nullptr;
PFN_vkDestroyPipeline DestroyPipeline = nullptr;
PFN_vkCreateDescriptorPool CreateDescriptorPool = nullptr;
PFN_vkDestroyDescriptorPool DestroyDescriptorPool = nullptr;
// Frees every set in the pool at once - used by FrameGen::configure() to reclaim
// the old scratch descriptor sets when a perf_preset change forces a live rebuild
// (otherwise repeated preset switches would exhaust the pool). May be null in
// theory; the rebuild path null-checks before calling.
PFN_vkResetDescriptorPool ResetDescriptorPool = nullptr;
PFN_vkAllocateDescriptorSets AllocateDescriptorSets = nullptr;
PFN_vkUpdateDescriptorSets UpdateDescriptorSets = nullptr;
// command recording
PFN_vkCreateCommandPool CreateCommandPool = nullptr;
PFN_vkDestroyCommandPool DestroyCommandPool = nullptr;
PFN_vkAllocateCommandBuffers AllocateCommandBuffers = nullptr;
PFN_vkFreeCommandBuffers FreeCommandBuffers = nullptr;
PFN_vkBeginCommandBuffer BeginCommandBuffer = nullptr;
PFN_vkEndCommandBuffer EndCommandBuffer = nullptr;
PFN_vkCmdBindPipeline CmdBindPipeline = nullptr;
PFN_vkCmdBindDescriptorSets CmdBindDescriptorSets = nullptr;
PFN_vkCmdDispatch CmdDispatch = nullptr;
PFN_vkCmdPipelineBarrier CmdPipelineBarrier = nullptr;
PFN_vkCmdCopyImage CmdCopyImage = nullptr;
PFN_vkCmdCopyImageToBuffer CmdCopyImageToBuffer = nullptr; // capture readback
PFN_vkCmdBlitImage CmdBlitImage = nullptr;
PFN_vkCmdClearColorImage CmdClearColorImage = nullptr;
PFN_vkCreateFence CreateFence = nullptr;
PFN_vkDestroyFence DestroyFence = nullptr;
PFN_vkWaitForFences WaitForFences = nullptr;
PFN_vkResetFences ResetFences = nullptr;
PFN_vkCreateSemaphore CreateSemaphore = nullptr;
PFN_vkDestroySemaphore DestroySemaphore = nullptr;
};
template <typename PFN>
static inline void load(PFN& slot, PFN_vkGetDeviceProcAddr gdpa, VkDevice dev, const char* name) {
slot = reinterpret_cast<PFN>(gdpa(dev, name));
}
} // namespace winfg
@@ -0,0 +1,204 @@
// See winfg_engine.h.
#include "winfg_engine.h"
#include "winfg_vkd.h"
#include "log.hpp"
#include <algorithm>
#include <cstring>
namespace winfg {
namespace {
// 2x: the guest layer synthesises at 0.35, not 0.5 - biased towards prev to
// cut the double-exposure ghost on HUD/text ("iterative bring-up knob" in
// layer.cpp). Kept for parity, since that is the tuning that was proven.
// 3x/4x: evenly spaced; never exercised by the guest layer, so this is the
// new ground native opens up and the first thing to judge by eye.
float alphaFor(uint32_t k, uint32_t n) {
if (n <= 1) return 0.35f;
return (float)(k + 1) / (float)(n + 1);
}
VkImageMemoryBarrier bar(VkImage img, VkImageLayout from, VkImageLayout to,
VkAccessFlags src, VkAccessFlags dst) {
VkImageMemoryBarrier b{};
b.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
b.oldLayout = from; b.newLayout = to;
b.srcAccessMask = src; b.dstAccessMask = dst;
b.srcQueueFamilyIndex = b.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
b.image = img;
b.subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1};
return b;
}
} // namespace
Engine::Engine() = default;
Engine::~Engine() { destroyRing(); fg_.destroy(); }
bool Engine::init(const VkTable& table, VkPhysicalDevice phys, VkDevice dev,
uint32_t queueFamily, VkQueue queue) {
if (!winfgVkdInit(table, dd_, id_)) {
WFG_LOGE("native: dispatch incomplete; frame generation unavailable");
return false;
}
phys_ = phys; dev_ = dev; qf_ = queueFamily; queue_ = queue;
id_.GetPhysicalDeviceMemoryProperties(phys_, &memProps_);
if (!fg_.init(&dd_, &id_, phys_, dev_, qf_, queue_)) {
WFG_LOGE("native: FrameGen::init failed");
unavailable_ = true;
return false;
}
WFG_LOGI("native: chain ready (10 pipelines, embedded shaders)");
return true;
}
void Engine::configure(uint32_t multiplier, int model, int perfPreset, float flowScale) {
cfg_.enabled = true;
cfg_.multiplier = (int)std::max<uint32_t>(2, multiplier);
cfg_.model = (model == 3) ? 3 : 4;
cfg_.perfPreset = std::clamp(perfPreset, 0, 2);
cfg_.flowScale = std::clamp(flowScale, 0.25f, 1.0f);
fg_.configure(cfg_);
}
bool Engine::prepare(uint32_t w, uint32_t h, VkFormat fmt) {
if (unavailable_ || w == 0 || h == 0 || fmt == VK_FORMAT_UNDEFINED) return false;
if (builtW_ == w && builtH_ == h && builtFmt_ == fmt && fg_.valid()) return true;
// onResize rebuilds the pyramids/scratch; our own input ring follows it.
if (!fg_.onResize(VkExtent2D{w, h}, fmt, /*force=*/false)) {
WFG_LOGE("native: onResize %ux%u failed; frame generation unavailable", w, h);
unavailable_ = true;
return false;
}
destroyRing();
for (Slot& s : ring_) {
if (!makeSlot(s, w, h, fmt)) { destroyRing(); unavailable_ = true; return false; }
}
builtW_ = w; builtH_ = h; builtFmt_ = fmt;
history_ = 0; curr_ = 0; frames_ = 0;
WFG_LOGI("native: built %ux%u fmt=%d model=%d preset=%d flow=%.2f",
w, h, (int)fmt, cfg_.model, cfg_.perfPreset, (double)cfg_.flowScale);
return true;
}
uint32_t Engine::plan(uint32_t capacity) const {
if (!valid() || history_ < 2) return 0; // need prev AND curr
const uint32_t want = (uint32_t)std::max(cfg_.multiplier - 1, 0);
return std::min({want, capacity, kMaxGenerations});
}
void Engine::process(VkCommandBuffer cmd, VkImage source, uint32_t w, uint32_t h,
uint32_t /*generations*/) {
if (!valid()) return;
// Rotate: the slot we are about to overwrite is the OLD prev; after the
// copy it is the new curr and the other slot is prev.
curr_ = 1 - curr_;
Slot& dst = ring_[curr_];
// source is GENERAL (composite render pass leaves it there); the slot may
// be in any layout from last use - UNDEFINED is legal as "discard".
VkImageMemoryBarrier pre[2] = {
bar(source, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_SHADER_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT),
bar(dst.img, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
0, VK_ACCESS_TRANSFER_WRITE_BIT),
};
dd_.CmdPipelineBarrier(cmd,
VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, nullptr, 0, nullptr, 2, pre);
VkImageCopy region{};
region.srcSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1};
region.dstSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1};
region.extent = {w, h, 1};
dd_.CmdCopyImage(cmd, source, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
dst.img, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
// source back to GENERAL for the real-frame copy that follows; the new
// curr becomes SHADER_READ_ONLY, which is what the chain samples it as.
VkImageMemoryBarrier post[2] = {
bar(source, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL,
VK_ACCESS_TRANSFER_READ_BIT, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_TRANSFER_READ_BIT),
bar(dst.img, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_SHADER_READ_BIT),
};
dd_.CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_TRANSFER_BIT,
VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT | VK_PIPELINE_STAGE_TRANSFER_BIT,
0, 0, nullptr, 0, nullptr, 2, post);
dst.valid = true;
if (history_ < 2) history_++;
frames_++;
}
void Engine::generateInto(VkCommandBuffer cmd, uint32_t generation, uint32_t count,
VkImage targetImage, VkImageView targetView, uint32_t w, uint32_t h) {
if (!valid() || history_ < 2) return;
const Slot& prev = ring_[1 - curr_];
const Slot& curr = ring_[curr_];
if (!prev.valid || !curr.valid) return;
// The chain writes the output through a STORAGE descriptor in GENERAL.
// The composite ring already keeps its targets in GENERAL; make the
// prior contents' writes visible and take ownership for the compute write.
VkImageMemoryBarrier toWrite = bar(targetImage, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL,
VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_SHADER_READ_BIT, VK_ACCESS_SHADER_WRITE_BIT);
dd_.CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_TRANSFER_BIT | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &toWrite);
// gmSlot indexes the C1 global-motion SSBO read back on the CPU next
// frame; kGmSlots (3) >= our frames in flight (2), so rotating per source
// frame keeps a slot from being read while its reduce is still in flight.
fg_.record(cmd, prev.view, curr.view, targetView, alphaFor(generation, count), gmSlot_);
if (generation + 1 == count) gmSlot_ = (gmSlot_ + 1) % (uint32_t)FrameGen::kGmSlots;
(void)w; (void)h;
}
void Engine::reset() { history_ = 0; frames_ = 0; }
// ---- input ring --------------------------------------------------------------
uint32_t Engine::memType(uint32_t bits, VkMemoryPropertyFlags props) const {
for (uint32_t i = 0; i < memProps_.memoryTypeCount; i++)
if ((bits & (1u << i)) && (memProps_.memoryTypes[i].propertyFlags & props) == props) return i;
return 0;
}
bool Engine::makeSlot(Slot& s, uint32_t w, uint32_t h, VkFormat fmt) {
VkImageCreateInfo ii{VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO};
ii.imageType = VK_IMAGE_TYPE_2D; ii.extent = {w, h, 1};
ii.mipLevels = 1; ii.arrayLayers = 1; ii.format = fmt;
ii.tiling = VK_IMAGE_TILING_OPTIMAL; ii.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
ii.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
ii.samples = VK_SAMPLE_COUNT_1_BIT; ii.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
if (dd_.CreateImage(dev_, &ii, nullptr, &s.img) != VK_SUCCESS) return false;
VkMemoryRequirements req; dd_.GetImageMemoryRequirements(dev_, s.img, &req);
VkMemoryAllocateInfo ai{VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO};
ai.allocationSize = req.size;
ai.memoryTypeIndex = memType(req.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
if (dd_.AllocateMemory(dev_, &ai, nullptr, &s.mem) != VK_SUCCESS) { destroySlot(s); return false; }
dd_.BindImageMemory(dev_, s.img, s.mem, 0);
VkImageViewCreateInfo vi{VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO};
vi.image = s.img; vi.viewType = VK_IMAGE_VIEW_TYPE_2D; vi.format = fmt;
vi.subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1};
if (dd_.CreateImageView(dev_, &vi, nullptr, &s.view) != VK_SUCCESS) { destroySlot(s); return false; }
s.valid = false;
return true;
}
void Engine::destroySlot(Slot& s) {
if (s.view) dd_.DestroyImageView(dev_, s.view, nullptr);
if (s.img) dd_.DestroyImage(dev_, s.img, nullptr);
if (s.mem) dd_.FreeMemory(dev_, s.mem, nullptr);
s = Slot{};
}
void Engine::destroyRing() {
if (dev_ == VK_NULL_HANDLE || !dd_.DeviceWaitIdle) return;
if (ring_[0].img || ring_[1].img) dd_.DeviceWaitIdle(dev_);
destroySlot(ring_[0]); destroySlot(ring_[1]);
history_ = 0;
}
} // namespace winfg
@@ -0,0 +1,102 @@
#pragma once
// ============================================================================
// winfg_engine - win-fg (Bannerlator's own frame generation) running inside
// the compositor, behind the same contract the LSFG engine uses:
//
// prepare(w, h, format) build/rebuild the chain for this size
// plan(capacity) how many frames to generate this time
// process(cmd, source, w, h, gens) take frame N in (becomes "curr")
// generateInto(cmd, k, n, ...) synthesise generated frame k of n
//
// Why this exists: as a guest-side Vulkan layer, win-fg's generated frames
// had to cross Wine -> DRI3 -> our X server -> the compositor, where the
// per-window latest-wins overwrite dropped them before they were ever
// presented - the HUD counted 2x, the panel got 1x. Here the chain runs in the
// compositor's own command stream and its frames are presented directly, on
// the same multi-present path that is device-proven for LSFG Native.
//
// Unlike LSFG this needs nothing from the user: the ten shaders are ours
// (MIT, see LICENSE.win-fg / NOTICE_FIDELITYFX_OPTICALFLOW.md) and embedded.
//
// The chain (framegen.cpp) is used unmodified. Its inputs are two sampled
// rgba8 views (prev, curr) and its output a GENERAL storage view; the guest
// layer transitions curr to SHADER_READ_ONLY before record() and the output
// UNDEFINED -> GENERAL, so we do exactly the same around the same call.
// ============================================================================
#include <cstdint>
#include <vulkan/vulkan.h>
#include "framegen.hpp"
#include "vk_dispatch.hpp"
struct VkTable;
namespace winfg {
// Hard ceiling on generated frames per source frame (2x..4x -> 1..3), matching
// the LSFG engine and the drawer's buttons.
constexpr uint32_t kMaxGenerations = 3;
class Engine {
public:
Engine();
~Engine();
Engine(const Engine&) = delete;
Engine& operator=(const Engine&) = delete;
bool init(const VkTable& table, VkPhysicalDevice phys, VkDevice dev,
uint32_t queueFamily, VkQueue queue);
bool valid() const { return fg_.valid() && !unavailable_; }
bool unavailable() const { return unavailable_; }
// model 3/4, perf preset 0..2, flow scale - the same knobs the drawer
// already exposes for win-fg; they map straight onto winfg::Config.
void configure(uint32_t multiplier, int model, int perfPreset, float flowScale);
bool prepare(uint32_t width, uint32_t height, VkFormat format);
// 0 until there is a previous frame to interpolate from.
uint32_t plan(uint32_t capacity) const;
// Copy the composited frame into the input ring as "curr" (the previous
// one becomes "prev"). `source` must be in GENERAL.
void process(VkCommandBuffer cmd, VkImage source, uint32_t width, uint32_t height,
uint32_t generations);
// Synthesise generated frame `generation` of `count` into the storage view.
// The target must be in GENERAL (the composite ring keeps it there).
void generateInto(VkCommandBuffer cmd, uint32_t generation, uint32_t count,
VkImage targetImage, VkImageView targetView,
uint32_t width, uint32_t height);
void reset();
private:
struct Slot { VkImage img = VK_NULL_HANDLE; VkDeviceMemory mem = VK_NULL_HANDLE;
VkImageView view = VK_NULL_HANDLE; bool valid = false; };
bool makeSlot(Slot& s, uint32_t w, uint32_t h, VkFormat fmt);
void destroySlot(Slot& s);
void destroyRing();
uint32_t memType(uint32_t bits, VkMemoryPropertyFlags props) const;
DeviceDispatch dd_{};
InstanceDispatch id_{};
VkPhysicalDevice phys_ = VK_NULL_HANDLE;
VkDevice dev_ = VK_NULL_HANDLE;
uint32_t qf_ = 0;
VkQueue queue_ = VK_NULL_HANDLE;
VkPhysicalDeviceMemoryProperties memProps_{};
FrameGen fg_;
Config cfg_;
bool unavailable_ = false;
Slot ring_[2];
int curr_ = 0; // index of "curr" in ring_; prev is 1 - curr_
uint32_t history_ = 0; // frames copied so far (need 2)
uint32_t gmSlot_ = 0; // rotates through FrameGen::kGmSlots
uint32_t builtW_ = 0, builtH_ = 0;
VkFormat builtFmt_ = VK_FORMAT_UNDEFINED;
uint64_t frames_ = 0;
};
} // namespace winfg
@@ -0,0 +1,56 @@
// See winfg_vkd.h.
#include "winfg_vkd.h"
#include "../VulkanRendererContext.h"
#include <android/log.h>
bool winfgVkdInit(const VkTable& table, winfg::DeviceDispatch& dd, winfg::InstanceDispatch& id) {
bool ok = true;
#define COPY(dst, fn) \
do { \
dst.fn = table.fn; \
if (!dst.fn) { \
__android_log_print(ANDROID_LOG_ERROR, "WinFgVkd", \
"entry point vk" #fn " did not resolve"); \
ok = false; \
} \
} while (0)
COPY(dd, AllocateDescriptorSets);
COPY(dd, AllocateMemory);
COPY(dd, BindBufferMemory);
COPY(dd, BindImageMemory);
COPY(dd, CmdBindDescriptorSets);
COPY(dd, CmdBindPipeline);
COPY(dd, CmdClearColorImage);
COPY(dd, CmdCopyImage);
COPY(dd, CmdDispatch);
COPY(dd, CmdPipelineBarrier);
COPY(dd, CreateBuffer);
COPY(dd, CreateComputePipelines);
COPY(dd, CreateDescriptorPool);
COPY(dd, CreateDescriptorSetLayout);
COPY(dd, CreateImage);
COPY(dd, CreateImageView);
COPY(dd, CreatePipelineLayout);
COPY(dd, CreateSampler);
COPY(dd, CreateShaderModule);
COPY(dd, DestroyBuffer);
COPY(dd, DestroyDescriptorPool);
COPY(dd, DestroyDescriptorSetLayout);
COPY(dd, DestroyImage);
COPY(dd, DestroyImageView);
COPY(dd, DestroyPipeline);
COPY(dd, DestroyPipelineLayout);
COPY(dd, DestroySampler);
COPY(dd, DestroyShaderModule);
COPY(dd, DeviceWaitIdle);
COPY(dd, FreeMemory);
COPY(dd, GetBufferMemoryRequirements);
COPY(dd, GetImageMemoryRequirements);
COPY(dd, MapMemory);
COPY(dd, ResetDescriptorPool);
COPY(dd, UnmapMemory);
COPY(dd, UpdateDescriptorSets);
COPY(id, GetPhysicalDeviceMemoryProperties);
#undef COPY
return ok;
}
@@ -0,0 +1,19 @@
#pragma once
// ============================================================================
// winfg_vkd - fill win-fg's own dispatch tables from the renderer's VkTable.
//
// win-fg's chain (framegen.cpp / record_impl.inc) was written as a Vulkan
// LAYER and calls through winfg::DeviceDispatch / InstanceDispatch. Inside the
// compositor there is no layer chain to resolve those from, so they are filled
// from the renderer's per-context table instead - the same bridge lsfg_vkd
// provides for the LSFG chain, for the same reason: an adrenotools driver
// shares no global symbols with the system loader.
//
// Only the entry points the chain actually calls are filled (36 device-level
// plus GetPhysicalDeviceMemoryProperties); everything else in the structs
// stays null and is never reached. winfgVkdInit reports a false if any of
// those failed to resolve, so a null is never called mid-frame.
// ============================================================================
#include "vk_dispatch.hpp"
struct VkTable;
bool winfgVkdInit(const VkTable& table, winfg::DeviceDispatch& dd, winfg::InstanceDispatch& id);