Files
d4r/kernels/support/vulkan_write.comp
ayo 694a7a0126 Add experimental native Vulkan DLSS frontend
Implement NGX's Vulkan API over the existing CUDA backend. Compute shaders
pack the game's sampled images into buffers shared with CUDA (device-local
memory exported through the Wine bridge), and a device event in the game's
command buffer holds its queue until the result is written back, keeping
frame age at zero. DLSS reads inputs through pitch-linear textures and its
native output kernel writes the shared buffer directly; input and
completion waits are adaptive.

Make it work across engines: shared buffers are concurrent over every
compute-capable queue family (Indiana Jones records DLSS on async compute),
depth kept in an R32F colour image is accepted under a depth aspect, and the
extension-requirement query allows a null list. Spare buffer sets are
imported on the first frame and never while a frame is pending, since an
import can block on GPU work that is waiting for us; host staging covers any
shortfall.

Fix two exit hazards. A game quitting without NGX shutdown left the GPU
waiting on an event that only a killed thread would set, resetting the ring
10 s later: the bridge now runs a shim hook before teardown and skips all
CUDA destroy/sync calls once Wine is shutting the process down. The shim's
own entry point skips CRT static destructors at process termination, where
locks held by killed threads made the exit spin forever.

Add a Vulkan DLSS harness (dynamic, recreate, discard, invalid, exit,
compute-queue and in-flight modes), staging/depth probes, ABI/config tests,
and an OptiScaler settings overlay for Vulkan games.
2026-10-09 02:57:23 -04:00

31 lines
1.4 KiB
Plaintext

#version 450
#ifndef OUTPUT_FORMAT
#define OUTPUT_FORMAT rgba16f
#endif
layout(local_size_x=8, local_size_y=8) in;
layout(OUTPUT_FORMAT, set=0, binding=0) uniform writeonly image2D destinationImage;
layout(std430, set=0, binding=1) readonly buffer Pixels { uvec2 pixels[]; };
layout(push_constant) uniform Size { uint width; uint height; } size;
// Bit decoding avoids a hardware half conversion that could flush subnormals.
float halfValue(uint h) {
uint sign = (h & 0x8000u) << 16;
uint exponent = (h >> 10) & 31u;
uint mantissa = h & 1023u;
if (exponent == 0u) {
if (mantissa == 0u) return uintBitsToFloat(sign);
int leading = findMSB(mantissa);
return uintBitsToFloat(sign | ((uint(leading) + 103u) << 23) |
((mantissa << uint(23-leading)) & 0x7fffffu));
}
if (exponent == 31u) return uintBitsToFloat(sign | 0x7f800000u | (mantissa << 13));
return uintBitsToFloat(sign | ((exponent + 112u) << 23) | (mantissa << 13));
}
void main() {
uvec2 p = gl_GlobalInvocationID.xy;
if (p.x >= size.width || p.y >= size.height ||
any(greaterThanEqual(ivec2(p), imageSize(destinationImage)))) return;
uvec2 h = pixels[p.y * size.width + p.x];
imageStore(destinationImage, ivec2(p), vec4(halfValue(h.x & 65535u), halfValue(h.x >> 16),
halfValue(h.y & 65535u), halfValue(h.y >> 16)));
}