Skip to content

XNU as a loadable kernel module inside Linux (macOS personality for arm64 Linux)

C

CPU Metal: a pixel-format view of a cube texture, and a cube view's arrayLength (#52)

Fred Nixdd46e1ddeced
diff --git a/gpu/xnu-cpu-metal/src/xnu-cpu-metal-bundle/XnuCpuMetalPlugin.mm b/gpu/xnu-cpu-metal/src/xnu-cpu-metal-bundle/XnuCpuMetalPlugin.mm
index c0ad5b1..bc1c5df 100644
--- a/gpu/xnu-cpu-metal/src/xnu-cpu-metal-bundle/XnuCpuMetalPlugin.mm
+++ b/gpu/xnu-cpu-metal/src/xnu-cpu-metal-bundle/XnuCpuMetalPlugin.mm
@@ -653,7 +653,9 @@ static bool xcmIOSurfacePlaneLayout(IOSurfaceRef surf, NSUInteger plane, NSUInte
desc.depth = MAX(1ul, _depth >> levelRange.location);
desc.mipmapLevelCount = levelRange.length;
desc.sampleCount = _sampleCount;
- desc.arrayLength = sliceRange.length;
+ // arrayLength counts cubes for a cube type, and a cube is six of the slices
+ bool cubes = textureType == MTLTextureTypeCube || textureType == MTLTextureTypeCubeArray;
+ desc.arrayLength = cubes ? MAX(1ul, sliceRange.length / 6) : sliceRange.length;
desc.usage = _usage;
desc.resourceOptions = _options;
XcmTexture *view = [[XcmTexture alloc] initWithHandle:vh device:_device descriptor:desc];
@@ -672,9 +674,10 @@ static bool xcmIOSurfacePlaneLayout(IOSurfaceRef surf, NSUInteger plane, NSUInte
return (id<MTLTexture>)view;
}
- (id<MTLTexture>)newTextureViewWithPixelFormat:(MTLPixelFormat)pixelFormat {
+ bool cubes = _textureType == MTLTextureTypeCube || _textureType == MTLTextureTypeCubeArray; // six slices each
return [self newTextureViewWithPixelFormat:pixelFormat textureType:_textureType
levels:NSMakeRange(0, _mipLevels)
- slices:NSMakeRange(0, _arrayLength)];
+ slices:NSMakeRange(0, cubes ? _arrayLength * 6 : _arrayLength)];
}
- (id<MTLTexture>)newTextureViewWithPixelFormat:(MTLPixelFormat)pixelFormat
textureType:(MTLTextureType)textureType