[Impeller] Do not emit metadata for structs that are not part of the shader's interface (flutter/engine#50029)
Fixes https://github.com/flutter/flutter/issues/138404
This commit is contained in:
@@ -142,6 +142,14 @@ TEST_P(CompilerTest, SkSLTextureLookUpOrderOfOperations) {
|
||||
"flutter_FragCoord.xy));") != -1);
|
||||
}
|
||||
|
||||
TEST_P(CompilerTest, CanCompileStructs) {
|
||||
if (GetParam() != TargetPlatform::kSkSL) {
|
||||
GTEST_SKIP() << "Only supported on SkSL";
|
||||
}
|
||||
ASSERT_TRUE(CanCompileAndReflect("struct_internal.frag",
|
||||
SourceType::kFragmentShader));
|
||||
}
|
||||
|
||||
#define INSTANTIATE_TARGET_PLATFORM_TEST_SUITE_P(suite_name) \
|
||||
INSTANTIATE_TEST_SUITE_P( \
|
||||
suite_name, CompilerTest, \
|
||||
|
||||
@@ -258,6 +258,18 @@ std::optional<nlohmann::json> Reflector::GenerateTemplateArguments() const {
|
||||
std::set<spirv_cross::ID> known_structs;
|
||||
ir_->for_each_typed_id<spirv_cross::SPIRType>(
|
||||
[&](uint32_t, const spirv_cross::SPIRType& type) {
|
||||
if (type.basetype != spirv_cross::SPIRType::BaseType::Struct) {
|
||||
return;
|
||||
}
|
||||
// Skip structs that do not have layout offset decorations.
|
||||
// These structs are used internally within the shader and are not
|
||||
// part of the shader's interface.
|
||||
for (size_t i = 0; i < type.member_types.size(); i++) {
|
||||
if (!compiler_->has_member_decoration(type.self, i,
|
||||
spv::DecorationOffset)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (known_structs.find(type.self) != known_structs.end()) {
|
||||
// Iterating over types this way leads to duplicates which may cause
|
||||
// duplicate struct definitions.
|
||||
|
||||
@@ -101,6 +101,7 @@ test_fixtures("file_fixtures") {
|
||||
"stage1.comp",
|
||||
"stage2.comp",
|
||||
"struct_def_bug.vert",
|
||||
"struct_internal.frag",
|
||||
"table_mountain_nx.png",
|
||||
"table_mountain_ny.png",
|
||||
"table_mountain_nz.png",
|
||||
|
||||
16
engine/src/flutter/impeller/fixtures/struct_internal.frag
Normal file
16
engine/src/flutter/impeller/fixtures/struct_internal.frag
Normal file
@@ -0,0 +1,16 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
out vec4 frag_color;
|
||||
|
||||
struct TestStruct {
|
||||
float a;
|
||||
float b;
|
||||
float c;
|
||||
};
|
||||
|
||||
void main() {
|
||||
TestStruct ts = TestStruct(1.0, 0.5, 0.25);
|
||||
frag_color = vec4(ts.c, ts.b, ts.a, 1.0);
|
||||
}
|
||||
Reference in New Issue
Block a user