Files
reims-vgpu/guest/bundle/src/RgfxLibraryFile.h
T
Anees Iqbal 5fc2e3c20c 🐛 Read a library URL of no scheme as the file at its path
newLibraryWithURL:error: read its URL through Foundation's URL loading, which
refuses a URL of no scheme (NSURLErrorDomain -1002), and answered nil and
NSCocoaErrorDomain 256. Espresso names each of its kernels' libraries by such
a URL (-[EspressoMetalKernelsCache lazySetup]), so on the device it had no
kernel library and every GPU Vision and Core ML request threw: Geekbench 7's
workload 302, Photos, FaceTime's and Continuity Camera's effects, on every
host GPU.

The device now opens the file at the URL's path, whatever its scheme, as Metal
does, and answers Metal's errors for a file it cannot read
(src/RgfxLibraryFile.*). Measured with a .metallib of our own at each URL form,
alike on macOS 26.7.1's AMD Radeon Pro 5300M and Intel UHD 630 and macOS
27.0.1's M3 Max (jobs m3-max-20286, 20287, 20288):
  - a URL of no scheme, absolute, relative to the current directory or with
    percent escapes, a file URL, one relative to a file URL, and an http or
    other scheme's URL of a file's path: the file's library;
  - no file there: MTLLibraryErrorDomain 6, "library not found", for a file
    URL too, which answered Foundation's read error before;
  - a URL of no path (data:): MTLLibraryErrorDomain 6, "Invalid file url";
  - a file it may not open: MTLLibraryErrorDomain 1, "metal library file PATH
    failed to open with error: Permission denied";
  - a directory or an empty file: MTLLibraryErrorDomain 1, "Invalid library
    file (unexpected end of file)".
A URL of another scheme is no longer fetched through URL loading.

The other URL readers do not read this way: a binary archive's descriptor URL
must be a file URL, the IO handles take Metal's own check of a file URL, and
dynamic libraries are not supported. The shell tests read each URL form, and
compare each answer with this Mac's Metal's.
2026-11-12 03:43:38 -08:00

42 lines
2.1 KiB
Objective-C

/*
* RgfxLibraryFile: the bytes of the library file a URL names, read as Metal's
* newLibraryWithURL:error: reads them, for the device's newLibraryWithURL:error: (and
* newLibraryWithFile:error:, which makes a file URL of its path).
*
* Metal opens the file at the URL's path, whatever the URL's scheme: a URL of no scheme is a path,
* relative to the current directory where it is relative, its percent escapes decoded; a URL of
* another scheme (http, one of no meaning) is the file at its path too. It answers nil and an
* error of MTLLibraryErrorDomain for a file it cannot read (measured: macOS 26.7.1, the AMD Radeon
* Pro 5300M and the Intel UHD 630, and macOS 27.0.1, the M3 Max, all alike, a .metallib of our own
* at each URL form):
* - a URL of no path (data:): MTLLibraryErrorFileNotFound (6), "Invalid file url";
* - no file at the path: MTLLibraryErrorFileNotFound (6), "library not found";
* - a file it may not open: MTLLibraryErrorUnsupported (1), "metal library file PATH failed to
* open with error: Permission denied", strerror's words for EACCES, the one error of an open
* measured besides ENOENT; another error is answered in the same form, with its own words;
* - a directory, or an empty file: MTLLibraryErrorUnsupported (1), "Invalid library file
* (unexpected end of file)".
* Each error's userInfo holds its description alone. Bytes that are not a library are the
* library's to refuse, as newLibraryWithData:error: refuses them.
*
* Our own ObjC++; no Apple private SPI.
*/
#ifndef RGFX_LIBRARY_FILE_H_
#define RGFX_LIBRARY_FILE_H_
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
/// The path Metal opens for `url`: its path, whatever its scheme; nil where it has none.
NSString *_Nullable RgfxLibraryFilePath(NSURL *url);
/// The bytes of the file at `path` (RgfxLibraryFilePath's), mapped where that is safe; nil, with
/// Metal's error in `*error`, where it cannot be read.
NSData *_Nullable RgfxLibraryFileData(NSString *_Nullable path, NSError *_Nullable __autoreleasing *_Nullable error);
NS_ASSUME_NONNULL_END
#endif // RGFX_LIBRARY_FILE_H_