私はiOS/OSX用のMetalを学びました。私はRay Wenderlichのチュートリアル(https://www.raywenderlich.com/146414/metal-tutorial-swift-3-part-1-getting-started)に従って始めました。このチュートリアルはうまくいきますが、MTLVertexAttributeDescriptorsについて言及していません。MTLVertexAttributeDescriptorsは必要ですか?彼らはなぜ必要なのですか?
私自身のアプリケーションを開発しているので、私は奇妙な不具合を起こしています。私がMTLVertexAttributeDescriptorsを使用しないという事実が問題に関連しているかどうかは疑問です。
どのような違いがありますか?私は様々な頂点構造を持つ様々なシェーダを作ることができましたが、私はこれらのことについても知らなかったのです。
シェーダで使用するために頂点コンポーネントのレイアウトを記述するためにそれらを使用することがわかっています。例えば、シェーダはこの構造体を頂点に使うことができ、それは下の関数の頂点記述子に設定されます。
typedef struct
{
float3 position [[attribute(T_VertexAttributePosition)]];
float2 texCoord [[attribute(T_VertexAttributeTexcoord)]];
} Vertex;
class func buildMetalVertexDescriptor() -> MTLVertexDescriptor {
let mtlVertexDescriptor = MTLVertexDescriptor()
mtlVertexDescriptor.attributes[T_VertexAttribute.position.rawValue].format = MTLVertexFormat.float3
mtlVertexDescriptor.attributes[T_VertexAttribute.position.rawValue].offset = 0
mtlVertexDescriptor.attributes[T_VertexAttribute.position.rawValue].bufferIndex = T_BufferIndex.meshPositions.rawValue
mtlVertexDescriptor.attributes[T_VertexAttribute.texcoord.rawValue].format = MTLVertexFormat.float2
mtlVertexDescriptor.attributes[T_VertexAttribute.texcoord.rawValue].offset = 0
mtlVertexDescriptor.attributes[T_VertexAttribute.texcoord.rawValue].bufferIndex = T_BufferIndex.meshGenerics.rawValue
mtlVertexDescriptor.layouts[T_BufferIndex.meshPositions.rawValue].stride = 12
mtlVertexDescriptor.layouts[T_BufferIndex.meshPositions.rawValue].stepRate = 1
mtlVertexDescriptor.layouts[T_BufferIndex.meshPositions.rawValue].stepFunction = MTLVertexStepFunction.perVertex
mtlVertexDescriptor.layouts[T_BufferIndex.meshGenerics.rawValue].stride = 8
mtlVertexDescriptor.layouts[T_BufferIndex.meshGenerics.rawValue].stepRate = 1
mtlVertexDescriptor.layouts[T_BufferIndex.meshGenerics.rawValue].stepFunction = MTLVertexStepFunction.perVertex
return mtlVertexDescriptor
}
しかし、たとえMTLVertexDescriptorセットアップなしで、シェーダは既に配列に頂点バッファと頂点の位置/ TEXCOORDコンポーネントにアクセスすることができます。頂点バッファを設定するだけで、シェーダはすべてのコンポーネントにアクセスできます。だから、ディスクリプタは何が良いですか?
ありがとうございました - [[stage_in]]と[[buffer]]の構文の違いについては、私は不思議でした。残念ながら、これはまた、頂点記述子の不足がおそらく私のグリッチの原因ではないことを意味します。 – bsabiston