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) {
58 return std::unique_ptr<RuntimeStage>(
63 const std::shared_ptr<fml::Mapping>& payload) {
64 if (payload ==
nullptr || !payload->GetMapping()) {
67 if (!fb::RuntimeStagesBufferHasIdentifier(payload->GetMapping())) {
71 auto raw_stages = fb::GetRuntimeStages(payload->GetMapping());
74 RuntimeStageIfPresent(raw_stages->sksl(), payload)},
76 RuntimeStageIfPresent(raw_stages->metal(), payload)},
78 RuntimeStageIfPresent(raw_stages->opengles(), payload)},
80 RuntimeStageIfPresent(raw_stages->opengles3(), payload)},
82 RuntimeStageIfPresent(raw_stages->vulkan(), payload)},
87 const std::shared_ptr<fml::Mapping>& payload)
89 FML_DCHECK(runtime_stage);
92 entrypoint_ = runtime_stage->entrypoint()->str();
94 auto* uniforms = runtime_stage->uniforms();
100 std::optional<size_t> ubo_id;
102 for (
auto i = uniforms->begin(),
end = uniforms->end(); i !=
end; i++) {
104 desc.
name = i->name()->str();
113 static_cast<size_t>(i->rows()),
static_cast<size_t>(i->columns())};
116 if (i->struct_layout()) {
117 for (
const auto& byte_type : *i->struct_layout()) {
118 desc.
struct_layout.push_back(
static_cast<uint8_t
>(byte_type));
122 uniforms_.push_back(std::move(desc));
126 code_mapping_ = std::make_shared<fml::NonOwnedMapping>(
127 runtime_stage->shader()->data(),
128 runtime_stage->shader()->size(),
129 [payload = payload_](
auto,
auto) {}
133 if (ubo_id.has_value() && ubo_id.value() == binding) {
136 for (
auto& uniform : uniforms_) {
138 uniform.binding = binding;
140 if (ubo_id.has_value() && ubo_id.value() == binding) {
149 static_cast<uint32_t
>(uniform.location),
155 static_cast<uint32_t
>(uniform.binding),
173 return code_mapping_;
182 const std::string& name)
const {
183 for (
const auto& uniform : uniforms_) {
184 if (uniform.name == name) {
209 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)