7 #include "flutter/fml/logging.h"
19 return MTLVertexFormatFloat;
21 return MTLVertexFormatFloat2;
23 return MTLVertexFormatFloat3;
25 return MTLVertexFormatFloat4;
27 return MTLVertexFormatHalf;
29 return MTLVertexFormatHalf2;
31 return MTLVertexFormatHalf3;
33 return MTLVertexFormatHalf4;
35 return MTLVertexFormatChar;
37 return MTLVertexFormatChar2;
39 return MTLVertexFormatChar3;
41 return MTLVertexFormatChar4;
43 return MTLVertexFormatUChar;
45 return MTLVertexFormatUChar2;
47 return MTLVertexFormatUChar3;
49 return MTLVertexFormatUChar4;
51 return MTLVertexFormatShort;
53 return MTLVertexFormatShort2;
55 return MTLVertexFormatShort3;
57 return MTLVertexFormatShort4;
59 return MTLVertexFormatUShort;
61 return MTLVertexFormatUShort2;
63 return MTLVertexFormatUShort3;
65 return MTLVertexFormatUShort4;
67 return MTLVertexFormatInt;
69 return MTLVertexFormatInt2;
71 return MTLVertexFormatInt3;
73 return MTLVertexFormatInt4;
75 return MTLVertexFormatUInt;
77 return MTLVertexFormatUInt2;
79 return MTLVertexFormatUInt3;
81 return MTLVertexFormatUInt4;
83 return MTLVertexFormatInvalid;
88 const std::vector<ShaderStageIOSlot>& inputs,
89 const std::vector<ShaderStageBufferLayout>& layouts) {
90 auto descriptor = descriptor_ = [MTLVertexDescriptor vertexDescriptor];
95 for (
size_t i = 0; i < inputs.size(); i++) {
96 const auto& input = inputs[i];
98 if (vertex_format == MTLVertexFormatInvalid) {
99 VALIDATION_LOG <<
"Format for input " << input.name <<
" not supported.";
102 auto attrib = descriptor.attributes[input.location];
103 attrib.format = vertex_format;
104 attrib.offset = input.offset;
109 for (
size_t i = 0; i < layouts.size(); i++) {
110 const auto& layout = layouts[i];
114 vertex_layout.stride = layout.stride;
115 vertex_layout.stepRate = 1u;
117 ? MTLVertexStepFunctionPerInstance
118 : MTLVertexStepFunctionPerVertex;
static constexpr size_t kReservedVertexBufferIndex
bool SetStageInputsAndLayout(const std::vector< ShaderStageIOSlot > &inputs, const std::vector< ShaderStageBufferLayout > &layouts)
MTLVertexDescriptor * GetMTLVertexDescriptor() const
@ kInstance
The binding is read once per instance.
static MTLVertexFormat ReadStageInputFormat(const ShaderStageIOSlot &input)
constexpr VertexAttributeFormat GetVertexAttributeFormat() const
Derives the flat vertex attribute format from this slot's scalar type, bit width, and component count...