Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MTLResourceID should expose _impl #660

Closed
Jasper-Bekkers opened this issue Oct 2, 2024 · 3 comments
Closed

MTLResourceID should expose _impl #660

Jasper-Bekkers opened this issue Oct 2, 2024 · 3 comments
Labels
A-framework Affects the framework crates and the translator for them enhancement New feature or request

Comments

@Jasper-Bekkers
Copy link

For FFI reasons its often useful to be able to get access to the raw value, at the moment I'm just transmuting the struct back and forth but nicer would be to have a to_raw() -> u64

@madsmtm madsmtm added enhancement New feature or request A-framework Affects the framework crates and the translator for them labels Oct 2, 2024
@madsmtm
Copy link
Owner

madsmtm commented Oct 2, 2024

I believe our generation is correct here in hiding the field, that's also what Apple's docs show.

But the again, Swift's generation still allows constructing it with the private name. I suspect that's a bug in Swift's generation though, private fields seems like a fairly rare case, I only found three in our currently generated files?


Anyhow, I'm fine with exposing from_raw and to_raw, though I think from_raw would have to be unsafe, from reading the docs on MTLResourceID:

A MTLResourceID represents a specific GPU resource, mutating this handle is undefined unless the mutation results in the value equalling an already existing handle of the same resource type.

I don't actually know if that's correct, haven't used this API myself and not too familiar with Metal, what do you think?

@Jasper-Bekkers
Copy link
Author

I believe our generation is correct here in hiding the field, that's also what Apple's docs show.

I think so too, there are some apple provided libraries though that access the field directly. (Metal Shader Converter), which is why we need it in our saxaboom crate.

But the again, Swift's generation still allows constructing it with the private name. I suspect that's a bug in Swift's generation though, private fields seems like a fairly rare case, I only found three in our currently generated files?


Anyhow, I'm fine with exposing from_raw and to_raw, though I think from_raw would have to be unsafe, from reading the docs on MTLResourceID:

A MTLResourceID represents a specific GPU resource, mutating this handle is undefined unless the mutation results in the value equalling an already existing handle of the same resource type.

I don't actually know if that's correct, haven't used this API myself and not too familiar with Metal, what do you think?

I don't mind marking from_raw as unsafe, and I've done similar for similar constructs in our engine.

@madsmtm madsmtm closed this as completed in 94f104f Oct 3, 2024
github-merge-queue bot pushed a commit to Traverse-Research/saxaboom that referenced this issue Oct 3, 2024
Does what it says on the tin, same as on `gpu-allocator`

It would be nice to have madsmtm/objc2#660
address tho, but it's not strictly required for now since it requires
spinning a new release and I don't think we have to wait that long for
this to get merged.

---------

Co-authored-by: Marijn Suijten <marijn@traverseresearch.nl>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-framework Affects the framework crates and the translator for them enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants