跪拜 Guibai
← All articles
Frontend · Android · Flutter

Flutter GPU Draft PRs Bring Real 3D Textures with Hardware Trilinear Filtering

By 恋猫de小郭 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

Developers doing volume rendering on Flutter can drop hand-rolled eight-voxel mixing and atlas bookkeeping for GPU-side trilinear filtering, but only on Metal and Vulkan, and only for sampling: no mip levels, no block compression, no render target.

Summary

Two draft Flutter Pull Requests add a real third dimension to GPU textures. #197354 introduces kTexture3D in Impeller's TextureDescriptor, and #197355 exposes it through the Flutter GPU Dart API. A 3D texture lets the GPU interpolate across X, Y, and Z in one texture() call; the existing 2D Texture Array only picks a layer on the third axis and forces manual two-layer mixing.

Volume rendering is the intended workload: temperature fields, fluid density, voxel scans, SDF. Without 3D textures, a Flutter developer packs slices into atlases, reconstructs 16-bit values from RGBA8 texels, gathers eight neighboring voxels, and performs seven mix operations to get one interpolated sample. With the new type, those lines collapse to a single hardware sample.

The Impeller patch maps the depth field to Vulkan's VK_IMAGE_TYPE_3D, Metal's MTLTextureType3D, and GL_TEXTURE_3D on GLES. The Dart layer reuses the slice parameter, so a simulation can upload each Z-slice as it arrives without first building a full CPU-side buffer. GLES stays out of the Dart API because the shader bundle lacks a GLSL ES 3.0 variant. The texture is sampling-only for now: one mip level, no block compression, no render target. Memory runs out quickly: a 256^3 RGBA8 volume needs 64 MiB, and 512^3 needs 512 MiB.

Takeaways
— Two draft Flutter PRs, #197354 and #197355, add 3D texture support to Impeller and the Flutter GPU Dart API.
— 3D textures enable hardware trilinear filtering along X, Y, and Z, eliminating manual two-layer sampling and mixing.
— Without 3D textures, volume rendering on Flutter required packed 2D atlases and manual interpolation across eight neighbors with seven mix calls.
— The Impeller TextureDescriptor gains a depth field, mapped to VK_IMAGE_TYPE_3D, MTLTextureType3D, and GL_TEXTURE_3D on Vulkan, Metal, and GLES respectively.
— The existing slice parameter now addresses Z positions, so simulated volumes can upload each slice independently without assembling a full CPU-side buffer.
— GLES is not exposed to Flutter GPU because the shader bundle lacks GLSL ES 3.0 variants, even when the backend supports 3D textures.
— Current 3D textures are sampling-only: single mip level, no block compression, no render target usage, and no compute-style writes.
— Memory grows quickly: a 256^3 RGBA8 texture takes 64 MiB, 512^3 takes 512 MiB, so practical sizes are far below hardware limits.
Conclusions

The slice-by-slice upload design spares CPU memory, but the full volume still must be allocated on the GPU, so VRAM is the real constraint.

The GLES gap points to shader compilation infrastructure as the bottleneck, not the absence of backend hardware support.

Cubic memory growth means the practical resolution of a 3D texture is dictated by VRAM budgets long before the reported max dimension.

Concepts & terms
3D texture
A texture with depth in addition to width and height, allowing direct sampling at 3D coordinates. The GPU can perform hardware interpolation along all three axes when the format and sampler allow it.
Trilinear filtering
In the context of a 3D texture, linear interpolation on all three axes at the sampling point, mixing the eight surrounding voxels to produce a smooth value. This differs from the older game-dev meaning of trilinear filtering across mipmap levels.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗