我想知道为什么我不能成功初始化MPSMatrix
?对象方法initWith只返回一个nil(这意味着init不成功)。我的代码如下所示,我想创建一个名为matrixA的MPSMatrix
,但只是回来了。
id<MTLDevice> device = MTLCreateSystemDefaultDevice();
id<MTLCommandQueue> commandQueue = [device newCommandQueue];
id<MTLCommandBuffer> mpsBuffer = commandQueue.commandBuffer;
float arrayA[5*6] =
{1,1,1,1,1,1,
2,2,2,2,2,2,
3,3,3,3,3,3,
4,4,4,4,4,4,
5,5,5,5,5,5};
float arrayB[6*5] =
{1,1,1,1,1,
2,2,2,2,2,
3,3,3,3,3,
4,4,4,4,4,
5,5,5,5,5,
6,6,6,6,6};
float arrayC[5*5] = {0};
id<MTLBuffer> bufferA = [device newBufferWithBytes:arrayA length:5*6*4 options:MTLResourceCPUCacheModeDefaultCache];
id<MTLBuffer> bufferB = [device newBufferWithBytes:arrayB length:6*5*4 options:MTLResourceCPUCacheModeDefaultCache];
id<MTLBuffer> bufferC = [device newBufferWithBytes:arrayC length:5*5*4 options:MTLResourceCPUCacheModeDefaultCache];
MPSMatrixDescriptor * descA = [MPSMatrixDescriptor matrixDescriptorWithDimensions:5 columns:6 rowBytes:6*4 dataType:MPSDataTypeFloat32];
MPSMatrixDescriptor * descB = [MPSMatrixDescriptor matrixDescriptorWithDimensions:6 columns:5 rowBytes:5*4 dataType:MPSDataTypeFloat32];
MPSMatrixDescriptor * descC = [MPSMatrixDescriptor matrixDescriptorWithDimensions:5 columns:5 rowBytes:5*4 dataType:MPSDataTypeFloat32];
MPSMatrix * matrixA = [[MPSMatrix alloc] initWithBuffer:bufferA descriptor:descA];
MPSMatrix * matrixB = [[MPSMatrix alloc] initWithBuffer:bufferB descriptor:descB];
MPSMatrix * matrixC = [[MPSMatrix alloc] initWithBuffer:bufferC descriptor:descC];
答案 0 :(得分:0)
我发现那是因为我以前调试的设备是5s,它只是部分地支持金属性能着色器基础。它可以获得MPSMatrixDescriptor但是它无法获得MPSMatrix。 叹息。
答案 1 :(得分:0)
是。使用MPSSupportsMTLDevice
确定MetalPerformanceShaders.framework是否支持MTLDevice。事实上,我的iPad mini2也不支持MPS。如下: