[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:
Jason Simmons
2024-01-25 11:48:57 -08:00
committed by GitHub
parent 5a1ecec956
commit 2bc62b42f1
4 changed files with 37 additions and 0 deletions

View File

@@ -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, \

View File

@@ -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.

View File

@@ -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",

View 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);
}