[PR #1963] runtime: check vkEnumerateDeviceExtensionProperties results and harden device_proc_or_khr in vulkan13_features #1969

Open
opened 2026-11-26 21:19:35 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1963
Author: @IlyassRS3
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: fix/rt-vulkan13-features-enum-and-proc-safety


📝 Commits (1)

  • db6916f runtime: check extension enumeration results and guard device_proc_or_khr in vulkan13_features

📊 Changes

2 files changed (+164 additions, -10 deletions)

View changed files

📝 runtime/src/vulkan13_features.h (+38 -9)
📝 runtime/test/vulkan13_features_test.cpp (+126 -1)

📄 Description

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.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1963 **Author:** [@IlyassRS3](https://github.com/IlyassRS3) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/rt-vulkan13-features-enum-and-proc-safety` --- ### 📝 Commits (1) - [`db6916f`](https://github.com/ubiquitarianism/leonida/commit/db6916f7213d7030b13c023a31a5eddb90d80549) runtime: check extension enumeration results and guard device_proc_or_khr in vulkan13_features ### 📊 Changes **2 files changed** (+164 additions, -10 deletions) <details> <summary>View changed files</summary> 📝 `runtime/src/vulkan13_features.h` (+38 -9) 📝 `runtime/test/vulkan13_features_test.cpp` (+126 -1) </details> ### 📄 Description 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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#1969
No description provided.