11 #include "fml/mapping.h"
15 #include "impeller/runtime_stage/runtime_stage_flatbuffers.h"
16 #include "runtime_stage_types_flatbuffers.h"
34 case fb::Stage::kVertex:
36 case fb::Stage::kFragment:
38 case fb::Stage::kCompute:
49 "_RESERVED_IDENTIFIER_FIXUP_gl_DefaultUniformBlock";
52 const fb::RuntimeStage* runtime_stage,
53 const std::shared_ptr<fml::Mapping>& payload) {
55 return absl::InvalidArgumentError(
"Runtime stage is null.");
60 stage.entrypoint_ = runtime_stage->entrypoint()->str();
62 auto* uniforms = runtime_stage->uniforms();
68 std::optional<size_t> ubo_id;
70 for (
auto i = uniforms->begin(),
end = uniforms->end(); i !=
end; i++) {
72 desc.
name = i->name()->str();
81 static_cast<size_t>(i->rows()),
static_cast<size_t>(i->columns())};
84 if (i->struct_layout()) {
85 for (
const auto& byte_type : *i->struct_layout()) {
86 desc.
struct_layout.push_back(
static_cast<uint8_t
>(byte_type));
90 stage.uniforms_.push_back(std::move(desc));
94 stage.code_mapping_ = std::make_shared<fml::NonOwnedMapping>(
95 runtime_stage->shader()->data(),
96 runtime_stage->shader()->size(),
97 [payload = stage.payload_](
auto,
auto) {}
101 if (ubo_id.has_value() && ubo_id.value() == binding) {
104 for (
auto& uniform : stage.uniforms_) {
106 uniform.binding = binding;
108 if (ubo_id.has_value() && ubo_id.value() == binding) {
117 static_cast<uint32_t
>(uniform.location),
123 static_cast<uint32_t
>(uniform.binding),
133 std::unique_ptr<RuntimeStage> RuntimeStage::RuntimeStageIfPresent(
134 const fb::RuntimeStage* runtime_stage,
135 const std::shared_ptr<fml::Mapping>& payload) {
136 auto stage =
Create(runtime_stage, payload);
140 return std::make_unique<RuntimeStage>(std::move(*stage));
144 const std::shared_ptr<fml::Mapping>& payload) {
145 if (payload ==
nullptr || !payload->GetMapping()) {
146 return absl::InvalidArgumentError(
"Payload is null or empty.");
148 if (!fb::RuntimeStagesBufferHasIdentifier(payload->GetMapping())) {
149 return absl::InvalidArgumentError(
150 "Payload does not have valid identifier.");
153 auto raw_stages = fb::GetRuntimeStages(payload->GetMapping());
155 return absl::InvalidArgumentError(
"Failed to get runtime stages.");
158 const uint32_t version = raw_stages->format_version();
159 const auto expected =
160 static_cast<uint32_t
>(fb::RuntimeStagesFormatVersion::kVersion);
161 if (version != expected) {
162 std::stringstream stream;
163 stream <<
"Unsupported runtime stages format version. Expected " << expected
164 <<
", got " << version <<
".";
165 return absl::InvalidArgumentError(stream.str());
170 RuntimeStageIfPresent(raw_stages->sksl(), payload)},
172 RuntimeStageIfPresent(raw_stages->metal(), payload)},
174 RuntimeStageIfPresent(raw_stages->opengles(), payload)},
176 RuntimeStageIfPresent(raw_stages->opengles3(), payload)},
178 RuntimeStageIfPresent(raw_stages->vulkan(), payload)},
183 : payload_(
std::move(payload)) {}
190 return code_mapping_;
199 const std::string& name)
const {
200 for (
const auto& uniform : uniforms_) {
201 if (uniform.name == name) {
226 return descriptor_set_layouts_;
RuntimeStage(RuntimeStage &&)
const std::string & GetEntrypoint() const
RuntimeStage & operator=(RuntimeStage &&)
static absl::StatusOr< RuntimeStage > Create(const fb::RuntimeStage *runtime_stage, const std::shared_ptr< fml::Mapping > &payload)
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
const std::shared_ptr< fml::Mapping > & GetCodeMapping() const
const std::vector< DescriptorSetLayout > & GetDescriptorSetLayouts() const
static absl::StatusOr< Map > DecodeRuntimeStages(const std::shared_ptr< fml::Mapping > &payload)
RuntimeShaderStage GetShaderStage() const
constexpr ShaderStage ToShaderStage(RuntimeShaderStage stage)
static RuntimeUniformType ToType(fb::UniformDataType type)