Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CP][canvaskit] fix: consider array size on canvaskit shader data (#49754) #52400

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 27 additions & 6 deletions lib/web_ui/lib/src/engine/shader_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,13 @@ class ShaderData {
if (rawShaderData is! Map<String, Object?>) {
throw const FormatException('Invalid Shader Data');
}
final Object? source = rawShaderData['sksl'];
final Object? rawUniforms = rawShaderData['uniforms'];
final Object? root = rawShaderData['sksl'];
if (root is! Map<String, Object?>) {
throw const FormatException('Invalid Shader Data');
}

final Object? source = root['shader'];
final Object? rawUniforms = root['uniforms'];
if (source is! String || rawUniforms is! List<Object?>) {
throw const FormatException('Invalid Shader Data');
}
Expand All @@ -47,14 +52,30 @@ class ShaderData {
if (type == UniformType.SampledImage) {
textureCount += 1;
} else {
final Object? rows = rawUniformData['rows'];
final Object? bitWidth = rawUniformData['bit_width'];
if (bitWidth is! int || rows is! int) {

final Object? arrayElements = rawUniformData['array_elements'];
final Object? rows = rawUniformData['rows'];
final Object? columns = rawUniformData['columns'];

if (bitWidth is! int ||
rows is! int ||
arrayElements is! int ||
columns is! int) {
throw const FormatException('Invalid Shader Data');
}
floatCount += (bitWidth ~/ 32) * rows;

final int units = rows * columns;

int value = (bitWidth ~/ 32) * units;

if (arrayElements > 1) {
value *= arrayElements;
}

floatCount += value;
}
uniforms[location] = UniformData(
uniforms[i] = UniformData(
name: name,
location: location,
type: type,
Expand Down
Loading