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'。 –