Begin wiring up struct definitions.
This commit is contained in:
@@ -26,7 +26,6 @@ source_set("compiler_lib") {
|
||||
"//third_party/rapidjson",
|
||||
"//third_party/shaderc_flutter",
|
||||
"//third_party/spirv_cross_flutter",
|
||||
"//third_party/spirv_reflect_flutter",
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,20 @@ struct {{camel_case(shader_name)}}{{camel_case(shader_stage)}}Info {
|
||||
static constexpr std::string_view kEntrypointName = "{{entrypoint}}";
|
||||
static constexpr ShaderStage kShaderStage = {{to_shader_stage(shader_stage)}};
|
||||
|
||||
|
||||
// ===========================================================================
|
||||
// Struct Definitions ========================================================
|
||||
// ===========================================================================
|
||||
{% for def in struct_definitions %}
|
||||
|
||||
struct {{def.name}} {
|
||||
{% for member in def.members %}
|
||||
{{member.type}} {{member.name}};
|
||||
{% endfor %}
|
||||
}; // struct {{def.name}}
|
||||
static_assert(sizeof({{def.name}}) == {{def.byte_length}}, "Size of {{def.name}} does not match {{def.byte_length}} in the shader.");
|
||||
{% endfor %}
|
||||
|
||||
// ===========================================================================
|
||||
// Stage Uniforms ============================================================
|
||||
// ===========================================================================
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include <atomic>
|
||||
#include <optional>
|
||||
#include <set>
|
||||
#include <sstream>
|
||||
|
||||
#include "flutter/fml/closure.h"
|
||||
@@ -186,7 +187,14 @@ std::optional<nlohmann::json> Reflector::GenerateTemplateArguments() const {
|
||||
|
||||
auto& struct_definitions = root["struct_definitions"] =
|
||||
nlohmann::json::array_t{};
|
||||
std::set<spirv_cross::ID> known_structs;
|
||||
ir_->for_each_typed_id<SPIRType>([&](uint32_t, const SPIRType& type) {
|
||||
if (known_structs.find(type.self) != known_structs.end()) {
|
||||
// Iterating over types this way leads to duplicates which may cause
|
||||
// duplicate struct definitions.
|
||||
return;
|
||||
}
|
||||
known_structs.insert(type.self);
|
||||
if (auto struc = ReflectStructDefinition(type.self); struc.has_value()) {
|
||||
struct_definitions.emplace_back(std::move(struc.value()));
|
||||
}
|
||||
@@ -274,6 +282,21 @@ std::optional<nlohmann::json::array_t> Reflector::ReflectResources(
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string GetHostStructMemberType(const SPIRType& type) {
|
||||
if (type.width == 32 && type.columns == 1 && type.vecsize == 1) {
|
||||
return "float";
|
||||
}
|
||||
|
||||
if (type.width == 32 && type.columns == 4 && type.vecsize == 4) {
|
||||
return "Matrix";
|
||||
}
|
||||
|
||||
const auto byte_length = (type.width * type.vecsize * type.columns) / 8u;
|
||||
std::stringstream stream;
|
||||
stream << "Padding<" << byte_length << ">";
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
std::optional<nlohmann::json::object_t> Reflector::ReflectStructDefinition(
|
||||
const TypeID& type_id) const {
|
||||
const auto& type = compiler_->get_type(type_id);
|
||||
@@ -296,6 +319,7 @@ std::optional<nlohmann::json::object_t> Reflector::ReflectStructDefinition(
|
||||
(member_type.width * member_type.vecsize * member_type.columns) / 8u;
|
||||
auto& member = struc["members"].emplace_back(nlohmann::json::object_t{});
|
||||
member["name"] = GetMemberNameAtIndex(type, i);
|
||||
member["type"] = GetHostStructMemberType(member_type);
|
||||
member["byte_length"] = byte_length;
|
||||
member["offset"] = total_size;
|
||||
total_size += byte_length;
|
||||
|
||||
@@ -4,9 +4,11 @@
|
||||
|
||||
uniform UniformBuffer {
|
||||
mat4 mvp;
|
||||
mat4 mvp2;
|
||||
mat4x2 mvp2;
|
||||
mat4 mvp3;
|
||||
mat4 mvp4;
|
||||
bool foo;
|
||||
float hello;
|
||||
mat4 mvp5;
|
||||
} uniforms;
|
||||
|
||||
|
||||
@@ -17,4 +17,6 @@ impeller_component("shader_glue") {
|
||||
"shader_types.cc",
|
||||
"shader_types.h",
|
||||
]
|
||||
|
||||
deps = [ "../geometry" ]
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
#include <cstddef>
|
||||
#include <string_view>
|
||||
|
||||
#include "impeller/geometry/matrix.h"
|
||||
|
||||
namespace impeller {
|
||||
|
||||
enum class ShaderStage {
|
||||
@@ -47,4 +49,10 @@ struct ShaderStageIOSlot {
|
||||
size_t columns;
|
||||
};
|
||||
|
||||
template <size_t Size>
|
||||
struct Padding {
|
||||
private:
|
||||
uint8_t pad_[Size];
|
||||
};
|
||||
|
||||
} // namespace impeller
|
||||
|
||||
Reference in New Issue
Block a user