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