mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-05 20:45:43 +00:00
Layer and bridges updated from Winlator-NeuralScale 71c140d9 (michaelisomer-cyber, GPL-3.0): - full FSR 4.1 on the NPU (S8 graph, U8 fallback), compiled on the device per HTP arch - ghosting fix: blank far depth when a game sends none, binding 11 bound with 62 - FSR 4.1.2 Lite S8/U8 zero-copy graphs - Snapdragon GSR 2 on the GPU (new engine sgsr2_gpu) - D3D11 DLSS through DXVK's interop (nvngx D3D11 entry points) Left out on purpose: upstream's root-only performance/thermal manager, GPU clock floor and bypass charging. Kept from DroidDeck: NPU detection by the app (DROIDDECK_UPSCALE_NPU, any HTP generation incl. the phone's own QNN libraries) instead of upstream's SoC list, DD env names and log tags, Intel XeSS 3 (runtime still fetched from a0ab6b0f, upstream dropped it in cb3ae04e). FSR 4.0 on the NPU is gone upstream; the engine id becomes fsr4_1_full_npu and saved fsr4_0_npu choices map to it. The full-FSR-4-on-Turnip guard is now opt-in (DROIDDECK_UPSCALE_FULL_OFF_ON_TURNIP=1), since upstream's binding-11 fix targets that black frame. Data files re-pinned to 71c140d9 (81 core + 8 NPU, sha256 checked).
98 lines
4.0 KiB
C
98 lines
4.0 KiB
C
// Lightweight non-blocking Vulkan GPU timestamp ring helper for live HUD ms telemetry.
|
|
// Supports optional pause/resume around Sync vkCmdWaitEvents so GPU ms reports active
|
|
// GPU shader time cleanly without counting NPU wait time inside GPU ms.
|
|
#pragma once
|
|
|
|
#include <vulkan/vulkan.h>
|
|
#include <stdint.h>
|
|
#include <string.h>
|
|
#include "fsr4_pipeline.h"
|
|
|
|
#define WL_TIMER_SLOTS 4u
|
|
|
|
typedef struct {
|
|
VkQueryPool pool;
|
|
int enabled;
|
|
uint32_t slot_used[WL_TIMER_SLOTS]; /* 0 = unused, 1 = single (2 ts), 2 = split (4 ts) */
|
|
uint32_t next_slot;
|
|
uint32_t last_us;
|
|
} WlGpuTimer;
|
|
|
|
static inline void wl_gpu_timer_init(WlGpuTimer *t, const WlVkDispatch *vk) {
|
|
memset(t, 0, sizeof *t);
|
|
if (!vk || !vk->has_timestamps || vk->timestamp_period <= 0.0f ||
|
|
!vk->CreateQueryPool || !vk->CmdResetQueryPool ||
|
|
!vk->CmdWriteTimestamp || !vk->GetQueryPoolResults) {
|
|
return;
|
|
}
|
|
VkQueryPoolCreateInfo ci = {
|
|
.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO,
|
|
.queryType = VK_QUERY_TYPE_TIMESTAMP,
|
|
.queryCount = WL_TIMER_SLOTS * 4u,
|
|
};
|
|
if (vk->CreateQueryPool(vk->device, &ci, NULL, &t->pool) == VK_SUCCESS && t->pool) {
|
|
t->enabled = 1;
|
|
}
|
|
}
|
|
|
|
static inline void wl_gpu_timer_destroy(WlGpuTimer *t, const WlVkDispatch *vk) {
|
|
if (t && t->pool && vk && vk->DestroyQueryPool) {
|
|
vk->DestroyQueryPool(vk->device, t->pool, NULL);
|
|
}
|
|
if (t) memset(t, 0, sizeof *t);
|
|
}
|
|
|
|
static inline uint32_t wl_gpu_timer_begin(WlGpuTimer *t, const WlVkDispatch *vk, VkCommandBuffer cb) {
|
|
if (!t || !t->enabled) return 0u;
|
|
uint32_t s = t->next_slot;
|
|
t->next_slot = (t->next_slot + 1u) % WL_TIMER_SLOTS;
|
|
|
|
// Non-blocking read of the oldest completed slot (zero stall)
|
|
uint32_t mode = t->slot_used[s];
|
|
if (mode == 1u) {
|
|
uint64_t ts[2] = {0, 0};
|
|
VkResult r = vk->GetQueryPoolResults(vk->device, t->pool, s * 4u, 2u,
|
|
sizeof ts, ts, sizeof(uint64_t),
|
|
VK_QUERY_RESULT_64_BIT);
|
|
if (r == VK_SUCCESS && ts[1] >= ts[0]) {
|
|
double us = (double)(ts[1] - ts[0]) * (double)vk->timestamp_period * 1e-3;
|
|
if (us >= 0.0 && us < 500000.0) t->last_us = (uint32_t)(us + 0.5);
|
|
}
|
|
} else if (mode == 2u) {
|
|
uint64_t ts[4] = {0, 0, 0, 0};
|
|
VkResult r = vk->GetQueryPoolResults(vk->device, t->pool, s * 4u, 4u,
|
|
sizeof ts, ts, sizeof(uint64_t),
|
|
VK_QUERY_RESULT_64_BIT);
|
|
if (r == VK_SUCCESS && ts[1] >= ts[0] && ts[3] >= ts[2]) {
|
|
double ticks = (double)(ts[1] - ts[0]) + (double)(ts[3] - ts[2]);
|
|
double us = ticks * (double)vk->timestamp_period * 1e-3;
|
|
if (us >= 0.0 && us < 500000.0) t->last_us = (uint32_t)(us + 0.5);
|
|
}
|
|
}
|
|
t->slot_used[s] = 0u;
|
|
vk->CmdResetQueryPool(cb, t->pool, s * 4u, 4u);
|
|
vk->CmdWriteTimestamp(cb, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, t->pool, s * 4u);
|
|
return s;
|
|
}
|
|
|
|
static inline void wl_gpu_timer_pause(WlGpuTimer *t, const WlVkDispatch *vk, VkCommandBuffer cb, uint32_t slot) {
|
|
if (!t || !t->enabled) return;
|
|
vk->CmdWriteTimestamp(cb, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, t->pool, slot * 4u + 1u);
|
|
}
|
|
|
|
static inline void wl_gpu_timer_resume(WlGpuTimer *t, const WlVkDispatch *vk, VkCommandBuffer cb, uint32_t slot) {
|
|
if (!t || !t->enabled) return;
|
|
vk->CmdWriteTimestamp(cb, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, t->pool, slot * 4u + 2u);
|
|
t->slot_used[slot] = 2u;
|
|
}
|
|
|
|
static inline void wl_gpu_timer_end(WlGpuTimer *t, const WlVkDispatch *vk, VkCommandBuffer cb, uint32_t slot) {
|
|
if (!t || !t->enabled) return;
|
|
if (t->slot_used[slot] == 2u) {
|
|
vk->CmdWriteTimestamp(cb, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, t->pool, slot * 4u + 3u);
|
|
} else {
|
|
vk->CmdWriteTimestamp(cb, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, t->pool, slot * 4u + 1u);
|
|
t->slot_used[slot] = 1u;
|
|
}
|
|
}
|