Skip to content

BGF: Minor Vulkan fixits - #129

Merged
natetrost merged 1 commit into
android:mainfrom
natetrost:main
Nov 17, 2026
Merged

natetrost merged 1 commit into
android:mainfrom
natetrost:main

Conversation

@natetrost

Copy link
Copy Markdown
Contributor

Fix Vulkan device creation and capability reporting bugs in
base_game_framework:

  • Reduced precision features: QueryDeviceCapabilities advertised F16/I8
    math and 16-bit storage through GraphicsAPIFeatures, but the device was
    created with none of them enabled, so shaders relying on them were
    invalid. CreateDevice now chains the supported
    VkPhysicalDeviceShaderFloat16Int8Features /
    VkPhysicalDevice16BitStorageFeatures bits and enables any extensions
    they need. 16-bit storage is core in Vulkan 1.1, and Float16/Int8 in
    1.2, so the extensions are only used below those versions. On 1.0,
    VK_KHR_16bit_storage also requires VK_KHR_storage_buffer_storage_class.
    Feature structs that report no supported bits are not chained.
    Extensions are only recorded once the feature query has succeeded, and
    feature bits are reset before each query.
  • InitializeGraphicsAPI queries device capabilities again on the real
    instance's physical device. QueryCapabilities used a temporary instance.
  • CreateDevice no longer sets device layers. They are deprecated, and VVL
    1.4.347+ rejects them (VUID-VkDeviceCreateInfo-enabledLayerCount-12384),
    so SetValidationLayersEnabled(true) failed device creation. Instance
    layers already validate device calls. CreateDevice also returns failure
    when vkCreateDevice fails instead of using a null device.
  • Validation layer state: "validation layers were requested but
    unavailable" is only logged when validation was actually requested (it
    was logged on every launch). Unavailable layers no longer clear the
    caller's static request.
  • GetGraphicsAPIResourcesVk: fill in physical_device, which was always
    VK_NULL_HANDLE. ShutdownGraphicsAPI clears it with the instance, and a
    failed InitializeGraphicsAPI releases what it created.
  • InitSwapchain: a VkSurfaceCapabilitiesKHR::maxImageCount of 0 means no
    upper limit. It was treated as a maximum of 0, so every swapchain
    request failed on such drivers. Document 0 as "no limit" for
    SwapchainConfigurations::max_swapchain_frame_count.
  • GetDisplayFormats: each format is listed once, and only if the surface
    supports the exact VkFormat. RGBA8 was listed twice when the surface
    reported both R8G8B8A8_UNORM and _SRGB, and was offered as
    VK_FORMAT_R8G8B8A8_SRGB even if only UNORM existed. The color space now
    means the same as in GLES. sRGB is an _SRGB VkFormat, which sRGB-encodes
    writes, so it applies only to RGBA8/BGRA8. Linear covers RGBA8/BGRA8
    UNORM (previously never offered) and the formats without an sRGB variant
    (RGB565, RGBA_16F, ABGR2_10_10_10, ...). Those were labelled sRGB even
    though writes are not encoded.

…numeration

Fix Vulkan device creation and capability reporting bugs in
base_game_framework:

- Reduced precision features: QueryDeviceCapabilities advertised F16/I8
  math and 16-bit storage through GraphicsAPIFeatures, but the device was
  created with none of them enabled, so shaders relying on them were
  invalid. CreateDevice now chains the supported
  VkPhysicalDeviceShaderFloat16Int8Features /
  VkPhysicalDevice16BitStorageFeatures bits and enables any extensions
  they need. 16-bit storage is core in Vulkan 1.1, and Float16/Int8 in
  1.2, so the extensions are only used below those versions. On 1.0,
  VK_KHR_16bit_storage also requires VK_KHR_storage_buffer_storage_class.
  Feature structs that report no supported bits are not chained.
  Extensions are only recorded once the feature query has succeeded, and
  feature bits are reset before each query.
- InitializeGraphicsAPI queries device capabilities again on the real
  instance's physical device. QueryCapabilities used a temporary instance.
- CreateDevice no longer sets device layers. They are deprecated, and VVL
  1.4.347+ rejects them (VUID-VkDeviceCreateInfo-enabledLayerCount-12384),
  so SetValidationLayersEnabled(true) failed device creation. Instance
  layers already validate device calls. CreateDevice also returns failure
  when vkCreateDevice fails instead of using a null device.
- Validation layer state: "validation layers were requested but
  unavailable" is only logged when validation was actually requested (it
  was logged on every launch). Unavailable layers no longer clear the
  caller's static request.
- GetGraphicsAPIResourcesVk: fill in physical_device, which was always
  VK_NULL_HANDLE. ShutdownGraphicsAPI clears it with the instance, and a
  failed InitializeGraphicsAPI releases what it created.
- InitSwapchain: a VkSurfaceCapabilitiesKHR::maxImageCount of 0 means no
  upper limit. It was treated as a maximum of 0, so every swapchain
  request failed on such drivers. Document 0 as "no limit" for
  SwapchainConfigurations::max_swapchain_frame_count.
- GetDisplayFormats: each format is listed once, and only if the surface
  supports the exact VkFormat. RGBA8 was listed twice when the surface
  reported both R8G8B8A8_UNORM and _SRGB, and was offered as
  VK_FORMAT_R8G8B8A8_SRGB even if only UNORM existed. The color space now
  means the same as in GLES. sRGB is an _SRGB VkFormat, which sRGB-encodes
  writes, so it applies only to RGBA8/BGRA8. Linear covers RGBA8/BGRA8
  UNORM (previously never offered) and the formats without an sRGB variant
  (RGB565, RGBA_16F, ABGR2_10_10_10, ...). Those were labelled sRGB even
  though writes are not encoded.

Tested on a Pixel 10 Pro with agdktunnel and Vulkan Validation Layers
1.4.363.1 (from third_party/android-binaries-1.4.363.1), using a
temporary test hook:
- With the layer injected via the Android GPU debug layer settings:
  - A shader module using the Float16 and StorageBuffer16BitAccess
    capabilities creates with no validation errors. Before, VVL reported
    VUID-VkShaderModuleCreateInfo-pCode-08740 and
    VUID-RuntimeSpirv-storageBuffer16BitAccess-11161.
  - physical_device is valid (was 0x0).
  - Display formats: 30 unique (RGBA8 sRGB and linear, RGBA_16F, RGB565,
    ABGR2_10_10_10, each with 6 depth/stencil options). Before: 30 with 6
    duplicate RGBA8 entries and no linear RGBA8.
- With SetValidationLayersEnabled(true) and no injection, the layer loads
  through BGF and reports through its debug messenger. There is no
  device layer error.
- No new validation errors in either mode. The two errors already on
  main (swapchain semaphore reuse, and the surface destroyed before the
  swapchain on window loss) are unchanged and tracked for PR 12.
- agdktunnel (requests RGBA8 sRGB) renders as before.
Not exercised on device: maxImageCount == 0 (this device reports 64), and
the Vulkan 1.0/1.1 extension paths (the device runs Vulkan 1.3, which
uses the core features).
@natetrost
natetrost merged commit 311cf2f into android:main Nov 17, 2026
7 checks passed
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.

1 participant