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

Commit 90c95f5

Browse files
authored
Merge branch 'main' into patch-1
2 parents d62a1e3 + 818191d commit 90c95f5

File tree

3 files changed

+84
-0
lines changed

3 files changed

+84
-0
lines changed

ci/licenses_golden/licenses_flutter

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40715,6 +40715,7 @@ ORIGIN: ../../../flutter/impeller/renderer/shader_key.cc + ../../../flutter/LICE
4071540715
ORIGIN: ../../../flutter/impeller/renderer/shader_key.h + ../../../flutter/LICENSE
4071640716
ORIGIN: ../../../flutter/impeller/renderer/shader_library.cc + ../../../flutter/LICENSE
4071740717
ORIGIN: ../../../flutter/impeller/renderer/shader_library.h + ../../../flutter/LICENSE
40718+
ORIGIN: ../../../flutter/impeller/renderer/shader_stage_compatibility_checker.h + ../../../flutter/LICENSE
4071840719
ORIGIN: ../../../flutter/impeller/renderer/snapshot.cc + ../../../flutter/LICENSE
4071940720
ORIGIN: ../../../flutter/impeller/renderer/snapshot.h + ../../../flutter/LICENSE
4072040721
ORIGIN: ../../../flutter/impeller/renderer/stroke.comp + ../../../flutter/LICENSE
@@ -43596,6 +43597,7 @@ FILE: ../../../flutter/impeller/renderer/shader_key.cc
4359643597
FILE: ../../../flutter/impeller/renderer/shader_key.h
4359743598
FILE: ../../../flutter/impeller/renderer/shader_library.cc
4359843599
FILE: ../../../flutter/impeller/renderer/shader_library.h
43600+
FILE: ../../../flutter/impeller/renderer/shader_stage_compatibility_checker.h
4359943601
FILE: ../../../flutter/impeller/renderer/snapshot.cc
4360043602
FILE: ../../../flutter/impeller/renderer/snapshot.h
4360143603
FILE: ../../../flutter/impeller/renderer/stroke.comp

impeller/renderer/pipeline.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "impeller/renderer/context.h"
1414
#include "impeller/renderer/pipeline_builder.h"
1515
#include "impeller/renderer/pipeline_descriptor.h"
16+
#include "impeller/renderer/shader_stage_compatibility_checker.h"
1617

1718
namespace impeller {
1819

@@ -89,6 +90,11 @@ PipelineFuture<ComputePipelineDescriptor> CreatePipelineFuture(
8990

9091
template <class VertexShader_, class FragmentShader_>
9192
class RenderPipelineT {
93+
static_assert(
94+
ShaderStageCompatibilityChecker<VertexShader_, FragmentShader_>::Check(),
95+
"The output slots for the fragment shader don't have matches in the "
96+
"vertex shader's output slots. This will result in a linker error.");
97+
9298
public:
9399
using VertexShader = VertexShader_;
94100
using FragmentShader = FragmentShader_;
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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+
#ifndef FLUTTER_IMPELLER_RENDERER_SHADER_STAGE_COMPATIBILITY_CHECKER_H_
6+
#define FLUTTER_IMPELLER_RENDERER_SHADER_STAGE_COMPATIBILITY_CHECKER_H_
7+
8+
namespace impeller {
9+
/// This is a classed use to check that the input slots of fragment shaders
10+
/// match the output slots of the vertex shaders.
11+
/// If they don't match it will result in linker errors when creating the
12+
/// pipeline. It's not used at runtime.
13+
template <typename VertexShaderT, typename FragmentShaderT>
14+
class ShaderStageCompatibilityChecker {
15+
public:
16+
static constexpr bool CompileTimeStrEqual(const char* str1,
17+
const char* str2) {
18+
return *str1 == *str2 &&
19+
(*str1 == '\0' || CompileTimeStrEqual(str1 + 1, str2 + 1));
20+
}
21+
22+
/// Returns `true` if the shader input slots for the fragment shader match the
23+
/// ones declared as outputs in the vertex shader.
24+
static constexpr bool Check() {
25+
constexpr size_t num_outputs = VertexShaderT::kAllShaderStageOutputs.size();
26+
constexpr size_t num_inputs = FragmentShaderT::kAllShaderStageInputs.size();
27+
28+
if (num_inputs > num_outputs) {
29+
return false;
30+
}
31+
32+
for (size_t i = 0; i < num_inputs; ++i) {
33+
const ShaderStageIOSlot* input_slot =
34+
FragmentShaderT::kAllShaderStageInputs[i];
35+
for (size_t j = 0; j < num_outputs; ++j) {
36+
const ShaderStageIOSlot* output_slot =
37+
VertexShaderT::kAllShaderStageOutputs[j];
38+
if (input_slot->location == output_slot->location) {
39+
if (!CompileTimeStrEqual(input_slot->name, output_slot->name) ||
40+
input_slot->set != output_slot->set ||
41+
input_slot->binding != output_slot->binding ||
42+
input_slot->type != output_slot->type ||
43+
input_slot->bit_width != output_slot->bit_width ||
44+
input_slot->vec_size != output_slot->vec_size ||
45+
input_slot->columns != output_slot->columns ||
46+
input_slot->offset != output_slot->offset) {
47+
return false;
48+
}
49+
}
50+
}
51+
}
52+
53+
return true;
54+
}
55+
};
56+
57+
// The following shaders don't define output slots.
58+
// TODO(https://github.com/flutter/flutter/issues/146852): Make impellerc emit
59+
// an empty array for output slots.
60+
struct CheckerboardVertexShader;
61+
struct ClipVertexShader;
62+
63+
template <typename FragmentShaderT>
64+
class ShaderStageCompatibilityChecker<CheckerboardVertexShader,
65+
FragmentShaderT> {
66+
public:
67+
static constexpr bool Check() { return true; }
68+
};
69+
70+
template <typename FragmentShaderT>
71+
class ShaderStageCompatibilityChecker<ClipVertexShader, FragmentShaderT> {
72+
public:
73+
static constexpr bool Check() { return true; }
74+
};
75+
} // namespace impeller
76+
#endif // FLUTTER_IMPELLER_RENDERER_SHADER_STAGE_COMPATIBILITY_CHECKER_H_

0 commit comments

Comments
 (0)