Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 0329772

Browse files
committed
[Impeller] Statically check stage interfaces for precision mismatches.
Fixes flutter/flutter#147078
1 parent 206e86e commit 0329772

File tree

4 files changed

+23
-13
lines changed

4 files changed

+23
-13
lines changed

impeller/compiler/code_gen_template.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ struct {{camel_case(shader_name)}}{{camel_case(shader_stage)}}Shader {
8888
{{stage_input.type.vec_size}}u, // vec size
8989
{{stage_input.type.columns}}u, // number of columns
9090
{{stage_input.offset}}u, // offset for interleaved layout
91+
{{stage_input.relaxed_precision}}, // relaxed precision
9192
};
9293
{% endfor %}
9394
{% endif %}
@@ -140,7 +141,9 @@ struct {{camel_case(shader_name)}}{{camel_case(shader_stage)}}Shader {
140141
{{stage_output.type.type_name}}, // type
141142
{{stage_output.type.bit_width}}u, // bit width of type
142143
{{stage_output.type.vec_size}}u, // vec size
143-
{{stage_output.type.columns}}u // number of columns
144+
{{stage_output.type.columns}}u, // number of columns
145+
{{stage_output.offset}}u, // offset for interleaved layout
146+
{{stage_output.relaxed_precision}}, // relaxed precision
144147
};
145148
{% endfor %}
146149
static constexpr std::array<const ShaderStageIOSlot*, {{length(stage_outputs)}}> kAllShaderStageOutputs = {

impeller/compiler/reflector.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -655,12 +655,15 @@ std::optional<nlohmann::json::object_t> Reflector::ReflectResource(
655655
CompilerBackend::ExtendedResourceIndex::kPrimary, resource.id);
656656
result["ext_res_1"] = compiler_.GetExtendedMSLResourceBinding(
657657
CompilerBackend::ExtendedResourceIndex::kSecondary, resource.id);
658+
result["relaxed_precision"] =
659+
compiler_->get_decoration(
660+
resource.id, spv::Decoration::DecorationRelaxedPrecision) == 1;
661+
result["offset"] = offset.value_or(0u);
658662
auto type = ReflectType(resource.type_id);
659663
if (!type.has_value()) {
660664
return std::nullopt;
661665
}
662666
result["type"] = std::move(type.value());
663-
result["offset"] = offset.value_or(0u);
664667
return result;
665668
}
666669

impeller/core/shader_types.h

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -119,22 +119,25 @@ struct ShaderStageIOSlot {
119119
size_t vec_size;
120120
size_t columns;
121121
size_t offset;
122+
bool relaxed_precision;
122123

123124
constexpr size_t GetHash() const {
124125
return fml::HashCombine(name, location, set, binding, type, bit_width,
125-
vec_size, columns, offset);
126+
vec_size, columns, offset, relaxed_precision);
126127
}
127128

128129
constexpr bool operator==(const ShaderStageIOSlot& other) const {
129-
return name == other.name && //
130-
location == other.location && //
131-
set == other.set && //
132-
binding == other.binding && //
133-
type == other.type && //
134-
bit_width == other.bit_width && //
135-
vec_size == other.vec_size && //
136-
columns == other.columns && //
137-
offset == other.offset;
130+
return name == other.name && //
131+
location == other.location && //
132+
set == other.set && //
133+
binding == other.binding && //
134+
type == other.type && //
135+
bit_width == other.bit_width && //
136+
vec_size == other.vec_size && //
137+
columns == other.columns && //
138+
offset == other.offset && //
139+
relaxed_precision == other.relaxed_precision //
140+
;
138141
}
139142
};
140143

impeller/renderer/shader_stage_compatibility_checker.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ class ShaderStageCompatibilityChecker {
4747
input_slot->bit_width != output_slot->bit_width ||
4848
input_slot->vec_size != output_slot->vec_size ||
4949
input_slot->columns != output_slot->columns ||
50-
input_slot->offset != output_slot->offset) {
50+
input_slot->offset != output_slot->offset ||
51+
input_slot->relaxed_precision != output_slot->relaxed_precision) {
5152
return false;
5253
}
5354
}

0 commit comments

Comments
 (0)