mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 20:36:04 +00:00
cleanup (#764)
This commit is contained in:
1 parent
5fd47421f9
commit
aecd2ebe1d
852 files changed
+4844
-46144
No files matched your search
@@ -84,12 +84,11 @@ struct VkTable {
|
||||
PFN_vkCmdSetScissor CmdSetScissor;
|
||||
PFN_vkCmdPipelineBarrier CmdPipelineBarrier;
|
||||
PFN_vkCmdCopyImage CmdCopyImage;
|
||||
PFN_vkCmdBlitImage CmdBlitImage; // frame-gen capture resolution: composite -> swapchain upscale
|
||||
// Compute: the native LSFG chain is 25 compute dispatches.
|
||||
PFN_vkCmdBlitImage CmdBlitImage;
|
||||
|
||||
PFN_vkCmdDispatch CmdDispatch;
|
||||
PFN_vkCreateComputePipelines CreateComputePipelines;
|
||||
PFN_vkUnmapMemory UnmapMemory;
|
||||
// win-fg native: clears its flow scratch, resets its scratch pool on resize.
|
||||
PFN_vkCmdClearColorImage CmdClearColorImage;
|
||||
PFN_vkResetDescriptorPool ResetDescriptorPool;
|
||||
PFN_vkCmdCopyBufferToImage CmdCopyBufferToImage;
|
||||
@@ -125,11 +124,8 @@ struct VkTable {
|
||||
#include <condition_variable>
|
||||
#include <chrono>
|
||||
|
||||
// Renderer-neutral direct-scanout impl (owns the SurfaceControl/AHB state).
|
||||
// Included after SCANOUT_LOG is defined above; its own definition is guarded.
|
||||
#include "../scanout/ScanoutContext.h"
|
||||
|
||||
// Native (compositor-side) LSFG frame generation - capability gate.
|
||||
#include "lsfg/lsfg_probe.h"
|
||||
#include <memory>
|
||||
#include <string>
|
||||
@@ -139,89 +135,83 @@ namespace winfg { class Engine; }
|
||||
|
||||
static constexpr uint32_t MAX_FRAMES_IN_FLIGHT = 2;
|
||||
|
||||
// Push-constant layouts for the spatial-upscaler post passes. The leading vec4
|
||||
// `ndc` matches upscale.vert; the remaining members are read only by the
|
||||
// fragment stage. std430 offsets line up with these C structs.
|
||||
struct SgsrPushConstants { // 36 bytes
|
||||
|
||||
|
||||
|
||||
struct SgsrPushConstants {
|
||||
float ndc[4];
|
||||
float viewportInfo[4]; // xy = 1/inputSize, zw = inputSize px
|
||||
float edgeSharpness; // SGSR EdgeSharpness, from the slider
|
||||
float viewportInfo[4];
|
||||
float edgeSharpness;
|
||||
};
|
||||
struct NisPushConstants { // 36 bytes
|
||||
struct NisPushConstants {
|
||||
float ndc[4];
|
||||
float viewportInfo[4]; // xy = 1/inputSize, zw = inputSize px
|
||||
float sharpness; // NIS sharpness [0..1], from the slider
|
||||
float viewportInfo[4];
|
||||
float sharpness;
|
||||
};
|
||||
struct EasuPushConstants { // 88 bytes
|
||||
struct EasuPushConstants {
|
||||
float ndc[4];
|
||||
uint32_t con0[4], con1[4], con2[4], con3[4];
|
||||
float outW, outH;
|
||||
};
|
||||
struct RcasPushConstants { // 40 bytes
|
||||
struct RcasPushConstants {
|
||||
float ndc[4];
|
||||
uint32_t con[4]; // con.x = bit-packed sharpness
|
||||
uint32_t con[4];
|
||||
float outW, outH;
|
||||
};
|
||||
// Composable post effects (AMD CAS sharpen + fake-HDR). Both lead with vec4 ndc
|
||||
// (offset 0) like the upscaler PCs and stay well under the 88-byte PC range.
|
||||
struct CasPushConstants { // 32 bytes
|
||||
|
||||
|
||||
struct CasPushConstants {
|
||||
float ndc[4];
|
||||
float resolution[2]; // input texture size in px
|
||||
float sharpness; // CAS SHARPNESS term [0..1]
|
||||
float resolution[2];
|
||||
float sharpness;
|
||||
float _pad;
|
||||
};
|
||||
struct HdrPushConstants { // 24 bytes
|
||||
struct HdrPushConstants {
|
||||
float ndc[4];
|
||||
float resolution[2]; // input texture size in px
|
||||
float resolution[2];
|
||||
};
|
||||
// Phase 2 screen effects ported from the GL EffectComposer. Each leads with vec4
|
||||
// ndc (offset 0) like the upscaler PCs and stays well under the 88-byte PC range.
|
||||
struct FxaaPushConstants { // 24 bytes
|
||||
|
||||
|
||||
struct FxaaPushConstants {
|
||||
float ndc[4];
|
||||
float resolution[2]; // input texture size in px
|
||||
float resolution[2];
|
||||
};
|
||||
struct ToonPushConstants { // 24 bytes
|
||||
struct ToonPushConstants {
|
||||
float ndc[4];
|
||||
float resolution[2]; // input texture size in px
|
||||
float resolution[2];
|
||||
};
|
||||
struct ColorPushConstants { // 32 bytes
|
||||
struct ColorPushConstants {
|
||||
float ndc[4];
|
||||
float brightness; // additive [-1,1]
|
||||
float contrast; // [0,2]
|
||||
float gamma; // [0.1,5]
|
||||
float saturation; // [0,2]; 1 = unchanged, 0 = greyscale.
|
||||
// APPENDED last so the three offsets above
|
||||
// stay where color.frag already had them.
|
||||
float brightness;
|
||||
float contrast;
|
||||
float gamma;
|
||||
float saturation;
|
||||
|
||||
|
||||
};
|
||||
struct NtscPushConstants { // 28 bytes
|
||||
struct NtscPushConstants {
|
||||
float ndc[4];
|
||||
float resolution[2]; // screen size in px (TextureSize/resolution)
|
||||
float frameCount; // animated chroma-phase counter
|
||||
float resolution[2];
|
||||
float frameCount;
|
||||
};
|
||||
struct CrtPushConstants { // 24 bytes
|
||||
struct CrtPushConstants {
|
||||
float ndc[4];
|
||||
float resolution[2]; // input texture size in px (unused by shader)
|
||||
float resolution[2];
|
||||
};
|
||||
struct DebandPushConstants { // 28 bytes
|
||||
struct DebandPushConstants {
|
||||
float ndc[4];
|
||||
float resolution[2]; // input texture size in px (layout parity)
|
||||
float strength; // dither amplitude in LSBs (1.0 = +/-1/255)
|
||||
float resolution[2];
|
||||
float strength;
|
||||
};
|
||||
|
||||
class VulkanRendererContext {
|
||||
public:
|
||||
// `lsfgVk11Compat` (experimental) lets the LSFG capability probe accept a
|
||||
// Vulkan 1.1/1.2 device that offers the extensions the chain needs; it has
|
||||
// to be known before vkCreateDevice, hence a constructor argument.
|
||||
VulkanRendererContext(ANativeWindow* window, int cWidth, int cHeight, void* adrenotoolsHandle = nullptr,
|
||||
bool lsfgVk11Compat = false);
|
||||
~VulkanRendererContext();
|
||||
|
||||
void onSurfaceResized(int width, int height);
|
||||
void setTransform(float ox, float oy, float sx, float sy);
|
||||
// #413: game-region clip rect (surface px). Stored and applied as the swapchain scissor in
|
||||
// recordCmdBuf so a FILL/STRETCH game confined to a half (TOP/BOTTOM alignment) can't bleed into
|
||||
// the on-screen-controls half. A full-surface (or w<=0) rect means "no clip" (CENTER).
|
||||
void setClipRegion(int x, int y, int w, int h);
|
||||
void updatePointerPosition(short x, short y);
|
||||
void updateWindowContent(int64_t id, void* pixels, short w, short h, short stride, int x, int y);
|
||||
@@ -241,13 +231,7 @@ public:
|
||||
void scanoutSetBuffer(AHardwareBuffer* ahb, int x, int y, int w, int h, int fenceFd = -1);
|
||||
void scanoutSetCursorImage(void* pixels, short w, short h, short stride);
|
||||
void scanoutSetCursorPos(short x, short y, short hotX, short hotY);
|
||||
// The renderer-neutral scanout implementation. The scanout methods above are
|
||||
// thin forwarders to this (see VulkanRendererScanout.cpp); the cursor render-
|
||||
// thread signalling stays in the forwarders, not in ScanoutContext.
|
||||
ScanoutContext scanout;
|
||||
// Bound to scanout's atomics so the existing JNI ABI (r->scanoutActive /
|
||||
// r->gameFrameDelivered direct member access) keeps compiling against a
|
||||
// single source of truth. Must be declared after `scanout`.
|
||||
std::atomic<bool>& scanoutActive = scanout.scanoutActive;
|
||||
std::atomic<bool>& gameFrameDelivered = scanout.gameFrameDelivered;
|
||||
std::atomic<bool> surfaceDetached{false};
|
||||
@@ -286,47 +270,16 @@ public:
|
||||
void setPresentMode(VkPresentModeKHR mode);
|
||||
std::vector<int> getSupportedPresentModes() const;
|
||||
|
||||
// --- Native LSFG frame generation -------------------------------------
|
||||
// Capability verdict for the compositor-side LSFG engine. Filled at device
|
||||
// creation and completed once the swapchain format is known; read by the
|
||||
// UI (through JNI) to grey the engine out with a reason.
|
||||
const lsfg::Caps& lsfgCaps() const { return lsfgCaps_; }
|
||||
|
||||
// Arm/disarm native LSFG frame generation for this session. Changing the
|
||||
// armed state recreates the swapchain, because the composite path needs
|
||||
// TRANSFER_DST usage and a deeper image queue that a normal session does
|
||||
// not pay for.
|
||||
void setFrameGenArmed(bool armed, int multiplier);
|
||||
bool frameGenArmed() const { return fgArmed_.load(std::memory_order_relaxed); }
|
||||
// Live frame-gen telemetry for the in-game readout:
|
||||
// [0] generations the governor currently trusts
|
||||
// [1] generations actually planned for the last source frame
|
||||
// [2] measured source (real) frames per second
|
||||
// [3] measured presented frames per second
|
||||
// [4] thermal status, -1 when the device gives no signal
|
||||
// [5] GPU milliseconds the chain spends per generated frame, -1 unknown
|
||||
void frameGenStats(float out[6]) const;
|
||||
// Why the selected native frame-gen engine cannot run here, for the UI:
|
||||
// -1 not known yet (caps not probed), 0 fine, 1 this driver lacks what the
|
||||
// engine needs (lsfgCaps().reason says which gate), 2 the engine failed to start.
|
||||
int frameGenProblem() const;
|
||||
// Path to the SPIR-V cache built from the user's Lossless.dll. Setting it
|
||||
// drops any existing engine so the next armed frame rebuilds from it.
|
||||
void setLsfgCachePath(const char* path);
|
||||
// Flow scale (0.25-1.0) and the panel's real refresh rate. The pacer never
|
||||
// generates above the refresh rate.
|
||||
// Experimental: `captureHeight` sizes the composite ring the chain runs on,
|
||||
// the width following the swapchain's aspect, so a phone GPU generates at
|
||||
// game-like resolution and the result is blitted up. 0 = panel;
|
||||
// kFgCaptureGame = the X screen's height (containerHeight), which already
|
||||
// carries the per-game override and render scale; otherwise a pixel height.
|
||||
static constexpr int32_t kFgCaptureGame = -1;
|
||||
void setFrameGenTuning(float flowScale, float refreshHz, int32_t captureHeight = 0);
|
||||
// Which native engine generates: 0 = LSFG (needs the cache built from the
|
||||
// user's Lossless.dll), 1 = win-fg (our own chain, embedded, needs nothing).
|
||||
// Switching drops the other engine so only one ever holds GPU resources.
|
||||
void setFrameGenEngine(int kind);
|
||||
// win-fg only: interpolation model (3/4) and performance preset (0..2).
|
||||
void setWinFgTuning(int model, int perfPreset);
|
||||
|
||||
private:
|
||||
@@ -359,11 +312,9 @@ private:
|
||||
|
||||
ANativeWindow* window;
|
||||
int surfaceWidth, surfaceHeight, containerWidth, containerHeight;
|
||||
// #413 compositor clip rect (surface px). clipRegionW<=0 => disabled (whole swapchain). Written from
|
||||
// the renderer thread (setClipRegion), read from the render thread (recordCmdBuf) -> atomic.
|
||||
std::atomic<int> clipRegionX{0}, clipRegionY{0}, clipRegionW{0}, clipRegionH{0};
|
||||
void* adrenotoolsHandle = nullptr;
|
||||
bool lsfgVk11Compat_ = false; // see the constructor
|
||||
bool lsfgVk11Compat_ = false;
|
||||
int filterMode = 0;
|
||||
bool swapRB = false;
|
||||
float maxAnisotropy = 1.0f;
|
||||
@@ -386,9 +337,6 @@ private:
|
||||
std::vector<VkImageMemoryBarrier> framePreUpload;
|
||||
std::vector<VkImageMemoryBarrier> framePostUpload;
|
||||
|
||||
// [P0] All SurfaceControl / AHardwareBuffer scanout state moved to
|
||||
// ScanoutContext (member `scanout` above). Dead members (lastDst*,
|
||||
// ScanoutPending/scanoutPending*, fnSTSetBackPressure) were dropped.
|
||||
|
||||
std::atomic<int> pointerX{0}, pointerY{0};
|
||||
float sceneOffsetX=0.f, sceneOffsetY=0.f, sceneScaleX=1.f, sceneScaleY=1.f;
|
||||
@@ -428,138 +376,69 @@ private:
|
||||
|
||||
VkPipeline pipeline = VK_NULL_HANDLE;
|
||||
|
||||
// ---- Spatial upscaler (SGSR / FSR1) ----
|
||||
// upscalerMode enum (mirrored by JNI nativeSetUpscaler):
|
||||
// 0 = none (passthrough; current sampler governs scaling)
|
||||
// 1 = linear (rebuild base sampler LINEAR; no shader pass)
|
||||
// 2 = nearest (rebuild base sampler NEAREST; no shader pass)
|
||||
// 3 = sgsr (Snapdragon GSR 1.0; single pass; aspect-fit / letterbox)
|
||||
// 4 = fsr (AMD FSR1 EASU+RCAS; two passes; fill / stretch)
|
||||
// 5 = fsr_fit (AMD FSR1 EASU+RCAS; two passes; aspect-fit / letterbox)
|
||||
// 6 = sharpen (RCAS-only; any resolution; aspect-fit / letterbox)
|
||||
// 7 = nis (NVIDIA Image Scaling NVScaler; single pass; aspect-fit)
|
||||
// 8 = sgsr_quality (SGSR 1 edge-direction variant; single pass; aspect-fit)
|
||||
// Shader upscaling only engages for modes 3-8 AND when the game render
|
||||
// resolution (container) is smaller than the swapchain. Otherwise the
|
||||
// existing direct-to-swapchain path is used unchanged.
|
||||
int upscalerMode = 0;
|
||||
// Independent of upscalerMode: high-quality Lanczos downscale for the
|
||||
// supersampling case (game render res > display res). When enabled and the
|
||||
// render res exceeds the swapchain, replaces the bilinear minify with a
|
||||
// proper downscale pass. Supersampling and the upscale modes are mutually
|
||||
// exclusive in practice (one is render>display, the other render<display).
|
||||
bool hqDownscale = false;
|
||||
|
||||
// Composable post effects, independent of the scaling mode. CAS layers a sharpen
|
||||
// on top of any mode (incl. native res); HDR is a binary fake-HDR. The upscaler
|
||||
// sharpness (RCAS lobe scale / SGSR EdgeSharpness) is driven by its own slider as a
|
||||
// linear 0..1 value: 0 = neutral (no sharpening; the upscale still runs), 1 = max.
|
||||
bool casEnabled = false;
|
||||
int casSharpness = 60; // slider 0..100 -> CAS SHARPNESS
|
||||
int casSharpness = 60;
|
||||
bool hdrEnabled = false;
|
||||
float upscaleSharpness01 = 0.75f; // slider/100; RCAS lobe scale, SGSR edge derived
|
||||
// Debanding: terminal TPDF/IGN dither pass before the 8-bit swapchain quantize.
|
||||
float upscaleSharpness01 = 0.75f;
|
||||
|
||||
bool debandEnabled = false;
|
||||
int debandStrength = 100; // slider 0..200 -> strength/100 LSBs
|
||||
int debandStrength = 100;
|
||||
|
||||
// Phase 2 screen effects (GL EffectComposer parity). FXAA/Toon/CRT/NTSC are
|
||||
// binary; Color is the brightness/contrast/gamma grade (always-applied via the
|
||||
// sliders, no toggle) and is "enabled" only when not at neutral (0,0,1).
|
||||
bool fxaaEnabled = false;
|
||||
bool toonEnabled = false;
|
||||
bool crtEnabled = false;
|
||||
bool ntscEnabled = false;
|
||||
bool colorEnabled = false; // derived: !neutral grade
|
||||
float colorBrightness = 0.0f; // [-1,1] (slider/100, clamped)
|
||||
float colorContrast = 0.0f; // [0,2] (slider/100, clamped)
|
||||
float colorGamma = 1.0f; // [0.1,5]
|
||||
float colorSaturation = 1.0f; // [0,2] (slider/100, clamped)
|
||||
uint32_t ntscFrameCounter = 0; // animates NTSC chroma phase
|
||||
bool colorEnabled = false;
|
||||
float colorBrightness = 0.0f;
|
||||
float colorContrast = 0.0f;
|
||||
float colorGamma = 1.0f;
|
||||
float colorSaturation = 1.0f;
|
||||
uint32_t ntscFrameCounter = 0;
|
||||
|
||||
VkSampler upscaleSampler = VK_NULL_HANDLE; // linear clamp; offscreen/mid input
|
||||
VkSampler upscaleSampler = VK_NULL_HANDLE;
|
||||
|
||||
// === Native LSFG: composite target ring ===================================
|
||||
// Frame generation cannot composite straight into a swapchain image: the
|
||||
// finished frame has to be READABLE (it becomes the next frame's LSFG
|
||||
// input) and generated frames have to be STORAGE-WRITABLE by a compute
|
||||
// dispatch. Android swapchain images are COLOR_ATTACHMENT only, and
|
||||
// storage support on a swapchain format is not something a driver owes us.
|
||||
//
|
||||
// So when frame gen is armed the whole existing recording is redirected at
|
||||
// a composite image we own - format-identical to the swapchain, so every
|
||||
// existing pipeline stays render-pass compatible - and a copy moves it into
|
||||
// the acquired swapchain image at the end. With frame gen off, not one of
|
||||
// these objects is created and the direct-to-swapchain path is untouched.
|
||||
struct CompositeTarget {
|
||||
VkImage img = VK_NULL_HANDLE;
|
||||
VkDeviceMemory mem = VK_NULL_HANDLE;
|
||||
VkImageView view = VK_NULL_HANDLE; // colour attachment + sampled
|
||||
VkImageView storageView = VK_NULL_HANDLE; // compute writes (generate)
|
||||
VkImageView view = VK_NULL_HANDLE;
|
||||
VkImageView storageView = VK_NULL_HANDLE;
|
||||
VkFramebuffer fb = VK_NULL_HANDLE;
|
||||
VkDescriptorSet ds = VK_NULL_HANDLE; // sampled, for later passes
|
||||
VkDescriptorSet ds = VK_NULL_HANDLE;
|
||||
};
|
||||
// Hard ceiling: (max generations + 1) presentable frames per source frame,
|
||||
// times a queue depth of 2, capped so the footprint stays bounded.
|
||||
static constexpr uint32_t kMaxCompositeTargets = 7;
|
||||
|
||||
std::vector<CompositeTarget> compositeTargets;
|
||||
VkRenderPass compositeRenderPass = VK_NULL_HANDLE; // CLEAR -> GENERAL
|
||||
VkRenderPass compositeRenderPass = VK_NULL_HANDLE;
|
||||
uint32_t compositeW = 0, compositeH = 0;
|
||||
uint32_t compositeIndex = 0; // rotates per composite; gives history for free
|
||||
bool compositeArmed = false; // targets exist AND this frame uses them
|
||||
bool swapchainTransferDst = false; // swapchain was created with TRANSFER_DST
|
||||
uint32_t compositeIndex = 0;
|
||||
bool compositeArmed = false;
|
||||
bool swapchainTransferDst = false;
|
||||
|
||||
// Set from the app when the native LSFG engine is selected for this
|
||||
// session. Read on the render thread; false keeps every path as it was.
|
||||
std::atomic<bool> fgArmed_{false};
|
||||
std::atomic<int> fgMultiplier_{0};
|
||||
// Tuning is written by the UI thread and consumed by the render thread, so
|
||||
// it is published through atomics and applied to the engine at the top of
|
||||
// the frame-gen block. The UI thread never touches the engine itself.
|
||||
std::atomic<float> fgFlowScale_{1.0f};
|
||||
std::atomic<float> fgRefreshHz_{0.0f};
|
||||
std::atomic<bool> fgConfigDirty_{true};
|
||||
// Experimental (see setFrameGenTuning): capture height of the composite
|
||||
// ring. 0 = panel resolution, kFgCaptureGame = the X screen's height.
|
||||
std::atomic<int32_t> fgCaptureHeight_{0};
|
||||
// Extent the composite ring should have for the current swapchain and
|
||||
// capture height (width follows the swapchain aspect, both even).
|
||||
void compositeExtentFor(uint32_t& w, uint32_t& h) const;
|
||||
// The extent the scene is rendered at this frame: the composite ring while
|
||||
// frame gen runs on a ring smaller than the swapchain (experimental capture
|
||||
// resolution), otherwise the swapchain. Every full-target pass (the effect
|
||||
// chain, the spatial upscalers, the render-scale downscale) sizes itself by
|
||||
// this, so those keep working below panel resolution and their
|
||||
// intermediates shrink with the ring.
|
||||
VkExtent2D renderExtent() const {
|
||||
if (compositeActive() && (compositeW != swapchainExt.width || compositeH != swapchainExt.height))
|
||||
return VkExtent2D{compositeW, compositeH};
|
||||
return swapchainExt;
|
||||
}
|
||||
// Copy (same extent) or blit (composite smaller than the swapchain) a
|
||||
// composite-ring image, already in TRANSFER_SRC, into a swapchain image
|
||||
// already in TRANSFER_DST.
|
||||
void recordCompositeToSwapchainTransfer(VkCommandBuffer cb, VkImage src, uint32_t imgIdx);
|
||||
|
||||
bool createCompositeRenderPass();
|
||||
bool ensureCompositeTargets(uint32_t w, uint32_t h, uint32_t count);
|
||||
void destroyCompositeTargets();
|
||||
// True when this frame should composite off-swapchain. Call on the render
|
||||
// thread; every gate must hold or we fall back to the untouched path.
|
||||
bool compositeActive() const;
|
||||
// Render pass / framebuffer this frame draws its FINAL pass into.
|
||||
VkRenderPass targetRenderPass() const;
|
||||
VkFramebuffer targetFramebuffer(uint32_t imgIdx) const;
|
||||
// Copy the finished composite into the acquired swapchain image and leave
|
||||
// it in PRESENT_SRC. No-op when the composite path is not active.
|
||||
void copyCompositeToSwapchain(VkCommandBuffer cb, uint32_t imgIdx);
|
||||
|
||||
// === Native LSFG: the software cursor ====================================
|
||||
// LSFG interpolates whatever it is given, so a cursor composited into the
|
||||
// frame gets warped along the flow field and smears. It is therefore
|
||||
// excluded from the composite while frame gen is armed and drawn once into
|
||||
// EVERY presented image instead - real and generated alike - through a
|
||||
// load-op render pass that leaves the image ready to present.
|
||||
VkRenderPass cursorOverlayRenderPass = VK_NULL_HANDLE;
|
||||
struct CursorOverlay {
|
||||
bool draw = false;
|
||||
@@ -569,19 +448,16 @@ private:
|
||||
CursorOverlay cursorOverlay_{};
|
||||
|
||||
bool createCursorOverlayRenderPass();
|
||||
// Draw the cursor into an already-copied swapchain image and leave it in
|
||||
// PRESENT_SRC. Takes over the final transition from the copy helpers.
|
||||
void recordCursorOverlay(VkCommandBuffer cb, uint32_t imgIdx);
|
||||
// True when the cursor is being drawn per present rather than composited.
|
||||
bool cursorDrawnPerPresent() const;
|
||||
|
||||
// === Native LSFG: the per-source-frame present plan =======================
|
||||
// Interpolation produces frames that belong BETWEEN N-1 and N, so the
|
||||
// generated frames are presented FIRST and real frame N is held back one
|
||||
// slot. All presents for one source frame are queued together: with FIFO
|
||||
// the driver then shows them on consecutive vblanks, so the pacing falls
|
||||
// out of the present mode for free - no sleeps, no render-mode change.
|
||||
static constexpr uint32_t kMaxPresentsPerFrame = 4; // 1 real + up to 3 generated
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static constexpr uint32_t kMaxPresentsPerFrame = 4;
|
||||
struct FrameGenPlan {
|
||||
uint32_t generations = 0;
|
||||
uint32_t presents = 1;
|
||||
@@ -594,30 +470,17 @@ private:
|
||||
bool lsfgEngineTried_ = false;
|
||||
std::unique_ptr<winfg::Engine> winfgEngine_;
|
||||
bool winfgEngineTried_ = false;
|
||||
std::atomic<int> fgEngineKind_{0}; // 0 = lsfg, 1 = win-fg
|
||||
std::atomic<int> fgEngineKind_{0};
|
||||
std::atomic<int> fgModel_{4};
|
||||
std::atomic<int> fgPerfPreset_{1};
|
||||
bool ensureWinFgEngine();
|
||||
// Capability gate for the SELECTED engine. win-fg's shaders need only a
|
||||
// storage-capable swapchain format; the LSFG chain also needs the fp16 /
|
||||
// memory-model feature set, which some otherwise capable GPUs lack.
|
||||
bool fgCapsOk() const;
|
||||
|
||||
// Sync objects are indexed per PRESENT, not per composite: each pending
|
||||
// present needs its own image-available and render-finished semaphore.
|
||||
uint32_t syncSlot(uint32_t k) const { return currentFrame * kMaxPresentsPerFrame + k; }
|
||||
// Destroy and rebuild every acquire/present semaphore. Called with the
|
||||
// swapchain, so no stale pending signal can survive into the new one.
|
||||
void recreateSyncObjects();
|
||||
uint32_t fgAcquireFailLog_ = 0;
|
||||
|
||||
// Measured PRESENTS per second - the rate that actually reaches the panel,
|
||||
// counting generated frames. The pacer's own "loop rate" cannot serve this
|
||||
// purpose: it is sampled once per SOURCE frame, so it always equals the
|
||||
// guest rate and contains no evidence that generation happened at all.
|
||||
float fgPresentedRate_ = 0.0f;
|
||||
// Measured SOURCE frames per second over the same window, for engines that
|
||||
// do not measure it themselves (win-fg).
|
||||
float fgSourceRate_ = 0.0f;
|
||||
uint32_t fgSourceAccum_ = 0;
|
||||
uint32_t fgPresentAccum_ = 0;
|
||||
@@ -626,22 +489,10 @@ private:
|
||||
void trackPresentedRate(uint32_t presents);
|
||||
|
||||
bool ensureLsfgEngine();
|
||||
// One command buffer per pending present: slot 0 carries the composite,
|
||||
// the chain's shared passes and generated frame 0; each later generated
|
||||
// frame and the real frame are recorded and submitted on their own, so a
|
||||
// finished frame reaches the presentation engine without waiting for the
|
||||
// rest of the chain.
|
||||
uint32_t cmdSlot(uint32_t k) const { return currentFrame * kMaxPresentsPerFrame + k; }
|
||||
// Shared chain passes (the 24 shaders every generated frame depends on).
|
||||
void recordFrameGenProcess(VkCommandBuffer cb);
|
||||
// Generated frame g: synthesise into a spare composite target and copy it
|
||||
// into the swapchain image reserved for it.
|
||||
void recordFrameGenGeneration(VkCommandBuffer cb, uint32_t g);
|
||||
|
||||
// Chain cost: a timestamp pair per frame slot, start before the shared
|
||||
// passes, end after the last generation's compute (before its copy, so a
|
||||
// vblank wait on the swapchain image is not counted). Read back after the
|
||||
// slot's fence wait, one frame later.
|
||||
VkQueryPool fgQueryPool_ = VK_NULL_HANDLE;
|
||||
bool fgTimestampsOk_ = false;
|
||||
float fgTimestampPeriodNs_ = 0.0f;
|
||||
@@ -654,22 +505,21 @@ private:
|
||||
void readFgQueryResult();
|
||||
|
||||
VkFormat offscreenFmt = VK_FORMAT_R8G8B8A8_UNORM;
|
||||
VkRenderPass offscreenRenderPass = VK_NULL_HANDLE; // CLEAR -> SHADER_READ_ONLY
|
||||
VkRenderPass offscreenRenderPass = VK_NULL_HANDLE;
|
||||
VkPipelineLayout postPipeLayout = VK_NULL_HANDLE;
|
||||
VkPipeline sgsrPipeline = VK_NULL_HANDLE;
|
||||
VkPipeline nisPipeline = VK_NULL_HANDLE; // NVIDIA Image Scaling (mode 7)
|
||||
VkPipeline sgsrQualityPipeline = VK_NULL_HANDLE; // SGSR 1 edge-direction (mode 8)
|
||||
VkPipeline nisPipeline = VK_NULL_HANDLE;
|
||||
VkPipeline sgsrQualityPipeline = VK_NULL_HANDLE;
|
||||
VkPipeline easuPipeline = VK_NULL_HANDLE;
|
||||
VkPipeline rcasPipeline = VK_NULL_HANDLE;
|
||||
VkPipeline downscalePipeline = VK_NULL_HANDLE;
|
||||
// CAS/HDR can be either a non-final pass (writes an fx target via
|
||||
// offscreenRenderPass) or the final pass (writes the swapchain via renderPass);
|
||||
// a pipeline is render-pass-specific, so keep one variant of each.
|
||||
VkPipeline casPipelineOff = VK_NULL_HANDLE; // -> fx target (offscreenRenderPass)
|
||||
VkPipeline casPipelineSwap = VK_NULL_HANDLE; // -> swapchain (renderPass)
|
||||
|
||||
|
||||
|
||||
VkPipeline casPipelineOff = VK_NULL_HANDLE;
|
||||
VkPipeline casPipelineSwap = VK_NULL_HANDLE;
|
||||
VkPipeline hdrPipelineOff = VK_NULL_HANDLE;
|
||||
VkPipeline hdrPipelineSwap = VK_NULL_HANDLE;
|
||||
// Phase 2 effects: same Off (-> fx target) / Swap (-> swapchain) variant pair.
|
||||
VkPipeline fxaaPipelineOff = VK_NULL_HANDLE;
|
||||
VkPipeline fxaaPipelineSwap = VK_NULL_HANDLE;
|
||||
VkPipeline toonPipelineOff = VK_NULL_HANDLE;
|
||||
@@ -680,10 +530,8 @@ private:
|
||||
VkPipeline ntscPipelineSwap = VK_NULL_HANDLE;
|
||||
VkPipeline crtPipelineOff = VK_NULL_HANDLE;
|
||||
VkPipeline crtPipelineSwap = VK_NULL_HANDLE;
|
||||
// Debanding is always the LAST effect (terminal) -> only a swapchain variant.
|
||||
VkPipeline debandPipelineSwap = VK_NULL_HANDLE;
|
||||
|
||||
// offscreen composite target @ game/container resolution
|
||||
VkImage offscreenImg = VK_NULL_HANDLE;
|
||||
VkDeviceMemory offscreenMem = VK_NULL_HANDLE;
|
||||
VkImageView offscreenView = VK_NULL_HANDLE;
|
||||
@@ -691,7 +539,6 @@ private:
|
||||
VkDescriptorSet offscreenDS = VK_NULL_HANDLE;
|
||||
int offscreenW = 0, offscreenH = 0;
|
||||
|
||||
// FSR intermediate (EASU output) @ upscale output resolution
|
||||
VkImage midImg = VK_NULL_HANDLE;
|
||||
VkDeviceMemory midMem = VK_NULL_HANDLE;
|
||||
VkImageView midView = VK_NULL_HANDLE;
|
||||
@@ -699,8 +546,6 @@ private:
|
||||
VkDescriptorSet midDS = VK_NULL_HANDLE;
|
||||
int midW = 0, midH = 0;
|
||||
|
||||
// Effect-chain intermediates @ swapchain resolution. fx1 holds the scaled (or
|
||||
// composited) image fed into CAS/HDR; fx2 ping-pongs when both effects run.
|
||||
VkImage fx1Img = VK_NULL_HANDLE;
|
||||
VkDeviceMemory fx1Mem = VK_NULL_HANDLE;
|
||||
VkImageView fx1View = VK_NULL_HANDLE;
|
||||
@@ -715,21 +560,18 @@ private:
|
||||
VkDescriptorSet fx2DS = VK_NULL_HANDLE;
|
||||
int fx2W = 0, fx2H = 0;
|
||||
|
||||
// Per-frame upscale plan, computed in renderFrame, consumed by recordCmdBuf.
|
||||
// upFrame.mode reuses the upscalerMode enum (3=sgsr,4=fsr,5=fsr_fit,6=sharpen,7=nis,8=sgsr_quality)
|
||||
// plus an internal sentinel (UPMODE_DOWNSCALE) for the supersampling path.
|
||||
struct UpscaleFrame {
|
||||
bool active = false;
|
||||
int mode = 0;
|
||||
int outX = 0, outY = 0, outW = 0, outH = 0;
|
||||
bool cas = false; // run CAS this frame (snapshot of casEnabled)
|
||||
bool hdr = false; // run HDR this frame (snapshot of hdrEnabled)
|
||||
bool fxaa = false; // snapshot of fxaaEnabled
|
||||
bool toon = false; // snapshot of toonEnabled
|
||||
bool color = false; // snapshot of colorEnabled (non-neutral grade)
|
||||
bool ntsc = false; // snapshot of ntscEnabled
|
||||
bool crt = false; // snapshot of crtEnabled
|
||||
bool deband = false;// snapshot of debandEnabled (terminal dither)
|
||||
bool cas = false;
|
||||
bool hdr = false;
|
||||
bool fxaa = false;
|
||||
bool toon = false;
|
||||
bool color = false;
|
||||
bool ntsc = false;
|
||||
bool crt = false;
|
||||
bool deband = false;
|
||||
SgsrPushConstants sgsrPC{};
|
||||
NisPushConstants nisPC{};
|
||||
EasuPushConstants easuPC{};
|
||||
|
||||
@@ -3,10 +3,6 @@
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2025 lsfg-vk
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
//
|
||||
// LSFG from the work of Camille LaVey / the Eden Emulator Project, following
|
||||
// upstream lsfg-vk. Ported to WinNative and DroidDeck by @maxjivi05; only the
|
||||
// Vulkan dispatch differs here (see lsfg_vkd.h).
|
||||
|
||||
#include "lsfg_alpha.hpp"
|
||||
#include "lsfg_shaders.hpp"
|
||||
|
||||
@@ -3,10 +3,6 @@
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2025 lsfg-vk
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
//
|
||||
// LSFG from the work of Camille LaVey / the Eden Emulator Project, following
|
||||
// upstream lsfg-vk. Ported to WinNative and DroidDeck by @maxjivi05; only the
|
||||
// Vulkan dispatch differs here (see lsfg_vkd.h).
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
@@ -3,10 +3,6 @@
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2025 lsfg-vk
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
//
|
||||
// LSFG from the work of Camille LaVey / the Eden Emulator Project, following
|
||||
// upstream lsfg-vk. Ported to WinNative and DroidDeck by @maxjivi05; only the
|
||||
// Vulkan dispatch differs here (see lsfg_vkd.h).
|
||||
|
||||
#include "lsfg_beta.hpp"
|
||||
#include "lsfg_shaders.hpp"
|
||||
|
||||
@@ -3,10 +3,6 @@
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2025 lsfg-vk
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
//
|
||||
// LSFG from the work of Camille LaVey / the Eden Emulator Project, following
|
||||
// upstream lsfg-vk. Ported to WinNative and DroidDeck by @maxjivi05; only the
|
||||
// Vulkan dispatch differs here (see lsfg_vkd.h).
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
@@ -3,10 +3,6 @@
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2025 lsfg-vk
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
//
|
||||
// LSFG from the work of Camille LaVey / the Eden Emulator Project, following
|
||||
// upstream lsfg-vk. Ported to WinNative and DroidDeck by @maxjivi05; only the
|
||||
// Vulkan dispatch differs here (see lsfg_vkd.h).
|
||||
|
||||
#include "lsfg_chain.hpp"
|
||||
#include "lsfg_shaders.hpp"
|
||||
|
||||
@@ -3,10 +3,6 @@
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2025 lsfg-vk
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
//
|
||||
// LSFG from the work of Camille LaVey / the Eden Emulator Project, following
|
||||
// upstream lsfg-vk. Ported to WinNative and DroidDeck by @maxjivi05; only the
|
||||
// Vulkan dispatch differs here (see lsfg_vkd.h).
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
@@ -3,10 +3,6 @@
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2025 lsfg-vk
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
//
|
||||
// LSFG from the work of Camille LaVey / the Eden Emulator Project, following
|
||||
// upstream lsfg-vk. Ported to WinNative and DroidDeck by @maxjivi05; only the
|
||||
// Vulkan dispatch differs here (see lsfg_vkd.h).
|
||||
|
||||
#include "lsfg_common.hpp"
|
||||
#include "lsfg_shaders.hpp"
|
||||
|
||||
@@ -3,10 +3,6 @@
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2025 lsfg-vk
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
//
|
||||
// LSFG from the work of Camille LaVey / the Eden Emulator Project, following
|
||||
// upstream lsfg-vk. Ported to WinNative and DroidDeck by @maxjivi05; only the
|
||||
// Vulkan dispatch differs here (see lsfg_vkd.h).
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
@@ -3,10 +3,6 @@
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2025 lsfg-vk
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
//
|
||||
// LSFG from the work of Camille LaVey / the Eden Emulator Project, following
|
||||
// upstream lsfg-vk. Ported to WinNative and DroidDeck by @maxjivi05; only the
|
||||
// Vulkan dispatch differs here (see lsfg_vkd.h).
|
||||
|
||||
#include "lsfg_delta.hpp"
|
||||
#include "lsfg_shaders.hpp"
|
||||
|
||||
@@ -3,10 +3,6 @@
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2025 lsfg-vk
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
//
|
||||
// LSFG from the work of Camille LaVey / the Eden Emulator Project, following
|
||||
// upstream lsfg-vk. Ported to WinNative and DroidDeck by @maxjivi05; only the
|
||||
// Vulkan dispatch differs here (see lsfg_vkd.h).
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
// See lsfg_dll.h. PE resource walk + on-device SPIR-V cache for the Lossless
|
||||
// Scaling frame-generation chain.
|
||||
//
|
||||
// LSFG from the work of Camille LaVey / the Eden Emulator Project, following
|
||||
// upstream lsfg-vk (PancakeTAS). Ported to WinNative (lsfg_dll.c) and DroidDeck
|
||||
// by @maxjivi05. GPL-3.0-or-later.
|
||||
// LSFG from Camille LaVey / the Eden Emulator Project, following upstream lsfg-vk (PancakeTAS).
|
||||
// Ported to WinNative and DroidDeck by @maxjivi05. GPL-3.0-or-later.
|
||||
|
||||
#include "lsfg_dll.h"
|
||||
#include "lsfg_dxbc.h"
|
||||
@@ -25,9 +21,9 @@
|
||||
namespace lsfg {
|
||||
namespace {
|
||||
|
||||
// ---- PE constants ---------------------------------------------------------
|
||||
constexpr uint16_t kDosMagic = 0x5A4Du; // "MZ"
|
||||
constexpr uint32_t kPeSignature = 0x00004550u; // "PE\0\0"
|
||||
|
||||
constexpr uint16_t kDosMagic = 0x5A4Du;
|
||||
constexpr uint32_t kPeSignature = 0x00004550u;
|
||||
constexpr uint16_t kPe32Magic = 0x010Bu;
|
||||
constexpr uint16_t kPe32PlusMagic = 0x020Bu;
|
||||
|
||||
@@ -47,7 +43,6 @@ constexpr size_t kResourceEntrySize = 8u;
|
||||
constexpr uint32_t kResourceSubdirectoryBit = 0x80000000u;
|
||||
constexpr uint32_t kResourceTypeRcData = 10u;
|
||||
|
||||
// ---- SPIR-V constants -----------------------------------------------------
|
||||
constexpr uint32_t kSpirvMagic = 0x07230203u;
|
||||
constexpr size_t kSpirvHeaderWords = 5u;
|
||||
constexpr uint32_t kSpirvWordCountShift = 16u;
|
||||
@@ -64,7 +59,7 @@ constexpr uint32_t kVariantFp32Offset = 98u;
|
||||
constexpr uint32_t kMaxResourceId = 512u;
|
||||
constexpr size_t kMaxSpirvWords = 16u * 1024u * 1024u;
|
||||
|
||||
constexpr uint32_t kCacheMagic = 0x4C534642u; // "BFSL" little-endian
|
||||
constexpr uint32_t kCacheMagic = 0x4C534642u;
|
||||
constexpr uint32_t kCacheVersion = 1u;
|
||||
|
||||
struct CacheHeader {
|
||||
@@ -83,7 +78,6 @@ struct PeSection {
|
||||
uint32_t rawSize = 0;
|
||||
};
|
||||
|
||||
// Read-only mapping of the DLL. Closes itself; the DLL is never executed.
|
||||
class PeImage {
|
||||
public:
|
||||
~PeImage() { close(); }
|
||||
@@ -168,7 +162,6 @@ private:
|
||||
std::vector<PeSection> sections_;
|
||||
};
|
||||
|
||||
// RCDATA id -> blob, for the ids we care about.
|
||||
struct ResourceTable {
|
||||
const uint8_t* data[kMaxResourceId] = {};
|
||||
uint32_t size[kMaxResourceId] = {};
|
||||
@@ -217,7 +210,6 @@ bool resourceReadLeaf(const PeImage& img, size_t leafOffset,
|
||||
return true;
|
||||
}
|
||||
|
||||
// Walk type -> name -> language and keep the first language of every RCDATA id.
|
||||
bool collectRcData(const PeImage& img, size_t resourceBase, ResourceTable& out) {
|
||||
size_t typeTotal = 0;
|
||||
if (!resourceEntryCount(img, resourceBase, typeTotal)) return false;
|
||||
@@ -256,7 +248,7 @@ bool collectRcData(const PeImage& img, size_t resourceBase, ResourceTable& out)
|
||||
if (!resourceReadLeaf(img, resourceBase + langOffset, blob, blobSize)) continue;
|
||||
out.data[nameId] = blob;
|
||||
out.size[nameId] = blobSize;
|
||||
break; // first language wins
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -289,7 +281,6 @@ DllStatus parseResources(PeImage& img, ResourceTable& table) {
|
||||
return DllStatus::Ok;
|
||||
}
|
||||
|
||||
// ---- SPIR-V adoption (precompiled-variant path) ---------------------------
|
||||
|
||||
bool isSpirvModule(const uint8_t* blob, uint32_t size) {
|
||||
if (!blob || size < kSpirvHeaderWords * sizeof(uint32_t)) return false;
|
||||
@@ -315,9 +306,6 @@ uint32_t lookupDescriptorSet(const std::vector<uint32_t>& w, uint32_t targetId)
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Precompiled blobs are renumbered into set/binding order - that is the
|
||||
// convention they were built with. The DXBC path uses encounter order instead
|
||||
// (see lsfg_dxbc), which is what DXVK's output pairs with. Do not merge them.
|
||||
bool renumberBindingsSetOrder(std::vector<uint32_t>& w) {
|
||||
struct Slot { uint32_t set; uint32_t binding; size_t literalOffset; };
|
||||
std::vector<Slot> slots;
|
||||
@@ -399,8 +387,6 @@ bool writeCache(const std::string& cachePath, const CacheHeader& header, const M
|
||||
if (ok) ok = fsync(fileno(f)) == 0;
|
||||
fclose(f);
|
||||
|
||||
// Temp file + rename, so a failed or interrupted build can never leave a
|
||||
// half-written cache that would later be loaded as if it were complete.
|
||||
if (!ok || rename(tempPath.c_str(), cachePath.c_str()) != 0) {
|
||||
unlink(tempPath.c_str());
|
||||
return false;
|
||||
@@ -416,9 +402,8 @@ bool readCacheHeader(const std::string& cachePath, CacheHeader& out) {
|
||||
return ok && out.magic == kCacheMagic && out.version == kCacheVersion;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
}
|
||||
|
||||
// ---- public API -----------------------------------------------------------
|
||||
|
||||
const std::vector<uint32_t>& shaderIds() {
|
||||
static const std::vector<uint32_t> ids = [] {
|
||||
@@ -584,7 +569,6 @@ DllStatus loadModules(const std::string& cachePath, ModuleSet& outSet) {
|
||||
return status;
|
||||
}
|
||||
|
||||
// ---- SPIR-V version lowering (Vulkan 1.1/1.2 compat) ----------------------
|
||||
|
||||
namespace {
|
||||
|
||||
@@ -593,14 +577,14 @@ constexpr uint32_t kSpirvOpExtInstImport= 11u;
|
||||
constexpr uint32_t kSpirvOpMemoryModel = 14u;
|
||||
constexpr uint32_t kSpirvOpCapability = 17u;
|
||||
|
||||
// Capabilities that are core in the version the translator emits but not in
|
||||
// the versions we lower to.
|
||||
constexpr uint32_t kCapVulkanMemoryModel = 5345u; // core from 1.5
|
||||
constexpr uint32_t kCapVulkanMemoryModelDeviceScope = 5346u; // core from 1.5
|
||||
constexpr uint32_t kCapDemoteToHelperInvocation = 5379u; // core from 1.6
|
||||
|
||||
|
||||
constexpr uint32_t kCapVulkanMemoryModel = 5345u;
|
||||
constexpr uint32_t kCapVulkanMemoryModelDeviceScope = 5346u;
|
||||
constexpr uint32_t kCapDemoteToHelperInvocation = 5379u;
|
||||
|
||||
std::vector<uint32_t> encodeOpExtension(const char* name) {
|
||||
const size_t len = strlen(name) + 1; // incl. NUL
|
||||
const size_t len = strlen(name) + 1;
|
||||
const size_t strWords = (len + 3) / 4;
|
||||
std::vector<uint32_t> ins(1 + strWords, 0u);
|
||||
ins[0] = ((uint32_t)(1 + strWords) << kSpirvWordCountShift) | kSpirvOpExtension;
|
||||
@@ -624,17 +608,13 @@ bool hasOpExtension(const std::vector<uint32_t>& w, const char* name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
}
|
||||
|
||||
bool downgradeSpirv(std::vector<uint32_t>& w, uint32_t targetVersion) {
|
||||
if (w.size() < kSpirvHeaderWords || w[0] != kSpirvMagic) return false;
|
||||
if (targetVersion < kSpirv14) return false;
|
||||
if (w[1] <= targetVersion) return true; // already low enough
|
||||
if (w[1] <= targetVersion) return true;
|
||||
|
||||
// Walk the preamble first and only touch the module once it is known to
|
||||
// be lowerable: note which extension-gated capabilities are declared and
|
||||
// where the capability block ends (OpExtension must follow every
|
||||
// OpCapability and precede OpExtInstImport / OpMemoryModel).
|
||||
bool needMemoryModel = false;
|
||||
size_t insertAt = kSpirvHeaderWords;
|
||||
size_t off = kSpirvHeaderWords;
|
||||
@@ -645,9 +625,6 @@ bool downgradeSpirv(std::vector<uint32_t>& w, uint32_t targetVersion) {
|
||||
if (opcode == kSpirvOpCapability && length >= 2) {
|
||||
const uint32_t cap = w[off + 1];
|
||||
if (cap == kCapVulkanMemoryModel || cap == kCapVulkanMemoryModelDeviceScope) needMemoryModel = true;
|
||||
// Core only in 1.6, and VK_EXT_shader_demote_to_helper_invocation
|
||||
// is never enabled on the compat path: refuse rather than hand the
|
||||
// driver a module that is not legal at the lowered version.
|
||||
if (cap == kCapDemoteToHelperInvocation) return false;
|
||||
insertAt = off + length;
|
||||
} else if (opcode == kSpirvOpExtension) {
|
||||
@@ -659,7 +636,6 @@ bool downgradeSpirv(std::vector<uint32_t>& w, uint32_t targetVersion) {
|
||||
off += length;
|
||||
}
|
||||
|
||||
// 1.5 has the memory model as core; only 1.4 needs it declared.
|
||||
if (targetVersion < kSpirv15 && needMemoryModel
|
||||
&& !hasOpExtension(w, "SPV_KHR_vulkan_memory_model")) {
|
||||
const auto e = encodeOpExtension("SPV_KHR_vulkan_memory_model");
|
||||
@@ -669,4 +645,4 @@ bool downgradeSpirv(std::vector<uint32_t>& w, uint32_t targetVersion) {
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace lsfg
|
||||
}
|
||||
@@ -1,35 +1,7 @@
|
||||
// LSFG from Camille LaVey / the Eden Emulator Project, following upstream lsfg-vk (PancakeTAS).
|
||||
// Ported to WinNative and DroidDeck by @maxjivi05. GPL-3.0-or-later.
|
||||
|
||||
#pragma once
|
||||
// ============================================================================
|
||||
// lsfg_dll - extract the Lossless Scaling frame-generation shader chain from
|
||||
// the user's own Lossless.dll, and cache it on device as SPIR-V.
|
||||
//
|
||||
// The 25 compute shaders that make up LSFG 3.1 are NOT redistributable. They
|
||||
// ship as RCDATA resources inside Lossless.dll from the user's own paid copy
|
||||
// of Lossless Scaling (Steam app 993090). Every implementation - upstream
|
||||
// lsfg-vk, LSFG-Android, eden, WinNative - requires the user to supply their
|
||||
// own DLL and extracts the resources on device. DroidDeck does the same, and
|
||||
// bundles nothing.
|
||||
//
|
||||
// The DLL is mmap'd READ-ONLY and parsed as data. It is never loaded as a
|
||||
// library and never executed.
|
||||
//
|
||||
// Resource layout, measured against real installs:
|
||||
// * The base chain lives at RCDATA ids 255, 256 and 280-302 (25 modules),
|
||||
// and is DXBC. It has always been DXBC.
|
||||
// * Lossless Scaling MAY additionally carry precompiled SPIR-V copies at
|
||||
// base+49 (native fp16) and base+98 (native fp32). No build currently
|
||||
// downloadable from Steam carries them - public buildId 19655272 was
|
||||
// measured with zero SPIR-V anywhere in the 311 MB install - so the DXBC
|
||||
// path is the normal path and the translator is not optional. The SPIR-V
|
||||
// path is kept because it costs nothing and a future build may ship them.
|
||||
//
|
||||
// Both producers fill the same shader-id -> SPIR-V words map, so everything
|
||||
// downstream of this file is source-agnostic.
|
||||
//
|
||||
// LSFG from the work of Camille LaVey / the Eden Emulator Project, following
|
||||
// upstream lsfg-vk (PancakeTAS). Ported to WinNative (lsfg_dll.c) and DroidDeck
|
||||
// by @maxjivi05. GPL-3.0-or-later.
|
||||
// ============================================================================
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
@@ -39,44 +11,37 @@ namespace lsfg {
|
||||
|
||||
enum class DllStatus {
|
||||
Ok = 0,
|
||||
NotInstalled, // no such file / cannot open
|
||||
UnreadableFile, // opens but cannot be mapped or is empty
|
||||
NotInstalled,
|
||||
UnreadableFile,
|
||||
NotPortableExecutable,
|
||||
MissingShaders, // parses, but the base chain is not all there
|
||||
TranslationFailed, // a shader failed DXBC->SPIR-V or SPIR-V adoption
|
||||
CacheUnusable // cache could not be written or read back
|
||||
MissingShaders,
|
||||
TranslationFailed,
|
||||
CacheUnusable
|
||||
};
|
||||
|
||||
// SPIR-V version words. The translator emits 1.6; a Vulkan 1.1 device takes
|
||||
// 1.4 (via VK_KHR_spirv_1_4) and a 1.2 device 1.5. One definition for the
|
||||
// probe, the engine and the shader loader.
|
||||
constexpr uint32_t kSpirv14 = 0x00010400u;
|
||||
constexpr uint32_t kSpirv15 = 0x00010500u;
|
||||
constexpr uint32_t kSpirv16 = 0x00010600u;
|
||||
|
||||
enum class Variant {
|
||||
None = 0,
|
||||
SpirvFp16, // precompiled fp16 blobs at base+49
|
||||
SpirvFp32, // precompiled fp32 blobs at base+98
|
||||
DxbcTranslated // base chain, translated on device (the normal case)
|
||||
SpirvFp16,
|
||||
SpirvFp32,
|
||||
DxbcTranslated
|
||||
};
|
||||
|
||||
// The 25 shader ids that make up the chain.
|
||||
constexpr uint32_t kShaderMipmaps = 255u;
|
||||
constexpr uint32_t kShaderGenerate = 256u;
|
||||
constexpr uint32_t kShaderChainFirst= 280u;
|
||||
constexpr uint32_t kShaderChainLast = 302u;
|
||||
constexpr uint32_t kShaderCount = 25u;
|
||||
|
||||
// Upstream spelling for the two ids the ported chain files refer to by name.
|
||||
// Kept so those files stay byte-close to their upstream form; these alias the
|
||||
// constants above rather than being a second source of truth.
|
||||
constexpr uint32_t LSFG_SHADER_MIPMAPS = kShaderMipmaps;
|
||||
constexpr uint32_t LSFG_SHADER_GENERATE = kShaderGenerate;
|
||||
|
||||
struct Module {
|
||||
uint32_t id = 0;
|
||||
std::vector<uint32_t> words; // SPIR-V
|
||||
std::vector<uint32_t> words;
|
||||
};
|
||||
|
||||
struct ModuleSet {
|
||||
@@ -87,41 +52,19 @@ struct ModuleSet {
|
||||
bool complete() const;
|
||||
};
|
||||
|
||||
// The canonical shader-id list, in dispatch-independent order.
|
||||
const std::vector<uint32_t>& shaderIds();
|
||||
|
||||
const char* statusName(DllStatus s);
|
||||
const char* variantName(Variant v);
|
||||
|
||||
// Does this file look like a usable Lossless.dll? Checks the base chain only,
|
||||
// so a DLL without the SPIR-V variants (i.e. every build on Steam today) is
|
||||
// reported as valid - the translator handles it.
|
||||
DllStatus validateDll(const std::string& dllPath);
|
||||
|
||||
// Parse the DLL, produce all 25 SPIR-V modules, and write them to cachePath
|
||||
// (via temp file + rename, so a failed build cannot leave a half-written
|
||||
// cache behind). Records which producer ran in the cache header.
|
||||
DllStatus buildCache(const std::string& dllPath, const std::string& cachePath, bool preferFp16);
|
||||
|
||||
// Load a previously built cache.
|
||||
DllStatus loadModules(const std::string& cachePath, ModuleSet& outSet);
|
||||
|
||||
// Which producer built an existing cache, without loading the modules.
|
||||
DllStatus cacheVariant(const std::string& cachePath, Variant& outVariant);
|
||||
|
||||
// Experimental Vulkan 1.1 / 1.2 compat: lower a DXBC-translated module's
|
||||
// declared SPIR-V version to `targetVersion` (kSpirv14 or kSpirv15). Below 1.5
|
||||
// the Vulkan memory model is not core, so SPV_KHR_vulkan_memory_model is
|
||||
// declared for it (the device side enables VK_KHR_vulkan_memory_model). The
|
||||
// cache is built without a device in hand, always at the translator's native
|
||||
// 1.6, so this runs at load time against whatever the device can take. A
|
||||
// module already at or below the target is left untouched. Returns false,
|
||||
// leaving the module untouched, for a malformed module, a target below 1.4, or
|
||||
// a module declaring DemoteToHelperInvocation: that capability is core only in
|
||||
// 1.6 and its extension is never enabled on the compat path, so such a module
|
||||
// cannot be made legal here (DXVK emits it for pixel-shader discard only, so
|
||||
// the 25 compute shaders never carry it). Whether the device then accepts the
|
||||
// result is vkCreateShaderModule's / vkCreateComputePipelines' verdict.
|
||||
bool downgradeSpirv(std::vector<uint32_t>& words, uint32_t targetVersion);
|
||||
|
||||
} // namespace lsfg
|
||||
}
|
||||
@@ -1,10 +1,5 @@
|
||||
// See lsfg_dxbc.h. DXBC -> SPIR-V via DXVK's vendored translator.
|
||||
//
|
||||
// Follows upstream lsfg-vk's src/extract/trans.cpp, including its
|
||||
// encounter-order binding renumber. Ported to WinNative (lsfg_dxbc.cpp) and
|
||||
// DroidDeck by @maxjivi05 from the work of Camille LaVey / the Eden Emulator
|
||||
// Project (GPL-3.0-or-later); the translator itself is DXVK's, zlib licensed,
|
||||
// vendored under cpp/thirdparty/dxbc.
|
||||
// Ported to WinNative and DroidDeck by @maxjivi05 from Camille LaVey / the Eden Emulator Project (GPL-3.0-or-later).
|
||||
// DXVK's translator is zlib licensed; vendored under cpp/thirdparty/dxbc.
|
||||
|
||||
#include "lsfg_dxbc.h"
|
||||
|
||||
@@ -21,12 +16,12 @@ namespace {
|
||||
|
||||
struct BindingSlot {
|
||||
uint32_t bindingIndex = 0;
|
||||
uint32_t bindingOffset = 0; // word offset of the Binding literal
|
||||
uint32_t bindingOffset = 0;
|
||||
uint32_t setIndex = 0;
|
||||
uint32_t setOffset = 0;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
}
|
||||
|
||||
bool translateDxbc(const uint8_t* bytecode, uint32_t size, std::vector<uint32_t>& outWords) {
|
||||
outWords.clear();
|
||||
@@ -38,9 +33,6 @@ bool translateDxbc(const uint8_t* bytecode, uint32_t size, std::vector<uint32_t>
|
||||
const dxvk::DxbcModuleInfo info{};
|
||||
auto code = module.compile(info, "CS");
|
||||
|
||||
// Collect the descriptor decorations in the order the Binding
|
||||
// decorations appear. Everything before the first OpFunction is the
|
||||
// decoration block, so the scan stops there.
|
||||
std::vector<BindingSlot> slotsByVarId;
|
||||
std::vector<uint32_t> varIdsInOrder;
|
||||
for (auto ins : code) {
|
||||
@@ -60,7 +52,6 @@ bool translateDxbc(const uint8_t* bytecode, uint32_t size, std::vector<uint32_t>
|
||||
if (ins.opCode() == spv::OpFunction) break;
|
||||
}
|
||||
|
||||
// Renumber to a dense 0..n range, in encounter order.
|
||||
uint32_t next = 0;
|
||||
for (const uint32_t varId : varIdsInOrder) {
|
||||
const BindingSlot& slot = slotsByVarId[varId];
|
||||
@@ -75,11 +66,9 @@ bool translateDxbc(const uint8_t* bytecode, uint32_t size, std::vector<uint32_t>
|
||||
std::memcpy(outWords.data(), code.data(), byteSize);
|
||||
return true;
|
||||
} catch (...) {
|
||||
// DXVK's compiler signals malformed bytecode by throwing. A bad
|
||||
// resource must degrade to "this DLL is unusable", never to a crash.
|
||||
outWords.clear();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace lsfg
|
||||
}
|
||||
@@ -1,39 +1,11 @@
|
||||
#pragma once
|
||||
// ============================================================================
|
||||
// lsfg_dxbc - DXBC -> SPIR-V for the Lossless Scaling shader chain.
|
||||
//
|
||||
// Why this exists at all: the base chain inside Lossless.dll is DXBC, and has
|
||||
// always been DXBC. Lossless Scaling 3.2.2's release note ("Added shaders
|
||||
// intended for use by the lsfg-vk project") describes precompiled SPIR-V
|
||||
// copies at RCDATA base+49 / base+98 - but no build downloadable from Steam
|
||||
// carries them. Measured against the current public build (buildId 19655272,
|
||||
// 2025-08-19; linux_testing byte-identical on depot 993091): the whole 311 MB
|
||||
// install contains zero occurrences of the SPIR-V magic word, and the DLL's
|
||||
// 202 RCDATA entries are all DXBC.
|
||||
//
|
||||
// So a translator is required, not optional. Upstream lsfg-vk reaches the same
|
||||
// conclusion and links DXVK's `dxbc` in src/extract/trans.cpp; we vendor the
|
||||
// same subset (zlib licence) under cpp/thirdparty/dxbc and follow its
|
||||
// trans.cpp step for step.
|
||||
//
|
||||
// The binding renumber here is ENCOUNTER ORDER - the order in which Binding
|
||||
// decorations appear in DXVK's output - which is what DXVK's own layout pairs
|
||||
// with. The precompiled-SPIR-V path in lsfg_dll.cpp uses a set/binding sort
|
||||
// instead, because those blobs were built with that convention. The two must
|
||||
// not be merged.
|
||||
// ============================================================================
|
||||
// DXVK's dxbc subset is zlib licensed; vendored under cpp/thirdparty/dxbc.
|
||||
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
namespace lsfg {
|
||||
|
||||
// Translate one DXBC compute shader to SPIR-V, renumbering descriptor bindings
|
||||
// into a dense 0..n range in encounter order. Returns false (leaving outWords
|
||||
// empty) on any malformed input - DXVK's compiler throws, and everything is
|
||||
// caught here.
|
||||
// Emits DXVK's native SPIR-V 1.6; lowering for a Vulkan 1.1/1.2 device happens
|
||||
// at load time (lsfg_dll.h downgradeSpirv).
|
||||
bool translateDxbc(const uint8_t* bytecode, uint32_t size, std::vector<uint32_t>& outWords);
|
||||
|
||||
} // namespace lsfg
|
||||
}
|
||||
@@ -1,8 +1,3 @@
|
||||
// See lsfg_engine.h.
|
||||
//
|
||||
// LSFG from the work of Camille LaVey / the Eden Emulator Project, following
|
||||
// upstream lsfg-vk. Ported to WinNative (vkr_lsfg.cpp) and DroidDeck by
|
||||
// @maxjivi05, where it runs on gamescope's output in the compositor.
|
||||
|
||||
#include "lsfg_engine.h"
|
||||
|
||||
@@ -21,9 +16,6 @@
|
||||
namespace lsfg {
|
||||
namespace {
|
||||
|
||||
// The chain needs two real frames in its history before anything it produces
|
||||
// is meaningful, and we require the plan to stay warm for a couple of frames
|
||||
// so a single settled sample cannot start generation from garbage.
|
||||
constexpr uint64_t kRequiredFrames = 2;
|
||||
constexpr uint32_t kRecurrenceFrames = 2;
|
||||
constexpr uint64_t kTelemetryInterval = 120;
|
||||
@@ -50,8 +42,6 @@ VkImageMemoryBarrier makeTransition(VkImage image, VkAccessFlags srcAccess,
|
||||
return b;
|
||||
}
|
||||
|
||||
// Copy the just-composited frame into the chain's input ring. `source` is the
|
||||
// composite target, which the composite render pass leaves in GENERAL.
|
||||
void copyPresentedFrame(VkCommandBuffer cmd, VkImage source, LsfgImage& destination,
|
||||
VkExtent2D extent) {
|
||||
const VkImageMemoryBarrier before[] = {
|
||||
@@ -88,7 +78,7 @@ void copyPresentedFrame(VkCommandBuffer cmd, VkImage source, LsfgImage& destinat
|
||||
destination.SetLayout(VK_IMAGE_LAYOUT_GENERAL);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
}
|
||||
|
||||
Engine::Engine() = default;
|
||||
|
||||
@@ -142,9 +132,6 @@ void Engine::setGuestExtent(uint32_t width, uint32_t height) {
|
||||
peakGuestExtent_.height = std::max(peakGuestExtent_.height, height);
|
||||
}
|
||||
|
||||
// The flow pyramid is the expensive part, so its resolution is scaled relative
|
||||
// to the largest guest surface seen: a game running well below panel
|
||||
// resolution does not need a panel-resolution flow field.
|
||||
float Engine::effectiveFlowScale(uint32_t width) const {
|
||||
if (width == 0 || peakGuestExtent_.width == 0) return flowScale_;
|
||||
const float ratio = (float)peakGuestExtent_.width / (float)width;
|
||||
@@ -171,8 +158,6 @@ bool Engine::prepare(uint32_t width, uint32_t height, VkFormat format) {
|
||||
chain_ = std::make_unique<LsfgChain>(device_, *shaders_, VkExtent2D{width, height}, format,
|
||||
scale);
|
||||
if (!chain_->Valid()) {
|
||||
// A device that cannot build the chain reports unsupported once and
|
||||
// stops trying, rather than thrashing allocations every frame.
|
||||
LSFG_LOGW("chain build failed at %ux%u; frame generation unavailable", width, height);
|
||||
chain_.reset();
|
||||
unavailable_ = true;
|
||||
@@ -204,17 +189,9 @@ uint32_t Engine::plan(uint32_t capacity, uint64_t sourceFrames) {
|
||||
|
||||
plan_ = pacer_.Plan(std::min<size_t>(capacity, kMaxGenerations), sourceFrames);
|
||||
|
||||
// The pacer says how many frames FIT in the panel's budget. The governor
|
||||
// says how many this device can actually afford right now - on a handheld
|
||||
// the chain competes with the game for one GPU, so an extra generation has
|
||||
// to prove it improves total output without collapsing the real frame rate.
|
||||
if (governorEnabled_) {
|
||||
const LsfgPacerStats s = pacer_.Stats();
|
||||
governor_.configure((uint32_t)std::min<size_t>(pacer_.MaxGenerations(), kMaxGenerations));
|
||||
// presentedRate_, NOT the pacer's loop rate. The pacer samples its loop
|
||||
// once per SOURCE frame, so its "loop rate" is the guest rate by
|
||||
// construction and can never show that generation added anything - the
|
||||
// governor could not accept a probe on any hardware.
|
||||
plan_.generations = governor_.cap((uint32_t)plan_.generations, s.source_rate,
|
||||
presentedRate_);
|
||||
}
|
||||
@@ -223,12 +200,6 @@ uint32_t Engine::plan(uint32_t capacity, uint64_t sourceFrames) {
|
||||
warmStreak_ = warm_ ? warmStreak_ + 1 : 0;
|
||||
generating_ = warm_ && warmStreak_ >= kRecurrenceFrames && plan_.generations > 0;
|
||||
|
||||
// The ring is only seeded while generating, so the first frame after any
|
||||
// gap - arming, or a pacer discontinuity after a hitch - would interpolate
|
||||
// between this frame and whatever the other slot held when generation last
|
||||
// stopped. That is a visible warp, and it happens every time the engine
|
||||
// starts. Spend this frame filling the ring instead and generate from the
|
||||
// next one, when both slots are genuinely consecutive.
|
||||
primeHistory_ = false;
|
||||
if (generating_ && !historyFresh()) {
|
||||
primeHistory_ = true;
|
||||
@@ -265,11 +236,6 @@ void Engine::process(VkCommandBuffer cmd, VkImage source, uint32_t width, uint32
|
||||
lastCount_ = count;
|
||||
lastGenerations_ = generations;
|
||||
|
||||
// Seeding the input ring is a full-resolution image copy every frame, so it
|
||||
// is NOT free at 100 fps - it was costing real frame rate while producing
|
||||
// nothing. Copy only when generating, on the one priming frame that
|
||||
// precedes generation, or while the governor is warming up towards a
|
||||
// probe - so the ring is populated by the time it is needed.
|
||||
const bool needHistory = generations > 0 || primeHistory_ || followEveryFrame()
|
||||
|| (governorEnabled_ && governor_.wantsHistory());
|
||||
if (needHistory) {
|
||||
@@ -278,13 +244,6 @@ void Engine::process(VkCommandBuffer cmd, VkImage source, uint32_t width, uint32
|
||||
haveCopied_ = true;
|
||||
}
|
||||
|
||||
// The SHARED chain is 24 of the 25 shaders - the whole flow pyramid - and
|
||||
// only `generate` runs per generated frame. Running it while producing
|
||||
// nothing spends almost the entire cost of frame generation for no frames
|
||||
// at all, every frame. That is what pinned the GPU at 100% on device
|
||||
// regardless of the game's own settings, and it fed straight back into the
|
||||
// governor: the chain made the source rate collapse, the governor saw the
|
||||
// collapse and refused to generate, and refusing did not stop the chain.
|
||||
if (warm_ && (generations > 0 || followEveryFrame())) chain_->DispatchShared(cmd, count);
|
||||
}
|
||||
|
||||
@@ -318,4 +277,4 @@ void Engine::reset() {
|
||||
plan_ = {};
|
||||
}
|
||||
|
||||
} // namespace lsfg
|
||||
}
|
||||
@@ -1,25 +1,4 @@
|
||||
#pragma once
|
||||
// ============================================================================
|
||||
// lsfg_engine - the compositor's handle on native LSFG frame generation.
|
||||
//
|
||||
// Owns the shader modules, the interpolation chain and the pacer, and exposes
|
||||
// the small contract the render loop needs:
|
||||
//
|
||||
// prepare(w, h, format) build/rebuild the chain for this size
|
||||
// plan(capacity, sourceFrames) how many frames to generate this time
|
||||
// process(cmd, source, w, h, gens) take frame N in, run the shared chain
|
||||
// generateInto(cmd, g, i, img, view) synthesise generated frame g
|
||||
//
|
||||
// Ordering matters and is not obvious: interpolation produces frames that
|
||||
// belong BETWEEN N-1 and N, so the generated frames are presented FIRST and
|
||||
// the real frame N is held back one slot. That one output interval is the
|
||||
// unavoidable cost of interpolating rather than extrapolating; no placement of
|
||||
// this code changes it.
|
||||
//
|
||||
// LSFG from the work of Camille LaVey / the Eden Emulator Project, following
|
||||
// upstream lsfg-vk. Ported to WinNative (vkr_lsfg.cpp) and DroidDeck by
|
||||
// @maxjivi05, where it runs on gamescope's output in the compositor.
|
||||
// ============================================================================
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
@@ -28,7 +7,7 @@
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
#include "lsfg_common.hpp"
|
||||
#include "lsfg_dll.h" // kSpirv16
|
||||
#include "lsfg_dll.h"
|
||||
#include "lsfg_governor.h"
|
||||
#include "lsfg_pacer.hpp"
|
||||
|
||||
@@ -37,27 +16,16 @@ namespace lsfg {
|
||||
class LsfgShaders;
|
||||
class LsfgChain;
|
||||
|
||||
// Hard ceiling on generated frames per source frame (2x..4x -> 1..3).
|
||||
constexpr uint32_t kMaxGenerations = 3;
|
||||
|
||||
class Engine {
|
||||
public:
|
||||
// Both the constructor and destructor are out-of-line ON PURPOSE. The
|
||||
// shader set and the chain are held by unique_ptr to forward-declared
|
||||
// types, and an inline constructor would make the compiler emit the
|
||||
// exception-cleanup path for those members at every construction site -
|
||||
// which needs the complete types there. Keeping both here confines that to
|
||||
// lsfg_engine.cpp, where the types are complete.
|
||||
Engine();
|
||||
~Engine();
|
||||
|
||||
Engine(const Engine&) = delete;
|
||||
Engine& operator=(const Engine&) = delete;
|
||||
|
||||
// Build the shader modules from a cache produced by lsfg_dll::buildCache.
|
||||
// Returns false if the cache does not yield all 25 modules. `spirvTarget`
|
||||
// is the highest SPIR-V version the device accepts (lsfg_probe.h); the
|
||||
// cached 1.6 modules are lowered to it when it is below that.
|
||||
bool init(VkDevice device, VkPhysicalDevice physicalDevice, const std::string& cachePath,
|
||||
uint32_t spirvTarget = kSpirv16);
|
||||
|
||||
@@ -71,28 +39,18 @@ public:
|
||||
bool needsRebuild(uint32_t width, uint32_t height, VkFormat format) const;
|
||||
bool prepare(uint32_t width, uint32_t height, VkFormat format);
|
||||
|
||||
// How many frames to generate for this source frame. Returns 0 until the
|
||||
// history slots are valid and the rates have settled, so the first frames
|
||||
// after a start or a resize are never interpolated from garbage.
|
||||
uint32_t plan(uint32_t capacity, uint64_t sourceFrames);
|
||||
|
||||
// Take the just-composited frame as LSFG input and run the shared part of
|
||||
// the chain (everything except `generate`). `source` must be in GENERAL.
|
||||
void process(VkCommandBuffer cmd, VkImage source, uint32_t width, uint32_t height,
|
||||
uint32_t generations);
|
||||
|
||||
// Synthesise generated frame `generation` into the given storage image.
|
||||
void generateInto(VkCommandBuffer cmd, uint32_t generation, uint32_t targetIndex,
|
||||
VkImage targetImage, VkImageView targetView,
|
||||
uint32_t width, uint32_t height);
|
||||
|
||||
// What the probe governor currently trusts, and the latest thermal
|
||||
// reading (-1 = no signal). Surfaced for the HUD and diagnostics.
|
||||
uint32_t acceptedGenerations() const { return governor_.accepted(); }
|
||||
int thermalStatus() const { return governor_.thermalStatus(); }
|
||||
float sourceRate() const;
|
||||
// The rate that actually reaches the panel, generated frames included.
|
||||
// Supplied by the renderer, which is the only thing that counts presents.
|
||||
float loopRate() const { return presentedRate_; }
|
||||
void setPresentedRate(float fps) { presentedRate_ = fps; }
|
||||
|
||||
@@ -102,16 +60,8 @@ public:
|
||||
private:
|
||||
float effectiveFlowScale(uint32_t width) const;
|
||||
|
||||
// A generated frame is a blend of the last two REAL frames, so the input
|
||||
// ring - which is two images deep - only holds usable history when the
|
||||
// other slot was filled by the frame immediately before this one. It is
|
||||
// not, every time generation resumes after a pause: the ring is seeded
|
||||
// only while generating, so the slot still carries whatever was there when
|
||||
// generation last stopped.
|
||||
bool historyFresh() const { return haveCopied_ && lastCopiedCount_ + 1 == frameCount_; }
|
||||
|
||||
// With a target rate the pacer plans 0..3 generations frame by frame, so the ring and the
|
||||
// shared chain have to follow every frame it keeps warm, not just the ones that generate.
|
||||
bool followEveryFrame() const { return warm_ && pacer_.Config().target_rate != 0; }
|
||||
|
||||
Device device_{};
|
||||
@@ -120,12 +70,6 @@ private:
|
||||
std::unique_ptr<LsfgChain> chain_;
|
||||
LsfgPacer pacer_;
|
||||
ProbeGovernor governor_;
|
||||
// The governor is OFF by default: the device's own thermal management is
|
||||
// the authority, and a probe loop that can veto the user's setting is not
|
||||
// wanted here. The multiplier is then what was asked for, still clamped by
|
||||
// what the panel can show. Kept behind a flag rather than deleted because
|
||||
// the probe/backoff logic is the right answer for a device WITHOUT decent
|
||||
// native throttling, and this is the only thing that would have to change.
|
||||
bool governorEnabled_ = false;
|
||||
LsfgPlan plan_{};
|
||||
|
||||
@@ -151,4 +95,4 @@ private:
|
||||
bool unavailable_{};
|
||||
};
|
||||
|
||||
} // namespace lsfg
|
||||
}
|
||||
@@ -3,10 +3,6 @@
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2025 lsfg-vk
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
//
|
||||
// LSFG from the work of Camille LaVey / the Eden Emulator Project, following
|
||||
// upstream lsfg-vk. Ported to WinNative and DroidDeck by @maxjivi05; only the
|
||||
// Vulkan dispatch differs here (see lsfg_vkd.h).
|
||||
|
||||
#include "lsfg_gamma.hpp"
|
||||
#include "lsfg_shaders.hpp"
|
||||
|
||||
@@ -3,10 +3,6 @@
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2025 lsfg-vk
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
//
|
||||
// LSFG from the work of Camille LaVey / the Eden Emulator Project, following
|
||||
// upstream lsfg-vk. Ported to WinNative and DroidDeck by @maxjivi05; only the
|
||||
// Vulkan dispatch differs here (see lsfg_vkd.h).
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
@@ -3,10 +3,6 @@
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2025 lsfg-vk
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
//
|
||||
// LSFG from the work of Camille LaVey / the Eden Emulator Project, following
|
||||
// upstream lsfg-vk. Ported to WinNative and DroidDeck by @maxjivi05; only the
|
||||
// Vulkan dispatch differs here (see lsfg_vkd.h).
|
||||
|
||||
#include "lsfg_generate.hpp"
|
||||
#include "lsfg_dll.h"
|
||||
|
||||
@@ -3,10 +3,6 @@
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2025 lsfg-vk
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
//
|
||||
// LSFG from the work of Camille LaVey / the Eden Emulator Project, following
|
||||
// upstream lsfg-vk. Ported to WinNative and DroidDeck by @maxjivi05; only the
|
||||
// Vulkan dispatch differs here (see lsfg_vkd.h).
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// See lsfg_governor.h.
|
||||
|
||||
#include "lsfg_governor.h"
|
||||
|
||||
@@ -12,13 +11,10 @@
|
||||
namespace lsfg {
|
||||
namespace {
|
||||
|
||||
// A probe has to run long enough to survive a single unlucky frame, and the
|
||||
// baseline long enough to be a fair comparison.
|
||||
constexpr float kBaselineSeconds = 2.0f;
|
||||
constexpr float kProbeSeconds = 2.0f;
|
||||
constexpr uint32_t kMinSamples = 30;
|
||||
|
||||
// Keep the extra generation only if it actually paid off.
|
||||
constexpr float kOutputGainRequired = 1.15f;
|
||||
constexpr float kSourceFloor = 0.70f;
|
||||
|
||||
@@ -28,20 +24,20 @@ constexpr uint32_t kBackoffSteps = 4;
|
||||
constexpr float kThermalPollSeconds = 2.0f;
|
||||
constexpr float kThermalDecaySeconds = 1.0f;
|
||||
|
||||
// ADEVICE_THERMAL_STATUS_* from <android/thermal.h>, which is API 30. Resolved
|
||||
// by dlsym so the build keeps working below that and on devices that do not
|
||||
// ship the service; -1 simply means "no thermal signal", never "hot".
|
||||
// Android reports a STATUS, not a temperature - NONE 0, LIGHT 1, MODERATE 2,
|
||||
// SEVERE 3, CRITICAL 4, EMERGENCY 5, SHUTDOWN 6 - so there is no degree value
|
||||
// here to raise. The equivalent of "let it run hotter" is to act on a higher
|
||||
// status, which is what these now do.
|
||||
//
|
||||
// A handheld under a real 3D load sits at SEVERE routinely; blocking there
|
||||
// made the governor refuse on a device that was working exactly as intended.
|
||||
// It now only stops GROWING at SEVERE and only gives frames back at CRITICAL,
|
||||
// leaving the device's own thermal management as the authority.
|
||||
constexpr int kThermalBlock = 4; // CRITICAL: give generations back
|
||||
constexpr int kThermalNoGrowth = 3; // SEVERE: keep what we have, stop probing
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
constexpr int kThermalBlock = 4;
|
||||
constexpr int kThermalNoGrowth = 3;
|
||||
|
||||
using PFN_AThermal_acquireManager = void* (*)();
|
||||
using PFN_AThermal_getCurrentThermalStatus = int (*)(void*);
|
||||
@@ -72,17 +68,12 @@ float phaseSeconds(std::chrono::steady_clock::time_point a,
|
||||
return std::chrono::duration<float>(b - a).count();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
}
|
||||
|
||||
void ProbeGovernor::configure(uint32_t maxGenerations) {
|
||||
if (maxGenerations_ == maxGenerations) return;
|
||||
// Raising the ceiling must NOT throw away what we already know works -
|
||||
// going 2x -> 4x used to reset the accepted level to zero and restart the
|
||||
// whole baseline/probe cycle, so a user raising the multiplier got FEWER
|
||||
// frames. Only clamp down to a ceiling that has actually been lowered.
|
||||
maxGenerations_ = maxGenerations;
|
||||
if (accepted_ > maxGenerations_) accepted_ = maxGenerations_;
|
||||
// Re-measure against the new ceiling, but keep the accepted level.
|
||||
phase_ = Phase::Baseline;
|
||||
havePhaseStart_ = false;
|
||||
sourceAccum_ = loopAccum_ = 0.0f;
|
||||
@@ -132,19 +123,8 @@ uint32_t ProbeGovernor::cap(uint32_t requested, float sourceRate, float loopRate
|
||||
if (!havePhaseStart_) enterBaseline(now);
|
||||
pollThermal(now);
|
||||
|
||||
// Thermal override: at SEVERE and above we stop asking for more and give
|
||||
// generations back, but SLOWLY.
|
||||
//
|
||||
// This runs once per source frame - about forty times a second - so the
|
||||
// previous version's unconditional accepted_-- was not "give one back", it
|
||||
// was "slam to zero in three frames", and its unconditional enterBackoff()
|
||||
// reset the backoff clock every single call, so the backoff could never
|
||||
// expire and the governor could never measure or recover. One decay per
|
||||
// second, and no churn at all once there is nothing left to give back.
|
||||
thermalBlocked_ = thermal_ >= kThermalBlock;
|
||||
if (thermal_ >= kThermalBlock) {
|
||||
// Logged, sparingly. This is a REFUSAL TO EVEN MEASURE, and it was
|
||||
// silent: on device it looked identical to "measured and declined".
|
||||
if ((refusalLog_++ % 600u) == 0u)
|
||||
GOV_LOGI("thermal status %d - not probing (accepted=%u)", thermal_, accepted_);
|
||||
const bool decayDue = !haveThermalDecay_
|
||||
@@ -183,12 +163,10 @@ uint32_t ProbeGovernor::cap(uint32_t requested, float sourceRate, float loopRate
|
||||
sourceAccum_ = loopAccum_ = 0.0f;
|
||||
samples_ = 0;
|
||||
} else {
|
||||
// Also previously silent. "Baseline completed but we did not
|
||||
// probe" is a decision worth seeing in a log.
|
||||
if ((refusalLog_++ % 600u) == 0u)
|
||||
GOV_LOGI("not probing: accepted=%u max=%u requested=%u thermal=%d",
|
||||
accepted_, maxGenerations_, requested, thermal_);
|
||||
enterBaseline(now); // nothing to try; measure again later
|
||||
enterBaseline(now);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -226,12 +204,10 @@ uint32_t ProbeGovernor::cap(uint32_t requested, float sourceRate, float loopRate
|
||||
break;
|
||||
}
|
||||
|
||||
// While probing we allow one more than is currently accepted; otherwise the
|
||||
// accepted level is the ceiling, and the pacer's own answer still applies.
|
||||
const uint32_t allowed = phase_ == Phase::Probing
|
||||
? std::min(accepted_ + 1, maxGenerations_)
|
||||
: accepted_;
|
||||
return std::min(requested, allowed);
|
||||
}
|
||||
|
||||
} // namespace lsfg
|
||||
}
|
||||
@@ -1,29 +1,4 @@
|
||||
#pragma once
|
||||
// ============================================================================
|
||||
// lsfg_governor - decides whether an extra generated frame is actually WORTH
|
||||
// it on this device, right now.
|
||||
//
|
||||
// The ported pacer answers "how many frames fit in the panel's budget". That
|
||||
// is necessary but not sufficient on a handheld: the LSFG chain competes with
|
||||
// the game for the same GPU, so a naive fixed 3x on a GPU-bound title lowers
|
||||
// the real frame rate by more than the generated frames add. The user sees a
|
||||
// higher HUD number and a worse-looking game.
|
||||
//
|
||||
// So the multiplier is treated as a ceiling to earn, not a setting to obey.
|
||||
// The governor starts at 0 generations, periodically PROBES one more, and
|
||||
// keeps it only if the probe measurably paid off:
|
||||
//
|
||||
// * total output rate must improve by at least 1.15x, and
|
||||
// * the real (source) frame rate must not collapse below 0.70x baseline.
|
||||
//
|
||||
// A failed probe reverts immediately and backs off 5s, 15s, 30s, then 60s, so
|
||||
// a device that cannot afford another generation stops being asked.
|
||||
//
|
||||
// Thermals are the second input a phone needs and a desktop does not.
|
||||
// Sustained frame generation is a thermal decision as much as a performance
|
||||
// one, so the governor gives back generations as the device heats and refuses
|
||||
// to probe while it is throttling.
|
||||
// ============================================================================
|
||||
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
@@ -34,22 +9,15 @@ class ProbeGovernor {
|
||||
public:
|
||||
void configure(uint32_t maxGenerations);
|
||||
|
||||
// Cap the pacer's answer. Called once per source frame with the measured
|
||||
// rates; returns the number of generations actually permitted.
|
||||
uint32_t cap(uint32_t requested, float sourceRate, float loopRate);
|
||||
|
||||
void reset();
|
||||
|
||||
uint32_t accepted() const { return accepted_; }
|
||||
bool probing() const { return phase_ == Phase::Probing; }
|
||||
// Whether the chain's input ring needs to be kept fed. Seeding it is a
|
||||
// full-resolution copy every frame, so it is skipped during the long idle
|
||||
// stretches - a backoff, or a thermal block - and resumed during Baseline,
|
||||
// which gives it a couple of seconds to fill before a probe can start.
|
||||
bool wantsHistory() const {
|
||||
return !thermalBlocked_ && phase_ != Phase::Backoff;
|
||||
}
|
||||
// Latest thermal reading, 0 (none) .. 6 (shutdown); -1 when unavailable.
|
||||
int thermalStatus() const { return thermal_; }
|
||||
|
||||
private:
|
||||
@@ -68,11 +36,9 @@ private:
|
||||
Clock::time_point phaseStart_{};
|
||||
bool havePhaseStart_ = false;
|
||||
|
||||
// Rolling means over the current phase window.
|
||||
float sourceAccum_ = 0.0f, loopAccum_ = 0.0f;
|
||||
uint32_t samples_ = 0;
|
||||
|
||||
// What the accepted level achieves, measured during Baseline.
|
||||
float baselineSource_ = 0.0f, baselineLoop_ = 0.0f;
|
||||
bool haveBaseline_ = false;
|
||||
|
||||
@@ -87,4 +53,4 @@ private:
|
||||
bool haveThermalPoll_ = false;
|
||||
};
|
||||
|
||||
} // namespace lsfg
|
||||
}
|
||||
@@ -1,8 +1,3 @@
|
||||
// JNI surface for native LSFG shader-cache management.
|
||||
//
|
||||
// Deliberately free of any renderer handle: extracting the shader chain from
|
||||
// Lossless.dll and caching it is a slow, once-per-DLL operation that the app
|
||||
// runs off the render thread, long before a game launches.
|
||||
|
||||
#include "lsfg_dll.h"
|
||||
|
||||
@@ -20,7 +15,7 @@ std::string toStdString(JNIEnv* env, jstring s) {
|
||||
return out;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jint JNICALL
|
||||
Java_com_droiddeck_launcher_gpu_LsfgNative_nativeValidateDll(JNIEnv* env, jclass, jstring dllPath) {
|
||||
|
||||
@@ -3,10 +3,6 @@
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2025 lsfg-vk
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
//
|
||||
// LSFG from the work of Camille LaVey / the Eden Emulator Project, following
|
||||
// upstream lsfg-vk. Ported to WinNative and DroidDeck by @maxjivi05; only the
|
||||
// Vulkan dispatch differs here (see lsfg_vkd.h).
|
||||
|
||||
#include "lsfg_mipmaps.hpp"
|
||||
#include "lsfg_dll.h"
|
||||
|
||||
@@ -3,10 +3,6 @@
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2025 lsfg-vk
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
//
|
||||
// LSFG from the work of Camille LaVey / the Eden Emulator Project, following
|
||||
// upstream lsfg-vk. Ported to WinNative and DroidDeck by @maxjivi05; only the
|
||||
// Vulkan dispatch differs here (see lsfg_vkd.h).
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
//
|
||||
// LSFG from the work of Camille LaVey / the Eden Emulator Project, following
|
||||
// upstream lsfg-vk. Ported to WinNative and DroidDeck by @maxjivi05; only the
|
||||
// Vulkan dispatch differs here (see lsfg_vkd.h).
|
||||
|
||||
#include "lsfg_pacer.hpp"
|
||||
|
||||
@@ -21,7 +17,6 @@ constexpr float SOURCE_SMOOTHING = 0.15f;
|
||||
constexpr float SOURCE_STALE_SECONDS = 0.5f;
|
||||
constexpr float DISCONTINUITY_SECONDS = 0.25f;
|
||||
constexpr float HEADROOM_EPSILON = 0.02f;
|
||||
// A target is aimed just under, so rounding never puts output past the panel's refresh rate.
|
||||
constexpr float TARGET_MARGIN = 0.1f;
|
||||
constexpr float CREDIT_EPSILON = 1.0e-4f;
|
||||
constexpr float SOURCE_ACCUM_FLOOR = 0.01f;
|
||||
@@ -121,17 +116,6 @@ LsfgPlan LsfgPacer::Plan(size_t capacity, uint64_t source_frames) {
|
||||
if (target_rate > 0.0f) target_rate -= TARGET_MARGIN;
|
||||
|
||||
if (target_rate == 0.0f) {
|
||||
// No explicit target rate: the multiplier is the multiplier, full stop.
|
||||
// The panel-headroom clamp was here briefly and was removed at the
|
||||
// user's decision; this is also upstream's behaviour on this branch.
|
||||
//
|
||||
// What that means above the panel's refresh rate, for the record: the
|
||||
// display cannot show more frames than it refreshes, so under FIFO the
|
||||
// surplus presents queue and the render thread waits on acquire. Nothing
|
||||
// is displayed faster, and the compositor falls behind on guest
|
||||
// deliveries instead. Below the refresh rate - every source at or under
|
||||
// panel/4 - this branch behaves identically with or without the clamp.
|
||||
// To restore it: limit = std::min(ceiling, HeadroomLimit()).
|
||||
output_credit = 0.0f;
|
||||
limit = ceiling;
|
||||
return LsfgPlan{limit, true};
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
//
|
||||
// LSFG from the work of Camille LaVey / the Eden Emulator Project, following
|
||||
// upstream lsfg-vk. Ported to WinNative and DroidDeck by @maxjivi05; only the
|
||||
// Vulkan dispatch differs here (see lsfg_vkd.h).
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// See lsfg_probe.h. Capability gate for native compositor-side LSFG.
|
||||
|
||||
#include "lsfg_probe.h"
|
||||
#include "../VulkanRendererContext.h"
|
||||
@@ -16,7 +15,7 @@ bool hasExtension(const std::vector<VkExtensionProperties>& exts, const char* na
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
}
|
||||
|
||||
FeatureSupport queryFeatures(const VkTable& vk, VkPhysicalDevice pd,
|
||||
const std::vector<VkExtensionProperties>& deviceExtensions,
|
||||
@@ -33,33 +32,21 @@ FeatureSupport queryFeatures(const VkTable& vk, VkPhysicalDevice pd,
|
||||
|
||||
const bool below12 = props.apiVersion < VK_API_VERSION_1_2;
|
||||
if (below12) {
|
||||
// Below 1.2 there is no VkPhysicalDeviceVulkan12Features to chain, and
|
||||
// the SPIR-V 1.6 modules will not load anyway. Unless the experimental
|
||||
// compat path is on AND the driver offers the extensions that make the
|
||||
// chain loadable as SPIR-V 1.4, don't touch the device further:
|
||||
// device creation stays exactly as it is today.
|
||||
if (!allowVk11) return fs;
|
||||
fs.hasSpirv14 = hasExtension(deviceExtensions, VK_KHR_SPIRV_1_4_EXTENSION_NAME);
|
||||
fs.hasFloatControls = hasExtension(deviceExtensions, VK_KHR_SHADER_FLOAT_CONTROLS_EXTENSION_NAME);
|
||||
fs.hasMemoryModelExt = hasExtension(deviceExtensions, VK_KHR_VULKAN_MEMORY_MODEL_EXTENSION_NAME);
|
||||
if (!fs.hasSpirv14 || !fs.hasFloatControls || !fs.hasMemoryModelExt) {
|
||||
// Report what was looked at so explain() can name the gap.
|
||||
fs.queried = true;
|
||||
return fs;
|
||||
}
|
||||
fs.extensionPath = true;
|
||||
fs.spirvTarget = kSpirv14;
|
||||
} else if (!fs.apiAtLeast13 && allowVk11) {
|
||||
// 1.2: SPIR-V 1.5 is core, VulkanMemoryModel is core. Nothing to
|
||||
// enable beyond the features; the modules only need their header
|
||||
// lowered from 1.6 to 1.5. Same experimental gate as the 1.1 path so
|
||||
// a production build keeps rejecting 1.2 exactly as before.
|
||||
fs.extensionPath = true;
|
||||
fs.spirvTarget = kSpirv15;
|
||||
}
|
||||
|
||||
// On 1.2+ the Vulkan12Features struct carries the memory model; below
|
||||
// that the KHR struct does (same sType value, same layout).
|
||||
VkPhysicalDeviceVulkan12Features v12{};
|
||||
v12.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES;
|
||||
VkPhysicalDeviceVulkanMemoryModelFeaturesKHR mm{};
|
||||
@@ -87,7 +74,7 @@ FeatureSupport queryFeatures(const VkTable& vk, VkPhysicalDevice pd,
|
||||
std::vector<const char*> extensionNames(const FeatureSupport& f) {
|
||||
std::vector<const char*> out;
|
||||
if (!f.extensionPath || f.deviceApiVersion >= VK_API_VERSION_1_2) return out;
|
||||
out.push_back(VK_KHR_SHADER_FLOAT_CONTROLS_EXTENSION_NAME); // dependency of spirv_1_4
|
||||
out.push_back(VK_KHR_SHADER_FLOAT_CONTROLS_EXTENSION_NAME);
|
||||
out.push_back(VK_KHR_SPIRV_1_4_EXTENSION_NAME);
|
||||
out.push_back(VK_KHR_VULKAN_MEMORY_MODEL_EXTENSION_NAME);
|
||||
return out;
|
||||
@@ -108,10 +95,6 @@ bool probeStorageFormat(const VkTable& vk, VkPhysicalDevice pd, VkFormat fmt) {
|
||||
VkFormatProperties fp{};
|
||||
vk.GetPhysicalDeviceFormatProperties(pd, fmt, &fp);
|
||||
|
||||
// The composite target is COLOR_ATTACHMENT (effect chain writes it),
|
||||
// SAMPLED (next frame's LSFG input reads it), STORAGE (generate writes it)
|
||||
// and both blit ends (it is copied - or, below panel resolution, blitted -
|
||||
// into the swapchain image).
|
||||
const VkFormatFeatureFlags need =
|
||||
VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT
|
||||
| VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT
|
||||
@@ -163,4 +146,4 @@ void explain(Caps& caps) {
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace lsfg
|
||||
}
|
||||
@@ -1,45 +1,17 @@
|
||||
#pragma once
|
||||
// ============================================================================
|
||||
// lsfg_probe - capability gate for native (compositor-side) LSFG frame
|
||||
// generation.
|
||||
//
|
||||
// The Lossless Scaling chain is 25 compute shaders that DXVK's DXBC translator
|
||||
// emits as SPIR-V 1.6 with OpCapability VulkanMemoryModel and
|
||||
// StorageImageWriteWithoutFormat. Three consequences, all checked here:
|
||||
//
|
||||
// * SPIR-V 1.6 will not load on a Vulkan 1.1 device, so the DEVICE (not just
|
||||
// the instance) must report 1.3+ ... OR, on the experimental Vulkan 1.1
|
||||
// compat path, offer VK_KHR_spirv_1_4 + VK_KHR_vulkan_memory_model so the
|
||||
// same modules can be handed over as SPIR-V 1.4 (see downgradeSpirv in
|
||||
// lsfg_dll.h). The stock Qualcomm driver on Adreno 7xx phones reports
|
||||
// 1.1.128 yet carries every one of those extensions (measured on an
|
||||
// Adreno 710 / HyperOS device with `cmd gpu vkjson`).
|
||||
// * vulkanMemoryModel, shaderStorageImageWriteWithoutFormat and
|
||||
// shaderStorageImageExtendedFormats must be ENABLED at device creation.
|
||||
// Today the renderer enables no features at all, so all three are off.
|
||||
// * `generate` writes into a storage image, and Android swapchain formats
|
||||
// are frequently not storage-capable - so the format is probed separately
|
||||
// once the swapchain has picked one.
|
||||
//
|
||||
// A device failing any gate reports unsupported UP FRONT, with a reason, so
|
||||
// the UI can grey the engine out instead of failing later inside
|
||||
// vkCreateShaderModule or vkCreateComputePipelines.
|
||||
// ============================================================================
|
||||
|
||||
#include <vulkan/vulkan.h>
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
#include "lsfg_dll.h" // kSpirv14/15/16
|
||||
#include "lsfg_dll.h"
|
||||
|
||||
struct VkTable;
|
||||
|
||||
namespace lsfg {
|
||||
|
||||
// Which of the three required features the physical device OFFERS. Queried
|
||||
// before vkCreateDevice; what we actually enable is recorded in Caps below.
|
||||
struct FeatureSupport {
|
||||
bool queried = false; // vkGetPhysicalDeviceFeatures2 resolved
|
||||
bool queried = false;
|
||||
bool apiAtLeast13 = false;
|
||||
bool vulkanMemoryModel = false;
|
||||
bool vulkanMemoryModelDeviceScope= false;
|
||||
@@ -47,65 +19,41 @@ struct FeatureSupport {
|
||||
bool storageImageExtendedFormats = false;
|
||||
uint32_t deviceApiVersion = 0;
|
||||
|
||||
// Experimental Vulkan 1.1 compat: the device is below 1.3 but offers the
|
||||
// extensions that make the chain loadable. When set, the renderer must
|
||||
// enable those extensions at device creation (see extensionNames) and the
|
||||
// modules are downgraded to `spirvTarget` at load.
|
||||
bool extensionPath = false;
|
||||
bool hasSpirv14 = false; // VK_KHR_spirv_1_4
|
||||
bool hasFloatControls = false; // VK_KHR_shader_float_controls (spirv_1_4 depends on it)
|
||||
bool hasMemoryModelExt = false; // VK_KHR_vulkan_memory_model
|
||||
bool hasSpirv14 = false;
|
||||
bool hasFloatControls = false;
|
||||
bool hasMemoryModelExt = false;
|
||||
uint32_t spirvTarget = kSpirv16;
|
||||
|
||||
// Every hard device-level gate passes (format is checked separately).
|
||||
bool deviceGatesPass() const {
|
||||
return queried && (apiAtLeast13 || extensionPath) && vulkanMemoryModel
|
||||
&& storageImageWriteWithoutFormat && storageImageExtendedFormats;
|
||||
}
|
||||
};
|
||||
|
||||
// What was actually enabled + the running verdict. Owned by the renderer.
|
||||
struct Caps {
|
||||
FeatureSupport features;
|
||||
bool featuresEnabled = false; // the chain was passed to vkCreateDevice
|
||||
bool featuresEnabled = false;
|
||||
bool storageOnSwapchainFormat = false;
|
||||
// The swapchain format blits with VK_FILTER_LINEAR (needs
|
||||
// SAMPLED_IMAGE_FILTER_LINEAR on the source). Not a gate: without it the
|
||||
// capture-resolution upscale falls back to NEAREST.
|
||||
bool linearBlitOnSwapchainFormat = false;
|
||||
VkFormat probedFormat = VK_FORMAT_UNDEFINED;
|
||||
char reason[160] = "not probed";
|
||||
|
||||
// The single question the UI and the render path ask.
|
||||
bool supported() const {
|
||||
return featuresEnabled && features.deviceGatesPass() && storageOnSwapchainFormat;
|
||||
}
|
||||
};
|
||||
|
||||
// Ask the physical device which of the required features it offers.
|
||||
// Safe on any driver: if vkGetPhysicalDeviceFeatures2 cannot be resolved, or
|
||||
// the device reports below Vulkan 1.2 and `allowVk11` is false, nothing is
|
||||
// chained and `queried` is left false - the caller then creates the device
|
||||
// exactly as it always has. With `allowVk11`, a 1.1 device is accepted when
|
||||
// `deviceExtensions` lists VK_KHR_spirv_1_4, VK_KHR_shader_float_controls and
|
||||
// VK_KHR_vulkan_memory_model, and the memory-model features are queried
|
||||
// through the KHR struct instead of VkPhysicalDeviceVulkan12Features.
|
||||
FeatureSupport queryFeatures(const VkTable& vk, VkPhysicalDevice pd,
|
||||
const std::vector<VkExtensionProperties>& deviceExtensions,
|
||||
bool allowVk11);
|
||||
|
||||
// The device extensions the extension path needs enabled, in the order they
|
||||
// should be pushed onto VkDeviceCreateInfo. Empty unless extensionPath.
|
||||
std::vector<const char*> extensionNames(const FeatureSupport& f);
|
||||
|
||||
// Probe VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT on the live swapchain format.
|
||||
// `generate` writes into an image of this format via a compute dispatch.
|
||||
bool probeStorageFormat(const VkTable& vk, VkPhysicalDevice pd, VkFormat fmt);
|
||||
|
||||
// Whether the format may be the source of a VK_FILTER_LINEAR blit.
|
||||
bool probeLinearBlit(const VkTable& vk, VkPhysicalDevice pd, VkFormat fmt);
|
||||
|
||||
// Fill caps.reason with the FIRST gate that failed (or "supported").
|
||||
void explain(Caps& caps);
|
||||
|
||||
} // namespace lsfg
|
||||
}
|
||||
@@ -1,9 +1,5 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
//
|
||||
// LSFG from the work of Camille LaVey / the Eden Emulator Project, following
|
||||
// upstream lsfg-vk. Ported to WinNative and DroidDeck by @maxjivi05; only the
|
||||
// Vulkan dispatch differs here (see lsfg_vkd.h).
|
||||
|
||||
#include "lsfg_shaders.hpp"
|
||||
#include "lsfg_common.hpp"
|
||||
@@ -27,12 +23,6 @@ LsfgShaders::LsfgShaders(const Device& device_, const std::string& cache_path,
|
||||
return;
|
||||
}
|
||||
|
||||
// Vulkan 1.1/1.2 compat: the cache is always built at the translator's
|
||||
// native SPIR-V 1.6 (no device exists at import time), so lower each module
|
||||
// to what THIS device accepts. A no-op on 1.3+ devices. Only the
|
||||
// DXBC-translated chain is lowered: downgradeSpirv knows the capabilities
|
||||
// DXVK emits, not whatever a precompiled vendor SPIR-V variant may carry,
|
||||
// and relabelling one of those could hand the driver invalid SPIR-V.
|
||||
uint32_t lowered = 0;
|
||||
for (Module& module : set.modules) {
|
||||
if (module.words.size() > 1 && module.words[1] > spirv_target) {
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
//
|
||||
// LSFG from the work of Camille LaVey / the Eden Emulator Project, following
|
||||
// upstream lsfg-vk. Ported to WinNative and DroidDeck by @maxjivi05; only the
|
||||
// Vulkan dispatch differs here (see lsfg_vkd.h).
|
||||
|
||||
#pragma once
|
||||
|
||||
@@ -20,8 +16,6 @@ class Device;
|
||||
class LsfgShaders {
|
||||
public:
|
||||
LsfgShaders() = default;
|
||||
// `spirv_target` is the highest SPIR-V version the device accepts (see
|
||||
// lsfg_probe.h); cached modules above it are lowered before creation.
|
||||
LsfgShaders(const Device& device, const std::string& cache_path,
|
||||
uint32_t spirv_target = kSpirv16);
|
||||
~LsfgShaders();
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// See lsfg_vkd.h. Fills the chain's dispatch from the renderer's own table.
|
||||
|
||||
#include "lsfg_vkd.h"
|
||||
#include "../VulkanRendererContext.h"
|
||||
|
||||
@@ -1,24 +1,4 @@
|
||||
#pragma once
|
||||
// ============================================================================
|
||||
// lsfg_vkd - the Vulkan entry points the LSFG chain calls, as a single global.
|
||||
//
|
||||
// Two dispatch styles meet here. DroidDeck's compositor resolves Vulkan
|
||||
// through a per-context VkTable (`vk_`), because an adrenotools-loaded driver
|
||||
// lives in an isolated linker namespace and shares no global symbols with the
|
||||
// system loader. The LSFG chain, ported from Eden by way of WinNative, calls
|
||||
// through a file-scope `vkd`. Rather than rewrite ~2,300 lines of proven chain
|
||||
// code to thread a table through every call, this shim exposes exactly the 34
|
||||
// entry points the chain uses and is filled from the renderer's own table when
|
||||
// the chain is created.
|
||||
//
|
||||
// That keeps the ported files close to their upstream form, which matters:
|
||||
// they are the part of this feature that is hardest to review by eye and
|
||||
// easiest to break with a well-meaning edit.
|
||||
//
|
||||
// Single-renderer assumption: there is one Vulkan compositor per process, so
|
||||
// one global table is correct. lsfgVkdInit() is idempotent and simply
|
||||
// overwrites; lsfgVkdReady() reports whether every pointer resolved.
|
||||
// ============================================================================
|
||||
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
@@ -63,8 +43,5 @@ struct LsfgVkDispatch {
|
||||
|
||||
extern LsfgVkDispatch vkd;
|
||||
|
||||
// Fill `vkd` from the renderer's table. Returns false (and leaves the chain
|
||||
// unusable) if any entry point failed to resolve - better to report the engine
|
||||
// unsupported than to call through a null pointer mid-frame.
|
||||
bool lsfgVkdInit(const VkTable& table);
|
||||
bool lsfgVkdReady();
|
||||
@@ -1,6 +1,3 @@
|
||||
// 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>
|
||||
@@ -12,143 +9,110 @@
|
||||
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 enabled = false;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
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 model = 4;
|
||||
int multiplier = 2;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
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.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int perfPreset = 1;
|
||||
float flowScale = 1.0f;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int gmMode = 0;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int frMode = 0;
|
||||
int frIters = 4;
|
||||
float frLambda = 2.0f;
|
||||
float frDt = 0.25f;
|
||||
float frEdge = 8.0f;
|
||||
float frEps = 0.05f;
|
||||
|
||||
float beta = 8.0f;
|
||||
float lambda = 0.6f;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
float epsilon = 0.07f;
|
||||
float photoScale = 7.5f;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
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.
|
||||
int capPatches = 3;
|
||||
int capPatchSize = 256;
|
||||
|
||||
|
||||
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 (perfPreset < 0 || perfPreset > 2) perfPreset = 1;
|
||||
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;
|
||||
@@ -158,7 +122,6 @@ struct Config {
|
||||
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;
|
||||
@@ -176,7 +139,6 @@ 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;
|
||||
@@ -185,19 +147,16 @@ static inline int parse_tristate(const std::string& v, int dflt) {
|
||||
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;
|
||||
@@ -229,7 +188,6 @@ static inline void apply_toml(Config& c, const std::string& path) {
|
||||
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());
|
||||
@@ -240,7 +198,6 @@ static inline void apply_toml(Config& c, const std::string& path) {
|
||||
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) {
|
||||
@@ -255,22 +212,18 @@ static inline void apply_toml(Config& c, const std::string& path) {
|
||||
}
|
||||
}
|
||||
|
||||
// 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;
|
||||
@@ -292,7 +245,6 @@ static inline Config load_config() {
|
||||
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);
|
||||
@@ -303,7 +255,6 @@ static inline Config load_config() {
|
||||
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) {
|
||||
@@ -321,37 +272,24 @@ static inline Config load_config() {
|
||||
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
|
||||
float lin[4];
|
||||
float linT[4];
|
||||
float app[4];
|
||||
float appT[4];
|
||||
};
|
||||
|
||||
// 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
|
||||
float dt;
|
||||
float lambda;
|
||||
float edgeAlpha;
|
||||
float epsTV;
|
||||
};
|
||||
|
||||
} // namespace winfg
|
||||
}
|
||||
@@ -1,5 +1,3 @@
|
||||
// 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>
|
||||
@@ -41,4 +39,4 @@ static inline Blob blob(Shader s) {
|
||||
default: return { nullptr, 0 };
|
||||
}
|
||||
}
|
||||
} } // namespace winfg::embedded
|
||||
} }
|
||||
@@ -1,4 +1,3 @@
|
||||
// win-fg - compute frame-generation engine implementation.
|
||||
#include "framegen.hpp"
|
||||
#include "embedded_shaders.hpp"
|
||||
#include "log.hpp"
|
||||
@@ -49,10 +48,6 @@ void FrameGen::destroyImage(Img& i) {
|
||||
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;
|
||||
@@ -75,8 +70,6 @@ bool FrameGen::makeGmBuffers() {
|
||||
|
||||
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;
|
||||
@@ -101,7 +94,6 @@ void FrameGen::destroyPipe(Pipe& p) {
|
||||
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) {
|
||||
@@ -123,12 +115,11 @@ bool FrameGen::init(const DeviceDispatch* dd, const InstanceDispatch* id,
|
||||
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
|
||||
{VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 16},
|
||||
};
|
||||
VkDescriptorPoolCreateInfo pci{VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO};
|
||||
pci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
|
||||
@@ -141,19 +132,15 @@ bool FrameGen::init(const DeviceDispatch* dd, const InstanceDispatch* id,
|
||||
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;
|
||||
@@ -177,23 +164,19 @@ 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.
|
||||
bool FrameGen::onResize(VkExtent2D extent, VkFormat , bool force) {
|
||||
|
||||
|
||||
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
|
||||
destroyImage(flowRegA_); destroyImage(flowRegB_);
|
||||
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);
|
||||
@@ -203,13 +186,11 @@ bool FrameGen::onResize(VkExtent2D extent, VkFormat /*colorFormat*/, bool force)
|
||||
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;
|
||||
@@ -229,13 +210,6 @@ void FrameGen::barrier(VkCommandBuffer cmd, VkImage img, VkImageLayout from, VkI
|
||||
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;
|
||||
@@ -245,11 +219,11 @@ void FrameGen::destroy() {
|
||||
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
|
||||
destroyImage(flowRegA_); destroyImage(flowRegB_);
|
||||
destroyPipe(pLuma_); destroyPipe(pDown_); destroyPipe(pFlow_); destroyPipe(pFlowM4_);
|
||||
destroyPipe(pExpand_); destroyPipe(pExpandM4_); destroyPipe(pSynth_);
|
||||
destroyPipe(pGmReduce_); destroyPipe(pGmPrewarp_);
|
||||
destroyPipe(pFlowReg_); // C2
|
||||
destroyPipe(pFlowReg_);
|
||||
for (int s = 0; s < kGmSlots; ++s) {
|
||||
if (gmSsboMem_[s]) dd_->UnmapMemory(device_, gmSsboMem_[s]);
|
||||
if (gmSsbo_[s]) dd_->DestroyBuffer(device_, gmSsbo_[s], nullptr);
|
||||
@@ -262,8 +236,6 @@ void FrameGen::destroy() {
|
||||
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"
|
||||
@@ -1,8 +1,3 @@
|
||||
// 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"
|
||||
@@ -14,70 +9,53 @@ 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 constexpr int kGmSlots = 3;
|
||||
static constexpr int kGmLevel = 3;
|
||||
static constexpr int kGmThreads = 512;
|
||||
static constexpr int kGmStride = 32;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static constexpr int kFlowFinestDefault = 2;
|
||||
|
||||
|
||||
|
||||
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)
|
||||
case 0: return 1;
|
||||
case 2: return 3;
|
||||
case 1: default: return kFlowFinestDefault;
|
||||
}
|
||||
}
|
||||
// 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 makeGmBuffers();
|
||||
|
||||
|
||||
|
||||
bool updateGlobalMotion(uint32_t gmSlot, VkExtent2D fullExtent);
|
||||
bool makePipe(Pipe& p, int shaderId,
|
||||
const std::vector<VkDescriptorType>& bindings);
|
||||
@@ -97,55 +75,36 @@ private:
|
||||
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).
|
||||
std::vector<Img> pyrA_, pyrB_;
|
||||
std::vector<Img> pyrAs_;
|
||||
std::vector<Img> flowLvl_;
|
||||
Img flowExpA_, flowExpB_;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
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
|
||||
bool gmHaveEst_ = false;
|
||||
int gmStableCount_ = 0;
|
||||
bool gmEngaged_ = false;
|
||||
float gmLastTransPx_ = 0.0f;
|
||||
unsigned long long gmFrames_ = 0;
|
||||
};
|
||||
|
||||
} // namespace winfg
|
||||
}
|
||||
@@ -1,5 +1,3 @@
|
||||
// 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>
|
||||
@@ -11,10 +9,4 @@
|
||||
#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)
|
||||
@@ -1,57 +1,28 @@
|
||||
// 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 sExpand[winfg::FrameGen::kGmSlots]{};
|
||||
|
||||
|
||||
|
||||
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
|
||||
std::vector<VkDescriptorSet> sGmPrewarp[winfg::FrameGen::kGmSlots];
|
||||
VkExtent2D builtFor{0,0};
|
||||
bool built = false;
|
||||
bool flowInited = false; // flow images laid out once, then persist (temporal predictor)
|
||||
bool flowInited = false;
|
||||
};
|
||||
ScratchState g_scratch; // one swapchain in flight in this first-draft engine
|
||||
ScratchState g_scratch;
|
||||
}
|
||||
|
||||
static bool makeUbo(const winfg::DeviceDispatch* dd, VkDevice dev,
|
||||
@@ -77,7 +48,6 @@ static VkDescriptorSet allocSet(const winfg::DeviceDispatch* dd, VkDevice dev,
|
||||
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;
|
||||
@@ -102,9 +72,6 @@ static void wSsbo(const winfg::DeviceDispatch* dd, VkDevice dev, VkDescriptorSet
|
||||
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) {
|
||||
@@ -112,7 +79,7 @@ static bool cholSolve6(double A[6][6], const double b[6], double x[6]) {
|
||||
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
|
||||
if (s <= 1e-20) return false;
|
||||
L[i][j] = std::sqrt(s);
|
||||
} else {
|
||||
L[i][j] = s / L[j][j];
|
||||
@@ -124,7 +91,6 @@ static bool cholSolve6(double A[6][6], const double b[6], double x[6]) {
|
||||
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];
|
||||
@@ -153,8 +119,6 @@ static void mulAff(const double A[3][3], const double B[3][3], double out[3][3])
|
||||
|
||||
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,
|
||||
@@ -168,11 +132,6 @@ static bool ensureScratch(FrameGen* fg, const DeviceDispatch* dd, VkDevice dev,
|
||||
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);
|
||||
@@ -186,29 +145,20 @@ static void destroyScratch(const DeviceDispatch* dd, VkDevice dev, VkDescriptorP
|
||||
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
|
||||
if (pool && dd->ResetDescriptorPool) dd->ResetDescriptorPool(dev, pool, 0);
|
||||
S = ScratchState{};
|
||||
}
|
||||
|
||||
// ── 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
|
||||
const int maxFinest = kLevels - 2;
|
||||
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)
|
||||
if (want < 1) want = 1;
|
||||
|
||||
const int prevFinest = flowFinest_;
|
||||
flowFinest_ = want;
|
||||
@@ -216,35 +166,27 @@ void FrameGen::configure(const Config& c) {
|
||||
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)
|
||||
if (!live) return;
|
||||
|
||||
// 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))
|
||||
|
||||
|
||||
|
||||
dd_->DeviceWaitIdle(device_);
|
||||
destroyScratch(dd_, device_, descPool_);
|
||||
if (!onResize(extent_, VK_FORMAT_UNDEFINED, 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.
|
||||
if (!gmBuffersReady_ || cfg_.gmMode == 2 ) {
|
||||
|
||||
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;
|
||||
@@ -260,31 +202,25 @@ bool FrameGen::updateGlobalMotion(uint32_t gmSlot, VkExtent2D fullExtent) {
|
||||
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;
|
||||
@@ -297,17 +233,14 @@ bool FrameGen::updateGlobalMotion(uint32_t gmSlot, VkExtent2D fullExtent) {
|
||||
|
||||
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
|
||||
case 1: gmEngaged_ = gmHaveEst_; break;
|
||||
case 2: gmEngaged_ = false; break;
|
||||
default: gmEngaged_ = (gmStableCount_ >= 3); break;
|
||||
}
|
||||
|
||||
// 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
|
||||
gmSlotValid_[gmSlot] = true;
|
||||
|
||||
gmLastTransPx_ = (float)std::sqrt(
|
||||
(gmRun_[4]*fullExtent.width) * (gmRun_[4]*fullExtent.width) +
|
||||
@@ -330,9 +263,7 @@ void FrameGen::record(VkCommandBuffer cmd, VkImageView prevView, VkImageView cur
|
||||
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];
|
||||
@@ -340,10 +271,9 @@ void FrameGen::record(VkCommandBuffer cmd, VkImageView prevView, VkImageView cur
|
||||
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) {
|
||||
@@ -353,12 +283,10 @@ void FrameGen::record(VkCommandBuffer cmd, VkImageView prevView, VkImageView cur
|
||||
}
|
||||
}
|
||||
|
||||
// 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);
|
||||
@@ -372,23 +300,13 @@ void FrameGen::record(VkCommandBuffer cmd, VkImageView prevView, VkImageView cur
|
||||
};
|
||||
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};
|
||||
@@ -406,20 +324,14 @@ void FrameGen::record(VkCommandBuffer cmd, VkImageView prevView, VkImageView cur
|
||||
}
|
||||
}
|
||||
|
||||
// 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);
|
||||
@@ -429,28 +341,15 @@ void FrameGen::record(VkCommandBuffer cmd, VkImageView prevView, VkImageView cur
|
||||
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_;
|
||||
@@ -471,9 +370,6 @@ void FrameGen::record(VkCommandBuffer cmd, VkImageView prevView, VkImageView cur
|
||||
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;
|
||||
@@ -491,7 +387,7 @@ void FrameGen::record(VkCommandBuffer cmd, VkImageView prevView, VkImageView cur
|
||||
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) {
|
||||
@@ -501,14 +397,11 @@ void FrameGen::record(VkCommandBuffer cmd, VkImageView prevView, VkImageView cur
|
||||
}
|
||||
}
|
||||
|
||||
// 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,
|
||||
@@ -528,7 +421,6 @@ static bool ensureScratch(FrameGen* fg, const DeviceDispatch* dd, VkDevice dev,
|
||||
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);
|
||||
@@ -536,19 +428,16 @@ static bool ensureScratch(FrameGen* fg, const DeviceDispatch* dd, VkDevice dev,
|
||||
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);
|
||||
@@ -559,10 +448,6 @@ static bool ensureScratch(FrameGen* fg, const DeviceDispatch* dd, VkDevice dev,
|
||||
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);
|
||||
@@ -575,19 +460,17 @@ static bool ensureScratch(FrameGen* fg, const DeviceDispatch* dd, VkDevice dev,
|
||||
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
|
||||
wImg (dd, dev, S.sGmReduce[s], 32, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, pyrB[FrameGen::kGmLevel].view, samp, GEN);
|
||||
wImg (dd, dev, S.sGmReduce[s], 33, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, pyrA[FrameGen::kGmLevel].view, samp, GEN);
|
||||
}
|
||||
}
|
||||
|
||||
// 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) {
|
||||
@@ -598,7 +481,6 @@ static bool ensureScratch(FrameGen* fg, const DeviceDispatch* dd, VkDevice dev,
|
||||
}
|
||||
}
|
||||
|
||||
// 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));
|
||||
@@ -608,9 +490,6 @@ static bool ensureScratch(FrameGen* fg, const DeviceDispatch* dd, VkDevice dev,
|
||||
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);
|
||||
@@ -619,26 +498,19 @@ static bool ensureScratch(FrameGen* fg, const DeviceDispatch* dd, VkDevice dev,
|
||||
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
|
||||
wImg(dd, dev, s, 33, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, flowLvl[F].view, samp, GEN);
|
||||
wImg(dd, dev, s, 34, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, pyrB[F].view, samp, GEN);
|
||||
}
|
||||
// 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);
|
||||
|
||||
@@ -646,4 +518,4 @@ static bool ensureScratch(FrameGen* fg, const DeviceDispatch* dd, VkDevice dev,
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace winfg
|
||||
}
|
||||
@@ -1,7 +1,3 @@
|
||||
// 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>
|
||||
@@ -9,53 +5,35 @@
|
||||
|
||||
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;
|
||||
@@ -73,7 +51,6 @@ struct DeviceDispatch {
|
||||
PFN_vkCreateSampler CreateSampler = nullptr;
|
||||
PFN_vkDestroySampler DestroySampler = nullptr;
|
||||
|
||||
// pipeline / descriptors
|
||||
PFN_vkCreateShaderModule CreateShaderModule = nullptr;
|
||||
PFN_vkDestroyShaderModule DestroyShaderModule = nullptr;
|
||||
PFN_vkCreateDescriptorSetLayout CreateDescriptorSetLayout = nullptr;
|
||||
@@ -84,15 +61,10 @@ struct DeviceDispatch {
|
||||
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;
|
||||
@@ -104,7 +76,7 @@ struct DeviceDispatch {
|
||||
PFN_vkCmdDispatch CmdDispatch = nullptr;
|
||||
PFN_vkCmdPipelineBarrier CmdPipelineBarrier = nullptr;
|
||||
PFN_vkCmdCopyImage CmdCopyImage = nullptr;
|
||||
PFN_vkCmdCopyImageToBuffer CmdCopyImageToBuffer = nullptr; // capture readback
|
||||
PFN_vkCmdCopyImageToBuffer CmdCopyImageToBuffer = nullptr;
|
||||
PFN_vkCmdBlitImage CmdBlitImage = nullptr;
|
||||
PFN_vkCmdClearColorImage CmdClearColorImage = nullptr;
|
||||
PFN_vkCreateFence CreateFence = nullptr;
|
||||
@@ -120,4 +92,4 @@ static inline void load(PFN& slot, PFN_vkGetDeviceProcAddr gdpa, VkDevice dev, c
|
||||
slot = reinterpret_cast<PFN>(gdpa(dev, name));
|
||||
}
|
||||
|
||||
} // namespace winfg
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
// See winfg_engine.h.
|
||||
#include "winfg_engine.h"
|
||||
#include "winfg_vkd.h"
|
||||
#include "log.hpp"
|
||||
@@ -8,11 +7,6 @@
|
||||
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);
|
||||
@@ -30,7 +24,7 @@ VkImageMemoryBarrier bar(VkImage img, VkImageLayout from, VkImageLayout to,
|
||||
return b;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
}
|
||||
|
||||
Engine::Engine() = default;
|
||||
Engine::~Engine() { destroyRing(); fg_.destroy(); }
|
||||
@@ -65,8 +59,8 @@ 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)) {
|
||||
|
||||
if (!fg_.onResize(VkExtent2D{w, h}, fmt, false)) {
|
||||
WFG_LOGE("native: onResize %ux%u failed; frame generation unavailable", w, h);
|
||||
unavailable_ = true;
|
||||
return false;
|
||||
@@ -83,21 +77,17 @@ bool Engine::prepare(uint32_t w, uint32_t h, VkFormat fmt) {
|
||||
}
|
||||
|
||||
uint32_t Engine::plan(uint32_t capacity) const {
|
||||
if (!valid() || history_ < 2) return 0; // need prev AND curr
|
||||
if (!valid() || history_ < 2) return 0;
|
||||
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*/) {
|
||||
uint32_t ) {
|
||||
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),
|
||||
@@ -115,8 +105,6 @@ void Engine::process(VkCommandBuffer cmd, VkImage source, uint32_t w, uint32_t h
|
||||
dd_.CmdCopyImage(cmd, source, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
|
||||
dst.img, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, ®ion);
|
||||
|
||||
// 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),
|
||||
@@ -138,17 +126,11 @@ void Engine::generateInto(VkCommandBuffer cmd, uint32_t generation, uint32_t cou
|
||||
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;
|
||||
|
||||
@@ -157,7 +139,6 @@ void Engine::generateInto(VkCommandBuffer cmd, uint32_t generation, uint32_t cou
|
||||
|
||||
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++)
|
||||
@@ -201,4 +182,4 @@ void Engine::destroyRing() {
|
||||
history_ = 0;
|
||||
}
|
||||
|
||||
} // namespace winfg
|
||||
}
|
||||
@@ -1,28 +1,4 @@
|
||||
#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"
|
||||
@@ -32,8 +8,6 @@ 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 {
|
||||
@@ -48,22 +22,15 @@ public:
|
||||
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);
|
||||
@@ -91,12 +58,12 @@ private:
|
||||
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
|
||||
int curr_ = 0;
|
||||
uint32_t history_ = 0;
|
||||
uint32_t gmSlot_ = 0;
|
||||
uint32_t builtW_ = 0, builtH_ = 0;
|
||||
VkFormat builtFmt_ = VK_FORMAT_UNDEFINED;
|
||||
uint64_t frames_ = 0;
|
||||
};
|
||||
|
||||
} // namespace winfg
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
// See winfg_vkd.h.
|
||||
#include "winfg_vkd.h"
|
||||
#include "../VulkanRendererContext.h"
|
||||
#include <android/log.h>
|
||||
|
||||
@@ -1,19 +1,4 @@
|
||||
#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);
|
||||
Reference in new issue
Block a user