Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
shader_types.h
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#ifndef FLUTTER_IMPELLER_CORE_SHADER_TYPES_H_
6#define FLUTTER_IMPELLER_CORE_SHADER_TYPES_H_
7
8#include <cstddef>
9#include <cstdint>
10#include <optional>
11#include <string_view>
12#include <vector>
13
14#include "flutter/fml/hash_combine.h"
15#include "flutter/fml/logging.h"
19
20namespace impeller {
21
22enum class ShaderStage {
24 kVertex,
27};
28
40
62
65 std::string name;
66 size_t offset;
67 size_t size;
69 std::optional<size_t> array_elements;
70};
71
73 // This must match the uniform name in the shader program.
74 std::string name;
75 std::vector<ShaderStructMemberMetadata> members;
76};
77
78/// @brief Metadata required to bind a buffer.
79///
80/// OpenGL binding requires the usage of the separate shader metadata struct.
82 /// @brief The name of the uniform slot.
83 const char* name;
84
85 /// @brief `ext_res_0` is the Metal binding value.
86 size_t ext_res_0;
87
88 /// @brief The Vulkan descriptor set index.
89 size_t set;
90
91 /// @brief The Vulkan binding value.
92 size_t binding;
93};
94
95/// @brief Metadata required to bind a combined texture and sampler.
96///
97/// OpenGL binding requires the usage of the separate shader metadata struct.
99 /// @brief The name of the uniform slot.
100 const char* name;
101
102 /// @brief `ext_res_0` is the Metal binding value.
104
105 /// @brief The Vulkan descriptor set index.
106 size_t set;
107
108 /// @brief The Vulkan binding value.
109 size_t binding;
110};
111
113 const char* name;
114 size_t location;
115 size_t set;
116 size_t binding;
118 size_t bit_width;
119 size_t vec_size;
120 size_t columns;
121 size_t offset;
122
123 constexpr size_t GetHash() const {
126 }
127
128 constexpr bool operator==(const ShaderStageIOSlot& other) const {
129 return name == other.name && //
130 location == other.location && //
131 set == other.set && //
132 binding == other.binding && //
133 type == other.type && //
134 bit_width == other.bit_width && //
135 vec_size == other.vec_size && //
136 columns == other.columns && //
137 offset == other.offset;
138 }
139};
140
142 size_t stride;
143 size_t binding;
144
145 constexpr size_t GetHash() const { return fml::HashCombine(stride, binding); }
146
147 constexpr bool operator==(const ShaderStageBufferLayout& other) const {
148 return stride == other.stride && //
149 binding == other.binding;
150 }
151};
152
161
167
168template <size_t Size>
169struct Padding {
170 private:
171 uint8_t pad_[Size];
172};
173
174/// @brief Struct used for padding uniform buffer array elements.
175template <typename T,
176 size_t Size,
177 class = std::enable_if_t<std::is_standard_layout_v<T>>>
178struct Padded {
181
182 Padded(T p_value) : value(p_value){}; // NOLINT(google-explicit-constructor)
183};
184
185inline constexpr Vector4 ToVector(Color color) {
186 return {color.red, color.green, color.blue, color.alpha};
187}
188
189} // namespace impeller
190
191#endif // FLUTTER_IMPELLER_CORE_SHADER_TYPES_H_
SkColor4f color
#define FML_UNREACHABLE()
Definition logging.h:109
constexpr std::size_t HashCombine()
constexpr ShaderStage ToShaderStage(RuntimeShaderStage stage)
constexpr Vector4 ToVector(Color color)
TSize< Scalar > Size
Definition size.h:137
#define T
Struct used for padding uniform buffer array elements.
Padded(T p_value)
Padding< Size > _PADDING_
Metadata required to bind a combined texture and sampler.
size_t texture_index
ext_res_0 is the Metal binding value.
size_t set
The Vulkan descriptor set index.
const char * name
The name of the uniform slot.
size_t binding
The Vulkan binding value.
std::vector< ShaderStructMemberMetadata > members
constexpr size_t GetHash() const
constexpr bool operator==(const ShaderStageBufferLayout &other) const
constexpr bool operator==(const ShaderStageIOSlot &other) const
constexpr size_t GetHash() const
std::optional< size_t > array_elements
Metadata required to bind a buffer.
size_t binding
The Vulkan binding value.
size_t ext_res_0
ext_res_0 is the Metal binding value.
size_t set
The Vulkan descriptor set index.
const char * name
The name of the uniform slot.