Skip to content

[Impeller] Compiler: GLSL array literals in shaders crash at runtime. #125630

Description

@nanokatze

Is there an existing issue for this?

Steps to reproduce

  1. Use a GLSL array literal in a shader and load it with FragmentProgram.fromAsset (see the code sample for detail)

Expected results

Shader compiling successfully and working correctly OR a diagnostic at flutter run and/or flutter build

Actual results

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Exception: Invalid SkSL:
// This SkSL shader is autogenerated by spirv-cross.

float4 flutter_FragCoord;

const vec2 _22[4] = vec2[](vec2(0.375, 0.125), vec2(0.875, 0.375), vec2(0.125, 0.625), vec2(0.625, 0.875));

vec4 outColor;

void FLT_main()
{
    outColor = vec4(1.0);
}

half4 main(float2 iFragCoord)
{
      flutter_FragCoord = float4(iFragCoord, 0, 0);
      FLT_main();
      return outColor;
}
|
SkSL Error:
error: 5: missing index in '[]'
const vec2 _22[4] = vec2[](vec2(0.375, 0.125), vec2(0.875, 0.375), vec2(0.125, 0.625), vec2(0.625, 0.875));
                        ^^
1 error

#0      new FragmentProgram._fromAsset (dart:ui/painting.dart:4328:7)
#1      FragmentProgram.fromAsset.<anonymous closure> (dart:ui/painting.dart:4355:55)
#2      new Future.microtask.<anonymous closure> (dart:async/future.dart:280:37)
#3      _microtaskLoop (dart:async/schedule_microtask.dart:40:21)
#4      _startMicrotaskLoop (dart:async/schedule_microtask.dart:49:5)

Code sample

Code sample
import 'dart:ui';

void main() async {
  await FragmentProgram.fromAsset('shaders/crasher.frag');
}

Drop the following into shaders/crasher.frag. Remember to add this shader to your list of shaders in pubspec.yaml.

vec2 sampleLocations[4] = {
  vec2(0.375, 0.125),
  vec2(0.875, 0.375),
  vec2(0.125, 0.625),
  vec2(0.625, 0.875),
};

out vec4 outColor;

void main() {
  outColor = vec4(1.0);
}

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
$ flutter --version
Flutter 3.10.0-15.0.pre.13 • channel master • https://github.com/flutter/flutter.git
Framework • revision b03d6d65b8 (18 hours ago) • 2023-04-26 15:02:09 -0400
Engine • revision f2882afe0e
Tools • Dart 3.1.0 (build 3.1.0-47.0.dev) • DevTools 2.23.1
$ flutter run
Launching lib/main.dart on Linux in debug mode...
Building Linux application...                                           
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Exception: Invalid SkSL:
// This SkSL shader is autogenerated by spirv-cross.

float4 flutter_FragCoord;

const vec2 _22[4] = vec2[](vec2(0.375, 0.125), vec2(0.875, 0.375), vec2(0.125, 0.625), vec2(0.625, 0.875));

vec4 outColor;

void FLT_main()
{
    outColor = vec4(1.0);
}

half4 main(float2 iFragCoord)
{
      flutter_FragCoord = float4(iFragCoord, 0, 0);
      FLT_main();
      return outColor;
}
|
SkSL Error:
error: 5: missing index in '[]'
const vec2 _22[4] = vec2[](vec2(0.375, 0.125), vec2(0.875, 0.375), vec2(0.125, 0.625), vec2(0.625, 0.875));
                        ^^
1 error

#0      new FragmentProgram._fromAsset (dart:ui/painting.dart:4328:7)
#1      FragmentProgram.fromAsset.<anonymous closure> (dart:ui/painting.dart:4355:55)
#2      new Future.microtask.<anonymous closure> (dart:async/future.dart:280:37)
#3      _microtaskLoop (dart:async/schedule_microtask.dart:40:21)
#4      _startMicrotaskLoop (dart:async/schedule_microtask.dart:49:5)

Flutter Doctor output

Doctor output
$ flutter doctor -v
[✓] Flutter (Channel master, 3.10.0-15.0.pre.13, on Ubuntu 22.04.2 LTS 5.19.0-40-generic, locale en_US.UTF-8)
    • Flutter version 3.10.0-15.0.pre.13 on channel master at /home/nanokatze/snap/flutter/common/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision b03d6d65b8 (18 hours ago), 2023-04-26 15:02:09 -0400
    • Engine revision f2882afe0e
    • Dart version 3.1.0 (build 3.1.0-47.0.dev)
    • DevTools version 2.23.1

[!] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
    • Android SDK at /usr/lib/android-sdk
    ✗ cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`
      See https://developer.android.com/studio/command-line for more details.
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/linux#android-setup for more details.

[✗] Chrome - develop for the web (Cannot find Chrome executable at google-chrome)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.

[✓] Linux toolchain - develop for Linux desktop
    • clang version 10.0.0-4ubuntu1
    • cmake version 3.16.3
    • ninja version 1.10.0
    • pkg-config version 0.29.1

[!] Android Studio (not installed)
    • Android Studio not found; download from https://developer.android.com/studio/index.html
      (or visit https://flutter.dev/docs/get-started/install/linux#android-setup for detailed instructions).

[✓] Connected device (1 available)
    • Linux (desktop) • linux • linux-x64 • Ubuntu 22.04.2 LTS 5.19.0-40-generic

[✓] Network resources
    • All expected network resources are available.

! Doctor found issues in 3 categories.

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work listc: crashStack traces logged to the consoleengineflutter/engine related. See also e: labels.found in release: 3.10Found to occur in 3.10found in release: 3.7Found to occur in 3.7has reproducible stepsThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer versionteam-engineOwned by Engine teamtriaged-engineTriaged by Engine team

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions