Skip to content

Turned on preserve bindings to impellerc#167203

Merged
auto-submit[bot] merged 8 commits into
flutter:masterfrom
gaaclarke:preserve-bindings
Apr 21, 2025
Merged

Turned on preserve bindings to impellerc#167203
auto-submit[bot] merged 8 commits into
flutter:masterfrom
gaaclarke:preserve-bindings

Conversation

@gaaclarke

@gaaclarke gaaclarke commented Apr 15, 2025

Copy link
Copy Markdown
Member

fixes #116900

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@flutter-dashboard

Copy link
Copy Markdown

It looks like this pull request may not have tests. Please make sure to add tests or get an explicit test exemption before merging.

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.If you believe this PR qualifies for a test exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!). The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group.

@github-actions github-actions Bot added engine flutter/engine related. See also e: labels. e: impeller Impeller rendering backend issues and features requests labels Apr 15, 2025
@gaaclarke gaaclarke requested review from flar and jonahwilliams April 15, 2025 16:30
@gaaclarke

Copy link
Copy Markdown
Member Author

@flar do you know, do the runtime shaders use impellerc too? I tested this with our own shaders. It has to, right?

@jonahwilliams

Copy link
Copy Markdown
Contributor

Everything uses impellerc

@jonahwilliams

Copy link
Copy Markdown
Contributor

(the difference is in vulkan vs runtime-stage vulkan)

@flar

flar commented Apr 15, 2025

Copy link
Copy Markdown
Contributor

@flar do you know, do the runtime shaders use impellerc too? I tested this with our own shaders. It has to, right?

TIL - what Jonah said...

@gaaclarke

Copy link
Copy Markdown
Member Author

The failures on CI seem apropos. It looks like we had 16bit float uniforms that were being removed with the dead code but now that they are present they are being flagged by validation layers.

Example:

�[0;33mNote: Google Test filter = Play/DisplayListTest.CanDrawCapsAndJoins/Vulkan
�[m�[0;32m[==========] �[mRunning 1 test from 1 test suite.
�[0;32m[----------] �[mGlobal test environment set-up.
�[0;32m[----------] �[m1 test from Play/DisplayListTest
�[0;32m[ RUN      ] �[mPlay/DisplayListTest.CanDrawCapsAndJoins/Vulkan
[INFO:flutter/impeller/renderer/backend/vulkan/capabilities_vk.cc(68)] Vulkan validations are enabled.
2025-04-15 10:05:53.323 impeller_unittests[71253:491135] Metal API Validation Enabled
[INFO:flutter/impeller/renderer/backend/vulkan/capabilities_vk.cc(68)] Vulkan validations are enabled.
../../../flutter/impeller/renderer/backend/vulkan/debug_report_vk.cc:191: Failure
Impeller Validation Error

--- Vulkan Debug Report  ----------------------------------------
|                Severity: Error
|                    Type: { Validation }
|                 ID Name: VUID-RuntimeSpirv-uniformAndStorageBuffer16BitAccess-06332
|               ID Number: 231017936
|       Queue Breadcrumbs: [NONE]
|  CMD Buffer Breadcrumbs: [NONE]
|                 Trigger: Validation Error: [ VUID-RuntimeSpirv-uniformAndStorageBuffer16BitAccess-06332 ] | MessageID = 0xdc50dd0 | vkCreateShaderModule(): SPIR-V contains an 16-bit OpVariable with Uniform Storage Class, but uniformAndStorageBuffer16BitAccess was not enabled.
%18 = OpVariable %17 2
The Vulkan spec states: If uniformAndStorageBuffer16BitAccess is VK_FALSE, then objects in the Uniform Storage Class with the Block decoration must not have 16-bit integer or 16-bit floating-point members (https://docs.vulkan.org/spec/latest/appendices/spirvenv.html#VUID-RuntimeSpirv-uniformAndStorageBuffer16BitAccess-06332)
-----------------------------------------------------------------

�[0;31m[  FAILED  ] �[mPlay/DisplayListTest.CanDrawCapsAndJoins/Vulkan, where GetParam() = 4-byte object <02-00 00-00> (180 ms)
�```

@gaaclarke

Copy link
Copy Markdown
Member Author

I can't reproduce the failure locally. I see a different validation error even without this PR

$41│ │ -----------------------------------------------------------------
$41│ │ 
$41│ │ Failure @ ./impeller/renderer/backend/vulkan/debug_report_vk.cc:191
$41│ │ Impeller Validation Error
$41│ │ 
$41│ │ --- Vulkan Debug Report  ----------------------------------------
$41│ │ |                Severity: Error
$41│ │ |                    Type: { Validation }
$41│ │ |                 ID Name: VUID-VkRenderPassBeginInfo-clearValueCount-00902
$41│ │ |               ID Number: 1306546659
$41│ │ |       Queue Breadcrumbs: [NONE]
$41│ │ |  CMD Buffer Breadcrumbs: [NONE]
$41│ │ |         Related Objects: RenderPass [8446704510784504200] [EntityPass Render Pass]
$41│ │ |                 Trigger: Validation Error: [ VUID-VkRenderPassBeginInfo-clearValueCount-00902 ] Object 0: handle = 0x7538b90000000188, name = EntityPass Render Pass, type = VK_OBJECT_TYPE_RENDER_PASS; | MessageID = 0x4de051e3 | In vkCmdBeginRenderPass the VkRenderPassBeginInfo struct has a clearValueCount of 1 but there must be at least 3 entries in pClearValues array to account for the highest index attachment in VkRenderPass 0x7538b90000000188[EntityPass Render Pass] that uses VK_ATTACHMENT_LOAD_OP_CLEAR is 3. Note that the pClearValues array is indexed by attachment number so even if some pClearValues entries between 0 and 2 correspond to attachments that aren't cleared they will be ignored. The Vulkan spec states: clearValueCount must be greater than the largest attachment index in renderPass specifying a loadOp (or stencilLoadOp, if the attachment has a depth/stencil format) of VK_ATTACHMENT_LOAD_OP_CLEAR (https://vulkan.lunarg.com/doc/view/1.3.243.0/mac/1.3-extensions/vkspec.html#VUID-VkRenderPassBeginInfo-clearValueCount-00902)

@gaaclarke

Copy link
Copy Markdown
Member Author

It's also possible that shaderc is transforming f16 to f32 without the preserve flag set.

@gaaclarke

Copy link
Copy Markdown
Member Author

I'm unable to reproduce the failure locally when patching #167360 onto this PR. I'm not sure if it's related.

@gaaclarke

Copy link
Copy Markdown
Member Author

I'm rebasing against #167360 to see if we get the errors on CI still.

@gaaclarke

Copy link
Copy Markdown
Member Author

I looked through the diff in shaderc that introduced this flag ( https://chromium.googlesource.com/external/github.com/google/shaderc/+/ca4c38cbc8137fba6fc3ddbf0d95362a04612fa2%5E%21/ ) and it really looks like this is a case where f16 uniforms were being stripped out because they weren't used, and now they are sticking around. The error messages aren't helpful about what variables those are though and I can't reproduce it locally since you need a device that doesn't support f16.


options.SetAutoBindUniforms(true);
options.SetAutoMapLocations(true);
options.SetPreserveBindings(true);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try setting this to true only when this is one of the "runtime stage" modes (runtime-stage-vulkan, et cetera) those are the developer authored shaders

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was hoping to get this working for us too since it makes working on the shaders a pain.

@gaaclarke

gaaclarke commented Apr 17, 2025

Copy link
Copy Markdown
Member Author

I'm able to reproduce this on my linux machine which is x86_64 (I had to download the validation layers myself):

LD_LIBRARY_PATH=$VULKAN_SDK/lib VK_ICD_FILENAMES=./vk_swiftshader_icd.json  VK_LAYER_PATH=$VULKAN_SDK/share/vulkan/explicit_layer.d/VkLayer_khronos_validation.json VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ./impeller_unittests --enable_playground --gtest_filter="*CanDrawCapsAndJoins*"

@gaaclarke

Copy link
Copy Markdown
Member Author

I tried to find the culprit by disassembling the spirv files and trying to find the 16bit uniform that is causing the error

find . -name "*.spirv" -exec sh -c 'spirv-dis "$0" -o "${0%.spirv}.spvasm"' {} \;
ag "OpTypeFloat 16"
ag "OpTypeInt 16"

Didn't show up anything.

These look potentially apropos:

gles/gaussian.frag.spvasm
535:%kernel_samples = OpVariable %_ptr_Uniform_KernelSamples Uniform
539:%texture_sampler = OpVariable %_ptr_UniformConstant_16 UniformConstant
541:%v_texture_coords = OpVariable %_ptr_Input_v2float Input
544: %frag_color = OpVariable %_ptr_Output_v4float Output

gles/tiled_texture_fill_external.frag.spvasm
180: %frag_color = OpVariable %_ptr_Output_v4float Output
181:%SAMPLER_EXTERNAL_OES_texture_sampler = OpVariable %_ptr_UniformConstant_16 UniformConstant
183:%v_texture_coords = OpVariable %_ptr_Input_v2float Input
186:  %frag_info = OpVariable %_ptr_Uniform_FragInfo Uniform

@gaaclarke

Copy link
Copy Markdown
Member Author

The culprit is a fragment shader with the name "half". I'm not sure where that is coming from:

[ERROR:flutter/impeller/renderer/backend/vulkan/shader_library_vk.cc(62)] baby 2 0x564641d356d0
[ERROR:flutter/impeller/renderer/backend/vulkan/shader_library_vk.cc(62)] spec_constant 2 0x564641d32480
[ERROR:flutter/impeller/renderer/backend/vulkan/shader_library_vk.cc(62)] box_fade 2 0x564641d36020
[ERROR:flutter/impeller/renderer/backend/vulkan/shader_library_vk.cc(62)] simple 1 0x564641d321e0
[ERROR:flutter/impeller/renderer/backend/vulkan/shader_library_vk.cc(62)] sample 3 0x564641d32150
[ERROR:flutter/impeller/renderer/backend/vulkan/shader_library_vk.cc(62)] planet 1 0x564641c6bc80
[ERROR:flutter/impeller/renderer/backend/vulkan/shader_library_vk.cc(62)] mipmaps 1 0x564641c6b950
[ERROR:flutter/impeller/renderer/backend/vulkan/shader_library_vk.cc(62)] instanced_draw 1 0x564641d3dbc0
[ERROR:flutter/impeller/renderer/backend/vulkan/shader_library_vk.cc(62)] mipmaps 2 0x564641c6b8c0
[ERROR:flutter/impeller/renderer/backend/vulkan/shader_library_vk.cc(62)] inactive_uniforms 1 0x564641d3d890
[ERROR:flutter/impeller/renderer/backend/vulkan/shader_library_vk.cc(62)] impeller 2 0x564641d3eb70
[ERROR:flutter/impeller/renderer/backend/vulkan/shader_library_vk.cc(62)] half 2 0x564641d3e8d0
../../flutter/impeller/renderer/backend/vulkan/debug_report_vk.cc:191: Failure
Impeller Validation Error

--- Vulkan Debug Report  ----------------------------------------
|                Severity: Error
|                    Type: { Validation }
|                 ID Name: VUID-RuntimeSpirv-uniformAndStorageBuffer16BitAccess-06332
|               ID Number: 231017936
|       Queue Breadcrumbs: [NONE]
|  CMD Buffer Breadcrumbs: [NONE]
|                 Trigger: Validation Error: [ VUID-RuntimeSpirv-uniformAndStorageBuffer16BitAccess-06332 ] | MessageID = 0xdc50dd0 | vkCreateShaderModule(): SPIR-V contains an 16-bit OpVariable with Uniform Storage Class, but uniformAndStorageBuffer16BitAccess was not enabled.
%18 = OpVariable %17 2
The Vulkan spec states: If uniformAndStorageBuffer16BitAccess is VK_FALSE, then objects in the Uniform Storage Class with the Block decoration must not have 16-bit integer or 16-bit floating-point members (https://docs.vulkan.org/spec/latest/appendices/spirvenv.html#VUID-RuntimeSpirv-uniformAndStorageBuffer16BitAccess-06332)
-----------------------------------------------------------------

@jonahwilliams

Copy link
Copy Markdown
Contributor

@gaaclarke

Copy link
Copy Markdown
Member Author

ah test fixture 🤔

@gaaclarke

Copy link
Copy Markdown
Member Author

Okay fixed it by not loading that shader if we don't support float16. I looked at the pr that introduced it and it doesn't look like we ever use it. We just compiled it. I think this points to some flaw in our thinking about float16 in vulkan. If this fragment shader was actually used we'd have to compile 2 different variants and load the appropriate one when the shader library is initialized.

engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 27, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 28, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 28, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 28, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 28, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 28, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 28, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 28, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 28, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 29, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 29, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 29, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 30, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 30, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 1, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 1, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 1, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 1, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 1, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 1, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 1, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 2, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 2, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 2, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 2, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 2, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 3, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 3, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 4, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

e: impeller Impeller rendering backend issues and features requests engine flutter/engine related. See also e: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Impeller] Ensure optimized out uniforms don't alter offsets

3 participants