2
TL; DR:金属似乎并没有检测一下我的顶点着色器返回片段功能似乎正确地写入,但金属抱怨
我已经写在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)
在创建管道状态时出现错误:
fatal error: 'try!' expression unexpectedly raised an error: Error Domain=CompilerError Code=1 "Link failed: fragment input vPos was not found in vertex shader outputs" [...]
我检查并重新检查了代码,并且无法理解错误。
任何想法?谢谢!
不是位置标签用于获取屏幕上的位置而不是相对于矩形的位置? –
感谢您的回答,我会在明天检查它 –
它与“窗口相对”相关,但这确实意味着与视口相关,该视口指定颜色或深度附件的一部分。对于像你的顶点着色器,它只返回一个'float4',返回值就是'position'。因为这就是你想要作为你的片段函数的输入,所以你也想把这个输入注释为'position'。 –