mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-06 04:55:44 +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).
148 lines
5.7 KiB
Plaintext
148 lines
5.7 KiB
Plaintext
#version 450
|
|
// Winlator Ludashi Native GPU FSR 3.1 Pass 1: Prepare & Dilate Motion Vectors
|
|
// Runs at native render resolution (rw x rh) on Adreno GPU.
|
|
// Performs 3x3 closest-depth MV dilation, exact NGX/FFX MV scaling, MVJittered cancellation,
|
|
// and computes depth/velocity discontinuity reactivity to eliminate character ghost trails.
|
|
layout(local_size_x = 8, local_size_y = 8) in;
|
|
|
|
layout(set = 0, binding = 0) uniform sampler2D u_color; // game render color
|
|
layout(set = 0, binding = 1) uniform sampler2D u_depth; // game depth (NEAREST)
|
|
layout(set = 0, binding = 2) uniform sampler2D u_mvec; // game motion vectors (NEAREST)
|
|
layout(set = 0, binding = 3, rg16f) writeonly uniform image2D u_dilated_mv;
|
|
layout(set = 0, binding = 4, rgba16f) writeonly uniform image2D u_lock_mask;
|
|
layout(set = 0, binding = 5) uniform sampler2D u_reactive; // optional reactive / DLSS BiasCurrentColorMask
|
|
layout(set = 0, binding = 6) uniform sampler2D u_exposure; // optional 1x1 ExposureTexture
|
|
|
|
layout(push_constant) uniform PC {
|
|
vec2 u_jitter;
|
|
vec2 u_mv_scale; // raw_mv * u_mv_scale -> normalized UV delta
|
|
vec2 u_jitter_cancel; // normalized UV jitter cancellation
|
|
float u_expo;
|
|
float u_sharp;
|
|
uint rw;
|
|
uint rh;
|
|
uint ow;
|
|
uint oh;
|
|
uint flags; // bit 0: has_depth, 1: depth_inv, 2: disp_res_mv, 3: reset, 4: has_reactive, 5: has_exposure_tex
|
|
uint col_base; // subrect_x | (subrect_y << 16)
|
|
uint dep_base;
|
|
uint mv_base;
|
|
uint react_base;
|
|
uint pad0;
|
|
} pc;
|
|
|
|
ivec2 unpackBase(uint b) {
|
|
return ivec2(int(b & 0xFFFFu), int(b >> 16u));
|
|
}
|
|
|
|
float getExposure() {
|
|
float e = pc.u_expo;
|
|
if ((pc.flags & 32u) != 0u) {
|
|
float te = texelFetch(u_exposure, ivec2(0), 0).r;
|
|
if (!isnan(te) && !isinf(te) && te > 1e-4 && te < 1e4) {
|
|
e *= te;
|
|
}
|
|
}
|
|
return clamp(e, 1e-4, 1e4);
|
|
}
|
|
|
|
vec3 safeColor(vec3 c) {
|
|
if (any(isnan(c)) || any(isinf(c))) return vec3(0.0);
|
|
return clamp(c, vec3(0.0), vec3(64000.0));
|
|
}
|
|
|
|
float luma(vec3 c) {
|
|
return dot(max(c, vec3(0.0)), vec3(0.2126, 0.7152, 0.0722));
|
|
}
|
|
|
|
vec2 fetchRawMV(ivec2 q, ivec2 mv_sz, ivec2 mv_base, ivec2 r_lim) {
|
|
ivec2 mv_q;
|
|
if ((pc.flags & 4u) != 0u) {
|
|
vec2 uv_n = (vec2(q) + vec2(0.5)) / vec2(pc.rw, pc.rh);
|
|
mv_q = clamp(mv_base + ivec2(uv_n * vec2(pc.ow, pc.oh)), ivec2(0), mv_sz - ivec2(1));
|
|
} else {
|
|
mv_q = clamp(mv_base + clamp(q, ivec2(0), r_lim), ivec2(0), mv_sz - ivec2(1));
|
|
}
|
|
vec2 raw = texelFetch(u_mvec, mv_q, 0).xy;
|
|
vec2 vel = raw * pc.u_mv_scale + pc.u_jitter_cancel;
|
|
if (isnan(vel.x) || isnan(vel.y) || isinf(vel.x) || isinf(vel.y) || abs(vel.x) > 4.0 || abs(vel.y) > 4.0) {
|
|
return vec2(0.0);
|
|
}
|
|
return vel;
|
|
}
|
|
|
|
void main() {
|
|
ivec2 p = ivec2(gl_GlobalInvocationID.xy);
|
|
if (p.x >= int(pc.rw) || p.y >= int(pc.rh)) return;
|
|
|
|
ivec2 r_lim = ivec2(int(pc.rw) - 1, int(pc.rh) - 1);
|
|
ivec2 col_sz = textureSize(u_color, 0);
|
|
ivec2 dep_sz = textureSize(u_depth, 0);
|
|
ivec2 mv_sz = textureSize(u_mvec, 0);
|
|
ivec2 c_base = unpackBase(pc.col_base);
|
|
ivec2 d_base = unpackBase(pc.dep_base);
|
|
ivec2 m_base = unpackBase(pc.mv_base);
|
|
ivec2 re_base = unpackBase(pc.react_base);
|
|
|
|
bool has_depth = (pc.flags & 1u) != 0u && dep_sz.x > 1 && dep_sz.y > 1;
|
|
bool dep_inv = (pc.flags & 2u) != 0u;
|
|
|
|
ivec2 best_q = p;
|
|
float center_d = 0.0;
|
|
float best_d = 0.0;
|
|
float far_d = 0.0;
|
|
|
|
if (has_depth) {
|
|
ivec2 d_max = dep_sz - ivec2(1);
|
|
ivec2 dp_c = clamp(d_base + p, ivec2(0), d_max);
|
|
center_d = texelFetch(u_depth, dp_c, 0).r;
|
|
best_d = center_d;
|
|
far_d = center_d;
|
|
best_q = p;
|
|
for (int dy = -1; dy <= 1; ++dy) {
|
|
for (int dx = -1; dx <= 1; ++dx) {
|
|
if (dx == 0 && dy == 0) continue;
|
|
ivec2 pq = clamp(p + ivec2(dx, dy), ivec2(0), r_lim);
|
|
ivec2 q = clamp(d_base + pq, ivec2(0), d_max);
|
|
float d = texelFetch(u_depth, q, 0).r;
|
|
bool closer = dep_inv ? (d > best_d) : (d < best_d);
|
|
if (closer) {
|
|
best_d = d;
|
|
best_q = pq;
|
|
}
|
|
bool farther = dep_inv ? (d < far_d) : (d > far_d);
|
|
if (farther) {
|
|
far_d = d;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
vec2 vel_dilated = fetchRawMV(best_q, mv_sz, m_base, r_lim);
|
|
vec2 vel_center = fetchRawMV(p, mv_sz, m_base, r_lim);
|
|
|
|
// Measure local motion-vector divergence across silhouette boundaries (moving characters vs background)
|
|
float mv_diff_px = length((vel_dilated - vel_center) * vec2(pc.ow, pc.oh));
|
|
float vel_px = length(vel_dilated * vec2(pc.ow, pc.oh));
|
|
float depth_edge = has_depth ? clamp(abs(best_d - far_d) / max(abs(best_d) + abs(far_d), 1e-4) * 4.0, 0.0, 1.0) : 0.0;
|
|
float disocc = clamp(max(mv_diff_px * 0.35, depth_edge * clamp(vel_px * 0.25, 0.0, 1.0)), 0.0, 1.0);
|
|
|
|
// Incorporate game-supplied Reactive / DLSS BiasCurrentColorMask (kills RDR2 hair/foliage/water ghosting!)
|
|
if ((pc.flags & 16u) != 0u) {
|
|
ivec2 re_sz = textureSize(u_reactive, 0);
|
|
if (re_sz.x > 1 && re_sz.y > 1) {
|
|
ivec2 rq = clamp(re_base + p, ivec2(0), re_sz - ivec2(1));
|
|
float react_m = clamp(texelFetch(u_reactive, rq, 0).r, 0.0, 1.0);
|
|
disocc = clamp(max(disocc, react_m), 0.0, 1.0);
|
|
}
|
|
}
|
|
|
|
float eff_expo = getExposure();
|
|
ivec2 col_q = clamp(c_base + p, ivec2(0), col_sz - ivec2(1));
|
|
vec3 col = safeColor(texelFetch(u_color, col_q, 0).rgb) * eff_expo;
|
|
float log_y = log2(1.0 + luma(col));
|
|
|
|
imageStore(u_dilated_mv, p, vec4(vel_dilated, 0.0, 0.0));
|
|
imageStore(u_lock_mask, p, vec4(best_d, disocc, log_y, clamp(vel_px / 16.0, 0.0, 1.0)));
|
|
}
|