Skip to content

AnimatedSampler VRAM leak #178498

Closed
Closed

Description

@daniel1414

Steps to reproduce

  1. Create a sample project using flutter create.
  2. Run the flutter pub add flutter_shaders command.
  3. Add a shader file called shader.frag into a folder called shaders in the root of your project and paste in the shader code from the code snippet below.
  4. Add
flutter:
  shaders:
    - shaders/shader.frag

to the pubspec.yaml
5. Paste in the dart code into main.dart from the sample below.
6. Run on multiple platforms, I see a difference between Linux and Android.

Also, the app sometimes launches just a black screen on the phone and nothing more happens, the progress indicator notification pop-up in VS Code is stuck at 'Installing', might be a different issue though.

Expected results

The VRAM memory doesn't overflow.

Actual results

On my android device (POCO X3 Pro) after running for a few seconds I get flooded by error messages, which can be found in the logs section below.

Runs fine on Linux (Ubuntu), no memory overflow there.

Code sample

Code sample

Fragment shader code:

#version 460 core

#include <flutter/runtime_effect.glsl>

uniform vec2 uSize;
uniform float uTime;
uniform sampler2D uWidget;

out vec4 fragColor;

void main()
{
    vec2 pos = FlutterFragCoord().xy / uSize;
    fragColor = mix(vec4(sin(pos.x * uTime * 0.5), pos.y, 0.78, 1.0), texture(uWidget, pos), 0.5);
}

Dart code:

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'package:flutter_shaders/flutter_shaders.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple)),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatelessWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  Widget build(BuildContext context) {
    return ShaderBuilder(
      (context, shader, _) => Scaffold(
        body: Center(child: Sampler(shader: shader)),
      ),
      assetKey: 'shaders/shader.frag',
    );
  }
}

class Sampler extends StatefulWidget {
  const Sampler({super.key, required this.shader});

  final FragmentShader shader;

  @override
  State<Sampler> createState() => _SamplerState();
}

class _SamplerState extends State<Sampler> with SingleTickerProviderStateMixin {
  late final Ticker _timer;
  double _time = 0.0;

  @override
  void initState() {
    super.initState();
    _timer = createTicker((elapsed) {
      setState(() {
        _time = elapsed.inMilliseconds.toDouble();
      });
    })..start();
  }

  @override
  Widget build(BuildContext context) {
    return AnimatedSampler(
      (image, size, canvas) {
        widget.shader
          ..setFloat(0, size.width)
          ..setFloat(1, size.height)
          ..setFloat(2, _time)
          ..setImageSampler(0, image);
        canvas.drawRect(Offset.zero & size, Paint()..shader = widget.shader);
      },
      child: Text('0', style: Theme.of(context).textTheme.displayLarge!.copyWith(fontSize: 520.0)),
      key: ValueKey('value'),
    );
  }

  @override
  void dispose() {
    _timer.dispose();
    super.dispose();
  }
}

Screenshots or Video

No response

Logs

Logs
E/flutter (28651): [ERROR:flutter/impeller/renderer/backend/vulkan/allocator_vk.cc(361)] Break on 'ImpellerValidationBreak' to inspect point of failure: Unable to allocate Vulkan Image: ErrorOutOfDeviceMemory Type: Texture2DMultisample Mode: DeviceTransient Usage: { RenderTarget } [VK]Flags: {} [VK]Format: R8G8B8A8Unorm [VK]Usage: { ColorAttachment | InputAttachment } [VK]Mem. Flags: { DeviceLocal }
E/flutter (28651): [ERROR:flutter/impeller/renderer/render_target.cc(411)] Break on 'ImpellerValidationBreak' to inspect point of failure: Could not create multisample color texture.
E/flutter (28651): [ERROR:flutter/impeller/renderer/render_target.cc(26)] Break on 'ImpellerValidationBreak' to inspect point of failure: Render target does not have color attachment at index 0.
W/Adreno-GSL(28651): <gsl_ldd_control:553>: ioctl fd 112 code 0xc0300945 (IOCTL_KGSL_GPUOBJ_ALLOC) failed: errno 12 Out of memory
E/Adreno-GSL(28651): <gsl_memory_alloc_pure:2604>: GSL MEM ERROR: kgsl_sharedmem_alloc ioctl failed.

Flutter Doctor output

Doctor output
anims flutter doctor -v                
[✓] Flutter (Channel stable, 3.35.5, on Ubuntu 24.04.3 LTS 6.14.0-34-generic, locale en_US.UTF-8) [40ms]
    • Flutter version 3.35.5 on channel stable at /home/daniel/Development/vendor/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision ac4e799d23 (7 weeks ago), 2025-09-26 12:05:09 -0700
    • Engine revision d3d45dcf25
    • Dart version 3.9.2
    • DevTools version 2.48.0
    • Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop, enable-android, enable-ios,
      cli-animations, enable-lldb-debugging

[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0) [2.5s]
    • Android SDK at /home/daniel/Development/vendor/android/android-sdk
    • Emulator version 35.3.12.0 (build_id 12990079) (CL:N/A)
    • Platform android-36, build-tools 35.0.0
    • ANDROID_HOME = /home/daniel/Development/vendor/android/android-sdk
    • ANDROID_SDK_ROOT = /home/daniel/Development/vendor/android/android-sdk
    • Java binary at: /home/daniel/Development/vendor/java/jdk-17.0.14+7/bin/java
      This JDK is specified by the JAVA_HOME environment variable.
      To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
    • Java version OpenJDK Runtime Environment Temurin-17.0.14+7 (build 17.0.14+7)
    • All Android licenses accepted.

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

[✓] Linux toolchain - develop for Linux desktop [242ms]
    • Ubuntu clang version 18.1.3 (1ubuntu1)
    • cmake version 3.28.1
    • ninja version 1.11.1
    • pkg-config version 1.8.1
    • OpenGL core renderer: AMD Radeon RX 7700 XT (radeonsi, navi32, LLVM 20.1.8, DRM 3.61, 6.14.0-34-generic) (X11)
    • OpenGL core version: 4.6 (Core Profile) Mesa 25.2.5 - kisak-mesa PPA (X11)
    • OpenGL core shading language version: 4.60 (X11)
    • OpenGL ES renderer: AMD Radeon RX 7700 XT (radeonsi, navi32, LLVM 20.1.8, DRM 3.61, 6.14.0-34-generic) (X11)
    • OpenGL ES version: OpenGL ES 3.2 Mesa 25.2.5 - kisak-mesa PPA (X11)
    • OpenGL ES shading language version: OpenGL ES GLSL ES 3.20 (X11)
    • GL_EXT_framebuffer_blit: yes (X11)
    • GL_EXT_texture_format_BGRA8888: yes (X11)

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

[✓] VS Code (version 1.105.1) [5ms]
    • VS Code at /usr/share/code
    • Flutter extension version 3.122.0

[✓] Connected device (2 available) [155ms]
    • M2102J20SG (mobile) • 192.0.0.2:5555 • android-arm64 • Android 13 (API 33)
    • Linux (desktop)     • linux          • linux-x64     • Ubuntu 24.04.3 LTS 6.14.0-34-generic

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

Activity

  1. daniel1414 commented on Nov 13, 2025

    @daniel1414
    Author

    Happens after upgrade to flutter 3.38.1 as well

  2. darshankawar commented on Nov 14, 2025

    @darshankawar
    Member

    Thanks for the report. I tried on S10+ device but wasn't able to see the reported log. My device uses OpenGles rendering so that could be reason, as I see that your log shows device using vulkan rendering. However, I tried by specifically enabling vulkan renderer, but still it didn't give me reported behavior, so this maybe specific to the device / hardware you are using:

    android device (POCO X3 Pro)

    https://www.gsmarena.com/xiaomi_poco_x3_pro-10802.php

    I'll keep the issue open for team's tracking.

  3. added
    platform-androidAndroid applications specifically
    e: impellerImpeller rendering backend issues and features requests
    engineflutter/engine related. See also e: labels.
    and removed
    in triagePresently being triaged by the triage team
    on Nov 14, 2025
  4. daniel1414 commented on Nov 14, 2025

    @daniel1414
    Author

    Hi @darshankawar, thanks for the quick response! That's quite concerning that it happens only on my device though.

  5. chinmaygarde commented on Nov 17, 2025

    @chinmaygarde
    Contributor

    @daniel1414 Can you check if your issue goes away after manually switching to the OpenGL ES backend on debug and profile modes?. See the instructions in https://github.com/flutter/flutter/blob/master/engine/src/flutter/impeller/README.md#try-impeller-in-flutter. You'd need to add the following to the manifest and verify that the renderer switch happened in the logs:

      <meta-data
        android:name="io.flutter.embedding.android.ImpellerBackend"
        android:value="opengles" />

    After 8834b42dff6e, we basically gave up on rescuing devices with incomplete implementations of framebuffer-fetch for Vulkan eligibility. Poco X3 Pro is an Adreno 640 and triagers think we should give up on the entire line for Vulkan eligibility. See another issue #178285 with this line.

    I recommend abandoning the entire Adreno line for Vulkan eligibility and closing both issues (after the original poster verifies).

  6. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Nov 17, 2025
  7. daniel1414 commented on Nov 18, 2025

    @daniel1414
    Author

    Hi @chinmaygarde!

    Thank you for your explanation.

    On the OpenGL ES backend I get no Vulkan errors 👍.

    Looking at the commit you've posted above,

    Image

    Can I hope that you will classify the Ardeno 640 as having bad drivers please (I'm a Vulkan fetishist and want it running on my device :p)

    Edit: Just realized turning off Vulkan on my device won't enable Vulkan on my device, ignore me. Would be nice to run Vulkan by default on other devices though.

  8. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Nov 18, 2025
  9. chinmaygarde commented on Nov 19, 2025

    @chinmaygarde
    Contributor

    Yup, both the 640 and 650 will be classified as naughty.

    I'm a Vulkan fetishist and want it running on my device

    We might share the same kink lol. And at least in this case, to our detriment. We tried to rescue Vulkan on these devices but the workarounds caused other issues. We should just leave these devices on the cusp or decent™ support for Vulkan be.

  10. chinmaygarde commented on Nov 19, 2025

    @chinmaygarde
    Contributor

    Reopening till we actually add it to the deny list.

  11. added
    r: fixedIssue is closed as already fixed in a newer version
    on Nov 20, 2025
  12. github-actions commented on Dec 4, 2025

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  13. locked as resolved and limited conversation to collaborators on Dec 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    e: device-specificOnly manifests on certain devicese: impellerImpeller rendering backend issues and features requestsengineflutter/engine related. See also e: labels.platform-androidAndroid applications specificallyr: fixedIssue is closed as already fixed in a newer versionteam-engineOwned by Engine teamwaiting for PR to land (fixed)A fix is in flight

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions