| Flutter Impeller |

Static Public Member Functions | List of all members
impeller::ShaderStageCompatibilityChecker< VertexShaderT, FragmentShaderT > Class Template Reference

Checks, at C++ compile-time, if the two pipeline stages are compatible. More...

`#include <shader_stage_compatibility_checker.h>`

## Static Public Member Functions
static constexpr bool | CompileTimeStrEqual (const char *str1, const char *str2)
static constexpr bool | Check ()

## Detailed Description

### template<typename VertexShaderT, typename FragmentShaderT>
class impeller::ShaderStageCompatibilityChecker< VertexShaderT, FragmentShaderT >

Checks, at C++ compile-time, if the two pipeline stages are compatible.

Stages may be incompatible if the outputs declared in the vertex stage don't line up with the inputs declared in the fragment stage. Additionally, the types of the inputs and outputs need to be identical. Some drivers like the one on the PowerVR GE8320 also have bugs the require the precision qualifier of the stage interfaces to match exactly.

Not ensuring stage compatibility will cause pipeline creation errors that will only be caught at runtime. In addition to the bugs discovered related to precision qualifier, some errors may only manifest at runtime on some devices.

This static compile-time C++ check ensures that all the possible runtime errors will be caught at build time.

There is no runtime overhead to using this class.

Template Parameters

  VertexShaderT | The vertex shader stage metadata.
  FragmentShaderT | The fragment shader stage metadata.

Definition at line 39 of file shader_stage_compatibility_checker.h.

## Member Function Documentation

## ◆ Check()

template<typename VertexShaderT , typename FragmentShaderT >

static constexpr bool impeller::ShaderStageCompatibilityChecker< VertexShaderT, FragmentShaderT >::Check | ( |  | ) |
| inlinestaticconstexpr

Returns `true` if the shader input slots for the fragment shader match the ones declared as outputs in the vertex shader.

Definition at line 49 of file shader_stage_compatibility_checker.h.

49 {
50 constexpr size_t num_outputs = VertexShaderT::kAllShaderStageOutputs.size();
51 constexpr size_t num_inputs = FragmentShaderT::kAllShaderStageInputs.size();
52
53 if (num_inputs > num_outputs) {
54 return false;
55 }
56
57 for (size_t i = 0; i < num_inputs; ++i) {
58 const ShaderStageIOSlot* input_slot =
59 FragmentShaderT::kAllShaderStageInputs[i];
60 for (size_t j = 0; j < num_outputs; ++j) {
61 const ShaderStageIOSlot* output_slot =
62 VertexShaderT::kAllShaderStageOutputs[j];
63 if (input_slot->location == output_slot->location) {
64 if (!CompileTimeStrEqual(input_slot->name, output_slot->name) ||
65 input_slot->set != output_slot->set ||
66 input_slot->binding != output_slot->binding ||
67 input_slot->type != output_slot->type ||
68 input_slot->bit_width != output_slot->bit_width ||
69 input_slot->vec_size != output_slot->vec_size ||
70 input_slot->columns != output_slot->columns ||
71 input_slot->offset != output_slot->offset ||
72 input_slot->relaxed_precision != output_slot->relaxed_precision) {
73 return false;
74 }
75 }
76 }
77 }
78
79 return true;
80 }
impeller::ShaderStageCompatibilityChecker::CompileTimeStrEqual
static constexpr bool CompileTimeStrEqual(const char *str1, const char *str2)
Definition: shader_stage_compatibility_checker.h:41

References impeller::ShaderStageIOSlot::binding, impeller::ShaderStageIOSlot::bit_width, impeller::ShaderStageIOSlot::columns, impeller::ShaderStageCompatibilityChecker< VertexShaderT, FragmentShaderT >::CompileTimeStrEqual(), impeller::ShaderStageIOSlot::location, impeller::ShaderStageIOSlot::name, impeller::ShaderStageIOSlot::offset, impeller::ShaderStageIOSlot::relaxed_precision, impeller::ShaderStageIOSlot::set, impeller::ShaderStageIOSlot::type, and impeller::ShaderStageIOSlot::vec_size.

## ◆ CompileTimeStrEqual()

template<typename VertexShaderT , typename FragmentShaderT >

static constexpr bool impeller::ShaderStageCompatibilityChecker< VertexShaderT, FragmentShaderT >::CompileTimeStrEqual | ( | const char * | str1,
|  | const char * | str2
| ) |  |
| inlinestaticconstexpr

Definition at line 41 of file shader_stage_compatibility_checker.h.

42 {
43 return *str1 == *str2 &&
44 (*str1 == '\0' || CompileTimeStrEqual(str1 + 1, str2 + 1));
45 }

Referenced by impeller::ShaderStageCompatibilityChecker< VertexShaderT, FragmentShaderT >::Check().

The documentation for this class was generated from the following file:

- impeller/renderer/shader_stage_compatibility_checker.h