Skip to content

Add support for importing correct Vulkan types#40

Merged
hazeycode merged 2 commits intozig-gamedev:mainfrom
carrot-sticks:main
Oct 4, 2025
Merged

Add support for importing correct Vulkan types#40
hazeycode merged 2 commits intozig-gamedev:mainfrom
carrot-sticks:main

Conversation

@carrot-sticks
Copy link
Contributor

This PR adds the ability for users to add their own module, which will be used to determine correct types for Vulkan implementation.

Most popular Vulkan implementation in Zig is vulkan-zig (made by Zig maintainer), and it uses fancy enum { .null_handle = 0, _ } types to add type checking to Vulkan opaque handles. This creates some type mismatches with zglfw.

First, thank you, @Fincap, for providing initial implementation. I had to change getInstanceProcAddress to not be wrapped in zglfw error handling. This function will be passed to the other C libraries (i.e. VulkanMemoryAllocator) , and should not return Zig error union. (Also, this happens with OpenGL #33).

There are few additional issues here. VkAllocationCallbacks isn't opaque. It has defined format, which users can supply.

createWindowSurface returns Error.APIUnavailable for any result besides VK_SUCCESS. That isn't true if for example VK_ERROR_OUT_OF_DEVICE_MEMORY is returned (docs with possible results).

I have tested this in Vulkan app with vulkan-zig and OpenGL app to see that everything still works.

@hazeycode hazeycode requested review from Copilot and removed request for Copilot October 4, 2025 09:39
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for importing external Vulkan types to improve type compatibility with popular Vulkan implementations like vulkan-zig. The changes enable users to optionally provide their own Vulkan module to resolve type mismatches between zglfw's default opaque types and more sophisticated typed Vulkan handles.

  • Added a build option import_vulkan to enable external Vulkan type imports
  • Replaced hardcoded Vulkan type definitions with conditional imports
  • Updated Vulkan-related function signatures to use the imported types
  • Modified getInstanceProcAddress to return the function directly without error wrapping

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
build.zig Adds new enable_vulkan_import build option for conditional Vulkan type importing
src/zglfw.zig Implements conditional Vulkan type system and updates function signatures to use imported types
README.md Adds documentation for Vulkan usage with example build configuration and fixes spelling error

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Member

@hazeycode hazeycode left a comment

Choose a reason for hiding this comment

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

Thanks!

@hazeycode hazeycode merged commit 6034a56 into zig-gamedev:main Oct 4, 2025
3 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.

3 participants