7#include "flutter/fml/logging.h"
19 return MTLVertexFormatInvalid;
24 if (input.
bit_width == 8 *
sizeof(
float)) {
27 return MTLVertexFormatFloat;
29 return MTLVertexFormatFloat2;
31 return MTLVertexFormatFloat3;
33 return MTLVertexFormatFloat4;
36 return MTLVertexFormatInvalid;
39 if (input.
bit_width == 8 *
sizeof(
float) / 2) {
42 return MTLVertexFormatHalf;
44 return MTLVertexFormatHalf2;
46 return MTLVertexFormatHalf3;
48 return MTLVertexFormatHalf4;
51 return MTLVertexFormatInvalid;
55 return MTLVertexFormatInvalid;
59 return MTLVertexFormatChar;
61 return MTLVertexFormatInvalid;
64 if (input.
bit_width == 8 *
sizeof(
char)) {
67 return MTLVertexFormatChar;
69 return MTLVertexFormatChar2;
71 return MTLVertexFormatChar3;
73 return MTLVertexFormatChar4;
76 return MTLVertexFormatInvalid;
79 if (input.
bit_width == 8 *
sizeof(
char)) {
82 return MTLVertexFormatUChar;
84 return MTLVertexFormatUChar2;
86 return MTLVertexFormatUChar3;
88 return MTLVertexFormatUChar4;
91 return MTLVertexFormatInvalid;
94 if (input.
bit_width == 8 *
sizeof(
short)) {
97 return MTLVertexFormatShort;
99 return MTLVertexFormatShort2;
101 return MTLVertexFormatShort3;
103 return MTLVertexFormatShort4;
106 return MTLVertexFormatInvalid;
109 if (input.
bit_width == 8 *
sizeof(ushort)) {
112 return MTLVertexFormatUShort;
114 return MTLVertexFormatUShort2;
116 return MTLVertexFormatUShort3;
118 return MTLVertexFormatUShort4;
121 return MTLVertexFormatInvalid;
124 if (input.
bit_width == 8 *
sizeof(int32_t)) {
127 return MTLVertexFormatInt;
129 return MTLVertexFormatInt2;
131 return MTLVertexFormatInt3;
133 return MTLVertexFormatInt4;
136 return MTLVertexFormatInvalid;
139 if (input.
bit_width == 8 *
sizeof(uint32_t)) {
142 return MTLVertexFormatUInt;
144 return MTLVertexFormatUInt2;
146 return MTLVertexFormatUInt3;
148 return MTLVertexFormatUInt4;
151 return MTLVertexFormatInvalid;
155 return MTLVertexFormatInvalid;
159 return MTLVertexFormatInvalid;
168 return MTLVertexFormatInvalid;
173 const std::vector<ShaderStageIOSlot>&
inputs,
174 const std::vector<ShaderStageBufferLayout>& layouts) {
175 auto descriptor = descriptor_ = [MTLVertexDescriptor vertexDescriptor];
180 for (
size_t i = 0;
i <
inputs.size();
i++) {
183 if (vertex_format == MTLVertexFormatInvalid) {
184 VALIDATION_LOG <<
"Format for input " << input.name <<
" not supported.";
187 auto attrib = descriptor.attributes[input.location];
188 attrib.format = vertex_format;
189 attrib.offset = input.offset;
194 for (
size_t i = 0;
i < layouts.size();
i++) {
195 const auto& layout = layouts[
i];
199 vertex_layout.stride = layout.stride;
200 vertex_layout.stepRate = 1u;
201 vertex_layout.stepFunction = MTLVertexStepFunctionPerVertex;
bool SetStageInputsAndLayout(const std::vector< ShaderStageIOSlot > &inputs, const std::vector< ShaderStageBufferLayout > &layouts)
MTLVertexDescriptor * GetMTLVertexDescriptor() const
static constexpr size_t kReservedVertexBufferIndex
static MTLVertexFormat ReadStageInputFormat(const ShaderStageIOSlot &input)