File tree 4 files changed +54
-2
lines changed
4 files changed +54
-2
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,14 @@ TEST_P(CompilerTest, CanCompile) {
24
24
ASSERT_TRUE (CanCompileAndReflect (" sample.vert" ));
25
25
}
26
26
27
+ TEST_P (CompilerTest, MustFailDueToMultipleLocationPerStructMember) {
28
+ if (GetParam () == TargetPlatform::kFlutterSPIRV ) {
29
+ // This is a failure of reflection which this target doesn't perform.
30
+ GTEST_SKIP ();
31
+ }
32
+ ASSERT_FALSE (CanCompileAndReflect (" struct_def_bug.vert" ));
33
+ }
34
+
27
35
#define INSTANTIATE_TARGET_PLATFORM_TEST_SUITE_P (suite_name ) \
28
36
INSTANTIATE_TEST_SUITE_P ( \
29
37
suite_name, CompilerTest, \
Original file line number Diff line number Diff line change @@ -232,11 +232,16 @@ std::optional<nlohmann::json> Reflector::GenerateTemplateArguments() const {
232
232
auto & struct_definitions = root[" struct_definitions" ] =
233
233
nlohmann::json::array_t {};
234
234
if (entrypoints.front ().execution_model ==
235
- spv::ExecutionModel::ExecutionModelVertex) {
235
+ spv::ExecutionModel::ExecutionModelVertex &&
236
+ !shader_resources.stage_inputs .empty ()) {
236
237
if (auto struc =
237
238
ReflectPerVertexStructDefinition (shader_resources.stage_inputs );
238
239
struc.has_value ()) {
239
240
struct_definitions.emplace_back (EmitStructDefinition (struc.value ()));
241
+ } else {
242
+ // If there are stage inputs, it is an error to not generate a per
243
+ // vertex data struct for a vertex like shader stage.
244
+ return std::nullopt;
240
245
}
241
246
}
242
247
@@ -662,7 +667,10 @@ Reflector::ReflectPerVertexStructDefinition(
662
667
663
668
for (size_t i = 0 ; i < locations.size (); i++) {
664
669
if (locations.count (i) != 1 ) {
665
- // Locations are not contiguous. Bail.
670
+ // Locations are not contiguous. This usually happens when a single stage
671
+ // input takes multiple input slots. No reflection information can be
672
+ // generated for such cases anyway. So bail! It is up to the shader author
673
+ // to make sure one stage input maps to a single input slot.
666
674
return std::nullopt;
667
675
}
668
676
}
@@ -677,6 +685,7 @@ Reflector::ReflectPerVertexStructDefinition(
677
685
}
678
686
}
679
687
// This really cannot happen with all the validation above.
688
+ FML_UNREACHABLE ();
680
689
return nullptr ;
681
690
};
682
691
Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ test_fixtures("file_fixtures") {
27
27
" embarcadero.jpg" ,
28
28
" kalimba.jpg" ,
29
29
" sample.vert" ,
30
+ " struct_def_bug.vert" ,
30
31
" types.h" ,
31
32
" test_texture.frag" ,
32
33
" //flutter/third_party/txt/third_party/fonts/Roboto-Regular.ttf" ,
Original file line number Diff line number Diff line change
1
+ // Copyright 2013 The Flutter Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+
5
+ uniform FrameInfo {
6
+ mat4 mvp;
7
+ vec2 atlas_size;
8
+ vec4 text_color;
9
+ } frame_info;
10
+
11
+ in vec2 unit_vertex;
12
+ in mat4 glyph_position; // <--- Causes multiple slots to be used and is a failure.
13
+ in vec2 glyph_size;
14
+ in vec2 atlas_position;
15
+ in vec2 atlas_glyph_size;
16
+
17
+ out vec2 v_unit_vertex;
18
+ out vec2 v_atlas_position;
19
+ out vec2 v_atlas_glyph_size;
20
+ out vec2 v_atlas_size;
21
+ out vec4 v_text_color;
22
+
23
+ void main() {
24
+ gl_Position = frame_info.mvp
25
+ * glyph_position
26
+ * vec4 (unit_vertex.x * glyph_size.x,
27
+ unit_vertex.y * glyph_size.y, 0.0 , 1.0 );
28
+
29
+ v_unit_vertex = unit_vertex;
30
+ v_atlas_position = atlas_position;
31
+ v_atlas_glyph_size = atlas_glyph_size;
32
+ v_atlas_size = frame_info.atlas_size;
33
+ v_text_color = frame_info.text_color;
34
+ }
You can’t perform that action at this time.
0 commit comments