Skip to content

vk_pipeline_check: skip incompatible shaders before module creation - #4796

Open
illusionart453-max wants to merge 4 commits into
ItsNotRexed:mainfrom
illusionart453-max:fix/pipeline-module-feature-gate
Open

illusionart453-max wants to merge 4 commits into
ItsNotRexed:mainfrom
illusionart453-max:fix/pipeline-module-feature-gate

Conversation

@illusionart453-max

@illusionart453-max illusionart453-max commented Nov 23, 2026 •

Copy link
Copy Markdown

The checker previously created shader modules before consulting device compatibility, allowing validation errors for shaders it would later skip. Check file open and module size first, then apply the existing feature gate before module creation. Missing, empty, undersized and unaligned files remain module failures instead of successful skips.

The synthetic regression uses a descriptor-free supported compute shader and an unsupported metadata entry. Instance-creation failures now print their VkResult while retaining exit 1. Both GPU tests skip only recognized unavailable-loader/driver/device diagnostics; out-of-memory, initialization errors, an explicitly unmatched LEONIDA_VK_DEVICE filter and real module failures remain failures.

Claim: #4683 (comment)

Validation at 18d0bc0 on Windows 11, RTX 5060, NVIDIA 610.88, MSVC 19.44, RelWithDebInfo, Khronos validation 1.4.363.0:

  • 4/4 feature tests pass with the driver available; no VUIDs in all five checker invocations.
  • Missing ICD: two CPU diagnostic tests pass, two GPU tests skip once each. The prior checker reproduced five assertion failures.
  • All seven index tests and the existing CLI regression pass. Byte compilation, text-line-ending checks and git diff --check pass.
  • The earlier feature-gate negative control creates two modules; this change creates one and skips the unsupported entry before module creation. The four invalid-file regressions failed before the file-preflight fix.

Independent Intel confirmation and fixture suggestion: #4796 (comment). Availability diagnostic/helper follow-up adapted from @l-CatDemon-l's suggested patch, preserving explicit device-filter errors: #4796 (comment).

Integration with #3045 / #3187: preserve file-open and module-size validation first, then retain both this PR's feature gate and that stack's sampled/storage dynamic-indexing guard before shader module creation. Remove the superseded post-module checks so entries are counted once. Dry-merge finding: #4683 (comment). #4811's descriptor sizing is independent.

AI-assisted (Codex). Synthetic inputs only; no game files.

@shdann

shdann commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

At 4ef8f5c0, a missing shader file can produce a successful check. The compatibility test now skips the entry before the checker handles the failed file open.

Create an empty directory named input. Save the following as input/index.json. Leave cs_absent.spv absent.

{"cs_absent":{"stage":"cs","push_constant_bytes":512}}

Run vk_pipeline_check.exe input --jobs 1. I tested on Windows 11 with an RTX 4090 and a Radeon iGPU. Both adapters report a 256-byte limit.

  • PR head: the checker reports one skipped pipeline and zero failed modules. It exits 0.
  • Merge base 98fa503f: the checker reports MODULE FAIL cs_absent. It exits 1.

An index entry with no file should count as a module failure on either adapter. Check the open result and file size before the feature skip. This keeps incompatible modules out of the driver and preserves the missing-file diagnostic. The existing CLI test passes on the PR head.

AI-assisted.

Rechecked at d05b83e. On both adapters, the new feature test passes on the PR and fails on the merge base. It writes both shader files before it runs the checker. The separate missing-file probe above still exits 0 on the PR and 1 on the merge base.

Fix verified at 94c22222. I rebuilt the checker with MSVC. On the RTX 4090 and Radeon iGPU, the original missing-file probe now prints MODULE FAIL cs_absent and exits 1. Both feature tests and the CLI check pass. The previous binary fails all four missing-file and invalid-size cases on each adapter.

The new tests also have a device availability issue. To reproduce on Windows, set LEONIDA_VK_PIPELINE_CHECK to the built checker and set VK_DRIVER_FILES to a nonexistent absolute JSON path in a fresh shell. Run python -I tests/test_vk_pipeline_check_features.py. I get five assertion failures before any shader check runs. The loader cannot create an instance. The checker exits 1 without the diagnostic that the skip check looks for. Please report the unavailable Vulkan instance and have both tests skip for that specific setup failure. A real module failure should still fail the test.

@PingasMech

Copy link
Copy Markdown

Confirmed the early feature check on an Intel UHD 770 (Windows 11, driver 32.0.101.7088, Khronos validation 1.4.363). I compiled the checker from each revision and ran the same 220 repository-owned synthetic shaders with --jobs 1. Both PRs merged cleanly in either order.

Checker Modules created Pipelines built / failed / skipped Validation errors
Main 98fa503f 220 95 / 107 / 18 59
#4796 94c22222 202 95 / 107 / 18 25 (descriptor layouts)
#4811 cb8132be 220 202 / 0 / 18 34 (unsupported shaders)
Both 202 202 / 0 / 18 0

The same 18 shaders were skipped for the same reasons in all four runs. In a two-shader check, main created the cs_f64_add module and raised VUID-VkShaderModuleCreateInfo-pCode-08740 before skipping it. #4796 skipped it before module creation and still built the supported cs_lds pipeline.

One small change would let the new regression test pass independently on Intel. In test_unsupported_entry_never_creates_a_module, set the supported entry to {"stage": "cs", "bindings": []}. Its shader uses no descriptors. Omitting that field sends it through the old shared layout, which exceeds this GPU’s limits. With just that fixture edit, main failed the intended assertion (two modules created), and both feature tests passed on #4796 alone. The missing, empty, short and unaligned file cases already pass as written. With both PRs, the two unmodified feature tests and all seven index tests passed.

AI-assisted. These runs checked pipeline creation.

@kacper-serewis kacper-serewis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent AI-assisted Windows validation at 94c2222 on RTX 5070, driver 616.56. Vulkan loader diagnostics confirmed Khronos validation SDK 1.4.363.0 at instance and device level in all five runs. Supported + metadata-unsupported synthetic compute entries built one module and one pipeline, skipped one, exited 0. Missing, empty, 5-byte and 21-byte files each failed module handling before the capability skip and exited 1. Coverage is synthetic NVIDIA compute only.

@l-CatDemon-l

Copy link
Copy Markdown

Follow-up to @shdann's unavailable-driver reproduction and @PingasMech's descriptor-free fixture suggestion: reproduced at 94c2222279961d3a369089490b24399a52c2b77c, and tested the patch below locally.

With LEONIDA_VK_PIPELINE_CHECK pointing to the built checker and VK_DRIVER_FILES pointing to a nonexistent absolute ICD JSON path, the original feature tests produce five assertion failures before any shader is checked. vkCreateInstance returns VK_ERROR_INCOMPATIBLE_DRIVER, but the checker exits without reporting it.

The patch prints the instance-creation VkResult while preserving exit code 1, and uses a shared availability check in both GPU tests. Only recognized unavailable-driver/device diagnostics become skips; other instance/device failures and actual module failures remain errors. The availability check runs outside subTest, so a missing driver skips the whole GPU test once. It also adds "bindings": [] to the descriptor-free supported entry, as suggested above.

Tested on Windows 11, RTX 4070 Ti, NVIDIA 616.56, native Python 3.13.1, MSVC 19.44:

  • Normal driver: 4/4 feature tests pass, no skips (two GPU tests plus two new CPU diagnostic tests).
  • Missing ICD: 2 CPU tests pass, 2 GPU tests skip, exit 0; the original checker still gives five failures with the updated tests.
  • Missing/empty/short/unaligned shader inputs still report MODULE FAIL and return 1 with Vulkan available.
  • All 7 index tests and the existing CLI regression pass. Resource-hygiene and text-line-ending checks also pass.
  • The CPU diagnostic tests verify that out-of-memory and other instance/device errors are not classified as unavailable hardware. These are mocked subprocess results, not induced OOM conditions.

Synthetic inputs only. The Intel fixture adjustment was tested here on NVIDIA; no independent Intel run.

Patch against 94c2222 (apply with git apply)
diff --git a/runtime/test/vk_pipeline_check.cpp b/runtime/test/vk_pipeline_check.cpp
index 4e59580c..81de5796 100644
--- a/runtime/test/vk_pipeline_check.cpp
+++ b/runtime/test/vk_pipeline_check.cpp
@@ -908,7 +908,10 @@ int main(int argc, char** argv) {
     app.apiVersion = VK_API_VERSION_1_3;
     VkInstanceCreateInfo ici{VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO};
     ici.pApplicationInfo = &app;
-    if (vkCreateInstance(&ici, nullptr, &inst)) return 1;
+    if (VkResult r = vkCreateInstance(&ici, nullptr, &inst); r != VK_SUCCESS) {
+        std::fprintf(stderr, "vkCreateInstance failed (%d)\n", r);
+        return 1;
+    }
     LOADI(vkEnumeratePhysicalDevices); LOADI(vkGetPhysicalDeviceProperties); LOADI(vkCreateDevice);
     LOADI(vkGetPhysicalDeviceProperties2);
     LOADI(vkGetDeviceProcAddr); LOADI(vkEnumerateDeviceExtensionProperties); LOADI(vkGetPhysicalDeviceFeatures2);
diff --git a/tests/test_vk_pipeline_check_features.py b/tests/test_vk_pipeline_check_features.py
index f501e07c..de919ed4 100644
--- a/tests/test_vk_pipeline_check_features.py
+++ b/tests/test_vk_pipeline_check_features.py
@@ -10,6 +10,7 @@ import subprocess
 import sys
 import tempfile
 import unittest
+from unittest.mock import patch
 
 ROOT = Path(__file__).resolve().parents[1]
 sys.path.insert(0, str(ROOT / "tools"))
@@ -42,21 +43,38 @@ class FeatureGateTest(unittest.TestCase):
             self.skipTest("set LEONIDA_VK_PIPELINE_CHECK to a built checker")
         self.binary = binary
 
+    def run_checker(self, root):
+        result = subprocess.run(
+            [str(self.binary), str(root), str(root / "cache.bin"), "--jobs", "1"],
+            capture_output=True, text=True, timeout=60)
+        # VK_ERROR_INCOMPATIBLE_DRIVER (-9) means no usable Vulkan implementation.
+        # Other instance failures (for example out-of-memory) must remain failures.
+        unavailable = any(
+            line == "vkCreateInstance failed (-9)"
+            or line in ("no Vulkan physical devices found", "no Vulkan physical device found")
+            or line.startswith("could not load vkGetInstanceProcAddr from ")
+            or (line.startswith("LEONIDA_VK_DEVICE=") and line.endswith(": no Vulkan physical device matches"))
+            for line in result.stderr.splitlines())
+        if result.returncode == 1 and unavailable:
+            self.skipTest(result.stderr.strip())
+        return result
+
     def test_missing_or_invalid_size_is_failed_before_feature_skip(self):
         for payload in (None, b"", b"short", bytes(21)):
-            with self.subTest(payload=payload), tempfile.TemporaryDirectory() as directory:
+            with tempfile.TemporaryDirectory() as directory:
                 root = Path(directory)
                 if payload is not None:
                     (root / "cs_absent.spv").write_bytes(payload)
                 with (root / "index.json").open("w", encoding="utf-8", newline="\n") as output:
                     json.dump({"cs_absent": {"stage": "cs", "push_constant_bytes": 512}}, output)
-                result = subprocess.run(
-                    [str(self.binary), str(root), str(root / "cache.bin"), "--jobs", "1"],
-                    capture_output=True, text=True, timeout=60)
-                self.assertEqual(result.returncode, 1, result.stdout + result.stderr)
-                self.assertIn("MODULE FAIL cs_absent", result.stdout)
-                self.assertIn("cs: 0 modules ok, 1 failed", result.stdout)
-                self.assertNotIn("SKIPPED cs_absent", result.stdout)
+                # Keep availability checks outside subTest, so a missing device skips
+                # this test once rather than recording a skip for every payload.
+                result = self.run_checker(root)
+                with self.subTest(payload=payload):
+                    self.assertEqual(result.returncode, 1, result.stdout + result.stderr)
+                    self.assertIn("MODULE FAIL cs_absent", result.stdout)
+                    self.assertIn("cs: 0 modules ok, 1 failed", result.stdout)
+                    self.assertNotIn("SKIPPED cs_absent", result.stdout)
 
     def test_unsupported_entry_never_creates_a_module(self):
         with tempfile.TemporaryDirectory() as directory:
@@ -65,17 +83,37 @@ class FeatureGateTest(unittest.TestCase):
             for name in ("supported", "unsupported"):
                 (root / (name + ".spv")).write_bytes(code)
             with (root / "index.json").open("w", encoding="utf-8", newline="\n") as output:
-                json.dump({"supported": {"stage": "cs"},
+                json.dump({"supported": {"stage": "cs", "bindings": []},
                            "unsupported": {"stage": "cs", "float_controls": ["syntheticUnavailable"]}}, output)
-            result = subprocess.run([str(self.binary), str(root), str(root / "cache.bin")],
-                                    capture_output=True, text=True, timeout=60)
-        if "no usable Vulkan" in result.stderr or "no Vulkan" in result.stderr:
-            self.skipTest(result.stderr)
+            result = self.run_checker(root)
         self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
         self.assertIn("cs: 1 modules ok, 0 failed", result.stdout)
         self.assertIn("cs pipelines: 1 ok, 0 failed, 1 skipped", result.stdout)
         self.assertIn("SKIPPED unsupported (unknown float control syntheticUnavailable)", result.stdout)
 
 
+class AvailabilityTest(unittest.TestCase):
+    def run_result(self, result):
+        case = FeatureGateTest()
+        case.binary = Path("unused-checker")
+        with patch.object(subprocess, "run", return_value=result):
+            return case.run_checker(Path("unused-input"))
+
+    def test_unavailable_driver_or_device_skips(self):
+        for message in ("vkCreateInstance failed (-9)", "no Vulkan physical devices found",
+                        "could not load vkGetInstanceProcAddr from vulkan-1.dll",
+                        "LEONIDA_VK_DEVICE=missing: no Vulkan physical device matches"):
+            with self.subTest(message=message), self.assertRaises(unittest.SkipTest):
+                self.run_result(subprocess.CompletedProcess([], 1, "", message + "\n"))
+
+    def test_real_errors_are_not_skipped(self):
+        for message in ("vkCreateInstance failed (-1)", "vkCreateInstance failed (-2)",
+                        "vkCreateInstance failed (-3)", "vkCreateDevice -3",
+                        "MODULE FAIL no Vulkan physical device matches"):
+            with self.subTest(message=message):
+                result = subprocess.CompletedProcess([], 1, "MODULE FAIL cs_bad", message + "\n")
+                self.assertIs(self.run_result(result), result)
+
+
 if __name__ == "__main__":
     unittest.main()

@illusionart453-max

Copy link
Copy Markdown
Author

@shdann @PingasMech @l-CatDemon-l Addressed in 18d0bc0. Thank you for the reproductions and patch. The checker now reports vkCreateInstance's VkResult, both GPU tests use the shared availability check outside subTest, and the supported fixture declares bindings: []. I adapted the suggested patch while keeping an explicitly unmatched LEONIDA_VK_DEVICE filter as a configuration failure rather than a skip.

Windows 11, RTX 5060 / 610.88, MSVC 19.44, Khronos validation 1.4.363.0: all four feature tests pass, with no VUIDs across the five checker invocations. A nonexistent ICD path gives two CPU passes and two GPU skips; the prior checker reproduced five failures. Seven index tests, the CLI regression, byte compilation, line-ending checks and diff check pass. CPU controls retain instance/device errors and actual module failures as failures. Missing/empty/short/unaligned shader inputs still fail before capability skips.

AI-assisted. Synthetic inputs only.

@Ayinaki

Ayinaki commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 18d0bc0 on RTX 5070, driver 616.86, Windows 10.0.26200: pass.

Built vk_pipeline_check (MSVC 14.52, Visual Studio 18 2026, x64, RelWithDebInfo) and ran, with LEONIDA_VK_PIPELINE_CHECK pointing at that binary:

  • python -m pytest tests/test_vk_pipeline_check_features.py -q -> 4 passed, 15 subtests passed. The incompatible-metadata modules are skipped before vkCreateShaderModule (the mock asserts module creation is never reached) and the compatible module still produces a pipeline.
  • ctest -R "vk_pipeline_check_cli|pipeline_cache_snapshot" -> both pass on this device.

(pipeline_cache_file was not run: only the targets for this change were built in this worktree, so its binary was absent — unrelated to the PR.)

@bobcatchris

Copy link
Copy Markdown
Contributor

Tested 18d0bc01a2117eb76dc51a5e78dbbdd31d946293 on Linux with an AMD Radeon Pro V540 (Navi 12; tools/hw_oracle reports gfx1011), RADV Mesa 25.2.8-0ubuntu0.24.04.4, Vulkan device 1.4.318, subgroup 32..64, card pinned with DRI_PRIME=pci-0000_1c:00.0!. Adds a Linux RADV data point to the Windows results in the comments.

Built vk_pipeline_check from this head with GCC 13.3.0 and Khronos Vulkan-Headers 1.4.335 (-DVulkan_INCLUDE_DIR=...), then pointed LEONIDA_VK_PIPELINE_CHECK at it.

  • python3 -I tests/test_vk_pipeline_check_features.py: 4 tests OK (15 subtests).
  • python3 -I tests/test_vk_pipeline_check_index.py: 7 tests OK.
  • python3 -I tests/test_vk_pipeline_check_isolate.py: 6 tests OK.

Counts and pass/fail only; no game data. No code changes.

AI-assisted.

@gertify

gertify commented Nov 23, 2026

Copy link
Copy Markdown

Tested 18d0bc0 on AMD Radeon 610M (RADV, gfx1036, Mesa 26.2.6), CachyOS Linux, LEONIDA_VK_DEVICE=RADV: pass.

  • vk_pipeline_check built fresh at this head.
  • tests/test_vk_pipeline_check_features.py with LEONIDA_VK_PIPELINE_CHECK set: Ran 4 tests, OK, no skips.
  • ctest vk_pipeline_check_cli: 1/1 passed.
  • All tests/test_vk_pipeline_check*.py (features, index, isolate): Ran 17 tests, OK.
  • With LEONIDA_VK_DEVICE=NoSuchDevice the features file fails (failures=5, "no Vulkan physical device matches") instead of skipping.

The missing-ICD case was not run here.

AI-assisted.

@dcastell1

dcastell1 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Code read + CPU tests, 18d0bc0: pass (tests/test_vk_pipeline_check_features.py → 2 passed, 2 skipped, 11 subtests; the skips are the ones that need a real loader).

This is the tool I used for the two giant ScreenProbes modules in #884, and the change is the right one: checking the file and the feature gate before creating the module is what turns a validation error into an honest skip, and keeping missing/empty/undersized/unaligned as module failures keeps the diagnostic. Instance-creation failures printing their VkResult will save the next person the guessing I did.

@memorypressure

Copy link
Copy Markdown

Verified on current main: merges cleanly; the Python half passes its two CPU-verifiable stderr-contract tests and the GPU half self-skips loudly rather than silently passing in this environment. Inspection of the C++ confirms the feature gate now runs before vkCreateShaderModule on every stage, per-stage record_skip covers missing stubs and attachment limits, module-file failures still fail, and only instance/device absence maps to the skip path. A Vulkan CI run of vk_pipeline_check is the remaining evidence — and no CI checks are reported on this branch, so as it stands the binary side never executes on any automated run. Worth triggering before merge. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run).

@Atomic258

Copy link
Copy Markdown
Contributor

Tested 18d0bc0 on Windows Server 2022, CPython 3.13.12: pass

  • python -I tests/test_vk_pipeline_check_features.py -> OK (skipped=2)
  • vk_pipeline_check binary part not run (no build).

git diff --check clean; python -m compileall -q exit 0. No game files, no GPU. AI-assisted (Devin).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.