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).
269 lines
9.7 KiB
Plaintext
269 lines
9.7 KiB
Plaintext
#version 450
|
|
// Winlator Ludashi Native GPU FSR 3.1 Pass 2: Temporal Super-Resolution Accumulation
|
|
// Runs at full native output resolution (ow x oh) on Adreno GPU (0 NPU watts, 0 extra latency).
|
|
// Combines jitter-aware Lanczos-2 reconstruction over 100% native rw x rh color,
|
|
// 5-tap Catmull-Rom bicubic history reprojection, YCoCg variance-guided AABB clipping
|
|
// (Salvi/AMD FSR 3.1), and motion/disocclusion-aware adaptive temporal accumulation.
|
|
layout(local_size_x = 8, local_size_y = 8) in;
|
|
|
|
layout(set = 0, binding = 0) uniform sampler2D u_color; // native rw x rh game color
|
|
layout(set = 0, binding = 1) uniform sampler2D u_dilated_mv; // rw x rh RG16F dilated UV velocity
|
|
layout(set = 0, binding = 2) uniform sampler2D u_lock_mask; // rw x rh RGBA16F disocclusion/luma
|
|
layout(set = 0, binding = 3) uniform sampler2D u_hist_prev; // ow x oh RGBA16F previous frame (LINEAR)
|
|
layout(set = 0, binding = 4, rgba16f) writeonly uniform image2D u_hist_cur;
|
|
layout(set = 0, binding = 5) uniform sampler2D u_exposure; // optional 1x1 ExposureTexture
|
|
|
|
layout(push_constant) uniform PC {
|
|
vec2 u_jitter;
|
|
vec2 u_mv_scale;
|
|
vec2 u_jitter_cancel;
|
|
float u_expo;
|
|
float u_sharp;
|
|
uint rw;
|
|
uint rh;
|
|
uint ow;
|
|
uint oh;
|
|
uint flags; // bit 3: reset, bit 5: has_exposure_tex
|
|
uint col_base;
|
|
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));
|
|
}
|
|
|
|
const float PI = 3.14159265359;
|
|
|
|
float luma(vec3 c) {
|
|
return dot(max(c, vec3(0.0)), vec3(0.2126, 0.7152, 0.0722));
|
|
}
|
|
|
|
// Karis/Reinhard reversible perceptual compression for artifact-free HDR temporal blending
|
|
vec3 tonemap(vec3 c) {
|
|
c = max(c, vec3(0.0));
|
|
return c / (1.0 + luma(c));
|
|
}
|
|
|
|
vec3 untonemap(vec3 c) {
|
|
c = clamp(c, vec3(0.0), vec3(0.9995));
|
|
return c / max(1.0 - luma(c), 1e-4);
|
|
}
|
|
|
|
vec3 rgbToYCoCg(vec3 c) {
|
|
float co = c.r - c.b;
|
|
float t = c.b + co * 0.5;
|
|
float cg = c.g - t;
|
|
float y = t + cg * 0.5;
|
|
return vec3(y, co, cg);
|
|
}
|
|
|
|
vec3 yCoCgToRgb(vec3 ycc) {
|
|
float t = ycc.x - ycc.z * 0.5;
|
|
float g = ycc.z + t;
|
|
float b = t - ycc.y * 0.5;
|
|
float r = b + ycc.y;
|
|
return max(vec3(r, g, b), vec3(0.0));
|
|
}
|
|
|
|
// Clip ray from history -> current onto YCoCg AABB (crisper than simple clamp, eliminates ghost trails)
|
|
vec3 clipAABB(vec3 aabb_min, vec3 aabb_max, vec3 cur, vec3 hist) {
|
|
vec3 center = 0.5 * (aabb_max + aabb_min);
|
|
vec3 half_ext = 0.5 * (aabb_max - aabb_min) + vec3(1e-5);
|
|
vec3 offset = hist - center;
|
|
vec3 v_unit = offset / half_ext;
|
|
vec3 a_unit = abs(v_unit);
|
|
float ma = max(a_unit.x, max(a_unit.y, a_unit.z));
|
|
if (ma > 1.0) {
|
|
return center + offset / ma;
|
|
}
|
|
return hist;
|
|
}
|
|
|
|
float lanczos2(float x) {
|
|
x = abs(x);
|
|
if (x < 1e-4) return 1.0;
|
|
if (x >= 2.0) return 0.0;
|
|
float px = PI * x;
|
|
return (sin(px) / px) * (sin(px * 0.5) / (px * 0.5));
|
|
}
|
|
|
|
// Fast 5-tap Catmull-Rom bicubic history fetch (Jorge Jimenez / AMD FSR 3.1 style)
|
|
vec4 sampleHistoryCatmullRom(vec2 uv, vec2 tex_size) {
|
|
vec2 pos = uv * tex_size;
|
|
vec2 center = floor(pos - 0.5) + 0.5;
|
|
vec2 f = pos - center;
|
|
vec2 f2 = f * f;
|
|
vec2 f3 = f2 * f;
|
|
|
|
vec2 w0 = f2 - 0.5 * (f3 + f);
|
|
vec2 w1 = 1.5 * f3 - 2.5 * f2 + 1.0;
|
|
vec2 w3 = 0.5 * (f3 - f2);
|
|
vec2 w2 = 1.0 - w0 - w1 - w3;
|
|
|
|
vec2 w12 = w1 + w2;
|
|
vec2 tc0 = (center - 1.0) / tex_size;
|
|
vec2 tc3 = (center + 2.0) / tex_size;
|
|
vec2 tc12 = (center + w2 / max(w12, vec2(1e-5))) / tex_size;
|
|
|
|
vec4 s0 = textureLod(u_hist_prev, vec2(tc12.x, tc0.y), 0.0);
|
|
vec4 s1 = textureLod(u_hist_prev, vec2(tc0.x, tc12.y), 0.0);
|
|
vec4 s2 = textureLod(u_hist_prev, vec2(tc12.x, tc12.y), 0.0);
|
|
vec4 s3 = textureLod(u_hist_prev, vec2(tc3.x, tc12.y), 0.0);
|
|
vec4 s4 = textureLod(u_hist_prev, vec2(tc12.x, tc3.y), 0.0);
|
|
|
|
float cw0 = w12.x * w0.y;
|
|
float cw1 = w0.x * w12.y;
|
|
float cw2 = w12.x * w12.y;
|
|
float cw3 = w3.x * w12.y;
|
|
float cw4 = w12.x * w3.y;
|
|
float wsum = cw0 + cw1 + cw2 + cw3 + cw4;
|
|
|
|
vec4 res = (s0 * cw0 + s1 * cw1 + s2 * cw2 + s3 * cw3 + s4 * cw4) / max(wsum, 1e-5);
|
|
res.rgb = max(res.rgb, vec3(0.0));
|
|
return res;
|
|
}
|
|
|
|
void main() {
|
|
uvec2 tid = gl_GlobalInvocationID.xy;
|
|
if (tid.x >= pc.ow || tid.y >= pc.oh) return;
|
|
|
|
ivec2 col_sz = textureSize(u_color, 0);
|
|
ivec2 c_base = unpackBase(pc.col_base);
|
|
ivec2 c_max = col_sz - ivec2(1);
|
|
ivec2 r_lim = ivec2(int(pc.rw) - 1, int(pc.rh) - 1);
|
|
float eff_expo = getExposure();
|
|
|
|
vec2 out_size = vec2(pc.ow, pc.oh);
|
|
vec2 ren_size = vec2(pc.rw, pc.rh);
|
|
vec2 out_uv = (vec2(tid) + vec2(0.5)) / out_size;
|
|
|
|
// Exact jitter-corrected native render pixel position
|
|
vec2 lr_f = out_uv * ren_size - vec2(0.5) + pc.u_jitter;
|
|
ivec2 lr_c = ivec2(roundEven(lr_f));
|
|
|
|
// Fetch dilated MV and disocclusion mask at nearest native pixel
|
|
ivec2 mv_p = clamp(lr_c, ivec2(0), r_lim);
|
|
vec2 vel = texelFetch(u_dilated_mv, mv_p, 0).xy;
|
|
vec4 lock_info = texelFetch(u_lock_mask, mv_p, 0);
|
|
float disocc = lock_info.g;
|
|
float vel_norm = lock_info.a;
|
|
|
|
// 3x3 Lanczos-2 upsampling + YCoCg statistical moments (m1, m2) + min/max
|
|
vec3 lanc_sum = vec3(0.0);
|
|
float lanc_wsum = 0.0;
|
|
float center_prox = 0.0;
|
|
|
|
vec3 m1 = vec3(0.0);
|
|
vec3 m2 = vec3(0.0);
|
|
vec3 box_min = vec3(1e9);
|
|
vec3 box_max = vec3(-1e9);
|
|
vec3 cross_min = vec3(1e9);
|
|
vec3 cross_max = vec3(-1e9);
|
|
|
|
for (int dy = -1; dy <= 1; ++dy) {
|
|
for (int dx = -1; dx <= 1; ++dx) {
|
|
ivec2 pq = clamp(lr_c + ivec2(dx, dy), ivec2(0), r_lim);
|
|
ivec2 q = clamp(c_base + pq, ivec2(0), c_max);
|
|
vec3 raw_c = safeColor(texelFetch(u_color, q, 0).rgb) * eff_expo;
|
|
vec3 tm = tonemap(raw_c);
|
|
vec3 ycc = rgbToYCoCg(tm);
|
|
|
|
m1 += ycc;
|
|
m2 += ycc * ycc;
|
|
box_min = min(box_min, ycc);
|
|
box_max = max(box_max, ycc);
|
|
if (dx == 0 || dy == 0) {
|
|
cross_min = min(cross_min, ycc);
|
|
cross_max = max(cross_max, ycc);
|
|
}
|
|
|
|
vec2 d = vec2(lr_c + ivec2(dx, dy)) - lr_f;
|
|
float w = lanczos2(d.x) * lanczos2(d.y);
|
|
// Clamp negative Lanczos lobes slightly to avoid ringing on harsh high-contrast UI/edges
|
|
float w_safe = max(w, -0.06);
|
|
lanc_sum += tm * w_safe;
|
|
lanc_wsum += w_safe;
|
|
if (dx == 0 && dy == 0) {
|
|
center_prox = clamp(1.0 - length(d), 0.0, 1.0);
|
|
}
|
|
}
|
|
}
|
|
|
|
vec3 cur_tm = clamp(lanc_sum / max(lanc_wsum, 1e-5), vec3(0.0), vec3(0.9995));
|
|
vec3 cur_ycc = rgbToYCoCg(cur_tm);
|
|
|
|
// Blend 3x3 full neighborhood & 5-tap cross neighborhood (standard FSR/TAA rounded diamond)
|
|
vec3 min_ycc = 0.5 * (box_min + cross_min);
|
|
vec3 max_ycc = 0.5 * (box_max + cross_max);
|
|
// Clamp Lanczos overshoot softly to neighborhood bounds
|
|
cur_ycc = clamp(cur_ycc, box_min, box_max);
|
|
|
|
bool is_reset = (pc.flags & 8u) != 0u;
|
|
vec2 prev_uv = out_uv + vel;
|
|
bool onscreen = prev_uv.x >= 0.0 && prev_uv.x <= 1.0 && prev_uv.y >= 0.0 && prev_uv.y <= 1.0;
|
|
|
|
vec3 out_tm;
|
|
float accum_conf;
|
|
|
|
if (is_reset || !onscreen) {
|
|
out_tm = yCoCgToRgb(cur_ycc);
|
|
accum_conf = 1.0 / 16.0;
|
|
} else {
|
|
vec4 prev_sample = sampleHistoryCatmullRom(prev_uv, out_size);
|
|
vec3 hist_tm = tonemap(safeColor(prev_sample.rgb) * eff_expo);
|
|
vec3 hist_ycc = rgbToYCoCg(hist_tm);
|
|
|
|
// Variance-guided YCoCg clipping (tighter on moving/disoccluded edges -> ZERO trails!)
|
|
vec3 mean = m1 / 9.0;
|
|
vec3 sigma = sqrt(max(m2 / 9.0 - mean * mean, vec3(0.0)));
|
|
float gamma = mix(1.20, 0.75, clamp(max(disocc, vel_norm), 0.0, 1.0));
|
|
vec3 v_min = max(min_ycc, mean - gamma * sigma);
|
|
vec3 v_max = min(max_ycc, mean + gamma * sigma);
|
|
// Ensure valid box around current sample
|
|
v_min = min(v_min, cur_ycc);
|
|
v_max = max(v_max, cur_ycc);
|
|
|
|
vec3 clipped_hist_ycc = clipAABB(v_min, v_max, cur_ycc, hist_ycc);
|
|
|
|
// Detect how strongly history was clipped (indicates disocclusion behind moving object!)
|
|
float clip_dist = length(hist_ycc - clipped_hist_ycc);
|
|
float luma_diff = abs(cur_ycc.x - clipped_hist_ycc.x) / max(cur_ycc.x + clipped_hist_ycc.x, 0.08);
|
|
|
|
// Adaptive temporal blend factor:
|
|
// - Static / subpixel-aligned: converges smoothly (~0.075 - 0.14) for clean AA & detail
|
|
// - Moving / disoccluded / clipped: increases rapidly toward 0.55 - 0.90 to kill trails
|
|
float prev_conf = clamp(prev_sample.a, 1.0 / 16.0, 1.0);
|
|
float base_alpha = max(1.0 / (prev_conf * 16.0 + 1.0), 0.075);
|
|
// Slightly favor fresh native pixels when jitter sample lands close to output pixel center
|
|
base_alpha = mix(base_alpha, min(base_alpha * 1.45, 0.25), center_prox);
|
|
float react = clamp(disocc * 0.75 + clip_dist * 4.5 + luma_diff * 0.25 + vel_norm * 0.18, 0.0, 0.90);
|
|
float alpha = clamp(max(base_alpha, react), 0.075, 1.0);
|
|
|
|
vec3 blended_ycc = mix(clipped_hist_ycc, cur_ycc, alpha);
|
|
out_tm = yCoCgToRgb(blended_ycc);
|
|
accum_conf = clamp(mix(prev_conf + 1.0 / 16.0, 1.0 / 16.0, react), 1.0 / 16.0, 1.0);
|
|
}
|
|
|
|
vec3 out_lin = clamp(untonemap(out_tm) / max(eff_expo, 1e-6), vec3(0.0), vec3(64000.0));
|
|
imageStore(u_hist_cur, ivec2(tid), vec4(out_lin, accum_conf));
|
|
}
|