Skip to content

GH-674 Check if Vulkan is supported before attempting to Initialize#1205

Open
JoltedJon wants to merge 3 commits intoRedot-Engine:masterfrom
JoltedJon:GH-674
Open

GH-674 Check if Vulkan is supported before attempting to Initialize#1205
JoltedJon wants to merge 3 commits intoRedot-Engine:masterfrom
JoltedJon:GH-674

Conversation

@JoltedJon
Copy link
Contributor

@JoltedJon JoltedJon commented Mar 1, 2026

Fixes #674

Runs a check to see if Vulkan is avaliable before trying to initialize the Rendering Driver for it.
This fixes the errors that popup if Vulkan drivers are not present on a users system despite being in Compatibility mode.

I tested it on mine and it seems to work on my system with and without vulkan drivers installed.

I suggest some additional testing from other people to make sure that this works

Summary by CodeRabbit

  • Bug Fixes
    • Improved Vulkan support detection at startup: the app now probes availability before continuing and fails fast with a clear error when Vulkan is unavailable, preventing unnecessary initialization and reducing startup issues on unsupported systems.

@coderabbitai
Copy link

coderabbitai bot commented Mar 1, 2026

Walkthrough

Adds a Vulkan support probe via RenderingContextDriverVulkan::_vulkan_is_supported() that optionally initializes Volk, creates a temporary Vulkan instance, loads instance functions, enumerates physical devices, and destroys the instance. initialize() now calls the probe and returns ERR_UNAVAILABLE early if Vulkan is not available.

Changes

Cohort / File(s) Summary
Vulkan Support Probe
drivers/vulkan/rendering_context_driver_vulkan.h, drivers/vulkan/rendering_context_driver_vulkan.cpp
Added bool _vulkan_is_supported() to detect Vulkan availability (optional Volk init, temporary VkInstance, load instance-level functions, enumerate physical devices, cleanup). initialize() now calls the probe and returns ERR_UNAVAILABLE if unsupported. Added core/error/error_list.h include.

Sequence Diagram(s)

mermaid
sequenceDiagram
participant App as "App / Engine"
participant Driver as "RenderingContextDriverVulkan"
participant Volk as "Volk (loader)"
participant Vulkan as "Vulkan Loader / Driver"
participant GPU as "Physical Devices"
App->>Driver: initialize()
Driver->>Driver: _vulkan_is_supported()
Driver->>Volk: optional volkInitialize()
Volk-->>Driver: volk initialized / already present
Driver->>Vulkan: vkCreateInstance (temporary)
Vulkan-->>Driver: VkInstance
Driver->>Vulkan: load instance functions
Driver->>GPU: vkEnumeratePhysicalDevices(VkInstance)
GPU-->>Driver: device list / empty
alt devices found
Driver->>App: continue initialization
else no devices / errors
Driver->>App: return ERR_UNAVAILABLE
end

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title clearly and specifically describes the main change: adding a Vulkan support check before initialization, which directly addresses the linked issue.
Linked Issues check ✅ Passed The code changes implement a runtime support probe via _vulkan_is_supported() that prevents initialization errors when Vulkan drivers are unavailable, directly addressing issue #674's reported initialization failures.
Out of Scope Changes check ✅ Passed All changes are scoped to adding Vulkan support detection; no unrelated modifications to other subsystems or features were introduced.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@drivers/vulkan/rendering_context_driver_vulkan.cpp`:
- Around line 918-953: The support probe in _vulkan_is_supported() currently
calls raw Vulkan entry points (volkInitialize, vkCreateInstance,
vkEnumeratePhysicalDevices) which bypasses the hook abstraction and can return
false when hook-backed setups are available; change the probe to consult and use
the VulkanHooks abstraction used by _create_vulkan_instance() and
_initialize_devices() (e.g., check VulkanHooks::is_available() or the equivalent
hook initializer and use its proc getters instead of raw vk* symbols) so the
probe respects hooked entry points, and if hooks report availability follow the
same creation/enumeration path the rest of the code uses (and only fall back to
raw entry points if VulkanHooks explicitly reports unavailable).
- Around line 933-957: The probe in _vulkan_is_supported creates an instance
(vkCreateInstance using create_info and app_info) but doesn't enable portability
enumeration, causing vkEnumeratePhysicalDevices to fail on MoltenVK; update the
probe's VkInstanceCreateInfo to add the
VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR flag and add the
"VK_KHR_portability_enumeration" extension to
create_info.ppEnabledExtensionNames (ensure create_info.enabledExtensionCount is
set accordingly) before calling vkCreateInstance so vkEnumeratePhysicalDevices
can return devices on portability implementations.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3ef8058 and 919a31f.

📒 Files selected for processing (2)
  • drivers/vulkan/rendering_context_driver_vulkan.cpp
  • drivers/vulkan/rendering_context_driver_vulkan.h

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@drivers/vulkan/rendering_context_driver_vulkan.cpp`:
- Around line 33-34: The `#include` "core/error/error_list.h" is outside the
VULKAN_ENABLED guard and should be moved so it's only included for Vulkan
builds; relocate that include into the existing `#ifdef` VULKAN_ENABLED block with
the other includes in rendering_context_driver_vulkan.cpp so ERR_UNAVAILABLE
(used around the ERR_UNAVAILABLE reference in the Vulkan-specific code) is only
available in Vulkan builds and non-Vulkan builds don't pull the header.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 919a31f and ccd1844.

📒 Files selected for processing (1)
  • drivers/vulkan/rendering_context_driver_vulkan.cpp

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
drivers/vulkan/rendering_context_driver_vulkan.cpp (1)

924-972: Add lightweight probe failure diagnostics.

The probe currently returns false silently on multiple branches, which makes support/debug triage harder when initialize() returns ERR_UNAVAILABLE. A small verbose log per failure branch would help without changing behavior.

🛠️ Suggested minimal logging additions
 `#ifdef` USE_VOLK
 	if (volkInitialize() != VK_SUCCESS) {
+		print_verbose("VULKAN: Support probe failed at volkInitialize.");
 		return false;
 	}
 
 	if (!vkCreateInstance) {
+		print_verbose("VULKAN: Support probe missing vkCreateInstance.");
 		return false;
 	}
 `#endif`
@@
 	VkInstance _instance;
 	if (vkCreateInstance(&create_info, nullptr, &_instance) != VK_SUCCESS) {
+		print_verbose("VULKAN: Support probe failed at vkCreateInstance.");
 		return false;
 	}
@@
 `#ifdef` USE_VOLK
 	if (!vkEnumeratePhysicalDevices) {
+		print_verbose("VULKAN: Support probe missing vkEnumeratePhysicalDevices.");
 		vkDestroyInstance(_instance, nullptr);
 		return false;
 	}
 `#endif`
@@
 	vkDestroyInstance(_instance, nullptr);
 
 	if (result != VK_SUCCESS || device_count == 0) {
+		print_verbose("VULKAN: Support probe found no usable Vulkan physical devices.");
 		return false;
 	}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@drivers/vulkan/rendering_context_driver_vulkan.cpp` around lines 924 - 972,
The probe currently returns false silently; add lightweight diagnostic logging
at each failure branch without changing behavior: log a clear message when
volkInitialize() fails, when vkCreateInstance function pointer is null, when
vkCreateInstance(&create_info, nullptr, &_instance) returns non-VK_SUCCESS
(include the VkResult), when vkLoadInstance/vkEnumeratePhysicalDevices function
pointer is null, and when vkEnumeratePhysicalDevices(_instance, &device_count,
nullptr) returns non-VK_SUCCESS or when device_count == 0 (include result and
device_count); reference the symbols volkInitialize, vkCreateInstance,
vkCreateInstance(&create_info,...,&_instance), volkLoadInstance,
vkEnumeratePhysicalDevices, _instance, result, and device_count, and ensure any
existing vkDestroyInstance(_instance, nullptr) calls remain in place and logs
are emitted before each return false.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@drivers/vulkan/rendering_context_driver_vulkan.cpp`:
- Around line 924-972: The probe currently returns false silently; add
lightweight diagnostic logging at each failure branch without changing behavior:
log a clear message when volkInitialize() fails, when vkCreateInstance function
pointer is null, when vkCreateInstance(&create_info, nullptr, &_instance)
returns non-VK_SUCCESS (include the VkResult), when
vkLoadInstance/vkEnumeratePhysicalDevices function pointer is null, and when
vkEnumeratePhysicalDevices(_instance, &device_count, nullptr) returns
non-VK_SUCCESS or when device_count == 0 (include result and device_count);
reference the symbols volkInitialize, vkCreateInstance,
vkCreateInstance(&create_info,...,&_instance), volkLoadInstance,
vkEnumeratePhysicalDevices, _instance, result, and device_count, and ensure any
existing vkDestroyInstance(_instance, nullptr) calls remain in place and logs
are emitted before each return false.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ccd1844 and 9aa6de0.

📒 Files selected for processing (1)
  • drivers/vulkan/rendering_context_driver_vulkan.cpp

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.

compatibility vulkan error

1 participant