Flutter Impeller
vertex_descriptor_mtl.mm
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
6 
7 #include "flutter/fml/logging.h"
9 
10 namespace impeller {
11 
13 
15 
16 static MTLVertexFormat ReadStageInputFormat(const ShaderStageIOSlot& input) {
17  switch (input.GetVertexAttributeFormat()) {
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;
84  }
85 }
86 
88  const std::vector<ShaderStageIOSlot>& inputs,
89  const std::vector<ShaderStageBufferLayout>& layouts) {
90  auto descriptor = descriptor_ = [MTLVertexDescriptor vertexDescriptor];
91 
92  // TODO(jonahwilliams): its odd that we offset buffers from the max index on
93  // metal but not on GLES or Vulkan. We should probably consistently start
94  // these at zero?
95  for (size_t i = 0; i < inputs.size(); i++) {
96  const auto& input = inputs[i];
97  auto vertex_format = ReadStageInputFormat(input);
98  if (vertex_format == MTLVertexFormatInvalid) {
99  VALIDATION_LOG << "Format for input " << input.name << " not supported.";
100  return false;
101  }
102  auto attrib = descriptor.attributes[input.location];
103  attrib.format = vertex_format;
104  attrib.offset = input.offset;
105  attrib.bufferIndex =
107  }
108 
109  for (size_t i = 0; i < layouts.size(); i++) {
110  const auto& layout = layouts[i];
111  auto vertex_layout =
113  layout.binding];
114  vertex_layout.stride = layout.stride;
115  vertex_layout.stepRate = 1u;
116  vertex_layout.stepFunction = layout.input_rate == VertexInputRate::kInstance
117  ? MTLVertexStepFunctionPerInstance
118  : MTLVertexStepFunctionPerVertex;
119  }
120  return true;
121 }
122 
123 MTLVertexDescriptor* VertexDescriptorMTL::GetMTLVertexDescriptor() const {
124  return descriptor_;
125 }
126 
127 } // namespace impeller
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...
Definition: shader_types.h:258
#define VALIDATION_LOG
Definition: validation.h:91