feat(guest): answer struct members, type kinds and the deprecated argument reflection

This commit is contained in:
Tyler Smith committed 2026-11-06 06:26:38 +00:00
1 parent bc408bf30e
commit c36d5e7024
2 files changed
+62 -1

No files matched your search

+38 -1
View File
@@ -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];
}
+24
View File
@@ -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