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

Commit d4d9537

Browse files
authored
[Impeller] Make stage compatibility checker work with stages that have no inputs or outputs. (#54406)
Also removes the workarounds and updates the docstring to talk about the PowerVR hack. I came across this while fixing #54375. Fixes flutter/flutter#146852
1 parent c2584c3 commit d4d9537

File tree

2 files changed

+26
-25
lines changed

2 files changed

+26
-25
lines changed

impeller/compiler/code_gen_template.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,7 @@ struct {{camel_case(shader_name)}}{{camel_case(shader_stage)}}Shader {
7575
// ===========================================================================
7676
// Stage Inputs ==============================================================
7777
// ===========================================================================
78-
{% if length(stage_inputs) > 0 %}
7978
{% for stage_input in stage_inputs %}
80-
8179
static constexpr auto kInput{{camel_case(stage_input.name)}} = ShaderStageIOSlot { // {{stage_input.name}}
8280
"{{stage_input.name}}", // name
8381
{{stage_input.location}}u, // attribute location
@@ -91,7 +89,6 @@ struct {{camel_case(shader_name)}}{{camel_case(shader_stage)}}Shader {
9189
{{stage_input.relaxed_precision}}, // relaxed precision
9290
};
9391
{% endfor %}
94-
{% endif %}
9592
9693
static constexpr std::array<const ShaderStageIOSlot*, {{length(stage_inputs)}}> kAllShaderStageInputs = {
9794
{% for stage_input in stage_inputs %}
@@ -131,7 +128,6 @@ struct {{camel_case(shader_name)}}{{camel_case(shader_stage)}}Shader {
131128
// ===========================================================================
132129
// Stage Outputs =============================================================
133130
// ===========================================================================
134-
{% if length(stage_outputs) > 0 %}
135131
{% for stage_output in stage_outputs %}
136132
static constexpr auto kOutput{{camel_case(stage_output.name)}} = ShaderStageIOSlot { // {{stage_output.name}}
137133
"{{stage_output.name}}", // name
@@ -151,7 +147,6 @@ struct {{camel_case(shader_name)}}{{camel_case(shader_stage)}}Shader {
151147
&kOutput{{camel_case(stage_output.name)}}, // {{stage_output.name}}
152148
{% endfor %}
153149
};
154-
{% endif %}
155150
156151
// ===========================================================================
157152
// Resource Binding Utilities ================================================

impeller/renderer/shader_stage_compatibility_checker.h

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,31 @@
1010
#include "impeller/core/shader_types.h"
1111

1212
namespace impeller {
13-
/// This is a classed use to check that the input slots of fragment shaders
14-
/// match the output slots of the vertex shaders.
15-
/// If they don't match it will result in linker errors when creating the
16-
/// pipeline. It's not used at runtime.
13+
14+
//------------------------------------------------------------------------------
15+
/// @brief Checks, at C++ compile-time, if the two pipeline stages are
16+
/// compatible.
17+
///
18+
/// Stages may be incompatible if the outputs declared in the vertex
19+
/// stage don't line up with the inputs declared in the fragment
20+
/// stage. Additionally, the types of the inputs and outputs need to
21+
/// be identical. Some drivers like the one on the PowerVR GE8320
22+
/// also have bugs the require the precision qualifier of the stage
23+
/// interfaces to match exactly.
24+
///
25+
/// Not ensuring stage compatibility will cause pipeline creation
26+
/// errors that will only be caught at runtime. In addition to the
27+
/// bugs discovered related to precision qualifier, some errors may
28+
/// only manifest at runtime on some devices.
29+
///
30+
/// This static compile-time C++ check ensures that all the possible
31+
/// runtime errors will be caught at build time.
32+
///
33+
/// There is no runtime overhead to using this class.
34+
///
35+
/// @tparam VertexShaderT The vertex shader stage metadata.
36+
/// @tparam FragmentShaderT The fragment shader stage metadata.
37+
///
1738
template <typename VertexShaderT, typename FragmentShaderT>
1839
class ShaderStageCompatibilityChecker {
1940
public:
@@ -59,21 +80,6 @@ class ShaderStageCompatibilityChecker {
5980
}
6081
};
6182

62-
// The following shaders don't define output slots.
63-
// TODO(https://github.com/flutter/flutter/issues/146852): Make impellerc emit
64-
// an empty array for output slots.
65-
struct ClipVertexShader;
66-
struct SolidFillVertexShader;
67-
68-
template <typename FragmentShaderT>
69-
class ShaderStageCompatibilityChecker<ClipVertexShader, FragmentShaderT> {
70-
public:
71-
static constexpr bool Check() { return true; }
72-
};
73-
template <typename FragmentShaderT>
74-
class ShaderStageCompatibilityChecker<SolidFillVertexShader, FragmentShaderT> {
75-
public:
76-
static constexpr bool Check() { return true; }
77-
};
7883
} // namespace impeller
84+
7985
#endif // FLUTTER_IMPELLER_RENDERER_SHADER_STAGE_COMPATIBILITY_CHECKER_H_

0 commit comments

Comments
 (0)