[英]Metal kernel function not found
我正在尝试将 Metal Performance Shaders 与 Core Image 一起使用。
不幸的是,过滤器代码在目标 C 中,我正在使用桥使其与 Swift 项目一起使用。
我的项目-桥接-Header.h
#import "MyCustomFilter.h"
我的自定义过滤器.h
#import <CoreImage/CoreImage.h>
@interface MyCustomFilter : CIFilter
......
@end
我的自定义过滤器.m
#import "MyCustomFilter.h"
#import "MyCustomFilterKernel.h"
.......
MyCustomFilterKernel.h
#import <CoreImage/CoreImage.h>
@interface MyCustomFilterKernel : CIImageProcessorKernel
@end
MyCustomFilterKernel.m
#import "FTWaveformScopeKernel.h"
#import "FTWaveformScopeFilter.h"
#import <Metal/Metal.h>
...
+ (void) initialize {
id<MTLFunction> customFunction = [defaultLibrary newFunctionWithName:@"custom_Function"];
if (customFunction) {
NSError* error;
kCustomComputePipelineState = [kDevice newComputePipelineStateWithFunction: customFunction error:&error];
if (error) {
NSLog(@"error loading kernel function (custom_Function): %@", error);
}
} else {
NSLog(@"kernel function (custom_Function) not found");
}
自定义函数.metal
#include <metal_stdlib>
using namespace metal;
......
kernel void
custom_Function(texture2d<float, access::sample> inTexture [[texture(0)]],
texture2d<float, access::write> outTexture [[texture(1)]],
volatile device atomic_uint* columnDataRed [[buffer(0)]],
volatile device atomic_uint* columnDataGreen [[buffer(1)]],
volatile device atomic_uint* columnDataBlue [[buffer(2)]],
sampler wrapSampler [[sampler(0)]],
uint2 gid
[[thread_position_in_grid]])
{
........
}
我得到的错误是(金属视图为空白/透明):
kernel function (custom_Function) not found
我也做过:
我正在处理 Xcode 12.x。 上面的代码编译并运行。
在第一次回复后,我按照新的 Xcode 12 及更高版本设置: https://developer.apple.com/videos/play/wwdc2020/10021/
现在项目不编译:
LLVM ERROR: Error opening
/Users/xxxxxx/Library/Developer/Xcode/DerivedData/xxxxxx-ggaphqixkeecbkewrntvhssdgnac/Build/Intermediates.noindex/xxxxxx.build/Debug-iphoneos/xxxxxx.build/DerivedSources/CustomFunction.ci.air': No such file or directory!
Command RuleScriptExecution failed with a nonzero exit code
RuleScriptExecution /Users/xxxx/Library/Developer/Xcode/DerivedData/xxxx-ggaphqixkeecbkewrntvhssdgnac/Build/Products/Debug-iphoneos/xxxx\ xxxx.app/CustomFunction.ci.metallib /Users/xxxx/Library/Developer/Xcode/DerivedData/xxxx-xxxx-ggaphqixkeecbkewrntvhssdgnac/Build/Intermediates.noindex/xxxx-xxxx.build/Debug-iphoneos/xxxx-xxxx.build/DerivedSources/CustomFunction.ci.air normal undefined_arch (in target 'xxxx-xxxx' from project 'xxxx-xxxx')
cd /Users/xxxx/Desktop/xxxx-xxxx\ CustomFunction
/bin/sh -c xcrun\ metallib\ -cikernel\ \"\$\{INPUT_FILE_PATH\}\"\ -o\ \"\$\{SCRIPT_OUTPUT_FILE_0\}\"'
'
这些是文本中的两行:
xcrun metallib -cikernel "${INPUT_FILE_PATH}" -o "${SCRIPT_OUTPUT_FILE_0}"
xcrun metal -c -I $MTL_HEADER_SEARCH_PATHS -fcikernel "${INPUT_FILE_PATH}" -o "${SCRIPT_OUPUT_FILE_0}"
因为我不得不看着截图输入这些,也许我在解释时犯了错误? -fcikernel
后有一个双空格?
在 Xcode 12 中更改了 Metal 工具链。上述 linker 标志不再起作用,因为默认工具链不再使用metallib
linker。
您的脚本中确实有错字(SCRIPT_OUPUT_FILE_0 中缺少 T)
我复制了你的脚本并得到了同样的错误。 纠正错别字后,应用程序构建成功。 更正后的脚本文本如下...
xcrun metal -c -I $MTL_HEADER_SEARCH_PATHS -fcikernel "${INPUT_FILE_PATH}" -o "${SCRIPT_OUTPUT_FILE_0}"
xcrun metallib -cikernel "${INPUT_FILE_PATH}" -o "${SCRIPT_OUTPUT_FILE_0}"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.