mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-05 12:35:42 +00:00
upscale: DLSS frames reach the layer in Streamline/Unreal D3D12 games
Bright Memory: Infinite (Unreal Engine, D3D12, NVIDIA Streamline) now passed NGX's checks but no frame reached the layer. Two causes, fixed here: - The layer recognised the bridge's mailbox by size and the storage bit only, in a 128-entry table; the game's own 8 KB storage buffers filled it first, so the bridge's doorbells were ignored. It now matches the exact usage the bridges create them with (mailbox STORAGE|TRANSFER_DST, marker TRANSFER_DST), keeps 1024 entries and warns once if the table is ever full. - Streamline (sl.interposer) wraps the devices and command lists it creates; vkd3d-proton and DXVK do not know the wrappers. wl_streamline.h asks a wrapper for StreamlineRetrieveBaseInterface (Streamline source/core/sl.interposer/d3d12/d3d12Device.cpp) and the interop calls retry on the wrapped object: device queries, BeginVkCommandBufferInterop/End, GetVulkanResourceInfo1. DROIDDECK_UPSCALE_LOG=1 now also logs the NGX bridge's D3D12 attach and first evaluate (seam ready, images found, command list accepted, dispatch result).
This commit is contained in:
1 parent
772f83cf95
commit
e5d7bddfdb
11 files changed
+230
-28
No files matched your search
@@ -1190,15 +1190,12 @@ def time_now():
|
|||||||
return time.time()
|
return time.time()
|
||||||
|
|
||||||
|
|
||||||
def upscale_xess(prefix, data):
|
def upscale_link(source, target):
|
||||||
"""Intel's XeSS runtime beside the bridge: libxess.dll loads wl_xess_official.dll from system32. A hard link
|
"""target = source's bytes: a hard link when both are on one file system, else a copy. Kept when equal."""
|
||||||
when the prefix is on the same file system as the data, else a copy."""
|
|
||||||
source = os.path.join(data, "xess", UPSCALE_XESS)
|
|
||||||
if not os.path.isfile(source):
|
|
||||||
return "XeSS runtime not downloaded"
|
|
||||||
target = os.path.join(prefix, "pfx", "drive_c", "windows", "system32", UPSCALE_XESS)
|
|
||||||
if os.path.isfile(target) and os.path.getsize(target) == os.path.getsize(source):
|
if os.path.isfile(target) and os.path.getsize(target) == os.path.getsize(source):
|
||||||
return None
|
with open(source, "rb") as a, open(target, "rb") as b:
|
||||||
|
if a.read() == b.read():
|
||||||
|
return
|
||||||
staged = target + ".droiddeck-tmp"
|
staged = target + ".droiddeck-tmp"
|
||||||
if os.path.lexists(staged):
|
if os.path.lexists(staged):
|
||||||
os.unlink(staged)
|
os.unlink(staged)
|
||||||
@@ -1212,6 +1209,42 @@ def upscale_xess(prefix, data):
|
|||||||
break
|
break
|
||||||
dst.write(chunk)
|
dst.write(chunk)
|
||||||
os.replace(staged, target)
|
os.replace(staged, target)
|
||||||
|
|
||||||
|
|
||||||
|
# DLSS games load nvapi64.dll and NGX's core from system32 only (NGXCore FullPath is C:\windows\system32), which
|
||||||
|
# the bridge folder on WINEDLLPATH does not answer. Wine copies the bridges there only when a prefix is created with
|
||||||
|
# the upscaler already on; Bright Memory: Infinite's prefix predates it: "Failed to initialize NVAPI", then NGX
|
||||||
|
# "failed to load C:\windows\system32\_nvngx.dll". With these four in system32 NGX reports "DLSS supported 1".
|
||||||
|
UPSCALE_NGX_FILES = ("nvapi64.dll", "_nvngx.dll", "nvngx.dll", "nvngx_dlss.dll")
|
||||||
|
|
||||||
|
|
||||||
|
def upscale_ngx_files(prefix, bridges, dlss):
|
||||||
|
"""DLSS mode: the bridge's NVAPI and NGX DLLs as files in the prefix's system32. Other modes: our copies go,
|
||||||
|
so a game taken out of DLSS mode no longer sees the NVIDIA stand-in (other files there are left alone)."""
|
||||||
|
system32 = os.path.join(prefix, "pfx", "drive_c", "windows", "system32")
|
||||||
|
if not os.path.isdir(system32):
|
||||||
|
return False
|
||||||
|
for name in UPSCALE_NGX_FILES:
|
||||||
|
source = os.path.join(bridges, "x86_64-windows", name)
|
||||||
|
target = os.path.join(system32, name)
|
||||||
|
if not os.path.isfile(source):
|
||||||
|
continue
|
||||||
|
if dlss:
|
||||||
|
upscale_link(source, target)
|
||||||
|
elif os.path.isfile(target) and os.path.getsize(target) == os.path.getsize(source):
|
||||||
|
with open(source, "rb") as a, open(target, "rb") as b:
|
||||||
|
if a.read() == b.read():
|
||||||
|
os.unlink(target)
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def upscale_xess(prefix, data):
|
||||||
|
"""Intel's XeSS runtime beside the bridge: libxess.dll loads wl_xess_official.dll from system32. A hard link
|
||||||
|
when the prefix is on the same file system as the data, else a copy."""
|
||||||
|
source = os.path.join(data, "xess", UPSCALE_XESS)
|
||||||
|
if not os.path.isfile(source):
|
||||||
|
return "XeSS runtime not downloaded"
|
||||||
|
upscale_link(source, os.path.join(prefix, "pfx", "drive_c", "windows", "system32", UPSCALE_XESS))
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
@@ -1280,6 +1313,11 @@ def upscale_settings(env, prefix):
|
|||||||
notes.append("NVIDIA NGX registry entries added to the prefix (DLSS mode)")
|
notes.append("NVIDIA NGX registry entries added to the prefix (DLSS mode)")
|
||||||
except OSError as error:
|
except OSError as error:
|
||||||
notes.append("NGX registry entries not written (%s)" % error)
|
notes.append("NGX registry entries not written (%s)" % error)
|
||||||
|
try:
|
||||||
|
if prefix:
|
||||||
|
upscale_ngx_files(prefix, bridges, True)
|
||||||
|
except OSError as error:
|
||||||
|
notes.append("NVAPI/NGX DLLs not placed in system32 (%s)" % error)
|
||||||
elif mode == "native":
|
elif mode == "native":
|
||||||
result["DROIDDECK_UPSCALE_SPOOF_DLSS"] = "0"
|
result["DROIDDECK_UPSCALE_SPOOF_DLSS"] = "0"
|
||||||
result["DROIDDECK_UPSCALE_GPU_SPOOF"] = "rdna4"
|
result["DROIDDECK_UPSCALE_GPU_SPOOF"] = "rdna4"
|
||||||
@@ -1288,6 +1326,11 @@ def upscale_settings(env, prefix):
|
|||||||
else:
|
else:
|
||||||
result["DROIDDECK_UPSCALE_SPOOF_DLSS"] = "0"
|
result["DROIDDECK_UPSCALE_SPOOF_DLSS"] = "0"
|
||||||
result["DROIDDECK_UPSCALE_GPU_SPOOF"] = "off"
|
result["DROIDDECK_UPSCALE_GPU_SPOOF"] = "off"
|
||||||
|
if prefix and mode != "dlss":
|
||||||
|
try:
|
||||||
|
upscale_ngx_files(prefix, bridges, False)
|
||||||
|
except OSError:
|
||||||
|
pass
|
||||||
if dxvk:
|
if dxvk:
|
||||||
current = result.get("DXVK_CONFIG", "").strip().rstrip(";").strip()
|
current = result.get("DXVK_CONFIG", "").strip().rstrip(";").strip()
|
||||||
result["DXVK_CONFIG"] = current + "; " + dxvk if current else dxvk
|
result["DXVK_CONFIG"] = current + "; " + dxvk if current else dxvk
|
||||||
|
|||||||
@@ -108,6 +108,28 @@ class UpscalerSettingsTest(unittest.TestCase):
|
|||||||
self.assertEqual("0", env["DROIDDECK_UPSCALE_SIGFIX"])
|
self.assertEqual("0", env["DROIDDECK_UPSCALE_SIGFIX"])
|
||||||
env, _ = MODULE["upscale_settings"]({"DROIDDECK_UPSCALE_MODE": "fsr"}, None)
|
env, _ = MODULE["upscale_settings"]({"DROIDDECK_UPSCALE_MODE": "fsr"}, None)
|
||||||
self.assertNotIn("DROIDDECK_UPSCALE_SIGFIX", env)
|
self.assertNotIn("DROIDDECK_UPSCALE_SIGFIX", env)
|
||||||
|
def test_dlss_mode_puts_nvapi_and_ngx_in_system32_and_other_modes_take_ours_out(self):
|
||||||
|
prefix = tempfile.mkdtemp()
|
||||||
|
self.addCleanup(shutil.rmtree, prefix, True)
|
||||||
|
system32 = Path(prefix, "pfx/drive_c/windows/system32")
|
||||||
|
system32.mkdir(parents=True)
|
||||||
|
for name in ("nvapi64.dll", "_nvngx.dll", "nvngx.dll", "nvngx_dlss.dll"):
|
||||||
|
Path(self.root, "bridges/x86_64-windows", name).write_bytes(b"MZ-v1-" + name.encode())
|
||||||
|
MODULE["upscale_settings"]({"DROIDDECK_UPSCALE_MODE": "dlss"}, prefix)
|
||||||
|
self.assertEqual(b"MZ-v1-nvapi64.dll", (system32 / "nvapi64.dll").read_bytes())
|
||||||
|
self.assertEqual(b"MZ-v1-_nvngx.dll", (system32 / "_nvngx.dll").read_bytes())
|
||||||
|
Path(self.root, "bridges/x86_64-windows/_nvngx.dll").unlink()
|
||||||
|
Path(self.root, "bridges/x86_64-windows/_nvngx.dll").write_bytes(b"MZ-v2-_nvngx.dll")
|
||||||
|
env, _ = MODULE["upscale_settings"]({"DROIDDECK_UPSCALE_MODE": "dlss"}, prefix)
|
||||||
|
self.assertEqual(b"MZ-v2-_nvngx.dll", (system32 / "_nvngx.dll").read_bytes())
|
||||||
|
self.assertEqual("rtx", env["DROIDDECK_UPSCALE_GPU_SPOOF"])
|
||||||
|
(system32 / "nvngx.dll").write_bytes(b"someone else's nvngx")
|
||||||
|
env, _ = MODULE["upscale_settings"]({"DROIDDECK_UPSCALE_MODE": "fsr"}, prefix)
|
||||||
|
self.assertEqual("off", env["DROIDDECK_UPSCALE_GPU_SPOOF"])
|
||||||
|
self.assertFalse((system32 / "nvapi64.dll").exists())
|
||||||
|
self.assertFalse((system32 / "_nvngx.dll").exists())
|
||||||
|
self.assertEqual(b"someone else's nvngx", (system32 / "nvngx.dll").read_bytes())
|
||||||
|
|
||||||
|
|
||||||
def test_a_game_started_on_xess_without_the_runtime_says_so(self):
|
def test_a_game_started_on_xess_without_the_runtime_says_so(self):
|
||||||
prefix = tempfile.mkdtemp()
|
prefix = tempfile.mkdtemp()
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include "wl_streamline.h"
|
||||||
|
|
||||||
// {e2ef5fa5-dc21-4af7-90c4-f67ef6a09323}
|
// {e2ef5fa5-dc21-4af7-90c4-f67ef6a09323}
|
||||||
static const GUID WL_IID_IDXGIVkInteropDevice = {
|
static const GUID WL_IID_IDXGIVkInteropDevice = {
|
||||||
@@ -83,6 +84,13 @@ static inline WlIDXGIVkInteropDevice *wl_query_dxvk_interop_device(void *d3d11_d
|
|||||||
if (obj->lpVtbl && obj->lpVtbl->QueryInterface(d3d11_device, &WL_IID_IDXGIVkInteropDevice, (void **)&out) == S_OK && out) {
|
if (obj->lpVtbl && obj->lpVtbl->QueryInterface(d3d11_device, &WL_IID_IDXGIVkInteropDevice, (void **)&out) == S_OK && out) {
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
void *base = wl_sl_base(d3d11_device);
|
||||||
|
if (base) {
|
||||||
|
IUnkObj *b = (IUnkObj *)base;
|
||||||
|
if (b->lpVtbl->QueryInterface(base, &WL_IID_IDXGIVkInteropDevice, (void **)&out) != S_OK) out = NULL;
|
||||||
|
wl_com_release(base);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,5 +105,12 @@ static inline WlIDXGIVkInteropSurface *wl_query_dxvk_interop_surface(void *d3d11
|
|||||||
if (obj->lpVtbl && obj->lpVtbl->QueryInterface(d3d11_res, &WL_IID_IDXGIVkInteropSurface, (void **)&out) == S_OK && out) {
|
if (obj->lpVtbl && obj->lpVtbl->QueryInterface(d3d11_res, &WL_IID_IDXGIVkInteropSurface, (void **)&out) == S_OK && out) {
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
void *base = wl_sl_base(d3d11_res);
|
||||||
|
if (base) {
|
||||||
|
IUnkObj *b = (IUnkObj *)base;
|
||||||
|
if (b->lpVtbl->QueryInterface(base, &WL_IID_IDXGIVkInteropSurface, (void **)&out) != S_OK) out = NULL;
|
||||||
|
wl_com_release(base);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -473,7 +473,7 @@ static void fill_dx12_img_ref(WlID3D12DXVKInteropDevice1 *interop, WlFsr4ImageRe
|
|||||||
if (!interop || !src || !src->resource) return;
|
if (!interop || !src || !src->resource) return;
|
||||||
UINT64 vk_img = 0, off = 0;
|
UINT64 vk_img = 0, off = 0;
|
||||||
UINT32 vk_fmt = 0;
|
UINT32 vk_fmt = 0;
|
||||||
if (interop->lpVtbl->GetVulkanResourceInfo1(interop, src->resource, &vk_img, &off, &vk_fmt) == S_OK && vk_img) {
|
if (wl_vkd3d_resource_info(interop, src->resource, &vk_img, &off, &vk_fmt) == S_OK && vk_img) {
|
||||||
dst->vk_image = vk_img;
|
dst->vk_image = vk_img;
|
||||||
dst->vk_format = vk_fmt ? vk_fmt : ffx_fmt_to_vk(src->description.format);
|
dst->vk_format = vk_fmt ? vk_fmt : ffx_fmt_to_vk(src->description.format);
|
||||||
dst->vk_layout = ffx_state_to_vk_layout(src->state, is_depth);
|
dst->vk_layout = ffx_state_to_vk_layout(src->state, is_depth);
|
||||||
@@ -558,9 +558,10 @@ __declspec(dllexport) ffxReturnCode_t ffxDispatch(ffxContext *context, const ffx
|
|||||||
|
|
||||||
void *vk_cb = NULL;
|
void *vk_cb = NULL;
|
||||||
int ok = 0;
|
int ok = 0;
|
||||||
if (ctx->dx12_interop->lpVtbl->BeginVkCommandBufferInterop(ctx->dx12_interop, d->commandList, &vk_cb) == S_OK && vk_cb) {
|
void *cl_used = NULL;
|
||||||
|
if (wl_vkd3d_begin_cb(ctx->dx12_interop, d->commandList, &vk_cb, &cl_used)) {
|
||||||
ok = wl_seam_dispatch_or_blit(&ctx->seam, (VkCommandBuffer)vk_cb, &f);
|
ok = wl_seam_dispatch_or_blit(&ctx->seam, (VkCommandBuffer)vk_cb, &f);
|
||||||
ctx->dx12_interop->lpVtbl->EndVkCommandBufferInterop(ctx->dx12_interop, d->commandList);
|
wl_vkd3d_end_cb(ctx->dx12_interop, d->commandList, cl_used);
|
||||||
}
|
}
|
||||||
if (!ok) return FFX_API_RETURN_ERROR_RUNTIME_ERROR;
|
if (!ok) return FFX_API_RETURN_ERROR_RUNTIME_ERROR;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -444,7 +444,7 @@ static void fsr_fill_ref(WlFsr23Ctx *ctx, WlFsr4ImageRef *dst, void *res,
|
|||||||
} else if (ctx->dx12_interop) {
|
} else if (ctx->dx12_interop) {
|
||||||
UINT64 vk_img = 0, off = 0;
|
UINT64 vk_img = 0, off = 0;
|
||||||
UINT32 vk_fmt = 0;
|
UINT32 vk_fmt = 0;
|
||||||
if (ctx->dx12_interop->lpVtbl->GetVulkanResourceInfo1(ctx->dx12_interop, res, &vk_img, &off, &vk_fmt) == S_OK && vk_img) {
|
if (wl_vkd3d_resource_info(ctx->dx12_interop, res, &vk_img, &off, &vk_fmt) == S_OK && vk_img) {
|
||||||
UINT32 layout = fsr_state_to_vk_layout(ffx_state, is_depth);
|
UINT32 layout = fsr_state_to_vk_layout(ffx_state, is_depth);
|
||||||
if (ctx->dx12_interop->lpVtbl->GetVulkanImageLayout) {
|
if (ctx->dx12_interop->lpVtbl->GetVulkanImageLayout) {
|
||||||
UINT32 queried = 0;
|
UINT32 queried = 0;
|
||||||
@@ -481,9 +481,10 @@ static int fsr_submit_frame_ex(WlFsr23Ctx *ctx, void *cmd_list, WlFsr4FrameDesc
|
|||||||
}
|
}
|
||||||
void *vk_cb = NULL;
|
void *vk_cb = NULL;
|
||||||
int ok = 0;
|
int ok = 0;
|
||||||
if (ctx->dx12_interop->lpVtbl->BeginVkCommandBufferInterop(ctx->dx12_interop, cmd_list, &vk_cb) == S_OK && vk_cb) {
|
void *cl_used = NULL;
|
||||||
|
if (wl_vkd3d_begin_cb(ctx->dx12_interop, cmd_list, &vk_cb, &cl_used)) {
|
||||||
ok = wl_seam_dispatch_or_blit(&ctx->seam, (VkCommandBuffer)vk_cb, f);
|
ok = wl_seam_dispatch_or_blit(&ctx->seam, (VkCommandBuffer)vk_cb, f);
|
||||||
ctx->dx12_interop->lpVtbl->EndVkCommandBufferInterop(ctx->dx12_interop, cmd_list);
|
wl_vkd3d_end_cb(ctx->dx12_interop, cmd_list, cl_used);
|
||||||
}
|
}
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
#include "wl_seam_client.h"
|
#include "wl_seam_client.h"
|
||||||
#include "wl_vkd3d_interop.h"
|
#include "wl_vkd3d_interop.h"
|
||||||
@@ -762,6 +763,26 @@ __declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_VULKAN_EvaluateFeature_C(VkComm
|
|||||||
return NVSDK_NGX_VULKAN_EvaluateFeature(cb, h, p, cbk);
|
return NVSDK_NGX_VULKAN_EvaluateFeature(cb, h, p, cbk);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DroidDeck: DROIDDECK_UPSCALE_LOG=1 appends why D3D12/D3D11 frames do or do not reach the layer to the bridge log.
|
||||||
|
static void ngx_log(const char *fmt, ...) {
|
||||||
|
static int on = -1;
|
||||||
|
if (on < 0) on = dd_env_is_on("DROIDDECK_UPSCALE_LOG");
|
||||||
|
if (!on) return;
|
||||||
|
char buf[320];
|
||||||
|
int n = snprintf(buf, sizeof buf, "[ngx] ");
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, fmt);
|
||||||
|
vsnprintf(buf + n, sizeof buf - (size_t)n, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
HANDLE hf = CreateFileA("C:\\windows\\temp\\wl_fsr4_bridge.log", FILE_APPEND_DATA, FILE_SHARE_READ | FILE_SHARE_WRITE,
|
||||||
|
NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||||
|
if (hf == INVALID_HANDLE_VALUE) return;
|
||||||
|
DWORD wr = 0;
|
||||||
|
WriteFile(hf, buf, (DWORD)strlen(buf), &wr, NULL);
|
||||||
|
WriteFile(hf, "\r\n", 2, &wr, NULL);
|
||||||
|
CloseHandle(hf);
|
||||||
|
}
|
||||||
|
|
||||||
// ---- D3D12 NGX API (via vkd3d-proton ID3D12DXVKInteropDevice1 -> same Hexagon NPU Vulkan layer!) ----
|
// ---- D3D12 NGX API (via vkd3d-proton ID3D12DXVKInteropDevice1 -> same Hexagon NPU Vulkan layer!) ----
|
||||||
static void dx12_ngx_attach(void *d3d12_dev) {
|
static void dx12_ngx_attach(void *d3d12_dev) {
|
||||||
ensure_cs();
|
ensure_cs();
|
||||||
@@ -774,6 +795,10 @@ static void dx12_ngx_attach(void *d3d12_dev) {
|
|||||||
if (g_dx12_interop->lpVtbl->GetVulkanHandles(g_dx12_interop, &vk_inst, &vk_phys, &vk_dev) == S_OK && vk_dev) {
|
if (g_dx12_interop->lpVtbl->GetVulkanHandles(g_dx12_interop, &vk_inst, &vk_phys, &vk_dev) == S_OK && vk_dev) {
|
||||||
wl_seam_init(&g_dx12_seam, vk_inst, vk_phys, vk_dev, NULL);
|
wl_seam_init(&g_dx12_seam, vk_inst, vk_phys, vk_dev, NULL);
|
||||||
}
|
}
|
||||||
|
ngx_log("D3D12 attach: device %p, vkd3d interop ok, VkDevice %p, layer seam %s", d3d12_dev, vk_dev,
|
||||||
|
g_dx12_seam.ready ? "ready" : "NOT ready");
|
||||||
|
} else {
|
||||||
|
ngx_log("D3D12 attach: device %p, no vkd3d interop (also not behind a Streamline wrapper)", d3d12_dev);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LeaveCriticalSection(&g_cs);
|
LeaveCriticalSection(&g_cs);
|
||||||
@@ -836,7 +861,7 @@ static void *extract_ngx_dx12_res(WlID3D12DXVKInteropDevice1 *interop, WlFsr4Ima
|
|||||||
if (!res || !interop) return res;
|
if (!res || !interop) return res;
|
||||||
UINT64 vk_img = 0, off = 0;
|
UINT64 vk_img = 0, off = 0;
|
||||||
UINT32 vk_fmt = 0;
|
UINT32 vk_fmt = 0;
|
||||||
if (interop->lpVtbl->GetVulkanResourceInfo1(interop, res, &vk_img, &off, &vk_fmt) == S_OK && vk_img) {
|
if (wl_vkd3d_resource_info(interop, res, &vk_img, &off, &vk_fmt) == S_OK && vk_img) {
|
||||||
dst->vk_image = vk_img;
|
dst->vk_image = vk_img;
|
||||||
dst->vk_format = vk_fmt;
|
dst->vk_format = vk_fmt;
|
||||||
dst->vk_layout = is_depth ? 4u : 1u; /* DEPTH_STENCIL_READ_ONLY or GENERAL */
|
dst->vk_layout = is_depth ? 4u : 1u; /* DEPTH_STENCIL_READ_ONLY or GENERAL */
|
||||||
@@ -866,7 +891,11 @@ __declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_D3D12_EvaluateFeature(void *cmd
|
|||||||
feat_rw = feat->rw; feat_rh = feat->rh; feat_ow = feat->ow; feat_oh = feat->oh;
|
feat_rw = feat->rw; feat_rh = feat->rh; feat_ow = feat->ow; feat_oh = feat->oh;
|
||||||
}
|
}
|
||||||
LeaveCriticalSection(&g_cs);
|
LeaveCriticalSection(&g_cs);
|
||||||
if (!ready || !interop) return NVSDK_NGX_Result_Fail;
|
static int logged_skip = 0, logged_first = 0;
|
||||||
|
if (!ready || !interop) {
|
||||||
|
if (!logged_skip) { logged_skip = 1; ngx_log("D3D12 evaluate skipped: seam %d interop %p", ready, (void *)interop); }
|
||||||
|
return NVSDK_NGX_Result_Fail;
|
||||||
|
}
|
||||||
|
|
||||||
WlFsr4FrameDesc f;
|
WlFsr4FrameDesc f;
|
||||||
memset(&f, 0, sizeof f);
|
memset(&f, 0, sizeof f);
|
||||||
@@ -940,9 +969,17 @@ __declspec(dllexport) NVSDK_NGX_Result NVSDK_NGX_D3D12_EvaluateFeature(void *cmd
|
|||||||
|
|
||||||
void *vk_cb = NULL;
|
void *vk_cb = NULL;
|
||||||
int ok = 0;
|
int ok = 0;
|
||||||
if (interop->lpVtbl->BeginVkCommandBufferInterop(interop, cmdList, &vk_cb) == S_OK && vk_cb) {
|
void *cl_used = NULL;
|
||||||
|
int began = wl_vkd3d_begin_cb(interop, cmdList, &vk_cb, &cl_used);
|
||||||
|
if (began) {
|
||||||
ok = wl_seam_dispatch_or_blit(&g_dx12_seam, (VkCommandBuffer)vk_cb, &f);
|
ok = wl_seam_dispatch_or_blit(&g_dx12_seam, (VkCommandBuffer)vk_cb, &f);
|
||||||
interop->lpVtbl->EndVkCommandBufferInterop(interop, cmdList);
|
wl_vkd3d_end_cb(interop, cmdList, cl_used);
|
||||||
|
}
|
||||||
|
if (!logged_first) {
|
||||||
|
logged_first = 1;
|
||||||
|
ngx_log("D3D12 evaluate: color %llx output %llx %ux%u->%ux%u, command list %s%s, dispatch %d", (unsigned long long)f.color.vk_image,
|
||||||
|
(unsigned long long)f.output.vk_image, f.render_w, f.render_h, f.output_w, f.output_h,
|
||||||
|
began ? "ok" : "REFUSED", (began && cl_used != cmdList) ? " (Streamline wrapper unwrapped)" : "", ok);
|
||||||
}
|
}
|
||||||
return ok ? NVSDK_NGX_Result_Success : NVSDK_NGX_Result_Fail;
|
return ok ? NVSDK_NGX_Result_Success : NVSDK_NGX_Result_Fail;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
// DroidDeck: NVIDIA Streamline (sl.interposer) wraps the D3D11/D3D12 devices and D3D12 command lists it creates
|
||||||
|
// (Unreal Engine games create their device through it). vkd3d-proton and DXVK do not know the wrappers, so their
|
||||||
|
// interop calls fail on them. QueryInterface(StreamlineRetrieveBaseInterface) on a wrapper returns the wrapped object,
|
||||||
|
// AddRef'd (Streamline source/core/sl.interposer/d3d12/d3d12Device.cpp); anything else answers E_NOINTERFACE.
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <windows.h>
|
||||||
|
|
||||||
|
static const GUID WL_IID_StreamlineRetrieveBaseInterface = {
|
||||||
|
0xadec44e2, 0x61f0, 0x45c3, { 0xad, 0x9f, 0x1b, 0x37, 0x37, 0x92, 0x84, 0xff }
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
HRESULT (__stdcall *QueryInterface)(void *This, const GUID *riid, void **ppv);
|
||||||
|
ULONG (__stdcall *AddRef)(void *This);
|
||||||
|
ULONG (__stdcall *Release)(void *This);
|
||||||
|
} WlUnknownVtbl;
|
||||||
|
typedef struct { const WlUnknownVtbl *lpVtbl; } WlUnknown;
|
||||||
|
|
||||||
|
/* The object a Streamline wrapper stands for, AddRef'd; NULL when obj is not a wrapper. */
|
||||||
|
static inline void *wl_sl_base(void *obj) {
|
||||||
|
WlUnknown *u = (WlUnknown *)obj;
|
||||||
|
void *base = NULL;
|
||||||
|
if (!u || !u->lpVtbl) return NULL;
|
||||||
|
if (u->lpVtbl->QueryInterface(obj, &WL_IID_StreamlineRetrieveBaseInterface, &base) != S_OK) return NULL;
|
||||||
|
return base;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void wl_com_release(void *obj) {
|
||||||
|
WlUnknown *u = (WlUnknown *)obj;
|
||||||
|
if (u && u->lpVtbl) u->lpVtbl->Release(obj);
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include "wl_streamline.h"
|
||||||
|
|
||||||
// {39da4e09-bd1c-4198-9fae-86bbe3be41fd}
|
// {39da4e09-bd1c-4198-9fae-86bbe3be41fd}
|
||||||
static const GUID WL_IID_ID3D12DXVKInteropDevice = {
|
static const GUID WL_IID_ID3D12DXVKInteropDevice = {
|
||||||
@@ -56,5 +57,44 @@ static inline WlID3D12DXVKInteropDevice1 *wl_query_vkd3d_interop(void *d3d12_dev
|
|||||||
if (obj->lpVtbl && obj->lpVtbl->QueryInterface(d3d12_device, &WL_IID_ID3D12DXVKInteropDevice1, (void **)&out) == S_OK && out) {
|
if (obj->lpVtbl && obj->lpVtbl->QueryInterface(d3d12_device, &WL_IID_ID3D12DXVKInteropDevice1, (void **)&out) == S_OK && out) {
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
void *base = wl_sl_base(d3d12_device);
|
||||||
|
if (base) {
|
||||||
|
IUnkObj *b = (IUnkObj *)base;
|
||||||
|
if (b->lpVtbl->QueryInterface(base, &WL_IID_ID3D12DXVKInteropDevice1, (void **)&out) != S_OK) out = NULL;
|
||||||
|
wl_com_release(base);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* BeginVkCommandBufferInterop on the command list vkd3d knows (a Streamline wrapper is unwrapped). On success *used is
|
||||||
|
* the list to pass to wl_vkd3d_end_cb, which also drops the unwrapped reference. */
|
||||||
|
static inline int wl_vkd3d_begin_cb(WlID3D12DXVKInteropDevice1 *interop, void *cmd_list, void **vk_cb, void **used) {
|
||||||
|
void *base = wl_sl_base(cmd_list);
|
||||||
|
void *target = base ? base : cmd_list;
|
||||||
|
*vk_cb = NULL;
|
||||||
|
*used = NULL;
|
||||||
|
if (interop->lpVtbl->BeginVkCommandBufferInterop(interop, target, vk_cb) == S_OK && *vk_cb) {
|
||||||
|
*used = target;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (base) wl_com_release(base);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void wl_vkd3d_end_cb(WlID3D12DXVKInteropDevice1 *interop, void *cmd_list, void *used) {
|
||||||
|
interop->lpVtbl->EndVkCommandBufferInterop(interop, used);
|
||||||
|
if (used != cmd_list) wl_com_release(used);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* GetVulkanResourceInfo1, retried on the wrapped object when res is a Streamline wrapper. */
|
||||||
|
static inline HRESULT wl_vkd3d_resource_info(WlID3D12DXVKInteropDevice1 *interop, void *res, UINT64 *vk_handle,
|
||||||
|
UINT64 *buf_offset, UINT32 *vk_format) {
|
||||||
|
HRESULT hr = interop->lpVtbl->GetVulkanResourceInfo1(interop, res, vk_handle, buf_offset, vk_format);
|
||||||
|
if (hr == S_OK && *vk_handle) return hr;
|
||||||
|
void *base = wl_sl_base(res);
|
||||||
|
if (!base) return hr;
|
||||||
|
hr = interop->lpVtbl->GetVulkanResourceInfo1(interop, base, vk_handle, buf_offset, vk_format);
|
||||||
|
wl_com_release(base);
|
||||||
|
return hr;
|
||||||
|
}
|
||||||
@@ -452,9 +452,10 @@ static int wl_xess3_eval_d3d12(WlXess3State *st, WlSeamClient *seam,
|
|||||||
// Bracket with Vulkan timestamp telemetry if interop is available
|
// Bracket with Vulkan timestamp telemetry if interop is available
|
||||||
if (seam && seam->ready && interop) {
|
if (seam && seam->ready && interop) {
|
||||||
void *vk_cb = NULL;
|
void *vk_cb = NULL;
|
||||||
if (interop->lpVtbl->BeginVkCommandBufferInterop(interop, d3d12_cmdlist, &vk_cb) == S_OK && vk_cb) {
|
void *cl_used = NULL;
|
||||||
|
if (wl_vkd3d_begin_cb(interop, d3d12_cmdlist, &vk_cb, &cl_used)) {
|
||||||
wl_seam_telemetry_begin(seam, (VkCommandBuffer)vk_cb);
|
wl_seam_telemetry_begin(seam, (VkCommandBuffer)vk_cb);
|
||||||
interop->lpVtbl->EndVkCommandBufferInterop(interop, d3d12_cmdlist);
|
wl_vkd3d_end_cb(interop, d3d12_cmdlist, cl_used);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -475,9 +476,10 @@ static int wl_xess3_eval_d3d12(WlXess3State *st, WlSeamClient *seam,
|
|||||||
|
|
||||||
if (seam && seam->ready && interop) {
|
if (seam && seam->ready && interop) {
|
||||||
void *vk_cb = NULL;
|
void *vk_cb = NULL;
|
||||||
if (interop->lpVtbl->BeginVkCommandBufferInterop(interop, d3d12_cmdlist, &vk_cb) == S_OK && vk_cb) {
|
void *cl_used = NULL;
|
||||||
|
if (wl_vkd3d_begin_cb(interop, d3d12_cmdlist, &vk_cb, &cl_used)) {
|
||||||
wl_seam_telemetry_end(seam, (VkCommandBuffer)vk_cb, f, cpu_us);
|
wl_seam_telemetry_end(seam, (VkCommandBuffer)vk_cb, f, cpu_us);
|
||||||
interop->lpVtbl->EndVkCommandBufferInterop(interop, d3d12_cmdlist);
|
wl_vkd3d_end_cb(interop, d3d12_cmdlist, cl_used);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
@@ -268,7 +268,7 @@ static void xess_fill_dx12_ref(WlID3D12DXVKInteropDevice1 *interop, WlFsr4ImageR
|
|||||||
if (!interop || !d3d12_res) return;
|
if (!interop || !d3d12_res) return;
|
||||||
UINT64 vk_img = 0, off = 0;
|
UINT64 vk_img = 0, off = 0;
|
||||||
UINT32 vk_fmt = 0;
|
UINT32 vk_fmt = 0;
|
||||||
if (interop->lpVtbl->GetVulkanResourceInfo1(interop, d3d12_res, &vk_img, &off, &vk_fmt) == S_OK && vk_img) {
|
if (wl_vkd3d_resource_info(interop, d3d12_res, &vk_img, &off, &vk_fmt) == S_OK && vk_img) {
|
||||||
UINT32 layout = (d3d12_state == 0x8u) ? 1u : (is_depth ? 4u : 5u);
|
UINT32 layout = (d3d12_state == 0x8u) ? 1u : (is_depth ? 4u : 5u);
|
||||||
if (interop->lpVtbl->GetVulkanImageLayout) {
|
if (interop->lpVtbl->GetVulkanImageLayout) {
|
||||||
UINT32 queried = 0;
|
UINT32 queried = 0;
|
||||||
@@ -649,9 +649,10 @@ __declspec(dllexport) xess_result_t xessD3D12Execute(xess_context_handle_t hCont
|
|||||||
|
|
||||||
void *vk_cb = NULL;
|
void *vk_cb = NULL;
|
||||||
int ok = 0;
|
int ok = 0;
|
||||||
if (c->dx12_interop->lpVtbl->BeginVkCommandBufferInterop(c->dx12_interop, pCommandList, &vk_cb) == S_OK && vk_cb) {
|
void *cl_used = NULL;
|
||||||
|
if (wl_vkd3d_begin_cb(c->dx12_interop, pCommandList, &vk_cb, &cl_used)) {
|
||||||
ok = wl_seam_dispatch_or_blit(&c->seam, (VkCommandBuffer)vk_cb, &f);
|
ok = wl_seam_dispatch_or_blit(&c->seam, (VkCommandBuffer)vk_cb, &f);
|
||||||
c->dx12_interop->lpVtbl->EndVkCommandBufferInterop(c->dx12_interop, pCommandList);
|
wl_vkd3d_end_cb(c->dx12_interop, pCommandList, cl_used);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ok ? XESS_RESULT_SUCCESS : XESS_RESULT_ERROR_DEVICE;
|
return ok ? XESS_RESULT_SUCCESS : XESS_RESULT_ERROR_DEVICE;
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ static inline void *dispatch_key(const void *obj) {
|
|||||||
// ---- Instance & Device tables ----
|
// ---- Instance & Device tables ----
|
||||||
#define MAX_INSTANCES 8
|
#define MAX_INSTANCES 8
|
||||||
#define MAX_DEVICES 16
|
#define MAX_DEVICES 16
|
||||||
#define MAX_TRACK_BUF 128
|
#define MAX_TRACK_BUF 1024
|
||||||
#define MAX_TRACK_IMG 4096
|
#define MAX_TRACK_IMG 4096
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@@ -1603,15 +1603,23 @@ static VkResult VKAPI_CALL hook_vkCreateBuffer(VkDevice device, const VkBufferCr
|
|||||||
if (!down) return VK_ERROR_INITIALIZATION_FAILED;
|
if (!down) return VK_ERROR_INITIALIZATION_FAILED;
|
||||||
VkResult r = down(device, pCreateInfo, pAllocator, pBuffer);
|
VkResult r = down(device, pCreateInfo, pAllocator, pBuffer);
|
||||||
if (r == VK_SUCCESS && d && pCreateInfo && pBuffer) {
|
if (r == VK_SUCCESS && d && pCreateInfo && pBuffer) {
|
||||||
|
// The bridges create the mailbox with exactly STORAGE_BUFFER|TRANSFER_DST and the marker with exactly
|
||||||
|
// TRANSFER_DST (wl_seam_client.h). Matching any buffer with those bits let a game's own 8 KB storage buffers
|
||||||
|
// fill the table before the bridge's (Bright Memory: Infinite, D3D12: DLSS frames never reached the layer).
|
||||||
int kind = 0;
|
int kind = 0;
|
||||||
if (pCreateInfo->size == WLFSR4_MAILBOX_BYTES && (pCreateInfo->usage & VK_BUFFER_USAGE_STORAGE_BUFFER_BIT))
|
if (pCreateInfo->size == WLFSR4_MAILBOX_BYTES &&
|
||||||
|
pCreateInfo->usage == (VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT))
|
||||||
kind = 1;
|
kind = 1;
|
||||||
else if (pCreateInfo->size == WLFSR4_MARKER_BYTES && (pCreateInfo->usage & VK_BUFFER_USAGE_TRANSFER_DST_BIT))
|
else if (pCreateInfo->size == WLFSR4_MARKER_BYTES && pCreateInfo->usage == VK_BUFFER_USAGE_TRANSFER_DST_BIT)
|
||||||
kind = 2;
|
kind = 2;
|
||||||
if (kind) {
|
if (kind) {
|
||||||
|
static int full_logged = 0;
|
||||||
pthread_mutex_lock(&g_mu);
|
pthread_mutex_lock(&g_mu);
|
||||||
if (d->nbufs < MAX_TRACK_BUF) {
|
if (d->nbufs < MAX_TRACK_BUF) {
|
||||||
d->bufs[d->nbufs++] = (SeamBufEnt){*pBuffer, VK_NULL_HANDLE, NULL, pCreateInfo->size, pCreateInfo->usage, kind};
|
d->bufs[d->nbufs++] = (SeamBufEnt){*pBuffer, VK_NULL_HANDLE, NULL, pCreateInfo->size, pCreateInfo->usage, kind};
|
||||||
|
} else if (!full_logged) {
|
||||||
|
full_logged = 1;
|
||||||
|
F4_LOGW("seam buffer table full (%d): a bridge buffer is not tracked", MAX_TRACK_BUF);
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&g_mu);
|
pthread_mutex_unlock(&g_mu);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user