Device::Initialize picks GPU and queue family without checking presentation support or required extensions #161

Open
opened 2026-10-06 13:25:46 +00:00 by jorijnvdgraaf · 0 comments

Summary

Device::Initialize picks the physical device and the queue family without checking that either can do what the library needs. Both work on the machines tested so far (single-queue-family GPUs, one usable GPU), so this is a robustness issue found by reading the code, not a reproduced failure. Line numbers refer to 6aa0338.

1. Presentation support is never queried

implementations/Crafter.Graphics-Device.cpp:712-719 takes the first queue family with VK_QUEUE_GRAPHICS_BIT. That queue is later used for vkQueuePresentKHR. vkGetPhysicalDeviceSurfaceSupportKHR is not called anywhere in the tree, although the spec requires the surface to be supported by the device and queue family the swapchain is used with.

Because the device is created before any Window exists, the platform query fits here: vkGetPhysicalDeviceWaylandPresentationSupportKHR / vkGetPhysicalDeviceWin32PresentationSupportKHR per queue family.

2. The physical device is chosen by type alone

:616-652 scores devices by deviceType only (discrete 5, integrated 4, virtual 3, CPU 2, other 1) and keeps the first of the best score. It does not look at the API version, the required extensions, or presentation support.

On a machine with several GPUs this can pick a device that cannot run the library while another one could. The descriptor-set fallback change (pending) at least makes that fail with the names of the missing extensions instead of a bare VK_ERROR_EXTENSION_NOT_PRESENT, but the selection itself is unchanged. There is also no way for an application or user to override the choice.

Suggested fix

  • Filter candidates first: required device extensions present, a queue family with graphics + compute + presentation support.
  • Score the survivors (device type, then whether the optional groups — descriptor heap, ray tracing — are available).
  • Add an override, e.g. an environment variable taking a device index or name substring.
## Summary `Device::Initialize` picks the physical device and the queue family without checking that either can do what the library needs. Both work on the machines tested so far (single-queue-family GPUs, one usable GPU), so this is a robustness issue found by reading the code, not a reproduced failure. Line numbers refer to `6aa0338`. ## 1. Presentation support is never queried `implementations/Crafter.Graphics-Device.cpp:712-719` takes the first queue family with `VK_QUEUE_GRAPHICS_BIT`. That queue is later used for `vkQueuePresentKHR`. `vkGetPhysicalDeviceSurfaceSupportKHR` is not called anywhere in the tree, although the spec requires the surface to be supported by the device and queue family the swapchain is used with. Because the device is created before any `Window` exists, the platform query fits here: `vkGetPhysicalDeviceWaylandPresentationSupportKHR` / `vkGetPhysicalDeviceWin32PresentationSupportKHR` per queue family. ## 2. The physical device is chosen by type alone `:616-652` scores devices by `deviceType` only (discrete 5, integrated 4, virtual 3, CPU 2, other 1) and keeps the first of the best score. It does not look at the API version, the required extensions, or presentation support. On a machine with several GPUs this can pick a device that cannot run the library while another one could. The descriptor-set fallback change (pending) at least makes that fail with the names of the missing extensions instead of a bare `VK_ERROR_EXTENSION_NOT_PRESENT`, but the selection itself is unchanged. There is also no way for an application or user to override the choice. ## Suggested fix - Filter candidates first: required device extensions present, a queue family with graphics + compute + presentation support. - Score the survivors (device type, then whether the optional groups — descriptor heap, ray tracing — are available). - Add an override, e.g. an environment variable taking a device index or name substring.
Sign in to join this conversation.
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
Catcrafts/Crafter.Graphics#161
No description provided.