🐛 Answer the device's compile of a visible function as the x86 Macs

macOS 12 and 13 guests' iconservicesagent and com.apple.dock.extra send
the device's private compileVisibleFunction:withDescriptor:error: at
start-up, from Metal's own link of Core Image's kernels, and the bundle
answered it unsupported while supportsFunctionPointers answers YES (17
boots of 11-15/16). Both x86 Macs answer each of its three forms with no
error for any function and descriptor, keep the function in the archive
of the archive form, and call the handler form's one-argument handler
with nil on the caller's thread (oracle_binfn, macOS 26.7.1, Q47).

What the guest now sees, where the host makes function pointers:
- the three compile forms answer as the Macs do and compile nothing,
  as the host compiles a binary function where a pipeline links it;
  the archive form keeps the function as addFunctionWithDescriptor:
  keeps it, and the handler runs before the call returns;
- newComputePipelineStateWithAdditionalBinaryFunctions:error: answers
  the pipeline itself, as the AMD 5300M's does (the Intel 630 makes
  another; the Macs diverge), where it answered nil and an error;
- the device's functionHandleWithFunction: and its resource-index form
  raise an unrecognized selector, as both Macs' devices do, where they
  answered nil.
Where the host makes none, each answers the unsupported error as before.
This commit is contained in:
Anees Iqbal committed 2026-11-16 12:56:26 -08:00
1 parent 6436c97b94
commit 74869d936c
9 files changed
+188 -54

No files matched your search

+31
View File
@@ -2539,6 +2539,37 @@ read by their keys, matched at best 10 of the 60 (m3-max-31104 and the probe abo
a hash structure of Metal's own. Ours (`RgfxLibrary.mm`, `functionNames`) answers the given order
reversed *(class 2: Metal's for every array of two and for some longer ones)*.
## Q47: binary functions, and the device's compile of a visible function
Probe: `oracle_binfn DEVICE`, 11-16, on the AMD Radeon Pro 5300M and the Intel UHD Graphics 630
under macOS 26.7.1 (m3-max-37213 and 37214; the device's own handles and tables m3-max-37220 and
37221). It wraps the device class's three forms of `compileVisibleFunction:withDescriptor:`, so
each call Metal makes of them is printed. macOS 12 and 13 guests' iconservicesagent and
`com.apple.dock.extra` send the form with an error out at start-up, from Metal's own link of
Core Image's kernels, which the bundle answered unsupported until then (17 boots of 11-15/16).
| asked | AMD | Intel |
|---|---|---|
| the device responds to the error, archive and handler forms | YES, YES, YES | the same |
| `newFunctionWithDescriptor:` of a visible function with `MTLFunctionOptionCompileToBinary` | the function, options 1; Metal's library sends the error form once, with the function (options still 0) and the descriptor | the same |
| the same of a kernel | the function, options 1; no compile sent | the same |
| the error form, sent with a visible function and a descriptor of options 0 or 1, a nil descriptor, or a kernel | returns, the error untouched | the same |
| the archive form, into an archive of the device | returns, the error untouched; the archive then has one key, of the function | the same |
| the handler form | calls its handler, of one argument, with nil, on the caller's thread before it returns | the same |
| a compute pipeline linking `binaryFunctions` (binary ones, or one made without the option) | made; the handles of its functions, dispatches through them right | the same |
| `newComputePipelineStateWithAdditionalBinaryFunctions:error:` (a binary function, a plain one, none) | the same pipeline object each time, no error; no handle of an added function | another pipeline each time, linking the added function: its handle made, a dispatch through it right |
| the device's `functionHandleWithFunction:` (macOS 26) and `functionHandleWithFunction:resourceIndex:` | raise an unrecognized selector, though the device responds to both | the same |
| the device's `newVisibleFunctionTableWithDescriptor:` | a table (`GFXAAMD_MtlVisibleFunctionTable`) | a table (`MTLIGAccelVisibleFunctionTable`) |
Ours (`RgfxMetalDevice.mm`, `RgfxBinaryArchive`'s `rgfxCompileVisibleFunction:descriptor:archive:`,
`RgfxComputePipelineState.mm`), where the host makes function pointers: each compile form as the
two Macs answer it, compiling nothing, as the host compiles a binary function where a pipeline links
it (`test_visible_compiles`, tests/archive_tests.mm); more binary functions answer the pipeline
itself, as the AMD's does *(class 2: the Macs diverge, and the AMD's answer makes nothing)*
(`test_function_pointers`, tests/shell_tests.mm); the device's handles raise as the two Macs' do. The
device's table stays unsupported: a table of the wire belongs to a pipeline
(`FUNCTION_TABLE_CREATE`).
## Not measured
- Cross-process lock waits for pending GPU work: rgk-lock's `lock_probe` (x86 matches the M3,
+16
View File
@@ -72,6 +72,22 @@ extern NSErrorDomain const RgfxBinaryArchiveMissDomain;
/// which rgfxMissOfFunction looks up.
- (void)rgfxAddFunction:(RgfxFunction *)fn options:(MTLFunctionOptions)options;
/// The device's private compile of a visible function into `archive`
/// (compileVisibleFunction:withDescriptor:destinationBinaryArchive:error:), whose form without an
/// archive Metal's library sends for a function made with MTLFunctionOptionCompileToBinary and
/// Metal's own link of Core Image's kernels sends on macOS 12 and 13 (iconservicesagent,
/// com.apple.dock.extra). The AMD 5300M and the Intel 630 answer each form with no error whatever
/// the function (a kernel too) and the descriptor (nil too), and the archive form adds the
/// function to the archive (measured: macOS 26.7.1, tools/oracle/oracle_binfn.m). Nothing is
/// compiled here: the host compiles a binary function where a pipeline links it
/// (RGFX_LINKED_BINARY_FUNCTIONS). `archive`, where it and `function` are this device's, keeps the
/// function as addFunctionWithDescriptor:library:error: keeps it, with the descriptor's options,
/// or the function's own where the descriptor is no MTLFunctionDescriptor; any other archive or
/// function is left as it is.
+ (void)rgfxCompileVisibleFunction:(nullable id<MTLFunction>)function
descriptor:(nullable id)descriptor
archive:(nullable id)archive;
/// Metal's miss of `fn`, made by newFunctionWithDescriptor:error: with `options` and `archives`, as
/// the AMD 5300M and the Intel 630 under macOS 26.7.1 answer it (oracle_bundle failmiss and
/// failmiss2), nil where it is made: with MTLFunctionOptionFailOnBinaryArchiveMiss and an archive
+11
View File
@@ -602,6 +602,17 @@ RGFX_LOG_UNRECOGNIZED
[self rgfxAdd:functionKey(fn, options)];
}
+ (void)rgfxCompileVisibleFunction:(id<MTLFunction>)function descriptor:(id)descriptor archive:(id)archive
{
if (![archive isKindOfClass:[RgfxBinaryArchive class]] ||
![(id)function isKindOfClass:[RgfxFunction class]])
return;
MTLFunctionOptions options = [descriptor isKindOfClass:[MTLFunctionDescriptor class]]
? ((MTLFunctionDescriptor *)descriptor).options
: function.options;
[(RgfxBinaryArchive *)archive rgfxAddFunction:(RgfxFunction *)function options:options];
}
// Metal's archive adds a stitched library by stitching it on its device into the archive
// (newLibraryWithStitchedDescriptor:destinationBinaryArchive:error:, measured: macOS 27), so it
// answers what that stitch answers: NO and Metal's error for a graph Metal cannot stitch, YES for
+11 -3
View File
@@ -999,7 +999,7 @@ NSError *RgfxComputeProgressError(BOOL hasProgress, NSInteger progress, BOOL has
serializer:_serializer]);
}
// --- unsupported: binary functions --------------------------------------------------
// --- binary functions ----------------------------------------------------------------
- (id<MTLFunctionHandle>)functionHandleWithBinaryFunction:(id<MTL4BinaryFunction>)function
{
@@ -1007,12 +1007,20 @@ NSError *RgfxComputeProgressError(BOOL hasProgress, NSInteger progress, BOOL has
return nil;
}
// The pipeline itself, with no error, whatever functions it is given, as the AMD 5300M's answers
// (measured: macOS 26.7.1, tools/oracle/oracle_binfn.m: it then has no handle of an added function).
// The Intel 630's makes another pipeline, which links them too: the Macs diverge, and the AMD's
// answer makes nothing. Where the host makes no function pointers, nil and the unsupported error.
- (id<MTLComputePipelineState>)
newComputePipelineStateWithAdditionalBinaryFunctions:(NSArray<id<MTLFunction>> *)functions
error:(__autoreleasing NSError **)error
{
RGFX_UNSUPPORTED_ERROR(error, "binary functions");
return nil;
if (_serializer == nullptr || !_serializer->carriesFunctionPointers()) {
RGFX_UNSUPPORTED_ERROR(error, "binary functions, where the host makes no function pointers");
return nil;
}
(void)functions;
return self;
}
- (id<MTLComputePipelineState>)
@@ -45,12 +45,6 @@ NSError *metal4Refusal()
// --- function pointers and dynamic libraries ------------------------------------------
- (id<MTLFunctionHandle>)functionHandleWithFunction:(id<MTLFunction>)function
{
RGFX_UNSUPPORTED(kFunctionPointers);
return nil;
}
- (id<MTLFunctionHandle>)functionHandleWithBinaryFunction:(id<MTL4BinaryFunction>)function
{
RGFX_UNSUPPORTED(kFunctionPointers);
@@ -271,43 +265,6 @@ NSError *metal4Refusal()
return nil;
}
// Function pointers: a visible function's compile (`v40@0:8@16@24^@32`,
// `v48@0:8@16@24@32^@40`, `v40@0:8@16@24@?32`) and a function's handle at a resource index
// (`@32@0:8@16Q24`).
- (void)compileVisibleFunction:(id<MTLFunction>)function
withDescriptor:(id)descriptor
error:(NSError **)error
{
RGFX_UNSUPPORTED_ERROR(error, kFunctionPointers);
}
- (void)compileVisibleFunction:(id<MTLFunction>)function
withDescriptor:(id)descriptor
destinationBinaryArchive:(id<MTLBinaryArchive>)archive
error:(NSError **)error
{
RGFX_UNSUPPORTED_ERROR(error, kFunctionPointers);
}
- (void)compileVisibleFunction:(id<MTLFunction>)function
withDescriptor:(id)descriptor
completionHandler:(id)completionHandler
{
NSError *error = nil;
RGFX_UNSUPPORTED_ERROR(&error, kFunctionPointers);
completionHandler = [completionHandler copy];
RgfxRunCreation(^{
RgfxCallCreationHandler(completionHandler, nil, error, _cmd);
});
}
- (id<MTLFunctionHandle>)functionHandleWithFunction:(id<MTLFunction>)function
resourceIndex:(NSUInteger)resourceIndex
{
RGFX_UNSUPPORTED(kFunctionPointers);
return nil;
}
// Dynamic libraries (`@40@0:8@16@24^@32`, `@32@0:8@16^@24` twice, `@40@0:8@16Q24^@32`) and binary
// libraries (`@40@0:8Q16@24^@32`).
- (id<MTLDynamicLibrary>)newDynamicLibrary:(id<MTLLibrary>)library
+66
View File
@@ -12,6 +12,7 @@
#include "RgfxLog.hpp"
#include "RgfxLogOnce.hpp"
#import "RgfxBinaryArchive.h"
#import "RgfxBuffer.h"
#import "RgfxInterop.h"
#import "RgfxIOSurface.h"
@@ -1689,6 +1690,71 @@ RGFX_LOG_UNRECOGNIZED
return NO;
}
// The device's private compile of a visible function (`v40@0:8@16@24^@32`,
// `v48@0:8@16@24@32^@40`, `v40@0:8@16@24@?32`), as the AMD 5300M and the Intel 630 answer it
// (measured: macOS 26.7.1, tools/oracle/oracle_binfn.m; RgfxBinaryArchive's
// rgfxCompileVisibleFunction:descriptor:archive:): no error, whatever the function and the
// descriptor; the archive form keeps the function in the archive; the handler form calls its
// handler, of one argument, with nil on the caller's thread before it returns. Metal's library
// sends it for MTLFunctionOptionCompileToBinary, and Metal's own link of Core Image's kernels on
// macOS 12 and 13. Where the host makes no function pointers (supportsFunctionPointers NO), each
// answers the unsupported error as before.
- (void)compileVisibleFunction:(id<MTLFunction>)function
withDescriptor:(id)descriptor
error:(NSError **)error
{
if (![self supportsFunctionPointers]) {
RGFX_UNSUPPORTED_ERROR(error, "function pointers, where the host makes none");
return;
}
[RgfxBinaryArchive rgfxCompileVisibleFunction:function descriptor:descriptor archive:nil];
}
- (void)compileVisibleFunction:(id<MTLFunction>)function
withDescriptor:(id)descriptor
destinationBinaryArchive:(id<MTLBinaryArchive>)archive
error:(NSError **)error
{
if (![self supportsFunctionPointers]) {
RGFX_UNSUPPORTED_ERROR(error, "function pointers, where the host makes none");
return;
}
[RgfxBinaryArchive rgfxCompileVisibleFunction:function descriptor:descriptor archive:archive];
}
- (void)compileVisibleFunction:(id<MTLFunction>)function
withDescriptor:(id)descriptor
completionHandler:(id)completionHandler
{
NSError *error = nil;
if (![self supportsFunctionPointers])
RGFX_UNSUPPORTED_ERROR(&error, "function pointers, where the host makes none");
else
[RgfxBinaryArchive rgfxCompileVisibleFunction:function descriptor:descriptor archive:nil];
if (completionHandler != nil)
((void (^)(NSError *))completionHandler)(error);
}
// A function's handle of the device (macOS 26's functionHandleWithFunction:, and the SPI's at a
// resource index, `@32@0:8@16Q24`): the AMD 5300M's and the Intel 630's devices raise an
// unrecognized selector at each, answering respondsToSelector: YES (measured: macOS 26.7.1,
// tools/oracle/oracle_binfn.m), and so does this.
- (id<MTLFunctionHandle>)functionHandleWithFunction:(id<MTLFunction>)function
{
(void)function;
[self doesNotRecognizeSelector:_cmd];
return nil;
}
- (id<MTLFunctionHandle>)functionHandleWithFunction:(id<MTLFunction>)function
resourceIndex:(NSUInteger)resourceIndex
{
(void)function;
(void)resourceIndex;
[self doesNotRecognizeSelector:_cmd];
return nil;
}
- (BOOL)supportsRaytracingFromRender
{
return _caps.identityFlag(kRgfxIdentitySupportsRaytracingFromRender);
+36
View File
@@ -459,6 +459,41 @@ void test_function_misses()
CHECK(miss(vertex, binary, @[ empty ]) == nil && miss(nil, binary, @[ empty ]) == nil);
}
// The device's compile of a visible function into an archive keeps the function there, as the x86
// Macs' archive form does (oracle_binfn, AMD 5300M and Intel 630, macOS 26.7.1), with the
// descriptor's options, or the function's own where the descriptor is none: a visible function
// compiled with MTLFunctionOptionCompileToBinary is then found by one made with it. Without an
// archive, or with another device's archive or function, nothing is kept and nothing fails.
void test_visible_compiles()
{
NSError *e = nil;
RgfxBinaryArchive *a = archive(nil, @"arch_a", &e);
RgfxFunction *visible = function(@"vc_visible");
[visible rgfxSetFunctionType:MTLFunctionTypeVisible];
RgfxFunction *plain = function(@"vc_plain");
[plain rgfxSetFunctionType:MTLFunctionTypeVisible];
const MTLFunctionOptions binary =
MTLFunctionOptionFailOnBinaryArchiveMiss | MTLFunctionOptionCompileToBinary;
MTLFunctionDescriptor *d = [MTLFunctionDescriptor functionDescriptor];
d.name = @"vc_visible";
d.options = MTLFunctionOptionCompileToBinary;
[RgfxBinaryArchive rgfxCompileVisibleFunction:visible descriptor:d archive:nil];
[RgfxBinaryArchive rgfxCompileVisibleFunction:visible descriptor:d archive:[NSObject new]];
[RgfxBinaryArchive rgfxCompileVisibleFunction:(id<MTLFunction>)[NSObject new] descriptor:d archive:a];
[RgfxBinaryArchive rgfxCompileVisibleFunction:nil descriptor:nil archive:a];
CHECK(a.keys.count == 0);
CHECK([RgfxBinaryArchive rgfxMissOfFunction:visible options:binary archives:@[ a ]] != nil);
[RgfxBinaryArchive rgfxCompileVisibleFunction:visible descriptor:d archive:a];
CHECK(a.keys.count == 1);
CHECK([RgfxBinaryArchive rgfxMissOfFunction:visible options:binary archives:@[ a ]] == nil);
// With no descriptor, the function's own options, none here: not found as a binary function.
[RgfxBinaryArchive rgfxCompileVisibleFunction:plain descriptor:nil archive:a];
CHECK(a.keys.count == 2);
CHECK([RgfxBinaryArchive rgfxMissOfFunction:plain options:binary archives:@[ a ]] != nil);
}
// A mesh pipeline created with MTLPipelineOptionFailOnBinaryArchiveMiss misses in every archive,
// which holds none, naming its fragment function, or its mesh function where it has none, in the
// x86 Macs' compiler's domain and words (oracle_mesh archive-miss*); with no archive named it is no
@@ -508,6 +543,7 @@ void rgfxArchiveTests()
test_archive_files();
test_archive_keys_and_options();
test_function_misses();
test_visible_compiles();
test_mesh_pipeline_misses();
[[NSFileManager defaultManager] removeItemAtPath:g_dir error:nil];
}
+6 -6
View File
@@ -255,7 +255,7 @@ functionHandleWithName: metal raises an unrecognized selector, as the AMD 5300M'
gpuResourceID implemented
imageblockMemoryLengthForDimensions: unsupported imageblock memory queries (not in the host's reflection)
maxTotalThreadsPerThreadgroup implemented
newComputePipelineStateWithAdditionalBinaryFunctions:error: unsupported binary functions
newComputePipelineStateWithAdditionalBinaryFunctions:error: partial binary functions, where the host makes no function pointers
newComputePipelineStateWithBinaryFunctions:error: unsupported binary functions
newIntersectionFunctionTableWithDescriptor: unsupported ray tracing
newVisibleFunctionTableWithDescriptor: partial function pointers, where the host makes none
@@ -431,9 +431,9 @@ argumentBuffersSupport implemented
bufferRobustnessSupport base %base-spi
commandBufferErrorOptions base %base-spi
commandQueueLimit base %base-spi
compileVisibleFunction:withDescriptor:completionHandler: partial function pointers
compileVisibleFunction:withDescriptor:destinationBinaryArchive:error: unsupported function pointers
compileVisibleFunction:withDescriptor:error: unsupported function pointers
compileVisibleFunction:withDescriptor:completionHandler: partial function pointers, where the host makes none
compileVisibleFunction:withDescriptor:destinationBinaryArchive:error: partial function pointers, where the host makes none
compileVisibleFunction:withDescriptor:error: partial function pointers, where the host makes none
compilerPropagatesThreadPriority: base %base-creator
convertSparsePixelRegions:toTileRegions:withTileSize:alignmentMode:numRegions: base %base-spi
convertSparseTileRegions:toPixelRegions:withTileSize:numRegions: base %base-spi
@@ -461,8 +461,8 @@ familyName implemented class 2 (the Macs diverge): the device name without the v
featureProfile implemented
featureQueries base %base-spi
functionHandleWithBinaryFunction: unsupported function pointers
functionHandleWithFunction: unsupported function pointers
functionHandleWithFunction:resourceIndex: unsupported function pointers
functionHandleWithFunction: metal raises an unrecognized selector, as the AMD 5300M's and the Intel 630's devices do, though they answer respondsToSelector: YES (measured: macOS 26.7.1, tools/oracle/oracle_binfn.m)
functionHandleWithFunction:resourceIndex: metal raises an unrecognized selector, as the AMD 5300M's and the Intel 630's devices do, though they answer respondsToSelector: YES (measured: macOS 26.7.1, tools/oracle/oracle_binfn.m)
genericAddressSpaceDispatchInfo base %base-spi
getBVHBuilderLock base %base-spi
getCompilerConnectionManager: base %base-spi
+11 -2
View File
@@ -15820,8 +15820,9 @@ struct FunctionPointerDevice {
// 0, and a range past its entries sets none. A handle's gpuResourceID and the pipeline's
// functionHandleWithName: raise an unrecognized selector, as the AMD 5300M's do, but on an Apple GPU
// a handle's gpuResourceID is 0, as the M3 Max's. A table stays NonVolatile whatever purgeable
// state it is told, as the M3 Max's and the Intel 630's do. Where the host makes none, each is nil
// and asks nothing.
// state it is told, as the M3 Max's and the Intel 630's do. More binary functions answer the
// pipeline itself, as the AMD 5300M's does. Where the host makes none, each is nil and asks
// nothing.
void test_function_pointers()
{
Fixture fx;
@@ -15853,8 +15854,16 @@ void test_function_pointers()
td.functionCount = 3;
CHECK([cs functionHandleWithFunction:add1] == nil);
CHECK([cs newVisibleFunctionTableWithDescriptor:td] == nil && device.calls == 0);
CHECK([cs newComputePipelineStateWithAdditionalBinaryFunctions:@[ neg ] error:&err] == nil &&
err.code == RgfxMetalErrorUnsupported);
fx.ser.setCarriesFunctionPointers(true);
// More binary functions answer the pipeline itself and ask the host nothing, as the AMD
// 5300M's pipeline answers (oracle_binfn, macOS 26.7.1).
err = nil;
CHECK([cs newComputePipelineStateWithAdditionalBinaryFunctions:@[ neg ] error:&err] == cs &&
err == nil && device.calls == 0);
CHECK([cs newComputePipelineStateWithAdditionalBinaryFunctions:@[] error:&err] == cs && err == nil);
id<MTLFunctionHandle> h = [cs functionHandleWithFunction:add1];
CHECK(h != nil && device.calls == 1);
if (h == nil)