From c36d5e7024e32bfd3ba86ea71da0bd2c0e71ab2b Mon Sep 17 00:00:00 2001 From: Tyler Smith <74526874+tylertms@users.noreply.github.com> Date: Fri, 6 Nov 2026 06:26:38 +0000 Subject: [PATCH] feat(guest): answer struct members, type kinds and the deprecated argument reflection --- guest/stela-gpu/bundle/Library.m | 39 +++++++++++++++++++++++++++++- guest/stela-gpu/bundle/Pipelines.m | 24 ++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/guest/stela-gpu/bundle/Library.m b/guest/stela-gpu/bundle/Library.m index b646f9f128..7025c8f642 100644 --- a/guest/stela-gpu/bundle/Library.m +++ b/guest/stela-gpu/bundle/Library.m @@ -132,6 +132,8 @@ static void hook(Class class, SEL selector, id block) @implementation StelaGPUFunctionConstant @end +Class objc_getClass(const char *name); + @implementation StelaGPUType - (NSUInteger)dataType @@ -139,6 +141,26 @@ static void hook(Class class, SEL selector, id block) return _dataType; } +/* One class serves every type, each of which is the kind of Metal's class + * its data type names: what applications tell types apart by. */ +- (BOOL)isKindOfClass:(Class)class +{ + const char *name = _dataType == MTLDataTypeStruct ? "MTLStructType" : + _dataType == MTLDataTypeArray ? "MTLArrayType" : + _dataType == MTLDataTypePointer ? "MTLPointerType" : + _dataType == MTLDataTypeTexture ? "MTLTextureReferenceType" : + NULL; + if (class && (class == objc_getClass("MTLType") || (name && class == objc_getClass(name)))) { + return YES; + } + return [super isKindOfClass:class]; +} + +- (NSArray *)members +{ + return _members; +} + - (id)memberByName:(NSString *)name { for (NSUInteger i = 0; i < _members.count; i++) { @@ -213,9 +235,17 @@ static void hook(Class class, SEL selector, id block) return _used; } +/* Every binding here is one of the function's own arguments. */ - (BOOL)isArgument { - return !_used; + return YES; +} + +/* `MTLArgument`, which the deprecated reflection answers with the same + * objects: its type and index values are its binding's. */ +- (BOOL)isActive +{ + return _used; } - (id)bufferStructType @@ -736,6 +766,13 @@ static id encoder_of_binding(StelaGPUDevice *device, StelaGPUBinding *binding) { if (reflection) { *reflection = nil; + NSArray *bindings = [StelaGPUReflection bindingsOfFunction:self]; + for (NSUInteger i = 0; i < bindings.count; i++) { + StelaGPUBinding *binding = [bindings objectAtIndex:i]; + if (binding.type == MTLBindingTypeBuffer && binding.index == index) { + *reflection = binding; + } + } } return [self newArgumentEncoderWithBufferIndex:index]; } diff --git a/guest/stela-gpu/bundle/Pipelines.m b/guest/stela-gpu/bundle/Pipelines.m index 3db17e3878..6b49c5e389 100644 --- a/guest/stela-gpu/bundle/Pipelines.m +++ b/guest/stela-gpu/bundle/Pipelines.m @@ -145,10 +145,34 @@ static id binary_functions_error(NSError **error, const char *reason) return nil; } +/* The deprecated `MTLArgument`s are the bindings, whose values agree. A + * pipeline here has no tile function, so it has no tile arguments. */ @implementation StelaGPURenderReflection + +- (NSArray *)vertexArguments +{ + return self.vertexBindings; +} + +- (NSArray *)fragmentArguments +{ + return self.fragmentBindings; +} + +- (NSArray *)tileArguments +{ + return [NSArray array]; +} + @end @implementation StelaGPUComputeReflection + +- (NSArray *)arguments +{ + return self.bindings; +} + @end @implementation StelaGPUFunctionHandle