runtime: check vkEnumerateDeviceExtensionProperties results and harden device_proc_or_khr in vulkan13_features #1963

Closed
IlyassRS3 wants to merge 1 commit from upstream-pr/1963 into main
IlyassRS3 commented 2026-11-25 16:51:07 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by IlyassRS3 on 2026-11-25T16:51:07Z.


Claim: RT-VULKAN13-FEATURES-ENUM-AND-PROC-SAFETY (claim comment #7168584905 on #1608).

Fixes (runtime/src/vulkan13_features.h)

  1. Check VkResult on both vkEnumerateDeviceExtensionProperties calls (Vulkan 1.2 / MoltenVK path):
    • Previously both calls ignored their VkResult: a failed count query could leave count uninitialized/poisoned and allocate from it, a count == 0 device issued an unnecessary second call, a failed fill query still inspected extensions, a VK_INCOMPLETE fill dropped extensions instead of retrying, and a short fill (count < extensions.size()) scanned unwritten trailing entries.
    • Now query() returns immediately on any error or count == 0, retries VK_INCOMPLETE up to 4 times, and resizes extensions to the actual returned count.
  2. Harden device_proc_or_khr() and eliminate per-lookup heap allocations:
    • Guard against null get, null name, or empty name (previously dereferenced null).
    • Use a 256-byte stack buffer for appending KHR / EXT (with a single-allocation std::string fallback only for unusually long names > 252 bytes) instead of allocating two temporary std::strings per Vulkan device proc lookup.
  3. Consistent compute_full_subgroups gating on Vulkan 1.3:
    • Gate compute_full_subgroups on subgroup_size_control on Vulkan 1.3 (in both query() and enable()), matching the existing Vulkan 1.2 path.

Verification

  • AI-assisted: yes.
  • GPUs tested: none (host is macOS arm64; no retail files; 0 CMakeLists.txt changes).
  • Expanded runtime/test/vulkan13_features_test.cpp to cover count error (poisoned count), count == 0, fill error, transient VK_INCOMPLETE retry, persistent VK_INCOMPLETE bounded exit, short fill ignoring trailing slots, Vulkan 1.3 compute_full_subgroups gating, null/empty device_proc_or_khr inputs, and long-name heap fallback.
  • Ran vulkan13_features_test cleanly under:
    • clang++ -std=c++20 -O1 -g -fsanitize=address,undefined -Wall -Wextra -Wno-missing-field-initializers -Werror
    • clang++ -std=c++20 -O1 -g -fsanitize=thread -Wall -Wextra -Wno-missing-field-initializers -Werror
    • clang++ -std=c++20 -O2 -Wall -Wextra -Wno-missing-field-initializers -Werror
  • Ran python3 -I scripts/check_no_game_data.py on both files and python3 -I tests/test_text_write_line_endings.py: all passed.
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5495465285 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1963). Originally posted by [IlyassRS3](https://github.com/IlyassRS3) on 2026-11-25T16:51:07Z. --- Claim: `RT-VULKAN13-FEATURES-ENUM-AND-PROC-SAFETY` (claim comment `#7168584905` on #1608). ### Fixes (`runtime/src/vulkan13_features.h`) 1. **Check `VkResult` on both `vkEnumerateDeviceExtensionProperties` calls (Vulkan 1.2 / MoltenVK path)**: - Previously both calls ignored their `VkResult`: a failed count query could leave `count` uninitialized/poisoned and allocate from it, a `count == 0` device issued an unnecessary second call, a failed fill query still inspected `extensions`, a `VK_INCOMPLETE` fill dropped extensions instead of retrying, and a short fill (`count < extensions.size()`) scanned unwritten trailing entries. - Now `query()` returns immediately on any error or `count == 0`, retries `VK_INCOMPLETE` up to 4 times, and resizes `extensions` to the actual returned `count`. 2. **Harden `device_proc_or_khr()` and eliminate per-lookup heap allocations**: - Guard against null `get`, null `name`, or empty `name` (previously dereferenced null). - Use a 256-byte stack buffer for appending `KHR` / `EXT` (with a single-allocation `std::string` fallback only for unusually long names > 252 bytes) instead of allocating two temporary `std::string`s per Vulkan device proc lookup. 3. **Consistent `compute_full_subgroups` gating on Vulkan 1.3**: - Gate `compute_full_subgroups` on `subgroup_size_control` on Vulkan 1.3 (in both `query()` and `enable()`), matching the existing Vulkan 1.2 path. ### Verification - **AI-assisted**: yes. - **GPUs tested**: none (host is macOS arm64; no retail files; 0 `CMakeLists.txt` changes). - Expanded `runtime/test/vulkan13_features_test.cpp` to cover count error (poisoned count), `count == 0`, fill error, transient `VK_INCOMPLETE` retry, persistent `VK_INCOMPLETE` bounded exit, short fill ignoring trailing slots, Vulkan 1.3 `compute_full_subgroups` gating, null/empty `device_proc_or_khr` inputs, and long-name heap fallback. - Ran `vulkan13_features_test` cleanly under: - `clang++ -std=c++20 -O1 -g -fsanitize=address,undefined -Wall -Wextra -Wno-missing-field-initializers -Werror` - `clang++ -std=c++20 -O1 -g -fsanitize=thread -Wall -Wextra -Wno-missing-field-initializers -Werror` - `clang++ -std=c++20 -O2 -Wall -Wextra -Wno-missing-field-initializers -Werror` - Ran `python3 -I scripts/check_no_game_data.py` on both files and `python3 -I tests/test_text_write_line_endings.py`: all passed.
copilot-pull-request-reviewer[bot] commented 2026-11-25 16:51:18 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-25T16:51:18Z.

Review: COMMENTED


Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6061526570 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1963#pullrequestreview-6061526570). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-11-25T16:51:18Z. **Review:** COMMENTED --- Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
MoonEyes commented 2026-11-28 02:51:29 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T02:51:29Z.


Hi @IlyassRS3, thanks for this pull request. It currently conflicts with main (conflicting file(s): runtime/src/vulkan13_features.h), so it carries the needs rebase label. CONTRIBUTING.md asks authors to rebase their branch on main; once it merges cleanly the label goes within the hour, and reviews start with the pull requests that do. Could you update the branch when you have a moment? If you no longer plan to continue with it, please say so here.

AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7232638403 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1963#issuecomment-7232638403). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T02:51:29Z. --- Hi @IlyassRS3, thanks for this pull request. It currently conflicts with `main` (conflicting file(s): `runtime/src/vulkan13_features.h`), so it carries the `needs rebase` label. CONTRIBUTING.md asks authors to rebase their branch on `main`; once it merges cleanly the label goes within the hour, and reviews start with the pull requests that do. Could you update the branch when you have a moment? If you no longer plan to continue with it, please say so here. AI-assisted (Claude Code, Claude Opus 5.5).
aslan2142 commented 2026-12-01 16:40:12 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T16:40:12Z.


Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (d3d12/) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, d3d12/, or general docs), please feel free to reopen it.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7318001169 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1963#issuecomment-7318001169). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T16:40:12Z. --- Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (`d3d12/`) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, `d3d12/`, or general docs), please feel free to reopen it.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!1963
No description provided.