27 return member.name == name;
37Shader::Shader() =
default;
42 std::string library_id,
43 std::string entrypoint,
45 std::shared_ptr<fml::Mapping> code_mapping,
46 std::vector<impeller::ShaderStageIOSlot> inputs,
47 std::vector<impeller::ShaderStageBufferLayout> layouts,
48 std::unordered_map<std::string, UniformBinding> uniform_structs,
49 std::unordered_map<std::string, TextureBinding> uniform_textures,
50 std::vector<impeller::DescriptorSetLayout> descriptor_set_layouts) {
51 auto shader = fml::MakeRefCounted<Shader>();
52 shader->library_id_ = std::move(library_id);
53 shader->entrypoint_ = std::move(entrypoint);
54 shader->stage_ = stage;
55 shader->code_mapping_ = std::move(code_mapping);
56 shader->inputs_ = std::move(inputs);
57 shader->layouts_ = std::move(layouts);
58 shader->uniform_structs_ = std::move(uniform_structs);
59 shader->uniform_textures_ = std::move(uniform_textures);
60 shader->descriptor_set_layouts_ = std::move(descriptor_set_layouts);
64std::string Shader::GetScopedName()
const {
71 return library.
GetFunction(GetScopedName(), stage_);
75 auto& lib = *
context.GetContext().GetShaderLibrary();
95 const bool code_changed =
96 code_mapping_ ==
nullptr || other.code_mapping_ ==
nullptr ||
97 code_mapping_->GetSize() != other.code_mapping_->GetSize() ||
98 std::memcmp(code_mapping_->GetMapping(),
99 other.code_mapping_->GetMapping(),
100 code_mapping_->GetSize()) != 0;
105 entrypoint_ = std::move(other.entrypoint_);
106 stage_ = other.stage_;
107 code_mapping_ = std::move(other.code_mapping_);
108 inputs_ = std::move(other.inputs_);
109 layouts_ = std::move(other.layouts_);
110 uniform_structs_ = std::move(other.uniform_structs_);
111 uniform_textures_ = std::move(other.uniform_textures_);
112 descriptor_set_layouts_ = std::move(other.descriptor_set_layouts_);
119 auto& lib = *
context.GetContext().GetShaderLibrary();
120 const std::string scoped_name = GetScopedName();
122 std::shared_ptr<const impeller::ShaderFunction> existing =
123 lib.GetFunction(scoped_name, stage_);
124 if (existing && !is_dirty_) {
131 if (existing && is_dirty_) {
132 context.GetContext().GetPipelineLibrary()->RemovePipelinesWithEntryPoint(
134 lib.UnregisterFunction(scoped_name, stage_);
137 std::promise<bool> promise;
138 auto future = promise.get_future();
139 lib.RegisterFunction(
140 scoped_name, stage_, code_mapping_,
142 promise.set_value(result);
153 auto vertex_descriptor = std::make_shared<impeller::VertexDescriptor>();
154 vertex_descriptor->SetStageInputs(inputs_, layouts_);
155 return vertex_descriptor;
162const std::vector<impeller::ShaderStageBufferLayout>&
171const std::vector<impeller::DescriptorSetLayout>&
173 return descriptor_set_layouts_;
177 const std::string&
name)
const {
178 auto uniform = uniform_structs_.find(
name);
179 if (uniform == uniform_structs_.end()) {
182 return &uniform->second;
186 const std::string&
name)
const {
187 auto uniform = uniform_textures_.find(
name);
188 if (uniform == uniform_textures_.end()) {
191 return &uniform->second;
203 Dart_Handle struct_name_handle) {
206 if (uniform ==
nullptr) {
215 Dart_Handle struct_name_handle,
216 Dart_Handle member_name_handle) {
219 if (uniform ==
nullptr) {
224 const auto* member = uniform->GetMemberMetadata(member_name);
225 if (member ==
nullptr) {
229 return member->offset;
An immutable collection of shaders loaded from a shader bundle asset.
const Shader::UniformBinding * GetUniformStruct(const std::string &name) const
impeller::ShaderStage GetShaderStage() const
bool IsRegistered(Context &context)
bool RegisterSync(Context &context)
void ResetFrom(Shader &other)
const std::vector< impeller::ShaderStageIOSlot > & GetStageInputs() const
std::shared_ptr< impeller::VertexDescriptor > CreateVertexDescriptor() const
static fml::RefPtr< Shader > Make(std::string library_id, std::string entrypoint, impeller::ShaderStage stage, std::shared_ptr< fml::Mapping > code_mapping, std::vector< impeller::ShaderStageIOSlot > inputs, std::vector< impeller::ShaderStageBufferLayout > layouts, std::unordered_map< std::string, UniformBinding > uniform_structs, std::unordered_map< std::string, TextureBinding > uniform_textures, std::vector< impeller::DescriptorSetLayout > descriptor_set_layouts)
const std::vector< impeller::ShaderStageBufferLayout > & GetStageBufferLayouts() const
const std::vector< impeller::DescriptorSetLayout > & GetDescriptorSetLayouts() const
const Shader::TextureBinding * GetUniformTexture(const std::string &name) const
std::shared_ptr< const impeller::ShaderFunction > GetFunctionFromLibrary(impeller::ShaderLibrary &library)
virtual std::shared_ptr< const ShaderFunction > GetFunction(std::string_view name, ShaderStage stage)=0
#define IMPLEMENT_WRAPPERTYPEINFO(LibraryName, ClassName)
int InternalFlutterGpu_Shader_GetUniformStructSize(flutter::gpu::Shader *wrapper, Dart_Handle struct_name_handle)
bool InternalFlutterGpu_Shader_DebugIsDirty(flutter::gpu::Shader *wrapper)
int InternalFlutterGpu_Shader_GetUniformMemberOffset(flutter::gpu::Shader *wrapper, Dart_Handle struct_name_handle, Dart_Handle member_name_handle)
DEF_SWITCHES_START aot vmservice shared library name
internal::CopyableLambda< T > MakeCopyable(T lambda)
std::string StdStringFromDart(Dart_Handle handle)
std::shared_ptr< ContextGLES > context
static constexpr std::string_view kScopeFlutterGPU
Scope tag for Flutter GPU user shader bundles.
static std::string MakeUserScopedName(std::string_view scope, std::string_view library_id, std::string_view entrypoint)