10 #include "fml/mapping.h"
14 #include "impeller/runtime_stage/runtime_stage_flatbuffers.h"
15 #include "runtime_stage_types_flatbuffers.h"
33 case fb::Stage::kVertex:
35 case fb::Stage::kFragment:
37 case fb::Stage::kCompute:
48 "_RESERVED_IDENTIFIER_FIXUP_gl_DefaultUniformBlock";
50 std::unique_ptr<RuntimeStage> RuntimeStage::RuntimeStageIfPresent(
51 const fb::RuntimeStage* runtime_stage,
52 const std::shared_ptr<fml::Mapping>& payload) {
57 return std::unique_ptr<RuntimeStage>(
62 const std::shared_ptr<fml::Mapping>& payload) {
63 if (payload ==
nullptr || !payload->GetMapping()) {
66 if (!fb::RuntimeStagesBufferHasIdentifier(payload->GetMapping())) {
70 auto raw_stages = fb::GetRuntimeStages(payload->GetMapping());
73 RuntimeStageIfPresent(raw_stages->sksl(), payload)},
75 RuntimeStageIfPresent(raw_stages->metal(), payload)},
77 RuntimeStageIfPresent(raw_stages->opengles(), payload)},
79 RuntimeStageIfPresent(raw_stages->opengles3(), payload)},
81 RuntimeStageIfPresent(raw_stages->vulkan(), payload)},
86 const std::shared_ptr<fml::Mapping>& payload)
88 FML_DCHECK(runtime_stage);
91 entrypoint_ = runtime_stage->entrypoint()->str();
93 auto* uniforms = runtime_stage->uniforms();
99 std::optional<size_t> ubo_id;
101 for (
auto i = uniforms->begin(), end = uniforms->end(); i != end; i++) {
103 desc.
name = i->name()->str();
112 static_cast<size_t>(i->rows()),
static_cast<size_t>(i->columns())};
115 if (i->struct_layout()) {
116 for (
const auto& byte_type : *i->struct_layout()) {
117 desc.
struct_layout.push_back(
static_cast<uint8_t
>(byte_type));
121 uniforms_.push_back(std::move(desc));
125 code_mapping_ = std::make_shared<fml::NonOwnedMapping>(
126 runtime_stage->shader()->data(),
127 runtime_stage->shader()->size(),
128 [payload = payload_](
auto,
auto) {}
132 if (ubo_id.has_value() && ubo_id.value() == binding) {
135 for (
auto& uniform : uniforms_) {
137 uniform.binding = binding;
139 if (ubo_id.has_value() && ubo_id.value() == binding) {
148 static_cast<uint32_t
>(uniform.location),
154 static_cast<uint32_t
>(uniform.binding),
172 return code_mapping_;
181 const std::string& name)
const {
182 for (
const auto& uniform : uniforms_) {
183 if (uniform.name == name) {
208 return descriptor_set_layouts_;
const std::string & GetEntrypoint() const
RuntimeStage & operator=(RuntimeStage &&)
const std::vector< RuntimeUniformDescription > & GetUniforms() const
const RuntimeUniformDescription * GetUniform(const std::string &name) const
std::map< RuntimeStageBackend, std::shared_ptr< RuntimeStage > > Map
static const char * kVulkanUBOName
static Map DecodeRuntimeStages(const std::shared_ptr< fml::Mapping > &payload)
const std::shared_ptr< fml::Mapping > & GetCodeMapping() const
const std::vector< DescriptorSetLayout > & GetDescriptorSetLayouts() const
RuntimeShaderStage GetShaderStage() const
RuntimeStage(const fb::RuntimeStage *runtime_stage, const std::shared_ptr< fml::Mapping > &payload)
constexpr ShaderStage ToShaderStage(RuntimeShaderStage stage)
static RuntimeUniformType ToType(fb::UniformDataType type)