Skip to content

Conversation

@Exanite
Copy link
Collaborator

@Exanite Exanite commented Jan 12, 2026

Summary of the PR

This changes the native name for namespaced enums like GLEnum to be GLenum.
In the process, I also found a bug where Vulkan enums had inconsistent native names.

Related issues, Discord discussions, or proposals

Discord conversation: https://discord.com/channels/521092042781229087/587346162802229298/1460042806952198310
PR where this issue was first discovered: #2503

This PR contains the following sub-PR:

Further Comments

N/A

@Exanite Exanite changed the title Improve handling of Khronos enum native names [3.0] Improve handling of Khronos enum native names Jan 12, 2026
Copy link
Collaborator 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 review complete. Marking as ready for review and subsequent merge.

@Exanite Exanite marked this pull request as ready for review January 12, 2026 11:02
@Exanite Exanite requested a review from a team as a code owner January 12, 2026 11:02
data.Groups[groupName] = new EnumGroup(
groupName,
nativeName,
anyGLStyleGroups ? "GLenum" : null,
Copy link
Member

Choose a reason for hiding this comment

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

Are we sure that hardcoding GLenum is correct here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This parameter specifies the base type of the enum and matches the code in the "Parse enum members" for loop below.

MixKhronosData has a type map during InitializeAsync that is hardcoded to add GLenum as an entry:

job.TypeMap.TryAdd("GLenum", "uint");

Not specifying the type in the new EnumGroup code means that the enum group is skipped when MixKhronosData goes to generate the enum later:

Enum "ALEnum" has no base type. Please add TypeMap entry to the configuration. This enum group will be skipped.

Compared to before, this is now needed because this line of code takes precedence over the new EnumGroup code in the "Parse enum members" for loop, meaning that it needs to take responsibility for initializing the base type in certain cases.

Copy link
Member

Choose a reason for hiding this comment

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

I think this is fine. We can remove the hardcoded GLenum in the TypeMap for consistency if desired, the intention behind this was to have a "sensible default" for the configuration.

I don't want the mod to be hardcoded to OpenGL specifically, as OpenAL is one example of a GL-style binding. GLenum is not an OpenAL type and our code doesn't have any business assuming that ALEnum is the same as GLenum and therefore uint, considering the rest of the code is agnostic to this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That makes sense. I assumed the intention behind using GLenum specifically was to indicate that the enum is a GL-style enum, not specifically that it was a GLenum.

GLbitfield is also declared in the type map, but it is not used anywhere.

It looks like the code that handles OpenCL later just hardcodes the base type, so this change would be consistent with that approach:
image

Proposed change:
image

Also debating if I want to pull the result of the condition into a variable so we don't have issues when we modify one, but not the other in the future. However, I don't want to wrongly imply that the resulting type needs to be used as a default (there are four places where we use new EnumGroup).

Copy link
Member

@Perksey Perksey Jan 13, 2026

Choose a reason for hiding this comment

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

I believe both of these cases should not hardcode a specific integer type. The OpenCL one is likely a leftover from the admittedly quite complex OpenCL-specific logic ported from BuildTools, I agree this new change is consistent but hardcoded logic for determining what the enum base type should be should be avoided, as this changes depending on what we're binding to and therefore should be specific in the configuration, optionally with "sensible defaults" in MixKhronosData that the configuration overrides.

Copy link
Collaborator Author

@Exanite Exanite Jan 13, 2026

Choose a reason for hiding this comment

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

Do you have a specific change in mind?

One approach for OpenGL/AL is to have the type be based on the namespace (eg: GLenum, ALenum, etc).
I'm unfamiliar with OpenCL so I'm not sure if the same approach will work there.

That being said, it should be "safe" to leave the type map unspecified (as in, not provide defaults for the config to override) since the generator will log errors and skip over enums that don't have base types. Anyone working on the bindings should be able to quickly see that and fix it by updating the configuration.

Copy link
Member

Choose a reason for hiding this comment

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

Leaving it unspecified and updating the configuration is what I had in mind.

That being said, ideally we don't want every single enum to be specified in the config, so we do really only want it to be the base types. For the OpenGL code, this should be an easy case of using $"{namespace}enum".

For the OpenCL code, I'm not quite sure how to make this more generic primarily because that logic is so esoteric and there's a lot hardcoded already, I would just suggest hardcoding this to cl_bitfield and we'll have to look at it in depth another time unless you can see something obvious that follows the same spirit as the OpenGL change.

Copy link
Member

@Perksey Perksey Jan 14, 2026

Choose a reason for hiding this comment

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

Wrt OpenCL, I think removing all the hardcoded stuff is likely a larger work item, so the best we can do is not make this problem worse and tackle it another time.

The changes likely aren't that complicated:

  • This loop removes knowledge of cl_properties/cl_bitfield, and instead of checking for those specific types should check whether the inner type element has a name in TypeMap.
  • Configuration should contain a bitmask types array, that if not provided has sensible defaults (i.e. cl_bitfield)
  • Additional work to either use other data within the registry in place of hardcoded cl/CL in strings, or to derive this from configuration.

But your call on how much to do for this PR, it does feel out-of-scope.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I haven't looked into OpenCL yet, but I agree, I'd much rather do this once we start working on the OpenCL bindings so we can review the output and work with actual data. Trying to rework the OpenCL code without looking at the output seems like a recipe for disaster.

@Exanite
Copy link
Collaborator Author

Exanite commented Jan 15, 2026

This PR will be ready for review/merge once Exanite#30 is merged into this PR.

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.

2 participants