Skip to content

Wrong shader float index when setting another first with layout(location = 0) #194661

Closed

Description

@szmarczak

Steps to reproduce

#version 460 core

#include <flutter/runtime_effect.glsl>

precision lowp float;

layout(location = 0) out vec4 color;

layout(location = 0) uniform float a;
layout(location = 1) uniform float b;
uniform float c;

void main() {

}
shader.getUniformFloat('a') // shader index 0
shader.getUniformFloat('b') // shader index 2, why?
shader.getUniformFloat('c') // shader index 1, why?

Expected results

https://api.flutter.dev/flutter/dart-ui/FragmentShader/setFloat.html

The correct index for each uniform is determined by the order of the uniforms as defined in the fragment program

shader.getUniformFloat('a') // shader index 0
shader.getUniformFloat('b') // shader index 1
shader.getUniformFloat('c') // shader index 2

Actual results

shader.getUniformFloat('a') // shader index 0
shader.getUniformFloat('b') // shader index 2
shader.getUniformFloat('c') // shader index 1

Code sample

fragmentProgram = await FragmentProgram.fromAsset('assets/shaders/display.frag');
shader = fragmentProgram.fragmentShader();
shader.getUniformFloat('a')
shader.getUniformFloat('b')
shader.getUniformFloat('c')

Screenshots or Video

N/A

Logs

N/A

Flutter Doctor output

Doctor output
PS C:\Users\szmar\StudioProjects\ctt_second_take> flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.47.7, on Microsoft Windows [Version 10.0.26300.9457], locale pl-PL)
[√] Windows Version (Windows 11 or higher, 26H2, 2009)
[!] Android toolchain - develop for Android devices (Android SDK version 36.0.0)
    X cmdline-tools component is missing.
      Try installing or updating Android Studio.
      Alternatively, download the tools from https://developer.android.com/studio#command-line-tools-only and make sure to set the ANDROID_HOME environment variable.
      See https://developer.android.com/studio/command-line for more details.
    X Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/to/windows-android-setup for more details.
[√] Chrome - develop for the web
[!] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.11.1)
    X Visual Studio is missing necessary components. Please re-run the Visual Studio installer for the "Desktop development with C++" workload, and include these components:
        MSVC v142 - VS 2019 C++ x64/x86 build tools
         - If there are multiple build tool versions available, install the latest
        C++ CMake tools for Windows
        Windows 10 SDK
[√] Connected device (4 available)
[√] Network resources

! Doctor found issues in 2 categories.

Activity

  1. szmarczak commented on Oct 18, 2026

    @szmarczak
    Author

    Looks like KhronosGroup/glslang#1756 is why

  2. mbcorona commented on Oct 19, 2026

    @mbcorona
    Member

    Hi @szmarczak , thanks for reporting.
    Could you share a minimal sample that actually runs and prints the resolved index for each uniform? The glslang #1756 link is a good lead for the cause, but we need the real output to confirm the indices are off.

  3. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    needs repro infoAutomated crash report whose cause isn't yet known
    on Oct 19, 2026
  4. szmarczak commented on Oct 19, 2026

    @szmarczak
    Author

    repro.zip took me 4 minutes, don't know why you couldn't copy-paste on default Android Studio project yourself?

    Set up a breakpoint on the line with runApp, in the debugger you'll see that the indexes are indeed 0 2 1.

  5. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Oct 19, 2026
  6. mbcorona commented on Oct 20, 2026

    @mbcorona
    Member

    Thanks for the repro, that confirms it. The indices resolve as 0, 2, 1 instead of declaration order. Routing to team-engine.

  7. added
    engineflutter/engine related. See also e: labels.
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    e: impellerImpeller rendering backend issues and features requests
    and removed
    needs repro infoAutomated crash report whose cause isn't yet known
    on Oct 20, 2026
  8. 6 remaining items

  9. mohamedalsamrai commented on Oct 26, 2026

    @mohamedalsamrai
    Contributor

    Thanks for triaging this. I'd like to send a PR. Which direction would you prefer?

    1. Use declaration order on every stage, like the Vulkan stage already does, and have impellerc warn that explicit uniform locations are ignored. This matches the current setFloat docs and is a contained change in impellerc.
    2. Make explicit locations define the order on every stage: auto-assigned locations would skip the explicit ones, and the Vulkan stage would follow Location too. This is a bigger change (glslang's location mapping, the Vulkan stage, and the docs).
  10. gaaclarke commented on Oct 26, 2026

    @gaaclarke
    Member

    I got you, thanks for clarifying. Honestly, I'd prefer to deprecate setFloat. I don't believe there is any reason it has to be used now.

  11. added
    P1High-priority issues at the top of the work list
    and removed
    P2Important issues not at the top of the work list
    on Oct 26, 2026
  12. mohamedalsamrai commented on Oct 26, 2026

    @mohamedalsamrai
    Contributor

    I got you, thanks for clarifying. Honestly, I'd prefer to deprecate setFloat. I don't believe there is any reason it has to be used now.

    Makes sense. The name-based API is implemented on web too (CanvasKit and skwasm), so deprecating setFloat shouldn't leave any platform without an alternative.

    The framework still calls setFloat in InkSparkle and StretchEffect, and the fragment shader docs use it in most examples, so I could start by moving those to the name-based API. Or are you planning to handle it yourself?

  13. gaaclarke commented on Oct 26, 2026

    @gaaclarke
    Member

    If you want to move over the framework usage, that would be helpful. What docs are you thinking of? https://docs.flutter.dev/ui/design/graphics/fragment-shaders mentions both, we should probably remove all reference to setFloat. You know what, I'll file a separate issue for this and those can be subissues.

  14. gaaclarke commented on Oct 26, 2026

    @gaaclarke
    Member

    closed in lieu of #195357

  15. mohamedalsamrai commented on Oct 26, 2026

    @mohamedalsamrai
    Contributor

    reference

    Yes, that's the page I meant. I'll start on the framework migration (InkSparkle and StretchEffect) and link the PR to the sub-issue once it's filed.

  16. github-actions commented on Nov 9, 2026

    @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.

  17. locked as resolved and limited conversation to collaborators on Nov 9, 2026
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

    P1High-priority issues at the top of the work liste: impellerImpeller rendering backend issues and features requestsengineflutter/engine related. See also e: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onteam-engineOwned by Engine teamtriaged-engineTriaged by Engine team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions