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

Commit c720046

Browse files
authored
fix: consider array size on canvaskit shader data (#49754)
This PR changes the ShaderData construction on canvaskit to consider array uniforms. flutter/flutter#141296 flutter/flutter#141838 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
1 parent 2e1016c commit c720046

File tree

4 files changed

+309
-177
lines changed

4 files changed

+309
-177
lines changed

lib/web_ui/lib/src/engine/shader_data.dart

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,13 @@ class ShaderData {
1919
if (rawShaderData is! Map<String, Object?>) {
2020
throw const FormatException('Invalid Shader Data');
2121
}
22-
final Object? source = rawShaderData['sksl'];
23-
final Object? rawUniforms = rawShaderData['uniforms'];
22+
final Object? root = rawShaderData['sksl'];
23+
if (root is! Map<String, Object?>) {
24+
throw const FormatException('Invalid Shader Data');
25+
}
26+
27+
final Object? source = root['shader'];
28+
final Object? rawUniforms = root['uniforms'];
2429
if (source is! String || rawUniforms is! List<Object?>) {
2530
throw const FormatException('Invalid Shader Data');
2631
}
@@ -47,14 +52,30 @@ class ShaderData {
4752
if (type == UniformType.SampledImage) {
4853
textureCount += 1;
4954
} else {
50-
final Object? rows = rawUniformData['rows'];
5155
final Object? bitWidth = rawUniformData['bit_width'];
52-
if (bitWidth is! int || rows is! int) {
56+
57+
final Object? arrayElements = rawUniformData['array_elements'];
58+
final Object? rows = rawUniformData['rows'];
59+
final Object? columns = rawUniformData['columns'];
60+
61+
if (bitWidth is! int ||
62+
rows is! int ||
63+
arrayElements is! int ||
64+
columns is! int) {
5365
throw const FormatException('Invalid Shader Data');
5466
}
55-
floatCount += (bitWidth ~/ 32) * rows;
67+
68+
final int units = rows * columns;
69+
70+
int value = (bitWidth ~/ 32) * units;
71+
72+
if (arrayElements > 1) {
73+
value *= arrayElements;
74+
}
75+
76+
floatCount += value;
5677
}
57-
uniforms[location] = UniformData(
78+
uniforms[i] = UniformData(
5879
name: name,
5980
location: location,
6081
type: type,

0 commit comments

Comments
 (0)