mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-05 20:45:43 +00:00
Merge main into feat/neural-upscaler
Conflicts: drawer pages moved into functions on main (upscaler group now in DrawerGamePage), launch.sh WSI bypass line, recipes.json/runtime_inputs.py lists (main's IME entries + the upscale layer), game-environment tests (both classes kept).
This commit is contained in:
commit
94bcfca5c0
449 files changed
+34769
-2967
No files matched your search
@@ -10,6 +10,17 @@ add_subdirectory(adrenotools)
|
||||
|
||||
add_subdirectory(thirdparty/dxbc)
|
||||
|
||||
# Pin ZeroFG to a fixed revision instead of vendoring thousands of generated shader lines.
|
||||
include(FetchContent)
|
||||
set(ZEROFG_VULKAN_HEADERS_DIR "${CMAKE_SYSROOT}/usr/include" CACHE PATH "" FORCE)
|
||||
set(ZEROFG_PREBUILT_SHADERS ON CACHE STRING "" FORCE)
|
||||
FetchContent_Declare(zerofg
|
||||
GIT_REPOSITORY https://github.com/hy300leosquizz-ctrl/ZeroFG.git
|
||||
GIT_TAG e6ca7ef9f9765db89847b6d8eed352e458f1a8bb
|
||||
GIT_PROGRESS TRUE
|
||||
)
|
||||
FetchContent_MakeAvailable(zerofg)
|
||||
|
||||
set(DDFG_UPSTREAM "v0.3.0")
|
||||
set(DDFG_CHAIN_SRC
|
||||
framegen/ddfg/framegen.cpp
|
||||
|
||||
@@ -4130,6 +4130,24 @@ EXPORT ssize_t read(int fd, void *buf, size_t count) {
|
||||
return read_input(fd, buf, count);
|
||||
}
|
||||
|
||||
// glibc's fortify failure; bionic (DroidDeck-Bionic preloads this library into its Wine processes) has no
|
||||
// __chk_fail, and a library naming it there cannot be loaded, which stops every Wine program from starting.
|
||||
#if defined(__BIONIC__)
|
||||
[[noreturn]] static void fakeinput_chk_fail(void) { abort(); }
|
||||
#else
|
||||
extern "C" [[noreturn]] void __chk_fail(void);
|
||||
[[noreturn]] static void fakeinput_chk_fail(void) { __chk_fail(); }
|
||||
#endif
|
||||
|
||||
/* Programs built with _FORTIFY_SOURCE (Flatpak runtimes among them) call these instead of read, poll
|
||||
* and ppoll, and glibc's versions go straight to the kernel. */
|
||||
EXPORT ssize_t __read_chk(int fd, void *buf, size_t count, size_t buflen) {
|
||||
static auto next_read_chk = reinterpret_cast<ssize_t (*)(int, void *, size_t, size_t)>(dlsym(RTLD_NEXT, "__read_chk"));
|
||||
if (count > buflen) fakeinput_chk_fail();
|
||||
if (next_read_chk && !is_fake_input_fd(fd)) return next_read_chk(fd, buf, count, buflen);
|
||||
return read_input(fd, buf, count);
|
||||
}
|
||||
|
||||
EXPORT ssize_t readv(int fd, const struct iovec *iov, int iovcnt) {
|
||||
if (!is_fake_input_fd(fd)) return syscall(SYS_readv, fd, iov, iovcnt);
|
||||
if (iovcnt < 0 || iovcnt > IOV_MAX) {
|
||||
@@ -4378,6 +4396,17 @@ EXPORT int ppoll(struct pollfd *fds, nfds_t nfds,
|
||||
return my_ppoll(fds, nfds, timeout, sigmask);
|
||||
}
|
||||
|
||||
EXPORT int __poll_chk(struct pollfd *fds, nfds_t nfds, int timeout, size_t fdslen) {
|
||||
if (fdslen / sizeof(*fds) < nfds) fakeinput_chk_fail();
|
||||
return poll(fds, nfds, timeout);
|
||||
}
|
||||
|
||||
EXPORT int __ppoll_chk(struct pollfd *fds, nfds_t nfds, const struct timespec *timeout,
|
||||
const sigset_t *sigmask, size_t fdslen) {
|
||||
if (fdslen / sizeof(*fds) < nfds) fakeinput_chk_fail();
|
||||
return ppoll(fds, nfds, timeout, sigmask);
|
||||
}
|
||||
|
||||
EXPORT int select(int nfds, fd_set *readfds, fd_set *writefds,
|
||||
fd_set *exceptfds, struct timeval *timeout) {
|
||||
const auto my_select = next_symbol<decltype(&::select)>(Next::select);
|
||||
|
||||
@@ -27,7 +27,31 @@ VkImageMemoryBarrier bar(VkImage img, VkImageLayout from, VkImageLayout to,
|
||||
}
|
||||
|
||||
Engine::Engine() = default;
|
||||
Engine::~Engine() { destroyRing(); fg_.destroy(); }
|
||||
Engine::~Engine() { (void)destroy(); }
|
||||
|
||||
bool Engine::destroy() {
|
||||
if (!fg_.destroy()) {
|
||||
DDFG_LOGE("native: retaining the input ring because GPU completion is unknown");
|
||||
return false;
|
||||
}
|
||||
if (!destroyRing(true)) {
|
||||
DDFG_LOGE("native: could not release the input ring during teardown");
|
||||
return false;
|
||||
}
|
||||
dev_ = VK_NULL_HANDLE;
|
||||
unavailable_ = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void Engine::abandon() {
|
||||
fg_.abandon();
|
||||
ring_[0] = Slot{};
|
||||
ring_[1] = Slot{};
|
||||
dev_ = VK_NULL_HANDLE;
|
||||
queue_ = VK_NULL_HANDLE;
|
||||
phys_ = VK_NULL_HANDLE;
|
||||
unavailable_ = true;
|
||||
}
|
||||
|
||||
bool Engine::init(const VkTable& table, VkPhysicalDevice phys, VkDevice dev,
|
||||
uint32_t queueFamily, VkQueue queue) {
|
||||
@@ -59,15 +83,29 @@ 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;
|
||||
|
||||
|
||||
if (!fg_.onResize(VkExtent2D{w, h}, fmt, false)) {
|
||||
const bool formatChanged = fmt != builtFmt_;
|
||||
if (!fg_.onResize(VkExtent2D{w, h}, fmt, formatChanged)) {
|
||||
DDFG_LOGE("native: onResize %ux%u failed; frame generation unavailable", w, h);
|
||||
unavailable_ = true;
|
||||
return false;
|
||||
}
|
||||
destroyRing();
|
||||
bool deviceLost = false;
|
||||
if (!destroyRing(false, &deviceLost)) {
|
||||
DDFG_LOGE("native: could not safely release the previous input ring");
|
||||
unavailable_ = true;
|
||||
return false;
|
||||
}
|
||||
if (deviceLost) {
|
||||
DDFG_LOGE("native: device lost while releasing the input ring");
|
||||
unavailable_ = true;
|
||||
return false;
|
||||
}
|
||||
for (Slot& s : ring_) {
|
||||
if (!makeSlot(s, w, h, fmt)) { destroyRing(); unavailable_ = true; return false; }
|
||||
if (!makeSlot(s, w, h, fmt)) {
|
||||
destroyRing(true);
|
||||
unavailable_ = true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
builtW_ = w; builtH_ = h; builtFmt_ = fmt;
|
||||
history_ = 0; curr_ = 0; frames_ = 0;
|
||||
@@ -178,11 +216,37 @@ void Engine::destroySlot(Slot& s) {
|
||||
s = Slot{};
|
||||
}
|
||||
|
||||
void Engine::destroyRing() {
|
||||
if (dev_ == VK_NULL_HANDLE || !dd_.DeviceWaitIdle) return;
|
||||
if (ring_[0].img || ring_[1].img) dd_.DeviceWaitIdle(dev_);
|
||||
destroySlot(ring_[0]); destroySlot(ring_[1]);
|
||||
bool Engine::destroyRing(bool deviceIdleConfirmed, bool* deviceLost) {
|
||||
if (deviceLost) *deviceLost = false;
|
||||
const bool hasResources = ring_[0].img || ring_[0].mem || ring_[0].view ||
|
||||
ring_[1].img || ring_[1].mem || ring_[1].view;
|
||||
if (!hasResources) {
|
||||
history_ = 0;
|
||||
return true;
|
||||
}
|
||||
if (dev_ == VK_NULL_HANDLE) {
|
||||
DDFG_LOGE("native: cannot release the input ring without a valid device");
|
||||
return false;
|
||||
}
|
||||
if (!deviceIdleConfirmed) {
|
||||
if (!dd_.DeviceWaitIdle) {
|
||||
DDFG_LOGE("native: cannot release the input ring without vkDeviceWaitIdle");
|
||||
return false;
|
||||
}
|
||||
const VkResult result = dd_.DeviceWaitIdle(dev_);
|
||||
if (result == VK_ERROR_DEVICE_LOST) {
|
||||
if (deviceLost) *deviceLost = true;
|
||||
unavailable_ = true;
|
||||
} else if (result != VK_SUCCESS) {
|
||||
DDFG_LOGE("native: DeviceWaitIdle failed (%d); retaining the input ring", (int)result);
|
||||
unavailable_ = true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
destroySlot(ring_[0]);
|
||||
destroySlot(ring_[1]);
|
||||
history_ = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -36,13 +36,15 @@ public:
|
||||
uint32_t width, uint32_t height);
|
||||
|
||||
void reset();
|
||||
bool destroy();
|
||||
void abandon();
|
||||
|
||||
private:
|
||||
struct Slot { VkImage img = VK_NULL_HANDLE; VkDeviceMemory mem = VK_NULL_HANDLE;
|
||||
VkImageView view = VK_NULL_HANDLE; bool valid = false; };
|
||||
bool makeSlot(Slot& s, uint32_t w, uint32_t h, VkFormat fmt);
|
||||
void destroySlot(Slot& s);
|
||||
void destroyRing();
|
||||
bool destroyRing(bool deviceIdleConfirmed = false, bool* deviceLost = nullptr);
|
||||
uint32_t memType(uint32_t bits, VkMemoryPropertyFlags props) const;
|
||||
|
||||
DeviceDispatch dd_{};
|
||||
|
||||
@@ -7,6 +7,31 @@
|
||||
|
||||
namespace ddfg {
|
||||
|
||||
struct ScratchState {
|
||||
VkDevice ownerDevice = VK_NULL_HANDLE;
|
||||
VkBuffer synthUbo[ddfg::FrameGen::kSynthSlots]{};
|
||||
VkDeviceMemory synthUboMem[ddfg::FrameGen::kSynthSlots]{};
|
||||
void* synthUboPtr[ddfg::FrameGen::kSynthSlots]{};
|
||||
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;
|
||||
VkBuffer flowRegUbo = VK_NULL_HANDLE; VkDeviceMemory flowRegUboMem = VK_NULL_HANDLE; void* flowRegUboPtr = nullptr;
|
||||
VkBuffer gmUbo[ddfg::FrameGen::kGmSlots]{};
|
||||
VkDeviceMemory gmUboMem[ddfg::FrameGen::kGmSlots]{};
|
||||
void* gmUboPtr[ddfg::FrameGen::kGmSlots]{};
|
||||
VkDescriptorSet sLumaCurr = VK_NULL_HANDLE, sLumaPrev = VK_NULL_HANDLE;
|
||||
std::vector<VkDescriptorSet> sDownA, sDownB, sFlow;
|
||||
VkDescriptorSet sExpand[ddfg::FrameGen::kGmSlots]{};
|
||||
VkDescriptorSet sFlowReg0 = VK_NULL_HANDLE, sFlowRegAB = VK_NULL_HANDLE, sFlowRegBA = VK_NULL_HANDLE;
|
||||
VkDescriptorSet sSynth[ddfg::FrameGen::kSynthSlots]{};
|
||||
VkDescriptorSet sGmReduce[ddfg::FrameGen::kGmSlots]{};
|
||||
std::vector<VkDescriptorSet> sGmPrewarp[ddfg::FrameGen::kGmSlots];
|
||||
VkExtent2D builtFor{0,0};
|
||||
uint64_t builtGeneration = 0;
|
||||
bool built = false;
|
||||
bool flowInited = false;
|
||||
bool flowReady = false;
|
||||
};
|
||||
|
||||
#define VKOK(x) do { if ((x) != VK_SUCCESS) { DDFG_LOGE("vk fail: %s", #x); return false; } } while (0)
|
||||
|
||||
uint32_t FrameGen::findMemType(uint32_t bits, VkMemoryPropertyFlags props) const {
|
||||
@@ -108,6 +133,10 @@ static bool buildSetLayout(const DeviceDispatch* dd, VkDevice dev,
|
||||
|
||||
bool FrameGen::init(const DeviceDispatch* dd, const InstanceDispatch* id,
|
||||
VkPhysicalDevice phys, VkDevice dev, uint32_t queueFamily, VkQueue queue) {
|
||||
if (device_ || completionUnknown_ || deviceLost_) {
|
||||
DDFG_LOGE("framegen: refusing to initialize an instance that still owns device resources");
|
||||
return false;
|
||||
}
|
||||
dd_ = dd; id_ = id; phys_ = phys; device_ = dev; queueFamily_ = queueFamily; queue_ = queue;
|
||||
id_->GetPhysicalDeviceMemoryProperties(phys_, &memProps_);
|
||||
|
||||
@@ -166,16 +195,19 @@ static VkExtent2D levelExtent(VkExtent2D e, int l) {
|
||||
}
|
||||
|
||||
bool FrameGen::onResize(VkExtent2D extent, VkFormat , bool force) {
|
||||
|
||||
|
||||
if (!force && ready_ && extent.width == extent_.width && extent.height == extent_.height) return true;
|
||||
if (ready_) {
|
||||
const VkResult idleResult = dd_->DeviceWaitIdle(device_);
|
||||
if (idleResult != VK_SUCCESS) {
|
||||
DDFG_LOGE("framegen resize: DeviceWaitIdle failed (%d); keeping existing images", (int)idleResult);
|
||||
return false;
|
||||
}
|
||||
if (completionUnknown_ || deviceLost_) return false;
|
||||
if (!device_) {
|
||||
DDFG_LOGE("framegen: cannot resize before device initialization");
|
||||
return false;
|
||||
}
|
||||
if (!force && ready_ && extent.width == extent_.width && extent.height == extent_.height) return true;
|
||||
if (ready_ && !waitIdle("resize")) return false;
|
||||
if (scratch_ && scratch_->ownerDevice != VK_NULL_HANDLE && !destroyScratchResources()) {
|
||||
DDFG_LOGE("framegen resize: scratch cleanup failed; retaining the previous image set");
|
||||
return false;
|
||||
}
|
||||
|
||||
ready_ = false;
|
||||
++imageGeneration_;
|
||||
for (auto& i : pyrA_) destroyImage(i); pyrA_.clear();
|
||||
for (auto& i : pyrB_) destroyImage(i); pyrB_.clear();
|
||||
@@ -183,7 +215,17 @@ bool FrameGen::onResize(VkExtent2D extent, VkFormat , bool force) {
|
||||
for (auto& i : flowLvl_) destroyImage(i); flowLvl_.clear();
|
||||
destroyImage(flowExpA_); destroyImage(flowExpB_);
|
||||
destroyImage(flowRegA_); destroyImage(flowRegB_);
|
||||
extent_ = extent; ready_ = false;
|
||||
extent_ = extent;
|
||||
|
||||
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;
|
||||
|
||||
const VkImageUsageFlags lumaUsage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT;
|
||||
const VkImageUsageFlags flowUsage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
|
||||
@@ -234,21 +276,37 @@ void FrameGen::initializeImage(VkCommandBuffer cmd, VkImage img, VkImageLayout t
|
||||
}
|
||||
|
||||
|
||||
void FrameGen::destroy() {
|
||||
if (!device_) return;
|
||||
const VkResult idleResult = dd_->DeviceWaitIdle(device_);
|
||||
if (idleResult != VK_SUCCESS && idleResult != VK_ERROR_DEVICE_LOST) {
|
||||
DDFG_LOGE("framegen destroy: DeviceWaitIdle failed (%d); preserving resources for safe retry", (int)idleResult);
|
||||
return;
|
||||
}
|
||||
if (idleResult == VK_ERROR_DEVICE_LOST) {
|
||||
// A lost device cannot become idle again. Still explicitly destroy its
|
||||
// child objects; skip descriptor-pool reset and release scratch ownership.
|
||||
DDFG_LOGE("framegen destroy: device lost; releasing owned resources without waiting");
|
||||
destroyScratchResources(false);
|
||||
} else {
|
||||
destroyScratchResources();
|
||||
bool FrameGen::destroy() {
|
||||
if (!device_) return true;
|
||||
if (!deviceLost_) {
|
||||
// A previous wait failure leaves completion unknown, but a later
|
||||
// teardown attempt may safely retry the wait before releasing resources.
|
||||
if (!dd_ || !dd_->DeviceWaitIdle) {
|
||||
ready_ = false;
|
||||
completionUnknown_ = true;
|
||||
DDFG_LOGE("framegen destroy: vkDeviceWaitIdle is unavailable; preserving GPU resources");
|
||||
return false;
|
||||
}
|
||||
const VkResult idleResult = dd_->DeviceWaitIdle(device_);
|
||||
if (idleResult == VK_SUCCESS) completionUnknown_ = false;
|
||||
if (idleResult != VK_SUCCESS) {
|
||||
ready_ = false;
|
||||
if (idleResult == VK_ERROR_DEVICE_LOST) {
|
||||
deviceLost_ = true;
|
||||
DDFG_LOGE("framegen destroy: device lost; releasing owned resources without waiting");
|
||||
} else {
|
||||
completionUnknown_ = true;
|
||||
DDFG_LOGE("framegen destroy: DeviceWaitIdle failed (%d); preserving resources because GPU completion is unknown",
|
||||
(int)idleResult);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ready_ = false;
|
||||
if (descPool_) dd_->DestroyDescriptorPool(device_, descPool_, nullptr);
|
||||
descPool_ = VK_NULL_HANDLE;
|
||||
releaseScratch();
|
||||
for (auto& i : pyrA_) destroyImage(i); pyrA_.clear();
|
||||
for (auto& i : pyrB_) destroyImage(i); pyrB_.clear();
|
||||
for (auto& i : pyrAs_) destroyImage(i); pyrAs_.clear();
|
||||
@@ -260,15 +318,45 @@ void FrameGen::destroy() {
|
||||
destroyPipe(pGmReduce_); destroyPipe(pGmPrewarp_);
|
||||
destroyPipe(pFlowReg_);
|
||||
for (int s = 0; s < kGmSlots; ++s) {
|
||||
if (gmSsboMem_[s]) dd_->UnmapMemory(device_, gmSsboMem_[s]);
|
||||
if (gmSsboPtr_[s] && gmSsboMem_[s]) dd_->UnmapMemory(device_, gmSsboMem_[s]);
|
||||
if (gmSsbo_[s]) dd_->DestroyBuffer(device_, gmSsbo_[s], nullptr);
|
||||
if (gmSsboMem_[s]) dd_->FreeMemory(device_, gmSsboMem_[s], nullptr);
|
||||
gmSsbo_[s] = VK_NULL_HANDLE; gmSsboMem_[s] = VK_NULL_HANDLE; gmSsboPtr_[s] = nullptr;
|
||||
}
|
||||
gmBuffersReady_ = false;
|
||||
if (descPool_) dd_->DestroyDescriptorPool(device_, descPool_, nullptr);
|
||||
if (linear_) dd_->DestroySampler(device_, linear_, nullptr);
|
||||
descPool_ = VK_NULL_HANDLE; linear_ = VK_NULL_HANDLE; device_ = VK_NULL_HANDLE; ready_ = false;
|
||||
linear_ = VK_NULL_HANDLE;
|
||||
device_ = VK_NULL_HANDLE;
|
||||
ready_ = false;
|
||||
deviceLost_ = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
void FrameGen::abandon() {
|
||||
device_ = VK_NULL_HANDLE;
|
||||
dd_ = nullptr;
|
||||
id_ = nullptr;
|
||||
phys_ = VK_NULL_HANDLE;
|
||||
queue_ = VK_NULL_HANDLE;
|
||||
linear_ = VK_NULL_HANDLE;
|
||||
descPool_ = VK_NULL_HANDLE;
|
||||
scratch_.reset();
|
||||
pyrA_.clear(); pyrB_.clear(); pyrAs_.clear(); flowLvl_.clear();
|
||||
flowExpA_ = Img{}; flowExpB_ = Img{};
|
||||
flowRegA_ = Img{}; flowRegB_ = Img{};
|
||||
pLuma_ = Pipe{}; pDown_ = Pipe{}; pFlow_ = Pipe{}; pFlowM4_ = Pipe{};
|
||||
pExpand_ = Pipe{}; pExpandM4_ = Pipe{}; pSynth_ = Pipe{};
|
||||
pGmReduce_ = Pipe{}; pGmPrewarp_ = Pipe{}; pFlowReg_ = Pipe{};
|
||||
for (int s = 0; s < kGmSlots; ++s) {
|
||||
gmSsbo_[s] = VK_NULL_HANDLE;
|
||||
gmSsboMem_[s] = VK_NULL_HANDLE;
|
||||
gmSsboPtr_[s] = nullptr;
|
||||
gmSlotValid_[s] = false;
|
||||
}
|
||||
gmBuffersReady_ = false;
|
||||
ready_ = false;
|
||||
completionUnknown_ = false;
|
||||
deviceLost_ = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,12 +1,20 @@
|
||||
#pragma once
|
||||
#include "vk_dispatch.hpp"
|
||||
#include "config.hpp"
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
namespace ddfg {
|
||||
|
||||
struct ScratchState;
|
||||
|
||||
class FrameGen {
|
||||
public:
|
||||
FrameGen();
|
||||
~FrameGen();
|
||||
FrameGen(const FrameGen&) = delete;
|
||||
FrameGen& operator=(const FrameGen&) = delete;
|
||||
|
||||
bool init(const DeviceDispatch* dd, const InstanceDispatch* id,
|
||||
VkPhysicalDevice phys, VkDevice dev, uint32_t queueFamily, VkQueue queue);
|
||||
void configure(const Config& c);
|
||||
@@ -14,7 +22,8 @@ public:
|
||||
void record(VkCommandBuffer cmd, VkImageView prevView, VkImageView currView,
|
||||
VkImageView outView, float alpha, uint32_t gmSlot = 0,
|
||||
uint32_t synthSlot = 0, bool reuseFlow = false);
|
||||
void destroy();
|
||||
bool destroy();
|
||||
void abandon();
|
||||
bool valid() const { return device_ != VK_NULL_HANDLE && ready_; }
|
||||
const Config& config() const { return cfg_; }
|
||||
|
||||
@@ -64,7 +73,9 @@ private:
|
||||
void destroyPipe(Pipe& p);
|
||||
void barrier(VkCommandBuffer cmd, VkImage img, VkImageLayout from, VkImageLayout to);
|
||||
void initializeImage(VkCommandBuffer cmd, VkImage img, VkImageLayout to);
|
||||
void destroyScratchResources(bool resetPool = true);
|
||||
bool waitIdle(const char* operation);
|
||||
bool destroyScratchResources(bool resetPool = true);
|
||||
void releaseScratch();
|
||||
|
||||
const DeviceDispatch* dd_ = nullptr;
|
||||
const InstanceDispatch* id_ = nullptr;
|
||||
@@ -80,7 +91,10 @@ private:
|
||||
VkExtent2D extent_{};
|
||||
uint64_t imageGeneration_ = 0;
|
||||
bool ready_ = false;
|
||||
bool completionUnknown_ = false;
|
||||
bool deviceLost_ = false;
|
||||
int flowFinest_ = kFlowFinestDefault;
|
||||
std::unique_ptr<ScratchState> scratch_;
|
||||
|
||||
Pipe pLuma_, pDown_, pFlow_, pFlowM4_, pExpand_, pExpandM4_, pSynth_;
|
||||
Pipe pGmReduce_, pGmPrewarp_;
|
||||
|
||||
@@ -1,33 +1,7 @@
|
||||
|
||||
namespace {
|
||||
struct ScratchState {
|
||||
VkDevice ownerDevice = VK_NULL_HANDLE;
|
||||
VkBuffer synthUbo[ddfg::FrameGen::kSynthSlots]{};
|
||||
VkDeviceMemory synthUboMem[ddfg::FrameGen::kSynthSlots]{};
|
||||
void* synthUboPtr[ddfg::FrameGen::kSynthSlots]{};
|
||||
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;
|
||||
VkBuffer flowRegUbo = VK_NULL_HANDLE; VkDeviceMemory flowRegUboMem = VK_NULL_HANDLE; void* flowRegUboPtr = nullptr;
|
||||
VkBuffer gmUbo[ddfg::FrameGen::kGmSlots]{};
|
||||
VkDeviceMemory gmUboMem[ddfg::FrameGen::kGmSlots]{};
|
||||
void* gmUboPtr[ddfg::FrameGen::kGmSlots]{};
|
||||
VkDescriptorSet sLumaCurr = VK_NULL_HANDLE, sLumaPrev = VK_NULL_HANDLE;
|
||||
std::vector<VkDescriptorSet> sDownA, sDownB, sFlow;
|
||||
VkDescriptorSet sExpand[ddfg::FrameGen::kGmSlots]{};
|
||||
|
||||
|
||||
|
||||
VkDescriptorSet sFlowReg0 = VK_NULL_HANDLE, sFlowRegAB = VK_NULL_HANDLE, sFlowRegBA = VK_NULL_HANDLE;
|
||||
VkDescriptorSet sSynth[ddfg::FrameGen::kSynthSlots]{};
|
||||
VkDescriptorSet sGmReduce[ddfg::FrameGen::kGmSlots]{};
|
||||
std::vector<VkDescriptorSet> sGmPrewarp[ddfg::FrameGen::kGmSlots];
|
||||
VkExtent2D builtFor{0,0};
|
||||
uint64_t builtGeneration = 0;
|
||||
bool built = false;
|
||||
bool flowInited = false;
|
||||
bool flowReady = false;
|
||||
};
|
||||
ScratchState g_scratch;
|
||||
namespace ddfg {
|
||||
FrameGen::FrameGen() : scratch_(std::make_unique<ScratchState>()) {}
|
||||
FrameGen::~FrameGen() { (void)destroy(); }
|
||||
}
|
||||
|
||||
static bool makeUbo(const ddfg::DeviceDispatch* dd, VkDevice dev,
|
||||
@@ -144,7 +118,7 @@ static void mulAff(const double A[3][3], const double B[3][3], double out[3][3])
|
||||
|
||||
namespace ddfg {
|
||||
|
||||
static bool ensureScratch(FrameGen* fg, const DeviceDispatch* dd, VkDevice dev,
|
||||
static bool ensureScratch(ScratchState& S, FrameGen* fg, const DeviceDispatch* dd, VkDevice dev,
|
||||
const VkPhysicalDeviceMemoryProperties& mp, VkDescriptorPool pool,
|
||||
VkSampler samp, VkExtent2D ext,
|
||||
std::vector<FrameGen::Img>& pyrA, std::vector<FrameGen::Img>& pyrB,
|
||||
@@ -157,30 +131,72 @@ static bool ensureScratch(FrameGen* fg, const DeviceDispatch* dd, VkDevice dev,
|
||||
FrameGen::Img& flowRegA, FrameGen::Img& flowRegB, VkBuffer* gmSsbo,
|
||||
int kLevels, const Config& cfg, uint64_t imageGeneration);
|
||||
|
||||
static void destroyScratch(const DeviceDispatch* dd, VkDevice dev, VkDescriptorPool pool,
|
||||
bool resetPool = true) {
|
||||
if (g_scratch.ownerDevice != VK_NULL_HANDLE && g_scratch.ownerDevice != dev) return;
|
||||
bool FrameGen::waitIdle(const char* operation) {
|
||||
if (completionUnknown_ || deviceLost_ || !device_) return false;
|
||||
if (!dd_ || !dd_->DeviceWaitIdle) {
|
||||
completionUnknown_ = true;
|
||||
ready_ = false;
|
||||
DDFG_LOGE("framegen: %s cannot confirm GPU completion; this instance is stopped and its resources are retained",
|
||||
operation);
|
||||
return false;
|
||||
}
|
||||
const VkResult result = dd_->DeviceWaitIdle(device_);
|
||||
if (result == VK_SUCCESS) return true;
|
||||
ready_ = false;
|
||||
if (result == VK_ERROR_DEVICE_LOST) {
|
||||
deviceLost_ = true;
|
||||
DDFG_LOGE("framegen: %s reported device loss; cleanup will skip further waits", operation);
|
||||
} else {
|
||||
completionUnknown_ = true;
|
||||
DDFG_LOGE("framegen: %s vkDeviceWaitIdle failed (%d); this instance is stopped and its GPU resources retained",
|
||||
operation, (int)result);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool FrameGen::destroyScratchResources(bool resetPool) {
|
||||
if (!scratch_) return true;
|
||||
if (resetPool && descPool_ && !deviceLost_) {
|
||||
if (!dd_ || !dd_->ResetDescriptorPool) {
|
||||
ready_ = false;
|
||||
DDFG_LOGE("framegen: descriptor-pool reset is unavailable; retaining scratch resources");
|
||||
return false;
|
||||
}
|
||||
const VkResult result = dd_->ResetDescriptorPool(device_, descPool_, 0);
|
||||
if (result != VK_SUCCESS) {
|
||||
ready_ = false;
|
||||
if (result == VK_ERROR_DEVICE_LOST) deviceLost_ = true;
|
||||
DDFG_LOGE("framegen: descriptor-pool reset failed (%d); retaining scratch resources",
|
||||
(int)result);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
releaseScratch();
|
||||
return true;
|
||||
}
|
||||
|
||||
void FrameGen::releaseScratch() {
|
||||
if (!scratch_) return;
|
||||
auto& S = *scratch_;
|
||||
auto freeUbo = [&](VkBuffer& b, VkDeviceMemory& m, void*& p) {
|
||||
if (m) dd->UnmapMemory(dev, m);
|
||||
if (b) dd->DestroyBuffer(dev, b, nullptr);
|
||||
if (m) dd->FreeMemory(dev, m, nullptr);
|
||||
b = VK_NULL_HANDLE; m = VK_NULL_HANDLE; p = nullptr;
|
||||
if (p && m) dd_->UnmapMemory(device_, m);
|
||||
if (b) dd_->DestroyBuffer(device_, b, nullptr);
|
||||
if (m) dd_->FreeMemory(device_, m, nullptr);
|
||||
b = VK_NULL_HANDLE;
|
||||
m = VK_NULL_HANDLE;
|
||||
p = nullptr;
|
||||
};
|
||||
auto& S = g_scratch;
|
||||
for (int s = 0; s < FrameGen::kSynthSlots; ++s) freeUbo(S.synthUbo[s], S.synthUboMem[s], S.synthUboPtr[s]);
|
||||
freeUbo(S.expandUbo, S.expandUboMem, S.expandUboPtr);
|
||||
freeUbo(S.expandUbo, S.expandUboMem, S.expandUboPtr);
|
||||
freeUbo(S.flowRegUbo, S.flowRegUboMem, S.flowRegUboPtr);
|
||||
for (size_t i = 0; i < S.flowUbo.size(); ++i) freeUbo(S.flowUbo[i], S.flowUboMem[i], S.flowUboPtr[i]);
|
||||
for (int s = 0; s < FrameGen::kGmSlots; ++s) freeUbo(S.gmUbo[s], S.gmUboMem[s], S.gmUboPtr[s]);
|
||||
if (resetPool && pool && dd->ResetDescriptorPool) dd->ResetDescriptorPool(dev, pool, 0);
|
||||
S = ScratchState{};
|
||||
}
|
||||
|
||||
void FrameGen::destroyScratchResources(bool resetPool) {
|
||||
destroyScratch(dd_, device_, descPool_, resetPool);
|
||||
}
|
||||
|
||||
void FrameGen::configure(const Config& c) {
|
||||
if (completionUnknown_ || deviceLost_) return;
|
||||
Config nextCfg = c;
|
||||
nextCfg.sanitize();
|
||||
int want = flowFinestForPreset(nextCfg.perfPreset);
|
||||
@@ -203,16 +219,12 @@ void FrameGen::configure(const Config& c) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Keep the previous configuration and image set if the device cannot idle.
|
||||
const VkResult idleResult = dd_->DeviceWaitIdle(device_);
|
||||
if (idleResult != VK_SUCCESS) {
|
||||
DDFG_LOGE("framegen configure: DeviceWaitIdle failed (%d); keeping previous configuration and images",
|
||||
(int)idleResult);
|
||||
if (!waitIdle("live preset rebuild")) return;
|
||||
if (scratch_ && scratch_->ownerDevice != VK_NULL_HANDLE && !destroyScratchResources()) {
|
||||
DDFG_LOGE("perf-preset live rebuild: scratch cleanup failed; keeping the previous configuration");
|
||||
return;
|
||||
}
|
||||
|
||||
// The device is idle, so reset motion history before rebuilding. This
|
||||
// also leaves the predictor reset if onResize fails.
|
||||
for (int i = 0; i < 6; ++i) gmRun_[i] = 0.0;
|
||||
for (int s = 0; s < kGmSlots; ++s) {
|
||||
gmSlotValid_[s] = false;
|
||||
@@ -223,20 +235,17 @@ void FrameGen::configure(const Config& c) {
|
||||
gmStableCount_ = 0;
|
||||
gmLastTransPx_ = 0.0f;
|
||||
|
||||
// Prevent onResize from issuing a second wait.
|
||||
destroyScratch(dd_, device_, descPool_);
|
||||
cfg_ = nextCfg;
|
||||
flowFinest_ = want;
|
||||
ready_ = false;
|
||||
if (!onResize(extent_, VK_FORMAT_UNDEFINED, true)) {
|
||||
ready_ = false;
|
||||
DDFG_LOGE("perf-preset live rebuild: onResize FAILED at %ux%u - FG disabled until next resize",
|
||||
DDFG_LOGE("perf-preset live rebuild: onResize FAILED at %ux%u - frame generation unavailable",
|
||||
extent_.width, extent_.height);
|
||||
return;
|
||||
}
|
||||
DDFG_LOGI("perf-preset live rebuild DONE (kFlowFinest=%d, flow predictor reset)", flowFinest_);
|
||||
}
|
||||
|
||||
bool FrameGen::updateGlobalMotion(uint32_t gmSlot, VkExtent2D fullExtent) {
|
||||
++gmFrames_;
|
||||
if (!gmBuffersReady_ || cfg_.gmMode == 2 ) {
|
||||
@@ -306,35 +315,33 @@ bool FrameGen::updateGlobalMotion(uint32_t gmSlot, VkExtent2D fullExtent) {
|
||||
void FrameGen::record(VkCommandBuffer cmd, VkImageView prevView, VkImageView currView,
|
||||
VkImageView outView, float alpha, uint32_t gmSlot, uint32_t synthSlot, bool reuseFlow) {
|
||||
if (!valid()) return;
|
||||
auto& S = *scratch_;
|
||||
if (gmSlot >= (uint32_t)kGmSlots) gmSlot = 0;
|
||||
if (synthSlot >= (uint32_t)kSynthSlots) synthSlot = 0;
|
||||
const bool m4 = (cfg_.model == 4);
|
||||
const Pipe& flowP = m4 ? pFlowM4_ : pFlow_;
|
||||
const Pipe& expandP = m4 ? pExpandM4_ : pExpand_;
|
||||
|
||||
if (!g_scratch.built || g_scratch.builtFor.width != extent_.width ||
|
||||
g_scratch.builtFor.height != extent_.height ||
|
||||
g_scratch.builtGeneration != imageGeneration_) {
|
||||
if (g_scratch.built) {
|
||||
const VkResult idleResult = dd_->DeviceWaitIdle(device_);
|
||||
if (idleResult != VK_SUCCESS) {
|
||||
DDFG_LOGE("framegen record: DeviceWaitIdle failed (%d); skipping scratch rebuild", (int)idleResult);
|
||||
return;
|
||||
}
|
||||
destroyScratch(dd_, device_, descPool_);
|
||||
if (!S.built || S.builtFor.width != extent_.width ||
|
||||
S.builtFor.height != extent_.height ||
|
||||
S.builtGeneration != imageGeneration_) {
|
||||
if (S.built && !waitIdle("scratch rebuild")) return;
|
||||
if (S.ownerDevice != VK_NULL_HANDLE && !destroyScratchResources()) {
|
||||
DDFG_LOGE("framegen record: scratch cleanup failed; skipping this frame");
|
||||
return;
|
||||
}
|
||||
if (!ensureScratch(this, dd_, device_, memProps_, descPool_, linear_, extent_,
|
||||
if (!ensureScratch(S, this, dd_, device_, memProps_, descPool_, linear_, extent_,
|
||||
pyrA_, pyrB_, pyrAs_, flowLvl_, flowExpA_, flowExpB_,
|
||||
pLuma_, pDown_, flowP, expandP, pSynth_, pGmReduce_, pGmPrewarp_,
|
||||
pFlowReg_, flowRegA_, flowRegB_, gmSsbo_, kLevels, cfg_, imageGeneration_))
|
||||
return;
|
||||
}
|
||||
|
||||
if (g_scratch.ownerDevice != device_) return;
|
||||
if (reuseFlow && !g_scratch.flowReady) return;
|
||||
if (S.ownerDevice != device_) return;
|
||||
if (reuseFlow && !S.flowReady) return;
|
||||
if (!reuseFlow) {
|
||||
bool gmEngaged = updateGlobalMotion(gmSlot, extent_);
|
||||
if (g_scratch.gmUboPtr[gmSlot]) {
|
||||
if (S.gmUboPtr[gmSlot]) {
|
||||
GMUBO g{};
|
||||
g.lin[0]=(float)gmRun_[0]; g.lin[1]=(float)gmRun_[1]; g.lin[2]=(float)gmRun_[2]; g.lin[3]=(float)gmRun_[3];
|
||||
g.linT[0]=(float)gmRun_[4]; g.linT[1]=(float)gmRun_[5]; g.linT[2]=gmEngaged?1.0f:0.0f; g.linT[3]=0.0f;
|
||||
@@ -342,7 +349,7 @@ void FrameGen::record(VkCommandBuffer cmd, VkImageView prevView, VkImageView cur
|
||||
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];
|
||||
}
|
||||
std::memcpy(g_scratch.gmUboPtr[gmSlot], &g, sizeof(g));
|
||||
std::memcpy(S.gmUboPtr[gmSlot], &g, sizeof(g));
|
||||
}
|
||||
{
|
||||
static int lastEng = -1;
|
||||
@@ -353,7 +360,7 @@ void FrameGen::record(VkCommandBuffer cmd, VkImageView prevView, VkImageView cur
|
||||
}
|
||||
}
|
||||
|
||||
const VkDescriptorSet lumaSets[] = {g_scratch.sLumaCurr, g_scratch.sLumaPrev};
|
||||
const VkDescriptorSet lumaSets[] = {S.sLumaCurr, S.sLumaPrev};
|
||||
const uint32_t lumaBindings[] = {32, 32};
|
||||
const VkDescriptorType lumaTypes[] = {
|
||||
VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER};
|
||||
@@ -367,9 +374,9 @@ void FrameGen::record(VkCommandBuffer cmd, VkImageView prevView, VkImageView cur
|
||||
|
||||
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[synthSlot]) std::memcpy(g_scratch.synthUboPtr[synthSlot], &su, sizeof(su));
|
||||
if (S.synthUboPtr[synthSlot]) std::memcpy(S.synthUboPtr[synthSlot], &su, sizeof(su));
|
||||
|
||||
const VkDescriptorSet synthSet = g_scratch.sSynth[synthSlot];
|
||||
const VkDescriptorSet synthSet = S.sSynth[synthSlot];
|
||||
const VkDescriptorSet synthSets[] = {synthSet, synthSet, synthSet};
|
||||
const uint32_t synthBindings[] = {32, 33, 48};
|
||||
const VkDescriptorType synthTypes[] = {
|
||||
@@ -468,17 +475,17 @@ void FrameGen::record(VkCommandBuffer cmd, VkImageView prevView, VkImageView cur
|
||||
VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &b);
|
||||
}
|
||||
|
||||
disp(pLuma_, g_scratch.sLumaCurr, levelExtent(extent_, 0));
|
||||
disp(pLuma_, g_scratch.sLumaPrev, levelExtent(extent_, 0));
|
||||
disp(pLuma_, S.sLumaCurr, levelExtent(extent_, 0));
|
||||
disp(pLuma_, S.sLumaPrev, levelExtent(extent_, 0));
|
||||
barPair(pyrA_[0], pyrB_[0]);
|
||||
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));
|
||||
disp(pDown_, S.sDownA[l - 1], levelExtent(extent_, l));
|
||||
disp(pDown_, S.sDownB[l - 1], levelExtent(extent_, l));
|
||||
barPair(pyrA_[l], pyrB_[l]);
|
||||
}
|
||||
if (gmBuffersReady_ && g_scratch.sGmReduce[gmSlot]) {
|
||||
if (gmBuffersReady_ && S.sGmReduce[gmSlot]) {
|
||||
dd_->CmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_COMPUTE, pGmReduce_.pipeline);
|
||||
dd_->CmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_COMPUTE, pGmReduce_.layout, 0, 1, &g_scratch.sGmReduce[gmSlot], 0, nullptr);
|
||||
dd_->CmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_COMPUTE, pGmReduce_.layout, 0, 1, &S.sGmReduce[gmSlot], 0, nullptr);
|
||||
dd_->CmdDispatch(cmd, (uint32_t)(kGmThreads / 64), 1, 1);
|
||||
VkMemoryBarrier mb{VK_STRUCTURE_TYPE_MEMORY_BARRIER};
|
||||
mb.srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT; mb.dstAccessMask = VK_ACCESS_HOST_READ_BIT;
|
||||
@@ -486,27 +493,27 @@ void FrameGen::record(VkCommandBuffer cmd, VkImageView prevView, VkImageView cur
|
||||
0, 1, &mb, 0, nullptr, 0, nullptr);
|
||||
}
|
||||
for (int l = flowFinest_; l < kLevels; ++l) {
|
||||
disp(pGmPrewarp_, g_scratch.sGmPrewarp[gmSlot][l], levelExtent(extent_, l));
|
||||
disp(pGmPrewarp_, S.sGmPrewarp[gmSlot][l], levelExtent(extent_, l));
|
||||
bar(pyrAs_[l]);
|
||||
}
|
||||
for (int l = kLevels - 1; l >= flowFinest_; --l) {
|
||||
disp(flowP, g_scratch.sFlow[l], levelExtent(extent_, l));
|
||||
disp(flowP, S.sFlow[l], levelExtent(extent_, l));
|
||||
bar(flowLvl_[l]);
|
||||
}
|
||||
|
||||
if (frEngaged) {
|
||||
const int F = flowFinest_;
|
||||
const VkExtent2D fe = levelExtent(extent_, F);
|
||||
if (g_scratch.flowRegUboPtr) {
|
||||
if (S.flowRegUboPtr) {
|
||||
FlowRegUBO fu{cfg_.frDt, cfg_.frLambda, cfg_.frEdge, cfg_.frEps};
|
||||
std::memcpy(g_scratch.flowRegUboPtr, &fu, sizeof(fu));
|
||||
std::memcpy(S.flowRegUboPtr, &fu, sizeof(fu));
|
||||
}
|
||||
FrameGen::Img* last = nullptr;
|
||||
for (int it = 0; it < cfg_.frIters; ++it) {
|
||||
VkDescriptorSet set; FrameGen::Img* outImg;
|
||||
if (it == 0) { set = g_scratch.sFlowReg0; outImg = &flowRegA_; }
|
||||
else if (it % 2 == 1) { set = g_scratch.sFlowRegAB; outImg = &flowRegB_; }
|
||||
else { set = g_scratch.sFlowRegBA; outImg = &flowRegA_; }
|
||||
if (it == 0) { set = S.sFlowReg0; outImg = &flowRegA_; }
|
||||
else if (it % 2 == 1) { set = S.sFlowRegAB; outImg = &flowRegB_; }
|
||||
else { set = S.sFlowRegBA; outImg = &flowRegA_; }
|
||||
dd_->CmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_COMPUTE, pFlowReg_.pipeline);
|
||||
dd_->CmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_COMPUTE, pFlowReg_.layout, 0, 1, &set, 0, nullptr);
|
||||
dd_->CmdDispatch(cmd, (fe.width + 15) / 16, (fe.height + 15) / 16, 1);
|
||||
@@ -540,14 +547,14 @@ void FrameGen::record(VkCommandBuffer cmd, VkImageView prevView, VkImageView cur
|
||||
}
|
||||
}
|
||||
|
||||
disp(expandP, g_scratch.sExpand[gmSlot], levelExtent(extent_, 0));
|
||||
disp(expandP, S.sExpand[gmSlot], levelExtent(extent_, 0));
|
||||
barPair(flowExpA_, flowExpB_);
|
||||
g_scratch.flowReady = true;
|
||||
S.flowReady = true;
|
||||
}
|
||||
disp(pSynth_, synthSet, levelExtent(extent_, 0));
|
||||
}
|
||||
|
||||
static bool ensureScratch(FrameGen* fg, const DeviceDispatch* dd, VkDevice dev,
|
||||
static bool ensureScratch(ScratchState& S, FrameGen* fg, const DeviceDispatch* dd, VkDevice dev,
|
||||
const VkPhysicalDeviceMemoryProperties& mp, VkDescriptorPool pool,
|
||||
VkSampler samp, VkExtent2D ext,
|
||||
std::vector<FrameGen::Img>& pyrA, std::vector<FrameGen::Img>& pyrB,
|
||||
@@ -559,7 +566,6 @@ static bool ensureScratch(FrameGen* fg, const DeviceDispatch* dd, VkDevice dev,
|
||||
const FrameGen::Pipe& pGmPrewarp, const FrameGen::Pipe& pFlowReg,
|
||||
FrameGen::Img& flowRegA, FrameGen::Img& flowRegB, VkBuffer* gmSsbo,
|
||||
int kLevels, const Config& cfg, uint64_t imageGeneration) {
|
||||
auto& S = g_scratch;
|
||||
if (S.ownerDevice != VK_NULL_HANDLE && S.ownerDevice != dev) return false;
|
||||
S = ScratchState{};
|
||||
S.ownerDevice = dev;
|
||||
|
||||
@@ -8,6 +8,6 @@ target_compile_features(droiddeckxr PRIVATE cxx_std_17)
|
||||
target_compile_definitions(droiddeckxr PRIVATE XR_USE_PLATFORM_ANDROID XR_USE_GRAPHICS_API_OPENGL_ES XR_USE_TIMESPEC)
|
||||
target_compile_options(droiddeckxr PRIVATE -Wall -Wextra -Wno-missing-field-initializers -Werror=return-type)
|
||||
target_link_options(droiddeckxr PRIVATE -Wl,-z,max-page-size=16384 -uANativeActivity_onCreate)
|
||||
target_link_libraries(droiddeckxr PRIVATE droiddeckxr_glue OpenXR::openxr_loader EGL GLESv3 android log)
|
||||
target_link_libraries(droiddeckxr PRIVATE droiddeckxr_glue OpenXR::openxr_loader EGL GLESv3 android jnigraphics log)
|
||||
|
||||
target_include_directories(droiddeckxr PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../tools/vr/src)
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <jni.h>
|
||||
#include <EGL/egl.h>
|
||||
#include <GLES3/gl3.h>
|
||||
#include <android/bitmap.h>
|
||||
#include <android/log.h>
|
||||
#include <android_native_app_glue.h>
|
||||
#include <time.h>
|
||||
@@ -22,10 +23,14 @@
|
||||
#include <cerrno>
|
||||
#include <cstddef>
|
||||
#include <ctime>
|
||||
#include <pthread.h>
|
||||
#include <algorithm>
|
||||
#include "xr_tracking.h"
|
||||
#include "xr_frame_channel.h"
|
||||
#include "xr_frame_math.h"
|
||||
#include "gpu_frames.h"
|
||||
#include "xr_host.h"
|
||||
#include "xr_overlay.h"
|
||||
|
||||
static void check(XrResult result, const char *operation) {
|
||||
if (XR_FAILED(result)) throw std::runtime_error(std::string(operation) + ": " + std::to_string(result));
|
||||
@@ -37,6 +42,15 @@ struct Eye {
|
||||
std::vector<XrSwapchainImageOpenGLESKHR> images;
|
||||
};
|
||||
|
||||
struct SurfaceLayer {
|
||||
XrSwapchain swapchain = XR_NULL_HANDLE;
|
||||
jobject surface = nullptr;
|
||||
int width = 0, height = 0;
|
||||
};
|
||||
|
||||
class QuestXR;
|
||||
static QuestXR *g_runtime = nullptr;
|
||||
|
||||
class QuestXR {
|
||||
public:
|
||||
explicit QuestXR(android_app *app) : app_(app) {}
|
||||
@@ -76,21 +90,74 @@ public:
|
||||
"\"headPosition\":[%.6f,%.6f,%.6f],\"controllersActive\":[%s,%s],"
|
||||
"\"periodNs\":%lld,\"surfaceSwapchain\":%s,\"source\":\"%s\",\"guestFrames\":%lld,\"steamvrState\":%d,"
|
||||
"\"receivedFrames\":%llu,\"rejectedFrames\":%llu,\"uploadedFrames\":%llu,\"sourceFrameId\":%llu,"
|
||||
"\"gpuReceivedFrames\":%llu,\"gpuDroppedFrames\":%llu,\"gpuVerifiedFrameId\":%llu,\"gpuChecksum\":%u,\"error\":\"%s\"}\n",
|
||||
"\"gpuReceivedFrames\":%llu,\"gpuDroppedFrames\":%llu,\"gpuVerifiedFrameId\":%llu,\"gpuChecksum\":%u,"
|
||||
"\"hostVersion\":%u,\"visibleLayers\":%d,\"overlay\":%s,\"error\":\"%s\"}\n",
|
||||
(unsigned long long)frames_, (unsigned long long)rendered_, state_,
|
||||
(unsigned long long)head_.locationFlags,
|
||||
head_.pose.position.x, head_.pose.position.y, head_.pose.position.z,
|
||||
handActive_[0] ? "true" : "false", handActive_[1] ? "true" : "false",
|
||||
(long long)period_, "false", "frames",
|
||||
(long long)period_, surfaceSupported_ ? "true" : "false", "frames",
|
||||
0LL, steamvrState, (unsigned long long)(receiver_.Received() + gpuFrames_.Received()),
|
||||
(unsigned long long)(receiver_.Rejected() + gpuFrames_.Rejected()),
|
||||
(unsigned long long)uploadedFrames_, (unsigned long long)sourceHeader_.frame_id,
|
||||
(unsigned long long)gpuFrames_.Received(), (unsigned long long)gpuFrames_.Dropped(),
|
||||
(unsigned long long)verifiedFrame_, gpuChecksum_, error);
|
||||
(unsigned long long)verifiedFrame_, gpuChecksum_,
|
||||
hostBuffers_ ? DROIDDECK_XR_HOST_VERSION : 0u, visibleLayers_,
|
||||
XrOverlay::active(hostControl_) ? "true" : "false", error);
|
||||
std::fclose(file);
|
||||
std::rename(temp.c_str(), path.c_str());
|
||||
}
|
||||
|
||||
bool onXrThread() const { return pthread_equal(pthread_self(), xrThread_); }
|
||||
|
||||
int createLayer(JNIEnv *env, int width, int height) {
|
||||
if (!onXrThread() || !createSurfaceSwapchain_ || session_ == XR_NULL_HANDLE || width <= 0 || height <= 0) return -1;
|
||||
for (int index = 0; index < DROIDDECK_XR_HOST_LAYERS; index++) {
|
||||
SurfaceLayer &layer = layers_[index];
|
||||
if (layer.swapchain) continue;
|
||||
XrSwapchainCreateInfo create{XR_TYPE_SWAPCHAIN_CREATE_INFO};
|
||||
create.usageFlags = XR_SWAPCHAIN_USAGE_SAMPLED_BIT | XR_SWAPCHAIN_USAGE_COLOR_ATTACHMENT_BIT;
|
||||
create.width = width; create.height = height;
|
||||
jobject surface = nullptr;
|
||||
XrResult result = createSurfaceSwapchain_(session_, &create, &layer.swapchain, &surface);
|
||||
if (XR_FAILED(result) || !surface) {
|
||||
__android_log_print(ANDROID_LOG_ERROR, "DroidDeckXR", "surface layer %dx%d failed: %d", width, height, result);
|
||||
if (layer.swapchain) xrDestroySwapchain(layer.swapchain);
|
||||
layer = {};
|
||||
return -1;
|
||||
}
|
||||
layer.surface = env->NewGlobalRef(surface);
|
||||
layer.width = width; layer.height = height;
|
||||
__android_log_print(ANDROID_LOG_INFO, "DroidDeckXR", "surface layer %d created %dx%d", index, width, height);
|
||||
return index;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
jobject layerSurface(JNIEnv *env, int index) {
|
||||
if (!onXrThread() || index < 0 || index >= DROIDDECK_XR_HOST_LAYERS || !layers_[index].surface) return nullptr;
|
||||
return env->NewLocalRef(layers_[index].surface);
|
||||
}
|
||||
|
||||
void setOrbImage(JNIEnv *env, jobject bitmap) {
|
||||
if (!onXrThread() || !bitmap) return;
|
||||
AndroidBitmapInfo info{};
|
||||
void *pixels = nullptr;
|
||||
if (AndroidBitmap_getInfo(env, bitmap, &info) != ANDROID_BITMAP_RESULT_SUCCESS
|
||||
|| info.format != ANDROID_BITMAP_FORMAT_RGBA_8888) return;
|
||||
if (AndroidBitmap_lockPixels(env, bitmap, &pixels) != ANDROID_BITMAP_RESULT_SUCCESS) return;
|
||||
overlay_.setLogo(pixels, (int)info.width, (int)info.height, (int)info.stride);
|
||||
AndroidBitmap_unlockPixels(env, bitmap);
|
||||
}
|
||||
|
||||
void destroyLayer(JNIEnv *env, int index) {
|
||||
if (!onXrThread() || index < 0 || index >= DROIDDECK_XR_HOST_LAYERS) return;
|
||||
SurfaceLayer &layer = layers_[index];
|
||||
if (layer.swapchain) xrDestroySwapchain(layer.swapchain);
|
||||
if (layer.surface) env->DeleteGlobalRef(layer.surface);
|
||||
layer = {};
|
||||
}
|
||||
|
||||
private:
|
||||
android_app *app_;
|
||||
JNIEnv *env_ = nullptr;
|
||||
@@ -104,6 +171,20 @@ private:
|
||||
XrAction primary_ = XR_NULL_HANDLE, secondary_ = XR_NULL_HANDLE, menu_ = XR_NULL_HANDLE;
|
||||
XrAction triggerTouch_ = XR_NULL_HANDLE, stickTouch_ = XR_NULL_HANDLE, primaryTouch_ = XR_NULL_HANDLE;
|
||||
XrAction secondaryTouch_ = XR_NULL_HANDLE, thumbrestTouch_ = XR_NULL_HANDLE;
|
||||
PFN_xrCreateSwapchainAndroidSurfaceKHR createSurfaceSwapchain_ = nullptr;
|
||||
bool surfaceSupported_ = false;
|
||||
bool imageLayoutSupported_ = false;
|
||||
pthread_t xrThread_{};
|
||||
SurfaceLayer layers_[DROIDDECK_XR_HOST_LAYERS];
|
||||
DroidDeckXrHostState hostState_{};
|
||||
DroidDeckXrHostControl hostControl_{};
|
||||
bool hostBuffers_ = false;
|
||||
jmethodID hostFrameCallback_ = nullptr;
|
||||
uint64_t hostPulse_[2]{};
|
||||
int visibleLayers_ = 0;
|
||||
XrOverlay overlay_;
|
||||
Eye overlayEyes_[2];
|
||||
GLuint overlayDepth_[2]{};
|
||||
DroidDeckXrHand inputs_[2]{};
|
||||
PFN_xrConvertTimeToTimespecTimeKHR convertTime_ = nullptr;
|
||||
bool timespecSupported_ = false;
|
||||
@@ -220,6 +301,8 @@ private:
|
||||
|
||||
void initialize() {
|
||||
app_->userData = this;
|
||||
xrThread_ = pthread_self();
|
||||
g_runtime = this;
|
||||
app_->onInputEvent = [](android_app *app, AInputEvent *event) -> int32_t {
|
||||
if (AInputEvent_getType(event) != AINPUT_EVENT_TYPE_KEY || AKeyEvent_getKeyCode(event) != AKEYCODE_BACK
|
||||
|| AKeyEvent_getAction(event) != AKEY_EVENT_ACTION_UP) return 0;
|
||||
@@ -244,6 +327,10 @@ private:
|
||||
frameCallback_ = env_->GetMethodID(activityClass, "onXrFrame", "(J)V");
|
||||
statusCallback_ = env_->GetMethodID(activityClass, "onXrStatus", "()I");
|
||||
if (env_->ExceptionCheck()) { env_->ExceptionClear(); throw std::runtime_error("XR activity bridge methods unavailable"); }
|
||||
hostFrameCallback_ = env_->GetMethodID(activityClass, "onXrHostFrame", "()V");
|
||||
jmethodID hostBuffersCallback = hostFrameCallback_ ?
|
||||
env_->GetMethodID(activityClass, "onXrHostBuffers", "(Ljava/nio/ByteBuffer;Ljava/nio/ByteBuffer;)V") : nullptr;
|
||||
if (env_->ExceptionCheck()) { env_->ExceptionClear(); hostFrameCallback_ = nullptr; hostBuffersCallback = nullptr; }
|
||||
env_->DeleteLocalRef(intentClass); env_->DeleteLocalRef(intent); env_->DeleteLocalRef(activityClass);
|
||||
PFN_xrInitializeLoaderKHR initializeLoader = nullptr;
|
||||
check(xrGetInstanceProcAddr(XR_NULL_HANDLE, "xrInitializeLoaderKHR",
|
||||
@@ -261,10 +348,21 @@ private:
|
||||
timespecSupported_ = true;
|
||||
if (!std::strcmp(extension.extensionName, XR_EXT_PERFORMANCE_SETTINGS_EXTENSION_NAME))
|
||||
performanceSupported_ = true;
|
||||
if (!std::strcmp(extension.extensionName, XR_KHR_ANDROID_SURFACE_SWAPCHAIN_EXTENSION_NAME))
|
||||
surfaceSupported_ = true;
|
||||
if (!std::strcmp(extension.extensionName, XR_FB_COMPOSITION_LAYER_IMAGE_LAYOUT_EXTENSION_NAME))
|
||||
imageLayoutSupported_ = true;
|
||||
}
|
||||
__android_log_print(ANDROID_LOG_INFO, "DroidDeckXR", "surface swapchain available=%d image layout=%d",
|
||||
surfaceSupported_, imageLayoutSupported_);
|
||||
// A surface swapchain's image arrives upside down, and a quad's back face is not drawn, so
|
||||
// panels need the layout flag to flip it.
|
||||
surfaceSupported_ = surfaceSupported_ && imageLayoutSupported_;
|
||||
std::vector<const char *> enabled{XR_KHR_ANDROID_CREATE_INSTANCE_EXTENSION_NAME, XR_KHR_OPENGL_ES_ENABLE_EXTENSION_NAME};
|
||||
if (timespecSupported_) enabled.push_back(XR_KHR_CONVERT_TIMESPEC_TIME_EXTENSION_NAME);
|
||||
if (performanceSupported_) enabled.push_back(XR_EXT_PERFORMANCE_SETTINGS_EXTENSION_NAME);
|
||||
if (surfaceSupported_) enabled.push_back(XR_KHR_ANDROID_SURFACE_SWAPCHAIN_EXTENSION_NAME);
|
||||
if (surfaceSupported_) enabled.push_back(XR_FB_COMPOSITION_LAYER_IMAGE_LAYOUT_EXTENSION_NAME);
|
||||
XrInstanceCreateInfoAndroidKHR androidInfo{XR_TYPE_INSTANCE_CREATE_INFO_ANDROID_KHR};
|
||||
androidInfo.applicationVM = app_->activity->vm;
|
||||
androidInfo.applicationActivity = app_->activity->clazz;
|
||||
@@ -281,6 +379,11 @@ private:
|
||||
reinterpret_cast<PFN_xrVoidFunction *>(&setPerformance_));
|
||||
if (XR_FAILED(result)) setPerformance_ = nullptr;
|
||||
}
|
||||
if (surfaceSupported_ && XR_FAILED(xrGetInstanceProcAddr(instance_, "xrCreateSwapchainAndroidSurfaceKHR",
|
||||
reinterpret_cast<PFN_xrVoidFunction *>(&createSurfaceSwapchain_)))) {
|
||||
createSurfaceSwapchain_ = nullptr;
|
||||
surfaceSupported_ = false;
|
||||
}
|
||||
if (timespecSupported_) check(xrGetInstanceProcAddr(instance_, "xrConvertTimeToTimespecTimeKHR",
|
||||
reinterpret_cast<PFN_xrVoidFunction *>(&convertTime_)), "time conversion entrypoint");
|
||||
XrSystemGetInfo systemInfo{XR_TYPE_SYSTEM_GET_INFO};
|
||||
@@ -334,6 +437,16 @@ private:
|
||||
bool gpu = !verifyPixels_ && gpuFrames_.Start(std::string(app_->activity->internalDataPath) + "/.wayland-rt/" DROIDDECK_XR_GPU_SOCKET, display_);
|
||||
__android_log_print(ANDROID_LOG_INFO, "DroidDeckXR", "GPU frame channel available=%d", gpu);
|
||||
}
|
||||
overlay_.initialize();
|
||||
hostState_.version = DROIDDECK_XR_HOST_VERSION;
|
||||
if (hostBuffersCallback) {
|
||||
jobject state = env_->NewDirectByteBuffer(&hostState_, sizeof(hostState_));
|
||||
jobject control = env_->NewDirectByteBuffer(&hostControl_, sizeof(hostControl_));
|
||||
env_->CallVoidMethod(app_->activity->clazz, hostBuffersCallback, state, control);
|
||||
if (env_->ExceptionCheck()) { env_->ExceptionDescribe(); env_->ExceptionClear(); hostFrameCallback_ = nullptr; }
|
||||
else hostBuffers_ = true;
|
||||
env_->DeleteLocalRef(state); env_->DeleteLocalRef(control);
|
||||
}
|
||||
health();
|
||||
}
|
||||
|
||||
@@ -422,6 +535,13 @@ private:
|
||||
target.images.resize(count, {XR_TYPE_SWAPCHAIN_IMAGE_OPENGL_ES_KHR});
|
||||
check(xrEnumerateSwapchainImages(target.swapchain, count, &count,
|
||||
reinterpret_cast<XrSwapchainImageBaseHeader *>(target.images.data())), "images");
|
||||
Eye &overlay = overlayEyes_[eye];
|
||||
overlay.width = target.width; overlay.height = target.height;
|
||||
check(xrCreateSwapchain(session_, &create, &overlay.swapchain), "overlay swapchain");
|
||||
check(xrEnumerateSwapchainImages(overlay.swapchain, 0, &count, nullptr), "overlay image count");
|
||||
overlay.images.resize(count, {XR_TYPE_SWAPCHAIN_IMAGE_OPENGL_ES_KHR});
|
||||
check(xrEnumerateSwapchainImages(overlay.swapchain, count, &count,
|
||||
reinterpret_cast<XrSwapchainImageBaseHeader *>(overlay.images.data())), "overlay images");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -530,6 +650,12 @@ private:
|
||||
|
||||
void initializeGraphics() {
|
||||
glGenFramebuffers(1, &framebuffer_);
|
||||
glGenRenderbuffers(2, overlayDepth_);
|
||||
for (int eye = 0; eye < 2; eye++) {
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, overlayDepth_[eye]);
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, overlayEyes_[eye].width, overlayEyes_[eye].height);
|
||||
}
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, 0);
|
||||
glGenVertexArrays(1, &vertexArray_);
|
||||
GLuint vertex = shader(GL_VERTEX_SHADER,
|
||||
"#version 300 es\nout vec2 uv; uniform float eye; void main(){vec2 coordinate=vec2(float((gl_VertexID<<1)&2),float(gl_VertexID&2));uv=vec2(coordinate.x*0.5+eye*0.5,1.0-coordinate.y);gl_Position=vec4(coordinate*2.0-1.0,0.0,1.0);}");
|
||||
@@ -584,24 +710,46 @@ private:
|
||||
if (verifyPixels_ || uploadedFrames_ % 72 == 1) health();
|
||||
}
|
||||
|
||||
void render(Eye &eye, uint32_t image) {
|
||||
void render(Eye &eye, uint32_t image, bool source, const XrPosef &pose, const XrFovf &fov, float seconds) {
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer_);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, eye.images[image].image, 0);
|
||||
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
|
||||
throw std::runtime_error("Incomplete eye framebuffer");
|
||||
{
|
||||
glViewport(0, 0, eye.width, eye.height); glDisable(GL_DEPTH_TEST);
|
||||
glViewport(0, 0, eye.width, eye.height); glDisable(GL_DEPTH_TEST);
|
||||
if (source) {
|
||||
glUseProgram(sourceProgram_); glBindVertexArray(vertexArray_);
|
||||
glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, sourceTexture_);
|
||||
glUniform1i(glGetUniformLocation(sourceProgram_, "source"), 0);
|
||||
glUniform1f(glGetUniformLocation(sourceProgram_, "eye"), &eye == &eyes_[1] ? 1.f : 0.f);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 3);
|
||||
} else {
|
||||
glClearColor(0.f, 0.f, 0.f, 1.f);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
}
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
if (glGetError() != GL_NO_ERROR) throw std::runtime_error("OpenGL render error");
|
||||
glFlush();
|
||||
}
|
||||
|
||||
// Lasers and the orb go in their own layer above the panels, which only the panels' depth hides.
|
||||
void renderOverlay(int index, uint32_t image, const XrPosef &pose, const XrFovf &fov, float seconds) {
|
||||
Eye &eye = overlayEyes_[index];
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer_);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, eye.images[image].image, 0);
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, overlayDepth_[index]);
|
||||
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
|
||||
throw std::runtime_error("Incomplete overlay framebuffer");
|
||||
glViewport(0, 0, eye.width, eye.height);
|
||||
glClearColor(0.f, 0.f, 0.f, 0.f); glClearDepthf(1.f);
|
||||
glDepthMask(GL_TRUE);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
overlay_.draw(pose, fov, hostControl_, hostState_, seconds);
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, 0);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
if (glGetError() != GL_NO_ERROR) throw std::runtime_error("OpenGL overlay error");
|
||||
glFlush();
|
||||
}
|
||||
|
||||
void pollEvents() {
|
||||
XrEventDataBuffer event{XR_TYPE_EVENT_DATA_BUFFER};
|
||||
XrResult result;
|
||||
@@ -685,6 +833,7 @@ private:
|
||||
XrViewState viewState{XR_TYPE_VIEW_STATE}; uint32_t count = 0;
|
||||
XrView views[2]{{XR_TYPE_VIEW}, {XR_TYPE_VIEW}};
|
||||
check(xrLocateViews(session_, &locate, &viewState, 2, &count, views), "xrLocateViews");
|
||||
hostFrame(frameState.predictedDisplayTime);
|
||||
publishTracking(views, frameState.predictedDisplayTime);
|
||||
if (guestAttached_) {
|
||||
timespec now{}; clock_gettime(CLOCK_MONOTONIC, &now);
|
||||
@@ -692,29 +841,34 @@ private:
|
||||
if (env_->ExceptionCheck()) { env_->ExceptionClear(); throw std::runtime_error("Guest frame callback failed"); }
|
||||
}
|
||||
XrCompositionLayerProjectionView projection[2]{{XR_TYPE_COMPOSITION_LAYER_PROJECTION_VIEW}, {XR_TYPE_COMPOSITION_LAYER_PROJECTION_VIEW}};
|
||||
bool valid = frameState.shouldRender && count == 2 &&
|
||||
const bool viewsValid = frameState.shouldRender && count == 2 &&
|
||||
(viewState.viewStateFlags & (XR_VIEW_STATE_ORIENTATION_VALID_BIT | XR_VIEW_STATE_POSITION_VALID_BIT))
|
||||
== (XR_VIEW_STATE_ORIENTATION_VALID_BIT | XR_VIEW_STATE_POSITION_VALID_BIT);
|
||||
{
|
||||
valid = valid && sourceHeader_.frame_id && xr_frame_now() - sourceHeader_.captured_ns < 500000000LL;
|
||||
if (valid) for (int eye = 0; eye < 2; eye++) {
|
||||
auto source = xr_frame_view(sourceHeader_, eye);
|
||||
views[eye].pose.orientation = {source.orientation[0], source.orientation[1], source.orientation[2], source.orientation[3]};
|
||||
views[eye].pose.position = {source.position[0], source.position[1], source.position[2]};
|
||||
views[eye].fov = {source.fov[0], source.fov[1], source.fov[2], source.fov[3]};
|
||||
}
|
||||
bool valid = viewsValid && sourceHeader_.frame_id && xr_frame_now() - sourceHeader_.captured_ns < 500000000LL;
|
||||
if (valid) for (int eye = 0; eye < 2; eye++) {
|
||||
auto source = xr_frame_view(sourceHeader_, eye);
|
||||
views[eye].pose.orientation = {source.orientation[0], source.orientation[1], source.orientation[2], source.orientation[3]};
|
||||
views[eye].pose.position = {source.position[0], source.position[1], source.position[2]};
|
||||
views[eye].fov = {source.fov[0], source.fov[1], source.fov[2], source.fov[3]};
|
||||
}
|
||||
std::vector<XrCompositionLayerQuad> quads;
|
||||
std::vector<XrCompositionLayerImageLayoutFB> layouts;
|
||||
if (viewsValid) collectQuads(quads, layouts);
|
||||
const bool uiOnly = !valid && viewsValid && !quads.empty();
|
||||
const bool draw = valid || uiOnly;
|
||||
const std::string capture = captureRequest();
|
||||
bool captured = valid;
|
||||
if (!capture.empty() && valid)
|
||||
captured = captureTexture(sourceTexture_, sourceHeader_.width, sourceHeader_.height, "source");
|
||||
if (valid) for (int eye = 0; eye < 2; eye++) {
|
||||
timespec clock{}; clock_gettime(CLOCK_MONOTONIC, &clock);
|
||||
const float seconds = (float)(clock.tv_sec % 3600) + clock.tv_nsec * 1e-9f;
|
||||
if (draw) for (int eye = 0; eye < 2; eye++) {
|
||||
uint32_t image = 0;
|
||||
XrSwapchainImageAcquireInfo acquire{XR_TYPE_SWAPCHAIN_IMAGE_ACQUIRE_INFO};
|
||||
check(xrAcquireSwapchainImage(eyes_[eye].swapchain, &acquire, &image), "acquire image");
|
||||
XrSwapchainImageWaitInfo imageWait{XR_TYPE_SWAPCHAIN_IMAGE_WAIT_INFO}; imageWait.timeout = XR_INFINITE_DURATION;
|
||||
check(xrWaitSwapchainImage(eyes_[eye].swapchain, &imageWait), "wait image");
|
||||
render(eyes_[eye], image);
|
||||
render(eyes_[eye], image, valid, views[eye].pose, views[eye].fov, seconds);
|
||||
if (!capture.empty()) captured = captureTexture(eyes_[eye].images[image].image, eyes_[eye].width, eyes_[eye].height, eye ? "right" : "left") && captured;
|
||||
XrSwapchainImageReleaseInfo release{XR_TYPE_SWAPCHAIN_IMAGE_RELEASE_INFO};
|
||||
check(xrReleaseSwapchainImage(eyes_[eye].swapchain, &release), "release image");
|
||||
@@ -722,19 +876,143 @@ private:
|
||||
projection[eye].subImage.swapchain = eyes_[eye].swapchain;
|
||||
projection[eye].subImage.imageRect.extent = {eyes_[eye].width, eyes_[eye].height};
|
||||
}
|
||||
const bool overlay = viewsValid && hostBuffers_ && XrOverlay::active(hostControl_);
|
||||
XrCompositionLayerProjectionView overlayViews[2]{{XR_TYPE_COMPOSITION_LAYER_PROJECTION_VIEW}, {XR_TYPE_COMPOSITION_LAYER_PROJECTION_VIEW}};
|
||||
if (overlay) for (int eye = 0; eye < 2; eye++) {
|
||||
uint32_t image = 0;
|
||||
XrSwapchainImageAcquireInfo acquire{XR_TYPE_SWAPCHAIN_IMAGE_ACQUIRE_INFO};
|
||||
check(xrAcquireSwapchainImage(overlayEyes_[eye].swapchain, &acquire, &image), "acquire overlay image");
|
||||
XrSwapchainImageWaitInfo imageWait{XR_TYPE_SWAPCHAIN_IMAGE_WAIT_INFO}; imageWait.timeout = XR_INFINITE_DURATION;
|
||||
check(xrWaitSwapchainImage(overlayEyes_[eye].swapchain, &imageWait), "wait overlay image");
|
||||
renderOverlay(eye, image, views[eye].pose, views[eye].fov, seconds);
|
||||
XrSwapchainImageReleaseInfo release{XR_TYPE_SWAPCHAIN_IMAGE_RELEASE_INFO};
|
||||
check(xrReleaseSwapchainImage(overlayEyes_[eye].swapchain, &release), "release overlay image");
|
||||
overlayViews[eye].pose = views[eye].pose; overlayViews[eye].fov = views[eye].fov;
|
||||
overlayViews[eye].subImage.swapchain = overlayEyes_[eye].swapchain;
|
||||
overlayViews[eye].subImage.imageRect.extent = {overlayEyes_[eye].width, overlayEyes_[eye].height};
|
||||
}
|
||||
XrCompositionLayerProjection layer{XR_TYPE_COMPOSITION_LAYER_PROJECTION};
|
||||
layer.space = world_; layer.viewCount = 2; layer.views = projection;
|
||||
const XrCompositionLayerBaseHeader *layers[] = {reinterpret_cast<XrCompositionLayerBaseHeader *>(&layer)};
|
||||
XrCompositionLayerProjection overlayLayer{XR_TYPE_COMPOSITION_LAYER_PROJECTION};
|
||||
overlayLayer.layerFlags = XR_COMPOSITION_LAYER_BLEND_TEXTURE_SOURCE_ALPHA_BIT;
|
||||
overlayLayer.space = world_; overlayLayer.viewCount = 2; overlayLayer.views = overlayViews;
|
||||
std::vector<const XrCompositionLayerBaseHeader *> layers;
|
||||
if (draw) layers.push_back(reinterpret_cast<XrCompositionLayerBaseHeader *>(&layer));
|
||||
for (auto &quad : quads) layers.push_back(reinterpret_cast<XrCompositionLayerBaseHeader *>(&quad));
|
||||
if (overlay) layers.push_back(reinterpret_cast<XrCompositionLayerBaseHeader *>(&overlayLayer));
|
||||
visibleLayers_ = (int)quads.size();
|
||||
XrFrameEndInfo end{XR_TYPE_FRAME_END_INFO}; end.displayTime = frameState.predictedDisplayTime;
|
||||
end.environmentBlendMode = XR_ENVIRONMENT_BLEND_MODE_OPAQUE; end.layerCount = valid ? 1 : 0; end.layers = layers;
|
||||
end.environmentBlendMode = XR_ENVIRONMENT_BLEND_MODE_OPAQUE;
|
||||
end.layerCount = (uint32_t)layers.size(); end.layers = layers.data();
|
||||
check(xrEndFrame(session_, &end), "xrEndFrame");
|
||||
if (!capture.empty()) captureResult(capture, captured, valid, projection, frameState.predictedDisplayTime);
|
||||
frames_++; if (valid) rendered_++;
|
||||
if (frames_ % 72 == 0) {
|
||||
health();
|
||||
__android_log_print(ANDROID_LOG_INFO, "DroidDeckXR", "frames=%llu rendered=%llu head=%llu hands=%d,%d period=%lld",
|
||||
__android_log_print(ANDROID_LOG_INFO, "DroidDeckXR", "frames=%llu rendered=%llu head=%llu hands=%d,%d period=%lld layers=%d",
|
||||
(unsigned long long)frames_, (unsigned long long)rendered_, (unsigned long long)head_.locationFlags,
|
||||
handActive_[0], handActive_[1], (long long)period_);
|
||||
handActive_[0], handActive_[1], (long long)period_, visibleLayers_);
|
||||
}
|
||||
}
|
||||
|
||||
// Android surfaces are stored top row first, while OpenXR samples images bottom row first.
|
||||
void collectQuads(std::vector<XrCompositionLayerQuad> &quads, std::vector<XrCompositionLayerImageLayoutFB> &layouts) {
|
||||
if (!hostBuffers_) return;
|
||||
quads.reserve(DROIDDECK_XR_HOST_LAYERS);
|
||||
layouts.reserve(DROIDDECK_XR_HOST_LAYERS);
|
||||
const DroidDeckXrHostLayer *ordered[DROIDDECK_XR_HOST_LAYERS];
|
||||
int visible = 0;
|
||||
for (const auto &layer : hostControl_.layers) {
|
||||
if (!layer.visible || layer.id < 0 || layer.id >= DROIDDECK_XR_HOST_LAYERS || !layers_[layer.id].swapchain) continue;
|
||||
if (!(layer.width > 0.f) || !(layer.height > 0.f)) continue;
|
||||
ordered[visible++] = &layer;
|
||||
}
|
||||
std::sort(ordered, ordered + visible, [](const DroidDeckXrHostLayer *a, const DroidDeckXrHostLayer *b) { return a->order < b->order; });
|
||||
for (int index = 0; index < visible; index++) {
|
||||
const auto &layer = *ordered[index];
|
||||
const SurfaceLayer &surface = layers_[layer.id];
|
||||
XrCompositionLayerQuad quad{XR_TYPE_COMPOSITION_LAYER_QUAD};
|
||||
quad.layerFlags = (layer.flags & DROIDDECK_XR_HOST_LAYER_ALPHA) ? XR_COMPOSITION_LAYER_BLEND_TEXTURE_SOURCE_ALPHA_BIT : 0;
|
||||
quad.space = (layer.flags & DROIDDECK_XR_HOST_LAYER_HEAD_LOCKED) ? view_ : world_;
|
||||
quad.eyeVisibility = XR_EYE_VISIBILITY_BOTH;
|
||||
quad.subImage.swapchain = surface.swapchain;
|
||||
quad.subImage.imageRect.extent = {surface.width, surface.height};
|
||||
quad.pose.orientation = {layer.pose.orientation[0], layer.pose.orientation[1], layer.pose.orientation[2], layer.pose.orientation[3]};
|
||||
quad.pose.position = {layer.pose.position[0], layer.pose.position[1], layer.pose.position[2]};
|
||||
quad.size = {layer.width, layer.height};
|
||||
layouts.push_back({XR_TYPE_COMPOSITION_LAYER_IMAGE_LAYOUT_FB, nullptr, XR_COMPOSITION_LAYER_IMAGE_LAYOUT_VERTICAL_FLIP_BIT_FB});
|
||||
quad.next = &layouts.back();
|
||||
quads.push_back(quad);
|
||||
}
|
||||
}
|
||||
|
||||
// SteamVR draws its laser from the "tip" of the Quest Touch render model the driver names
|
||||
// (resources/rendermodels/oculus_quest_plus_controller_*), placed on the raw grip pose; panels
|
||||
// use the same ray so there is one laser per controller.
|
||||
static DroidDeckXrPose steamVrPointer(const XrSpaceLocation &grip, int hand) {
|
||||
const float q[4] = {grip.pose.orientation.x, grip.pose.orientation.y, grip.pose.orientation.z, grip.pose.orientation.w};
|
||||
const XrVec3 tip{hand == 0 ? 0.016694f : -0.016694f, -0.02522f, 0.024687f};
|
||||
const XrVec3 at = XrVec3{grip.pose.position.x, grip.pose.position.y, grip.pose.position.z} + rotate(q, tip);
|
||||
const float tx = -0.320613f, tw = 0.947210f;
|
||||
DroidDeckXrPose pose{};
|
||||
pose.orientation[0] = q[3] * tx + q[0] * tw;
|
||||
pose.orientation[1] = q[1] * tw + q[2] * tx;
|
||||
pose.orientation[2] = q[2] * tw - q[1] * tx;
|
||||
pose.orientation[3] = q[3] * tw - q[0] * tx;
|
||||
pose.position[0] = at.x; pose.position[1] = at.y; pose.position[2] = at.z;
|
||||
pose.flags = (uint32_t)grip.locationFlags;
|
||||
return pose;
|
||||
}
|
||||
|
||||
void hostFrame(XrTime predicted) {
|
||||
if (!hostBuffers_ || !hostFrameCallback_) return;
|
||||
hostState_.version = DROIDDECK_XR_HOST_VERSION;
|
||||
hostState_.session_state = state_;
|
||||
hostState_.flags = (surfaceSupported_ ? DROIDDECK_XR_HOST_SURFACE_SWAPCHAIN : 0u) |
|
||||
(state_ == XR_SESSION_STATE_FOCUSED ? DROIDDECK_XR_HOST_FOCUSED : 0u);
|
||||
hostState_.frame = (int64_t)frames_;
|
||||
hostState_.display_time_ns = 0;
|
||||
if (convertTime_) {
|
||||
timespec displayTime{};
|
||||
if (XR_SUCCEEDED(convertTime_(instance_, predicted, &displayTime)))
|
||||
hostState_.display_time_ns = (int64_t)displayTime.tv_sec * 1000000000LL + displayTime.tv_nsec;
|
||||
}
|
||||
hostState_.head = posePacket(head_.pose, head_.locationFlags);
|
||||
const XrSpaceLocationFlags tracked = XR_SPACE_LOCATION_ORIENTATION_VALID_BIT | XR_SPACE_LOCATION_POSITION_VALID_BIT;
|
||||
for (int hand = 0; hand < 2; hand++) {
|
||||
auto &out = hostState_.hands[hand];
|
||||
out.grip = posePacket(handLocations_[hand].pose, handLocations_[hand].locationFlags);
|
||||
out.aim = steamVrPointer(handLocations_[hand], hand);
|
||||
out.trigger = inputs_[hand].trigger; out.squeeze = inputs_[hand].squeeze;
|
||||
out.stick[0] = inputs_[hand].stick[0]; out.stick[1] = inputs_[hand].stick[1];
|
||||
out.buttons = inputs_[hand].buttons;
|
||||
out.active = handActive_[hand] && (handLocations_[hand].locationFlags & tracked) == tracked;
|
||||
}
|
||||
env_->CallVoidMethod(app_->activity->clazz, hostFrameCallback_);
|
||||
if (env_->ExceptionCheck()) {
|
||||
env_->ExceptionDescribe(); env_->ExceptionClear();
|
||||
hostControl_ = {};
|
||||
return;
|
||||
}
|
||||
if (hostControl_.version != DROIDDECK_XR_HOST_VERSION) { hostControl_ = {}; return; }
|
||||
for (int hand = 0; hand < 2; hand++) {
|
||||
const auto &control = hostControl_.hands[hand];
|
||||
if (control.mask & DROIDDECK_XR_HOST_MASK_INPUT) {
|
||||
inputs_[hand].trigger = 0; inputs_[hand].squeeze = 0;
|
||||
inputs_[hand].stick[0] = inputs_[hand].stick[1] = 0;
|
||||
inputs_[hand].buttons = 0;
|
||||
}
|
||||
const auto &pulse = control.haptic;
|
||||
if (pulse.id == hostPulse_[hand]) continue;
|
||||
hostPulse_[hand] = pulse.id;
|
||||
if (state_ != XR_SESSION_STATE_FOCUSED || !handActive_[hand]
|
||||
|| pulse.duration_ns < 1000000 || pulse.duration_ns > 1000000000
|
||||
|| !std::isfinite(pulse.amplitude) || pulse.amplitude < 0 || pulse.amplitude > 1
|
||||
|| !std::isfinite(pulse.frequency) || pulse.frequency < 0) continue;
|
||||
XrHapticActionInfo info{XR_TYPE_HAPTIC_ACTION_INFO}; info.action = vibration_; info.subactionPath = hands_[hand];
|
||||
XrHapticVibration vibration{XR_TYPE_HAPTIC_VIBRATION};
|
||||
vibration.duration = pulse.duration_ns; vibration.amplitude = pulse.amplitude; vibration.frequency = pulse.frequency;
|
||||
check(xrApplyHapticFeedback(session_, &info, reinterpret_cast<XrHapticBaseHeader *>(&vibration)), "host haptics");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -749,11 +1027,17 @@ private:
|
||||
munmap(tracking_, sizeof(DroidDeckXrTracking));
|
||||
}
|
||||
if (haptics_) munmap(haptics_, sizeof(DroidDeckXrHaptics));
|
||||
g_runtime = nullptr;
|
||||
hostBuffers_ = false;
|
||||
if (display_ != EGL_NO_DISPLAY && context_ != EGL_NO_CONTEXT) {
|
||||
glDeleteFramebuffers(1, &framebuffer_); glDeleteVertexArrays(1, &vertexArray_);
|
||||
glDeleteTextures(1, &cpuTexture_); glDeleteProgram(sourceProgram_);
|
||||
glDeleteRenderbuffers(2, overlayDepth_);
|
||||
overlay_.destroy();
|
||||
}
|
||||
if (env_) for (int index = 0; index < DROIDDECK_XR_HOST_LAYERS; index++) destroyLayer(env_, index);
|
||||
for (auto &eye : eyes_) if (eye.swapchain) xrDestroySwapchain(eye.swapchain);
|
||||
for (auto &eye : overlayEyes_) if (eye.swapchain) xrDestroySwapchain(eye.swapchain);
|
||||
for (auto space : handSpaces_) if (space) xrDestroySpace(space);
|
||||
if (view_) xrDestroySpace(view_); if (world_) xrDestroySpace(world_);
|
||||
if (session_) xrDestroySession(session_);
|
||||
@@ -769,6 +1053,26 @@ private:
|
||||
}
|
||||
};
|
||||
|
||||
extern "C" JNIEXPORT jint JNICALL
|
||||
Java_com_droiddeck_launcher_QuestXrActivity_nativeCreateLayer(JNIEnv *env, jobject, jint width, jint height) {
|
||||
return g_runtime ? g_runtime->createLayer(env, width, height) : -1;
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jobject JNICALL
|
||||
Java_com_droiddeck_launcher_QuestXrActivity_nativeLayerSurface(JNIEnv *env, jobject, jint index) {
|
||||
return g_runtime ? g_runtime->layerSurface(env, index) : nullptr;
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_droiddeck_launcher_QuestXrActivity_nativeDestroyLayer(JNIEnv *env, jobject, jint index) {
|
||||
if (g_runtime) g_runtime->destroyLayer(env, index);
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL
|
||||
Java_com_droiddeck_launcher_QuestXrActivity_nativeSetOrbImage(JNIEnv *env, jobject, jobject bitmap) {
|
||||
if (g_runtime) g_runtime->setOrbImage(env, bitmap);
|
||||
}
|
||||
|
||||
void android_main(android_app *app) {
|
||||
QuestXR runtime(app);
|
||||
try { runtime.run(); }
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
#pragma once
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include "xr_tracking.h"
|
||||
|
||||
// Shared with com.droiddeck.launcher.session.xr.XrHost, which reads and writes these through direct
|
||||
// ByteBuffers by fixed offset: any layout change must bump the version and update both sides.
|
||||
#define DROIDDECK_XR_HOST_VERSION 1u
|
||||
#define DROIDDECK_XR_HOST_LAYERS 6
|
||||
|
||||
#define DROIDDECK_XR_HOST_SURFACE_SWAPCHAIN (1u << 0)
|
||||
#define DROIDDECK_XR_HOST_FOCUSED (1u << 1)
|
||||
|
||||
#define DROIDDECK_XR_HOST_MASK_INPUT (1u << 0)
|
||||
|
||||
#define DROIDDECK_XR_HOST_LAYER_ALPHA (1u << 0)
|
||||
#define DROIDDECK_XR_HOST_LAYER_HEAD_LOCKED (1u << 1)
|
||||
|
||||
struct DroidDeckXrHostHand {
|
||||
DroidDeckXrPose grip;
|
||||
DroidDeckXrPose aim;
|
||||
float trigger, squeeze, stick[2];
|
||||
uint32_t buttons, active;
|
||||
uint32_t reserved[2];
|
||||
};
|
||||
|
||||
struct DroidDeckXrHostState {
|
||||
uint32_t version, session_state, flags, reserved0;
|
||||
int64_t frame, display_time_ns;
|
||||
DroidDeckXrPose head;
|
||||
DroidDeckXrHostHand hands[2];
|
||||
uint32_t reserved[8];
|
||||
};
|
||||
|
||||
struct DroidDeckXrHostHaptic {
|
||||
uint64_t id;
|
||||
int64_t duration_ns;
|
||||
float amplitude, frequency;
|
||||
};
|
||||
|
||||
struct DroidDeckXrHostHandControl {
|
||||
uint32_t mask;
|
||||
float laser;
|
||||
DroidDeckXrHostHaptic haptic;
|
||||
uint32_t reserved[2];
|
||||
};
|
||||
|
||||
struct DroidDeckXrHostOrb {
|
||||
uint32_t visible;
|
||||
float progress, burst, radius;
|
||||
DroidDeckXrPose pose;
|
||||
};
|
||||
|
||||
struct DroidDeckXrHostLayer {
|
||||
int32_t id;
|
||||
uint32_t visible, flags;
|
||||
int32_t order;
|
||||
DroidDeckXrPose pose;
|
||||
float width, height;
|
||||
uint32_t reserved[2];
|
||||
};
|
||||
|
||||
struct DroidDeckXrHostControl {
|
||||
uint32_t version, reserved0;
|
||||
DroidDeckXrHostHandControl hands[2];
|
||||
DroidDeckXrHostOrb orb;
|
||||
DroidDeckXrHostLayer layers[DROIDDECK_XR_HOST_LAYERS];
|
||||
uint32_t reserved[8];
|
||||
};
|
||||
|
||||
static_assert(sizeof(DroidDeckXrHostHand) == 96, "XR host hand layout");
|
||||
static_assert(offsetof(DroidDeckXrHostHand, aim) == 32 && offsetof(DroidDeckXrHostHand, trigger) == 64 &&
|
||||
offsetof(DroidDeckXrHostHand, stick) == 72 && offsetof(DroidDeckXrHostHand, buttons) == 80 &&
|
||||
offsetof(DroidDeckXrHostHand, active) == 84, "XR host hand layout");
|
||||
static_assert(offsetof(DroidDeckXrHostState, flags) == 8 && offsetof(DroidDeckXrHostState, frame) == 16 &&
|
||||
offsetof(DroidDeckXrHostState, head) == 32, "XR host state layout");
|
||||
static_assert(offsetof(DroidDeckXrHostHandControl, laser) == 4 && offsetof(DroidDeckXrHostHandControl, haptic) == 8,
|
||||
"XR host hand control layout");
|
||||
static_assert(offsetof(DroidDeckXrHostHaptic, duration_ns) == 8 && offsetof(DroidDeckXrHostHaptic, amplitude) == 16,
|
||||
"XR host haptic layout");
|
||||
static_assert(offsetof(DroidDeckXrHostOrb, progress) == 4 && offsetof(DroidDeckXrHostOrb, pose) == 16, "XR host orb layout");
|
||||
static_assert(offsetof(DroidDeckXrHostLayer, order) == 12 && offsetof(DroidDeckXrHostLayer, pose) == 16 &&
|
||||
offsetof(DroidDeckXrHostLayer, width) == 48, "XR host layer layout");
|
||||
static_assert(sizeof(DroidDeckXrHostState) == 288, "XR host state layout");
|
||||
static_assert(offsetof(DroidDeckXrHostState, hands) == 64, "XR host state layout");
|
||||
static_assert(sizeof(DroidDeckXrHostHandControl) == 40, "XR host hand control layout");
|
||||
static_assert(sizeof(DroidDeckXrHostOrb) == 48, "XR host orb layout");
|
||||
static_assert(sizeof(DroidDeckXrHostLayer) == 64, "XR host layer layout");
|
||||
static_assert(offsetof(DroidDeckXrHostControl, orb) == 88, "XR host control layout");
|
||||
static_assert(offsetof(DroidDeckXrHostControl, layers) == 136, "XR host control layout");
|
||||
static_assert(sizeof(DroidDeckXrHostControl) == 552, "XR host control layout");
|
||||
@@ -0,0 +1,229 @@
|
||||
#pragma once
|
||||
#include <GLES3/gl3.h>
|
||||
#include <openxr/openxr.h>
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <stdexcept>
|
||||
#include "xr_host.h"
|
||||
|
||||
struct XrVec3 { float x, y, z; };
|
||||
|
||||
static inline XrVec3 xrv(float x, float y, float z) { return {x, y, z}; }
|
||||
static inline XrVec3 operator+(XrVec3 a, XrVec3 b) { return {a.x + b.x, a.y + b.y, a.z + b.z}; }
|
||||
static inline XrVec3 operator-(XrVec3 a, XrVec3 b) { return {a.x - b.x, a.y - b.y, a.z - b.z}; }
|
||||
static inline XrVec3 operator*(XrVec3 a, float s) { return {a.x * s, a.y * s, a.z * s}; }
|
||||
static inline float dot(XrVec3 a, XrVec3 b) { return a.x * b.x + a.y * b.y + a.z * b.z; }
|
||||
static inline XrVec3 cross(XrVec3 a, XrVec3 b) { return {a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x}; }
|
||||
static inline XrVec3 normalized(XrVec3 a) {
|
||||
float length = std::sqrt(dot(a, a));
|
||||
return length > 1e-6f ? a * (1.f / length) : xrv(0, 0, 0);
|
||||
}
|
||||
|
||||
static inline XrVec3 rotate(const float q[4], XrVec3 v) {
|
||||
XrVec3 u{q[0], q[1], q[2]};
|
||||
float s = q[3];
|
||||
return u * (2.f * dot(u, v)) + v * (s * s - dot(u, u)) + cross(u, v) * (2.f * s);
|
||||
}
|
||||
|
||||
class XrOverlay {
|
||||
public:
|
||||
void initialize() {
|
||||
GLuint vertex = compile(GL_VERTEX_SHADER,
|
||||
"#version 300 es\nlayout(location=0) in vec3 position; layout(location=1) in vec2 coordinate;"
|
||||
"uniform mat4 viewProjection; out vec2 uv;"
|
||||
"void main(){uv=coordinate;gl_Position=viewProjection*vec4(position,1.0);}");
|
||||
GLuint fragment = compile(GL_FRAGMENT_SHADER,
|
||||
"#version 300 es\nprecision highp float; in vec2 uv; uniform int mode; uniform float progress, burst, time;"
|
||||
"uniform vec3 color; uniform sampler2D logo; uniform int hasLogo; out vec4 outputColor;"
|
||||
"void main(){"
|
||||
" if(mode==0){float across=1.0-abs(uv.y); float a=smoothstep(0.0,0.7,across)*mix(0.95,0.35,uv.x);"
|
||||
" outputColor=vec4(color*a,a);return;}"
|
||||
" if(mode==1){float r=length(uv); float a=1.0-smoothstep(0.55,1.0,r); outputColor=vec4(vec3(1.0)*a,a);return;}"
|
||||
" float r=length(uv); vec3 c=vec3(0.0); float a=0.0;"
|
||||
" float pulse=0.5+0.5*sin(time*6.0);"
|
||||
" float glow=exp(-pow(max(r-0.45,0.0)*6.0,2.0))*(0.25+0.2*pulse)*step(0.5,r); c+=color*glow; a=max(a,glow*0.7);"
|
||||
" if(hasLogo==1&&r<0.52){vec4 l=texture(logo,vec2(0.5+uv.x/1.04,0.5-uv.y/1.04)); c=c*(1.0-l.a)+l.rgb; a=a*(1.0-l.a)+l.a;}"
|
||||
" else if(r<0.5){float core=1.0-smoothstep(0.46,0.5,r); c+=color*core; a=max(a,core);}"
|
||||
" float angle=atan(uv.x,uv.y); float sweep=(angle<0.0?angle+6.2831853:angle)/6.2831853;"
|
||||
" float band=1.0-smoothstep(0.0,0.03,abs(r-0.64));"
|
||||
" float track=band*0.25; float fill=band*step(sweep,progress);"
|
||||
" c+=vec3(1.0)*track+color*fill*1.4; a=max(a,max(track,fill));"
|
||||
" if(burst>0.0){float ring=(1.0-smoothstep(0.0,0.06,abs(r-(0.64+burst*0.3))))*(1.0-burst); c+=color*ring*2.0; a=max(a,ring);}"
|
||||
" a=clamp(a,0.0,1.0); outputColor=vec4(c*a,a);"
|
||||
"}");
|
||||
program_ = glCreateProgram();
|
||||
glAttachShader(program_, vertex); glAttachShader(program_, fragment);
|
||||
glLinkProgram(program_); glDeleteShader(vertex); glDeleteShader(fragment);
|
||||
GLint linked = 0; glGetProgramiv(program_, GL_LINK_STATUS, &linked);
|
||||
if (!linked) throw std::runtime_error("Overlay shader link failed");
|
||||
viewProjection_ = glGetUniformLocation(program_, "viewProjection");
|
||||
mode_ = glGetUniformLocation(program_, "mode");
|
||||
progress_ = glGetUniformLocation(program_, "progress");
|
||||
burst_ = glGetUniformLocation(program_, "burst");
|
||||
time_ = glGetUniformLocation(program_, "time");
|
||||
color_ = glGetUniformLocation(program_, "color");
|
||||
logoSampler_ = glGetUniformLocation(program_, "logo");
|
||||
hasLogo_ = glGetUniformLocation(program_, "hasLogo");
|
||||
glGenVertexArrays(1, &vertexArray_);
|
||||
glGenBuffers(1, &buffer_);
|
||||
glBindVertexArray(vertexArray_);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, buffer_);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 5 * 6, nullptr, GL_DYNAMIC_DRAW);
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(float) * 5, nullptr);
|
||||
glEnableVertexAttribArray(1);
|
||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 5, reinterpret_cast<void *>(sizeof(float) * 3));
|
||||
glBindVertexArray(0);
|
||||
}
|
||||
|
||||
/** [pixels] are premultiplied RGBA rows, top row first, as an Android ARGB_8888 bitmap holds them. */
|
||||
void setLogo(const void *pixels, int width, int height, int stride) {
|
||||
if (!logo_) glGenTextures(1, &logo_);
|
||||
glBindTexture(GL_TEXTURE_2D, logo_);
|
||||
glPixelStorei(GL_UNPACK_ROW_LENGTH, stride / 4);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_SRGB8_ALPHA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
|
||||
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
||||
glGenerateMipmap(GL_TEXTURE_2D);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
}
|
||||
|
||||
void destroy() {
|
||||
if (logo_) glDeleteTextures(1, &logo_);
|
||||
logo_ = 0;
|
||||
if (program_) glDeleteProgram(program_);
|
||||
if (buffer_) glDeleteBuffers(1, &buffer_);
|
||||
if (vertexArray_) glDeleteVertexArrays(1, &vertexArray_);
|
||||
program_ = buffer_ = vertexArray_ = 0;
|
||||
}
|
||||
|
||||
static bool active(const DroidDeckXrHostControl &control) {
|
||||
return control.orb.visible || control.hands[0].laser > 0.f || control.hands[1].laser > 0.f;
|
||||
}
|
||||
|
||||
void draw(const XrPosef &eye, const XrFovf &fov, const DroidDeckXrHostControl &control,
|
||||
const DroidDeckXrHostState &state, float seconds) {
|
||||
if (!active(control)) return;
|
||||
float matrix[16];
|
||||
viewProjectionOf(eye, fov, matrix);
|
||||
const float eyeOrientation[4] = {eye.orientation.x, eye.orientation.y, eye.orientation.z, eye.orientation.w};
|
||||
const XrVec3 eyePosition{eye.position.x, eye.position.y, eye.position.z};
|
||||
glUseProgram(program_);
|
||||
glUniformMatrix4fv(viewProjection_, 1, GL_FALSE, matrix);
|
||||
glUniform3f(color_, 0.12f, 0.62f, 1.0f);
|
||||
glUniform1f(time_, seconds);
|
||||
glBindVertexArray(vertexArray_);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, buffer_);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDepthFunc(GL_LEQUAL);
|
||||
glDepthMask(GL_TRUE);
|
||||
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
|
||||
glDisable(GL_BLEND);
|
||||
glUniform1i(mode_, 0);
|
||||
for (const auto &layer : control.layers) {
|
||||
if (!layer.visible || !(layer.width > 0.f) || !(layer.height > 0.f)) continue;
|
||||
if (layer.flags & DROIDDECK_XR_HOST_LAYER_HEAD_LOCKED) continue;
|
||||
XrVec3 center{layer.pose.position[0], layer.pose.position[1], layer.pose.position[2]};
|
||||
XrVec3 right = rotate(layer.pose.orientation, xrv(layer.width / 2.f, 0, 0));
|
||||
XrVec3 up = rotate(layer.pose.orientation, xrv(0, layer.height / 2.f, 0));
|
||||
quad(center - right - up, center + right - up, center - right + up, center + right + up, 0.f, 1.f);
|
||||
}
|
||||
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
||||
glDepthMask(GL_FALSE);
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
||||
for (int hand = 0; hand < 2; hand++) {
|
||||
float length = control.hands[hand].laser;
|
||||
if (!(length > 0.f) || !state.hands[hand].active) continue;
|
||||
const auto &aim = state.hands[hand].aim;
|
||||
XrVec3 start{aim.position[0], aim.position[1], aim.position[2]};
|
||||
XrVec3 direction = normalized(rotate(aim.orientation, xrv(0, 0, -1)));
|
||||
XrVec3 end = start + direction * std::max(length - 0.004f, 0.f);
|
||||
XrVec3 side = normalized(cross(direction, eyePosition - start)) * 0.0022f;
|
||||
glUniform1i(mode_, 0);
|
||||
quad(start - side, start + side, end - side, end + side, 0.f, 1.f);
|
||||
XrVec3 right = rotate(eyeOrientation, xrv(1, 0, 0)) * 0.007f;
|
||||
XrVec3 up = rotate(eyeOrientation, xrv(0, 1, 0)) * 0.007f;
|
||||
glUniform1i(mode_, 1);
|
||||
billboard(end + normalized(eyePosition - end) * 0.008f, right, up);
|
||||
}
|
||||
if (control.orb.visible) {
|
||||
const auto &pose = control.orb.pose;
|
||||
XrVec3 center{pose.position[0], pose.position[1], pose.position[2]};
|
||||
float size = control.orb.radius * 1.25f;
|
||||
XrVec3 right = rotate(eyeOrientation, xrv(1, 0, 0)) * size;
|
||||
XrVec3 up = rotate(eyeOrientation, xrv(0, 1, 0)) * size;
|
||||
glUniform1i(mode_, 2);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, logo_);
|
||||
glUniform1i(logoSampler_, 0);
|
||||
glUniform1i(hasLogo_, logo_ ? 1 : 0);
|
||||
glUniform1f(progress_, control.orb.progress);
|
||||
glUniform1f(burst_, control.orb.burst);
|
||||
billboard(center, right, up);
|
||||
}
|
||||
glBindVertexArray(0);
|
||||
glDisable(GL_BLEND);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDepthMask(GL_TRUE);
|
||||
}
|
||||
|
||||
private:
|
||||
GLuint program_ = 0, buffer_ = 0, vertexArray_ = 0, logo_ = 0;
|
||||
GLint viewProjection_ = -1, mode_ = -1, progress_ = -1, burst_ = -1, time_ = -1, color_ = -1;
|
||||
GLint logoSampler_ = -1, hasLogo_ = -1;
|
||||
|
||||
static GLuint compile(GLenum type, const char *text) {
|
||||
GLuint handle = glCreateShader(type);
|
||||
glShaderSource(handle, 1, &text, nullptr); glCompileShader(handle);
|
||||
GLint success = 0; glGetShaderiv(handle, GL_COMPILE_STATUS, &success);
|
||||
if (!success) { glDeleteShader(handle); throw std::runtime_error("Overlay shader compile failed"); }
|
||||
return handle;
|
||||
}
|
||||
|
||||
void billboard(XrVec3 center, XrVec3 right, XrVec3 up) {
|
||||
quadUv(center - right - up, center + right - up, center - right + up, center + right + up);
|
||||
}
|
||||
|
||||
void quad(XrVec3 a0, XrVec3 a1, XrVec3 b0, XrVec3 b1, float from, float to) {
|
||||
const float vertices[] = {
|
||||
a0.x, a0.y, a0.z, from, -1, a1.x, a1.y, a1.z, from, 1, b0.x, b0.y, b0.z, to, -1,
|
||||
b0.x, b0.y, b0.z, to, -1, a1.x, a1.y, a1.z, from, 1, b1.x, b1.y, b1.z, to, 1};
|
||||
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertices), vertices);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
}
|
||||
|
||||
void quadUv(XrVec3 bottomLeft, XrVec3 bottomRight, XrVec3 topLeft, XrVec3 topRight) {
|
||||
const float vertices[] = {
|
||||
bottomLeft.x, bottomLeft.y, bottomLeft.z, -1, -1, bottomRight.x, bottomRight.y, bottomRight.z, 1, -1,
|
||||
topLeft.x, topLeft.y, topLeft.z, -1, 1, topLeft.x, topLeft.y, topLeft.z, -1, 1,
|
||||
bottomRight.x, bottomRight.y, bottomRight.z, 1, -1, topRight.x, topRight.y, topRight.z, 1, 1};
|
||||
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertices), vertices);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
}
|
||||
|
||||
static void viewProjectionOf(const XrPosef &pose, const XrFovf &fov, float out[16]) {
|
||||
const float q[4] = {pose.orientation.x, pose.orientation.y, pose.orientation.z, pose.orientation.w};
|
||||
XrVec3 xAxis = rotate(q, xrv(1, 0, 0)), yAxis = rotate(q, xrv(0, 1, 0)), zAxis = rotate(q, xrv(0, 0, 1));
|
||||
XrVec3 position{pose.position.x, pose.position.y, pose.position.z};
|
||||
float view[16] = {
|
||||
xAxis.x, yAxis.x, zAxis.x, 0, xAxis.y, yAxis.y, zAxis.y, 0, xAxis.z, yAxis.z, zAxis.z, 0,
|
||||
-dot(xAxis, position), -dot(yAxis, position), -dot(zAxis, position), 1};
|
||||
const float nearZ = 0.05f, farZ = 100.f;
|
||||
float left = std::tan(fov.angleLeft), right = std::tan(fov.angleRight);
|
||||
float up = std::tan(fov.angleUp), down = std::tan(fov.angleDown);
|
||||
float width = right - left, height = up - down;
|
||||
float projection[16] = {
|
||||
2.f / width, 0, 0, 0, 0, 2.f / height, 0, 0,
|
||||
(right + left) / width, (up + down) / height, -(farZ + nearZ) / (farZ - nearZ), -1,
|
||||
0, 0, -2.f * farZ * nearZ / (farZ - nearZ), 0};
|
||||
for (int column = 0; column < 4; column++)
|
||||
for (int row = 0; row < 4; row++) {
|
||||
float sum = 0;
|
||||
for (int k = 0; k < 4; k++) sum += projection[k * 4 + row] * view[column * 4 + k];
|
||||
out[column * 4 + row] = sum;
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -1,4 +1,5 @@
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <jni.h>
|
||||
#include <limits.h>
|
||||
#include <linux/futex.h>
|
||||
@@ -27,3 +28,16 @@ Java_com_droiddeck_launcher_session_ThreadSignals_tgkill(JNIEnv *env, jclass cla
|
||||
(void)clazz;
|
||||
return syscall(SYS_tgkill, tgid, tid, signal) == 0 ? 0 : errno;
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_com_droiddeck_launcher_session_PageCacheNative_fadviseDontNeed(JNIEnv *env, jclass clazz, jstring path) {
|
||||
(void)clazz;
|
||||
const char *chars = (*env)->GetStringUTFChars(env, path, NULL);
|
||||
if (!chars) return ENOMEM;
|
||||
int fd = open(chars, O_RDONLY | O_CLOEXEC | O_NOFOLLOW);
|
||||
(*env)->ReleaseStringUTFChars(env, path, chars);
|
||||
if (fd < 0) return errno;
|
||||
int rc = posix_fadvise(fd, 0, 0, POSIX_FADV_DONTNEED);
|
||||
close(fd);
|
||||
return rc;
|
||||
}
|
||||
@@ -39,7 +39,7 @@
|
||||
// - Same push constants as cas.frag: ndc, input size, sharpness [0..1].
|
||||
// CasSetup's const1.x = -1 / lerp(8, 5, sharpness) is computed here.
|
||||
// - The input is the effect chain's previous target at the same size, so the
|
||||
// output pixel reads the input pixel 1:1 (texelFetch, edges clamped).
|
||||
// output pixel reads the input pixel 1:1 (texel centres, edges clamped).
|
||||
// =============================================================================
|
||||
|
||||
// DD_HALF is set for the *_half_frag.h build (gen_shaders.sh): colour and
|
||||
@@ -64,8 +64,8 @@ layout(location = 0) in highp vec2 fragTexCoord;
|
||||
layout(location = 0) out vec4 outColor;
|
||||
|
||||
vec3 CasLoad(ivec2 p) {
|
||||
ivec2 sz = textureSize(InputTexture, 0);
|
||||
return texelFetch(InputTexture, clamp(p, ivec2(0), sz - ivec2(1)), 0).rgb;
|
||||
highp vec2 uv = (vec2(p) + 0.5) / pc.resolution;
|
||||
return textureLod(InputTexture, uv, 0.0).rgb;
|
||||
}
|
||||
|
||||
float AMin3F1(float x, float y, float z) { return min(x, min(y, z)); }
|
||||
|
||||
@@ -1,214 +1,213 @@
|
||||
// 1116.2.0
|
||||
// 1115.1.0
|
||||
#pragma once
|
||||
const uint32_t cas_ffx_half_code[] = {
|
||||
0x07230203,0x00010000,0x0008000b,0x000000d7,0x00000000,0x00020011,0x00000001,0x00020011,
|
||||
0x00000032,0x0006000b,0x00000001,0x4c534c47,0x6474732e,0x3035342e,0x00000000,0x0003000e,
|
||||
0x00000000,0x00000001,0x0007000f,0x00000004,0x00000004,0x6e69616d,0x00000000,0x00000043,
|
||||
0x000000d1,0x00030010,0x00000004,0x00000007,0x00030003,0x00000002,0x000001c2,0x00040005,
|
||||
0x00000004,0x6e69616d,0x00000000,0x00060005,0x0000000d,0x4c736143,0x2864616f,0x3b326976,
|
||||
0x00000000,0x00030005,0x0000000c,0x00000070,0x00070005,0x00000014,0x6e694d41,0x28314633,
|
||||
0x663b3166,0x31663b31,0x0000003b,0x00030005,0x00000011,0x00000078,0x00030005,0x00000012,
|
||||
0x00000079,0x00030005,0x00000013,0x0000007a,0x00070005,0x00000019,0x78614d41,0x28314633,
|
||||
0x663b3166,0x31663b31,0x0000003b,0x00030005,0x00000016,0x00000078,0x00030005,0x00000017,
|
||||
0x00000079,0x00030005,0x00000018,0x0000007a,0x00030005,0x0000001b,0x00007a73,0x00060005,
|
||||
0x0000001f,0x75706e49,0x78655474,0x65727574,0x00000000,0x00030005,0x00000040,0x00007073,
|
||||
0x00060005,0x00000043,0x67617266,0x43786554,0x64726f6f,0x00000000,0x00030005,0x00000045,
|
||||
0x00004350,0x00040006,0x00000045,0x00000000,0x0063646e,0x00060006,0x00000045,0x00000001,
|
||||
0x6f736572,0x6974756c,0x00006e6f,0x00060006,0x00000045,0x00000002,0x72616873,0x73656e70,
|
||||
0x00000073,0x00030005,0x00000047,0x00006370,0x00040005,0x0000004d,0x6b616570,0x00000000,
|
||||
0x00030005,0x0000005b,0x00000062,0x00040005,0x00000060,0x61726170,0x0000006d,0x00030005,
|
||||
0x00000062,0x00000064,0x00040005,0x00000066,0x61726170,0x0000006d,0x00030005,0x00000068,
|
||||
0x00000065,0x00040005,0x00000069,0x61726170,0x0000006d,0x00030005,0x0000006c,0x00000066,
|
||||
0x00040005,0x00000070,0x61726170,0x0000006d,0x00030005,0x00000072,0x00000068,0x00040005,
|
||||
0x00000076,0x61726170,0x0000006d,0x00030005,0x00000078,0x00476e6d,0x00040005,0x00000079,
|
||||
0x61726170,0x0000006d,0x00040005,0x0000007e,0x61726170,0x0000006d,0x00040005,0x00000081,
|
||||
0x61726170,0x0000006d,0x00040005,0x00000085,0x61726170,0x0000006d,0x00040005,0x00000086,
|
||||
0x61726170,0x0000006d,0x00040005,0x00000089,0x61726170,0x0000006d,0x00030005,0x0000008d,
|
||||
0x0047786d,0x00040005,0x0000008e,0x61726170,0x0000006d,0x00040005,0x00000091,0x61726170,
|
||||
0x0000006d,0x00040005,0x00000094,0x61726170,0x0000006d,0x00040005,0x00000098,0x61726170,
|
||||
0x0000006d,0x00040005,0x00000099,0x61726170,0x0000006d,0x00040005,0x0000009c,0x61726170,
|
||||
0x0000006d,0x00040005,0x000000a0,0x4d706372,0x00000047,0x00040005,0x000000a5,0x47706d61,
|
||||
0x00000000,0x00030005,0x000000af,0x00004777,0x00050005,0x000000b3,0x57706372,0x68676965,
|
||||
0x00000074,0x00030005,0x000000b9,0x00786970,0x00050005,0x000000d1,0x4374756f,0x726f6c6f,
|
||||
0x00000000,0x00030047,0x0000000d,0x00000000,0x00030047,0x00000011,0x00000000,0x00030047,
|
||||
0x00000012,0x00000000,0x00030047,0x00000013,0x00000000,0x00030047,0x00000014,0x00000000,
|
||||
0x00030047,0x00000016,0x00000000,0x00030047,0x00000017,0x00000000,0x00030047,0x00000018,
|
||||
0x00000000,0x00030047,0x00000019,0x00000000,0x00030047,0x0000001f,0x00000000,0x00040047,
|
||||
0x0000001f,0x00000021,0x00000000,0x00040047,0x0000001f,0x00000022,0x00000000,0x00030047,
|
||||
0x00000020,0x00000000,0x00030047,0x00000024,0x00000000,0x00030047,0x0000002e,0x00000000,
|
||||
0x00030047,0x0000002f,0x00000000,0x00030047,0x00000032,0x00000000,0x00030047,0x00000033,
|
||||
0x00000000,0x00030047,0x00000034,0x00000000,0x00030047,0x00000035,0x00000000,0x00030047,
|
||||
0x00000036,0x00000000,0x00030047,0x00000039,0x00000000,0x00030047,0x0000003a,0x00000000,
|
||||
0x00030047,0x0000003b,0x00000000,0x00030047,0x0000003c,0x00000000,0x00030047,0x0000003d,
|
||||
0x00000000,0x00040047,0x00000043,0x0000001e,0x00000000,0x00030047,0x00000045,0x00000002,
|
||||
0x00050048,0x00000045,0x00000000,0x00000023,0x00000000,0x00050048,0x00000045,0x00000001,
|
||||
0x00000023,0x00000010,0x00040048,0x00000045,0x00000002,0x00000000,0x00050048,0x00000045,
|
||||
0x00000002,0x00000023,0x00000018,0x00030047,0x0000004d,0x00000000,0x00030047,0x00000054,
|
||||
0x00000000,0x00030047,0x00000057,0x00000000,0x00030047,0x00000058,0x00000000,0x00030047,
|
||||
0x00000059,0x00000000,0x00030047,0x0000005b,0x00000000,0x00030047,0x00000061,0x00000000,
|
||||
0x00030047,0x00000062,0x00000000,0x00030047,0x00000067,0x00000000,0x00030047,0x00000068,
|
||||
0x00000000,0x00030047,0x0000006b,0x00000000,0x00030047,0x0000006c,0x00000000,0x00030047,
|
||||
0x00000071,0x00000000,0x00030047,0x00000072,0x00000000,0x00030047,0x00000077,0x00000000,
|
||||
0x00030047,0x00000078,0x00000000,0x00030047,0x00000079,0x00000000,0x00030047,0x0000007d,
|
||||
0x00000000,0x00030047,0x0000007e,0x00000000,0x00030047,0x00000080,0x00000000,0x00030047,
|
||||
0x00000081,0x00000000,0x00030047,0x00000083,0x00000000,0x00030047,0x00000084,0x00000000,
|
||||
0x00030047,0x00000085,0x00000000,0x00030047,0x00000086,0x00000000,0x00030047,0x00000088,
|
||||
0x00000000,0x00030047,0x00000089,0x00000000,0x00030047,0x0000008b,0x00000000,0x00030047,
|
||||
0x0000008c,0x00000000,0x00030047,0x0000008d,0x00000000,0x00030047,0x0000008e,0x00000000,
|
||||
0x00030047,0x00000090,0x00000000,0x00030047,0x00000091,0x00000000,0x00030047,0x00000093,
|
||||
0x00000000,0x00030047,0x00000094,0x00000000,0x00030047,0x00000096,0x00000000,0x00030047,
|
||||
0x00000097,0x00000000,0x00030047,0x00000098,0x00000000,0x00030047,0x00000099,0x00000000,
|
||||
0x00030047,0x0000009b,0x00000000,0x00030047,0x0000009c,0x00000000,0x00030047,0x0000009e,
|
||||
0x00000000,0x00030047,0x0000009f,0x00000000,0x00030047,0x000000a0,0x00000000,0x00030047,
|
||||
0x000000a1,0x00000000,0x00030047,0x000000a3,0x00000000,0x00030047,0x000000a4,0x00000000,
|
||||
0x00030047,0x000000a5,0x00000000,0x00030047,0x000000a6,0x00000000,0x00030047,0x000000a7,
|
||||
0x00000000,0x00030047,0x000000a8,0x00000000,0x00030047,0x000000a9,0x00000000,0x00030047,
|
||||
0x000000aa,0x00000000,0x00030047,0x000000ab,0x00000000,0x00030047,0x000000ac,0x00000000,
|
||||
0x00030047,0x000000ad,0x00000000,0x00030047,0x000000ae,0x00000000,0x00030047,0x000000af,
|
||||
0x00000000,0x00030047,0x000000b0,0x00000000,0x00030047,0x000000b1,0x00000000,0x00030047,
|
||||
0x000000b2,0x00000000,0x00030047,0x000000b3,0x00000000,0x00030047,0x000000b5,0x00000000,
|
||||
0x00030047,0x000000b6,0x00000000,0x00030047,0x000000b7,0x00000000,0x00030047,0x000000b8,
|
||||
0x00000000,0x00030047,0x000000b9,0x00000000,0x00030047,0x000000ba,0x00000000,0x00030047,
|
||||
0x000000bb,0x00000000,0x00030047,0x000000bc,0x00000000,0x00030047,0x000000bd,0x00000000,
|
||||
0x00030047,0x000000be,0x00000000,0x00030047,0x000000bf,0x00000000,0x00030047,0x000000c0,
|
||||
0x00000000,0x00030047,0x000000c1,0x00000000,0x00030047,0x000000c2,0x00000000,0x00030047,
|
||||
0x000000c3,0x00000000,0x00030047,0x000000c4,0x00000000,0x00030047,0x000000c5,0x00000000,
|
||||
0x00030047,0x000000c6,0x00000000,0x00030047,0x000000c7,0x00000000,0x00030047,0x000000c8,
|
||||
0x00000000,0x00030047,0x000000c9,0x00000000,0x00030047,0x000000ca,0x00000000,0x00030047,
|
||||
0x000000cb,0x00000000,0x00030047,0x000000cc,0x00000000,0x00030047,0x000000cd,0x00000000,
|
||||
0x00030047,0x000000ce,0x00000000,0x00030047,0x000000cf,0x00000000,0x00030047,0x000000d1,
|
||||
0x00000000,0x00040047,0x000000d1,0x0000001e,0x00000000,0x00030047,0x000000d2,0x00000000,
|
||||
0x00030047,0x000000d3,0x00000000,0x00030047,0x000000d4,0x00000000,0x00030047,0x000000d5,
|
||||
0x00000000,0x00030047,0x000000d6,0x00000000,0x00020013,0x00000002,0x00030021,0x00000003,
|
||||
0x00000002,0x00040015,0x00000006,0x00000020,0x00000001,0x00040017,0x00000007,0x00000006,
|
||||
0x00000002,0x00040020,0x00000008,0x00000007,0x00000007,0x00030016,0x00000009,0x00000020,
|
||||
0x00040017,0x0000000a,0x00000009,0x00000003,0x00040021,0x0000000b,0x0000000a,0x00000008,
|
||||
0x00040020,0x0000000f,0x00000007,0x00000009,0x00060021,0x00000010,0x00000009,0x0000000f,
|
||||
0x0000000f,0x0000000f,0x00090019,0x0000001c,0x00000009,0x00000001,0x00000000,0x00000000,
|
||||
0x00000000,0x00000001,0x00000000,0x0003001b,0x0000001d,0x0000001c,0x00040020,0x0000001e,
|
||||
0x00000000,0x0000001d,0x0004003b,0x0000001e,0x0000001f,0x00000000,0x0004002b,0x00000006,
|
||||
0x00000021,0x00000000,0x0005002c,0x00000007,0x00000026,0x00000021,0x00000021,0x0004002b,
|
||||
0x00000006,0x00000028,0x00000001,0x0005002c,0x00000007,0x00000029,0x00000028,0x00000028,
|
||||
0x00040017,0x0000002d,0x00000009,0x00000004,0x00040017,0x00000041,0x00000009,0x00000002,
|
||||
0x00040020,0x00000042,0x00000001,0x00000041,0x0004003b,0x00000042,0x00000043,0x00000001,
|
||||
0x0005001e,0x00000045,0x0000002d,0x00000041,0x00000009,0x00040020,0x00000046,0x00000009,
|
||||
0x00000045,0x0004003b,0x00000046,0x00000047,0x00000009,0x00040020,0x00000048,0x00000009,
|
||||
0x00000041,0x0004002b,0x00000009,0x0000004e,0xbf800000,0x0004002b,0x00000009,0x0000004f,
|
||||
0x41000000,0x0004002b,0x00000009,0x00000050,0x40a00000,0x0004002b,0x00000006,0x00000051,
|
||||
0x00000002,0x00040020,0x00000052,0x00000009,0x00000009,0x0004002b,0x00000009,0x00000055,
|
||||
0x00000000,0x0004002b,0x00000009,0x00000056,0x3f800000,0x00040020,0x0000005a,0x00000007,
|
||||
0x0000000a,0x0004002b,0x00000006,0x0000005d,0xffffffff,0x0005002c,0x00000007,0x0000005e,
|
||||
0x00000021,0x0000005d,0x0005002c,0x00000007,0x00000064,0x0000005d,0x00000021,0x0005002c,
|
||||
0x00000007,0x0000006e,0x00000028,0x00000021,0x0005002c,0x00000007,0x00000074,0x00000021,
|
||||
0x00000028,0x00040015,0x0000007a,0x00000020,0x00000000,0x0004002b,0x0000007a,0x0000007b,
|
||||
0x00000001,0x0004002b,0x00000009,0x000000a2,0x3a800000,0x0004002b,0x00000009,0x000000b4,
|
||||
0x40800000,0x00040020,0x000000d0,0x00000003,0x0000002d,0x0004003b,0x000000d0,0x000000d1,
|
||||
0x00000003,0x00050036,0x00000002,0x00000004,0x00000000,0x00000003,0x000200f8,0x00000005,
|
||||
0x0004003b,0x00000008,0x00000040,0x00000007,0x0004003b,0x0000000f,0x0000004d,0x00000007,
|
||||
0x0004003b,0x0000005a,0x0000005b,0x00000007,0x0004003b,0x00000008,0x00000060,0x00000007,
|
||||
0x0004003b,0x0000005a,0x00000062,0x00000007,0x0004003b,0x00000008,0x00000066,0x00000007,
|
||||
0x0004003b,0x0000005a,0x00000068,0x00000007,0x0004003b,0x00000008,0x00000069,0x00000007,
|
||||
0x0004003b,0x0000005a,0x0000006c,0x00000007,0x0004003b,0x00000008,0x00000070,0x00000007,
|
||||
0x0004003b,0x0000005a,0x00000072,0x00000007,0x0004003b,0x00000008,0x00000076,0x00000007,
|
||||
0x0004003b,0x0000000f,0x00000078,0x00000007,0x0004003b,0x0000000f,0x00000079,0x00000007,
|
||||
0x0004003b,0x0000000f,0x0000007e,0x00000007,0x0004003b,0x0000000f,0x00000081,0x00000007,
|
||||
0x0004003b,0x0000000f,0x00000085,0x00000007,0x0004003b,0x0000000f,0x00000086,0x00000007,
|
||||
0x0004003b,0x0000000f,0x00000089,0x00000007,0x0004003b,0x0000000f,0x0000008d,0x00000007,
|
||||
0x0004003b,0x0000000f,0x0000008e,0x00000007,0x0004003b,0x0000000f,0x00000091,0x00000007,
|
||||
0x0004003b,0x0000000f,0x00000094,0x00000007,0x0004003b,0x0000000f,0x00000098,0x00000007,
|
||||
0x0004003b,0x0000000f,0x00000099,0x00000007,0x0004003b,0x0000000f,0x0000009c,0x00000007,
|
||||
0x0004003b,0x0000000f,0x000000a0,0x00000007,0x0004003b,0x0000000f,0x000000a5,0x00000007,
|
||||
0x0004003b,0x0000000f,0x000000af,0x00000007,0x0004003b,0x0000000f,0x000000b3,0x00000007,
|
||||
0x0004003b,0x0000005a,0x000000b9,0x00000007,0x0004003d,0x00000041,0x00000044,0x00000043,
|
||||
0x00050041,0x00000048,0x00000049,0x00000047,0x00000028,0x0004003d,0x00000041,0x0000004a,
|
||||
0x00000049,0x00050085,0x00000041,0x0000004b,0x00000044,0x0000004a,0x0004006e,0x00000007,
|
||||
0x0000004c,0x0000004b,0x0003003e,0x00000040,0x0000004c,0x00050041,0x00000052,0x00000053,
|
||||
0x00000047,0x00000051,0x0004003d,0x00000009,0x00000054,0x00000053,0x0008000c,0x00000009,
|
||||
0x00000057,0x00000001,0x0000002b,0x00000054,0x00000055,0x00000056,0x0008000c,0x00000009,
|
||||
0x00000058,0x00000001,0x0000002e,0x0000004f,0x00000050,0x00000057,0x00050088,0x00000009,
|
||||
0x00000059,0x0000004e,0x00000058,0x0003003e,0x0000004d,0x00000059,0x0004003d,0x00000007,
|
||||
0x0000005c,0x00000040,0x00050080,0x00000007,0x0000005f,0x0000005c,0x0000005e,0x0003003e,
|
||||
0x00000060,0x0000005f,0x00050039,0x0000000a,0x00000061,0x0000000d,0x00000060,0x0003003e,
|
||||
0x0000005b,0x00000061,0x0004003d,0x00000007,0x00000063,0x00000040,0x00050080,0x00000007,
|
||||
0x00000065,0x00000063,0x00000064,0x0003003e,0x00000066,0x00000065,0x00050039,0x0000000a,
|
||||
0x00000067,0x0000000d,0x00000066,0x0003003e,0x00000062,0x00000067,0x0004003d,0x00000007,
|
||||
0x0000006a,0x00000040,0x0003003e,0x00000069,0x0000006a,0x00050039,0x0000000a,0x0000006b,
|
||||
0x0000000d,0x00000069,0x0003003e,0x00000068,0x0000006b,0x0004003d,0x00000007,0x0000006d,
|
||||
0x00000040,0x00050080,0x00000007,0x0000006f,0x0000006d,0x0000006e,0x0003003e,0x00000070,
|
||||
0x0000006f,0x00050039,0x0000000a,0x00000071,0x0000000d,0x00000070,0x0003003e,0x0000006c,
|
||||
0x00000071,0x0004003d,0x00000007,0x00000073,0x00000040,0x00050080,0x00000007,0x00000075,
|
||||
0x00000073,0x00000074,0x0003003e,0x00000076,0x00000075,0x00050039,0x0000000a,0x00000077,
|
||||
0x0000000d,0x00000076,0x0003003e,0x00000072,0x00000077,0x00050041,0x0000000f,0x0000007c,
|
||||
0x00000062,0x0000007b,0x0004003d,0x00000009,0x0000007d,0x0000007c,0x0003003e,0x00000079,
|
||||
0x0000007d,0x00050041,0x0000000f,0x0000007f,0x00000068,0x0000007b,0x0004003d,0x00000009,
|
||||
0x00000080,0x0000007f,0x0003003e,0x0000007e,0x00000080,0x00050041,0x0000000f,0x00000082,
|
||||
0x0000006c,0x0000007b,0x0004003d,0x00000009,0x00000083,0x00000082,0x0003003e,0x00000081,
|
||||
0x00000083,0x00070039,0x00000009,0x00000084,0x00000014,0x00000079,0x0000007e,0x00000081,
|
||||
0x0003003e,0x00000085,0x00000084,0x00050041,0x0000000f,0x00000087,0x0000005b,0x0000007b,
|
||||
0x0004003d,0x00000009,0x00000088,0x00000087,0x0003003e,0x00000086,0x00000088,0x00050041,
|
||||
0x0000000f,0x0000008a,0x00000072,0x0000007b,0x0004003d,0x00000009,0x0000008b,0x0000008a,
|
||||
0x0003003e,0x00000089,0x0000008b,0x00070039,0x00000009,0x0000008c,0x00000014,0x00000085,
|
||||
0x00000086,0x00000089,0x0003003e,0x00000078,0x0000008c,0x00050041,0x0000000f,0x0000008f,
|
||||
0x00000062,0x0000007b,0x0004003d,0x00000009,0x00000090,0x0000008f,0x0003003e,0x0000008e,
|
||||
0x00000090,0x00050041,0x0000000f,0x00000092,0x00000068,0x0000007b,0x0004003d,0x00000009,
|
||||
0x00000093,0x00000092,0x0003003e,0x00000091,0x00000093,0x00050041,0x0000000f,0x00000095,
|
||||
0x0000006c,0x0000007b,0x0004003d,0x00000009,0x00000096,0x00000095,0x0003003e,0x00000094,
|
||||
0x00000096,0x00070039,0x00000009,0x00000097,0x00000019,0x0000008e,0x00000091,0x00000094,
|
||||
0x0003003e,0x00000098,0x00000097,0x00050041,0x0000000f,0x0000009a,0x0000005b,0x0000007b,
|
||||
0x0004003d,0x00000009,0x0000009b,0x0000009a,0x0003003e,0x00000099,0x0000009b,0x00050041,
|
||||
0x0000000f,0x0000009d,0x00000072,0x0000007b,0x0004003d,0x00000009,0x0000009e,0x0000009d,
|
||||
0x0003003e,0x0000009c,0x0000009e,0x00070039,0x00000009,0x0000009f,0x00000019,0x00000098,
|
||||
0x00000099,0x0000009c,0x0003003e,0x0000008d,0x0000009f,0x0004003d,0x00000009,0x000000a1,
|
||||
0x0000008d,0x0007000c,0x00000009,0x000000a3,0x00000001,0x00000028,0x000000a1,0x000000a2,
|
||||
0x00050088,0x00000009,0x000000a4,0x00000056,0x000000a3,0x0003003e,0x000000a0,0x000000a4,
|
||||
0x0004003d,0x00000009,0x000000a6,0x00000078,0x0004003d,0x00000009,0x000000a7,0x0000008d,
|
||||
0x00050083,0x00000009,0x000000a8,0x00000056,0x000000a7,0x0007000c,0x00000009,0x000000a9,
|
||||
0x00000001,0x00000025,0x000000a6,0x000000a8,0x0004003d,0x00000009,0x000000aa,0x000000a0,
|
||||
0x00050085,0x00000009,0x000000ab,0x000000a9,0x000000aa,0x0008000c,0x00000009,0x000000ac,
|
||||
0x00000001,0x0000002b,0x000000ab,0x00000055,0x00000056,0x0003003e,0x000000a5,0x000000ac,
|
||||
0x0004003d,0x00000009,0x000000ad,0x000000a5,0x0006000c,0x00000009,0x000000ae,0x00000001,
|
||||
0x0000001f,0x000000ad,0x0003003e,0x000000a5,0x000000ae,0x0004003d,0x00000009,0x000000b0,
|
||||
0x000000a5,0x0004003d,0x00000009,0x000000b1,0x0000004d,0x00050085,0x00000009,0x000000b2,
|
||||
0x000000b0,0x000000b1,0x0003003e,0x000000af,0x000000b2,0x0004003d,0x00000009,0x000000b5,
|
||||
0x000000af,0x00050085,0x00000009,0x000000b6,0x000000b4,0x000000b5,0x00050081,0x00000009,
|
||||
0x000000b7,0x00000056,0x000000b6,0x00050088,0x00000009,0x000000b8,0x00000056,0x000000b7,
|
||||
0x0003003e,0x000000b3,0x000000b8,0x0004003d,0x0000000a,0x000000ba,0x0000005b,0x0004003d,
|
||||
0x00000009,0x000000bb,0x000000af,0x0005008e,0x0000000a,0x000000bc,0x000000ba,0x000000bb,
|
||||
0x0004003d,0x0000000a,0x000000bd,0x00000062,0x0004003d,0x00000009,0x000000be,0x000000af,
|
||||
0x0005008e,0x0000000a,0x000000bf,0x000000bd,0x000000be,0x00050081,0x0000000a,0x000000c0,
|
||||
0x000000bc,0x000000bf,0x0004003d,0x0000000a,0x000000c1,0x0000006c,0x0004003d,0x00000009,
|
||||
0x000000c2,0x000000af,0x0005008e,0x0000000a,0x000000c3,0x000000c1,0x000000c2,0x00050081,
|
||||
0x0000000a,0x000000c4,0x000000c0,0x000000c3,0x0004003d,0x0000000a,0x000000c5,0x00000072,
|
||||
0x0004003d,0x00000009,0x000000c6,0x000000af,0x0005008e,0x0000000a,0x000000c7,0x000000c5,
|
||||
0x000000c6,0x00050081,0x0000000a,0x000000c8,0x000000c4,0x000000c7,0x0004003d,0x0000000a,
|
||||
0x000000c9,0x00000068,0x00050081,0x0000000a,0x000000ca,0x000000c8,0x000000c9,0x0004003d,
|
||||
0x00000009,0x000000cb,0x000000b3,0x0005008e,0x0000000a,0x000000cc,0x000000ca,0x000000cb,
|
||||
0x00060050,0x0000000a,0x000000cd,0x00000055,0x00000055,0x00000055,0x00060050,0x0000000a,
|
||||
0x000000ce,0x00000056,0x00000056,0x00000056,0x0008000c,0x0000000a,0x000000cf,0x00000001,
|
||||
0x0000002b,0x000000cc,0x000000cd,0x000000ce,0x0003003e,0x000000b9,0x000000cf,0x0004003d,
|
||||
0x0000000a,0x000000d2,0x000000b9,0x00050051,0x00000009,0x000000d3,0x000000d2,0x00000000,
|
||||
0x00050051,0x00000009,0x000000d4,0x000000d2,0x00000001,0x00050051,0x00000009,0x000000d5,
|
||||
0x000000d2,0x00000002,0x00070050,0x0000002d,0x000000d6,0x000000d3,0x000000d4,0x000000d5,
|
||||
0x00000056,0x0003003e,0x000000d1,0x000000d6,0x000100fd,0x00010038,0x00050036,0x0000000a,
|
||||
0x0000000d,0x00000000,0x0000000b,0x00030037,0x00000008,0x0000000c,0x000200f8,0x0000000e,
|
||||
0x0004003b,0x00000008,0x0000001b,0x00000007,0x0004003d,0x0000001d,0x00000020,0x0000001f,
|
||||
0x00040064,0x0000001c,0x00000022,0x00000020,0x00050067,0x00000007,0x00000023,0x00000022,
|
||||
0x00000021,0x0003003e,0x0000001b,0x00000023,0x0004003d,0x0000001d,0x00000024,0x0000001f,
|
||||
0x0004003d,0x00000007,0x00000025,0x0000000c,0x0004003d,0x00000007,0x00000027,0x0000001b,
|
||||
0x00050082,0x00000007,0x0000002a,0x00000027,0x00000029,0x0008000c,0x00000007,0x0000002b,
|
||||
0x00000001,0x0000002d,0x00000025,0x00000026,0x0000002a,0x00040064,0x0000001c,0x0000002c,
|
||||
0x00000024,0x0007005f,0x0000002d,0x0000002e,0x0000002c,0x0000002b,0x00000002,0x00000021,
|
||||
0x0008004f,0x0000000a,0x0000002f,0x0000002e,0x0000002e,0x00000000,0x00000001,0x00000002,
|
||||
0x000200fe,0x0000002f,0x00010038,0x00050036,0x00000009,0x00000014,0x00000000,0x00000010,
|
||||
0x00030037,0x0000000f,0x00000011,0x00030037,0x0000000f,0x00000012,0x00030037,0x0000000f,
|
||||
0x00000013,0x000200f8,0x00000015,0x0004003d,0x00000009,0x00000032,0x00000011,0x0004003d,
|
||||
0x00000009,0x00000033,0x00000012,0x0004003d,0x00000009,0x00000034,0x00000013,0x0007000c,
|
||||
0x00000009,0x00000035,0x00000001,0x00000025,0x00000033,0x00000034,0x0007000c,0x00000009,
|
||||
0x00000036,0x00000001,0x00000025,0x00000032,0x00000035,0x000200fe,0x00000036,0x00010038,
|
||||
0x00050036,0x00000009,0x00000019,0x00000000,0x00000010,0x00030037,0x0000000f,0x00000016,
|
||||
0x00030037,0x0000000f,0x00000017,0x00030037,0x0000000f,0x00000018,0x000200f8,0x0000001a,
|
||||
0x0004003d,0x00000009,0x00000039,0x00000016,0x0004003d,0x00000009,0x0000003a,0x00000017,
|
||||
0x0004003d,0x00000009,0x0000003b,0x00000018,0x0007000c,0x00000009,0x0000003c,0x00000001,
|
||||
0x00000028,0x0000003a,0x0000003b,0x0007000c,0x00000009,0x0000003d,0x00000001,0x00000028,
|
||||
0x00000039,0x0000003c,0x000200fe,0x0000003d,0x00010038
|
||||
0x07230203,0x00010000,0x0008000b,0x000000d7,0x00000000,0x00020011,0x00000001,0x0006000b,
|
||||
0x00000001,0x4c534c47,0x6474732e,0x3035342e,0x00000000,0x0003000e,0x00000000,0x00000001,
|
||||
0x0007000f,0x00000004,0x00000004,0x6e69616d,0x00000000,0x00000047,0x000000d1,0x00030010,
|
||||
0x00000004,0x00000007,0x00030003,0x00000002,0x000001c2,0x00040005,0x00000004,0x6e69616d,
|
||||
0x00000000,0x00060005,0x0000000d,0x4c736143,0x2864616f,0x3b326976,0x00000000,0x00030005,
|
||||
0x0000000c,0x00000070,0x00070005,0x00000014,0x6e694d41,0x28314633,0x663b3166,0x31663b31,
|
||||
0x0000003b,0x00030005,0x00000011,0x00000078,0x00030005,0x00000012,0x00000079,0x00030005,
|
||||
0x00000013,0x0000007a,0x00070005,0x00000019,0x78614d41,0x28314633,0x663b3166,0x31663b31,
|
||||
0x0000003b,0x00030005,0x00000016,0x00000078,0x00030005,0x00000017,0x00000079,0x00030005,
|
||||
0x00000018,0x0000007a,0x00030005,0x0000001d,0x00007675,0x00030005,0x00000024,0x00004350,
|
||||
0x00040006,0x00000024,0x00000000,0x0063646e,0x00060006,0x00000024,0x00000001,0x6f736572,
|
||||
0x6974756c,0x00006e6f,0x00060006,0x00000024,0x00000002,0x72616873,0x73656e70,0x00000073,
|
||||
0x00030005,0x00000026,0x00006370,0x00060005,0x0000002f,0x75706e49,0x78655474,0x65727574,
|
||||
0x00000000,0x00030005,0x00000045,0x00007073,0x00060005,0x00000047,0x67617266,0x43786554,
|
||||
0x64726f6f,0x00000000,0x00040005,0x0000004d,0x6b616570,0x00000000,0x00030005,0x0000005a,
|
||||
0x00000062,0x00040005,0x00000060,0x61726170,0x0000006d,0x00030005,0x00000062,0x00000064,
|
||||
0x00040005,0x00000066,0x61726170,0x0000006d,0x00030005,0x00000068,0x00000065,0x00040005,
|
||||
0x00000069,0x61726170,0x0000006d,0x00030005,0x0000006c,0x00000066,0x00040005,0x00000070,
|
||||
0x61726170,0x0000006d,0x00030005,0x00000072,0x00000068,0x00040005,0x00000076,0x61726170,
|
||||
0x0000006d,0x00030005,0x00000078,0x00476e6d,0x00040005,0x00000079,0x61726170,0x0000006d,
|
||||
0x00040005,0x0000007e,0x61726170,0x0000006d,0x00040005,0x00000081,0x61726170,0x0000006d,
|
||||
0x00040005,0x00000085,0x61726170,0x0000006d,0x00040005,0x00000086,0x61726170,0x0000006d,
|
||||
0x00040005,0x00000089,0x61726170,0x0000006d,0x00030005,0x0000008d,0x0047786d,0x00040005,
|
||||
0x0000008e,0x61726170,0x0000006d,0x00040005,0x00000091,0x61726170,0x0000006d,0x00040005,
|
||||
0x00000094,0x61726170,0x0000006d,0x00040005,0x00000098,0x61726170,0x0000006d,0x00040005,
|
||||
0x00000099,0x61726170,0x0000006d,0x00040005,0x0000009c,0x61726170,0x0000006d,0x00040005,
|
||||
0x000000a0,0x4d706372,0x00000047,0x00040005,0x000000a5,0x47706d61,0x00000000,0x00030005,
|
||||
0x000000af,0x00004777,0x00050005,0x000000b3,0x57706372,0x68676965,0x00000074,0x00030005,
|
||||
0x000000b9,0x00786970,0x00050005,0x000000d1,0x4374756f,0x726f6c6f,0x00000000,0x00030047,
|
||||
0x0000000d,0x00000000,0x00030047,0x00000011,0x00000000,0x00030047,0x00000012,0x00000000,
|
||||
0x00030047,0x00000013,0x00000000,0x00030047,0x00000014,0x00000000,0x00030047,0x00000016,
|
||||
0x00000000,0x00030047,0x00000017,0x00000000,0x00030047,0x00000018,0x00000000,0x00030047,
|
||||
0x00000019,0x00000000,0x00030047,0x00000024,0x00000002,0x00050048,0x00000024,0x00000000,
|
||||
0x00000023,0x00000000,0x00050048,0x00000024,0x00000001,0x00000023,0x00000010,0x00040048,
|
||||
0x00000024,0x00000002,0x00000000,0x00050048,0x00000024,0x00000002,0x00000023,0x00000018,
|
||||
0x00030047,0x0000002f,0x00000000,0x00040047,0x0000002f,0x00000021,0x00000000,0x00040047,
|
||||
0x0000002f,0x00000022,0x00000000,0x00030047,0x00000030,0x00000000,0x00030047,0x00000033,
|
||||
0x00000000,0x00030047,0x00000034,0x00000000,0x00030047,0x00000037,0x00000000,0x00030047,
|
||||
0x00000038,0x00000000,0x00030047,0x00000039,0x00000000,0x00030047,0x0000003a,0x00000000,
|
||||
0x00030047,0x0000003b,0x00000000,0x00030047,0x0000003e,0x00000000,0x00030047,0x0000003f,
|
||||
0x00000000,0x00030047,0x00000040,0x00000000,0x00030047,0x00000041,0x00000000,0x00030047,
|
||||
0x00000042,0x00000000,0x00040047,0x00000047,0x0000001e,0x00000000,0x00030047,0x0000004d,
|
||||
0x00000000,0x00030047,0x00000054,0x00000000,0x00030047,0x00000056,0x00000000,0x00030047,
|
||||
0x00000057,0x00000000,0x00030047,0x00000058,0x00000000,0x00030047,0x0000005a,0x00000000,
|
||||
0x00030047,0x00000061,0x00000000,0x00030047,0x00000062,0x00000000,0x00030047,0x00000067,
|
||||
0x00000000,0x00030047,0x00000068,0x00000000,0x00030047,0x0000006b,0x00000000,0x00030047,
|
||||
0x0000006c,0x00000000,0x00030047,0x00000071,0x00000000,0x00030047,0x00000072,0x00000000,
|
||||
0x00030047,0x00000077,0x00000000,0x00030047,0x00000078,0x00000000,0x00030047,0x00000079,
|
||||
0x00000000,0x00030047,0x0000007d,0x00000000,0x00030047,0x0000007e,0x00000000,0x00030047,
|
||||
0x00000080,0x00000000,0x00030047,0x00000081,0x00000000,0x00030047,0x00000083,0x00000000,
|
||||
0x00030047,0x00000084,0x00000000,0x00030047,0x00000085,0x00000000,0x00030047,0x00000086,
|
||||
0x00000000,0x00030047,0x00000088,0x00000000,0x00030047,0x00000089,0x00000000,0x00030047,
|
||||
0x0000008b,0x00000000,0x00030047,0x0000008c,0x00000000,0x00030047,0x0000008d,0x00000000,
|
||||
0x00030047,0x0000008e,0x00000000,0x00030047,0x00000090,0x00000000,0x00030047,0x00000091,
|
||||
0x00000000,0x00030047,0x00000093,0x00000000,0x00030047,0x00000094,0x00000000,0x00030047,
|
||||
0x00000096,0x00000000,0x00030047,0x00000097,0x00000000,0x00030047,0x00000098,0x00000000,
|
||||
0x00030047,0x00000099,0x00000000,0x00030047,0x0000009b,0x00000000,0x00030047,0x0000009c,
|
||||
0x00000000,0x00030047,0x0000009e,0x00000000,0x00030047,0x0000009f,0x00000000,0x00030047,
|
||||
0x000000a0,0x00000000,0x00030047,0x000000a1,0x00000000,0x00030047,0x000000a3,0x00000000,
|
||||
0x00030047,0x000000a4,0x00000000,0x00030047,0x000000a5,0x00000000,0x00030047,0x000000a6,
|
||||
0x00000000,0x00030047,0x000000a7,0x00000000,0x00030047,0x000000a8,0x00000000,0x00030047,
|
||||
0x000000a9,0x00000000,0x00030047,0x000000aa,0x00000000,0x00030047,0x000000ab,0x00000000,
|
||||
0x00030047,0x000000ac,0x00000000,0x00030047,0x000000ad,0x00000000,0x00030047,0x000000ae,
|
||||
0x00000000,0x00030047,0x000000af,0x00000000,0x00030047,0x000000b0,0x00000000,0x00030047,
|
||||
0x000000b1,0x00000000,0x00030047,0x000000b2,0x00000000,0x00030047,0x000000b3,0x00000000,
|
||||
0x00030047,0x000000b5,0x00000000,0x00030047,0x000000b6,0x00000000,0x00030047,0x000000b7,
|
||||
0x00000000,0x00030047,0x000000b8,0x00000000,0x00030047,0x000000b9,0x00000000,0x00030047,
|
||||
0x000000ba,0x00000000,0x00030047,0x000000bb,0x00000000,0x00030047,0x000000bc,0x00000000,
|
||||
0x00030047,0x000000bd,0x00000000,0x00030047,0x000000be,0x00000000,0x00030047,0x000000bf,
|
||||
0x00000000,0x00030047,0x000000c0,0x00000000,0x00030047,0x000000c1,0x00000000,0x00030047,
|
||||
0x000000c2,0x00000000,0x00030047,0x000000c3,0x00000000,0x00030047,0x000000c4,0x00000000,
|
||||
0x00030047,0x000000c5,0x00000000,0x00030047,0x000000c6,0x00000000,0x00030047,0x000000c7,
|
||||
0x00000000,0x00030047,0x000000c8,0x00000000,0x00030047,0x000000c9,0x00000000,0x00030047,
|
||||
0x000000ca,0x00000000,0x00030047,0x000000cb,0x00000000,0x00030047,0x000000cc,0x00000000,
|
||||
0x00030047,0x000000cd,0x00000000,0x00030047,0x000000ce,0x00000000,0x00030047,0x000000cf,
|
||||
0x00000000,0x00030047,0x000000d1,0x00000000,0x00040047,0x000000d1,0x0000001e,0x00000000,
|
||||
0x00030047,0x000000d2,0x00000000,0x00030047,0x000000d3,0x00000000,0x00030047,0x000000d4,
|
||||
0x00000000,0x00030047,0x000000d5,0x00000000,0x00030047,0x000000d6,0x00000000,0x00020013,
|
||||
0x00000002,0x00030021,0x00000003,0x00000002,0x00040015,0x00000006,0x00000020,0x00000001,
|
||||
0x00040017,0x00000007,0x00000006,0x00000002,0x00040020,0x00000008,0x00000007,0x00000007,
|
||||
0x00030016,0x00000009,0x00000020,0x00040017,0x0000000a,0x00000009,0x00000003,0x00040021,
|
||||
0x0000000b,0x0000000a,0x00000008,0x00040020,0x0000000f,0x00000007,0x00000009,0x00060021,
|
||||
0x00000010,0x00000009,0x0000000f,0x0000000f,0x0000000f,0x00040017,0x0000001b,0x00000009,
|
||||
0x00000002,0x00040020,0x0000001c,0x00000007,0x0000001b,0x0004002b,0x00000009,0x00000020,
|
||||
0x3f000000,0x00040017,0x00000023,0x00000009,0x00000004,0x0005001e,0x00000024,0x00000023,
|
||||
0x0000001b,0x00000009,0x00040020,0x00000025,0x00000009,0x00000024,0x0004003b,0x00000025,
|
||||
0x00000026,0x00000009,0x0004002b,0x00000006,0x00000027,0x00000001,0x00040020,0x00000028,
|
||||
0x00000009,0x0000001b,0x00090019,0x0000002c,0x00000009,0x00000001,0x00000000,0x00000000,
|
||||
0x00000000,0x00000001,0x00000000,0x0003001b,0x0000002d,0x0000002c,0x00040020,0x0000002e,
|
||||
0x00000000,0x0000002d,0x0004003b,0x0000002e,0x0000002f,0x00000000,0x0004002b,0x00000009,
|
||||
0x00000032,0x00000000,0x00040020,0x00000046,0x00000001,0x0000001b,0x0004003b,0x00000046,
|
||||
0x00000047,0x00000001,0x0004002b,0x00000009,0x0000004e,0xbf800000,0x0004002b,0x00000009,
|
||||
0x0000004f,0x41000000,0x0004002b,0x00000009,0x00000050,0x40a00000,0x0004002b,0x00000006,
|
||||
0x00000051,0x00000002,0x00040020,0x00000052,0x00000009,0x00000009,0x0004002b,0x00000009,
|
||||
0x00000055,0x3f800000,0x00040020,0x00000059,0x00000007,0x0000000a,0x0004002b,0x00000006,
|
||||
0x0000005c,0x00000000,0x0004002b,0x00000006,0x0000005d,0xffffffff,0x0005002c,0x00000007,
|
||||
0x0000005e,0x0000005c,0x0000005d,0x0005002c,0x00000007,0x00000064,0x0000005d,0x0000005c,
|
||||
0x0005002c,0x00000007,0x0000006e,0x00000027,0x0000005c,0x0005002c,0x00000007,0x00000074,
|
||||
0x0000005c,0x00000027,0x00040015,0x0000007a,0x00000020,0x00000000,0x0004002b,0x0000007a,
|
||||
0x0000007b,0x00000001,0x0004002b,0x00000009,0x000000a2,0x3a800000,0x0004002b,0x00000009,
|
||||
0x000000b4,0x40800000,0x00040020,0x000000d0,0x00000003,0x00000023,0x0004003b,0x000000d0,
|
||||
0x000000d1,0x00000003,0x00050036,0x00000002,0x00000004,0x00000000,0x00000003,0x000200f8,
|
||||
0x00000005,0x0004003b,0x00000008,0x00000045,0x00000007,0x0004003b,0x0000000f,0x0000004d,
|
||||
0x00000007,0x0004003b,0x00000059,0x0000005a,0x00000007,0x0004003b,0x00000008,0x00000060,
|
||||
0x00000007,0x0004003b,0x00000059,0x00000062,0x00000007,0x0004003b,0x00000008,0x00000066,
|
||||
0x00000007,0x0004003b,0x00000059,0x00000068,0x00000007,0x0004003b,0x00000008,0x00000069,
|
||||
0x00000007,0x0004003b,0x00000059,0x0000006c,0x00000007,0x0004003b,0x00000008,0x00000070,
|
||||
0x00000007,0x0004003b,0x00000059,0x00000072,0x00000007,0x0004003b,0x00000008,0x00000076,
|
||||
0x00000007,0x0004003b,0x0000000f,0x00000078,0x00000007,0x0004003b,0x0000000f,0x00000079,
|
||||
0x00000007,0x0004003b,0x0000000f,0x0000007e,0x00000007,0x0004003b,0x0000000f,0x00000081,
|
||||
0x00000007,0x0004003b,0x0000000f,0x00000085,0x00000007,0x0004003b,0x0000000f,0x00000086,
|
||||
0x00000007,0x0004003b,0x0000000f,0x00000089,0x00000007,0x0004003b,0x0000000f,0x0000008d,
|
||||
0x00000007,0x0004003b,0x0000000f,0x0000008e,0x00000007,0x0004003b,0x0000000f,0x00000091,
|
||||
0x00000007,0x0004003b,0x0000000f,0x00000094,0x00000007,0x0004003b,0x0000000f,0x00000098,
|
||||
0x00000007,0x0004003b,0x0000000f,0x00000099,0x00000007,0x0004003b,0x0000000f,0x0000009c,
|
||||
0x00000007,0x0004003b,0x0000000f,0x000000a0,0x00000007,0x0004003b,0x0000000f,0x000000a5,
|
||||
0x00000007,0x0004003b,0x0000000f,0x000000af,0x00000007,0x0004003b,0x0000000f,0x000000b3,
|
||||
0x00000007,0x0004003b,0x00000059,0x000000b9,0x00000007,0x0004003d,0x0000001b,0x00000048,
|
||||
0x00000047,0x00050041,0x00000028,0x00000049,0x00000026,0x00000027,0x0004003d,0x0000001b,
|
||||
0x0000004a,0x00000049,0x00050085,0x0000001b,0x0000004b,0x00000048,0x0000004a,0x0004006e,
|
||||
0x00000007,0x0000004c,0x0000004b,0x0003003e,0x00000045,0x0000004c,0x00050041,0x00000052,
|
||||
0x00000053,0x00000026,0x00000051,0x0004003d,0x00000009,0x00000054,0x00000053,0x0008000c,
|
||||
0x00000009,0x00000056,0x00000001,0x0000002b,0x00000054,0x00000032,0x00000055,0x0008000c,
|
||||
0x00000009,0x00000057,0x00000001,0x0000002e,0x0000004f,0x00000050,0x00000056,0x00050088,
|
||||
0x00000009,0x00000058,0x0000004e,0x00000057,0x0003003e,0x0000004d,0x00000058,0x0004003d,
|
||||
0x00000007,0x0000005b,0x00000045,0x00050080,0x00000007,0x0000005f,0x0000005b,0x0000005e,
|
||||
0x0003003e,0x00000060,0x0000005f,0x00050039,0x0000000a,0x00000061,0x0000000d,0x00000060,
|
||||
0x0003003e,0x0000005a,0x00000061,0x0004003d,0x00000007,0x00000063,0x00000045,0x00050080,
|
||||
0x00000007,0x00000065,0x00000063,0x00000064,0x0003003e,0x00000066,0x00000065,0x00050039,
|
||||
0x0000000a,0x00000067,0x0000000d,0x00000066,0x0003003e,0x00000062,0x00000067,0x0004003d,
|
||||
0x00000007,0x0000006a,0x00000045,0x0003003e,0x00000069,0x0000006a,0x00050039,0x0000000a,
|
||||
0x0000006b,0x0000000d,0x00000069,0x0003003e,0x00000068,0x0000006b,0x0004003d,0x00000007,
|
||||
0x0000006d,0x00000045,0x00050080,0x00000007,0x0000006f,0x0000006d,0x0000006e,0x0003003e,
|
||||
0x00000070,0x0000006f,0x00050039,0x0000000a,0x00000071,0x0000000d,0x00000070,0x0003003e,
|
||||
0x0000006c,0x00000071,0x0004003d,0x00000007,0x00000073,0x00000045,0x00050080,0x00000007,
|
||||
0x00000075,0x00000073,0x00000074,0x0003003e,0x00000076,0x00000075,0x00050039,0x0000000a,
|
||||
0x00000077,0x0000000d,0x00000076,0x0003003e,0x00000072,0x00000077,0x00050041,0x0000000f,
|
||||
0x0000007c,0x00000062,0x0000007b,0x0004003d,0x00000009,0x0000007d,0x0000007c,0x0003003e,
|
||||
0x00000079,0x0000007d,0x00050041,0x0000000f,0x0000007f,0x00000068,0x0000007b,0x0004003d,
|
||||
0x00000009,0x00000080,0x0000007f,0x0003003e,0x0000007e,0x00000080,0x00050041,0x0000000f,
|
||||
0x00000082,0x0000006c,0x0000007b,0x0004003d,0x00000009,0x00000083,0x00000082,0x0003003e,
|
||||
0x00000081,0x00000083,0x00070039,0x00000009,0x00000084,0x00000014,0x00000079,0x0000007e,
|
||||
0x00000081,0x0003003e,0x00000085,0x00000084,0x00050041,0x0000000f,0x00000087,0x0000005a,
|
||||
0x0000007b,0x0004003d,0x00000009,0x00000088,0x00000087,0x0003003e,0x00000086,0x00000088,
|
||||
0x00050041,0x0000000f,0x0000008a,0x00000072,0x0000007b,0x0004003d,0x00000009,0x0000008b,
|
||||
0x0000008a,0x0003003e,0x00000089,0x0000008b,0x00070039,0x00000009,0x0000008c,0x00000014,
|
||||
0x00000085,0x00000086,0x00000089,0x0003003e,0x00000078,0x0000008c,0x00050041,0x0000000f,
|
||||
0x0000008f,0x00000062,0x0000007b,0x0004003d,0x00000009,0x00000090,0x0000008f,0x0003003e,
|
||||
0x0000008e,0x00000090,0x00050041,0x0000000f,0x00000092,0x00000068,0x0000007b,0x0004003d,
|
||||
0x00000009,0x00000093,0x00000092,0x0003003e,0x00000091,0x00000093,0x00050041,0x0000000f,
|
||||
0x00000095,0x0000006c,0x0000007b,0x0004003d,0x00000009,0x00000096,0x00000095,0x0003003e,
|
||||
0x00000094,0x00000096,0x00070039,0x00000009,0x00000097,0x00000019,0x0000008e,0x00000091,
|
||||
0x00000094,0x0003003e,0x00000098,0x00000097,0x00050041,0x0000000f,0x0000009a,0x0000005a,
|
||||
0x0000007b,0x0004003d,0x00000009,0x0000009b,0x0000009a,0x0003003e,0x00000099,0x0000009b,
|
||||
0x00050041,0x0000000f,0x0000009d,0x00000072,0x0000007b,0x0004003d,0x00000009,0x0000009e,
|
||||
0x0000009d,0x0003003e,0x0000009c,0x0000009e,0x00070039,0x00000009,0x0000009f,0x00000019,
|
||||
0x00000098,0x00000099,0x0000009c,0x0003003e,0x0000008d,0x0000009f,0x0004003d,0x00000009,
|
||||
0x000000a1,0x0000008d,0x0007000c,0x00000009,0x000000a3,0x00000001,0x00000028,0x000000a1,
|
||||
0x000000a2,0x00050088,0x00000009,0x000000a4,0x00000055,0x000000a3,0x0003003e,0x000000a0,
|
||||
0x000000a4,0x0004003d,0x00000009,0x000000a6,0x00000078,0x0004003d,0x00000009,0x000000a7,
|
||||
0x0000008d,0x00050083,0x00000009,0x000000a8,0x00000055,0x000000a7,0x0007000c,0x00000009,
|
||||
0x000000a9,0x00000001,0x00000025,0x000000a6,0x000000a8,0x0004003d,0x00000009,0x000000aa,
|
||||
0x000000a0,0x00050085,0x00000009,0x000000ab,0x000000a9,0x000000aa,0x0008000c,0x00000009,
|
||||
0x000000ac,0x00000001,0x0000002b,0x000000ab,0x00000032,0x00000055,0x0003003e,0x000000a5,
|
||||
0x000000ac,0x0004003d,0x00000009,0x000000ad,0x000000a5,0x0006000c,0x00000009,0x000000ae,
|
||||
0x00000001,0x0000001f,0x000000ad,0x0003003e,0x000000a5,0x000000ae,0x0004003d,0x00000009,
|
||||
0x000000b0,0x000000a5,0x0004003d,0x00000009,0x000000b1,0x0000004d,0x00050085,0x00000009,
|
||||
0x000000b2,0x000000b0,0x000000b1,0x0003003e,0x000000af,0x000000b2,0x0004003d,0x00000009,
|
||||
0x000000b5,0x000000af,0x00050085,0x00000009,0x000000b6,0x000000b4,0x000000b5,0x00050081,
|
||||
0x00000009,0x000000b7,0x00000055,0x000000b6,0x00050088,0x00000009,0x000000b8,0x00000055,
|
||||
0x000000b7,0x0003003e,0x000000b3,0x000000b8,0x0004003d,0x0000000a,0x000000ba,0x0000005a,
|
||||
0x0004003d,0x00000009,0x000000bb,0x000000af,0x0005008e,0x0000000a,0x000000bc,0x000000ba,
|
||||
0x000000bb,0x0004003d,0x0000000a,0x000000bd,0x00000062,0x0004003d,0x00000009,0x000000be,
|
||||
0x000000af,0x0005008e,0x0000000a,0x000000bf,0x000000bd,0x000000be,0x00050081,0x0000000a,
|
||||
0x000000c0,0x000000bc,0x000000bf,0x0004003d,0x0000000a,0x000000c1,0x0000006c,0x0004003d,
|
||||
0x00000009,0x000000c2,0x000000af,0x0005008e,0x0000000a,0x000000c3,0x000000c1,0x000000c2,
|
||||
0x00050081,0x0000000a,0x000000c4,0x000000c0,0x000000c3,0x0004003d,0x0000000a,0x000000c5,
|
||||
0x00000072,0x0004003d,0x00000009,0x000000c6,0x000000af,0x0005008e,0x0000000a,0x000000c7,
|
||||
0x000000c5,0x000000c6,0x00050081,0x0000000a,0x000000c8,0x000000c4,0x000000c7,0x0004003d,
|
||||
0x0000000a,0x000000c9,0x00000068,0x00050081,0x0000000a,0x000000ca,0x000000c8,0x000000c9,
|
||||
0x0004003d,0x00000009,0x000000cb,0x000000b3,0x0005008e,0x0000000a,0x000000cc,0x000000ca,
|
||||
0x000000cb,0x00060050,0x0000000a,0x000000cd,0x00000032,0x00000032,0x00000032,0x00060050,
|
||||
0x0000000a,0x000000ce,0x00000055,0x00000055,0x00000055,0x0008000c,0x0000000a,0x000000cf,
|
||||
0x00000001,0x0000002b,0x000000cc,0x000000cd,0x000000ce,0x0003003e,0x000000b9,0x000000cf,
|
||||
0x0004003d,0x0000000a,0x000000d2,0x000000b9,0x00050051,0x00000009,0x000000d3,0x000000d2,
|
||||
0x00000000,0x00050051,0x00000009,0x000000d4,0x000000d2,0x00000001,0x00050051,0x00000009,
|
||||
0x000000d5,0x000000d2,0x00000002,0x00070050,0x00000023,0x000000d6,0x000000d3,0x000000d4,
|
||||
0x000000d5,0x00000055,0x0003003e,0x000000d1,0x000000d6,0x000100fd,0x00010038,0x00050036,
|
||||
0x0000000a,0x0000000d,0x00000000,0x0000000b,0x00030037,0x00000008,0x0000000c,0x000200f8,
|
||||
0x0000000e,0x0004003b,0x0000001c,0x0000001d,0x00000007,0x0004003d,0x00000007,0x0000001e,
|
||||
0x0000000c,0x0004006f,0x0000001b,0x0000001f,0x0000001e,0x00050050,0x0000001b,0x00000021,
|
||||
0x00000020,0x00000020,0x00050081,0x0000001b,0x00000022,0x0000001f,0x00000021,0x00050041,
|
||||
0x00000028,0x00000029,0x00000026,0x00000027,0x0004003d,0x0000001b,0x0000002a,0x00000029,
|
||||
0x00050088,0x0000001b,0x0000002b,0x00000022,0x0000002a,0x0003003e,0x0000001d,0x0000002b,
|
||||
0x0004003d,0x0000002d,0x00000030,0x0000002f,0x0004003d,0x0000001b,0x00000031,0x0000001d,
|
||||
0x00070058,0x00000023,0x00000033,0x00000030,0x00000031,0x00000002,0x00000032,0x0008004f,
|
||||
0x0000000a,0x00000034,0x00000033,0x00000033,0x00000000,0x00000001,0x00000002,0x000200fe,
|
||||
0x00000034,0x00010038,0x00050036,0x00000009,0x00000014,0x00000000,0x00000010,0x00030037,
|
||||
0x0000000f,0x00000011,0x00030037,0x0000000f,0x00000012,0x00030037,0x0000000f,0x00000013,
|
||||
0x000200f8,0x00000015,0x0004003d,0x00000009,0x00000037,0x00000011,0x0004003d,0x00000009,
|
||||
0x00000038,0x00000012,0x0004003d,0x00000009,0x00000039,0x00000013,0x0007000c,0x00000009,
|
||||
0x0000003a,0x00000001,0x00000025,0x00000038,0x00000039,0x0007000c,0x00000009,0x0000003b,
|
||||
0x00000001,0x00000025,0x00000037,0x0000003a,0x000200fe,0x0000003b,0x00010038,0x00050036,
|
||||
0x00000009,0x00000019,0x00000000,0x00000010,0x00030037,0x0000000f,0x00000016,0x00030037,
|
||||
0x0000000f,0x00000017,0x00030037,0x0000000f,0x00000018,0x000200f8,0x0000001a,0x0004003d,
|
||||
0x00000009,0x0000003e,0x00000016,0x0004003d,0x00000009,0x0000003f,0x00000017,0x0004003d,
|
||||
0x00000009,0x00000040,0x00000018,0x0007000c,0x00000009,0x00000041,0x00000001,0x00000028,
|
||||
0x0000003f,0x00000040,0x0007000c,0x00000009,0x00000042,0x00000001,0x00000028,0x0000003e,
|
||||
0x00000041,0x000200fe,0x00000042,0x00010038
|
||||
};
|
||||
@@ -0,0 +1 @@
|
||||
ZeroFG is fetched by CMake from hy300leosquizz-ctrl/ZeroFG (the upstream repository) at pinned commit e6ca7ef9f9765db89847b6d8eed352e458f1a8bb. DroidDeck keeps ownership of presentation; the independent presenter is not used. License: Apache-2.0 OR GPL-2.0-or-later; see the fetched ZeroFG source tree for the license text.
|
||||
@@ -42,6 +42,11 @@ add_library(droiddeckwayland SHARED
|
||||
src/hudframes.c
|
||||
src/hudframes_jni.c
|
||||
)
|
||||
option(DROIDDECK_FRAME_ACQUIRE_PROBE "Build opt-in signaled producer acquire protocol support" ON)
|
||||
if (DROIDDECK_FRAME_ACQUIRE_PROBE)
|
||||
target_sources(droiddeckwayland PRIVATE generated/droiddeck-frame-acquire-v1-protocol.c)
|
||||
target_compile_definitions(droiddeckwayland PRIVATE DROIDDECK_FRAME_ACQUIRE_PROBE=1)
|
||||
endif()
|
||||
target_compile_options(droiddeckwayland PRIVATE
|
||||
$<$<COMPILE_LANGUAGE:C>:-Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers>)
|
||||
target_include_directories(droiddeckwayland PRIVATE
|
||||
@@ -59,6 +64,7 @@ if (TARGET dxbc AND EXISTS ${DROIDDECK_FRAMEGEN_LSFG_DIR}/lsfg_engine.cpp
|
||||
message(STATUS "droiddeckwayland: frame-generation engines built in (LSFG Native, DD-FG Native)")
|
||||
target_sources(droiddeckwayland PRIVATE
|
||||
src/framegen_engine.cpp
|
||||
src/framegen_zerofg.cpp
|
||||
${DROIDDECK_FRAMEGEN_LSFG_DIR}/lsfg_probe.cpp
|
||||
${DROIDDECK_FRAMEGEN_LSFG_DIR}/lsfg_dll.cpp
|
||||
${DROIDDECK_FRAMEGEN_LSFG_DIR}/lsfg_dxbc.cpp
|
||||
@@ -85,12 +91,12 @@ if (TARGET dxbc AND EXISTS ${DROIDDECK_FRAMEGEN_LSFG_DIR}/lsfg_engine.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../framegen
|
||||
)
|
||||
target_compile_options(droiddeckwayland PRIVATE
|
||||
$<$<COMPILE_LANGUAGE:CXX>:-std=c++17 -fvisibility=hidden>)
|
||||
$<$<COMPILE_LANGUAGE:CXX>:-std=c++20 -fvisibility=hidden>)
|
||||
target_compile_definitions(droiddeckwayland PRIVATE
|
||||
DDFG_UPSTREAM="${DDFG_UPSTREAM}"
|
||||
DDFG_CHAIN_HASH="${DDFG_CHAIN_HASH}"
|
||||
)
|
||||
target_link_libraries(droiddeckwayland dxbc atomic)
|
||||
target_link_libraries(droiddeckwayland dxbc atomic zerofg::zerofg)
|
||||
else()
|
||||
message(STATUS "droiddeckwayland: frame-generation engines NOT built in (standalone build): stub")
|
||||
target_sources(droiddeckwayland PRIVATE src/framegen_engine_stub.c)
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
/* Generated by wayland-scanner 1.22.0 */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include "wayland-util.h"
|
||||
|
||||
#ifndef __has_attribute
|
||||
# define __has_attribute(x) 0 /* Compatibility with non-clang compilers. */
|
||||
#endif
|
||||
|
||||
#if (__has_attribute(visibility) || defined(__GNUC__) && __GNUC__ >= 4)
|
||||
#define WL_PRIVATE __attribute__ ((visibility("hidden")))
|
||||
#else
|
||||
#define WL_PRIVATE
|
||||
#endif
|
||||
|
||||
extern const struct wl_interface wl_buffer_interface;
|
||||
extern const struct wl_interface wl_surface_interface;
|
||||
|
||||
static const struct wl_interface *droiddeck_frame_acquire_v1_types[] = {
|
||||
&wl_surface_interface,
|
||||
&wl_buffer_interface,
|
||||
NULL,
|
||||
};
|
||||
|
||||
static const struct wl_message droiddeck_frame_acquire_v1_requests[] = {
|
||||
{ "destroy", "", droiddeck_frame_acquire_v1_types + 0 },
|
||||
{ "set_acquire_fence", "ooh", droiddeck_frame_acquire_v1_types + 0 },
|
||||
};
|
||||
|
||||
WL_PRIVATE const struct wl_interface droiddeck_frame_acquire_v1_interface = {
|
||||
"droiddeck_frame_acquire_v1", 1,
|
||||
2, droiddeck_frame_acquire_v1_requests,
|
||||
0, NULL,
|
||||
};
|
||||
@@ -0,0 +1,128 @@
|
||||
/* Generated by wayland-scanner 1.22.0 */
|
||||
|
||||
#ifndef DROIDDECK_FRAME_ACQUIRE_V1_SERVER_PROTOCOL_H
|
||||
#define DROIDDECK_FRAME_ACQUIRE_V1_SERVER_PROTOCOL_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include "wayland-server.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct wl_client;
|
||||
struct wl_resource;
|
||||
|
||||
/**
|
||||
* @page page_droiddeck_frame_acquire_v1 The droiddeck_frame_acquire_v1 protocol
|
||||
* @section page_ifaces_droiddeck_frame_acquire_v1 Interfaces
|
||||
* - @subpage page_iface_droiddeck_frame_acquire_v1 - DroidDeck producer write completion for a single Wayland attachment
|
||||
*/
|
||||
struct droiddeck_frame_acquire_v1;
|
||||
struct wl_buffer;
|
||||
struct wl_surface;
|
||||
|
||||
#ifndef DROIDDECK_FRAME_ACQUIRE_V1_INTERFACE
|
||||
#define DROIDDECK_FRAME_ACQUIRE_V1_INTERFACE
|
||||
/**
|
||||
* @page page_iface_droiddeck_frame_acquire_v1 droiddeck_frame_acquire_v1
|
||||
* @section page_iface_droiddeck_frame_acquire_v1_desc Description
|
||||
*
|
||||
* Optional explicit acquire sideband independent of DRM syncobj and buffer
|
||||
* allocation. Binding does not opt the client out of ordinary wl_buffer
|
||||
* release or existing synchronization protocols. The server advertises it
|
||||
* only when it implements all semantics for the selected display path.
|
||||
* @section page_iface_droiddeck_frame_acquire_v1_api API
|
||||
* See @ref iface_droiddeck_frame_acquire_v1.
|
||||
*/
|
||||
/**
|
||||
* @defgroup iface_droiddeck_frame_acquire_v1 The droiddeck_frame_acquire_v1 interface
|
||||
*
|
||||
* Optional explicit acquire sideband independent of DRM syncobj and buffer
|
||||
* allocation. Binding does not opt the client out of ordinary wl_buffer
|
||||
* release or existing synchronization protocols. The server advertises it
|
||||
* only when it implements all semantics for the selected display path.
|
||||
*/
|
||||
extern const struct wl_interface droiddeck_frame_acquire_v1_interface;
|
||||
#endif
|
||||
|
||||
#ifndef DROIDDECK_FRAME_ACQUIRE_V1_ERROR_ENUM
|
||||
#define DROIDDECK_FRAME_ACQUIRE_V1_ERROR_ENUM
|
||||
enum droiddeck_frame_acquire_v1_error {
|
||||
/**
|
||||
* not the same client's pending DMA-BUF attachment
|
||||
*/
|
||||
DROIDDECK_FRAME_ACQUIRE_V1_ERROR_INVALID_ATTACHMENT = 0,
|
||||
/**
|
||||
* that attachment already has an acquire fence
|
||||
*/
|
||||
DROIDDECK_FRAME_ACQUIRE_V1_ERROR_DUPLICATE_FENCE = 1,
|
||||
/**
|
||||
* not a real successfully signaled Linux sync_file
|
||||
*/
|
||||
DROIDDECK_FRAME_ACQUIRE_V1_ERROR_INVALID_FENCE = 2,
|
||||
/**
|
||||
* not the paired test peer
|
||||
*/
|
||||
DROIDDECK_FRAME_ACQUIRE_V1_ERROR_UNAUTHORIZED_PEER = 3,
|
||||
};
|
||||
#endif /* DROIDDECK_FRAME_ACQUIRE_V1_ERROR_ENUM */
|
||||
|
||||
/**
|
||||
* @ingroup iface_droiddeck_frame_acquire_v1
|
||||
* @struct droiddeck_frame_acquire_v1_interface
|
||||
*/
|
||||
struct droiddeck_frame_acquire_v1_interface {
|
||||
/**
|
||||
*/
|
||||
void (*destroy)(struct wl_client *client,
|
||||
struct wl_resource *resource);
|
||||
/**
|
||||
* set a one-shot kernel sync_file for the pending attachment
|
||||
*
|
||||
* After wl_surface.attach of a non-null buffer, and before its
|
||||
* next wl_surface.commit, send the producer's final writer fence
|
||||
* for that exact attachment. This outer probe requires that fence
|
||||
* to have already successfully signaled. The fence must be a real
|
||||
* Linux sync_file, not a dma-buf, eventfd, or Vulkan OPAQUE_FD.
|
||||
* The server consumes its received descriptor once for that
|
||||
* attachment; the caller closes its local FD after marshalling.
|
||||
*
|
||||
* The receiver validates the matching pending surface and buffer
|
||||
* and validates the descriptor. A duplicate, invalid, pending or
|
||||
* mismatched request is a protocol error; it is never downgraded
|
||||
* to implicit sync. Another attach (even the same wl_buffer),
|
||||
* detach, surface/resource loss or supersession makes the old
|
||||
* proof inapplicable. Metadata-only commits may amend
|
||||
* receiver-side still-pending state but cannot introduce or re-use
|
||||
* a fence themselves. If no request was made, the receiver keeps
|
||||
* its established safe path. If a valid fence has been accepted
|
||||
* and later the layer is ineligible, the buffer must not be
|
||||
* copied/read before that fence is satisfied or imported as the
|
||||
* source dependency. Transport never implies readiness on missed
|
||||
* deadlines and never changes release/retirement requirements.
|
||||
* @param fence producer's native acquire sync_file
|
||||
*/
|
||||
void (*set_acquire_fence)(struct wl_client *client,
|
||||
struct wl_resource *resource,
|
||||
struct wl_resource *surface,
|
||||
struct wl_resource *buffer,
|
||||
int32_t fence);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @ingroup iface_droiddeck_frame_acquire_v1
|
||||
*/
|
||||
#define DROIDDECK_FRAME_ACQUIRE_V1_DESTROY_SINCE_VERSION 1
|
||||
/**
|
||||
* @ingroup iface_droiddeck_frame_acquire_v1
|
||||
*/
|
||||
#define DROIDDECK_FRAME_ACQUIRE_V1_SET_ACQUIRE_FENCE_SINCE_VERSION 1
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,45 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<protocol name="droiddeck_frame_acquire_v1">
|
||||
<interface name="droiddeck_frame_acquire_v1" version="1">
|
||||
<description summary="DroidDeck producer write completion for a single Wayland attachment">
|
||||
Optional explicit acquire sideband independent of DRM syncobj and buffer
|
||||
allocation. Binding does not opt the client out of ordinary wl_buffer
|
||||
release or existing synchronization protocols. The server advertises it
|
||||
only when it implements all semantics for the selected display path and
|
||||
only to the test fixture's app-authorized Gamescope worker.
|
||||
</description>
|
||||
<request name="destroy" type="destructor"/>
|
||||
<enum name="error">
|
||||
<entry name="invalid_attachment" value="0" summary="not the same client's pending DMA-BUF attachment"/>
|
||||
<entry name="duplicate_fence" value="1" summary="that attachment already has an acquire fence"/>
|
||||
<entry name="invalid_fence" value="2" summary="not a real successfully signaled Linux sync_file"/>
|
||||
<entry name="unauthorized_peer" value="3" summary="not the paired test peer"/>
|
||||
</enum>
|
||||
<request name="set_acquire_fence">
|
||||
<description summary="set a one-shot kernel sync_file for the pending attachment">
|
||||
After wl_surface.attach of a non-null buffer, and before its next
|
||||
wl_surface.commit, send the producer's final writer fence for that
|
||||
exact attachment. This outer probe requires that fence to have already
|
||||
successfully signaled. The fence must be a real Linux sync_file, not a
|
||||
dma-buf, eventfd, or Vulkan OPAQUE_FD. The server consumes its received
|
||||
descriptor once for that attachment; the caller closes its local FD
|
||||
after marshalling.
|
||||
|
||||
The receiver validates the matching pending surface and buffer and
|
||||
validates the descriptor. A duplicate, invalid, pending or mismatched
|
||||
request is a protocol error; it is never downgraded to implicit sync. Another attach (even the same
|
||||
wl_buffer), detach, surface/resource loss or supersession makes the
|
||||
old proof inapplicable. Metadata-only commits may amend receiver-side
|
||||
still-pending state but cannot introduce or re-use a fence themselves.
|
||||
If no request was made, the receiver keeps its established safe path.
|
||||
If a valid fence has been accepted and later the layer is ineligible,
|
||||
the buffer must not be copied/read before that fence is satisfied or
|
||||
imported as the source dependency. Transport never implies readiness
|
||||
on missed deadlines and never changes release/retirement requirements.
|
||||
</description>
|
||||
<arg name="surface" type="object" interface="wl_surface"/>
|
||||
<arg name="buffer" type="object" interface="wl_buffer"/>
|
||||
<arg name="fence" type="fd" summary="producer's native acquire sync_file"/>
|
||||
</request>
|
||||
</interface>
|
||||
</protocol>
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "droiddeck-ahb-v1-server-protocol.h"
|
||||
#include <android/hardware_buffer.h>
|
||||
#include <errno.h>
|
||||
#include <linux/sync_file.h>
|
||||
#include <fcntl.h>
|
||||
#include <poll.h>
|
||||
#include <pthread.h>
|
||||
@@ -53,6 +54,7 @@ static struct wl_list g_clients;
|
||||
static uint64_t g_next_id = 1;
|
||||
static struct wl_event_loop *g_loop;
|
||||
static unsigned g_stat_zero_copy;
|
||||
static unsigned g_stat_producer_fence;
|
||||
static int g_export_failed_logged, g_import_failed_logged;
|
||||
static int g_advertised;
|
||||
static int g_mode_sent = -1;
|
||||
@@ -145,6 +147,12 @@ static void handle_released(uint64_t id, int fd) {
|
||||
if (poll(&p, 1, 0) > 0) {
|
||||
close(fd);
|
||||
} else {
|
||||
if (ab->fence_src) {
|
||||
struct sync_merge_data m = {.name = "droiddeck-release", .fd2 = fd};
|
||||
if (ioctl(ab->fence_fd, SYNC_IOC_MERGE, &m) == 0) { close(fd); fd = m.fence; }
|
||||
wl_event_source_remove(ab->fence_src);
|
||||
close(ab->fence_fd);
|
||||
}
|
||||
ab->fence_fd = fd;
|
||||
ab->fence_src = wl_event_loop_add_fd(g_loop, fd, WL_EVENT_READABLE, on_fence_readable, ab);
|
||||
if (!ab->fence_src) { close(fd); ab->fence_fd = -1; }
|
||||
@@ -152,6 +160,7 @@ static void handle_released(uint64_t id, int fd) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ab->fence_src) return;
|
||||
send_deferred_release(ab);
|
||||
maybe_free(ab);
|
||||
}
|
||||
@@ -193,27 +202,47 @@ int ahb_swapchain_present(struct dmabuf_buffer *b, struct surface *s, int scene_
|
||||
struct ahb_buf *ab = b ? *droiddeck_dmabuf_ahb_slot(b) : NULL;
|
||||
if (!ab) return -1;
|
||||
int dmabuf_fd = droiddeck_dmabuf_fd(b);
|
||||
int acquire = -1;
|
||||
struct droiddeck_dma_buf_sync_file exp = {.flags = DROIDDECK_DMA_BUF_SYNC_READ, .fd = -1};
|
||||
if (dmabuf_fd >= 0 && ioctl(dmabuf_fd, DROIDDECK_DMA_BUF_IOCTL_EXPORT_SYNC_FILE, &exp) == 0 && exp.fd >= 0) {
|
||||
acquire = exp.fd;
|
||||
} else if (dmabuf_fd >= 0) {
|
||||
if (!g_export_failed_logged) {
|
||||
g_export_failed_logged = 1;
|
||||
droiddeck_log("layer", "zero-copy: DMA_BUF_IOCTL_EXPORT_SYNC_FILE failed (%s): waiting for each frame on the CPU instead",
|
||||
strerror(errno));
|
||||
int acquire = droiddeck_surface_dup_acquire(s, b);
|
||||
if (acquire == -2) return -1;
|
||||
#ifdef DROIDDECK_FRAME_ACQUIRE_PROBE
|
||||
const int explicit_acquire = acquire >= 0;
|
||||
#endif
|
||||
if (acquire < 0) {
|
||||
struct droiddeck_dma_buf_sync_file exp = {.flags = DROIDDECK_DMA_BUF_SYNC_READ, .fd = -1};
|
||||
if (dmabuf_fd >= 0 && ioctl(dmabuf_fd, DROIDDECK_DMA_BUF_IOCTL_EXPORT_SYNC_FILE, &exp) == 0 && exp.fd >= 0) {
|
||||
acquire = exp.fd;
|
||||
} else {
|
||||
if (!g_export_failed_logged) {
|
||||
g_export_failed_logged = 1;
|
||||
droiddeck_log("layer", "zero-copy: no acquire fence from the game's dma-buf (%s): %s",
|
||||
dmabuf_fd >= 0 ? strerror(errno) : "no dma-buf fd",
|
||||
draw ? "its frames are copied instead" : "it cannot be copied, so each frame is waited for on the CPU");
|
||||
}
|
||||
if (dmabuf_fd >= 0) {
|
||||
struct pollfd p = {.fd = dmabuf_fd, .events = POLLIN};
|
||||
int r;
|
||||
do { r = poll(&p, 1, 100); } while (r < 0 && errno == EINTR);
|
||||
}
|
||||
if (draw) return -1;
|
||||
}
|
||||
struct pollfd p = {.fd = dmabuf_fd, .events = POLLIN};
|
||||
int r;
|
||||
do { r = poll(&p, 1, 100); } while (r < 0 && errno == EINTR);
|
||||
}
|
||||
int r = sc_layer_present_ahb(ab->ahb, ab->w, ab->h, acquire, (void *)(uintptr_t)ab->id, scene_w, scene_h, draw,
|
||||
s ? droiddeck_surface_color(s) : NULL, ab->format);
|
||||
if (r < 0) return -1;
|
||||
if (r == 1) return 0;
|
||||
#ifdef DROIDDECK_FRAME_ACQUIRE_PROBE
|
||||
static int explicit_logged;
|
||||
if (explicit_acquire && !explicit_logged) {
|
||||
explicit_logged = 1;
|
||||
droiddeck_log("layer", "probe: SurfaceControl accepted a verified producer acquire fence");
|
||||
}
|
||||
#endif
|
||||
if (!ab->on_layer) {
|
||||
ab->on_layer = 1;
|
||||
g_stat_zero_copy++;
|
||||
#ifdef DROIDDECK_FRAME_ACQUIRE_PROBE
|
||||
if (explicit_acquire) g_stat_producer_fence++;
|
||||
#endif
|
||||
g_last_zero_copy_ns = now_ns();
|
||||
}
|
||||
if (s && g_announced != s) {
|
||||
@@ -253,6 +282,12 @@ unsigned ahb_swapchain_stats_take(void) {
|
||||
return n;
|
||||
}
|
||||
|
||||
unsigned ahb_swapchain_producer_fence_stats_take(void) {
|
||||
unsigned n = g_stat_producer_fence;
|
||||
g_stat_producer_fence = 0;
|
||||
return n;
|
||||
}
|
||||
|
||||
int ahb_swapchain_advertised(void) { return g_advertised; }
|
||||
|
||||
uint32_t ahb_swapchain_ahb_format(const struct dmabuf_buffer *b) {
|
||||
|
||||
@@ -20,7 +20,9 @@ int ahb_swapchain_present(struct dmabuf_buffer *b, struct surface *s, int scene_
|
||||
int ahb_swapchain_defer_release(struct dmabuf_buffer *b, struct wl_resource *buffer, struct surface *s, int paced);
|
||||
void ahb_swapchain_surface_gone(struct surface *s);
|
||||
unsigned ahb_swapchain_stats_take(void);
|
||||
unsigned ahb_swapchain_producer_fence_stats_take(void);
|
||||
int ahb_swapchain_advertised(void);
|
||||
int droiddeck_surface_dup_acquire(const struct surface *s, const struct dmabuf_buffer *b);
|
||||
uint32_t ahb_swapchain_ahb_format(const struct dmabuf_buffer *b);
|
||||
|
||||
void ahb_swapchain_layer_released(void *token, int release_fd);
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -62,8 +62,40 @@ struct entry {
|
||||
static struct wl_list g_entries;
|
||||
static struct wl_event_loop *g_loop;
|
||||
static uint64_t g_next_id = 1;
|
||||
static int g_refused_logged;
|
||||
static int g_ubwc_promised;
|
||||
|
||||
#define DISPLAY_BUFFER_MISMATCH_SIGNATURES 64u
|
||||
struct display_buffer_mismatch_signature {
|
||||
uint32_t kind, format, stride, offset;
|
||||
int width, height;
|
||||
uint64_t modifier;
|
||||
};
|
||||
static struct display_buffer_mismatch_signature g_mismatch_signatures[DISPLAY_BUFFER_MISMATCH_SIGNATURES];
|
||||
static uint32_t g_mismatch_signature_count;
|
||||
static int g_mismatch_limit_logged;
|
||||
|
||||
static int mismatch_should_log(const struct dmabuf_buffer *b, uint32_t kind) {
|
||||
const struct display_buffer_mismatch_signature key = {
|
||||
.kind = kind, .format = b->format, .stride = b->stride[0], .offset = b->offset[0],
|
||||
.width = b->width, .height = b->height, .modifier = b->modifier};
|
||||
for (uint32_t i = 0; i < g_mismatch_signature_count; i++) {
|
||||
const struct display_buffer_mismatch_signature *seen = &g_mismatch_signatures[i];
|
||||
if (seen->kind == key.kind && seen->format == key.format && seen->stride == key.stride &&
|
||||
seen->offset == key.offset && seen->width == key.width && seen->height == key.height &&
|
||||
seen->modifier == key.modifier)
|
||||
return 0;
|
||||
}
|
||||
if (g_mismatch_signature_count >= DISPLAY_BUFFER_MISMATCH_SIGNATURES) {
|
||||
if (!g_mismatch_limit_logged) {
|
||||
g_mismatch_limit_logged = 1;
|
||||
droiddeck_log("layer", "display buffers: further mismatch diagnostics suppressed after %u distinct buffer signatures",
|
||||
DISPLAY_BUFFER_MISMATCH_SIGNATURES);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
g_mismatch_signatures[g_mismatch_signature_count++] = key;
|
||||
return 1;
|
||||
}
|
||||
static int g_ubwc_probed[2];
|
||||
|
||||
static uint32_t ahb_format_of(uint32_t drm, uint64_t modifier) {
|
||||
@@ -238,16 +270,51 @@ static void handle_alloc(struct peer *p, const struct display_buffers_request *q
|
||||
} else {
|
||||
if (ahb) AHardwareBuffer_release(ahb);
|
||||
fd = -1;
|
||||
if (sized && wanted && (compressed || !g_refused_logged)) {
|
||||
g_refused_logged = 1;
|
||||
droiddeck_log(compressed ? "error" : "layer", "display buffers: no gralloc buffer matches pid %d's %ux%u "
|
||||
"%c%c%c%c %s layout (stride %u bytes, pixels at %u, %llu bytes; gralloc's layout has pixels at "
|
||||
"%llu, %llu bytes): %s", (int)p->pid, q->width, q->height,
|
||||
q->format & 0xff, (q->format >> 8) & 0xff, (q->format >> 16) & 0xff, (q->format >> 24) & 0xff,
|
||||
compressed ? "UBWC" : "linear", q->stride, q->offset, (unsigned long long)q->size,
|
||||
(unsigned long long)(compressed ? ubwc_meta_size(q->width, q->height) : 0),
|
||||
(unsigned long long)(compressed ? ubwc_size(q->width, q->height, q->stride) : q->size),
|
||||
compressed ? "its compressed frames cannot be shown" : "its frames keep the copy path");
|
||||
static struct {
|
||||
pid_t pid;
|
||||
uint32_t width, height, format, stride, offset, reason;
|
||||
uint64_t size, modifier;
|
||||
} refused[32];
|
||||
static unsigned refused_count;
|
||||
static int refused_limit_logged;
|
||||
uint32_t reason = !sized ? 1u : !sane ? 2u : !wanted ? 3u :
|
||||
!ahb_swapchain_advertised() ? 4u :
|
||||
p->count >= DISPLAY_BUFFERS_MAX_PER_CLIENT ? 5u : 6u;
|
||||
int seen = 0;
|
||||
for (unsigned i = 0; i < refused_count; i++) {
|
||||
if (refused[i].pid == p->pid && refused[i].width == q->width && refused[i].height == q->height &&
|
||||
refused[i].format == q->format && refused[i].stride == q->stride && refused[i].offset == q->offset &&
|
||||
refused[i].size == q->size && refused[i].modifier == q->modifier && refused[i].reason == reason) {
|
||||
seen = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!seen && refused_count < 32) {
|
||||
refused[refused_count].pid = p->pid;
|
||||
refused[refused_count].width = q->width;
|
||||
refused[refused_count].height = q->height;
|
||||
refused[refused_count].format = q->format;
|
||||
refused[refused_count].stride = q->stride;
|
||||
refused[refused_count].offset = q->offset;
|
||||
refused[refused_count].size = q->size;
|
||||
refused[refused_count].modifier = q->modifier;
|
||||
refused[refused_count].reason = reason;
|
||||
refused_count++;
|
||||
const char *why = reason == 1 ? "invalid dimensions, format, or stride" :
|
||||
reason == 2 ? "size/offset/layout sanity check failed" :
|
||||
reason == 3 ? "zero-copy or UBWC offering is disabled" :
|
||||
reason == 4 ? "AHardwareBuffer swapchain is not advertised" :
|
||||
reason == 5 ? "per-client allocation limit reached" :
|
||||
"gralloc allocation/fd/size validation failed";
|
||||
droiddeck_log(compressed ? "error" : "layer",
|
||||
"display buffers: allocation refused for pid %d: %s; request %ux%u %c%c%c%c %s stride=%u offset=%u size=%llu modifier=0x%llx (client has %d allocations)",
|
||||
(int)p->pid, why, q->width, q->height,
|
||||
q->format & 0xff, (q->format >> 8) & 0xff, (q->format >> 16) & 0xff, (q->format >> 24) & 0xff,
|
||||
compressed ? "UBWC" : "linear", q->stride, q->offset,
|
||||
(unsigned long long)q->size, (unsigned long long)q->modifier, p->count);
|
||||
} else if (!seen && !refused_limit_logged) {
|
||||
refused_limit_logged = 1;
|
||||
droiddeck_log("layer", "display buffers: further allocation-refusal diagnostics suppressed after 32 signatures");
|
||||
}
|
||||
}
|
||||
if (reply(p, &r, fd) != 0 && e) entry_free(e);
|
||||
@@ -299,9 +366,18 @@ static int on_listen(int fd, uint32_t mask, void *data) {
|
||||
}
|
||||
|
||||
void display_buffers_match(struct wl_client *c, struct wl_resource *buffer, struct dmabuf_buffer *b) {
|
||||
static int invalid_logged;
|
||||
struct stat st;
|
||||
struct entry *e;
|
||||
if (!g_loop || wl_list_empty(&g_entries) || b->n_planes != 1 || b->offset[0] != 0 || fstat(b->fd[0], &st) != 0) return;
|
||||
if (!g_loop || wl_list_empty(&g_entries)) return;
|
||||
if (b->n_planes != 1 || b->offset[0] != 0 || fstat(b->fd[0], &st) != 0) {
|
||||
if (!invalid_logged) {
|
||||
invalid_logged = 1;
|
||||
droiddeck_log("layer", "display buffers: cannot associate %s's DMA-BUF with gralloc (plane count %u; expected one plane at offset 0, or fstat failed)",
|
||||
droiddeck_client_name(c), b->n_planes);
|
||||
}
|
||||
return;
|
||||
}
|
||||
wl_list_for_each(e, &g_entries, link) {
|
||||
if (e->dev != st.st_dev || e->ino != st.st_ino) continue;
|
||||
AHardwareBuffer_Desc d;
|
||||
@@ -311,11 +387,27 @@ void display_buffers_match(struct wl_client *c, struct wl_resource *buffer, stru
|
||||
(uint32_t)b->height == e->height
|
||||
: (b->modifier == MOD_LINEAR || b->modifier == MOD_INVALID) &&
|
||||
e->stride == b->stride[0];
|
||||
if (laid_out && e->format == ahb_format_of(b->format, e->modifier) && b->width > 0 && b->height > 0 &&
|
||||
(uint32_t)b->width <= d.width && (uint32_t)b->height <= d.height)
|
||||
const uint32_t expected_format = ahb_format_of(b->format, e->modifier);
|
||||
const int dimensions = b->width > 0 && b->height > 0 &&
|
||||
(uint32_t)b->width <= d.width && (uint32_t)b->height <= d.height;
|
||||
if (laid_out && e->format == expected_format && dimensions) {
|
||||
ahb_swapchain_adopt(c, buffer, b, e->ahb, e->modifier);
|
||||
} else if (mismatch_should_log(b, 2)) {
|
||||
droiddeck_log("layer", "display buffers: gralloc DMA-BUF identity matched but layout was rejected for %s: %c%c%c%c %dx%d stride %u offset %u modifier 0x%llx; gralloc %ux%u stride %u format 0x%x, expected format 0x%x (layout %s, dimensions %s)",
|
||||
droiddeck_client_name(c), b->format & 0xff, (b->format >> 8) & 0xff,
|
||||
(b->format >> 16) & 0xff, (b->format >> 24) & 0xff, b->width, b->height,
|
||||
b->stride[0], b->offset[0], (unsigned long long)b->modifier,
|
||||
e->width, e->height, e->stride, e->format, expected_format,
|
||||
laid_out ? "ok" : "mismatch", dimensions ? "ok" : "mismatch");
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (mismatch_should_log(b, 1)) {
|
||||
droiddeck_log("layer", "display buffers: no registered gralloc allocation matches %s's DMA-BUF identity: %c%c%c%c %dx%d stride %u offset %u modifier 0x%llx; imported normally, copy path only",
|
||||
droiddeck_client_name(c), b->format & 0xff, (b->format >> 8) & 0xff,
|
||||
(b->format >> 16) & 0xff, (b->format >> 24) & 0xff, b->width, b->height,
|
||||
b->stride[0], b->offset[0], (unsigned long long)b->modifier);
|
||||
}
|
||||
}
|
||||
|
||||
void display_buffers_init(struct wl_display *display) {
|
||||
|
||||
@@ -4,12 +4,14 @@
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <pthread.h>
|
||||
#include <limits.h>
|
||||
#include <linux/input-event-codes.h>
|
||||
#include <android/log.h>
|
||||
#include "droiddeck_ext.h"
|
||||
#include "ahb_swapchain.h"
|
||||
#include "droiddeck_color.h"
|
||||
|
||||
enum host_kind { HOST_CLIPBOARD = 1, HOST_TEXT_COMMIT, HOST_TEXT_PREEDIT, HOST_TEXT_DELETE, HOST_ZERO_COPY, HOST_HDR_OUTPUT };
|
||||
enum host_kind { HOST_CLIPBOARD = 1, HOST_TEXT_COMMIT, HOST_TEXT_PREEDIT, HOST_TEXT_DELETE, HOST_ZERO_COPY, HOST_HDR_OUTPUT, HOST_KEY, HOST_SELECT_GAME_FIELD };
|
||||
|
||||
struct host_msg {
|
||||
enum host_kind kind;
|
||||
@@ -23,6 +25,32 @@ static pthread_mutex_t g_mu = PTHREAD_MUTEX_INITIALIZER;
|
||||
static struct host_msg *g_head, *g_tail;
|
||||
static int g_wake[2] = {-1, -1};
|
||||
|
||||
/* Compositor-thread-only fallback ordering state. */
|
||||
static int g_pending_token, g_pending_submit;
|
||||
static int g_fallback_failed;
|
||||
static int g_next_token = 1;
|
||||
static struct host_msg *g_deferred_head, *g_deferred_tail;
|
||||
static size_t g_deferred_count, g_deferred_bytes;
|
||||
static int g_deferred_overflow;
|
||||
static int g_completed_token, g_completed_result;
|
||||
|
||||
#define DROIDDECK_EVDEV_KEY_MAX 768
|
||||
#define DROIDDECK_TEXT_DEFERRED_LIMIT 256
|
||||
#define DROIDDECK_TEXT_DEFERRED_BYTES (256 * 1024)
|
||||
static unsigned char g_ordered_key_down[DROIDDECK_EVDEV_KEY_MAX];
|
||||
|
||||
void droiddeck_host_text_input_fallback_complete(int token, int result) {
|
||||
pthread_mutex_lock(&g_mu);
|
||||
g_completed_token = token;
|
||||
g_completed_result = result;
|
||||
pthread_mutex_unlock(&g_mu);
|
||||
if (g_wake[1] >= 0) {
|
||||
char c = 1;
|
||||
ssize_t n = write(g_wake[1], &c, 1);
|
||||
(void)n;
|
||||
}
|
||||
}
|
||||
|
||||
static void host_post(enum host_kind kind, const char *text, size_t len, int a, int b) {
|
||||
struct host_msg *m = calloc(1, sizeof(*m));
|
||||
if (!m) return;
|
||||
@@ -51,6 +79,9 @@ void droiddeck_host_clipboard_text(const char *utf8, int len) {
|
||||
void droiddeck_host_text_commit(const char *utf8, int len) {
|
||||
host_post(HOST_TEXT_COMMIT, utf8, len > 0 ? (size_t)len : 0, 0, 0);
|
||||
}
|
||||
void droiddeck_host_text_commit_and_submit(const char *utf8, int len) {
|
||||
if (len > 0) host_post(HOST_TEXT_COMMIT, utf8, (size_t)len, 1, 0);
|
||||
}
|
||||
void droiddeck_host_text_preedit(const char *utf8, int len, int cursor_begin, int cursor_end) {
|
||||
host_post(HOST_TEXT_PREEDIT, utf8, len > 0 ? (size_t)len : 0, cursor_begin, cursor_end);
|
||||
}
|
||||
@@ -63,23 +94,173 @@ void droiddeck_host_zero_copy(int on, int live) {
|
||||
void droiddeck_host_hdr_output(int on) {
|
||||
host_post(HOST_HDR_OUTPUT, NULL, 0, on, 0);
|
||||
}
|
||||
void droiddeck_host_key(int evdev, int state) {
|
||||
host_post(HOST_KEY, NULL, 0, evdev, state);
|
||||
}
|
||||
|
||||
void droiddeck_host_select_game_field(int copy) {
|
||||
host_post(HOST_SELECT_GAME_FIELD, NULL, 0, copy, 0);
|
||||
}
|
||||
|
||||
static void tap_unheld_key(uint32_t key) {
|
||||
if (droiddeck_key_is_down(key)) return;
|
||||
droiddeck_inject_key(key, 1);
|
||||
droiddeck_inject_key(key, 0);
|
||||
}
|
||||
|
||||
static void select_game_field(int copy) {
|
||||
/* Apply pending raw releases before using the compositor's held-key state. */
|
||||
droiddeck_dispatch_pending_input();
|
||||
int temporary_ctrl = !droiddeck_key_is_down(KEY_LEFTCTRL) && !droiddeck_key_is_down(KEY_RIGHTCTRL);
|
||||
if (temporary_ctrl) droiddeck_inject_key(KEY_LEFTCTRL, 1);
|
||||
tap_unheld_key(KEY_A);
|
||||
if (copy) tap_unheld_key(KEY_C);
|
||||
if (temporary_ctrl) droiddeck_inject_key(KEY_LEFTCTRL, 0);
|
||||
}
|
||||
|
||||
static void restore_deferred_to_front(void) {
|
||||
if (g_deferred_head) {
|
||||
g_deferred_tail->next = g_head;
|
||||
if (!g_head) g_tail = g_deferred_tail;
|
||||
g_head = g_deferred_head;
|
||||
g_deferred_head = g_deferred_tail = NULL;
|
||||
g_deferred_count = g_deferred_bytes = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Only suppress the queued submit for this commit, not a later commit or a held-key release. */
|
||||
static void discard_queued_submit(void) {
|
||||
struct host_msg *prev = NULL;
|
||||
struct host_msg *m = g_head;
|
||||
int enter_held = g_ordered_key_down[KEY_ENTER];
|
||||
int key_pad_enter_held = g_ordered_key_down[KEY_KPENTER];
|
||||
while (m) {
|
||||
int soft_submit = 0;
|
||||
if (m->kind == HOST_TEXT_COMMIT) {
|
||||
if (m->a || m->len == 0) break;
|
||||
soft_submit = 1;
|
||||
size_t i = 0;
|
||||
for (; i < m->len; i++) {
|
||||
char c = m->text[i];
|
||||
if (c != '\r' && c != '\n') soft_submit = 0;
|
||||
if (c != '\r' && c != '\n' && c != '\b' && c != '\t' && c != 0x7f) break;
|
||||
}
|
||||
if (i != m->len) break;
|
||||
}
|
||||
struct host_msg *next = m->next;
|
||||
int *held = m->a == KEY_ENTER ? &enter_held : m->a == KEY_KPENTER ? &key_pad_enter_held : NULL;
|
||||
if (soft_submit || (m->kind == HOST_KEY && held && (m->b != 0 || !*held))) {
|
||||
if (prev) prev->next = next; else g_head = next;
|
||||
if (g_tail == m) g_tail = prev;
|
||||
free(m->text);
|
||||
free(m);
|
||||
} else {
|
||||
if (m->kind == HOST_KEY && held) *held = 0;
|
||||
prev = m;
|
||||
}
|
||||
m = next;
|
||||
}
|
||||
}
|
||||
|
||||
static int release_held_key(const struct host_msg *m) {
|
||||
int k = m->a;
|
||||
if (m->kind != HOST_KEY || m->b != 0 || k < 0 || k >= DROIDDECK_EVDEV_KEY_MAX ||
|
||||
!g_ordered_key_down[k]) return 0;
|
||||
g_ordered_key_down[k] = 0;
|
||||
droiddeck_inject_key((uint32_t)k, 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void discard_deferred_input(void) {
|
||||
struct host_msg *m = g_deferred_head;
|
||||
while (m) {
|
||||
struct host_msg *next = m->next;
|
||||
release_held_key(m);
|
||||
free(m->text);
|
||||
free(m);
|
||||
m = next;
|
||||
}
|
||||
g_deferred_head = g_deferred_tail = NULL;
|
||||
g_deferred_count = g_deferred_bytes = 0;
|
||||
}
|
||||
|
||||
static int on_wake(int fd, uint32_t mask, void *data) {
|
||||
char buf[64];
|
||||
while (read(fd, buf, sizeof(buf)) > 0) {}
|
||||
for (;;) {
|
||||
int deferred = 0, submit = 0;
|
||||
pthread_mutex_lock(&g_mu);
|
||||
if (g_pending_token != 0 && g_completed_token == g_pending_token) {
|
||||
int result = g_completed_result;
|
||||
g_completed_token = 0;
|
||||
restore_deferred_to_front();
|
||||
if (result != DROIDDECK_TEXT_DELIVERED) discard_queued_submit();
|
||||
if (result == DROIDDECK_TEXT_UNRESOLVED) {
|
||||
g_fallback_failed = 1;
|
||||
} else {
|
||||
if (result == DROIDDECK_TEXT_DELIVERED) submit = g_pending_submit;
|
||||
g_pending_submit = 0;
|
||||
g_pending_token = 0;
|
||||
g_fallback_failed = 0;
|
||||
g_deferred_overflow = 0;
|
||||
}
|
||||
}
|
||||
struct host_msg *m = g_head;
|
||||
if (m) { g_head = m->next; if (!g_head) g_tail = NULL; }
|
||||
if (m) { g_head = m->next; if (!g_head) g_tail = NULL; m->next = NULL; }
|
||||
pthread_mutex_unlock(&g_mu);
|
||||
if (submit) tap_unheld_key(KEY_ENTER);
|
||||
if (!m) break;
|
||||
if (g_pending_token != 0 &&
|
||||
(m->kind == HOST_TEXT_COMMIT || m->kind == HOST_TEXT_PREEDIT ||
|
||||
m->kind == HOST_TEXT_DELETE || m->kind == HOST_KEY ||
|
||||
m->kind == HOST_SELECT_GAME_FIELD)) {
|
||||
int released_during_recovery = g_fallback_failed && release_held_key(m);
|
||||
if (released_during_recovery || g_deferred_overflow ||
|
||||
g_deferred_count == DROIDDECK_TEXT_DEFERRED_LIMIT ||
|
||||
m->len > DROIDDECK_TEXT_DEFERRED_BYTES - g_deferred_bytes) {
|
||||
if (!released_during_recovery) {
|
||||
/* An incomplete queue could replay a submit or lose a paired release. */
|
||||
if (!g_deferred_overflow)
|
||||
droiddeck_log("text-input", "deferred input exceeded the recovery queue limit");
|
||||
discard_deferred_input();
|
||||
release_held_key(m);
|
||||
g_deferred_overflow = 1;
|
||||
}
|
||||
free(m->text);
|
||||
free(m);
|
||||
continue;
|
||||
}
|
||||
if (g_deferred_tail) g_deferred_tail->next = m; else g_deferred_head = m;
|
||||
g_deferred_tail = m;
|
||||
g_deferred_count++;
|
||||
g_deferred_bytes += m->len;
|
||||
deferred = 1;
|
||||
}
|
||||
if (deferred) continue;
|
||||
switch (m->kind) {
|
||||
case HOST_CLIPBOARD:
|
||||
clipboard_host_text(m->text, m->len);
|
||||
m->text = NULL;
|
||||
break;
|
||||
case HOST_TEXT_COMMIT:
|
||||
text_input_host_commit(m->text ? m->text : "", m->len);
|
||||
if (!text_input_host_commit(m->text ? m->text : "", m->len)) {
|
||||
int token = 0;
|
||||
if (g_next_token == INT_MAX) g_next_token = 1;
|
||||
else g_next_token++;
|
||||
token = g_next_token;
|
||||
g_pending_token = 0;
|
||||
if (droiddeck_on_text_input_fallback(m->text ? m->text : "", (int)m->len, token)) {
|
||||
g_pending_token = token;
|
||||
g_pending_submit = m->a;
|
||||
} else {
|
||||
droiddeck_log("text-input", "fallback had no accepting Android listener");
|
||||
pthread_mutex_lock(&g_mu);
|
||||
discard_queued_submit();
|
||||
pthread_mutex_unlock(&g_mu);
|
||||
}
|
||||
} else if (m->a) {
|
||||
tap_unheld_key(KEY_ENTER);
|
||||
}
|
||||
break;
|
||||
case HOST_TEXT_PREEDIT:
|
||||
text_input_host_preedit(m->text ? m->text : "", m->len, m->a, m->b);
|
||||
@@ -93,6 +274,19 @@ static int on_wake(int fd, uint32_t mask, void *data) {
|
||||
case HOST_HDR_OUTPUT:
|
||||
droiddeck_color_set_output(m->a);
|
||||
break;
|
||||
case HOST_SELECT_GAME_FIELD:
|
||||
select_game_field(m->a);
|
||||
break;
|
||||
case HOST_KEY:
|
||||
if (m->b == 1) {
|
||||
int k = m->a;
|
||||
if (k >= 0 && k < DROIDDECK_EVDEV_KEY_MAX) g_ordered_key_down[k] = 1;
|
||||
} else if (m->b == 0) {
|
||||
int k = m->a;
|
||||
if (k >= 0 && k < DROIDDECK_EVDEV_KEY_MAX) g_ordered_key_down[k] = 0;
|
||||
}
|
||||
droiddeck_inject_key((uint32_t)m->a, m->b);
|
||||
break;
|
||||
}
|
||||
free(m->text);
|
||||
free(m);
|
||||
|
||||
@@ -15,22 +15,34 @@ struct wl_display *droiddeck_get_display(void);
|
||||
struct wl_resource *droiddeck_ime_target(void);
|
||||
void droiddeck_surface_scene_origin(struct wl_resource *surface, int *x, int *y);
|
||||
void droiddeck_inject_key(uint32_t evdev, int pressed);
|
||||
int droiddeck_key_is_down(uint32_t evdev);
|
||||
void droiddeck_dispatch_pending_input(void);
|
||||
|
||||
void droiddeck_on_clipboard_text(const char *utf8, int len);
|
||||
int droiddeck_on_text_input_fallback(const char *utf8, int len, int token);
|
||||
void droiddeck_on_text_input(int enabled, const char *program, int x, int y, int w, int h);
|
||||
|
||||
|
||||
void droiddeck_host_clipboard_text(const char *utf8, int len);
|
||||
void droiddeck_host_text_commit(const char *utf8, int len);
|
||||
void droiddeck_host_text_commit_and_submit(const char *utf8, int len);
|
||||
void droiddeck_host_text_preedit(const char *utf8, int len, int cursor_begin, int cursor_end);
|
||||
void droiddeck_host_text_delete(int before, int after);
|
||||
void droiddeck_host_zero_copy(int on, int live);
|
||||
void droiddeck_host_hdr_output(int on);
|
||||
void droiddeck_host_key(int evdev, int state);
|
||||
void droiddeck_host_select_game_field(int copy);
|
||||
enum droiddeck_text_input_result {
|
||||
DROIDDECK_TEXT_NOT_DELIVERED = 0,
|
||||
DROIDDECK_TEXT_DELIVERED = 1,
|
||||
DROIDDECK_TEXT_UNRESOLVED = 2,
|
||||
};
|
||||
void droiddeck_host_text_input_fallback_complete(int token, int result);
|
||||
|
||||
void clipboard_init(struct wl_display *display);
|
||||
void clipboard_host_text(char *utf8, size_t len);
|
||||
void text_input_init(struct wl_display *display);
|
||||
void text_input_host_commit(const char *utf8, size_t len);
|
||||
int text_input_host_commit(const char *utf8, size_t len);
|
||||
void text_input_host_preedit(const char *utf8, size_t len, int cursor_begin, int cursor_end);
|
||||
void text_input_host_delete(int before, int after);
|
||||
void toplevel_icon_init(struct wl_display *display);
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "blend_pass.h"
|
||||
#include "vk_loader.h"
|
||||
#include "vk_present.h"
|
||||
#include "framegen_bridge.h"
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -69,6 +70,7 @@ static struct fx_settings g_set = {
|
||||
.gamma = 1.0f, .saturation = 1.0f, .s_raw = 100.0f, .look = "Off"};
|
||||
static volatile int g_changed;
|
||||
static struct fx_settings g_cur;
|
||||
static struct fx_settings g_generated_settings;
|
||||
static int g_cur_valid;
|
||||
|
||||
static void set_begin(void) { pthread_mutex_lock(&g_lock); }
|
||||
@@ -235,13 +237,24 @@ static VkDescriptorPool g_dpool;
|
||||
static VkSampler g_sampler;
|
||||
enum { P_SGSR, P_SGSR_HQ, P_NIS, P_EASU, P_RCAS, P_CAS, P_COLOR, P_FXAA, P_FXAA_TOON, P_SMAA_EDGE, P_SMAA_WEIGHTS, P_SMAA_BLEND, P_TOON, P_TOON_COLOR, P_HDR, P_NTSC, P_CRT, P_DEBAND, P_NIS_LUMA, P_COUNT };
|
||||
static VkPipeline g_pipe[P_COUNT];
|
||||
static struct fx_target g_t[2], g_mid, g_smaa_edges, g_smaa_weights;
|
||||
struct fx_context {
|
||||
struct fx_target targets[2], mid, nissrc;
|
||||
struct { VkImage img; VkImageView view; VkDescriptorSet ds; int w, h; } scene;
|
||||
};
|
||||
#define FX_CONTEXTS (VKP_FG_MAX_GENERATIONS + 2)
|
||||
static struct fx_context g_contexts[FX_CONTEXTS];
|
||||
static int g_context;
|
||||
#define g_t (g_contexts[g_context].targets)
|
||||
#define g_mid (g_contexts[g_context].mid)
|
||||
#define g_nissrc (g_contexts[g_context].nissrc)
|
||||
static struct fx_target g_smaa_edges, g_smaa_weights;
|
||||
/* Half set: NIS = nis_luma prepass (scene rgb + luma in alpha, scene size) into g_nissrc, then
|
||||
* nis3 gathers its luma from that alpha, its coefficient banks (nis_coef.h) in a uniform buffer
|
||||
* at descriptor set 1 (g_pl_nis = {g_dsl, g_coef_dsl}, same push-constant range as g_pl).
|
||||
* Old set (or no buffer): nis.frag on the scene, P_NIS_LUMA unused. */
|
||||
static struct fx_target g_nissrc;
|
||||
static int g_nis_fast;
|
||||
static int g_nis_attempted;
|
||||
static int g_upscale_half;
|
||||
static VkDescriptorSetLayout g_coef_dsl;
|
||||
static VkPipelineLayout g_pl_nis;
|
||||
static VkDescriptorPool g_coef_pool;
|
||||
@@ -249,7 +262,7 @@ static VkDescriptorSet g_coef_ds;
|
||||
static VkBuffer g_coef_buf;
|
||||
static VkDeviceMemory g_coef_mem;
|
||||
|
||||
static struct { VkImage img; VkImageView view; VkDescriptorSet ds; int w, h; } g_scene;
|
||||
#define g_scene (g_contexts[g_context].scene)
|
||||
|
||||
void vkp_effects_bind_device(VkDevice dev, VkPhysicalDevice pd,
|
||||
const VkPhysicalDeviceMemoryProperties *memprops) {
|
||||
@@ -347,7 +360,53 @@ static void scene_release(void) {
|
||||
}
|
||||
|
||||
void vkp_effects_forget_image(VkImage img) {
|
||||
if (img && g_scene.img == img) scene_release();
|
||||
int saved = g_context;
|
||||
for (g_context = 0; g_context < FX_CONTEXTS; g_context++)
|
||||
if (img && g_scene.img == img) scene_release();
|
||||
g_context = saved;
|
||||
}
|
||||
|
||||
VkImageView vkp_effects_framegen_image_view(VkImage img, int w, int h, VkFormat fmt) {
|
||||
if (!g_dev || !img || w <= 0 || h <= 0 || fmt == VK_FORMAT_UNDEFINED) return VK_NULL_HANDLE;
|
||||
|
||||
for (int i = 0; i < FX_CONTEXTS; ++i) {
|
||||
struct fx_context *ctx = &g_contexts[i];
|
||||
if (ctx->scene.img == img && ctx->scene.view) return ctx->scene.view;
|
||||
for (int j = 0; j < 2; ++j)
|
||||
if (ctx->targets[j].img == img && ctx->targets[j].view) return ctx->targets[j].view;
|
||||
if (ctx->mid.img == img && ctx->mid.view) return ctx->mid.view;
|
||||
if (ctx->nissrc.img == img && ctx->nissrc.view) return ctx->nissrc.view;
|
||||
}
|
||||
if (g_smaa_edges.img == img && g_smaa_edges.view) return g_smaa_edges.view;
|
||||
if (g_smaa_weights.img == img && g_smaa_weights.view) return g_smaa_weights.view;
|
||||
|
||||
/* The effects chain can bypass every pass and return the compositor's scene image
|
||||
* directly. Keep a view for that image in the existing per-context cache so the
|
||||
* normal image-forget path destroys it before the image itself. */
|
||||
int saved = g_context;
|
||||
g_context = 0;
|
||||
if (g_scene.img != img || g_scene.view == VK_NULL_HANDLE ||
|
||||
g_scene.w != w || g_scene.h != h) {
|
||||
scene_release();
|
||||
VkImageView view = make_view(img, fmt);
|
||||
if (!view) {
|
||||
g_context = saved;
|
||||
return VK_NULL_HANDLE;
|
||||
}
|
||||
g_scene.img = img;
|
||||
g_scene.view = view;
|
||||
g_scene.w = w;
|
||||
g_scene.h = h;
|
||||
g_scene.ds = VK_NULL_HANDLE;
|
||||
}
|
||||
VkImageView result = g_scene.view;
|
||||
g_context = saved;
|
||||
return result;
|
||||
}
|
||||
|
||||
void vkp_effects_release_generated_sources(void) {
|
||||
for (g_context = 1; g_context < FX_CONTEXTS; g_context++) scene_release();
|
||||
g_context = 0;
|
||||
}
|
||||
|
||||
static int scene_ensure(VkImage img, int w, int h) {
|
||||
@@ -473,9 +532,14 @@ static int upscale_half_set(void) {
|
||||
|
||||
static void objects_destroy(void) {
|
||||
if (!g_dev) return;
|
||||
scene_release();
|
||||
target_destroy(&g_t[0]); target_destroy(&g_t[1]); target_destroy(&g_mid);
|
||||
target_destroy(&g_smaa_edges); target_destroy(&g_smaa_weights); target_destroy(&g_nissrc);
|
||||
int saved = g_context;
|
||||
for (g_context = 0; g_context < FX_CONTEXTS; g_context++) {
|
||||
scene_release();
|
||||
target_destroy(&g_t[0]); target_destroy(&g_t[1]); target_destroy(&g_mid);
|
||||
target_destroy(&g_nissrc);
|
||||
}
|
||||
g_context = saved;
|
||||
target_destroy(&g_smaa_edges); target_destroy(&g_smaa_weights);
|
||||
for (int i = 0; i < P_COUNT; i++) { if (g_pipe[i]) g_vk.DestroyPipeline(g_dev, g_pipe[i], NULL); g_pipe[i] = VK_NULL_HANDLE; }
|
||||
if (g_dpool) g_vk.DestroyDescriptorPool(g_dev, g_dpool, NULL);
|
||||
if (g_pl) g_vk.DestroyPipelineLayout(g_dev, g_pl, NULL);
|
||||
@@ -486,6 +550,7 @@ static void objects_destroy(void) {
|
||||
if (g_rp) g_vk.DestroyRenderPass(g_dev, g_rp, NULL);
|
||||
g_dpool = VK_NULL_HANDLE; g_pl = VK_NULL_HANDLE; g_dsl = VK_NULL_HANDLE;
|
||||
g_sampler = VK_NULL_HANDLE; g_rp = VK_NULL_HANDLE; g_smaa_rp = VK_NULL_HANDLE;
|
||||
g_nis_fast = 0; g_nis_attempted = 0; g_upscale_half = 0;
|
||||
g_ready = 0;
|
||||
}
|
||||
|
||||
@@ -505,7 +570,9 @@ void vkp_effects_set_formats(VkFormat scene_fmt, VkFormat target_fmt, int scene_
|
||||
: target_fmt == VK_FORMAT_R16G16B16A16_SFLOAT ? "the HDR picture for frame generation"
|
||||
: "the HDR composition's picture: PQ, or tone-mapped SDR with HDR output off");
|
||||
} else if (scene_fmt != g_scene_fmt) {
|
||||
scene_release();
|
||||
int saved = g_context;
|
||||
for (g_context = 0; g_context < FX_CONTEXTS; g_context++) scene_release();
|
||||
g_context = saved;
|
||||
g_scene_fmt = scene_fmt;
|
||||
}
|
||||
}
|
||||
@@ -556,75 +623,17 @@ static int objects_ensure(void) {
|
||||
VkPipelineLayoutCreateInfo pli = {.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, .setLayoutCount = 2, .pSetLayouts = set_layouts,
|
||||
.pushConstantRangeCount = 1, .pPushConstantRanges = &pcr};
|
||||
if (g_vk.CreatePipelineLayout(g_dev, &pli, NULL, &g_pl) != VK_SUCCESS) goto fail;
|
||||
VkDescriptorPoolSize ps = {VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 10};
|
||||
VkDescriptorPoolSize ps = {VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, FX_CONTEXTS * 5 + 2};
|
||||
VkDescriptorPoolCreateInfo dpi = {.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
|
||||
.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT, .maxSets = 10,
|
||||
.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT, .maxSets = FX_CONTEXTS * 5 + 2,
|
||||
.poolSizeCount = 1, .pPoolSizes = &ps};
|
||||
if (g_vk.CreateDescriptorPool(g_dev, &dpi, NULL, &g_dpool) != VK_SUCCESS) goto fail;
|
||||
|
||||
VkShaderModule vert = shader(upscale_vert_code, sizeof(upscale_vert_code));
|
||||
if (!vert) goto fail;
|
||||
#define MKL(slot, code, name, layout) do { g_pipe[slot] = post_pipeline_for_renderpass(vert, code, sizeof(code), g_rp, name, layout); if (!g_pipe[slot]) { g_vk.DestroyShaderModule(g_dev, vert, NULL); goto fail; } } while (0)
|
||||
#define MK(slot, code, name) MKL(slot, code, name, g_pl)
|
||||
const int half = upscale_half_set();
|
||||
g_upscale_half = upscale_half_set();
|
||||
g_nis_fast = 0;
|
||||
if (half && !fx_alpha_holds_luma(g_fx_fmt))
|
||||
droiddeck_log("effects", "NIS uses nis.frag: the chain format has no 8-bit alpha for the luma prepass");
|
||||
else if (half && coef_create() != 0)
|
||||
droiddeck_log("effects", "NIS coefficient buffer unavailable; NIS uses nis.frag");
|
||||
else if (half)
|
||||
g_nis_fast = 1;
|
||||
if (half) {
|
||||
MK(P_SGSR, sgsr_half_code, "sgsr_half");
|
||||
MK(P_SGSR_HQ, sgsr_quality_half_code, "sgsr_quality_half");
|
||||
if (g_nis_fast) {
|
||||
/* optional: a driver that rejects either fast NIS pipeline gets nis.frag, not a dead chain */
|
||||
g_pipe[P_NIS] = post_pipeline_for_renderpass(vert, nis3_half_code, sizeof(nis3_half_code), g_rp, "nis3_half", g_pl_nis);
|
||||
g_pipe[P_NIS_LUMA] = g_pipe[P_NIS]
|
||||
? post_pipeline_for_renderpass(vert, nis_luma_half_code, sizeof(nis_luma_half_code), g_rp, "nis_luma_half", g_pl)
|
||||
: VK_NULL_HANDLE;
|
||||
if (!g_pipe[P_NIS] || !g_pipe[P_NIS_LUMA]) {
|
||||
if (g_pipe[P_NIS]) g_vk.DestroyPipeline(g_dev, g_pipe[P_NIS], NULL);
|
||||
g_pipe[P_NIS] = VK_NULL_HANDLE;
|
||||
coef_destroy();
|
||||
g_nis_fast = 0;
|
||||
droiddeck_log("effects", "fast NIS pipelines failed to build; NIS uses nis.frag");
|
||||
}
|
||||
}
|
||||
if (!g_nis_fast) MK(P_NIS, nis_code, "nis");
|
||||
MK(P_EASU, fsr_easu_half_code, "fsr_easu_half");
|
||||
MK(P_RCAS, fsr_rcas_half_code, "fsr_rcas_half");
|
||||
MK(P_CAS, cas_ffx_half_code, "cas_ffx_half");
|
||||
} else {
|
||||
MK(P_SGSR, sgsr_code, "sgsr");
|
||||
MK(P_SGSR_HQ, sgsr_quality_code, "sgsr_quality");
|
||||
MK(P_NIS, nis_code, "nis");
|
||||
MK(P_EASU, fsr_easu_code, "fsr_easu");
|
||||
MK(P_RCAS, fsr_rcas_code, "fsr_rcas");
|
||||
MK(P_CAS, cas_code, "cas");
|
||||
}
|
||||
MK(P_COLOR, color_code, "color");
|
||||
MK(P_FXAA, fxaa_code, "fxaa");
|
||||
MK(P_FXAA_TOON, fxaa_toon_code, "fxaa_toon");
|
||||
g_pipe[P_SMAA_EDGE] = post_pipeline_for_renderpass(
|
||||
vert, smaa_edge_code, sizeof(smaa_edge_code), g_smaa_rp, "smaa_edge", g_pl);
|
||||
if (!g_pipe[P_SMAA_EDGE]) { g_vk.DestroyShaderModule(g_dev, vert, NULL); goto fail; }
|
||||
g_pipe[P_SMAA_WEIGHTS] = post_pipeline_for_renderpass(
|
||||
vert, smaa_weights_code, sizeof(smaa_weights_code), g_smaa_rp, "smaa_weights", g_pl);
|
||||
if (!g_pipe[P_SMAA_WEIGHTS]) { g_vk.DestroyShaderModule(g_dev, vert, NULL); goto fail; }
|
||||
MK(P_SMAA_BLEND, smaa_blend_code, "smaa_blend");
|
||||
MK(P_TOON, toon_code, "toon");
|
||||
MK(P_TOON_COLOR, toon_color_code, "toon_color");
|
||||
MK(P_HDR, hdr_code, "hdr");
|
||||
MK(P_NTSC, ntsc_code, "ntsc");
|
||||
MK(P_CRT, crt_code, "crt");
|
||||
MK(P_DEBAND, deband_code, "deband");
|
||||
#undef MK
|
||||
#undef MKL
|
||||
g_vk.DestroyShaderModule(g_dev, vert, NULL);
|
||||
g_nis_attempted = 0;
|
||||
g_ready = 1;
|
||||
droiddeck_log("effects", "chain ready: 16 pipelines (SGSR, SGSR HQ, NIS, FSR EASU+RCAS, CAS, colour, FXAA, SMAA edge/weights/blend, Toon, HDR, NTSC, CRT, deband), %s upscalers%s, on %s",
|
||||
half ? "half-precision" : "old fp32", g_nis_fast ? " + NIS luma prepass" : "", vkp_gpu_name());
|
||||
droiddeck_log("effects", "shared resources ready on %s; effect pipelines are created when needed", vkp_gpu_name());
|
||||
return 0;
|
||||
fail:
|
||||
objects_destroy();
|
||||
@@ -633,6 +642,95 @@ fail:
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int chain_failed(void) {
|
||||
objects_destroy();
|
||||
g_ready = -1;
|
||||
droiddeck_log("error", "effects: the screen-effect chain could not be built on this driver; effects are off for this session");
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int pipelines_ensure(int spatial, const struct fx_settings *s) {
|
||||
VkShaderModule vert = VK_NULL_HANDLE;
|
||||
#define MKL(needed, slot, code, name, render_pass, layout) do { \
|
||||
if ((needed) && !g_pipe[slot]) { \
|
||||
if (!vert && !(vert = shader(upscale_vert_code, sizeof(upscale_vert_code)))) goto fail; \
|
||||
g_pipe[slot] = post_pipeline_for_renderpass(vert, code, sizeof(code), render_pass, name, layout); \
|
||||
if (!g_pipe[slot]) goto fail; \
|
||||
} \
|
||||
} while (0)
|
||||
#define MK(needed, slot, code, name) MKL(needed, slot, code, name, g_rp, g_pl)
|
||||
if (spatial == 3) {
|
||||
if (g_upscale_half) MK(1, P_SGSR, sgsr_half_code, "sgsr_half");
|
||||
else MK(1, P_SGSR, sgsr_code, "sgsr");
|
||||
}
|
||||
if (spatial == 8) {
|
||||
if (g_upscale_half) MK(1, P_SGSR_HQ, sgsr_quality_half_code, "sgsr_quality_half");
|
||||
else MK(1, P_SGSR_HQ, sgsr_quality_code, "sgsr_quality");
|
||||
}
|
||||
if (spatial == 4 || spatial == 5) {
|
||||
if (g_upscale_half) MK(1, P_EASU, fsr_easu_half_code, "fsr_easu_half");
|
||||
else MK(1, P_EASU, fsr_easu_code, "fsr_easu");
|
||||
if (s->sharp_pct != 0) {
|
||||
if (g_upscale_half) MK(1, P_RCAS, fsr_rcas_half_code, "fsr_rcas_half");
|
||||
else MK(1, P_RCAS, fsr_rcas_code, "fsr_rcas");
|
||||
}
|
||||
}
|
||||
if (spatial == 6) {
|
||||
if (g_upscale_half) MK(1, P_RCAS, fsr_rcas_half_code, "fsr_rcas_half");
|
||||
else MK(1, P_RCAS, fsr_rcas_code, "fsr_rcas");
|
||||
}
|
||||
if (spatial == 7) {
|
||||
if (g_upscale_half && !g_nis_attempted) {
|
||||
g_nis_attempted = 1;
|
||||
if (!fx_alpha_holds_luma(g_fx_fmt))
|
||||
droiddeck_log("effects", "NIS uses nis.frag: the chain format has no 8-bit alpha for the luma prepass");
|
||||
else if (coef_create() != 0)
|
||||
droiddeck_log("effects", "NIS coefficient buffer unavailable; NIS uses nis.frag");
|
||||
else {
|
||||
if (!vert && !(vert = shader(upscale_vert_code, sizeof(upscale_vert_code)))) goto fail;
|
||||
g_pipe[P_NIS] = post_pipeline_for_renderpass(vert, nis3_half_code, sizeof(nis3_half_code), g_rp, "nis3_half", g_pl_nis);
|
||||
if (g_pipe[P_NIS])
|
||||
g_pipe[P_NIS_LUMA] = post_pipeline_for_renderpass(vert, nis_luma_half_code, sizeof(nis_luma_half_code), g_rp, "nis_luma_half", g_pl);
|
||||
if (g_pipe[P_NIS] && g_pipe[P_NIS_LUMA]) g_nis_fast = 1;
|
||||
else {
|
||||
if (g_pipe[P_NIS]) g_vk.DestroyPipeline(g_dev, g_pipe[P_NIS], NULL);
|
||||
if (g_pipe[P_NIS_LUMA]) g_vk.DestroyPipeline(g_dev, g_pipe[P_NIS_LUMA], NULL);
|
||||
g_pipe[P_NIS] = VK_NULL_HANDLE;
|
||||
g_pipe[P_NIS_LUMA] = VK_NULL_HANDLE;
|
||||
coef_destroy();
|
||||
droiddeck_log("effects", "fast NIS pipelines failed to build; NIS uses nis.frag");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!g_nis_fast) MK(1, P_NIS, nis_code, "nis");
|
||||
else if (g_upscale_half) MK(1, P_SGSR, sgsr_half_code, "sgsr_half");
|
||||
}
|
||||
if (cas_active(s)) {
|
||||
if (g_upscale_half) MK(1, P_CAS, cas_ffx_half_code, "cas_ffx_half");
|
||||
else MK(1, P_CAS, cas_code, "cas");
|
||||
}
|
||||
if (s->color_on && !(s->toon && g_fx_fmt == FX_FORMAT)) MK(1, P_COLOR, color_code, "color");
|
||||
if (s->aa_mode == 1 || s->aa_mode == 2) MK(1, P_FXAA, fxaa_code, "fxaa");
|
||||
if (s->aa_mode == 2) {
|
||||
MKL(1, P_SMAA_EDGE, smaa_edge_code, "smaa_edge", g_smaa_rp, g_pl);
|
||||
MKL(1, P_SMAA_WEIGHTS, smaa_weights_code, "smaa_weights", g_smaa_rp, g_pl);
|
||||
MK(1, P_SMAA_BLEND, smaa_blend_code, "smaa_blend");
|
||||
}
|
||||
if (s->toon && s->color_on && g_fx_fmt == FX_FORMAT) MK(1, P_TOON_COLOR, toon_color_code, "toon_color");
|
||||
else if (s->toon) MK(1, P_TOON, toon_code, "toon");
|
||||
if (s->hdr_on) MK(1, P_HDR, hdr_code, "hdr");
|
||||
if (s->ntsc) MK(1, P_NTSC, ntsc_code, "ntsc");
|
||||
if (s->crt) MK(1, P_CRT, crt_code, "crt");
|
||||
if (deband_active(s)) MK(1, P_DEBAND, deband_code, "deband");
|
||||
#undef MK
|
||||
#undef MKL
|
||||
if (vert) g_vk.DestroyShaderModule(g_dev, vert, NULL);
|
||||
return 0;
|
||||
fail:
|
||||
if (vert) g_vk.DestroyShaderModule(g_dev, vert, NULL);
|
||||
return chain_failed();
|
||||
}
|
||||
|
||||
|
||||
static void barrier(VkCommandBuffer cmd, VkImage img, VkImageLayout from, VkImageLayout to,
|
||||
VkPipelineStageFlags src_stage, VkAccessFlags src_access,
|
||||
@@ -681,14 +779,26 @@ static void pass_dual(VkCommandBuffer cmd, VkPipeline p, struct fx_target *dst,
|
||||
static const float FULL_NDC[4] = {-1.0f, -1.0f, 1.0f, 1.0f};
|
||||
#define SET_NDC(pc) memcpy((pc).ndc, FULL_NDC, sizeof(FULL_NDC))
|
||||
|
||||
VkImage vkp_effects_run(VkCommandBuffer cmd, VkImage scene, int scene_w, int scene_h,
|
||||
int out_w, int out_h, int *res_w, int *res_h) {
|
||||
struct fx_source_state {
|
||||
VkImageLayout layout;
|
||||
VkPipelineStageFlags stage;
|
||||
VkAccessFlags access;
|
||||
};
|
||||
|
||||
static VkImage effects_run(VkCommandBuffer cmd, VkImage scene, int scene_w, int scene_h,
|
||||
int out_w, int out_h, int *res_w, int *res_h,
|
||||
VkImageLayout input_layout, const struct fx_settings *frozen,
|
||||
struct fx_source_state *source_state) {
|
||||
struct fx_settings snapshot;
|
||||
const struct fx_settings *s;
|
||||
vkp_effects_sync();
|
||||
pthread_mutex_lock(&g_lock);
|
||||
snapshot = g_cur;
|
||||
pthread_mutex_unlock(&g_lock);
|
||||
if (frozen) {
|
||||
snapshot = *frozen;
|
||||
} else {
|
||||
vkp_effects_sync();
|
||||
pthread_mutex_lock(&g_lock);
|
||||
snapshot = g_cur;
|
||||
pthread_mutex_unlock(&g_lock);
|
||||
}
|
||||
s = &snapshot;
|
||||
*res_w = scene_w; *res_h = scene_h;
|
||||
|
||||
@@ -723,7 +833,7 @@ VkImage vkp_effects_run(VkCommandBuffer cmd, VkImage scene, int scene_w, int sce
|
||||
effect_count(s) - (fuse_toon_color ? 1 : 0) -
|
||||
(fuse_fxaa_toon ? 1 : 0);
|
||||
|
||||
if ((spatial || nfx) && objects_ensure() == 0 && scene_ensure(scene, scene_w, scene_h) == 0 &&
|
||||
if ((spatial || nfx) && objects_ensure() == 0 && pipelines_ensure(spatial, s) == 0 && scene_ensure(scene, scene_w, scene_h) == 0 &&
|
||||
target_ensure(&g_t[0], cw, ch, FX_TARGET_USAGE, "chain") == 0 && (chain_passes < 2 || target_ensure(&g_t[1], cw, ch, FX_TARGET_USAGE, "chain") == 0) &&
|
||||
(!(spatial == 4 || spatial == 5) || s->sharp_pct == 0 ||
|
||||
target_ensure(&g_mid, cw, ch, FX_SCRATCH_USAGE, "EASU") == 0)) {
|
||||
@@ -748,8 +858,10 @@ VkImage vkp_effects_run(VkCommandBuffer cmd, VkImage scene, int scene_w, int sce
|
||||
g_vk.CmdSetScissor(cmd, 0, 1, &chain_sc);
|
||||
|
||||
if (spatial) {
|
||||
barrier(cmd, scene, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
|
||||
VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_TRANSFER_WRITE_BIT,
|
||||
if (source_state) *source_state = (struct fx_source_state){VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
|
||||
VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, VK_ACCESS_SHADER_READ_BIT};
|
||||
barrier(cmd, scene, input_layout, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
|
||||
VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_ACCESS_MEMORY_WRITE_BIT,
|
||||
VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, VK_ACCESS_SHADER_READ_BIT);
|
||||
struct fx_target *dst = FREE_TARGET();
|
||||
if (spatial == 3 || spatial == 8 || spatial == 7) {
|
||||
@@ -809,8 +921,10 @@ VkImage vkp_effects_run(VkCommandBuffer cmd, VkImage scene, int scene_w, int sce
|
||||
cur = dst; cur_ds = dst->ds;
|
||||
} else if (resize) {
|
||||
struct fx_target *dst = FREE_TARGET();
|
||||
barrier(cmd, scene, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
|
||||
VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_TRANSFER_WRITE_BIT,
|
||||
if (source_state) *source_state = (struct fx_source_state){VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
|
||||
VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_TRANSFER_READ_BIT};
|
||||
barrier(cmd, scene, input_layout, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
|
||||
VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_ACCESS_MEMORY_WRITE_BIT,
|
||||
VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_TRANSFER_READ_BIT);
|
||||
barrier(cmd, dst->img, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
|
||||
VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, 0, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_TRANSFER_WRITE_BIT);
|
||||
@@ -823,8 +937,10 @@ VkImage vkp_effects_run(VkCommandBuffer cmd, VkImage scene, int scene_w, int sce
|
||||
VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, VK_ACCESS_SHADER_READ_BIT);
|
||||
cur = dst; cur_ds = dst->ds;
|
||||
} else {
|
||||
barrier(cmd, scene, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
|
||||
VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_TRANSFER_WRITE_BIT,
|
||||
if (source_state) *source_state = (struct fx_source_state){VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
|
||||
VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, VK_ACCESS_SHADER_READ_BIT};
|
||||
barrier(cmd, scene, input_layout, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
|
||||
VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_ACCESS_MEMORY_WRITE_BIT,
|
||||
VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, VK_ACCESS_SHADER_READ_BIT);
|
||||
cur = NULL; cur_ds = g_scene.ds;
|
||||
}
|
||||
@@ -907,8 +1023,59 @@ VkImage vkp_effects_run(VkCommandBuffer cmd, VkImage scene, int scene_w, int sce
|
||||
return scene;
|
||||
}
|
||||
|
||||
barrier(cmd, scene, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
|
||||
VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_TRANSFER_WRITE_BIT,
|
||||
if (source_state) *source_state = (struct fx_source_state){VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
|
||||
VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_TRANSFER_READ_BIT};
|
||||
barrier(cmd, scene, input_layout, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
|
||||
VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_ACCESS_MEMORY_WRITE_BIT,
|
||||
VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_TRANSFER_READ_BIT);
|
||||
return scene;
|
||||
}
|
||||
|
||||
VkImage vkp_effects_run(VkCommandBuffer cmd, VkImage scene, int scene_w, int scene_h,
|
||||
int out_w, int out_h, int *res_w, int *res_h) {
|
||||
return effects_run(cmd, scene, scene_w, scene_h, out_w, out_h, res_w, res_h,
|
||||
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, NULL, NULL);
|
||||
}
|
||||
|
||||
int vkp_effects_prepare_generated(void) {
|
||||
vkp_effects_sync();
|
||||
pthread_mutex_lock(&g_lock);
|
||||
g_generated_settings = g_cur;
|
||||
pthread_mutex_unlock(&g_lock);
|
||||
return spatial_mode(g_generated_settings.scaling) && g_generated_settings.scaling != 6 &&
|
||||
effect_count(&g_generated_settings) == 0;
|
||||
}
|
||||
|
||||
VkImage vkp_effects_run_before_generated(VkCommandBuffer cmd, VkImage scene, int w, int h,
|
||||
int *res_w, int *res_h) {
|
||||
struct fx_settings settings = g_generated_settings;
|
||||
settings.scaling = 0;
|
||||
return effects_run(cmd, scene, w, h, w, h, res_w, res_h,
|
||||
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &settings, NULL);
|
||||
}
|
||||
|
||||
VkImage vkp_effects_run_generated(VkCommandBuffer cmd, VkImage scene, int scene_w, int scene_h,
|
||||
int out_w, int out_h, int slot, int *res_w, int *res_h) {
|
||||
if (slot < 0 || slot > VKP_FG_MAX_GENERATIONS) {
|
||||
*res_w = scene_w; *res_h = scene_h;
|
||||
return scene;
|
||||
}
|
||||
g_context = slot + 1;
|
||||
struct fx_source_state source_state = {0};
|
||||
VkImage result = effects_run(cmd, scene, scene_w, scene_h, out_w, out_h, res_w, res_h,
|
||||
VK_IMAGE_LAYOUT_GENERAL, &g_generated_settings, &source_state);
|
||||
if (result != scene) {
|
||||
barrier(cmd, result, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL,
|
||||
VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT,
|
||||
VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_TRANSFER_READ_BIT);
|
||||
barrier(cmd, scene, source_state.layout, VK_IMAGE_LAYOUT_GENERAL,
|
||||
source_state.stage, source_state.access,
|
||||
VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT);
|
||||
} else if (source_state.layout == VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL) {
|
||||
barrier(cmd, scene, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL,
|
||||
VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT,
|
||||
VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_TRANSFER_READ_BIT);
|
||||
}
|
||||
g_context = 0;
|
||||
return result;
|
||||
}
|
||||
@@ -18,10 +18,17 @@ VkFilter vkp_effects_blit_filter(void);
|
||||
|
||||
VkImage vkp_effects_run(VkCommandBuffer cmd, VkImage scene, int scene_w, int scene_h,
|
||||
int out_w, int out_h, int *res_w, int *res_h);
|
||||
int vkp_effects_prepare_generated(void);
|
||||
void vkp_effects_release_generated_sources(void);
|
||||
VkImage vkp_effects_run_before_generated(VkCommandBuffer cmd, VkImage scene, int w, int h,
|
||||
int *res_w, int *res_h);
|
||||
VkImage vkp_effects_run_generated(VkCommandBuffer cmd, VkImage scene, int scene_w, int scene_h,
|
||||
int out_w, int out_h, int slot, int *res_w, int *res_h);
|
||||
|
||||
void vkp_effects_destroy(void);
|
||||
|
||||
void vkp_effects_forget_image(VkImage img);
|
||||
VkImageView vkp_effects_framegen_image_view(VkImage img, int w, int h, VkFormat fmt);
|
||||
|
||||
void vkp_effects_set_formats(VkFormat scene_fmt, VkFormat target_fmt, int scene_is_pq);
|
||||
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
#ifndef DD_FRAME_ACQUIRE_H
|
||||
#define DD_FRAME_ACQUIRE_H
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
#include <linux/sync_file.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/* A zero-initialized slot owns no descriptor. Only an already successful
|
||||
* sync_file can enter this slot; display-side release ownership is separate. */
|
||||
struct dd_frame_acquire { int fd_plus_one; };
|
||||
enum dd_frame_acquire_result { DD_ACQUIRE_OK, DD_ACQUIRE_DUPLICATE, DD_ACQUIRE_INVALID };
|
||||
|
||||
static inline void dd_frame_acquire_clear(struct dd_frame_acquire *f) {
|
||||
if (f->fd_plus_one) close(f->fd_plus_one - 1);
|
||||
f->fd_plus_one = 0;
|
||||
}
|
||||
|
||||
static inline enum dd_frame_acquire_result
|
||||
dd_frame_acquire_set(struct dd_frame_acquire *f, int fd) {
|
||||
enum dd_frame_acquire_result result;
|
||||
struct sync_file_info info = {0};
|
||||
if (f->fd_plus_one) result = DD_ACQUIRE_DUPLICATE;
|
||||
else if (fd < 0 || fd == INT_MAX || ioctl(fd, SYNC_IOC_FILE_INFO, &info) != 0 ||
|
||||
info.status != 1 || info.num_fences == 0) result = DD_ACQUIRE_INVALID;
|
||||
else {
|
||||
f->fd_plus_one = fd + 1;
|
||||
return DD_ACQUIRE_OK;
|
||||
}
|
||||
if (fd >= 0) close(fd);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline int dd_frame_acquire_dup(const struct dd_frame_acquire *f) {
|
||||
if (!f->fd_plus_one) return -1; /* Legacy: no explicit attachment proof. */
|
||||
int fd = fcntl(f->fd_plus_one - 1, F_DUPFD_CLOEXEC, 0);
|
||||
return fd < 0 ? -2 : fd; /* Do not re-enter the legacy direct path. */
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,81 @@
|
||||
#ifndef DD_WORKER_PEER_H
|
||||
#define DD_WORKER_PEER_H
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <inttypes.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
/* Model of one app-issued, session-bound authorization record. No callers,
|
||||
* property access, proc traversal, or authorization is installed by this file. */
|
||||
struct dd_worker_grant {
|
||||
uint32_t owner, uid, pid, dev_major, dev_minor;
|
||||
uint64_t start_ticks, ino, expires;
|
||||
const char *canonical_file;
|
||||
bool app_launch_verified, final_go;
|
||||
};
|
||||
|
||||
enum dd_worker_stat_result {
|
||||
DD_WORKER_STAT_OK, DD_WORKER_STAT_DENIED, DD_WORKER_STAT_HIDDEN, DD_WORKER_STAT_OPEN,
|
||||
DD_WORKER_STAT_READ, DD_WORKER_STAT_PARSE, DD_WORKER_STAT_ZERO,
|
||||
};
|
||||
|
||||
static inline enum dd_worker_stat_result dd_worker_parse_start(const char *line, uint64_t *out) {
|
||||
const char *p = strrchr(line, ')');
|
||||
if (!p || p[1] != ' ' || !p[2] || p[3] != ' ') return DD_WORKER_STAT_PARSE;
|
||||
p += 2;
|
||||
// State is field 3. The starttime (22) is always followed by vsize (23).
|
||||
for (int field = 3; field < 22; ++field) {
|
||||
p = strchr(p, ' ');
|
||||
if (!p) return DD_WORKER_STAT_PARSE;
|
||||
while (*p == ' ') ++p;
|
||||
}
|
||||
char *end;
|
||||
if (*p < '0' || *p > '9') return DD_WORKER_STAT_PARSE;
|
||||
errno = 0;
|
||||
uint64_t value = strtoull(p, &end, 10);
|
||||
if (errno || end == p || *end != ' ') return DD_WORKER_STAT_PARSE;
|
||||
if (!value) return DD_WORKER_STAT_ZERO;
|
||||
*out = value;
|
||||
return DD_WORKER_STAT_OK;
|
||||
}
|
||||
|
||||
static inline enum dd_worker_stat_result dd_worker_open_failure(int error) {
|
||||
if (error == EACCES || error == EPERM) return DD_WORKER_STAT_DENIED;
|
||||
if (error == ENOENT || error == ESRCH) return DD_WORKER_STAT_HIDDEN;
|
||||
return DD_WORKER_STAT_OPEN;
|
||||
}
|
||||
|
||||
static inline bool dd_worker_receipt_allows_reserve(enum dd_worker_stat_result stat,
|
||||
uint64_t raw, uint64_t receipt) {
|
||||
if (!receipt) return false;
|
||||
if (stat == DD_WORKER_STAT_OK) return raw == receipt;
|
||||
// Only a visibility denial can defer the broker-side stat check, not any
|
||||
// bad read, malformed record, mismatched timestamp, or other open error.
|
||||
return stat == DD_WORKER_STAT_DENIED || stat == DD_WORKER_STAT_HIDDEN;
|
||||
}
|
||||
|
||||
static inline bool dd_worker_map_matches(const struct dd_worker_grant *g, const char *line) {
|
||||
unsigned major, minor;
|
||||
uint64_t lo, hi, off, ino;
|
||||
int prefix = 0;
|
||||
char mode[5];
|
||||
if (!g->canonical_file || !*g->canonical_file ||
|
||||
sscanf(line, "%" SCNx64 "-%" SCNx64 " %4s %" SCNx64 " %x:%x %" SCNu64 " %n",
|
||||
&lo,&hi,mode,&off,&major,&minor,&ino,&prefix)!=7 ||
|
||||
prefix <= 0 || hi <= lo || strlen(mode)!=4 || mode[2]!='x' ||
|
||||
major!=g->dev_major || minor!=g->dev_minor || !ino || ino!=g->ino)
|
||||
return false;
|
||||
size_t path_len=strcspn(line+prefix,"\r\n");
|
||||
return strlen(g->canonical_file)==path_len && !memcmp(line+prefix,g->canonical_file,path_len);
|
||||
}
|
||||
|
||||
static inline bool dd_worker_grant_matches(const struct dd_worker_grant *g, uint32_t owner,
|
||||
uint32_t uid, uint32_t pid, uint64_t start, uint64_t now, const char *executable_map) {
|
||||
return g && g->app_launch_verified && g->final_go && owner && owner==g->owner &&
|
||||
uid==g->uid && pid>1 && pid==g->pid && start && start==g->start_ticks &&
|
||||
now<g->expires && executable_map && dd_worker_map_matches(g,executable_map);
|
||||
}
|
||||
#endif
|
||||
@@ -1,7 +1,9 @@
|
||||
#define _POSIX_C_SOURCE 200809L
|
||||
#include "framegen_bridge.h"
|
||||
#include "framegen_engine.h"
|
||||
#include "effects_chain.h"
|
||||
#include "vk_loader.h"
|
||||
#include "sc_layer.h"
|
||||
#include <pthread.h>
|
||||
#include <stdatomic.h>
|
||||
#include <stdio.h>
|
||||
@@ -35,7 +37,7 @@ static VkQueue g_queue;
|
||||
static uint32_t g_qfam;
|
||||
static _Atomic int g_dev_ready, g_dev_lost;
|
||||
static int g_features_enabled;
|
||||
static _Atomic int g_caps_lsfg_ok, g_caps_ddfg_ok;
|
||||
static _Atomic int g_caps_lsfg_ok, g_caps_ddfg_ok, g_caps_zero_ok;
|
||||
static VkPhysicalDeviceMemoryProperties g_memprops;
|
||||
static struct {
|
||||
PFN_vkCreateImage CreateImage;
|
||||
@@ -86,9 +88,44 @@ static int64_t now_ns(void) {
|
||||
return (int64_t)ts.tv_sec * 1000000000LL + ts.tv_nsec;
|
||||
}
|
||||
|
||||
/* The pair the last run made, for the display probe and the pacer: when its real frame reached the
|
||||
* compositor, the game moment each generated frame shows, and the refresh the pacer timed each for. */
|
||||
static _Atomic int g_pacer_on;
|
||||
static int g_layer_path;
|
||||
static int g_out_gens;
|
||||
static int64_t g_out_planned[VKP_FG_MAX_GENERATIONS + 1];
|
||||
static int64_t g_completion_issue;
|
||||
|
||||
void vkp_framegen_set_pacer(int on) {
|
||||
if (atomic_exchange(&g_pacer_on, on ? 1 : 0) != (on ? 1 : 0)) {
|
||||
fge_pacer_reset();
|
||||
FGLOG("ZeroFG pacer %s", on ? "on: frame generation times its frames itself" : "off: the display layer times them");
|
||||
}
|
||||
}
|
||||
|
||||
static int pacer_wanted(void) { return atomic_load(&g_pacer_on); }
|
||||
|
||||
void vkp_framegen_pacer_abort(void) {
|
||||
g_completion_issue = 0;
|
||||
fge_pacer_reset();
|
||||
}
|
||||
|
||||
void vkp_framegen_output_planned(int k, int gens, int64_t *planned) {
|
||||
*planned = (k < 0 || k >= gens || k >= g_out_gens)
|
||||
? g_out_planned[g_out_gens] : g_out_planned[k];
|
||||
}
|
||||
|
||||
void vkp_framegen_completed(void) {
|
||||
if (!g_completion_issue) return;
|
||||
fge_pacer_completed(g_completion_issue, now_ns());
|
||||
g_completion_issue = 0;
|
||||
}
|
||||
|
||||
void vkp_framegen_real_shown(int64_t planned_ns, int64_t shown_ns) { fge_pacer_shown(planned_ns, shown_ns); }
|
||||
|
||||
|
||||
void vkp_framegen_set_engine(int kind) {
|
||||
if (kind != VKP_FG_ENGINE_LSFG && kind != VKP_FG_ENGINE_DDFG) kind = VKP_FG_ENGINE_LSFG;
|
||||
if (kind != VKP_FG_ENGINE_LSFG && kind != VKP_FG_ENGINE_DDFG && kind != VKP_FG_ENGINE_ZEROFG) kind = VKP_FG_ENGINE_LSFG;
|
||||
atomic_store(&g_kind, kind);
|
||||
atomic_store(&g_failed_kind, -1);
|
||||
atomic_store(&g_cfg_dirty, 1);
|
||||
@@ -117,6 +154,11 @@ void vkp_framegen_set_lsfg_cache_path(const char *path) {
|
||||
pthread_mutex_unlock(&g_lock);
|
||||
}
|
||||
|
||||
void vkp_framegen_set_layer_timing(int layer) {
|
||||
g_layer_path = layer;
|
||||
fge_set_layer_timing(layer);
|
||||
}
|
||||
|
||||
void vkp_framegen_set_tuning(float flow_scale, float refresh_hz) {
|
||||
if (flow_scale < 0.25f) flow_scale = 0.25f;
|
||||
if (flow_scale > 1.0f) flow_scale = 1.0f;
|
||||
@@ -145,15 +187,15 @@ static void mark_failed(int kind) {
|
||||
int vkp_framegen_problem(void) {
|
||||
if (!atomic_load(&g_dev_ready)) return -1;
|
||||
int kind = atomic_load(&g_kind);
|
||||
int caps_ok = kind == VKP_FG_ENGINE_DDFG
|
||||
? atomic_load(&g_caps_ddfg_ok)
|
||||
: atomic_load(&g_caps_lsfg_ok);
|
||||
int caps_ok = kind == VKP_FG_ENGINE_ZEROFG ? atomic_load(&g_caps_zero_ok) :
|
||||
kind == VKP_FG_ENGINE_DDFG ? atomic_load(&g_caps_ddfg_ok) :
|
||||
atomic_load(&g_caps_lsfg_ok);
|
||||
if (!caps_ok) return 1;
|
||||
if (start_failed_for(kind)) return 2;
|
||||
if (g_engine_ok && g_engine_kind == kind && fge_unavailable()) return 2;
|
||||
return 0;
|
||||
}
|
||||
const char *vkp_framegen_caps_reason(void) { return fge_caps_reason(); }
|
||||
const char *vkp_framegen_caps_reason(void) { return fge_caps_reason(atomic_load(&g_kind)); }
|
||||
|
||||
void vkp_framegen_stats(float out[6]) {
|
||||
float accepted = 0.0f, src = 0.0f, thermal = -1.0f;
|
||||
@@ -186,12 +228,14 @@ void vkp_framegen_device_ready(VkDevice dev, VkQueue queue, uint32_t qfam, int f
|
||||
fge_device_ready(g_gipa, g_inst, g_pd, dev, queue, qfam, features_enabled);
|
||||
atomic_store(&g_caps_lsfg_ok, fge_caps_ok(VKP_FG_ENGINE_LSFG));
|
||||
atomic_store(&g_caps_ddfg_ok, fge_caps_ok(VKP_FG_ENGINE_DDFG));
|
||||
atomic_store(&g_caps_zero_ok, fge_caps_ok(VKP_FG_ENGINE_ZEROFG));
|
||||
atomic_store(&g_dev_lost, 0);
|
||||
atomic_store(&g_dev_ready,
|
||||
vk.CreateImage && vk.CreateImageView && vk.CmdPipelineBarrier);
|
||||
FGLOG("engines ready on the compositor's device: LSFG Native %s (%s), DD-FG Native %s",
|
||||
fge_caps_ok(VKP_FG_ENGINE_LSFG) ? "available" : "unavailable", fge_caps_reason(),
|
||||
fge_caps_ok(VKP_FG_ENGINE_DDFG) ? "available" : "unavailable");
|
||||
FGLOG("engines ready on compositor device: LSFG %s, DD-FG %s, ZeroFG %s",
|
||||
fge_caps_ok(VKP_FG_ENGINE_LSFG) ? "available" : "unavailable",
|
||||
fge_caps_ok(VKP_FG_ENGINE_DDFG) ? "available" : "unavailable",
|
||||
fge_caps_ok(VKP_FG_ENGINE_ZEROFG) ? "available" : "unavailable");
|
||||
}
|
||||
|
||||
void vkp_framegen_device_lost(void) {
|
||||
@@ -226,7 +270,10 @@ static void destroy_ring(void) {
|
||||
if (vk.DeviceWaitIdle) vk.DeviceWaitIdle(g_dev);
|
||||
for (uint32_t i = 0; i < g_ring_n; i++) {
|
||||
if (g_ring[i].view) vk.DestroyImageView(g_dev, g_ring[i].view, NULL);
|
||||
if (g_ring[i].img) vk.DestroyImage(g_dev, g_ring[i].img, NULL);
|
||||
if (g_ring[i].img) {
|
||||
vkp_effects_forget_image(g_ring[i].img);
|
||||
vk.DestroyImage(g_dev, g_ring[i].img, NULL);
|
||||
}
|
||||
if (g_ring[i].mem) vk.FreeMemory(g_dev, g_ring[i].mem, NULL);
|
||||
memset(&g_ring[i], 0, sizeof(g_ring[i]));
|
||||
}
|
||||
@@ -279,16 +326,18 @@ static int engine_usable(void) {
|
||||
int kind = atomic_load(&g_kind);
|
||||
int ready = atomic_load(&g_dev_ready);
|
||||
int lost = atomic_load(&g_dev_lost);
|
||||
int caps_ok = kind == VKP_FG_ENGINE_DDFG
|
||||
? atomic_load(&g_caps_ddfg_ok)
|
||||
: atomic_load(&g_caps_lsfg_ok);
|
||||
int caps_ok = kind == VKP_FG_ENGINE_ZEROFG ? atomic_load(&g_caps_zero_ok) :
|
||||
kind == VKP_FG_ENGINE_DDFG ? atomic_load(&g_caps_ddfg_ok) :
|
||||
atomic_load(&g_caps_lsfg_ok);
|
||||
return ready && !lost && caps_ok && !start_failed_for(kind);
|
||||
}
|
||||
|
||||
int vkp_framegen_format_ok(VkFormat fmt) {
|
||||
if (fmt == VK_FORMAT_R8G8B8A8_UNORM) return 1;
|
||||
if (!g_dev_ready || g_dev_lost || format_refused(fmt)) return 0;
|
||||
return fge_format_ok(fmt);
|
||||
int kind = atomic_load(&g_kind);
|
||||
if (kind == VKP_FG_ENGINE_ZEROFG) return fge_format_ok(VKP_FG_ENGINE_ZEROFG, fmt);
|
||||
if (fmt == VK_FORMAT_R8G8B8A8_UNORM) return 1;
|
||||
return fge_format_ok(kind, fmt);
|
||||
}
|
||||
|
||||
static void refuse_format(VkFormat fmt, int kind, int w, int h, const char *what) {
|
||||
@@ -373,11 +422,14 @@ static void log_arm_transition(int armed, int kind, int mult) {
|
||||
|
||||
int vkp_framegen_run(VkCommandBuffer cmd, VkImage scene, VkImageView scene_view, int w, int h,
|
||||
VkFormat fmt, VkImage gens[VKP_FG_MAX_GENERATIONS]) {
|
||||
(void)scene_view;
|
||||
int kind = atomic_load(&g_kind);
|
||||
int armed = atomic_load(&g_armed);
|
||||
int mult = atomic_load(&g_mult);
|
||||
g_planned = 0;
|
||||
const int64_t issue = now_ns();
|
||||
g_out_gens = 0;
|
||||
memset(g_out_planned, 0, sizeof(g_out_planned));
|
||||
g_completion_issue = 0;
|
||||
if (!armed || !engine_usable() || w <= 0 || h <= 0) { log_arm_transition(0, kind, mult); return 0; }
|
||||
if (!ensure_engine(kind)) { log_arm_transition(0, kind, mult); return 0; }
|
||||
log_arm_transition(1, kind, mult);
|
||||
@@ -419,8 +471,31 @@ int vkp_framegen_run(VkCommandBuffer cmd, VkImage scene, VkImageView scene_view,
|
||||
|
||||
++g_source_frames;
|
||||
const uint64_t game_frames = droiddeck_game_frames();
|
||||
uint32_t n_gen = fge_plan(g_ring_n, game_frames ? game_frames : g_source_frames, g_presented_rate);
|
||||
const uint64_t planning_sequence = game_frames ? game_frames : g_source_frames;
|
||||
uint32_t n_gen = fge_plan(g_ring_n, planning_sequence, g_presented_rate);
|
||||
if (n_gen > g_ring_n) n_gen = g_ring_n;
|
||||
if (kind == VKP_FG_ENGINE_ZEROFG && n_gen > 0 && !scene_view) {
|
||||
scene_view = vkp_effects_framegen_image_view(scene, w, h, fmt);
|
||||
if (!scene_view) {
|
||||
static int view_warning;
|
||||
if (!view_warning++) FGLOG("ZeroFG could not create a view for the source image; showing real frames only");
|
||||
n_gen = 0;
|
||||
}
|
||||
}
|
||||
fge_set_phases(NULL, 0);
|
||||
if (kind == VKP_FG_ENGINE_ZEROFG && pacer_wanted() && g_layer_path) {
|
||||
int64_t vsync = 0, period = 0;
|
||||
sc_layer_timeline(&vsync, &period);
|
||||
int64_t planned[VKP_FG_MAX_GENERATIONS + 1];
|
||||
float phases[VKP_FG_MAX_GENERATIONS + 1];
|
||||
const uint32_t count = period > 0
|
||||
? fge_pacer_plan((uint32_t)mult, period, vsync, issue, n_gen, planned, phases) : 0;
|
||||
if (count >= 1 && count - 1 <= n_gen) {
|
||||
n_gen = count - 1;
|
||||
for (uint32_t i = 0; i < count; i++) g_out_planned[i] = planned[i];
|
||||
fge_set_phases(phases, n_gen);
|
||||
}
|
||||
}
|
||||
g_planned = n_gen;
|
||||
|
||||
VkImageMemoryBarrier bars[1 + VKP_FG_MAX_GENERATIONS];
|
||||
@@ -448,21 +523,25 @@ int vkp_framegen_run(VkCommandBuffer cmd, VkImage scene, VkImageView scene_view,
|
||||
VK_PIPELINE_STAGE_TRANSFER_BIT | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
|
||||
0, 0, NULL, 0, NULL, nb, bars);
|
||||
|
||||
fge_process(cmd, scene, (uint32_t)w, (uint32_t)h, n_gen);
|
||||
fge_process(cmd, scene, scene_view, (uint32_t)w, (uint32_t)h, fmt, planning_sequence, n_gen);
|
||||
for (uint32_t g = 0; g < n_gen; g++) {
|
||||
fge_generate(cmd, g, n_gen, g_ring[g].img, g_ring[g].view, (uint32_t)w, (uint32_t)h);
|
||||
gens[g] = g_ring[g].img;
|
||||
}
|
||||
if (n_gen) {
|
||||
nb = 0;
|
||||
const VkAccessFlags generated_access = kind == VKP_FG_ENGINE_ZEROFG
|
||||
? VK_ACCESS_MEMORY_WRITE_BIT : VK_ACCESS_SHADER_WRITE_BIT;
|
||||
const VkPipelineStageFlags generated_stage = kind == VKP_FG_ENGINE_ZEROFG
|
||||
? VK_PIPELINE_STAGE_ALL_COMMANDS_BIT : VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT;
|
||||
for (uint32_t g = 0; g < n_gen; g++)
|
||||
bars[nb++] = (VkImageMemoryBarrier){
|
||||
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
|
||||
.srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT, .dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT,
|
||||
.srcAccessMask = generated_access, .dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT,
|
||||
.oldLayout = VK_IMAGE_LAYOUT_GENERAL, .newLayout = VK_IMAGE_LAYOUT_GENERAL,
|
||||
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
||||
.image = g_ring[g].img, .subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}};
|
||||
vk.CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT,
|
||||
vk.CmdPipelineBarrier(cmd, generated_stage, VK_PIPELINE_STAGE_TRANSFER_BIT,
|
||||
0, 0, NULL, 0, NULL, nb, bars);
|
||||
if (!g_generating_logged) {
|
||||
g_generating_logged = 1;
|
||||
@@ -472,6 +551,8 @@ int vkp_framegen_run(VkCommandBuffer cmd, VkImage scene, VkImageView scene_view,
|
||||
fmt == VK_FORMAT_R16G16B16A16_SFLOAT ? ", FP16: the HDR picture" : "");
|
||||
}
|
||||
}
|
||||
g_out_gens = (int)n_gen;
|
||||
if (n_gen > 0) g_completion_issue = issue;
|
||||
return (int)n_gen;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#endif
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
enum { VKP_FG_ENGINE_LSFG = 0, VKP_FG_ENGINE_DDFG = 1 };
|
||||
enum { VKP_FG_ENGINE_LSFG = 0, VKP_FG_ENGINE_DDFG = 1, VKP_FG_ENGINE_ZEROFG = 2 };
|
||||
#define VKP_FG_MAX_GENERATIONS 3
|
||||
|
||||
void vkp_framegen_set_engine(int kind);
|
||||
@@ -26,6 +26,18 @@ void vkp_framegen_device_lost(void);
|
||||
|
||||
int vkp_framegen_active(void);
|
||||
int vkp_framegen_extra_images(void);
|
||||
/* 1 when the next run's frames are shown through the scene layer's timed group, 0 through the swapchain's FIFO. */
|
||||
void vkp_framegen_set_layer_timing(int layer);
|
||||
/* ZeroFG's pacer (include/zerofg/inline_pacer.h) times the layer's frames instead of the layer's own spacing. */
|
||||
void vkp_framegen_set_pacer(int on);
|
||||
/* Reset pacing history when a planned real-frame pair is aborted before presentation. */
|
||||
void vkp_framegen_pacer_abort(void);
|
||||
/* Refresh planned for output k of the last run (k == gens: its real frame; 0: use layer timing). */
|
||||
void vkp_framegen_output_planned(int k, int gens, int64_t *planned);
|
||||
/* The last run's GPU work finished (the compositor's fence signalled). */
|
||||
void vkp_framegen_completed(void);
|
||||
/* A real frame the pacer timed for planned_ns was shown at shown_ns. */
|
||||
void vkp_framegen_real_shown(int64_t planned_ns, int64_t shown_ns);
|
||||
int vkp_framegen_run(VkCommandBuffer cmd, VkImage scene, VkImageView scene_view, int w, int h,
|
||||
VkFormat fmt, VkImage gens[VKP_FG_MAX_GENERATIONS]);
|
||||
void vkp_framegen_presented(int generated);
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -13,6 +14,9 @@
|
||||
#include "lsfg/lsfg_probe.h"
|
||||
#include "lsfg/lsfg_vkd.h"
|
||||
#include "ddfg/ddfg_engine.h"
|
||||
#include "framegen_zerofg.h"
|
||||
|
||||
#include <zerofg/inline_pacer.h>
|
||||
|
||||
#define ELOG(...) __android_log_print(ANDROID_LOG_INFO, "DroidDeckWayland", "framegen: " __VA_ARGS__)
|
||||
#define ELOGE(...) __android_log_print(ANDROID_LOG_ERROR, "DroidDeckWayland", "framegen: " __VA_ARGS__)
|
||||
@@ -22,15 +26,21 @@ namespace {
|
||||
VkTable g_table{};
|
||||
lsfg::Caps g_caps{};
|
||||
VkPhysicalDeviceVulkan12Features g_v12{};
|
||||
VkPhysicalDeviceVulkan13Features g_v13{};
|
||||
VkPhysicalDeviceFeatures2 g_f2{};
|
||||
VkPhysicalDevice g_pd = VK_NULL_HANDLE;
|
||||
VkDevice g_dev = VK_NULL_HANDLE;
|
||||
VkQueue g_queue = VK_NULL_HANDLE;
|
||||
uint32_t g_qfam = 0;
|
||||
bool g_probed = false, g_ready = false;
|
||||
bool g_zero_supported = false, g_zero_enabled = false;
|
||||
zerofg::InlinePacer g_pacer;
|
||||
zerofg::InlineReadiness g_readiness;
|
||||
std::mutex g_pacer_mutex;
|
||||
|
||||
std::unique_ptr<lsfg::Engine> g_lsfg;
|
||||
std::unique_ptr<ddfg::Engine> g_ddfg;
|
||||
std::vector<std::unique_ptr<ddfg::Engine>> g_retained_ddfg;
|
||||
int g_kind = -1;
|
||||
char g_build[96] = "";
|
||||
|
||||
@@ -87,30 +97,57 @@ const void *fge_probe(PFN_vkGetInstanceProcAddr gipa, VkInstance inst, VkPhysica
|
||||
if (n) enumExts(pd, nullptr, &n, exts.data());
|
||||
}
|
||||
g_caps = lsfg::Caps{};
|
||||
|
||||
|
||||
g_caps.features = lsfg::queryFeatures(g_table, pd, exts, false);
|
||||
g_caps.features = lsfg::queryFeatures(g_table, pd, exts, false);
|
||||
g_caps.probedFormat = ring_fmt;
|
||||
g_caps.storageOnSwapchainFormat = g_table.GetPhysicalDeviceFormatProperties
|
||||
? lsfg::probeStorageFormat(g_table, pd, ring_fmt) : false;
|
||||
g_caps.linearBlitOnSwapchainFormat = g_table.GetPhysicalDeviceFormatProperties
|
||||
? lsfg::probeLinearBlit(g_table, pd, ring_fmt) : false;
|
||||
g_probed = true;
|
||||
if (!g_caps.features.deviceGatesPass()) {
|
||||
|
||||
VkPhysicalDeviceProperties props{};
|
||||
if (g_table.GetPhysicalDeviceProperties) g_table.GetPhysicalDeviceProperties(pd, &props);
|
||||
VkPhysicalDeviceVulkan13Features supported13{};
|
||||
supported13.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES;
|
||||
VkPhysicalDeviceFeatures2 supported2{};
|
||||
supported2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
|
||||
if (props.apiVersion >= VK_API_VERSION_1_3) supported2.pNext = &supported13;
|
||||
if (g_table.GetPhysicalDeviceFeatures2) g_table.GetPhysicalDeviceFeatures2(pd, &supported2);
|
||||
g_zero_supported = props.apiVersion >= VK_API_VERSION_1_3 &&
|
||||
supported13.synchronization2 == VK_TRUE &&
|
||||
supported2.features.shaderStorageImageExtendedFormats == VK_TRUE;
|
||||
g_zero_enabled = false;
|
||||
|
||||
const bool lsfg_supported = g_caps.features.deviceGatesPass();
|
||||
if (!lsfg_supported) {
|
||||
lsfg::explain(g_caps);
|
||||
ELOG("device gates for the LSFG chain fail: %s", g_caps.reason);
|
||||
}
|
||||
if (!lsfg_supported && !g_zero_supported) {
|
||||
g_v12 = {};
|
||||
g_v13 = {};
|
||||
g_f2 = {};
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
g_v12 = VkPhysicalDeviceVulkan12Features{};
|
||||
g_v12.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES;
|
||||
g_v12.vulkanMemoryModel = VK_TRUE;
|
||||
g_v12.vulkanMemoryModel =
|
||||
g_caps.features.vulkanMemoryModel ? VK_TRUE : VK_FALSE;
|
||||
g_v12.vulkanMemoryModelDeviceScope =
|
||||
g_caps.features.vulkanMemoryModelDeviceScope ? VK_TRUE : VK_FALSE;
|
||||
g_v13 = VkPhysicalDeviceVulkan13Features{};
|
||||
g_v13.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES;
|
||||
g_v13.synchronization2 = g_zero_supported ? VK_TRUE : VK_FALSE;
|
||||
if (g_zero_supported) g_v12.pNext = &g_v13;
|
||||
|
||||
g_f2 = VkPhysicalDeviceFeatures2{};
|
||||
g_f2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
|
||||
g_f2.pNext = &g_v12;
|
||||
g_f2.features.shaderStorageImageWriteWithoutFormat = VK_TRUE;
|
||||
g_f2.features.shaderStorageImageExtendedFormats = VK_TRUE;
|
||||
g_f2.features.shaderStorageImageWriteWithoutFormat =
|
||||
supported2.features.shaderStorageImageWriteWithoutFormat ? VK_TRUE : VK_FALSE;
|
||||
g_f2.features.shaderStorageImageExtendedFormats =
|
||||
supported2.features.shaderStorageImageExtendedFormats ? VK_TRUE : VK_FALSE;
|
||||
return &g_f2;
|
||||
}
|
||||
|
||||
@@ -121,14 +158,29 @@ void fge_device_ready(PFN_vkGetInstanceProcAddr gipa, VkInstance inst, VkPhysica
|
||||
fill_device(dev);
|
||||
g_caps.featuresEnabled = features_enabled != 0;
|
||||
lsfg::explain(g_caps);
|
||||
VkPhysicalDeviceProperties props{};
|
||||
if (g_table.GetPhysicalDeviceProperties) g_table.GetPhysicalDeviceProperties(pd, &props);
|
||||
g_zero_enabled = g_zero_supported && features_enabled != 0;
|
||||
zfg_device_ready(gipa, inst, pd, dev,
|
||||
props.apiVersion > VK_API_VERSION_1_3 ? VK_API_VERSION_1_3 : props.apiVersion,
|
||||
g_zero_enabled,
|
||||
g_zero_enabled && g_f2.features.shaderStorageImageExtendedFormats == VK_TRUE);
|
||||
g_ready = true;
|
||||
ELOG("device ready: lsfg caps '%s', storage on ring format %d", g_caps.reason,
|
||||
(int)g_caps.storageOnSwapchainFormat);
|
||||
ELOG("device ready: lsfg caps '%s', storage on ring format %d, ZeroFG %s",
|
||||
g_caps.reason, (int)g_caps.storageOnSwapchainFormat,
|
||||
g_zero_enabled ? "available" : "unavailable");
|
||||
}
|
||||
|
||||
void fge_device_lost(void) {
|
||||
g_lsfg.reset();
|
||||
g_ddfg.reset();
|
||||
if (g_ddfg) {
|
||||
if (g_ddfg->destroy()) g_ddfg.reset();
|
||||
else g_retained_ddfg.push_back(std::move(g_ddfg));
|
||||
}
|
||||
// The device is being torn down. Unknown-completion resources must not be
|
||||
// passed to Vulkan destruction calls; the VkDevice teardown reclaims them.
|
||||
for (auto& engine : g_retained_ddfg) engine->abandon();
|
||||
g_retained_ddfg.clear();
|
||||
g_kind = -1;
|
||||
g_dev = VK_NULL_HANDLE;
|
||||
g_queue = VK_NULL_HANDLE;
|
||||
@@ -141,24 +193,45 @@ void fge_device_lost(void) {
|
||||
g_v12 = {};
|
||||
g_f2 = {};
|
||||
g_build[0] = 0;
|
||||
g_zero_supported = g_zero_enabled = false;
|
||||
zfg_device_lost();
|
||||
}
|
||||
|
||||
int fge_caps_ok(int kind) {
|
||||
if (!g_ready) return 0;
|
||||
if (kind == 2) return g_zero_enabled && zfg_caps_ok();
|
||||
if (kind == 1) return g_caps.storageOnSwapchainFormat ? 1 : 0;
|
||||
return g_caps.supported() ? 1 : 0;
|
||||
}
|
||||
|
||||
const char *fge_caps_reason(void) { return g_caps.reason; }
|
||||
int fge_engine_available(int kind) { return fge_caps_ok(kind); }
|
||||
|
||||
int fge_format_ok(VkFormat fmt) {
|
||||
const char *fge_caps_reason(int kind) {
|
||||
if (kind == 2 && !g_zero_enabled)
|
||||
return "ZeroFG requires Vulkan 1.3, synchronization2 and extended storage-image formats";
|
||||
if (kind == 2) return zfg_caps_reason();
|
||||
return g_caps.reason;
|
||||
}
|
||||
|
||||
int fge_format_ok(int kind, VkFormat fmt) {
|
||||
if (kind == 2) return zfg_format_ok(fmt);
|
||||
if (!g_ready || !g_table.GetPhysicalDeviceFormatProperties || fmt == VK_FORMAT_UNDEFINED) return 0;
|
||||
return lsfg::probeStorageFormat(g_table, g_pd, fmt) && lsfg::probeLinearBlit(g_table, g_pd, fmt) ? 1 : 0;
|
||||
}
|
||||
|
||||
int fge_start(int kind, const char *cache_path) {
|
||||
fge_stop();
|
||||
fge_pacer_reset();
|
||||
if (!g_ready) return -1;
|
||||
if (kind == 2) {
|
||||
if (!g_zero_enabled || !zfg_start()) {
|
||||
ELOGE("ZeroFG engine init failed");
|
||||
return -1;
|
||||
}
|
||||
g_kind = 2;
|
||||
std::snprintf(g_build, sizeof(g_build), "ZeroFG ReallyZero, Vulkan 1.3 Compat");
|
||||
return 0;
|
||||
}
|
||||
if (kind == 1) {
|
||||
auto e = std::make_unique<ddfg::Engine>();
|
||||
if (!e->init(g_table, g_pd, g_dev, g_qfam, g_queue)) {
|
||||
@@ -193,13 +266,30 @@ int fge_start(int kind, const char *cache_path) {
|
||||
}
|
||||
|
||||
void fge_stop(void) {
|
||||
if ((g_lsfg || g_ddfg) && g_table.DeviceWaitIdle && g_dev) g_table.DeviceWaitIdle(g_dev);
|
||||
if ((g_kind == 0 || g_kind == 2) && g_table.DeviceWaitIdle && g_dev)
|
||||
g_table.DeviceWaitIdle(g_dev);
|
||||
|
||||
g_lsfg.reset();
|
||||
g_ddfg.reset();
|
||||
|
||||
for (auto it = g_retained_ddfg.begin(); it != g_retained_ddfg.end();) {
|
||||
if ((*it)->destroy()) it = g_retained_ddfg.erase(it);
|
||||
else ++it;
|
||||
}
|
||||
|
||||
if (g_ddfg) {
|
||||
if (g_ddfg->destroy()) g_ddfg.reset();
|
||||
else {
|
||||
ELOGE("ddfg-native: retaining engine until GPU completion is known or device teardown");
|
||||
g_retained_ddfg.push_back(std::move(g_ddfg));
|
||||
}
|
||||
}
|
||||
|
||||
zfg_stop();
|
||||
g_kind = -1;
|
||||
}
|
||||
|
||||
int fge_unavailable(void) {
|
||||
if (g_kind == 2) return zfg_unavailable();
|
||||
if (g_kind == 1) return g_ddfg && g_ddfg->unavailable() ? 1 : 0;
|
||||
return g_lsfg && g_lsfg->unavailable() ? 1 : 0;
|
||||
}
|
||||
@@ -207,11 +297,13 @@ int fge_unavailable(void) {
|
||||
void fge_configure(uint32_t multiplier, uint32_t target_fps, float flow_scale, float refresh_hz,
|
||||
int model, int perf_preset) {
|
||||
if (multiplier < 2) multiplier = 2;
|
||||
if (g_kind == 2) { zfg_configure(multiplier, refresh_hz); return; }
|
||||
if (g_kind == 1 && g_ddfg) g_ddfg->configure(multiplier, model, perf_preset, flow_scale);
|
||||
else if (g_lsfg) g_lsfg->configure(multiplier, target_fps, flow_scale, refresh_hz);
|
||||
}
|
||||
|
||||
int fge_prepare(uint32_t w, uint32_t h, VkFormat fmt) {
|
||||
if (g_kind == 2) return zfg_prepare(w, h, fmt);
|
||||
if (g_kind == 1) return g_ddfg && g_ddfg->prepare(w, h, fmt) ? 1 : 0;
|
||||
if (!g_lsfg) return 0;
|
||||
g_lsfg->setGuestExtent(w, h);
|
||||
@@ -219,24 +311,74 @@ int fge_prepare(uint32_t w, uint32_t h, VkFormat fmt) {
|
||||
}
|
||||
|
||||
uint32_t fge_plan(uint32_t capacity, uint64_t source_frames, float presented_rate) {
|
||||
if (g_kind == 2) return zfg_plan(capacity, source_frames);
|
||||
if (g_kind == 1) return g_ddfg ? g_ddfg->plan(capacity) : 0;
|
||||
if (!g_lsfg) return 0;
|
||||
g_lsfg->setPresentedRate(presented_rate);
|
||||
return g_lsfg->plan(capacity, source_frames);
|
||||
}
|
||||
|
||||
void fge_process(VkCommandBuffer cmd, VkImage source, uint32_t w, uint32_t h, uint32_t gens) {
|
||||
void fge_process(VkCommandBuffer cmd, VkImage source, VkImageView source_view,
|
||||
uint32_t w, uint32_t h, VkFormat fmt, uint64_t sequence, uint32_t gens) {
|
||||
if (g_kind == 2) {
|
||||
zfg_process(cmd, source, source_view, w, h, fmt, sequence, gens);
|
||||
return;
|
||||
}
|
||||
if (g_kind == 1) { if (g_ddfg) g_ddfg->process(cmd, source, w, h, gens); return; }
|
||||
if (g_lsfg) g_lsfg->process(cmd, source, w, h, gens);
|
||||
}
|
||||
|
||||
void fge_generate(VkCommandBuffer cmd, uint32_t g, uint32_t count, VkImage img, VkImageView view,
|
||||
uint32_t w, uint32_t h) {
|
||||
if (g_kind == 2) { zfg_generate(cmd, g, count, img, view, w, h); return; }
|
||||
if (g_kind == 1) { if (g_ddfg) g_ddfg->generateInto(cmd, g, count, img, view, w, h); return; }
|
||||
if (g_lsfg) g_lsfg->generateInto(cmd, g, g, img, view, w, h);
|
||||
}
|
||||
|
||||
void fge_set_layer_timing(int layer) { zfg_set_layer_timing(layer); }
|
||||
|
||||
void fge_set_phases(const float *phases, uint32_t count) { zfg_set_phases(phases, count); }
|
||||
|
||||
float fge_phase(uint32_t index, uint32_t count) {
|
||||
if (g_kind == 2) return zfg_phase(index, count);
|
||||
return static_cast<float>(index + 1) / static_cast<float>(count + 1);
|
||||
}
|
||||
|
||||
uint32_t fge_pacer_plan(uint32_t multiplier, int64_t period_ns, int64_t vsync_ns, int64_t issue_ns, uint32_t max_generated,
|
||||
int64_t *present_ns, float *phases) {
|
||||
if (period_ns <= 0 || issue_ns <= 0) return 0;
|
||||
std::lock_guard<std::mutex> lock(g_pacer_mutex);
|
||||
g_pacer.SetMultiplier(multiplier);
|
||||
g_pacer.ObserveVsync(static_cast<uint64_t>(period_ns), static_cast<uint64_t>(vsync_ns > 0 ? vsync_ns : 0));
|
||||
const uint64_t issue = static_cast<uint64_t>(issue_ns);
|
||||
const zerofg::InlinePacer::Plan plan =
|
||||
g_pacer.PlanPair(issue, issue + g_readiness.MarginNs(static_cast<uint64_t>(period_ns)), max_generated + 1);
|
||||
for (uint32_t i = 0; i < plan.count; i++) {
|
||||
present_ns[i] = static_cast<int64_t>(plan.outputs[i].present_ns);
|
||||
phases[i] = plan.outputs[i].phase;
|
||||
}
|
||||
return plan.count;
|
||||
}
|
||||
|
||||
void fge_pacer_completed(int64_t issue_ns, int64_t done_ns) {
|
||||
std::lock_guard<std::mutex> lock(g_pacer_mutex);
|
||||
if (issue_ns > 0 && done_ns > issue_ns)
|
||||
g_readiness.ObserveCompleted(static_cast<uint64_t>(issue_ns), static_cast<uint64_t>(done_ns));
|
||||
}
|
||||
|
||||
void fge_pacer_shown(int64_t planned_ns, int64_t shown_ns) {
|
||||
std::lock_guard<std::mutex> lock(g_pacer_mutex);
|
||||
if (planned_ns > 0 && shown_ns > 0)
|
||||
g_pacer.ObserveRealShown(static_cast<uint64_t>(planned_ns), static_cast<uint64_t>(shown_ns));
|
||||
}
|
||||
|
||||
void fge_pacer_reset(void) {
|
||||
std::lock_guard<std::mutex> lock(g_pacer_mutex);
|
||||
g_pacer.Reset();
|
||||
}
|
||||
|
||||
void fge_forget_targets(void) {
|
||||
if (g_kind == 2) { zfg_forget_targets(); return; }
|
||||
if (g_lsfg) g_lsfg->forgetTargets();
|
||||
}
|
||||
|
||||
@@ -246,10 +388,14 @@ void fge_telemetry(float *accepted, float *source_rate, float *thermal) {
|
||||
*accepted = (float)g_lsfg->acceptedGenerations();
|
||||
*source_rate = g_lsfg->sourceRate();
|
||||
*thermal = (float)g_lsfg->thermalStatus();
|
||||
} else if (g_kind == 2) {
|
||||
zfg_telemetry(accepted, source_rate);
|
||||
}
|
||||
}
|
||||
|
||||
const char *fge_engine_name(int kind) { return kind == 1 ? "DD-FG Native" : "LSFG Native"; }
|
||||
const char *fge_engine_name(int kind) {
|
||||
return kind == 2 ? "ZeroFG" : kind == 1 ? "DD-FG Native" : "LSFG Native";
|
||||
}
|
||||
const char *fge_build_info(void) { return g_build; }
|
||||
|
||||
}
|
||||
@@ -16,8 +16,9 @@ void fge_device_lost(void);
|
||||
void fge_device_ready(PFN_vkGetInstanceProcAddr gipa, VkInstance inst, VkPhysicalDevice pd,
|
||||
VkDevice dev, VkQueue queue, uint32_t qfam, int features_enabled);
|
||||
int fge_caps_ok(int kind);
|
||||
const char *fge_caps_reason(void);
|
||||
int fge_format_ok(VkFormat fmt);
|
||||
const char *fge_caps_reason(int kind);
|
||||
int fge_format_ok(int kind, VkFormat fmt);
|
||||
int fge_engine_available(int kind);
|
||||
|
||||
int fge_start(int kind, const char *cache_path);
|
||||
void fge_stop(void);
|
||||
@@ -26,10 +27,22 @@ void fge_configure(uint32_t multiplier, uint32_t target_fps, float flow_scale, f
|
||||
int model, int perf_preset);
|
||||
int fge_prepare(uint32_t w, uint32_t h, VkFormat fmt);
|
||||
uint32_t fge_plan(uint32_t capacity, uint64_t source_frames, float presented_rate);
|
||||
void fge_process(VkCommandBuffer cmd, VkImage source, uint32_t w, uint32_t h, uint32_t gens);
|
||||
void fge_process(VkCommandBuffer cmd, VkImage source, VkImageView source_view,
|
||||
uint32_t w, uint32_t h, VkFormat fmt, uint64_t sequence, uint32_t gens);
|
||||
void fge_generate(VkCommandBuffer cmd, uint32_t g, uint32_t count, VkImage img, VkImageView view,
|
||||
uint32_t w, uint32_t h);
|
||||
void fge_forget_targets(void);
|
||||
void fge_set_layer_timing(int layer);
|
||||
/* The phases the pacer chose for the next pair's generated frames (engines that can take any phase). */
|
||||
void fge_set_phases(const float *phases, uint32_t count);
|
||||
/* The phase generated frame [index] of [count] shows. */
|
||||
float fge_phase(uint32_t index, uint32_t count);
|
||||
|
||||
uint32_t fge_pacer_plan(uint32_t multiplier, int64_t period_ns, int64_t vsync_ns, int64_t issue_ns, uint32_t max_generated,
|
||||
int64_t *present_ns, float *phases);
|
||||
void fge_pacer_completed(int64_t issue_ns, int64_t done_ns);
|
||||
void fge_pacer_shown(int64_t planned_ns, int64_t shown_ns);
|
||||
void fge_pacer_reset(void);
|
||||
void fge_telemetry(float *accepted, float *source_rate, float *thermal);
|
||||
const char *fge_engine_name(int kind);
|
||||
const char *fge_build_info(void);
|
||||
|
||||
@@ -10,9 +10,12 @@ void fge_device_ready(PFN_vkGetInstanceProcAddr gipa, VkInstance inst, VkPhysica
|
||||
(void)gipa; (void)inst; (void)pd; (void)dev; (void)queue; (void)qfam; (void)features_enabled;
|
||||
}
|
||||
void fge_device_lost(void) {}
|
||||
void zfg_discard_history_update(void) {}
|
||||
void zfg_commit_history_update(void) {}
|
||||
int fge_caps_ok(int kind) { (void)kind; return 0; }
|
||||
const char *fge_caps_reason(void) { return "frame-generation engines not built into this compositor"; }
|
||||
int fge_format_ok(VkFormat fmt) { (void)fmt; return 0; }
|
||||
const char *fge_caps_reason(int kind) { (void)kind; return "frame-generation engines not built into this compositor"; }
|
||||
int fge_format_ok(int kind, VkFormat fmt) { (void)kind; (void)fmt; return 0; }
|
||||
int fge_engine_available(int kind) { (void)kind; return 0; }
|
||||
int fge_start(int kind, const char *cache_path) { (void)kind; (void)cache_path; return -1; }
|
||||
void fge_stop(void) {}
|
||||
int fge_unavailable(void) { return 1; }
|
||||
@@ -24,16 +27,28 @@ int fge_prepare(uint32_t w, uint32_t h, VkFormat fmt) { (void)w; (void)h; (void)
|
||||
uint32_t fge_plan(uint32_t capacity, uint64_t source_frames, float presented_rate) {
|
||||
(void)capacity; (void)source_frames; (void)presented_rate; return 0;
|
||||
}
|
||||
void fge_process(VkCommandBuffer cmd, VkImage source, uint32_t w, uint32_t h, uint32_t gens) {
|
||||
(void)cmd; (void)source; (void)w; (void)h; (void)gens;
|
||||
void fge_process(VkCommandBuffer cmd, VkImage source, VkImageView source_view, uint32_t w, uint32_t h,
|
||||
VkFormat fmt, uint64_t sequence, uint32_t gens) {
|
||||
(void)cmd; (void)source; (void)source_view; (void)w; (void)h; (void)fmt; (void)sequence; (void)gens;
|
||||
}
|
||||
void fge_generate(VkCommandBuffer cmd, uint32_t g, uint32_t count, VkImage img, VkImageView view,
|
||||
uint32_t w, uint32_t h) {
|
||||
(void)cmd; (void)g; (void)count; (void)img; (void)view; (void)w; (void)h;
|
||||
}
|
||||
void fge_forget_targets(void) {}
|
||||
void fge_set_layer_timing(int layer) { (void)layer; }
|
||||
void fge_set_phases(const float *phases, uint32_t count) { (void)phases; (void)count; }
|
||||
float fge_phase(uint32_t index, uint32_t count) { return (float)(index + 1) / (float)(count + 1); }
|
||||
uint32_t fge_pacer_plan(uint32_t multiplier, int64_t period_ns, int64_t vsync_ns, int64_t issue_ns, uint32_t max_generated,
|
||||
int64_t *present_ns, float *phases) {
|
||||
(void)multiplier; (void)period_ns; (void)vsync_ns; (void)issue_ns; (void)max_generated; (void)present_ns; (void)phases;
|
||||
return 0;
|
||||
}
|
||||
void fge_pacer_completed(int64_t issue_ns, int64_t done_ns) { (void)issue_ns; (void)done_ns; }
|
||||
void fge_pacer_shown(int64_t planned_ns, int64_t shown_ns) { (void)planned_ns; (void)shown_ns; }
|
||||
void fge_pacer_reset(void) {}
|
||||
void fge_telemetry(float *accepted, float *source_rate, float *thermal) {
|
||||
*accepted = 0.0f; *source_rate = 0.0f; *thermal = -1.0f;
|
||||
}
|
||||
const char *fge_engine_name(int kind) { return kind == 1 ? "DD-FG Native" : "LSFG Native"; }
|
||||
const char *fge_engine_name(int kind) { return kind == 2 ? "ZeroFG" : kind == 1 ? "DD-FG Native" : "LSFG Native"; }
|
||||
const char *fge_build_info(void) { return "stub"; }
|
||||
@@ -14,6 +14,12 @@ Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeSetFrameGenArmed(JNI
|
||||
vkp_framegen_set_armed(armed ? 1 : 0, (int)multiplier, (int)targetFps);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeSetFrameGenPacer(JNIEnv *env, jclass clazz, jboolean on) {
|
||||
(void)env; (void)clazz;
|
||||
vkp_framegen_set_pacer(on ? 1 : 0);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeSetLsfgCachePath(JNIEnv *env, jclass clazz, jstring path) {
|
||||
(void)clazz;
|
||||
|
||||
@@ -0,0 +1,602 @@
|
||||
#include "framegen_zerofg.h"
|
||||
#include "sc_layer.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <chrono>
|
||||
#include <cmath>
|
||||
#include <cstdio>
|
||||
#include <memory>
|
||||
|
||||
#include <android/log.h>
|
||||
#include <zerofg/zerofg.h>
|
||||
|
||||
#define ZFG_LOG(...) __android_log_print(ANDROID_LOG_INFO, "DroidDeckWayland", "ZeroFG: " __VA_ARGS__)
|
||||
#define ZFG_ERR(...) __android_log_print(ANDROID_LOG_ERROR, "DroidDeckWayland", "ZeroFG: " __VA_ARGS__)
|
||||
|
||||
namespace {
|
||||
PFN_vkGetInstanceProcAddr g_gipa = nullptr;
|
||||
PFN_vkGetDeviceProcAddr g_gdpa = nullptr;
|
||||
VkInstance g_instance = VK_NULL_HANDLE;
|
||||
VkPhysicalDevice g_physical = VK_NULL_HANDLE;
|
||||
VkDevice g_device = VK_NULL_HANDLE;
|
||||
uint32_t g_api_version = VK_API_VERSION_1_0;
|
||||
bool g_synchronization2 = false, g_extended_formats = false;
|
||||
bool g_ready = false, g_supported = false, g_failed = false;
|
||||
char g_reason[160] = "device has not been checked";
|
||||
|
||||
PFN_vkGetPhysicalDeviceMemoryProperties g_GetPhysicalDeviceMemoryProperties = nullptr;
|
||||
PFN_vkGetPhysicalDeviceFormatProperties g_GetPhysicalDeviceFormatProperties = nullptr;
|
||||
PFN_vkCreateImage g_CreateImage = nullptr;
|
||||
PFN_vkDestroyImage g_DestroyImage = nullptr;
|
||||
PFN_vkCreateImageView g_CreateImageView = nullptr;
|
||||
PFN_vkDestroyImageView g_DestroyImageView = nullptr;
|
||||
PFN_vkGetImageMemoryRequirements g_GetImageMemoryRequirements = nullptr;
|
||||
PFN_vkAllocateMemory g_AllocateMemory = nullptr;
|
||||
PFN_vkFreeMemory g_FreeMemory = nullptr;
|
||||
PFN_vkBindImageMemory g_BindImageMemory = nullptr;
|
||||
PFN_vkCmdPipelineBarrier g_CmdPipelineBarrier = nullptr;
|
||||
PFN_vkCmdCopyImage g_CmdCopyImage = nullptr;
|
||||
PFN_vkDeviceWaitIdle g_DeviceWaitIdle = nullptr;
|
||||
VkPhysicalDeviceMemoryProperties g_memory_properties{};
|
||||
|
||||
std::unique_ptr<zerofg::Interpolator> g_interpolator;
|
||||
VkImage g_history = VK_NULL_HANDLE;
|
||||
VkImageView g_history_view = VK_NULL_HANDLE;
|
||||
VkDeviceMemory g_history_memory = VK_NULL_HANDLE;
|
||||
uint32_t g_width = 0, g_height = 0;
|
||||
VkFormat g_format = VK_FORMAT_UNDEFINED;
|
||||
bool g_history_layout_defined = false, g_history_valid = false;
|
||||
uint64_t g_history_sequence = 0;
|
||||
bool g_history_recorded_pending = false;
|
||||
uint64_t g_history_recorded_sequence = 0;
|
||||
std::array<bool, 4> g_fallback_outputs{};
|
||||
VkImage g_current = VK_NULL_HANDLE;
|
||||
VkImageView g_current_view = VK_NULL_HANDLE;
|
||||
uint64_t g_current_sequence = 0;
|
||||
bool g_pair_pending = false;
|
||||
|
||||
// Pacing. The compositor presents a pair's generated frames and its real frame back to back in FIFO,
|
||||
// so they reach the panel on consecutive refreshes right after the tick that drew them.
|
||||
constexpr uint64_t kBreakNs = 250000000ull;
|
||||
constexpr size_t kIntervalWindow = 8;
|
||||
constexpr size_t kMinIntervals = 4;
|
||||
constexpr double kSlotTolerance = 0.15;
|
||||
uint32_t g_multiplier = 2;
|
||||
float g_refresh_hz = 0.0f;
|
||||
bool g_layer_timing = false;
|
||||
// The phases the pacer chose for this pair (count 0: none, the timing above decides).
|
||||
std::array<float, 4> g_external_phases{};
|
||||
uint32_t g_external_count = 0;
|
||||
uint64_t g_last_sequence = 0;
|
||||
uint64_t g_last_issue_ns = 0;
|
||||
uint64_t g_pair_interval_ns = 0;
|
||||
uint32_t g_prev_count = 0, g_pair_count = 0;
|
||||
std::array<uint64_t, kIntervalWindow> g_intervals{};
|
||||
size_t g_interval_count = 0, g_interval_next = 0;
|
||||
|
||||
uint64_t now_ns() {
|
||||
return static_cast<uint64_t>(std::chrono::duration_cast<std::chrono::nanoseconds>(
|
||||
std::chrono::steady_clock::now().time_since_epoch()).count());
|
||||
}
|
||||
|
||||
void reset_pacing() {
|
||||
g_last_issue_ns = 0;
|
||||
g_pair_interval_ns = 0;
|
||||
g_prev_count = g_pair_count = 0;
|
||||
g_interval_count = g_interval_next = 0;
|
||||
}
|
||||
|
||||
uint64_t period_ns() {
|
||||
return g_refresh_hz > 1.0f ? static_cast<uint64_t>(1e9 / static_cast<double>(g_refresh_hz)) : 0;
|
||||
}
|
||||
|
||||
uint64_t typical_interval_ns() {
|
||||
if (g_interval_count < kMinIntervals) return 0;
|
||||
std::array<uint64_t, kIntervalWindow> sorted = g_intervals;
|
||||
std::sort(sorted.begin(), sorted.begin() + g_interval_count);
|
||||
return sorted[g_interval_count / 2];
|
||||
}
|
||||
|
||||
void note_sequence(uint64_t sequence) {
|
||||
if (sequence == g_last_sequence) return;
|
||||
const uint64_t now = now_ns();
|
||||
if (sequence < g_last_sequence) {
|
||||
// The frame counter changed source (game frames vs compositor scenes): no pair across it.
|
||||
g_history_valid = false;
|
||||
g_history_sequence = 0;
|
||||
reset_pacing();
|
||||
} else if (g_last_issue_ns && now > g_last_issue_ns) {
|
||||
const uint64_t interval = now - g_last_issue_ns;
|
||||
if (interval > kBreakNs) {
|
||||
reset_pacing();
|
||||
} else {
|
||||
g_pair_interval_ns = interval;
|
||||
g_intervals[g_interval_next] = interval;
|
||||
g_interval_next = (g_interval_next + 1) % kIntervalWindow;
|
||||
g_interval_count = std::min(g_interval_count + 1, kIntervalWindow);
|
||||
}
|
||||
}
|
||||
g_last_sequence = sequence;
|
||||
g_last_issue_ns = now;
|
||||
}
|
||||
|
||||
// Generated frames a pair can show without its presents queueing past the next game frame:
|
||||
// one refresh each, the real frame one more, all inside the game's typical frame interval.
|
||||
uint32_t pair_capacity(uint32_t wanted) {
|
||||
const uint64_t period = period_ns();
|
||||
const uint64_t typical = typical_interval_ns();
|
||||
if (!period || !typical) return wanted;
|
||||
const double slots = std::floor(static_cast<double>(typical) / static_cast<double>(period) + kSlotTolerance);
|
||||
return slots < 2.0 ? 0u : std::min<uint32_t>(wanted, static_cast<uint32_t>(slots) - 1u);
|
||||
}
|
||||
|
||||
// The scene layer (sc_layer.c) shows a group of [count] generated frames and then B, frame k of the group
|
||||
// max(k, round(k * gap / (count + 1))) refreshes after the first, a group every game frame interval.
|
||||
float layer_phase(uint32_t index, uint32_t count, uint64_t period) {
|
||||
const float even = static_cast<float>(index + 1) / static_cast<float>(count + 1);
|
||||
int64_t cadence_gap = 0;
|
||||
int cadence_frames = 0;
|
||||
sc_layer_cadence_info(&cadence_gap, &cadence_frames);
|
||||
const uint64_t gap = cadence_gap > 0 ? static_cast<uint64_t>(cadence_gap) : typical_interval_ns();
|
||||
const uint32_t group_frames = cadence_frames > static_cast<int>(count)
|
||||
? static_cast<uint32_t>(cadence_frames) : count + 1;
|
||||
if (!gap) return even;
|
||||
const int64_t slots = static_cast<int64_t>((gap + period / 2) / period);
|
||||
if (slots < static_cast<int64_t>(group_frames)) return even;
|
||||
const auto step = [&](uint32_t k) {
|
||||
const int64_t s = static_cast<int64_t>((static_cast<uint64_t>(k) * gap / group_frames + period / 2) / period);
|
||||
return std::max<int64_t>(s, k);
|
||||
};
|
||||
const double phase = static_cast<double>(step(index) - step(count) + slots) / static_cast<double>(slots);
|
||||
return static_cast<float>(std::clamp(phase, 0.05, 0.95));
|
||||
}
|
||||
|
||||
// FIFO presents the generated group and B back-to-back; phase uses the measured real-frame span.
|
||||
float pair_phase(uint32_t index, uint32_t count) {
|
||||
if (g_external_count == count && index < count) return std::clamp(g_external_phases[index], 0.01f, 0.99f);
|
||||
const float even = static_cast<float>(index + 1) / static_cast<float>(count + 1);
|
||||
const uint64_t period = period_ns();
|
||||
if (!period) return even;
|
||||
if (g_layer_timing) return layer_phase(index, count, period);
|
||||
if (!g_pair_interval_ns) return even;
|
||||
const double span = static_cast<double>(g_pair_interval_ns) +
|
||||
(static_cast<double>(count) - static_cast<double>(g_prev_count)) * static_cast<double>(period);
|
||||
if (span <= static_cast<double>(period) * (count + 1)) return even;
|
||||
const double phase = 1.0 - static_cast<double>(count - index) * static_cast<double>(period) / span;
|
||||
return static_cast<float>(std::clamp(phase, 0.05, 0.95));
|
||||
}
|
||||
|
||||
void load_device_functions() {
|
||||
if (g_gipa && g_instance) {
|
||||
g_GetPhysicalDeviceMemoryProperties =
|
||||
reinterpret_cast<PFN_vkGetPhysicalDeviceMemoryProperties>(
|
||||
g_gipa(g_instance, "vkGetPhysicalDeviceMemoryProperties"));
|
||||
g_GetPhysicalDeviceFormatProperties =
|
||||
reinterpret_cast<PFN_vkGetPhysicalDeviceFormatProperties>(
|
||||
g_gipa(g_instance, "vkGetPhysicalDeviceFormatProperties"));
|
||||
}
|
||||
if (!g_gdpa || !g_device) return;
|
||||
#define LOAD(name) g_##name = reinterpret_cast<PFN_vk##name>(g_gdpa(g_device, "vk" #name))
|
||||
LOAD(CreateImage);
|
||||
LOAD(DestroyImage);
|
||||
LOAD(CreateImageView);
|
||||
LOAD(DestroyImageView);
|
||||
LOAD(GetImageMemoryRequirements);
|
||||
LOAD(AllocateMemory);
|
||||
LOAD(FreeMemory);
|
||||
LOAD(BindImageMemory);
|
||||
LOAD(CmdPipelineBarrier);
|
||||
LOAD(CmdCopyImage);
|
||||
LOAD(DeviceWaitIdle);
|
||||
#undef LOAD
|
||||
}
|
||||
|
||||
void clear_history_state() {
|
||||
g_history_valid = false;
|
||||
g_history_sequence = 0;
|
||||
g_pair_pending = false;
|
||||
g_current = VK_NULL_HANDLE;
|
||||
g_current_view = VK_NULL_HANDLE;
|
||||
g_current_sequence = 0;
|
||||
}
|
||||
|
||||
void destroy_history() {
|
||||
if (g_device) {
|
||||
if (g_history_view && g_DestroyImageView) g_DestroyImageView(g_device, g_history_view, nullptr);
|
||||
if (g_history && g_DestroyImage) g_DestroyImage(g_device, g_history, nullptr);
|
||||
if (g_history_memory && g_FreeMemory) g_FreeMemory(g_device, g_history_memory, nullptr);
|
||||
}
|
||||
g_history = VK_NULL_HANDLE;
|
||||
g_history_view = VK_NULL_HANDLE;
|
||||
g_history_memory = VK_NULL_HANDLE;
|
||||
g_width = g_height = 0;
|
||||
g_format = VK_FORMAT_UNDEFINED;
|
||||
g_history_layout_defined = false;
|
||||
clear_history_state();
|
||||
}
|
||||
|
||||
uint32_t find_memory_type(uint32_t bits) {
|
||||
uint32_t fallback = UINT32_MAX;
|
||||
for (uint32_t i = 0; i < g_memory_properties.memoryTypeCount; ++i) {
|
||||
if ((bits & (1u << i)) == 0) continue;
|
||||
const auto flags = g_memory_properties.memoryTypes[i].propertyFlags;
|
||||
if (flags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) return i;
|
||||
if (fallback == UINT32_MAX) fallback = i;
|
||||
}
|
||||
return fallback;
|
||||
}
|
||||
|
||||
bool make_history(uint32_t width, uint32_t height, VkFormat format) {
|
||||
if (!g_CreateImage || !g_GetImageMemoryRequirements || !g_AllocateMemory ||
|
||||
!g_BindImageMemory || !g_CreateImageView || !g_GetPhysicalDeviceMemoryProperties) {
|
||||
std::snprintf(g_reason, sizeof(g_reason), "Vulkan image functions unavailable");
|
||||
return false;
|
||||
}
|
||||
VkImageCreateInfo image_info{};
|
||||
image_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
|
||||
image_info.imageType = VK_IMAGE_TYPE_2D;
|
||||
image_info.format = format;
|
||||
image_info.extent = {width, height, 1};
|
||||
image_info.mipLevels = 1;
|
||||
image_info.arrayLayers = 1;
|
||||
image_info.samples = VK_SAMPLE_COUNT_1_BIT;
|
||||
image_info.tiling = VK_IMAGE_TILING_OPTIMAL;
|
||||
image_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
|
||||
image_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
|
||||
image_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||
if (g_CreateImage(g_device, &image_info, nullptr, &g_history) != VK_SUCCESS) {
|
||||
std::snprintf(g_reason, sizeof(g_reason), "could not create temporal history image");
|
||||
return false;
|
||||
}
|
||||
|
||||
VkMemoryRequirements requirements{};
|
||||
g_GetImageMemoryRequirements(g_device, g_history, &requirements);
|
||||
const uint32_t memory_index = find_memory_type(requirements.memoryTypeBits);
|
||||
if (memory_index == UINT32_MAX) {
|
||||
std::snprintf(g_reason, sizeof(g_reason), "no compatible memory for temporal history");
|
||||
destroy_history();
|
||||
return false;
|
||||
}
|
||||
VkMemoryAllocateInfo allocation{};
|
||||
allocation.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
|
||||
allocation.allocationSize = requirements.size;
|
||||
allocation.memoryTypeIndex = memory_index;
|
||||
if (g_AllocateMemory(g_device, &allocation, nullptr, &g_history_memory) != VK_SUCCESS ||
|
||||
g_BindImageMemory(g_device, g_history, g_history_memory, 0) != VK_SUCCESS) {
|
||||
std::snprintf(g_reason, sizeof(g_reason), "could not allocate temporal history memory");
|
||||
destroy_history();
|
||||
return false;
|
||||
}
|
||||
|
||||
VkImageViewCreateInfo view_info{};
|
||||
view_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
|
||||
view_info.image = g_history;
|
||||
view_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
|
||||
view_info.format = format;
|
||||
view_info.subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1};
|
||||
if (g_CreateImageView(g_device, &view_info, nullptr, &g_history_view) != VK_SUCCESS) {
|
||||
std::snprintf(g_reason, sizeof(g_reason), "could not create temporal history view");
|
||||
destroy_history();
|
||||
return false;
|
||||
}
|
||||
g_width = width;
|
||||
g_height = height;
|
||||
g_format = format;
|
||||
g_history_layout_defined = false;
|
||||
g_history_recorded_pending = false;
|
||||
g_history_recorded_sequence = 0;
|
||||
clear_history_state();
|
||||
return true;
|
||||
}
|
||||
|
||||
void copy_current_to_history(VkCommandBuffer cmd, VkImage source,
|
||||
uint32_t width, uint32_t height, uint64_t sequence) {
|
||||
if (!g_history || !source || !g_CmdPipelineBarrier || !g_CmdCopyImage) return;
|
||||
VkImageMemoryBarrier before{};
|
||||
before.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
|
||||
const bool layout_defined = g_history_layout_defined || g_history_recorded_pending;
|
||||
before.srcAccessMask = layout_defined ? VK_ACCESS_SHADER_READ_BIT : 0;
|
||||
before.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
|
||||
before.oldLayout = layout_defined ? VK_IMAGE_LAYOUT_GENERAL : VK_IMAGE_LAYOUT_UNDEFINED;
|
||||
before.newLayout = VK_IMAGE_LAYOUT_GENERAL;
|
||||
before.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||
before.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||
before.image = g_history;
|
||||
before.subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1};
|
||||
g_CmdPipelineBarrier(cmd,
|
||||
layout_defined ? VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT : VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
|
||||
VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, nullptr, 0, nullptr, 1, &before);
|
||||
|
||||
VkImageCopy region{};
|
||||
region.srcSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1};
|
||||
region.dstSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1};
|
||||
region.extent = {width, height, 1};
|
||||
g_CmdCopyImage(cmd, source, VK_IMAGE_LAYOUT_GENERAL, g_history, VK_IMAGE_LAYOUT_GENERAL, 1, ®ion);
|
||||
|
||||
VkImageMemoryBarrier after{};
|
||||
after.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
|
||||
after.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
|
||||
after.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
|
||||
after.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
|
||||
after.newLayout = VK_IMAGE_LAYOUT_GENERAL;
|
||||
after.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||
after.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||
after.image = g_history;
|
||||
after.subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1};
|
||||
g_CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
|
||||
0, 0, nullptr, 0, nullptr, 1, &after);
|
||||
g_history_recorded_pending = true;
|
||||
g_history_recorded_sequence = sequence;
|
||||
g_pair_pending = false;
|
||||
}
|
||||
|
||||
void copy_current_to_output(VkCommandBuffer cmd, VkImage output, uint32_t width, uint32_t height) {
|
||||
if (!g_current || !output || !g_CmdPipelineBarrier || !g_CmdCopyImage) return;
|
||||
VkImageMemoryBarrier before{};
|
||||
before.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
|
||||
before.srcAccessMask = VK_ACCESS_MEMORY_WRITE_BIT | VK_ACCESS_SHADER_WRITE_BIT;
|
||||
before.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
|
||||
before.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
|
||||
before.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
|
||||
before.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||
before.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||
before.image = output;
|
||||
before.subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1};
|
||||
g_CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT,
|
||||
0, 0, nullptr, 0, nullptr, 1, &before);
|
||||
VkImageCopy region{};
|
||||
region.srcSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1};
|
||||
region.dstSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1};
|
||||
region.extent = {width, height, 1};
|
||||
g_CmdCopyImage(cmd, g_current, VK_IMAGE_LAYOUT_GENERAL,
|
||||
output, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, ®ion);
|
||||
VkImageMemoryBarrier after{};
|
||||
after.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
|
||||
after.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
|
||||
after.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_SHADER_READ_BIT;
|
||||
after.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
|
||||
after.newLayout = VK_IMAGE_LAYOUT_GENERAL;
|
||||
after.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||
after.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||
after.image = output;
|
||||
after.subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1};
|
||||
g_CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
|
||||
0, 0, nullptr, 0, nullptr, 1, &after);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
extern "C" {
|
||||
void zfg_device_ready(PFN_vkGetInstanceProcAddr gipa, VkInstance instance,
|
||||
VkPhysicalDevice physical_device, VkDevice device,
|
||||
uint32_t api_version, int synchronization2_enabled,
|
||||
int extended_storage_formats_enabled) {
|
||||
g_gipa = gipa;
|
||||
g_instance = instance;
|
||||
g_physical = physical_device;
|
||||
g_device = device;
|
||||
g_api_version = api_version;
|
||||
g_synchronization2 = synchronization2_enabled != 0;
|
||||
g_extended_formats = extended_storage_formats_enabled != 0;
|
||||
g_gdpa = g_gipa && g_instance
|
||||
? reinterpret_cast<PFN_vkGetDeviceProcAddr>(g_gipa(g_instance, "vkGetDeviceProcAddr"))
|
||||
: nullptr;
|
||||
load_device_functions();
|
||||
if (g_GetPhysicalDeviceMemoryProperties && g_physical)
|
||||
g_GetPhysicalDeviceMemoryProperties(g_physical, &g_memory_properties);
|
||||
g_ready = g_device != VK_NULL_HANDLE;
|
||||
g_supported = g_ready && g_api_version >= VK_API_VERSION_1_3 &&
|
||||
g_synchronization2 && g_extended_formats;
|
||||
g_failed = false;
|
||||
std::snprintf(g_reason, sizeof(g_reason), "%s", g_supported ? "available" :
|
||||
"requires Vulkan 1.3, synchronization2 and shaderStorageImageExtendedFormats");
|
||||
}
|
||||
|
||||
void zfg_device_lost(void) {
|
||||
g_interpolator.reset();
|
||||
destroy_history();
|
||||
g_gipa = nullptr; g_gdpa = nullptr;
|
||||
g_instance = VK_NULL_HANDLE; g_physical = VK_NULL_HANDLE; g_device = VK_NULL_HANDLE;
|
||||
g_ready = g_supported = g_failed = false;
|
||||
g_synchronization2 = g_extended_formats = false;
|
||||
g_api_version = VK_API_VERSION_1_0;
|
||||
g_GetPhysicalDeviceMemoryProperties = nullptr;
|
||||
g_GetPhysicalDeviceFormatProperties = nullptr;
|
||||
g_CreateImage = nullptr; g_DestroyImage = nullptr;
|
||||
g_CreateImageView = nullptr; g_DestroyImageView = nullptr;
|
||||
g_GetImageMemoryRequirements = nullptr; g_AllocateMemory = nullptr;
|
||||
g_FreeMemory = nullptr; g_BindImageMemory = nullptr;
|
||||
g_CmdPipelineBarrier = nullptr; g_CmdCopyImage = nullptr; g_DeviceWaitIdle = nullptr;
|
||||
g_memory_properties = {};
|
||||
std::snprintf(g_reason, sizeof(g_reason), "device lost");
|
||||
}
|
||||
|
||||
int zfg_caps_ok(void) { return g_supported ? 1 : 0; }
|
||||
const char *zfg_caps_reason(void) { return g_reason; }
|
||||
|
||||
int zfg_start(void) {
|
||||
if (!g_supported || !g_ready) return 0;
|
||||
if (g_interpolator) return 1;
|
||||
zerofg::CreateInfo info{};
|
||||
info.vulkan.instance = g_instance;
|
||||
info.vulkan.physical_device = g_physical;
|
||||
info.vulkan.device = g_device;
|
||||
info.vulkan.get_instance_proc_addr = g_gipa;
|
||||
info.mode = zerofg::Mode::kReallyZero;
|
||||
info.backend = zerofg::Backend::kCompat;
|
||||
info.frame_context_count = 4;
|
||||
info.capabilities.effective_api_version = g_api_version;
|
||||
info.capabilities.synchronization2_enabled = g_synchronization2;
|
||||
info.capabilities.shader_storage_image_extended_formats_enabled = g_extended_formats;
|
||||
zerofg::Status status = zerofg::Status::kSuccess;
|
||||
g_interpolator = zerofg::Interpolator::Create(info, &status);
|
||||
if (!g_interpolator) {
|
||||
std::snprintf(g_reason, sizeof(g_reason), "interpolator creation failed (%d)", (int)status);
|
||||
g_failed = true;
|
||||
ZFG_ERR("%s", g_reason);
|
||||
return 0;
|
||||
}
|
||||
g_failed = false;
|
||||
ZFG_LOG("ReallyZero engine ready (Compat backend)");
|
||||
return 1;
|
||||
}
|
||||
|
||||
void zfg_stop(void) {
|
||||
g_interpolator.reset();
|
||||
destroy_history();
|
||||
reset_pacing();
|
||||
g_last_sequence = 0;
|
||||
g_failed = false;
|
||||
}
|
||||
int zfg_unavailable(void) { return g_failed || !g_interpolator ? 1 : 0; }
|
||||
|
||||
int zfg_format_ok(VkFormat format) {
|
||||
if (!g_supported || !g_GetPhysicalDeviceFormatProperties || format == VK_FORMAT_UNDEFINED) return 0;
|
||||
VkFormatProperties input{};
|
||||
g_GetPhysicalDeviceFormatProperties(g_physical, format, &input);
|
||||
const VkFormatFeatureFlags sampled =
|
||||
VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT | VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT;
|
||||
if ((input.optimalTilingFeatures & sampled) != sampled) return 0;
|
||||
if (format == VK_FORMAT_A2B10G10R10_UNORM_PACK32)
|
||||
return (input.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) != 0;
|
||||
VkFormatProperties internal{};
|
||||
g_GetPhysicalDeviceFormatProperties(g_physical, VK_FORMAT_A2B10G10R10_UNORM_PACK32, &internal);
|
||||
const VkFormatFeatureFlags needed = VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT | VK_FORMAT_FEATURE_BLIT_SRC_BIT;
|
||||
return (input.optimalTilingFeatures & VK_FORMAT_FEATURE_BLIT_DST_BIT) != 0 &&
|
||||
(internal.optimalTilingFeatures & needed) == needed;
|
||||
}
|
||||
|
||||
int zfg_prepare(uint32_t width, uint32_t height, VkFormat format) {
|
||||
if (!g_interpolator || g_failed || !width || !height) return 0;
|
||||
if (!zfg_format_ok(format)) {
|
||||
std::snprintf(g_reason, sizeof(g_reason), "unsupported input/output format %d", (int)format);
|
||||
g_failed = true;
|
||||
ZFG_ERR("%s", g_reason);
|
||||
return 0;
|
||||
}
|
||||
if (g_width == width && g_height == height && g_format == format && g_history) return 1;
|
||||
if (g_DeviceWaitIdle) g_DeviceWaitIdle(g_device);
|
||||
destroy_history();
|
||||
const zerofg::Status resized = g_interpolator->Resize(width, height, format, format);
|
||||
if (resized != zerofg::Status::kSuccess) {
|
||||
std::snprintf(g_reason, sizeof(g_reason), "resize failed (%d)", (int)resized);
|
||||
g_failed = true;
|
||||
ZFG_ERR("%s", g_reason);
|
||||
return 0;
|
||||
}
|
||||
if (!make_history(width, height, format)) {
|
||||
g_failed = true;
|
||||
ZFG_ERR("%s", g_reason);
|
||||
return 0;
|
||||
}
|
||||
ZFG_LOG("prepared %ux%u format %d", width, height, (int)format);
|
||||
return 1;
|
||||
}
|
||||
|
||||
void zfg_configure(uint32_t multiplier, float refresh_hz) {
|
||||
g_multiplier = std::clamp<uint32_t>(multiplier, 2, 4);
|
||||
g_refresh_hz = refresh_hz > 1.0f ? refresh_hz : 0.0f;
|
||||
}
|
||||
|
||||
void zfg_set_layer_timing(int layer) { g_layer_timing = layer != 0; }
|
||||
|
||||
void zfg_set_phases(const float *phases, uint32_t count) {
|
||||
g_external_count = phases ? std::min<uint32_t>(count, static_cast<uint32_t>(g_external_phases.size())) : 0;
|
||||
for (uint32_t i = 0; i < g_external_count; i++) g_external_phases[i] = phases[i];
|
||||
}
|
||||
|
||||
float zfg_phase(uint32_t index, uint32_t count) { return pair_phase(index, count); }
|
||||
|
||||
uint32_t zfg_plan(uint32_t capacity, uint64_t sequence) {
|
||||
if (!g_interpolator || g_failed) return 0;
|
||||
note_sequence(sequence);
|
||||
if (!g_history_valid || sequence <= g_history_sequence || !g_pair_interval_ns) return 0;
|
||||
return pair_capacity(std::min<uint32_t>({capacity, 3u, g_multiplier - 1}));
|
||||
}
|
||||
|
||||
void zfg_telemetry(float *generated, float *source_rate) {
|
||||
const uint64_t typical = typical_interval_ns();
|
||||
*generated = static_cast<float>(g_pair_count);
|
||||
*source_rate = typical ? static_cast<float>(1e9 / static_cast<double>(typical)) : 0.0f;
|
||||
}
|
||||
|
||||
void zfg_process(VkCommandBuffer cmd, VkImage source, VkImageView source_view,
|
||||
uint32_t width, uint32_t height, VkFormat format,
|
||||
uint64_t sequence, uint32_t generations) {
|
||||
g_pair_pending = false;
|
||||
g_fallback_outputs.fill(false);
|
||||
if (!g_interpolator || g_failed || !source || !g_history ||
|
||||
format != g_format || width != g_width || height != g_height) return;
|
||||
if (sequence > g_history_sequence) {
|
||||
g_prev_count = g_pair_count;
|
||||
g_pair_count = generations;
|
||||
}
|
||||
if (generations == 0 || !g_history_valid || sequence <= g_history_sequence) {
|
||||
copy_current_to_history(cmd, source, width, height, sequence);
|
||||
return;
|
||||
}
|
||||
if (!source_view) return;
|
||||
g_current = source;
|
||||
g_current_view = source_view;
|
||||
g_current_sequence = sequence;
|
||||
g_pair_pending = true;
|
||||
}
|
||||
|
||||
void zfg_generate(VkCommandBuffer cmd, uint32_t index, uint32_t count,
|
||||
VkImage output, VkImageView output_view, uint32_t width, uint32_t height) {
|
||||
if (!g_pair_pending || !g_interpolator || !g_history_valid || index >= count || !output || !output_view) return;
|
||||
const float phase = pair_phase(index, count);
|
||||
zerofg::Image previous{};
|
||||
previous.image = g_history; previous.view = g_history_view;
|
||||
previous.layout = VK_IMAGE_LAYOUT_GENERAL; previous.format = g_format;
|
||||
previous.width = g_width; previous.height = g_height;
|
||||
previous.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
|
||||
previous.sequence = g_history_sequence;
|
||||
zerofg::Image current{};
|
||||
current.image = g_current; current.view = g_current_view;
|
||||
current.layout = VK_IMAGE_LAYOUT_GENERAL; current.format = g_format;
|
||||
current.width = g_width; current.height = g_height;
|
||||
current.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
|
||||
current.sequence = g_current_sequence;
|
||||
zerofg::Image result{};
|
||||
result.image = output; result.view = output_view;
|
||||
result.layout = VK_IMAGE_LAYOUT_GENERAL; result.format = g_format;
|
||||
result.width = width; result.height = height;
|
||||
result.usage = VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_SAMPLED_BIT |
|
||||
VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
|
||||
|
||||
const zerofg::Status status =
|
||||
g_interpolator->Interpolate(cmd, index, previous, current, phase, result);
|
||||
if (status != zerofg::Status::kSuccess) {
|
||||
ZFG_ERR("interpolation status %d; copying the real frame as fallback", (int)status);
|
||||
g_fallback_outputs[index] = true;
|
||||
copy_current_to_output(cmd, output, width, height);
|
||||
}
|
||||
if (index + 1 >= count) {
|
||||
copy_current_to_history(cmd, g_current, width, height, g_current_sequence);
|
||||
g_pair_pending = false;
|
||||
}
|
||||
}
|
||||
|
||||
void zfg_commit_history_update(void) {
|
||||
if (!g_history_recorded_pending) return;
|
||||
g_history_layout_defined = true;
|
||||
g_history_valid = true;
|
||||
g_history_sequence = g_history_recorded_sequence;
|
||||
g_history_recorded_pending = false;
|
||||
}
|
||||
|
||||
void zfg_discard_history_update(void) {
|
||||
g_history_recorded_pending = false;
|
||||
g_history_recorded_sequence = 0;
|
||||
}
|
||||
|
||||
void zfg_forget_targets(void) {
|
||||
g_pair_pending = false;
|
||||
g_history_recorded_pending = false;
|
||||
g_history_recorded_sequence = 0;
|
||||
g_history_valid = false;
|
||||
g_history_sequence = 0;
|
||||
reset_pacing();
|
||||
}
|
||||
} // extern "C"
|
||||
@@ -0,0 +1,38 @@
|
||||
#ifndef FRAMEGEN_ZEROFG_H
|
||||
#define FRAMEGEN_ZEROFG_H
|
||||
#include <stdint.h>
|
||||
#include <vulkan/vulkan.h>
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
void zfg_device_ready(PFN_vkGetInstanceProcAddr gipa, VkInstance instance,
|
||||
VkPhysicalDevice physical_device, VkDevice device,
|
||||
uint32_t api_version, int synchronization2_enabled,
|
||||
int extended_storage_formats_enabled);
|
||||
void zfg_device_lost(void);
|
||||
int zfg_caps_ok(void);
|
||||
const char *zfg_caps_reason(void);
|
||||
int zfg_start(void);
|
||||
void zfg_stop(void);
|
||||
int zfg_unavailable(void);
|
||||
int zfg_format_ok(VkFormat format);
|
||||
int zfg_prepare(uint32_t width, uint32_t height, VkFormat format);
|
||||
void zfg_configure(uint32_t multiplier, float refresh_hz);
|
||||
void zfg_set_layer_timing(int layer);
|
||||
void zfg_set_phases(const float *phases, uint32_t count);
|
||||
float zfg_phase(uint32_t index, uint32_t count);
|
||||
uint32_t zfg_plan(uint32_t capacity, uint64_t sequence);
|
||||
void zfg_telemetry(float *generated, float *source_rate);
|
||||
void zfg_process(VkCommandBuffer command_buffer, VkImage source, VkImageView source_view,
|
||||
uint32_t width, uint32_t height, VkFormat format,
|
||||
uint64_t sequence, uint32_t generations);
|
||||
void zfg_generate(VkCommandBuffer command_buffer, uint32_t index, uint32_t count,
|
||||
VkImage output, VkImageView output_view,
|
||||
uint32_t width, uint32_t height);
|
||||
void zfg_forget_targets(void);
|
||||
void zfg_commit_history_update(void);
|
||||
void zfg_discard_history_update(void);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
@@ -58,6 +58,7 @@ static struct {
|
||||
void (*reparent)(ASurfaceTransaction *, ASurfaceControl *, ASurfaceControl *);
|
||||
void (*setOnComplete)(ASurfaceTransaction *, void *, sc_complete_fn);
|
||||
int (*prevReleaseFence)(ASurfaceTransactionStats *, ASurfaceControl *);
|
||||
int (*presentFence)(ASurfaceTransactionStats *);
|
||||
void (*setFrameRate)(ASurfaceTransaction *, ASurfaceControl *, float, int8_t);
|
||||
void (*setFrameRateStrategy)(ASurfaceTransaction *, ASurfaceControl *, float, int8_t, int8_t);
|
||||
void (*setBufferDataSpace)(ASurfaceTransaction *, ASurfaceControl *, int32_t);
|
||||
@@ -102,6 +103,7 @@ static int load_api(void) {
|
||||
SYM(reparent, "ASurfaceTransaction_reparent");
|
||||
SYM(setOnComplete, "ASurfaceTransaction_setOnComplete");
|
||||
SYM(prevReleaseFence, "ASurfaceTransactionStats_getPreviousReleaseFenceFd");
|
||||
SYM(presentFence, "ASurfaceTransactionStats_getPresentFenceFd");
|
||||
SYM(setFrameRate, "ASurfaceTransaction_setFrameRate");
|
||||
SYM(setFrameRateStrategy, "ASurfaceTransaction_setFrameRateWithChangeStrategy");
|
||||
SYM(setBufferDataSpace, "ASurfaceTransaction_setBufferDataSpace");
|
||||
@@ -187,6 +189,8 @@ struct layer {
|
||||
static struct layer g_layers[SC_LAYER_COUNT];
|
||||
static void apply_frame_rate(ASurfaceTransaction *tx, struct layer *l);
|
||||
static void coverage_text(const struct layer *l, char *out, size_t n);
|
||||
static int overlay_slot(struct layer *l, struct vkp_image *src, int *idx, int *wait_fd);
|
||||
static int overlay_shown(struct layer *l, int idx, const int geo[8], int translucent);
|
||||
static int g_layers_ready;
|
||||
static pthread_mutex_t g_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
static int g_pending_cb;
|
||||
@@ -263,7 +267,33 @@ static int64_t cadence_target(int64_t now, int64_t earliest, int64_t period) {
|
||||
return target;
|
||||
}
|
||||
|
||||
static int64_t g_planned_next_ns;
|
||||
|
||||
void sc_layer_set_planned(int64_t present_ns) {
|
||||
pthread_mutex_lock(&g_lock);
|
||||
g_planned_next_ns = present_ns;
|
||||
pthread_mutex_unlock(&g_lock);
|
||||
}
|
||||
|
||||
void sc_layer_timeline(int64_t *present_ns, int64_t *period_ns) {
|
||||
pthread_mutex_lock(&g_timeline_lock);
|
||||
*present_ns = g_timeline_present_ns;
|
||||
*period_ns = g_timeline_period_ns;
|
||||
pthread_mutex_unlock(&g_timeline_lock);
|
||||
}
|
||||
|
||||
void sc_layer_cadence_info(int64_t *gap_ns, int *group_frames) {
|
||||
if (gap_ns) *gap_ns = g_cadence_gap_ns;
|
||||
if (group_frames) *group_frames = g_group_frames;
|
||||
}
|
||||
|
||||
static void apply_present_time(ASurfaceTransaction *tx, int game) {
|
||||
pthread_mutex_lock(&g_lock);
|
||||
const int64_t planned = game ? g_planned_next_ns : 0;
|
||||
if (game) {
|
||||
g_planned_next_ns = 0;
|
||||
}
|
||||
pthread_mutex_unlock(&g_lock);
|
||||
if (!api.setDesiredPresentTime) return;
|
||||
pthread_mutex_lock(&g_timeline_lock);
|
||||
const int64_t present = g_timeline_present_ns, deadline = g_timeline_deadline_ns, period = g_timeline_period_ns;
|
||||
@@ -283,6 +313,9 @@ static void apply_present_time(ASurfaceTransaction *tx, int game) {
|
||||
target = cadence_target(now, target, period);
|
||||
}
|
||||
if (game && g_group_frames > 1 && ++g_group_index >= g_group_frames) { g_group_index = 0; g_group_frames = 1; }
|
||||
if (planned > 0) {
|
||||
target = planned;
|
||||
}
|
||||
api.setDesiredPresentTime(tx, target - period / 2);
|
||||
}
|
||||
|
||||
@@ -721,9 +754,15 @@ static int layer_geometry(int w, int h, int scene_w, int scene_h, const struct v
|
||||
static ARect g_game_src, g_game_dst;
|
||||
static int g_game_geo_known;
|
||||
|
||||
static void note_game_geometry(const int r[8]) {
|
||||
g_game_src = (ARect){r[0], r[1], r[2], r[3]};
|
||||
g_game_dst = (ARect){r[4], r[5], r[6], r[7]};
|
||||
g_game_geo_known = 1;
|
||||
}
|
||||
|
||||
static void apply_geometry(ASurfaceTransaction *tx, struct layer *l, const int r[8]) {
|
||||
ARect srcR = {r[0], r[1], r[2], r[3]}, dstR = {r[4], r[5], r[6], r[7]};
|
||||
if (l == &g_layers[SC_LAYER_GAME]) { g_game_src = srcR; g_game_dst = dstR; g_game_geo_known = 1; }
|
||||
if (l == &g_layers[SC_LAYER_GAME]) note_game_geometry(r);
|
||||
if (!l->geo_valid || memcmp(&srcR, &l->geo_src, sizeof(srcR)) || memcmp(&dstR, &l->geo_dst, sizeof(dstR))) {
|
||||
api.setGeometry(tx, l->sc, &srcR, &dstR, 0 );
|
||||
l->geo_src = srcR; l->geo_dst = dstR; l->geo_valid = 1;
|
||||
@@ -885,7 +924,9 @@ static int present_slot(struct layer *l, int idx, const int r[8], const struct d
|
||||
int translucent) {
|
||||
struct slot *s = &l->slots[idx];
|
||||
ASurfaceTransaction *tx = api.txCreate();
|
||||
if (!tx) return -1;
|
||||
if (!tx) {
|
||||
return -1;
|
||||
}
|
||||
const int was_shown = l->shown;
|
||||
const int32_t ds_applied = l->ds_applied;
|
||||
const uint32_t md_applied = l->md_applied;
|
||||
@@ -998,19 +1039,40 @@ unavailable:
|
||||
}
|
||||
|
||||
int sc_layer_present(struct vkp_image *src, int scene_w, int scene_h, const struct vkp_draw *draw,
|
||||
const struct droiddeck_color *color) {
|
||||
const struct droiddeck_color *color, const struct vkp_draw *over, int *over_shown) {
|
||||
struct layer *l = layer_of(SC_LAYER_GAME);
|
||||
*over_shown = 0;
|
||||
if (!src || ensure_sc(l) != 0) return -1;
|
||||
int sw = vkp_image_width(src), sh = vkp_image_height(src);
|
||||
int r[8];
|
||||
int g = layer_geometry(sw, sh, scene_w, scene_h, draw, r);
|
||||
if (g < 0) return -1;
|
||||
if (g == 0) { sc_layer_hide(); return 0; }
|
||||
int og[8];
|
||||
if (over && !vkp_map_draw(over, og)) over = NULL;
|
||||
if (g == 0) {
|
||||
sc_layer_hide();
|
||||
if (over) *over_shown = sc_layer_present_overlay(over->img, og, over->blend) == 0 ? 1 : -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int wait_fd;
|
||||
int idx = take_free_slot(l, sw, sh, AHB_RGBA8, &wait_fd);
|
||||
if (idx < 0) { log_drop(l); return g_alloc_failed ? -1 : 0; }
|
||||
if (vkp_blit_image(src, l->slots[idx].img, wait_fd) != 0) return -1;
|
||||
struct vkp_blit blits[2] = {{.src = src, .wait_fd = -1}, {.src = over ? over->img : NULL, .wait_fd = -1}};
|
||||
int idx = take_free_slot(l, sw, sh, AHB_RGBA8, &blits[0].wait_fd);
|
||||
if (idx < 0) {
|
||||
log_drop(l);
|
||||
if (g_alloc_failed) return -1;
|
||||
if (over) *over_shown = sc_layer_present_overlay(over->img, og, over->blend) == 0 ? 1 : -1;
|
||||
return 0;
|
||||
}
|
||||
blits[0].dst = l->slots[idx].img;
|
||||
struct layer *ol = layer_of(SC_LAYER_OVERLAY);
|
||||
int over_idx = -1;
|
||||
if (over) {
|
||||
note_game_geometry(r);
|
||||
const int taken = overlay_slot(ol, over->img, &over_idx, &blits[1].wait_fd);
|
||||
*over_shown = taken < 0 ? -1 : 1;
|
||||
if (taken > 0) blits[1].dst = ol->slots[over_idx].img;
|
||||
}
|
||||
if (vkp_blit_images(blits, over_idx >= 0 ? 2 : 1) != 0) return -1;
|
||||
if (present_slot(l, idx, r, color, 0) != 0) return -1;
|
||||
if (color && color->dataspace) droiddeck_color_frame_shown(color, DROIDDECK_HDR_LAYER_COPY, AHB_RGBA8);
|
||||
if (!l->first_logged) {
|
||||
@@ -1020,6 +1082,7 @@ int sc_layer_present(struct vkp_image *src, int scene_w, int scene_h, const stru
|
||||
pool_kind(l->pool_modifier), l->pool_n);
|
||||
}
|
||||
vkp_signal_first_frame();
|
||||
if (over_idx >= 0 && overlay_shown(ol, over_idx, og, over->blend) != 0) *over_shown = -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1084,7 +1147,7 @@ int sc_layer_present_generated(const struct vkp_draw *draws, int n_draws, const
|
||||
if (!mapped) { vkp_pass_abort(); sc_layer_hide(); return 0; }
|
||||
idx[VKP_FG_MAX_GENERATIONS] = deep ? take_hdr_slot(l, rw, rh, &first_fd)
|
||||
: take_free_slot(l, rw, rh, AHB_RGBA8, &first_fd);
|
||||
if (idx[VKP_FG_MAX_GENERATIONS] < 0) { vkp_pass_abort(); log_drop(l); return g_alloc_failed ? -1 : 0; }
|
||||
if (idx[VKP_FG_MAX_GENERATIONS] < 0) { vkp_pass_abort(); vkp_framegen_pacer_abort(); log_drop(l); return g_alloc_failed ? -1 : 0; }
|
||||
pthread_mutex_lock(&g_lock);
|
||||
l->slots[idx[VKP_FG_MAX_GENERATIONS]].busy = 1;
|
||||
pthread_mutex_unlock(&g_lock);
|
||||
@@ -1106,13 +1169,18 @@ int sc_layer_present_generated(const struct vkp_draw *draws, int n_draws, const
|
||||
if (!have_fd) { first_fd = fd; have_fd = 1; }
|
||||
}
|
||||
if (vkp_pass_copy_generated(dst, m, real, first_fd) != 0) {
|
||||
vkp_framegen_pacer_abort();
|
||||
slots_idle(l, idx, 0, m);
|
||||
if (real) slots_idle(l, idx, VKP_FG_MAX_GENERATIONS, VKP_FG_MAX_GENERATIONS + 1);
|
||||
return -1;
|
||||
}
|
||||
g_group_frames = m + 1;
|
||||
for (int k = 0; k < m; k++) {
|
||||
int64_t planned;
|
||||
vkp_framegen_output_planned(k, m, &planned);
|
||||
sc_layer_set_planned(planned);
|
||||
if (present_slot(l, idx[k], r, color, 0) == 0) continue;
|
||||
vkp_framegen_pacer_abort();
|
||||
slots_idle(l, idx, k, m);
|
||||
if (real) slots_idle(l, idx, VKP_FG_MAX_GENERATIONS, VKP_FG_MAX_GENERATIONS + 1);
|
||||
g_group_index = 0;
|
||||
@@ -1121,7 +1189,11 @@ int sc_layer_present_generated(const struct vkp_draw *draws, int n_draws, const
|
||||
}
|
||||
vkp_framegen_presented(m);
|
||||
if (real) {
|
||||
int64_t planned;
|
||||
vkp_framegen_output_planned(m, m, &planned);
|
||||
sc_layer_set_planned(planned);
|
||||
if (present_slot(l, idx[VKP_FG_MAX_GENERATIONS], r, color, 0) != 0) {
|
||||
vkp_framegen_pacer_abort();
|
||||
slots_idle(l, idx, VKP_FG_MAX_GENERATIONS, VKP_FG_MAX_GENERATIONS + 1);
|
||||
g_group_index = 0;
|
||||
g_group_frames = 1;
|
||||
@@ -1209,17 +1281,19 @@ int sc_layer_overlay_affordable(void) {
|
||||
return ok;
|
||||
}
|
||||
|
||||
int sc_layer_present_overlay(struct vkp_image *src, const int geo[8], int translucent) {
|
||||
struct layer *l = layer_of(SC_LAYER_OVERLAY);
|
||||
if (!src || !geo) return -1;
|
||||
static int overlay_slot(struct layer *l, struct vkp_image *src, int *idx, int *wait_fd) {
|
||||
*wait_fd = -1;
|
||||
if (!src) return -1;
|
||||
if (!sc_layer_overlay_affordable()) return -1;
|
||||
if (ensure_sc(l) != 0) return -1;
|
||||
int sw = vkp_image_width(src), sh = vkp_image_height(src);
|
||||
if (sw <= 0 || sh <= 0) return -1;
|
||||
int wait_fd;
|
||||
int idx = take_free_slot(l, sw, sh, AHB_RGBA8, &wait_fd);
|
||||
if (idx < 0) { log_drop(l); return g_alloc_failed ? -1 : 0; }
|
||||
if (vkp_blit_image(src, l->slots[idx].img, wait_fd) != 0) return -1;
|
||||
*idx = take_free_slot(l, sw, sh, AHB_RGBA8, wait_fd);
|
||||
if (*idx < 0) { log_drop(l); return g_alloc_failed ? -1 : 0; }
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int overlay_shown(struct layer *l, int idx, const int geo[8], int translucent) {
|
||||
if (present_slot(l, idx, geo, NULL, translucent) != 0) return -1;
|
||||
if (!l->first_logged) {
|
||||
l->first_logged = 1;
|
||||
@@ -1228,6 +1302,18 @@ int sc_layer_present_overlay(struct vkp_image *src, const int geo[8], int transl
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sc_layer_present_overlay(struct vkp_image *src, const int geo[8], int translucent) {
|
||||
struct layer *l = layer_of(SC_LAYER_OVERLAY);
|
||||
if (!geo) return -1;
|
||||
int idx;
|
||||
struct vkp_blit blit = {.src = src, .wait_fd = -1};
|
||||
const int taken = overlay_slot(l, src, &idx, &blit.wait_fd);
|
||||
if (taken <= 0) return taken;
|
||||
blit.dst = l->slots[idx].img;
|
||||
if (vkp_blit_images(&blit, 1) != 0) return -1;
|
||||
return overlay_shown(l, idx, geo, translucent);
|
||||
}
|
||||
|
||||
static int hide_layer(struct layer *l) {
|
||||
if (!l->sc || !l->shown || api.state != 1) return 0;
|
||||
ASurfaceTransaction *tx = api.txCreate();
|
||||
|
||||
@@ -4,6 +4,10 @@
|
||||
#include <stdint.h>
|
||||
#include <android/hardware_buffer.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct vkp_image;
|
||||
struct vkp_draw;
|
||||
struct droiddeck_color;
|
||||
@@ -22,7 +26,7 @@ void sc_layer_hdr_symbols(char *out, size_t size);
|
||||
|
||||
|
||||
int sc_layer_present(struct vkp_image *src, int scene_w, int scene_h, const struct vkp_draw *draw,
|
||||
const struct droiddeck_color *color);
|
||||
const struct droiddeck_color *color, const struct vkp_draw *over, int *over_shown);
|
||||
|
||||
int sc_layer_present_pass(const struct vkp_draw *draws, int n, int scene_w, int scene_h);
|
||||
int sc_layer_present_generated(const struct vkp_draw *draws, int n_draws, const struct vkp_hdr_frame *hf,
|
||||
@@ -51,7 +55,16 @@ void sc_layer_window_gone(void);
|
||||
|
||||
void sc_layer_frame_timeline(int64_t present_ns, int64_t deadline_ns, int64_t period_ns);
|
||||
void sc_layer_aim_take(unsigned *next, unsigned *later, unsigned *even);
|
||||
/* The refresh the next game-layer frame is timed for, instead of the layer's own spacing (0: the layer's). */
|
||||
void sc_layer_set_planned(int64_t present_ns);
|
||||
/* The display's frame timeline: the next expected present and the refresh period (0 until known). */
|
||||
void sc_layer_timeline(int64_t *present_ns, int64_t *period_ns);
|
||||
void sc_layer_cadence_info(int64_t *gap_ns, int *group_frames);
|
||||
unsigned sc_layer_frames_take(void);
|
||||
unsigned sc_layer_drops_take(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "effects_chain.h"
|
||||
#include "cardboard.h"
|
||||
#include "framegen_bridge.h"
|
||||
#include "framegen_zerofg.h"
|
||||
#include "hdr_compose.h"
|
||||
#include "blend_pass.h"
|
||||
#include "gpu_busy.h"
|
||||
@@ -20,6 +21,8 @@
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <poll.h>
|
||||
#include <linux/sync_file.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <time.h>
|
||||
#include <pthread.h>
|
||||
#include <stdarg.h>
|
||||
@@ -602,6 +605,10 @@ static void update_map(int scene_w, int scene_h) {
|
||||
float min_y = (float)g_map.ry + g_map.rh - image_h;
|
||||
if (g_map.off_y < min_y) g_map.off_y = min_y;
|
||||
if (g_map.off_y > g_map.ry) g_map.off_y = (float)g_map.ry;
|
||||
} else if (align == VKP_ALIGN_PICTURE_TOP) {
|
||||
g_map.off_y = 0;
|
||||
} else if (align == VKP_ALIGN_PICTURE_BOTTOM) {
|
||||
g_map.off_y = H - image_h;
|
||||
} else {
|
||||
g_map.off_y = (float)g_map.ry + (g_map.rh - image_h) * 0.5f;
|
||||
}
|
||||
@@ -2759,6 +2766,21 @@ static int render_impl(int scene_w, int scene_h, const struct vkp_draw *draws, i
|
||||
pass_n = 1;
|
||||
overlay_start = source_end;
|
||||
}
|
||||
const int upscale_w = (int)(scene_w * g_map.kx + 0.5f);
|
||||
const int upscale_h = (int)(scene_h * g_map.ky + 0.5f);
|
||||
const int post_upscale = fx && fg && !hf && !cb && vkp_effects_upscaling() &&
|
||||
vkp_effects_prepare_generated() &&
|
||||
(upscale_w > input_w || upscale_h > input_h);
|
||||
if (post_upscale) {
|
||||
static int last_input_w, last_input_h, last_output_w, last_output_h;
|
||||
if (input_w != last_input_w || input_h != last_input_h ||
|
||||
upscale_w != last_output_w || upscale_h != last_output_h) {
|
||||
droiddeck_log("framegen", "post-upscale: interpolate %dx%d, spatial filter each present to %dx%d",
|
||||
input_w, input_h, upscale_w, upscale_h);
|
||||
last_input_w = input_w; last_input_h = input_h;
|
||||
last_output_w = upscale_w; last_output_h = upscale_h;
|
||||
}
|
||||
}
|
||||
const int deep = hf && n > 0 && fg && g_swap_is_hdr && !hf->tonemap && vkp_framegen_format_ok(FG_HDR_FMT) &&
|
||||
ensure_img(&g_fgscene, scene_w, scene_h, FG_HDR_FMT,
|
||||
VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT |
|
||||
@@ -2878,6 +2900,7 @@ static int render_impl(int scene_w, int scene_h, const struct vkp_draw *draws, i
|
||||
|
||||
if (!(pass && fx)) release_external_client_draws(cmd, draws, n);
|
||||
int ngen = 0;
|
||||
int history_staged = 0;
|
||||
VkImage gens[VKP_FG_MAX_GENERATIONS] = {VK_NULL_HANDLE};
|
||||
VkImage result = scene_img;
|
||||
int rw = input_w, rh = input_h;
|
||||
@@ -2894,8 +2917,11 @@ static int render_impl(int scene_w, int scene_h, const struct vkp_draw *draws, i
|
||||
if (fx) {
|
||||
int mapped_w = (int)(scene_w * g_map.kx + 0.5f), mapped_h = (int)(scene_h * g_map.ky + 0.5f);
|
||||
if (fg && !vkp_effects_sharpening()) { mapped_w = scene_w; mapped_h = scene_h; }
|
||||
if (post_upscale) { mapped_w = input_w; mapped_h = input_h; }
|
||||
vkp_effects_set_formats(scene_fmt, scene_fmt, hdr_how == 1 || hdr_unconverted);
|
||||
result = vkp_effects_run(cmd, scene_img, input_w, input_h, mapped_w, mapped_h, &rw, &rh);
|
||||
result = post_upscale
|
||||
? vkp_effects_run_before_generated(cmd, scene_img, input_w, input_h, &rw, &rh)
|
||||
: vkp_effects_run(cmd, scene_img, input_w, input_h, mapped_w, mapped_h, &rw, &rh);
|
||||
effects_overlay_draws(cmd, result, rw, rh, scene_w, scene_h,
|
||||
draws ? draws + overlay_start : NULL, n - overlay_start);
|
||||
release_external_client_draws(cmd, draws, n);
|
||||
@@ -2913,12 +2939,19 @@ static int render_impl(int scene_w, int scene_h, const struct vkp_draw *draws, i
|
||||
0, 0, NULL, 0, NULL, 1, &b_general);
|
||||
|
||||
if (fg) {
|
||||
vkp_framegen_set_layer_timing(0);
|
||||
history_staged = 1;
|
||||
ngen = vkp_framegen_run(cmd, result, VK_NULL_HANDLE, rw, rh, scene_fmt, gens);
|
||||
if (ngen < 0) ngen = 0;
|
||||
if (ngen > VKP_FG_MAX_GENERATIONS) ngen = VKP_FG_MAX_GENERATIONS;
|
||||
}
|
||||
|
||||
record_screen_blit(cmd, ngen ? gens[0] : result, rw, rh, scene_w, scene_h, img, blit_filter, cb);
|
||||
VkImage screen = ngen ? gens[0] : result;
|
||||
int screen_w = rw, screen_h = rh;
|
||||
if (post_upscale)
|
||||
screen = vkp_effects_run_generated(cmd, screen, rw, rh, upscale_w, upscale_h,
|
||||
0, &screen_w, &screen_h);
|
||||
record_screen_blit(cmd, screen, screen_w, screen_h, scene_w, scene_h, img, blit_filter, cb);
|
||||
}
|
||||
g_vk.EndCommandBuffer(cmd);
|
||||
|
||||
@@ -2933,7 +2966,10 @@ static int render_impl(int scene_w, int scene_h, const struct vkp_draw *draws, i
|
||||
/* Teardown may have retained this frame's pending work, or
|
||||
* acquire may have reported real device loss. Neither permits
|
||||
* a completion-marker submit or another fence wait. */
|
||||
if (g_dev_state != 1) return -1;
|
||||
if (g_dev_state != 1) {
|
||||
if (history_staged) zfg_discard_history_update();
|
||||
return -1;
|
||||
}
|
||||
droiddeck_log("framegen", "present %d/%d: no swapchain image; the frame ends early", k + 1, presents);
|
||||
pr = VK_ERROR_OUT_OF_DATE_KHR;
|
||||
break;
|
||||
@@ -2942,7 +2978,12 @@ static int render_impl(int scene_w, int scene_h, const struct vkp_draw *draws, i
|
||||
VkCommandBuffer ck = g_cmds[k];
|
||||
g_vk.ResetCommandBuffer(ck, 0);
|
||||
g_vk.BeginCommandBuffer(ck, &bi);
|
||||
record_screen_blit(ck, k < ngen ? gens[k] : result, rw, rh, scene_w, scene_h, img, blit_filter, cb);
|
||||
VkImage screen = k < ngen ? gens[k] : result;
|
||||
int screen_w = rw, screen_h = rh;
|
||||
if (post_upscale)
|
||||
screen = vkp_effects_run_generated(ck, screen, rw, rh, upscale_w, upscale_h,
|
||||
k, &screen_w, &screen_h);
|
||||
record_screen_blit(ck, screen, screen_w, screen_h, scene_w, scene_h, img, blit_filter, cb);
|
||||
g_vk.EndCommandBuffer(ck);
|
||||
}
|
||||
const int last = (k + 1 == presents);
|
||||
@@ -2952,6 +2993,7 @@ static int render_impl(int scene_w, int scene_h, const struct vkp_draw *draws, i
|
||||
if (img >= g_rnd_count || !g_rnds[img]) {
|
||||
droiddeck_log("error", "present: image index %u exceeds semaphore count %u",
|
||||
img, g_rnd_count);
|
||||
if (history_staged) zfg_discard_history_update();
|
||||
destroy_swapchain();
|
||||
return -1;
|
||||
}
|
||||
@@ -2960,12 +3002,17 @@ static int render_impl(int scene_w, int scene_h, const struct vkp_draw *draws, i
|
||||
.pCommandBuffers = &g_cmds[k], .signalSemaphoreCount = 1, .pSignalSemaphores = &g_rnds[img]};
|
||||
VkResult qr = g_vk.QueueSubmit(g_queue, 1, &si, last ? g_fence : VK_NULL_HANDLE);
|
||||
if (qr != VK_SUCCESS) {
|
||||
if (history_staged) zfg_discard_history_update();
|
||||
if (qr == VK_ERROR_DEVICE_LOST) device_lost("submit");
|
||||
else LOGE("present: submit %d/%d failed (%d)", k + 1, presents, (int)qr);
|
||||
if (g_dev_state != -2) destroy_swapchain();
|
||||
return -1;
|
||||
}
|
||||
fence_submitted = last;
|
||||
if (k == 0 && history_staged) {
|
||||
zfg_commit_history_update();
|
||||
history_staged = 0;
|
||||
}
|
||||
VkPresentInfoKHR pi = {.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR, .waitSemaphoreCount = 1,
|
||||
.pWaitSemaphores = &g_rnds[img], .swapchainCount = 1,
|
||||
.pSwapchains = &g_swapchain, .pImageIndices = &img};
|
||||
@@ -2973,21 +3020,38 @@ static int render_impl(int scene_w, int scene_h, const struct vkp_draw *draws, i
|
||||
pr = g_vk.QueuePresentKHR(g_queue, &pi);
|
||||
perf_add(&g_perf.present_ns, &g_perf.present_max_ns, &g_perf.presents, perf_now() - t_pres);
|
||||
if (k < ngen) presented_gen++;
|
||||
if (pr == VK_ERROR_DEVICE_LOST) { device_lost("present"); return -1; }
|
||||
if (pr == VK_ERROR_DEVICE_LOST) {
|
||||
if (history_staged) zfg_discard_history_update();
|
||||
device_lost("present");
|
||||
return -1;
|
||||
}
|
||||
if (pr == VK_ERROR_OUT_OF_DATE_KHR || pr == VK_ERROR_SURFACE_LOST_KHR) break;
|
||||
}
|
||||
if (!fence_submitted) {
|
||||
VkSubmitInfo si = {.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO};
|
||||
VkResult marker = g_vk.QueueSubmit(g_queue, 1, &si, g_fence);
|
||||
if (marker != VK_SUCCESS) {
|
||||
if (history_staged) zfg_discard_history_update();
|
||||
if (marker == VK_ERROR_DEVICE_LOST) device_lost("frame completion submit");
|
||||
else quarantine_pending_work(marker, "frame completion submit");
|
||||
return -1; /* no fence was submitted; never wait on its unsignalled state */
|
||||
}
|
||||
if (history_staged) {
|
||||
zfg_discard_history_update();
|
||||
history_staged = 0;
|
||||
}
|
||||
}
|
||||
VkResult fr = timed_wait(g_fence, UINT64_MAX);
|
||||
if (fr == VK_ERROR_DEVICE_LOST || pr == VK_ERROR_DEVICE_LOST) { device_lost("present"); return -1; }
|
||||
if (fr != VK_SUCCESS) return -1;
|
||||
if (fr == VK_ERROR_DEVICE_LOST || pr == VK_ERROR_DEVICE_LOST) {
|
||||
if (history_staged) zfg_discard_history_update();
|
||||
device_lost("present");
|
||||
return -1;
|
||||
}
|
||||
if (fr != VK_SUCCESS) {
|
||||
if (history_staged) zfg_discard_history_update();
|
||||
return -1;
|
||||
}
|
||||
vkp_effects_release_generated_sources();
|
||||
if (fg) vkp_framegen_presented(presented_gen);
|
||||
if (pr == VK_ERROR_OUT_OF_DATE_KHR || pr == VK_ERROR_SURFACE_LOST_KHR) {
|
||||
droiddeck_log("gpu", "screen surface %s on present: rebuilding the swapchain", vk_result_name(pr));
|
||||
@@ -3133,8 +3197,38 @@ static void blit_to_layer(VkCommandBuffer cmd, VkImage src, VkImageLayout src_la
|
||||
0, 0, NULL, 0, NULL, 1, &release);
|
||||
}
|
||||
|
||||
int vkp_blit_image(struct vkp_image *src, struct vkp_image *dst, int wait_fd) {
|
||||
if (!src || src->blit_dst || !dst || !dst->blit_dst || dev_init() != 0) {
|
||||
static int merge_wait_fds(int a, int b) {
|
||||
if (a < 0) return b;
|
||||
if (b < 0) return a;
|
||||
struct sync_merge_data m = {.name = "droiddeck-layer-copy", .fd2 = b};
|
||||
if (ioctl(a, SYNC_IOC_MERGE, &m) == 0) {
|
||||
close(a);
|
||||
close(b);
|
||||
return m.fence;
|
||||
}
|
||||
struct pollfd p = {.fd = b, .events = POLLIN};
|
||||
int r;
|
||||
do { r = poll(&p, 1, 100); } while (r < 0 && errno == EINTR);
|
||||
close(b);
|
||||
if (r != 0) return a;
|
||||
p.fd = a;
|
||||
do { r = poll(&p, 1, 100); } while (r < 0 && errno == EINTR);
|
||||
close(a);
|
||||
return -2;
|
||||
}
|
||||
|
||||
int vkp_blit_images(const struct vkp_blit *blits, int n) {
|
||||
int wait_fd = -1;
|
||||
for (int i = 0; i < n; i++) {
|
||||
if (wait_fd == -2) { if (blits[i].wait_fd >= 0) close(blits[i].wait_fd); continue; }
|
||||
wait_fd = merge_wait_fds(wait_fd, blits[i].wait_fd);
|
||||
}
|
||||
int valid = n > 0 && wait_fd != -2;
|
||||
for (int i = 0; valid && i < n; i++) {
|
||||
const struct vkp_image *src = blits[i].src, *dst = blits[i].dst;
|
||||
if (!src || src->blit_dst || !dst || !dst->blit_dst) valid = 0;
|
||||
}
|
||||
if (!valid || dev_init() != 0) {
|
||||
if (wait_fd >= 0) close(wait_fd);
|
||||
return -1;
|
||||
}
|
||||
@@ -3147,32 +3241,35 @@ int vkp_blit_image(struct vkp_image *src, struct vkp_image *dst, int wait_fd) {
|
||||
VkCommandBufferBeginInfo bi = {.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
|
||||
.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT};
|
||||
g_vk.BeginCommandBuffer(g_cmd, &bi);
|
||||
stage_linear_dmabuf(g_cmd, src);
|
||||
struct vkp_external_client_barrier_pair src_pair;
|
||||
const int src_external = vkp_external_client_barrier_pair(
|
||||
src->image, g_qfam, foreign_image(src), src->blit_dst, &src_pair);
|
||||
VkImageMemoryBarrier acq = src_external ? src_pair.acquire : (VkImageMemoryBarrier){
|
||||
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, .oldLayout = VK_IMAGE_LAYOUT_UNDEFINED,
|
||||
.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
|
||||
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
||||
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
||||
.image = src->image, .subresourceRange = range, .dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT};
|
||||
if (!src_external) {
|
||||
acq.oldLayout = src->in_general ? VK_IMAGE_LAYOUT_GENERAL : VK_IMAGE_LAYOUT_PREINITIALIZED;
|
||||
acq.newLayout = VK_IMAGE_LAYOUT_GENERAL;
|
||||
acq.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
|
||||
src->in_general = 1;
|
||||
for (int i = 0; i < n; i++) {
|
||||
struct vkp_image *src = blits[i].src, *dst = blits[i].dst;
|
||||
stage_linear_dmabuf(g_cmd, src);
|
||||
struct vkp_external_client_barrier_pair src_pair;
|
||||
const int src_external = vkp_external_client_barrier_pair(
|
||||
src->image, g_qfam, foreign_image(src), src->blit_dst, &src_pair);
|
||||
VkImageMemoryBarrier acq = src_external ? src_pair.acquire : (VkImageMemoryBarrier){
|
||||
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, .oldLayout = VK_IMAGE_LAYOUT_UNDEFINED,
|
||||
.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
|
||||
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
||||
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
||||
.image = src->image, .subresourceRange = range, .dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT};
|
||||
if (!src_external) {
|
||||
acq.oldLayout = src->in_general ? VK_IMAGE_LAYOUT_GENERAL : VK_IMAGE_LAYOUT_PREINITIALIZED;
|
||||
acq.newLayout = VK_IMAGE_LAYOUT_GENERAL;
|
||||
acq.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
|
||||
src->in_general = 1;
|
||||
}
|
||||
g_vk.CmdPipelineBarrier(g_cmd, VK_PIPELINE_STAGE_HOST_BIT | VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
|
||||
VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, NULL, 0, NULL, 1, &acq);
|
||||
int bw = src->w < dst->w ? src->w : dst->w, bh = src->h < dst->h ? src->h : dst->h;
|
||||
VkImageBlit blit = {.srcSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1},
|
||||
.srcOffsets = {{0, 0, 0}, {bw, bh, 1}},
|
||||
.dstSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1},
|
||||
.dstOffsets = {{0, 0, 0}, {bw, bh, 1}}};
|
||||
blit_to_layer(g_cmd, src->image, src_external ? VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL : VK_IMAGE_LAYOUT_GENERAL,
|
||||
dst, &blit, VK_FILTER_NEAREST);
|
||||
release_external_client_image(g_cmd, src);
|
||||
}
|
||||
g_vk.CmdPipelineBarrier(g_cmd, VK_PIPELINE_STAGE_HOST_BIT | VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
|
||||
VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, NULL, 0, NULL, 1, &acq);
|
||||
int bw = src->w < dst->w ? src->w : dst->w, bh = src->h < dst->h ? src->h : dst->h;
|
||||
VkImageBlit blit = {.srcSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1},
|
||||
.srcOffsets = {{0, 0, 0}, {bw, bh, 1}},
|
||||
.dstSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1},
|
||||
.dstOffsets = {{0, 0, 0}, {bw, bh, 1}}};
|
||||
blit_to_layer(g_cmd, src->image, src_external ? VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL : VK_IMAGE_LAYOUT_GENERAL,
|
||||
dst, &blit, VK_FILTER_NEAREST);
|
||||
release_external_client_image(g_cmd, src);
|
||||
g_vk.EndCommandBuffer(g_cmd);
|
||||
|
||||
VkPipelineStageFlags wait_stage = VK_PIPELINE_STAGE_TRANSFER_BIT;
|
||||
@@ -3305,6 +3402,9 @@ static struct {
|
||||
int active;
|
||||
VkImage result;
|
||||
int rw, rh;
|
||||
/* The layer buffers' size: rw x rh, or the spatial filter's output when it runs on each frame after generation. */
|
||||
int ow, oh;
|
||||
int post_upscale;
|
||||
int ngen;
|
||||
VkImage gens[VKP_FG_MAX_GENERATIONS];
|
||||
} g_pass;
|
||||
@@ -3444,10 +3544,29 @@ static int pass_begin_impl(int scene_w, int scene_h, const struct vkp_draw *draw
|
||||
}
|
||||
|
||||
int mapped_w = (int)(scene_w * g_map.kx + 0.5f), mapped_h = (int)(scene_h * g_map.ky + 0.5f);
|
||||
g_pass.post_upscale = generate && !hf && vkp_effects_active() && vkp_effects_upscaling() &&
|
||||
vkp_effects_prepare_generated() && (mapped_w > input_w || mapped_h > input_h);
|
||||
if (g_pass.post_upscale) {
|
||||
static int last_input_w, last_input_h, last_output_w, last_output_h;
|
||||
if (input_w != last_input_w || input_h != last_input_h || mapped_w != last_output_w || mapped_h != last_output_h) {
|
||||
droiddeck_log("framegen", "post-upscale on the display layer: interpolate %dx%d, spatial filter each "
|
||||
"frame to %dx%d", input_w, input_h, mapped_w, mapped_h);
|
||||
last_input_w = input_w; last_input_h = input_h;
|
||||
last_output_w = mapped_w; last_output_h = mapped_h;
|
||||
}
|
||||
}
|
||||
if (generate && !vkp_effects_sharpening()) { mapped_w = scene_w; mapped_h = scene_h; }
|
||||
g_pass.rw = input_w; g_pass.rh = input_h;
|
||||
g_pass.result = vkp_effects_run(cmd, scene_img, input_w, input_h, mapped_w, mapped_h,
|
||||
&g_pass.rw, &g_pass.rh);
|
||||
if (g_pass.post_upscale) {
|
||||
g_pass.ow = (int)(scene_w * g_map.kx + 0.5f);
|
||||
g_pass.oh = (int)(scene_h * g_map.ky + 0.5f);
|
||||
g_pass.result = vkp_effects_run_before_generated(cmd, scene_img, input_w, input_h, &g_pass.rw, &g_pass.rh);
|
||||
} else {
|
||||
g_pass.result = vkp_effects_run(cmd, scene_img, input_w, input_h, mapped_w, mapped_h,
|
||||
&g_pass.rw, &g_pass.rh);
|
||||
g_pass.ow = g_pass.rw;
|
||||
g_pass.oh = g_pass.rh;
|
||||
}
|
||||
effects_overlay_draws(cmd, g_pass.result, g_pass.rw, g_pass.rh, scene_w, scene_h,
|
||||
draws ? draws + overlay_start : NULL, n - overlay_start);
|
||||
release_external_client_draws(cmd, draws, n);
|
||||
@@ -3462,38 +3581,45 @@ static int pass_begin_impl(int scene_w, int scene_h, const struct vkp_draw *draw
|
||||
g_vk.CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
|
||||
VK_PIPELINE_STAGE_TRANSFER_BIT | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
|
||||
0, 0, NULL, 0, NULL, 1, &b);
|
||||
vkp_framegen_set_layer_timing(1);
|
||||
int ngen = vkp_framegen_run(cmd, g_pass.result, VK_NULL_HANDLE, g_pass.rw, g_pass.rh, scene_fmt, g_pass.gens);
|
||||
if (ngen < 0) ngen = 0;
|
||||
g_pass.ngen = ngen > VKP_FG_MAX_GENERATIONS ? VKP_FG_MAX_GENERATIONS : ngen;
|
||||
}
|
||||
g_pass.active = 1;
|
||||
if (rw) *rw = g_pass.rw;
|
||||
if (rh) *rh = g_pass.rh;
|
||||
if (rw) *rw = g_pass.ow;
|
||||
if (rh) *rh = g_pass.oh;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int pass_finish(const VkImage *srcs, VkImageLayout src_layout, struct vkp_image *const *dsts, int n,
|
||||
int wait_fd) {
|
||||
if (!g_pass.active) { if (wait_fd >= 0) close(wait_fd); return -1; }
|
||||
if (!g_pass.active) { zfg_discard_history_update(); if (wait_fd >= 0) close(wait_fd); return -1; }
|
||||
g_pass.active = 0;
|
||||
if (g_dev_state != 1) { if (wait_fd >= 0) close(wait_fd); return -1; }
|
||||
if (g_dev_state != 1) { zfg_discard_history_update(); if (wait_fd >= 0) close(wait_fd); return -1; }
|
||||
VkCommandBuffer cmd = g_cmds[0];
|
||||
for (int i = 0; i < n; i++) {
|
||||
if (dsts[i] && dsts[i]->blit_dst) continue;
|
||||
if (wait_fd >= 0) close(wait_fd);
|
||||
g_vk.EndCommandBuffer(cmd);
|
||||
zfg_discard_history_update();
|
||||
return -1;
|
||||
}
|
||||
const int gpu_wait = take_wait_fd(wait_fd);
|
||||
if (gpu_wait < 0) { g_vk.EndCommandBuffer(cmd); return -1; }
|
||||
if (gpu_wait < 0) { zfg_discard_history_update(); g_vk.EndCommandBuffer(cmd); return -1; }
|
||||
const int post_upscale = g_pass.post_upscale && src_layout == VK_IMAGE_LAYOUT_GENERAL;
|
||||
for (int i = 0; i < n; i++) {
|
||||
struct vkp_image *dst = dsts[i];
|
||||
VkImage src = srcs[i];
|
||||
int sw = g_pass.rw, sh = g_pass.rh;
|
||||
if (post_upscale)
|
||||
src = vkp_effects_run_generated(cmd, src, g_pass.rw, g_pass.rh, g_pass.ow, g_pass.oh, i, &sw, &sh);
|
||||
VkImageBlit blit = {.srcSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1},
|
||||
.srcOffsets = {{0, 0, 0}, {g_pass.rw, g_pass.rh, 1}},
|
||||
.srcOffsets = {{0, 0, 0}, {sw, sh, 1}},
|
||||
.dstSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1},
|
||||
.dstOffsets = {{0, 0, 0}, {dst->w, dst->h, 1}}};
|
||||
blit_to_layer(cmd, srcs[i], src_layout, dst, &blit,
|
||||
(g_pass.rw == dst->w && g_pass.rh == dst->h) ? VK_FILTER_NEAREST : VK_FILTER_LINEAR);
|
||||
blit_to_layer(cmd, src, src_layout, dst, &blit,
|
||||
(sw == dst->w && sh == dst->h) ? VK_FILTER_NEAREST : VK_FILTER_LINEAR);
|
||||
}
|
||||
g_vk.EndCommandBuffer(cmd);
|
||||
|
||||
@@ -3504,13 +3630,17 @@ static int pass_finish(const VkImage *srcs, VkImageLayout src_layout, struct vkp
|
||||
g_vk.ResetFences(g_dev, 1, &g_fence);
|
||||
VkResult qr = g_vk.QueueSubmit(g_queue, 1, &si, g_fence);
|
||||
if (qr != VK_SUCCESS) {
|
||||
zfg_discard_history_update();
|
||||
if (qr == VK_ERROR_DEVICE_LOST) device_lost("layer pass");
|
||||
else LOGE("layer: effects pass submit failed (%d)", (int)qr);
|
||||
return -1;
|
||||
}
|
||||
zfg_commit_history_update();
|
||||
VkResult fr = timed_wait(g_fence, 1000000000ULL);
|
||||
if (fr == VK_ERROR_DEVICE_LOST) { device_lost("layer pass"); return -1; }
|
||||
if (fr != VK_SUCCESS) { LOGE("layer: effects pass fence wait -> %s", vk_result_name(fr)); return -1; }
|
||||
if (post_upscale) vkp_effects_release_generated_sources();
|
||||
vkp_framegen_completed();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -3528,6 +3658,7 @@ int vkp_pass_copy_generated(struct vkp_image *const *dsts, int n, struct vkp_ima
|
||||
}
|
||||
|
||||
void vkp_pass_abort(void) {
|
||||
zfg_discard_history_update();
|
||||
if (!g_pass.active) return;
|
||||
g_pass.active = 0;
|
||||
if (g_dev_state == 1)
|
||||
|
||||
@@ -105,7 +105,11 @@ int vkp_render_hdr(int scene_w, int scene_h, const struct vkp_draw *draws, int n
|
||||
int vkp_pass_begin_hdr(int scene_w, int scene_h, const struct vkp_draw *draws, int n,
|
||||
const struct vkp_hdr_frame *hf, int *rw, int *rh);
|
||||
|
||||
int vkp_blit_image(struct vkp_image *src, struct vkp_image *dst, int wait_fd);
|
||||
struct vkp_blit {
|
||||
struct vkp_image *src, *dst;
|
||||
int wait_fd;
|
||||
};
|
||||
int vkp_blit_images(const struct vkp_blit *blits, int n);
|
||||
int vkp_image_readback(struct vkp_image *src, uint32_t *out, int max_px);
|
||||
int vkp_update_map(int scene_w, int scene_h);
|
||||
int vkp_map_draw(const struct vkp_draw *d, int out[8]);
|
||||
|
||||
@@ -68,6 +68,7 @@ static jmethodID g_on_compositor_frame;
|
||||
static jmethodID g_on_game_program;
|
||||
static jmethodID g_on_pointer_lock;
|
||||
static jmethodID g_on_clipboard;
|
||||
static jmethodID g_on_text_input_fallback;
|
||||
static jmethodID g_on_text_input;
|
||||
static jmethodID g_on_overlay_planes;
|
||||
static jmethodID g_on_refresh_target;
|
||||
@@ -92,6 +93,8 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
|
||||
if ((*env)->ExceptionCheck(env)) { (*env)->ExceptionClear(env); g_on_game_program = NULL; }
|
||||
g_on_pointer_lock = (*env)->GetStaticMethodID(env, g_compositor_cls, "onPointerLock", "(ZII)V");
|
||||
g_on_clipboard = (*env)->GetStaticMethodID(env, g_compositor_cls, "onClipboardText", "([B)V");
|
||||
g_on_text_input_fallback = (*env)->GetStaticMethodID(env, g_compositor_cls, "onTextInputFallback",
|
||||
"([BI)Z");
|
||||
g_on_text_input = (*env)->GetStaticMethodID(env, g_compositor_cls, "onTextInput",
|
||||
"(ZLjava/lang/String;IIII)V");
|
||||
g_on_overlay_planes = (*env)->GetStaticMethodID(env, g_compositor_cls, "onOverlayPlanes", "(I)V");
|
||||
@@ -203,6 +206,20 @@ void droiddeck_on_clipboard_text(const char *utf8, int len) {
|
||||
(*env)->DeleteLocalRef(env, arr);
|
||||
}
|
||||
|
||||
int droiddeck_on_text_input_fallback(const char *utf8, int len, int token) {
|
||||
JNIEnv *env;
|
||||
if (len <= 0 || token <= 0 || !utf8 || !g_compositor_cls || !g_on_text_input_fallback || !(env = thread_env()))
|
||||
return 0;
|
||||
jbyteArray arr = (*env)->NewByteArray(env, len);
|
||||
if (!arr) { (*env)->ExceptionClear(env); return 0; }
|
||||
(*env)->SetByteArrayRegion(env, arr, 0, len, (const jbyte *)utf8);
|
||||
jboolean accepted = (*env)->CallStaticBooleanMethod(env, g_compositor_cls, g_on_text_input_fallback, arr,
|
||||
(jint)token);
|
||||
if ((*env)->ExceptionCheck(env)) { (*env)->ExceptionClear(env); accepted = JNI_FALSE; }
|
||||
(*env)->DeleteLocalRef(env, arr);
|
||||
return accepted == JNI_TRUE ? 1 : 0;
|
||||
}
|
||||
|
||||
void droiddeck_on_text_input(int enabled, const char *program, int x, int y, int w, int h) {
|
||||
JNIEnv *env;
|
||||
if (!g_compositor_cls || !g_on_text_input || !(env = thread_env())) return;
|
||||
@@ -376,6 +393,18 @@ Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeSendKey(
|
||||
droiddeck_wayland_send_key(evdev, state);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeSendKeyOrdered(
|
||||
JNIEnv *env, jclass clazz, jint evdev, jint state) {
|
||||
droiddeck_host_key(evdev, state);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeSelectGameField(
|
||||
JNIEnv *env, jclass clazz, jboolean copy) {
|
||||
droiddeck_host_select_game_field(copy);
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeFocusTakesTouch(
|
||||
JNIEnv *env, jclass clazz) {
|
||||
@@ -807,6 +836,15 @@ Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeTextInputCommit(JNIE
|
||||
free(buf);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeTextInputCommitAndSubmit(
|
||||
JNIEnv *env, jclass clazz, jbyteArray utf8) {
|
||||
int len;
|
||||
char *buf = dup_bytes(env, utf8, &len);
|
||||
if (buf && len) droiddeck_host_text_commit_and_submit(buf, len);
|
||||
free(buf);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeTextInputPreedit(JNIEnv *env, jclass clazz, jbyteArray utf8,
|
||||
jint cursorBegin, jint cursorEnd) {
|
||||
@@ -821,6 +859,12 @@ Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeTextInputDelete(JNIE
|
||||
droiddeck_host_text_delete(before, after);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeCompleteTextInputFallback(
|
||||
JNIEnv *env, jclass clazz, jint token, jint result) {
|
||||
droiddeck_host_text_input_fallback_complete(token, result);
|
||||
}
|
||||
|
||||
extern void adrenotools_set_turbo(bool turbo);
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeSetGpuTurbo(JNIEnv *env, jclass clazz, jboolean on) {
|
||||
@@ -872,3 +916,42 @@ JNIEXPORT jint JNICALL
|
||||
Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeStreamFrames(JNIEnv *env, jclass clazz) {
|
||||
return (jint)droiddeck_stream_frames();
|
||||
}
|
||||
|
||||
|
||||
#ifdef DROIDDECK_FRAME_ACQUIRE_PROBE
|
||||
extern int droiddeck_frame_worker_grant(int owner, pid_t pid, uint64_t expires, const char *path,
|
||||
uint64_t dev, uint64_t ino, uint64_t receipt);
|
||||
extern void droiddeck_frame_worker_revoke(int owner, int pid);
|
||||
#endif
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_droiddeck_launcher_wayland_WaylandCompositor_frameWorkerProbeEnabled(JNIEnv *env, jclass c) {
|
||||
#ifdef DROIDDECK_FRAME_ACQUIRE_PROBE
|
||||
return JNI_TRUE;
|
||||
#else
|
||||
return JNI_FALSE;
|
||||
#endif
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_droiddeck_launcher_wayland_WaylandCompositor_frameWorkerProbeGrant(JNIEnv *env, jclass c,
|
||||
jint owner, jint pid, jlong expires, jstring path, jlong dev, jlong ino, jlong start_ticks) {
|
||||
#ifdef DROIDDECK_FRAME_ACQUIRE_PROBE
|
||||
if (!path || expires <= 0 || ino <= 0 || start_ticks <= 0) return JNI_FALSE;
|
||||
const char *name = (*env)->GetStringUTFChars(env, path, NULL);
|
||||
if (!name) return JNI_FALSE;
|
||||
int granted = droiddeck_frame_worker_grant(owner, pid, (uint64_t)expires, name, (uint64_t)dev, (uint64_t)ino, (uint64_t)start_ticks);
|
||||
(*env)->ReleaseStringUTFChars(env, path, name);
|
||||
return granted ? JNI_TRUE : JNI_FALSE;
|
||||
#else
|
||||
return JNI_FALSE;
|
||||
#endif
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_droiddeck_launcher_wayland_WaylandCompositor_frameWorkerProbeRevoke(JNIEnv *env, jclass c,
|
||||
jint owner, jint pid) {
|
||||
#ifdef DROIDDECK_FRAME_ACQUIRE_PROBE
|
||||
droiddeck_frame_worker_revoke(owner, pid);
|
||||
#endif
|
||||
}
|
||||
@@ -10,6 +10,12 @@
|
||||
#ifndef KEY_DELETE
|
||||
#define KEY_DELETE 111
|
||||
#endif
|
||||
#ifndef KEY_ENTER
|
||||
#define KEY_ENTER 28
|
||||
#endif
|
||||
#ifndef KEY_TAB
|
||||
#define KEY_TAB 15
|
||||
#endif
|
||||
|
||||
static struct wl_display *g_disp;
|
||||
|
||||
@@ -203,16 +209,43 @@ static int32_t utf8_offset(const char *s, size_t len, int chars) {
|
||||
return (int32_t)i;
|
||||
}
|
||||
|
||||
void text_input_host_commit(const char *utf8, size_t len) {
|
||||
static int control_evdev(unsigned char c) {
|
||||
switch (c) {
|
||||
case '\r': case '\n': return KEY_ENTER;
|
||||
case '\b': return KEY_BACKSPACE;
|
||||
case 0x7f: return KEY_DELETE;
|
||||
case '\t': return KEY_TAB;
|
||||
default: return -1;
|
||||
}
|
||||
}
|
||||
|
||||
static int all_controls(const char *utf8, size_t len) {
|
||||
for (size_t i = 0; i < len; i++)
|
||||
if (control_evdev((unsigned char)utf8[i]) < 0) return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int text_input_host_commit(const char *utf8, size_t len) {
|
||||
struct text_input *ti = active_input();
|
||||
if (!ti) {
|
||||
droiddeck_log("text-input", "typed text (%zu chars) dropped: no program accepts text input", utf8_chars(utf8, len));
|
||||
return;
|
||||
droiddeck_log("text-input", "typed text (%zu chars): no program accepts Wayland text input", utf8_chars(utf8, len));
|
||||
return 0;
|
||||
}
|
||||
if (len > 0 && all_controls(utf8, len)) {
|
||||
/* Keep editing keys on the compositor queue so they cannot overtake text commits. */
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
int code = control_evdev((unsigned char)utf8[i]);
|
||||
droiddeck_inject_key(code, 1);
|
||||
droiddeck_inject_key(code, 0);
|
||||
}
|
||||
droiddeck_log("text-input", "injected %zu soft control(s) to %s", len, ti_program(ti));
|
||||
return 1;
|
||||
}
|
||||
if (ti->has_preedit) { zwp_text_input_v3_send_preedit_string(ti->res, "", 0, 0); ti->has_preedit = 0; }
|
||||
zwp_text_input_v3_send_commit_string(ti->res, utf8);
|
||||
zwp_text_input_v3_send_done(ti->res, ti->serial);
|
||||
droiddeck_log("text-input", "committed %zu chars to %s", utf8_chars(utf8, len), ti_program(ti));
|
||||
return 1;
|
||||
}
|
||||
|
||||
void text_input_host_preedit(const char *utf8, size_t len, int cursor_begin, int cursor_end) {
|
||||
|
||||
Reference in new issue
Block a user