10 #include "flutter/fml/logging.h"
11 #include "flutter/fml/make_copyable.h"
17 #include "impeller/entity/runtime_effect.vert.h"
26 std::shared_ptr<RuntimeStage> runtime_stage) {
27 runtime_stage_ = std::move(runtime_stage);
31 std::shared_ptr<std::vector<uint8_t>> uniform_data) {
32 uniform_data_ = std::move(uniform_data);
36 std::vector<TextureInput> texture_inputs) {
37 texture_inputs_ = std::move(texture_inputs);
55 auto library = context->GetShaderLibrary();
63 std::shared_ptr<const ShaderFunction>
function = library->GetFunction(
66 if (
function && runtime_stage_->IsDirty()) {
67 context->GetPipelineLibrary()->RemovePipelinesWithEntryPoint(
function);
68 library->UnregisterFunction(runtime_stage_->GetEntrypoint(),
75 std::promise<bool> promise;
76 auto future = promise.get_future();
78 library->RegisterFunction(
79 runtime_stage_->GetEntrypoint(),
81 runtime_stage_->GetCodeMapping(),
82 fml::MakeCopyable([promise = std::move(promise)](
bool result)
mutable {
83 promise.set_value(result);
88 << runtime_stage_->GetEntrypoint() <<
")";
92 function = library->GetFunction(runtime_stage_->GetEntrypoint(),
96 <<
"Failed to fetch runtime effect function immediately after "
97 "registering it (entry point: "
98 << runtime_stage_->GetEntrypoint() <<
")";
102 runtime_stage_->SetClean();
109 auto geometry_result =
110 GetGeometry()->GetPositionBuffer(renderer, entity, pass);
116 const auto& caps = context->GetCapabilities();
117 const auto color_attachment_format = caps->GetDefaultColorFormat();
118 const auto stencil_attachment_format = caps->GetDefaultStencilFormat();
120 using VS = RuntimeEffectVertexShader;
127 auto vertex_descriptor = std::make_shared<VertexDescriptor>();
128 vertex_descriptor->SetStageInputs(VS::kAllShaderStageInputs,
129 VS::kInterleavedBufferLayout);
132 0u, {.format = color_attachment_format, .blending_enabled =
true});
140 if (geometry_result.prevent_overdraw) {
144 options.primitive_type = geometry_result.type;
145 options.ApplyToPipelineDescriptor(desc);
147 auto pipeline = context->GetPipelineLibrary()->GetPipeline(desc).Get();
149 VALIDATION_LOG <<
"Failed to get or create runtime effect pipeline.";
163 VS::FrameInfo frame_info;
164 frame_info.mvp = geometry_result.transform;
171 size_t minimum_sampler_index = 100000000;
172 size_t buffer_index = 0;
173 size_t buffer_offset = 0;
174 for (
auto uniform : runtime_stage_->GetUniforms()) {
177 std::shared_ptr<ShaderMetadata> metadata =
178 std::make_shared<ShaderMetadata>();
180 switch (uniform.type) {
190 minimum_sampler_index =
191 std::min(minimum_sampler_index, uniform.location);
198 uniform_data_->data() + buffer_offset, uniform.GetSize(),
202 uniform_slot.
name = uniform.name.c_str();
203 uniform_slot.
ext_res_0 = uniform.location;
207 buffer_offset += uniform.GetSize();
227 size_t sampler_index = 0;
228 for (
auto uniform : runtime_stage_->GetUniforms()) {
233 switch (uniform.type) {
235 FML_DCHECK(sampler_index < texture_inputs_.size());
236 auto& input = texture_inputs_[sampler_index];
239 context->GetSamplerLibrary()->GetSampler(input.sampler_descriptor);
242 image_slot.
name = uniform.name.c_str();
243 image_slot.
texture_index = uniform.location - minimum_sampler_index;
244 image_slot.
sampler_index = uniform.location - minimum_sampler_index;
246 input.texture, sampler);
258 if (geometry_result.prevent_overdraw) {
261 return restore.Render(renderer, entity, pass);
264 #endif // FML_OS_ANDROID