[英]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.