Flutter Engine
 
Loading...
Searching...
No Matches
flutter::gpu::Shader Class Reference

An immutable collection of shaders loaded from a shader bundle asset. More...

#include <shader.h>

Inheritance diagram for flutter::gpu::Shader:
flutter::RefCountedDartWrappable< Shader > fml::RefCountedThreadSafe< T > tonic::DartWrappable fml::internal::RefCountedThreadSafeBase

Classes

struct  TextureBinding
 
struct  UniformBinding
 

Public Member Functions

 ~Shader () override
 
std::shared_ptr< const impeller::ShaderFunctionGetFunctionFromLibrary (impeller::ShaderLibrary &library)
 
bool IsRegistered (Context &context)
 
bool RegisterSync (Context &context)
 
std::shared_ptr< impeller::VertexDescriptorCreateVertexDescriptor () const
 
const std::vector< impeller::DescriptorSetLayout > & GetDescriptorSetLayouts () const
 
impeller::ShaderStage GetShaderStage () const
 
const Shader::UniformBindingGetUniformStruct (const std::string &name) const
 
const Shader::TextureBindingGetUniformTexture (const std::string &name) const
 
- Public Member Functions inherited from flutter::RefCountedDartWrappable< Shader >
virtual void RetainDartWrappableReference () const override
 
virtual void ReleaseDartWrappableReference () const override
 
- Public Member Functions inherited from fml::RefCountedThreadSafe< T >
void Release () const
 
- Public Member Functions inherited from fml::internal::RefCountedThreadSafeBase
void AddRef () const
 
bool HasOneRef () const
 
void AssertHasOneRef () const
 
- Public Member Functions inherited from tonic::DartWrappable
 DartWrappable ()
 
virtual const DartWrapperInfoGetDartWrapperInfo () const =0
 
Dart_Handle CreateDartWrapper (DartState *dart_state)
 
void AssociateWithDartWrapper (Dart_Handle wrappable)
 
void ClearDartWrapper ()
 
Dart_WeakPersistentHandle dart_wrapper () const
 

Static Public Member Functions

static fml::RefPtr< ShaderMake (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)
 

Additional Inherited Members

- Public Types inherited from tonic::DartWrappable
enum  DartNativeFields {
  kPeerIndex ,
  kNumberOfNativeFields
}
 
- Protected Member Functions inherited from fml::RefCountedThreadSafe< T >
 RefCountedThreadSafe ()
 
 ~RefCountedThreadSafe ()
 
- Protected Member Functions inherited from fml::internal::RefCountedThreadSafeBase
 RefCountedThreadSafeBase ()
 
 ~RefCountedThreadSafeBase ()
 
bool Release () const
 
void Adopt ()
 
- Protected Member Functions inherited from tonic::DartWrappable
virtual ~DartWrappable ()
 
- Static Protected Member Functions inherited from tonic::DartWrappable
static Dart_PersistentHandle GetTypeForWrapper (tonic::DartState *dart_state, const tonic::DartWrapperInfo &wrapper_info)
 

Detailed Description

An immutable collection of shaders loaded from a shader bundle asset.

Definition at line 23 of file shader.h.

Constructor & Destructor Documentation

◆ ~Shader()

flutter::gpu::Shader::~Shader ( )
overridedefault

Member Function Documentation

◆ CreateVertexDescriptor()

std::shared_ptr< impeller::VertexDescriptor > flutter::gpu::Shader::CreateVertexDescriptor ( ) const

Definition at line 89 of file shader.cc.

90 {
91 auto vertex_descriptor = std::make_shared<impeller::VertexDescriptor>();
92 vertex_descriptor->SetStageInputs(inputs_, layouts_);
93 return vertex_descriptor;
94}

Referenced by flutter::gpu::RenderPipeline::BindToPipelineDescriptor().

◆ GetDescriptorSetLayouts()

const std::vector< impeller::DescriptorSetLayout > & flutter::gpu::Shader::GetDescriptorSetLayouts ( ) const

Definition at line 101 of file shader.cc.

101 {
102 return descriptor_set_layouts_;
103}

Referenced by flutter::gpu::RenderPipeline::BindToPipelineDescriptor().

◆ GetFunctionFromLibrary()

std::shared_ptr< const impeller::ShaderFunction > flutter::gpu::Shader::GetFunctionFromLibrary ( impeller::ShaderLibrary library)

Definition at line 59 of file shader.cc.

60 {
61 return library.GetFunction(entrypoint_, stage_);
62}
virtual std::shared_ptr< const ShaderFunction > GetFunction(std::string_view name, ShaderStage stage)=0

References impeller::ShaderLibrary::GetFunction().

Referenced by flutter::gpu::RenderPipeline::BindToPipelineDescriptor(), and IsRegistered().

◆ GetShaderStage()

impeller::ShaderStage flutter::gpu::Shader::GetShaderStage ( ) const

Definition at line 96 of file shader.cc.

96 {
97 return stage_;
98}

Referenced by BindUniform(), and InternalFlutterGpu_RenderPass_BindTexture().

◆ GetUniformStruct()

const Shader::UniformBinding * flutter::gpu::Shader::GetUniformStruct ( const std::string &  name) const

Definition at line 105 of file shader.cc.

106 {
107 auto uniform = uniform_structs_.find(name);
108 if (uniform == uniform_structs_.end()) {
109 return nullptr;
110 }
111 return &uniform->second;
112}
DEF_SWITCHES_START aot vmservice shared library name
Definition switch_defs.h:27

References flutter::name.

Referenced by BindUniform(), InternalFlutterGpu_Shader_GetUniformMemberOffset(), and InternalFlutterGpu_Shader_GetUniformStructSize().

◆ GetUniformTexture()

const Shader::TextureBinding * flutter::gpu::Shader::GetUniformTexture ( const std::string &  name) const

Definition at line 114 of file shader.cc.

115 {
116 auto uniform = uniform_textures_.find(name);
117 if (uniform == uniform_textures_.end()) {
118 return nullptr;
119 }
120 return &uniform->second;
121}

References flutter::name.

Referenced by InternalFlutterGpu_RenderPass_BindTexture().

◆ IsRegistered()

bool flutter::gpu::Shader::IsRegistered ( Context context)

Definition at line 64 of file shader.cc.

64 {
65 auto& lib = *context.GetContext().GetShaderLibrary();
66 return GetFunctionFromLibrary(lib) != nullptr;
67}
std::shared_ptr< const impeller::ShaderFunction > GetFunctionFromLibrary(impeller::ShaderLibrary &library)
Definition shader.cc:59

References flutter::gpu::Context::GetContext(), GetFunctionFromLibrary(), and impeller::Context::GetShaderLibrary().

Referenced by RegisterSync().

◆ Make()

fml::RefPtr< Shader > flutter::gpu::Shader::Make ( 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 
)
static

Definition at line 38 of file shader.cc.

46 {
47 auto shader = fml::MakeRefCounted<Shader>();
48 shader->entrypoint_ = std::move(entrypoint);
49 shader->stage_ = stage;
50 shader->code_mapping_ = std::move(code_mapping);
51 shader->inputs_ = std::move(inputs);
52 shader->layouts_ = std::move(layouts);
53 shader->uniform_structs_ = std::move(uniform_structs);
54 shader->uniform_textures_ = std::move(uniform_textures);
55 shader->descriptor_set_layouts_ = std::move(descriptor_set_layouts);
56 return shader;
57}

Referenced by flutter::gpu::ShaderLibrary::MakeFromFlatbuffer().

◆ RegisterSync()

bool flutter::gpu::Shader::RegisterSync ( Context context)

Definition at line 69 of file shader.cc.

69 {
70 if (IsRegistered(context)) {
71 return true; // Already registered.
72 }
73
74 auto& lib = *context.GetContext().GetShaderLibrary();
75
76 std::promise<bool> promise;
77 auto future = promise.get_future();
78 lib.RegisterFunction(
79 entrypoint_, stage_, code_mapping_,
80 fml::MakeCopyable([promise = std::move(promise)](bool result) mutable {
81 promise.set_value(result);
82 }));
83 if (!future.get()) {
84 return false; // Registration failed.
85 }
86 return true;
87}
bool IsRegistered(Context &context)
Definition shader.cc:64
internal::CopyableLambda< T > MakeCopyable(T lambda)

References flutter::gpu::Context::GetContext(), impeller::Context::GetShaderLibrary(), IsRegistered(), and fml::MakeCopyable().

Referenced by InternalFlutterGpu_RenderPipeline_Initialize().


The documentation for this class was generated from the following files: