| Flutter Impeller |

vertex_descriptor_vk.cc
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
5 #include "impeller/renderer/backend/vulkan/vertex_descriptor_vk.h"
6
7 #include <cstdint>
8
9 namespace impeller {
10
11 vk::Format ToVertexDescriptorFormat(const ShaderStageIOSlot& input) {
12 if (input.columns != 1) {
13 // All matrix types are unsupported as vertex inputs.
14 return vk::Format::eUndefined;
15 }
16
17 switch (input.type) {
18 case ShaderType::kFloat: {
19 if (input.bit_width == 8 * sizeof(float)) {
20 switch (input.vec_size) {
21 case 1:
22 return vk::Format::eR32Sfloat;
23 case 2:
24 return vk::Format::eR32G32Sfloat;
25 case 3:
26 return vk::Format::eR32G32B32Sfloat;
27 case 4:
28 return vk::Format::eR32G32B32A32Sfloat;
29 }
30 }
31 return vk::Format::eUndefined;
32 }
33 case ShaderType::kHalfFloat: {
34 if (input.bit_width == 8 * sizeof(float) / 2) {
35 switch (input.vec_size) {
36 case 1:
37 return vk::Format::eR16Sfloat;
38 case 2:
39 return vk::Format::eR16G16Sfloat;
40 case 3:
41 return vk::Format::eR16G16B16Sfloat;
42 case 4:
43 return vk::Format::eR16G16B16A16Sfloat;
44 }
45 }
46 return vk::Format::eUndefined;
47 }
48 case ShaderType::kDouble: {
49 // Unsupported.
50 return vk::Format::eUndefined;
51 }
52 case ShaderType::kBoolean: {
53 if (input.bit_width == 8 * sizeof(bool) && input.vec_size == 1) {
54 return vk::Format::eR8Uint;
55 }
56 return vk::Format::eUndefined;
57 }
58 case ShaderType::kSignedByte: {
59 if (input.bit_width == 8 * sizeof(char)) {
60 switch (input.vec_size) {
61 case 1:
62 return vk::Format::eR8Sint;
63 case 2:
64 return vk::Format::eR8G8Sint;
65 case 3:
66 return vk::Format::eR8G8B8Sint;
67 case 4:
68 return vk::Format::eR8G8B8A8Sint;
69 }
70 }
71 return vk::Format::eUndefined;
72 }
73 case ShaderType::kUnsignedByte: {
74 if (input.bit_width == 8 * sizeof(char)) {
75 switch (input.vec_size) {
76 case 1:
77 return vk::Format::eR8Uint;
78 case 2:
79 return vk::Format::eR8G8Uint;
80 case 3:
81 return vk::Format::eR8G8B8Uint;
82 case 4:
83 return vk::Format::eR8G8B8A8Uint;
84 }
85 }
86 return vk::Format::eUndefined;
87 }
88 case ShaderType::kSignedShort: {
89 if (input.bit_width == 8 * sizeof(int16_t)) {
90 switch (input.vec_size) {
91 case 1:
92 return vk::Format::eR16Sint;
93 case 2:
94 return vk::Format::eR16G16Sint;
95 case 3:
96 return vk::Format::eR16G16B16Sint;
97 case 4:
98 return vk::Format::eR16G16B16A16Sint;
99 }
100 }
101 return vk::Format::eUndefined;
102 }
103 case ShaderType::kUnsignedShort: {
104 if (input.bit_width == 8 * sizeof(uint16_t)) {
105 switch (input.vec_size) {
106 case 1:
107 return vk::Format::eR16Uint;
108 case 2:
109 return vk::Format::eR16G16Uint;
110 case 3:
111 return vk::Format::eR16G16B16Uint;
112 case 4:
113 return vk::Format::eR16G16B16A16Uint;
114 }
115 }
116 return vk::Format::eUndefined;
117 }
118 case ShaderType::kSignedInt: {
119 if (input.bit_width == 8 * sizeof(int32_t)) {
120 switch (input.vec_size) {
121 case 1:
122 return vk::Format::eR32Sint;
123 case 2:
124 return vk::Format::eR32G32Sint;
125 case 3:
126 return vk::Format::eR32G32B32Sint;
127 case 4:
128 return vk::Format::eR32G32B32A32Sint;
129 }
130 }
131 return vk::Format::eUndefined;
132 }
133 case ShaderType::kUnsignedInt: {
134 if (input.bit_width == 8 * sizeof(uint32_t)) {
135 switch (input.vec_size) {
136 case 1:
137 return vk::Format::eR32Uint;
138 case 2:
139 return vk::Format::eR32G32Uint;
140 case 3:
141 return vk::Format::eR32G32B32Uint;
142 case 4:
143 return vk::Format::eR32G32B32A32Uint;
144 }
145 }
146 return vk::Format::eUndefined;
147 }
148 case ShaderType::kSignedInt64: {
149 // Unsupported.
150 return vk::Format::eUndefined;
151 }
152 case ShaderType::kUnsignedInt64: {
153 // Unsupported.
154 return vk::Format::eUndefined;
155 }
156 case ShaderType::kAtomicCounter:
157 case ShaderType::kStruct:
158 case ShaderType::kImage:
159 case ShaderType::kSampledImage:
160 case ShaderType::kUnknown:
161 case ShaderType::kVoid:
162 case ShaderType::kSampler:
163 return vk::Format::eUndefined;
164 }
165 }
166
167 } // namespace impeller
impeller::ShaderStageIOSlot
Definition: shader_types.h:112
impeller::ShaderType::kAtomicCounter
@ kAtomicCounter
impeller::ShaderStageIOSlot::columns
size_t columns
Definition: shader_types.h:120
impeller::ShaderType::kDouble
@ kDouble
impeller::ShaderType::kSignedInt64
@ kSignedInt64
impeller::ShaderType::kImage
@ kImage
impeller::ShaderType::kVoid
@ kVoid
impeller::ShaderType::kSignedByte
@ kSignedByte
impeller::ShaderType::kUnsignedShort
@ kUnsignedShort
impeller::ShaderType::kUnsignedInt64
@ kUnsignedInt64
impeller::ShaderType::kUnsignedByte
@ kUnsignedByte
impeller::ShaderType::kFloat
@ kFloat
impeller::ShaderStageIOSlot::bit_width
size_t bit_width
Definition: shader_types.h:118
impeller::ShaderType::kBoolean
@ kBoolean
impeller::ShaderType::kSampler
@ kSampler
impeller::ToVertexDescriptorFormat
vk::Format ToVertexDescriptorFormat(const ShaderStageIOSlot &input)
Definition: vertex_descriptor_vk.cc:11
impeller::ShaderType::kSampledImage
@ kSampledImage
impeller::ShaderType::kUnsignedInt
@ kUnsignedInt
impeller::ShaderType::kStruct
@ kStruct
impeller::ShaderType::kSignedShort
@ kSignedShort
impeller::ShaderType::kHalfFloat
@ kHalfFloat
impeller::ShaderType::kSignedInt
@ kSignedInt
impeller::ShaderStageIOSlot::type
ShaderType type
Definition: shader_types.h:117
vertex_descriptor_vk.h
impeller::ShaderType::kUnknown
@ kUnknown
impeller
Definition: allocation.cc:12
impeller::ShaderStageIOSlot::vec_size
size_t vec_size
Definition: shader_types.h:119