TL;DR: Metal似乎无法检测到我的顶点着色器返回的内容
我在MSL中编写了这两个函数:
vertex float4 base_image_rect(constant float4 *pos [[buffer(0)]],
uint vid [[vertex_id]]) {
return pos[vid];
}
fragment float4 fragment_image_display(float4 vPos [[stage_in]],
texture2d<float, access::sample> imageToRender [[texture(0)]],
sampler imageSampler [[sampler(0)]]) {
return imageToRender.sample(imageSampler, float2(vPos.x, vPos.y));
}
当我尝试使用这些代码创建我的渲染管道状态时:
// Make image display render pipeline state
let imageDisplayStateDescriptor = MTLRenderPipelineDescriptor()
imageDisplayStateDescriptor.colorAttachments[0].pixelFormat = view.colorPixelFormat
imageDisplayStateDescriptor.vertexFunction = library.makeFunction(name: "base_image_rect")
imageDisplayStateDescriptor.fragmentFunction = library.makeFunction(name: "fragment_image_display")
displayImagePipelineState = try! device.makeRenderPipelineState(descriptor: imageDisplayStateDescriptor)
在创建管线状态时出现错误:
致命错误:'try!'表达式意外地引发了一个错误:错误领域=编译器错误代码=1“链接失败:片段输入vPos在顶点着色器输出中未被找到”[...]
我已经检查了代码,但仍然不知道哪里出错了。
有什么想法吗?谢谢!
float4
的顶点着色器,返回值就是position
。由于这是您希望作为片段函数输入的内容,因此您也希望将该输入注释为position
。 - Ken Thomases