Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
shader.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_LIB_GPU_SHADER_H_
6#define FLUTTER_LIB_GPU_SHADER_H_
7
8#include <algorithm>
9#include <memory>
10#include <string>
11
14#include "fml/memory/ref_ptr.h"
18
19namespace flutter {
20namespace gpu {
21
22/// An immutable collection of shaders loaded from a shader bundle asset.
23class Shader : public RefCountedDartWrappable<Shader> {
24 DEFINE_WRAPPERTYPEINFO();
26
27 public:
36
41
42 ~Shader() override;
43
45 std::string library_id,
46 std::string entrypoint,
48 std::shared_ptr<fml::Mapping> code_mapping,
49 std::vector<impeller::ShaderStageIOSlot> inputs,
50 std::vector<impeller::ShaderStageBufferLayout> layouts,
51 std::unordered_map<std::string, UniformBinding> uniform_structs,
52 std::unordered_map<std::string, TextureBinding> uniform_textures,
53 std::vector<impeller::DescriptorSetLayout> descriptor_set_layouts);
54
55 std::shared_ptr<const impeller::ShaderFunction> GetFunctionFromLibrary(
57
59
61
62 /// Whether this shader needs to be re-registered with the impeller shader
63 /// library on next use. Fresh shaders start dirty. Set back to false by
64 /// `RegisterSync` after registration completes, and back to true by
65 /// `ResetFrom` when the underlying asset is reloaded.
66 bool IsDirty() const;
67
68 void SetClean();
69
70 /// Replaces this shader's payload (code, layouts, uniforms) with the data
71 /// from `other`, preserving the library_id / entrypoint registry key and
72 /// marking this shader dirty. Used by `ShaderLibrary` to reload a shader
73 /// bundle in place without breaking existing Dart wrappers.
74 void ResetFrom(Shader& other);
75
76 std::shared_ptr<impeller::VertexDescriptor> CreateVertexDescriptor() const;
77
78 const std::vector<impeller::ShaderStageIOSlot>& GetStageInputs() const;
79
80 const std::vector<impeller::ShaderStageBufferLayout>& GetStageBufferLayouts()
81 const;
82
83 const std::vector<impeller::DescriptorSetLayout>& GetDescriptorSetLayouts()
84 const;
85
87
88 const Shader::UniformBinding* GetUniformStruct(const std::string& name) const;
89
91 const std::string& name) const;
92
93 private:
94 Shader();
95
96 // Stable per-source identifier used to namespace this shader's entrypoint
97 // in the shared shader registry. Set by ShaderLibrary at construction, and
98 // shared by all shaders within the same library. Typically the asset path
99 // the bundle was loaded from.
100 std::string library_id_;
101 std::string entrypoint_;
103 std::shared_ptr<fml::Mapping> code_mapping_;
104 std::vector<impeller::ShaderStageIOSlot> inputs_;
105 std::vector<impeller::ShaderStageBufferLayout> layouts_;
106 std::unordered_map<std::string, UniformBinding> uniform_structs_;
107 std::unordered_map<std::string, TextureBinding> uniform_textures_;
108 std::vector<impeller::DescriptorSetLayout> descriptor_set_layouts_;
109 bool is_dirty_ = true;
110
111 // Returns the scoped name to use when registering or looking up this
112 // shader's function in a shared impeller::ShaderLibrary.
113 std::string GetScopedName() const;
114
116};
117
118} // namespace gpu
119} // namespace flutter
120
121//----------------------------------------------------------------------------
122/// Exports
123///
124
125extern "C" {
126
129 flutter::gpu::Shader* wrapper,
130 Dart_Handle struct_name_handle);
131
134 flutter::gpu::Shader* wrapper,
135 Dart_Handle struct_name_handle,
136 Dart_Handle member_name_handle);
137
138// Test-only: exposes the per-shader dirty bit so tests can assert that
139// reload deduplication keeps unchanged shaders clean.
142 flutter::gpu::Shader* wrapper);
143
144} // extern "C"
145
146#endif // FLUTTER_LIB_GPU_SHADER_H_
An immutable collection of shaders loaded from a shader bundle asset.
Definition shader.h:23
const Shader::UniformBinding * GetUniformStruct(const std::string &name) const
Definition shader.cc:176
impeller::ShaderStage GetShaderStage() const
Definition shader.cc:167
bool IsRegistered(Context &context)
Definition shader.cc:74
bool RegisterSync(Context &context)
Definition shader.cc:118
void ResetFrom(Shader &other)
Definition shader.cc:87
const std::vector< impeller::ShaderStageIOSlot > & GetStageInputs() const
Definition shader.cc:158
std::shared_ptr< impeller::VertexDescriptor > CreateVertexDescriptor() const
Definition shader.cc:151
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)
Definition shader.cc:41
const std::vector< impeller::ShaderStageBufferLayout > & GetStageBufferLayouts() const
Definition shader.cc:163
const std::vector< impeller::DescriptorSetLayout > & GetDescriptorSetLayouts() const
Definition shader.cc:172
bool IsDirty() const
Definition shader.cc:79
const Shader::TextureBinding * GetUniformTexture(const std::string &name) const
Definition shader.cc:185
std::shared_ptr< const impeller::ShaderFunction > GetFunctionFromLibrary(impeller::ShaderLibrary &library)
Definition shader.cc:69
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition macros.h:27
FLUTTER_GPU_EXPORT int InternalFlutterGpu_Shader_GetUniformMemberOffset(flutter::gpu::Shader *wrapper, Dart_Handle struct_name_handle, Dart_Handle member_name_handle)
Definition shader.cc:213
FLUTTER_GPU_EXPORT bool InternalFlutterGpu_Shader_DebugIsDirty(flutter::gpu::Shader *wrapper)
Definition shader.cc:232
FLUTTER_GPU_EXPORT int InternalFlutterGpu_Shader_GetUniformStructSize(flutter::gpu::Shader *wrapper, Dart_Handle struct_name_handle)
Definition shader.cc:201
#define FLUTTER_GPU_EXPORT
Definition export.h:13
DEF_SWITCHES_START aot vmservice shared library name
Definition switch_defs.h:27
#define FML_FRIEND_MAKE_REF_COUNTED(T)
std::shared_ptr< ContextGLES > context
impeller::SampledImageSlot slot
Definition shader.h:38
impeller::ShaderMetadata metadata
Definition shader.h:39
impeller::ShaderMetadata metadata
Definition shader.h:30
impeller::ShaderUniformSlot slot
Definition shader.h:29
const impeller::ShaderStructMemberMetadata * GetMemberMetadata(const std::string &name) const
Definition shader.cc:23
Metadata required to bind a combined texture and sampler.
Metadata required to bind a buffer.