Skip to content

[Impeller] Add a Direct3D 12 backend and use it on Windows behind --impeller-backend=d3d12 - #197844

Draft
bdero wants to merge 11 commits into
flutter:masterfrom
bdero:bdero/impeller-d3d12
Draft

bdero wants to merge 11 commits into
flutter:masterfrom
bdero:bdero/impeller-d3d12

Conversation

@bdero

@bdero bdero commented Dec 3, 2026

Copy link
Copy Markdown
Member

This is a draft of a feature-complete end-to-end D3D12 backend for Impeller/Flutter GPU that I generated near the end of October, but decided to hold off on fully vetting it and presenting it to the Flutter team at the time, as we had bigger fish to fry.
Now that the team is exploring the possibility of landing a D3D11 backend (#197842), I'm sharing this in case it's useful. We obviously shouldn't merge this as-is, but pushing it now to contribute to the discussion. :)

Adds a Direct3D 12 backend to Impeller and wires it through impellerc (an HLSL target), the embedder API, the tester, Flutter GPU, runtime effects, and the Windows shell, which presents through a DirectComposition swapchain. It is opt-in behind --impeller-backend=d3d12, so ANGLE stays the default and remains the fallback when no device can be created.

Pre-launch Checklist

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

If this change needs to override an active code freeze, provide a comment explaining why. The code freeze workflow can be overridden by code reviewers. See pinned issues for any active code freezes with guidance.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

bdero added 11 commits October 30, 2026 13:38
Adds the d3d12 and runtime-stage-d3d12 targets, translating SPIR-V to
shader model 5.1 HLSL through SPIRV-Cross, with the matching
TargetPlatform, RuntimeStageBackend, flatbuffer fields, GN templates,
and shader archive support. Compute shaders get the num-workgroups
cbuffer at register space 1. Adds check_d3d12_shaders.py, which
compiles every emitted HLSL file with fxc. impellerc now reports a
failed check on stderr instead of raising the debug CRT dialog.
Adds impeller/renderer/backend/d3d12, a native backend behind
impeller_enable_d3d12 (on for Windows): committed resource allocator,
textures with state tracking and per texture descriptor slots, HLSL
shader library compiled at pipeline creation through d3dcompiler_47,
root signatures built from the shader register declarations, render
and blit passes recorded straight into the command list, draw based
mipmap generation, a single fence with a waiter thread, a flip model
swapchain for the playground, and the debug layer wired into
validation. Adds PlaygroundBackend::kD3D12, a WARP switch, and
kD3D12 at every backend switch site. Compute, the interop context,
golden screenshots and caches are left as TODOs.

Registers a PNG decoder in the Impeller test suite on Windows so
DirectWrite color emoji glyphs decode.
…ter.

Builds impeller_golden_tests on Windows with a harness that renders on
Direct3D 12 (hardware, or WARP with IMPELLER_GOLDEN_USE_WARP=1), Vulkan
and the driver's GLES context. Screenshots come from a backend neutral
readback through a blit pass and are encoded with Skia, which also
gives Vulkan and GLES screenshots on Windows. Adds a script that ranks
two golden directories by differing pixels, and wires the Windows
unit test and golden runs into run_tests.py.

Textures now expose every mip level to samplers, like the other
backends, which fixes sampling manually filled levels.
…ell tests.

Adds kDirect3D12 and kFlutterBackingStoreTypeDirect3D12 with the renderer config, texture, backing store and external texture structs, an Impeller only EmbedderSurfaceD3D12Impeller and GPUSurfaceD3D12Impeller, external texture resolution, a WARP tester context behind --impeller-backend=d3d12, a D3D12 shell test platform view, and embedder tests on WARP that match the existing Impeller fixtures. Wrapped resources are handed over and returned in the common state. Fixes the queue falling through to the unimplemented direct submit on SubmitWithReceipt and builds the lib/ui shader fixtures with a d3d12 runtime stage.
…nd=d3d12.

Adds a Direct3D 12 manager (device, direct queue, adapter choice, WARP and debug layer knobs, a Direct3D 11 on 12 layer for plugin textures), a DirectComposition presenter per view, a compositor that renders into Direct3D 12 textures, and external textures for pixel buffers and shared Direct3D 11 textures. The engine picks the backend when the switch is set and Impeller is on, and falls back to ANGLE when no device can be created. Views resize the presenter in place, the graphics adapter query answers from the Direct3D 12 device, and the switch skips the signed distance field text default.
ComputePipelineD3D12 compiles the compute shader, checks the thread group against the device limits first, and builds a root signature and pipeline state; ComputePassD3D12 keeps bindings by register, applies them with the transitions each dispatch needs, binds the workgroup counts for shaders that read them, and orders dispatches with an unordered access barrier. Host visible buffers move to a custom write back heap so compute can write what the CPU reads, and buffers read in several ways share the combined read state. The capability flips on for the renderer and Flutter GPU, and the compute suite runs on D3D12.
…ndows.

The new option reaches desktop apps as an engine switch and flutter_tester as a flag, so run, drive and test can pick the Direct3D 12 renderer. Shaders built for Windows and for the tester carry a Direct3D 12 runtime stage.
…d lists per frame.

Compiled shaders persist under the context's cache directory, which the embedder names through FlutterD3D12RendererConfig.shader_cache_path and the Windows shell places under the local app data directory. Command lists enqueued during a frame execute as one batch, with buffer states tracked by promotion since lists can run in a different order than they were recorded. A removed device is reported where it is first noticed.
The hooks runner starts hooks with an allow list of environment variables, so a hook compiling shader bundles found the cached impellerc even for a local engine build. The tool now passes IMPELLERC resolved through the artifacts, which follow --local-engine.
Two pipelines compiling the same shader at once both write the same cache file, and the second write losing the rename is not an error.
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@bdero bdero mentioned this pull request Dec 5, 2026
7 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant