From 8166366d196f04382fc8263a22348d46bbea7f1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Kanapitsas?= Date: Sat, 7 Nov 2026 19:31:23 +0100 Subject: [PATCH] Report an NVIDIA adapter to shaderapivk by default With the Apple vendor id (0x106b), Source's shaderapivk turns off shadow depth textures (r_flashlightdepthtexture 0, r_flashlightdepthres 0), so dynamic lights cast no shadows on the Metal renderer while OpenGL has them (issue #20). With 0x10de both cvars match OpenGL. P2_D3D9_VENDOR_ID still overrides the default. Co-Authored-By: Claude Opus 5.5 --- docs/d3d9-bridge.md | 5 +++-- runtime/d3d9.c | 6 ++++-- tests/checks_d3d9.c | 4 ++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/docs/d3d9-bridge.md b/docs/d3d9-bridge.md index a44fc8b..da07282 100644 --- a/docs/d3d9-bridge.md +++ b/docs/d3d9-bridge.md @@ -49,8 +49,9 @@ in the environment.) - From the app: the bundled library is used by default; `P2_RENDERER=opengl "~/Applications/Portal 2 Natif.app/Contents/MacOS/launcher"` forces OpenGL. - `P2_D3D9_VENDOR_ID` / `P2_D3D9_DEVICE_ID` (hex): PCI ids handed to the - library for `D3DADAPTER_IDENTIFIER9` (default Apple `106b` / `0000`; Source - keys vendor-specific paths on them). `P2_D3D9_CACHE`: shader/PSO cache + library for `D3DADAPTER_IDENTIFIER9` (default NVIDIA `10de` / `0000`; Source + keys vendor-specific paths on them, and with Apple `106b` it turns off the + shadow depth textures of dynamic lights). `P2_D3D9_CACHE`: shader/PSO cache directory (default `/d3d9metal-cache`). - Memory caps: before `d3d9metal_init` the runtime puts `memory.pageboxPoolCapMB=64;memory.vbibRetentionCapMB=192;memory.vramBudgetMB=1024` diff --git a/runtime/d3d9.c b/runtime/d3d9.c index 730bb60..9f8f17f 100644 --- a/runtime/d3d9.c +++ b/runtime/d3d9.c @@ -237,8 +237,10 @@ static void fill_host(void) { .size = sizeof(D3D9MetalHost), .user = NULL, .metal_layer = host_metal_layer, .alloc_app = host_alloc_app, .free_app = host_free_app, .blocking_begin = host_blocking_begin, .blocking_end = host_blocking_end, - // Apple par défaut : aucune branche propre à un fabricant dans Source. - .vendor_id = env_id("P2_D3D9_VENDOR_ID", 0x106b), .device_id = env_id("P2_D3D9_DEVICE_ID", 0), + // NVIDIA par défaut : avec un fabricant inconnu (Apple, 0x106b), shaderapivk + // désactive les textures de profondeur des ombres dynamiques + // (r_flashlightdepthtexture 0, issue #20). OpenGL les a déjà. + .vendor_id = env_id("P2_D3D9_VENDOR_ID", 0x10de), .device_id = env_id("P2_D3D9_DEVICE_ID", 0), .cache_dir = NULL, }; const char *env = getenv("P2_D3D9_CACHE"), *user = rt_user_root(); diff --git a/tests/checks_d3d9.c b/tests/checks_d3d9.c index 59716de..ae68328 100644 --- a/tests/checks_d3d9.c +++ b/tests/checks_d3d9.c @@ -330,7 +330,7 @@ RT_CHECK(d3d9_bridge_against_fake_native_library) { assert(rt_shim(&c, "Direct3DCreate9") == 1); uint32_t d3d_proxy = c.eax; assert(d3d_proxy && R32(d3d_proxy + 4) == tag(D3D9_IDirect3D9) && R64(d3d_proxy + 8) == (uintptr_t)&d3d); - assert(fake_host && fake_host->vendor_id == 0x106b && fake_host->metal_layer && fake_host->alloc_app); + assert(fake_host && fake_host->vendor_id == 0x10de && fake_host->metal_layer && fake_host->alloc_app); assert(!strcmp(rt_dynamic_import_name(R32(R32(d3d_proxy) + 4 * 16)), "IDirect3D9::CreateDevice")); // D3DADAPTER_IDENTIFIER9 : 1100 octets i386, rien au-delà. @@ -338,7 +338,7 @@ RT_CHECK(d3d9_bridge_against_fake_native_library) { memset(GPTR(id), 0xcc, 1104); assert(CALL(d3d_proxy, IDirect3D9, GetAdapterIdentifier, 0, 0, id).eax == 0); assert(!strcmp((const char *)GPTR(id + 512), "Fake Metal GPU") && R64(id + 1056) == 0x0001000200030004ull); - assert(R32(id + 1064) == 0x106b && R32(id + 1068) == 0x1234 && R8(id + 1095) == 0x5a && R32(id + 1096) == 0xabcd); + assert(R32(id + 1064) == 0x10de && R32(id + 1068) == 0x1234 && R8(id + 1095) == 0x5a && R32(id + 1096) == 0xabcd); assert(R32(id + 1100) == 0xccccccccu); // CreateDevice : D3DPRESENT_PARAMETERS i386 (56 octets, HWND en 0x1c) traduits et réécrits.