From 7853f64af513381210ab245b7924af7c9e357889 Mon Sep 17 00:00:00 2001 From: Yash Dubey Date: Tue, 24 Nov 2026 09:26:11 +0530 Subject: [PATCH] d3d12_xs_surface: SDK discovery skips a newer driver-kit include folder without the D3D headers --- tests/test_d3d12_xs_surface.py | 27 +++++++++++++++++++++++++++ tools/d3d12_xs_surface.py | 6 ++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/tests/test_d3d12_xs_surface.py b/tests/test_d3d12_xs_surface.py index 274dab600d..1cdd522726 100644 --- a/tests/test_d3d12_xs_surface.py +++ b/tests/test_d3d12_xs_surface.py @@ -81,6 +81,7 @@ def test_sdk_discovery_sorts_versions_numerically(): vdir = os.path.join(include, ver) os.makedirs(os.path.join(vdir, "um")) os.makedirs(os.path.join(vdir, "shared")) + open(os.path.join(vdir, "um", "d3d12.h"), "w").close() with mock.patch.dict(os.environ, {"ProgramFiles(x86)": tmp, "ProgramFiles": tmp}, clear=False): os.environ.pop("WINDOWS_SDK_INCLUDE", None) @@ -93,6 +94,31 @@ def test_sdk_discovery_sorts_versions_numerically(): os.path.join(include, "10.0.100000.0", "shared")), got_shared +def test_sdk_discovery_skips_a_newer_driver_kit_folder(): + # A Windows Driver Kit adds a newer version folder whose um/ holds only driver headers (measured: 43 files in + # 10.0.26100.0 beside a full 10.0.19041.0 on Windows 11); picking it found none of the 83 GUIDs, so the SDK check + # failed instead of using the SDK that is there. + with tempfile.TemporaryDirectory() as tmp: + include = os.path.join(tmp, "Windows Kits", "10", "Include") + sdk = os.path.join(include, "10.0.19041.0") + wdk = os.path.join(include, "10.0.26100.0") + for vdir in (sdk, wdk): + os.makedirs(os.path.join(vdir, "um")) + os.makedirs(os.path.join(vdir, "shared")) + open(os.path.join(sdk, "um", "d3d12.h"), "w").close() + open(os.path.join(wdk, "um", "d3d12umddi.h"), "w").close() + with mock.patch.dict(os.environ, {"ProgramFiles(x86)": tmp, "ProgramFiles": tmp}, clear=False): + os.environ.pop("WINDOWS_SDK_INCLUDE", None) + os.environ.pop("SDK_INCLUDE", None) + got_um, got_shared = S.find_sdk_include() + assert got_um is not None + assert os.path.normcase(got_um) == os.path.normcase(os.path.join(sdk, "um")), got_um + assert os.path.normcase(got_shared) == os.path.normcase(os.path.join(sdk, "shared")), got_shared + # Only the driver kit: no SDK, so the check skips rather than failing on 83 missing GUIDs. + os.remove(os.path.join(sdk, "um", "d3d12.h")) + assert S.find_sdk_include() == (None, None) + + def test_scarab_cross_check(): root = os.environ.get("SCARAB_REF") if not root: @@ -109,6 +135,7 @@ def test_scarab_cross_check(): test_unrecovered_console_iids_stay_outside_the_table() test_sdk_include_override_accepts_a_trailing_separator() test_sdk_discovery_sorts_versions_numerically() + test_sdk_discovery_skips_a_newer_driver_kit_folder() # Call the two optional checks through their real definitions so this runner cannot drift from them; both # raise unittest.SkipTest when their inputs (SDK headers, SCARAB_REF) are absent. for optional in (test_standard_iids_match_sdk, test_scarab_cross_check): diff --git a/tools/d3d12_xs_surface.py b/tools/d3d12_xs_surface.py index 72d7d86cb6..fe54de18c1 100644 --- a/tools/d3d12_xs_surface.py +++ b/tools/d3d12_xs_surface.py @@ -404,7 +404,7 @@ def check_iid_order(): def find_sdk_include(): - """Return (um_dir, shared_dir) for the newest installed Windows SDK, or (None, None).""" + """Return (um_dir, shared_dir) for the newest installed Windows SDK with the D3D headers, or (None, None).""" env = os.environ.get("WINDOWS_SDK_INCLUDE") or os.environ.get("SDK_INCLUDE") if env: candidates = [env] @@ -420,7 +420,9 @@ def find_sdk_include(): path = os.path.normpath(path) # "...\um\" has an empty basename um = path if os.path.basename(path).lower() == "um" else os.path.join(path, "um") shared = os.path.join(os.path.dirname(um), "shared") - if os.path.isdir(um): + # A Windows Driver Kit installs its own version folder (10.0.26100.0 beside an SDK's 10.0.19041.0, say) that + # holds only driver headers; take the newest folder that has the D3D headers, not the newest one there is. + if os.path.isdir(um) and (env or os.path.isfile(os.path.join(um, "d3d12.h"))): name = os.path.basename(os.path.dirname(um)) try: key = (1, tuple(map(int, name.split("."))))