mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-06 21:15:43 +00:00
* feat(lsfg): take Lossless Scaling from Steam by itself, import it once owned, rebuild on update - Lossless.kt owns the DLL and its shader cache. The copy the Steam client installs (runtime library or the card's) is taken by itself and taken again when the client updates it (size/mtime stamp). The DLL is copied in and built into a cache named after its SHA-256, so a new DLL hands the compositor a new path; a build that fails keeps the working cache. Builds are serialized. - The Steam session asks the signed-in client once per session whether the account owns app 993090 until the answer is yes, then records it and the app stops asking (BL_LOSSLESS_OWNED). Once owned, the frame generation menu offers "Import Lossless.dll…", on the main screen and in the session drawer; an import stays until Steam's copy changes. - The compositor restarts the LSFG engine when its cache path changes, and a new engine selection clears an earlier start failure, so an updated DLL or a retry no longer needs the app restarted. - The HUD says when LSFG is waiting on Lossless Scaling instead of "starting"; frame generation strings are resources. - Removed LsfgNative's unused DLL variant and cache-match calls. * Find Lossless.dll in added Games libraries too * LSFG: 120, 90 and 60 fps targets alongside 2x-4x The pacer's target-rate mode picks 0-3 generations per game frame. While it is warm the input ring and shared chain follow every frame, so frames that generate nothing don't leave the next one without history. * Credit LSFG: Camille LaVey / Eden, ported to WinNative and DroidDeck by @maxjivi05 * LSFG: aim 0.1 fps under the target so output never passes the refresh rate
155 lines
6.6 KiB
C++
155 lines
6.6 KiB
C++
#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>
|
|
#include <string>
|
|
|
|
#include <vulkan/vulkan.h>
|
|
|
|
#include "lsfg_common.hpp"
|
|
#include "lsfg_dll.h" // kSpirv16
|
|
#include "lsfg_governor.h"
|
|
#include "lsfg_pacer.hpp"
|
|
|
|
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);
|
|
|
|
bool valid() const { return shaders_ != nullptr && !unavailable_; }
|
|
bool unavailable() const { return unavailable_; }
|
|
|
|
void configure(uint32_t multiplier, uint32_t targetRate, float flowScale, float refreshRate);
|
|
void setRefreshRate(float refreshRate);
|
|
void setGuestExtent(uint32_t width, uint32_t height);
|
|
|
|
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; }
|
|
|
|
void forgetTargets();
|
|
void reset();
|
|
|
|
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_{};
|
|
std::string cachePath_;
|
|
std::unique_ptr<LsfgShaders> shaders_;
|
|
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_{};
|
|
|
|
VkExtent2D builtExtent_{};
|
|
VkExtent2D peakGuestExtent_{};
|
|
VkFormat builtFormat_{VK_FORMAT_UNDEFINED};
|
|
float builtFlowScale_{};
|
|
float flowScale_{1.0f};
|
|
|
|
float presentedRate_{};
|
|
|
|
uint64_t frameCount_{};
|
|
uint64_t lastCopiedCount_{};
|
|
bool haveCopied_{};
|
|
bool primeHistory_{};
|
|
uint64_t primeLogCount_{};
|
|
uint64_t lastCount_{};
|
|
size_t lastGenerations_{};
|
|
uint64_t planCalls_{};
|
|
uint32_t warmStreak_{};
|
|
bool warm_{};
|
|
bool generating_{};
|
|
bool unavailable_{};
|
|
};
|
|
|
|
} // namespace lsfg
|