M2(Vulkan): capture hook via GPA interception + vkCmdCopyImageToBuffer read-back

New vk_hook.cpp inline-hooks the vulkan-1.dll vkGetInstanceProcAddr export and
hands back our wrappers for vkCreateInstance / vkCreateDevice / vkGetDeviceProcAddr
/ vkCreateSwapchainKHR / vkQueuePresentKHR, so a volk-using (loader-bypass) app
resolves our hooks. On present it reads the swap-chain image back with
vkCmdCopyImageToBuffer into a host-visible buffer (same read-back model as
D3D10/D3D9/OpenGL), swizzles BGRA->RGBA, and uploads it into the shared
keyed-mutex texture on a hook-owned D3D11 device. The read-back submit re-chains
the present's wait semaphores (consume the originals, signal our own that the
real present waits on) so capture orders after rendering without double-waiting.

Wired into the video subsystem with a lazy retry (vulkan-1.dll loads late). Hook
links the official Vulkan-Headers (headers only, VK_NO_PROTOTYPES) via the
include dir so the x86 sub-build builds too.

Because Vulkan caches its present pointer at init, late injection can't hook it:
mock_game_test launches the mock **suspended**, injects, resumes, and under
COOP_MOCK_VK_EARLY the mock loads Vulkan and waits so the hook arms first -- then
decodes frames through the hook like the other backends. 15/15 ctest (x64 +
x86); skips cleanly without a Vulkan driver.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-22 12:39:07 +02:00
parent d4a83e75bb
commit dd976979a1
6 changed files with 875 additions and 26 deletions

View File

@@ -24,6 +24,7 @@
#include "d3d9_hook.hpp"
#include "opengl_hook.hpp"
#include "present_hook.hpp"
#include "vk_hook.hpp"
#include "xinput_hook.hpp"
namespace
@@ -73,6 +74,7 @@ DWORD WINAPI worker_thread(LPVOID)
bool audio_installed = false;
bool audio_ring_open = false;
bool video_installed = false;
bool vk_installed = false; // tracked separately: vulkan-1.dll loads lazily, so retry until present
bool mkb_installed = false;
// Each tick, reconcile each subsystem with the host's requested state: install
@@ -143,11 +145,24 @@ DWORD WINAPI worker_thread(LPVOID)
present_ok ? 1 : 0, gl_ok ? 1 : 0, d3d9_ok ? 1 : 0);
}
}
// Vulkan separately: vulkan-1.dll loads lazily (volk dlopens it after start), so the DXGI/
// GL/D3D9 hooks above may install before it exists. Keep trying each tick until it appears.
if (want_video && !vk_installed)
{
vk_installed = coop::hook::install_vk_hooks(g_ipc);
if (vk_installed)
{
video_installed = true; // a Vulkan-only game otherwise has no video hook installed
coop::hook::logf("worker_thread: vulkan video hook installed");
}
}
else if (!want_video && video_installed)
{
coop::hook::remove_present_hooks();
coop::hook::remove_opengl_hooks();
coop::hook::remove_d3d9_hooks();
coop::hook::remove_vk_hooks();
vk_installed = false;
video_installed = false;
coop::hook::logf("worker_thread: video hooks removed (host request)");
}
@@ -259,6 +274,7 @@ BOOL APIENTRY DllMain(HMODULE module, DWORD reason, LPVOID reserved)
coop::hook::remove_present_hooks();
coop::hook::remove_opengl_hooks();
coop::hook::remove_d3d9_hooks();
coop::hook::remove_vk_hooks();
coop::hook::remove_mkb_hooks();
coop::hook::hook_registry_reset();
}