This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Flutter GPU] Runtime shader import. (#48875)
* Add `--shader-bundle` mode to impellerc that takes a simple JSON spec and produces a single flatbuffer with a pack of named shaders. * Added "single invocation" mode to the impellerc GN templates. * Record vertex attribute reflection information. * Light refactoring of the compiler frontend to make compiler invocations easier to follow. Example shader bundle spec (json form of the yaml spec as shown in the [Flutter GPU](https://docs.google.com/document/d/1Sh1BAC5c_kkuMVreo7ymBzPoMzb7lamZRPsI7GBXv5M/edit?resourcekey=0-5w8u2V-LS41tCHeoE8bDTQ#heading=h.a3gmnzue7wgq) doc): ```json { "UnlitFragment": { "type": "fragment", "file": "shaders/flutter_gpu_unlit.frag" }, "UnlitVertex": { "type": "vertex", "file": "shaders/flutter_gpu_unlit.vert" }, "TextureFragment": { "type": "fragment", "file": "shaders/flutter_gpu_texture.frag" }, "TextureVertex": { "type": "vertex", "file": "shaders/flutter_gpu_texture.vert" } } ``` Example impellerc invocation: ```bash impellerc \ --include=~/projects/flutter/engine/src/flutter/impeller/compiler/shader_lib \ --runtime-stage-metal \ --sl=assets/TestLibrary.shaderbundle \ --shader-bundle='{"UnlitFragment": {"type": "fragment", "file": "shaders/flutter_gpu_unlit.frag"}, "UnlitVertex": {"type": "vertex", "file": "shaders/flutter_gpu_unlit.vert"}, "TextureFragment": {"type": "fragment", "file": "shaders/flutter_gpu_texture.frag"}, "TextureVertex": {"type": "vertex", "file": "shaders/flutter_gpu_texture.vert"}}' ``` Runtime usage: ```dart /// Add a render pass encoder to the command buffer so that we can start /// encoding commands. final encoder = commandBuffer.createRenderPass(renderTarget); /// Load a shader bundle asset. final library = gpu.ShaderLibrary.fromAsset('assets/TestLibrary.shaderbundle')!; /// Create a RenderPipeline using shaders from the asset. final vertex = library['TextureVertex']!; final fragment = library['TextureFragment']!; final pipeline = gpu.gpuContext.createRenderPipeline(vertex, fragment); encoder.bindPipeline(pipeline); ``` https://github.com/flutter/engine/assets/919017/6f3e9a59-d180-4ba6-b14c-fa6d7056965c
- Loading branch information
Showing
33 changed files
with
1,339 additions
and
325 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.