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

Add support for MTLDevice.newLibraryWithData:error #699

Open
mariusdkm opened this issue Jan 21, 2025 · 2 comments
Open

Add support for MTLDevice.newLibraryWithData:error #699

mariusdkm opened this issue Jan 21, 2025 · 2 comments
Labels
A-dispatch2 Affects the `dispatch2` crate A-framework Affects the framework crates and the translator for them enhancement New feature or request

Comments

@mariusdkm
Copy link

Would it be possible to get MTLDevice.newLibraryWithData:error implemented?
https://developer.apple.com/documentation/metal/mtldevice/makelibrary(data:)?language=objc

It would be highly beneficial to implement MTLDevice.newLibraryWithData:error as it allows embedding compiled Metal library code directly into the binary. This eliminates the need to load shaders from separate files, saving time and improving performance.

I understand that this requires dispatch support—how complex would this be to implement?

Thank you for considering this feature!

@madsmtm madsmtm added enhancement New feature or request A-framework Affects the framework crates and the translator for them A-dispatch2 Affects the `dispatch2` crate labels Jan 21, 2025
@madsmtm
Copy link
Owner

madsmtm commented Jan 21, 2025

Dispatch support is tracked in #77, and some work is going on in #681, but I've had to delay it 'till after the next release, so it'll probably be a while before we get that support.

In the meantime, you can do something like:

use dispatch2::dispatch_data_t;
use objc2::rc::Retained;
use objc2::msg_send_id;
use objc2_metal::{MTLDevice, MTLLibrary};
use objc2_foundation::NSError;

unsafe fn newLibraryWithData_error(
    device: &ProtocolObject<dyn MTLDevice>,
    data: dispatch_data_t,
) -> Result<Retained<ProtocolObject<dyn MTLLibrary>>, Retained<NSError>> {
    unsafe { msg_send_id![device, newLibraryWithData: data, error: _] }
}

@madsmtm
Copy link
Owner

madsmtm commented Jan 21, 2025

(and then construct the dispatch_data_t manually using dispatch_data_create or similar)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-dispatch2 Affects the `dispatch2` crate 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

2 participants