我可以在Metal(MSL)中使用[[stage_in]]签名和[[buffer(0)]]签名吗?

问题描述 投票:0回答:1

以下 MSL 代码有效吗?

struct UniformBuffer
{
    float2 scale;
    float2 translate;
};

struct VertexInput
{
    float4 position [[ attribute(0) ]];
    float2 texcoord [[ attribute(1) ]];
    float4 color [[ attribute(2) ]];
};

struct VertexOutput
{
    //...
};

vertex VertexOutput main(constant UniformBuffer& ubo[[ buffer(0) ]], VertexInput input [[ stage_in ]])
{
    //...
}

如果此代码有效,那么在 Metal 应用程序中调用 setVertexBuffer 时,我应该如何指定 [[stage_in]] 缓冲区和 [[buffer(0)]] 缓冲区的索引?

我尝试根据页面调用setVertexBuffer函数

https://developer.apple.com/documentation/metal/mtlrendercommandencoder/1515829-setvertexbuffer?language=objc,

但我不确定为 atIndex 指定什么值是正确的。

metal
1个回答
0
投票

着色器本身是有效的。顶点着色器中的

stage_in
意味着您将使用在
MTLVertexDescriptor
上设置的
MTLRenderPipelineDescriptor
MTLVertexDescriptor
包含
attributes
layouts
。这些是其他描述符的数组。通过设置
stage_in
上的
bufferIndex
来指定
MTLVertexAttributeDescriptor
变量“拉取”数据的缓冲区索引。您唯一需要做的就是确保您使用的索引不是用于
buffer(i)
绑定点。

© www.soinside.com 2019 - 2024. All rights reserved.