Skip to content

[3.0] Add Khronos StructureType field initializers#2576

Open
Exanite wants to merge 8 commits into
develop/3.0from
feature/vk-structure-types
Open

[3.0] Add Khronos StructureType field initializers#2576
Exanite wants to merge 8 commits into
develop/3.0from
feature/vk-structure-types

Conversation

@Exanite
Copy link
Copy Markdown
Member

@Exanite Exanite commented May 1, 2026

Summary of the PR

This adds default field initializers to structures that have structure type members, such as sType for VkStructureType in Vulkan.

Related issues, Discord discussions, or proposals

Original discussion with Perksey: https://discord.com/channels/521092042781229087/1376331581198827520/1395826788101263463

Discord thread for work done during this PR: https://discord.com/channels/521092042781229087/1499891853217103902

Further Comments

Tasks

  • Scrape structure type member information
  • Add field initializers to structure type members
    • Add explicit constructor since field initializers require them.
  • Update generator.json to use the new config option
  • Wait for previous PRs to be merged
    • Rebase
  • Regenerate Vulkan bindings using Windows

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 1, 2026

File Coverage
All files 16%

Minimum allowed coverage is 0%

Generated by 🐒 cobertura-action against c9d23c9

@Exanite Exanite force-pushed the feature/vk-structure-types branch from 7a20a21 to c2c40d6 Compare June 5, 2026 23:27
@Exanite
Copy link
Copy Markdown
Member Author

Exanite commented Jun 5, 2026

Verified Windows generation output is the exact same, so not adding an extra commit.

Copy link
Copy Markdown
Member Author

@Exanite Exanite left a comment

Choose a reason for hiding this comment

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

Self code review done.

@@ -1,5 +1,6 @@
@../../common.rsp
--define-macro
VK_ENABLE_BETA_EXTENSIONS
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

TerraFX also does the same: https://github.com/terrafx/terrafx.interop.vulkan/blob/86629a4d0afc1de12d10111b4d1e8bbd4be4363b/generation/settings.rsp#L36

This macro mainly guards a few enum members. Without these enum members, the generated bindings fail to compile.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I did a search over the repo for any missing structure type initializers, and looks like we are good:
Image

).Project;
}

// Rewrite phase 4
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I've decided that it's better to use separate rewriters for everything in MixKhronosData.

There is a performance impact of doing this, but it's much more maintainable to keep every transformation independent of the others. The performance impact is roughly 2 seconds for Vulkan so it is very much worth paying. It also does not affect non-Khronos bindings.

I also plan to keep any new metadata storage structures separate from existing structures. This is to further keep things independent. Every transformation should scrape their own data (within reason).

In particular, what I have in mind relates to StructureTypeMembers within this PR and any metadata we need for the Vulkan struct chaining feature later on. I plan to keep metadata used for Vulkan struct chaining separate from the structure type field initialization code added in this PR.

Comment thread generator.json
"SpecPath": "eng/submodules/vulkan/xml/vk.xml",
"Namespace": "Silk.NET.Vulkan",
"StructureTypes": [
"VkStructureType"
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Similar to FlagsTypes immediately below, StructureTypes should let us handle OpenXR easily once we get to that point.

"VK_KHR_deferred_host_operations+VK_VERSION_1_2",
]
)]
public AccelerationStructureBuildGeometryInfoKHR() { }
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Structs that have field initializers need a constructor.

@Exanite Exanite marked this pull request as ready for review June 5, 2026 23:54
@Exanite Exanite requested a review from a team as a code owner June 5, 2026 23:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

1 participant