[英]Fragment function seems properly written but Metal complains
TL;DR: Metal doesn't seem to detect what my vertex shader returns TL; DR:Metal似乎没有检测到我的顶点着色器返回的内容
I have these two functions written in MSL : 我有这两个用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));
}
When I try to create my render pipeline state with those, using this code: 当我尝试使用这些代码创建渲染管道状态时:
// 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)
There is an error at the creation of the pipeline state: 创建管道状态时出错:
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 " [...]
表达意外加一个错误:错误域= CompilerError代码= 1“链接失败:片段VPOS输入未 在顶点着色器输出发现 ” [...]
I checked and rechecked the code and can't understand what's wrong. 我检查并重新检查了代码,无法理解什么是错的。
Any ideas? 有任何想法吗? Thank you!
谢谢!
Try replacing stage_in
with position
. 尝试更换
stage_in
与position
。 I think that stage_in
is mostly used with struct
s where each field is either annotated with a specific attribute qualifier or matched by name. 我认为
stage_in
主要用于struct
s,其中每个字段都使用特定属性限定符进行注释或按名称进行匹配。 Apparently, when it's used with a non-struct type, it's trying to match by name. 显然,当它与非结构类型一起使用时,它会尝试按名称进行匹配。 For example, if your vertex function were to output a struct one of whose fields was
vPos
, that would find it. 例如,如果您的顶点函数要输出其字段为
vPos
,那么就可以找到它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.