Commit Graph

8218 Commits

Author SHA1 Message Date
Mathias Agopian
ffcccb336e Refactor EVSM shadowing to use per-shadowmap blurring (#9850)
This commit addresses several issues with EVSM blur precision 
and shadow atlas boundary handling by replacing the global layer blur 
with a dedicated, per-shadowmap separated Gaussian blur pass.

Key improvements:
- Per-ShadowMap Blurring: Moved the EVSM blurring and mipmap passes
  from `PostProcessManager` to `ShadowMapManager`. Blurring is now 
  applied individually per shadow map using its specific `blurWidth`, 
  rather than being incorrectly applied across the entire atlas layer.

- Custom EVSM Gaussian Shader: Introduced a new dedicated 
  post-processing material (`gaussian.fs` and `gaussian.mat`) tailored 
  specifically for EVSM. 

- Safe FP16 Accumulation: The new blur shader pre-scales the color
  accumulation using safe FP16 FMA to strictly prevent `+Inf` overflows
  during Gaussian pass sampling.

- Atlas Boundary Clamping: The custom blur shader enforces clamping
  to an explicit sub-rectangle (`bounds` uniform) preventing texture
  bleed across adjacent shadow maps in the atlas.

- Code Organization: Created a new `evsm/` material directory, 
  extracting `vsmMipmap.mat` and registering the new `gaussian.mat`.
2026-03-30 20:55:02 -07:00
Filament Bot
ae48711ae2 [automated] Updating /docs due to commit f9573a1
Full commit hash is f9573a112d

DOCS_ALLOW_DIRECT_EDITS
2026-03-31 00:57:54 +00:00
Mathias Agopian
f9573a112d fp32 texture formats are not necessarily filterable (#9855)
* fp32 texture formats are not necessarily filterable

Mobile devices don't always support filtering of fp32 textures.
This PR adds a query at the driver level.

High precision EVSM is now conditional to this feature being supported.

* use MTLDevice supports32BitFloatFiltering if available
2026-03-30 17:29:11 -07:00
Mathias Agopian
a007b59f39 repair matdbg shader editing (#9854)
The new LineDictionary API requires to call resolve().
2026-03-27 22:08:47 -07:00
Mathias Agopian
d7b10bdd3b update glslang, spirv-tools and spirv-opt to their latest version (#9845)
* update spirv-cross to a0fba56

* update spirv-tools to v2026.1

* update spirv-headers to 04f10f6

* update glslang to 16.2.0
2026-03-27 16:35:56 -07:00
Mathias Agopian
04270afb83 gltf_viewer should use a SUN light (#9848)
this matches the desktop version.
2026-03-27 16:06:28 -07:00
Ben Doherty
3b7ad307ff Dawn: silence availability warnings on macOS (#9849) 2026-03-27 22:54:52 +00:00
Sungun Park
bedbcbb7eb OpenGL: Factor per-thread state out of OpenGLContext (#9830)
The OpenGLContext class in the OpenGL backend currently conflates two
distinct parts: immutable configuration (extensions, bugs, capabilities)
and a mutable GL state cache. This single-object design is incompatible
with a multi-threaded rendering architecture, where each thread requires
a dedicated GL context and, critically, its own independent state
machine/cache.

This refactoring implements the proposed architecture by:
1. Introducing a new OpenGLState class to exclusively manage the mutable
   GL state cache (texture bindings, buffer bindings, etc.) with
   explicit per-thread ownership (e.g., mBackendState and mWorkerState).
2. Ensuring OpenGLContext retains only the shared, immutable
   configuration.
3. Preserving the existing gl.XXX usage pattern by implementing inline
   accessors in OpenGLState that forward read-only queries (e.g.,
   gl.ext.XXX, gl.isES2()) to the back-referenced OpenGLContext.
4. Updating common functions shared between backend and worker threads
   to explicitly accept an OpenGLState& parameter.

This change enables a multi-threaded approach by guaranteeing each
thread operates on its own dedicated GL state cache, while reusing the
shared, immutable context configuration.

BUGS=[487347473]
2026-03-27 20:53:53 +00:00
Filament Bot
58cd8624d2 [automated] Updating /docs due to commit 8a98387
Full commit hash is 8a9838706e

DOCS_ALLOW_DIRECT_EDITS
2026-03-27 20:19:13 +00:00
Mathias Agopian
f0108247d1 Fix various overflow, truncation, and NEON alignment bugs in bitset.h (#9843)
- Fix constant wrap-around: Define `BIT_COUNT`, `BITS_PER_WORD`, and 
  `WORD_COUNT` (fixed typo from `WORLD_COUNT`) as `size_t` rather than 
  `T` to prevent silent overflows on large bitsets using small integer 
  types.

- Fix NEON `all()` truncation: Remove the generic `T` cast to correctly
  evaluate bounds across the full 64-bit vector lanes.

- Fix non-NEON `count()` overflow: Use a `size_t` accumulator rather 
  than `T` to prevent overflow when counting >255 bits on `uint8_t` 
  parameters.

- Fix NEON strict alignment UB: Enforce unconditional `alignas(16)` on 
  `storage` when `BIT_COUNT` satisfies 128-bit vector multiples, adding 
  a compile-time `static_assert` to ensure ABI expectations match NEON 
  load intrinsics.

- Remove dead masking code inside `firstSetBit()`.
2026-03-27 12:51:40 -07:00
Powei Feng
8a9838706e viewer: update sunlight settings (#9846)
Missing the castShadows=true caused the shadows to be missing
on mobile (using the remote settings page).

Update README.md (this will trigger an update to the remote
page's filament.js)
2026-03-27 19:51:28 +00:00
Mathias Agopian
9511be4caa update draco to 1.5.7 (#9844) 2026-03-27 12:20:37 -07:00
Filament Bot
8705a627db [automated] Updating /docs due to commit 4b040fb
Full commit hash is 4b040fbae6

DOCS_ALLOW_DIRECT_EDITS
2026-03-27 06:08:44 +00:00
Mathias Agopian
167a91efaa Optimize Shader LineDictionary (#9814)
* Optimize Shader LineDictionary with Variable-Length 3-Streams

This commit completely reorganizes the string dictionary compression
pipeline used by compiled Material Text Chunks and improves matinfo
dictionary output.

1. Multi-Base Variable-Length Scaling:
We replaced the static 16-bit indices overhead with a
bounded payload. Now, indices scale dynamically:
- 0 to 239 evaluate in 1 byte.
- 240 to 3584 leverage 0xF0-0xFD escapes evaluating in 2 bytes.
- 3584+ are locked behind a 0xFF marker to 3 bytes.
This natively eradicated the massive monolithic lengths and zero-padding
issues previously dominating shader packages.

2. Variable-Length 3-Stream Decoding:
To solve the Zstandard/Zlib entropy fragmentation that conventionally
plagues interleaved variable byte lengths (which previously inflated
our `filament.aar` boundary constraint by +2KB), we segregated the encoded
payloads.

By grouping high-entropy string boundaries into a `Base Stream`
and isolating offset digits inside an `Extension Stream`,
predictive LZ77 ZIP sliding-windows perfectly map
over both arrays independently without disruption.

3. Optimize Numeric Stream using LEB128
Prior to this change, numerical suffixes split from shader
variables (e.g., `param_1024` -> `param_` + `1024`) were fed back
into the localized String Dictionary. Because high-frequency numbers were
assigned disjointed localized IDs per shader variant, LZ77
failed to cross-reference their repetitive structures across
shipped `.aar` archives, fracturing compression sequences.

This patch implements a unified 3-Stream topology. It
extracts numerical primitives (< 32768) away from the baseline
String Dictionary, writing them into an isolated, contiguous
LEB128 array.

By using a dedicated `[254]` Escape Token within the primary stream, numerical
variables maintain exact 1-byte (`< 128`) or 2-byte (`>= 128`)
geometric layouts across all permutations.

The resulting deterministic alignment guarantees that Zlib sliding windows
can deduplicate highly repetitive variables across the
entire application binary block.

4. We use the ShaderStage information to create distinct index ranges, which
further help use 1-byte indices.

Verification Metrics:
 `filament-android.aar`: -7,938 B
 `gltfio-android.aar`: -290,939 B
 `libfilament.a`: -18,464 B

* Optimize shader dictionary by decoding '_' for numeric literals

Most numbers extracted from the shader text are preceded by an 
underscore (e.g., from `_`, `hp_copy_`), which previously caused 
standalone `_` strings to heavily pollute the LineDictionary.

This change removes the standalone `_` from the dictionary index:
- `MaterialChunk` rehydrates the `_` prefix when decoding these numeric
literals.

This frees up dictionary indices, yielding massive byte savings across 
uncompressed binaries (e.g., -28.4 KB for volume_masked.filamat).

* Optimize ShaderMinifier to strip explicit spacing

Spirv-cross outputs GLSL with explicit spacing around generic
operators (e.g., ` = `, `, `, ` ) * `). This padding consumes a 
significant amount of uncompressed bytes across large ubershaders. 

By applying targeted string replacements at the end of the `ShaderMinifier` 
pass, we strip this extraneous padding down to its raw tokens 
(e.g., `a=b`, `a,b`, `a*b`). 

This optimization preserves isolating spaces where valuable, ensuring 
line-dictionary tokens (such as raw `=` or `,`)  remain deduplicated 
instead of fusing into unpredictable variables. 

Impact:
This saves roughly ~9.1 KB in `libfilament.a` and ~3.2 KB in 
`volume_masked.filamat` uncompressed, with proportional gains across 
the downstream LZ4 compressed archives.
2026-03-26 22:41:36 -07:00
Mathias Agopian
4b040fbae6 A new Sky simulation Web demo (#9828)
* sky simulation sample

Also added documentation on how to add another web sample

---------

Co-authored-by: Powei Feng <powei@google.com>
2026-03-26 22:40:34 -07:00
Evan Mezeske
566aeac5ed metal: Clamp minimum stencil texture size to 1x1 to avoid abort due to zero-size texture, e.g. when the attached NSView is being destroyed (#9835) (#9836) 2026-03-26 11:21:07 -07:00
Mathias Agopian
ab2ece54d7 Fix memory safety vulnerabilities in filaflat parsing components (#9832)
* Fix out-of-bounds string read by verifying null-terminator existence
  during extraction.
* Fix heap buffer overflow by validating dictionary string lengths 
  against target shader buffers before copying.
* Fix out-of-bounds array reads by validating chunk-provided lookup 
  indices against parsed dictionary sizes.
* Fix integer wrapping exploits by replacing pointer addition with 
  offset subtraction during chunk size verifications.

Add unit tests for these vulerabilities.
2026-03-26 11:19:08 -07:00
Filament Bot
e28b7dafae [automated] Updating /docs due to commit 7a869e7
Full commit hash is 7a869e7c01

DOCS_ALLOW_DIRECT_EDITS
2026-03-26 06:27:35 +00:00
Powei Feng
7a869e7c01 docs: format docs_src/README.md
to trigger a docs regen
2026-03-25 22:59:48 -07:00
Powei Feng
31d447fec4 github: move some presubmit tests to arm linux (#9831)
- Move filament tests (frontend) to arm linux build
 - Move header check to arm linux build
 - Move backend test and correctness to arm linux
 - Disable a failing GL test (b/495913675) - only fails on arm.
2026-03-26 02:04:38 +00:00
Powei Feng
1a4fdd143d docs: fix missing remote/index.html 2026-03-25 18:33:54 -07:00
dependabot[bot]
077add3170 build(deps): bump requests (#9837)
Bumps the pip group with 1 update in the /test/renderdiff/src directory: [requests](https://github.com/psf/requests).


Updates `requests` from 2.32.5 to 2.33.0
- [Release notes](https://github.com/psf/requests/releases)
- [Changelog](https://github.com/psf/requests/blob/main/HISTORY.md)
- [Commits](https://github.com/psf/requests/compare/v2.32.5...v2.33.0)

---
updated-dependencies:
- dependency-name: requests
  dependency-version: 2.33.0
  dependency-type: direct:production
  dependency-group: pip
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-26 01:01:31 +00:00
Filament Bot
0c9be998d2 [automated] Updating /docs due to commit a73957a
Full commit hash is a73957a590

DOCS_ALLOW_DIRECT_EDITS
2026-03-26 00:21:11 +00:00
Powei Feng
a73957a590 web: refactor examples and tutorials (#9833)
* Refactor web examples and tutorials

- Consolidate web/docs and web/samples into web/examples
- Remove literal programming blocks from Markdown tutorials
- Replace tutorial_template.html with a fully embedded template in serve.py
- Move serve.py to web/examples/serve.py and update dependency rules
- Update filament-js wrapper to expose _malloc, _free and set GEN_MIPMAPPABLE usage
- Update sample materials and WebGL asset generation within web/examples/CMakeLists.txt
- Add python venv instructions and usage details to web/README.md
- Remove obsolete examples, Pipfile, and demo templates

* Transfer web tutorials and samples to docs_src

- Introduce copy_web_docs.py api to deploy and rewrite web sample outputs into the docs output tree
- Hook copy_web_docs into docs_src/build/run.py natively
- Configure duplicates.json to map WebGL outputs to embedded .md docs
- Strip html skeleton out of examples in run.py so they map into markdown cleanly
- Update update-docs workflow to pre-build the WebGL target
- Remove obsolete remote docs path from src_raw
- Add explanatory comments to copy_web_docs.py and run.py
- Add index page with thumbnails for Web Tutorials and samples
2026-03-25 23:52:48 +00:00
Powei Feng
541a4feae1 imgdiff: add positional and frequency robustness parameters (#9822)
- Introduce `shiftRadius` to allow positional tolerances by searching
  a local neighborhood, absorbing sub-pixel shifts and MSAA quirks.
- Introduce `blurRadius` to apply local area averaging, ignoring
  high-frequency noise like hardware dithering.
- Enhance `ImageDiffResult` to include an `averageError` array and
  a 10-bin `errorHistogram` for actionable failure debugging.
- Update Android JNI bindings (`ImageDiff.java` and `ImageDiff.cpp`)
  to propagate the new error distribution statistics to Java callers.
- Update C++ unit tests to cover the new heuristic options.
- Document the new parameters and JSON result format in README.md.
- Add synthetic image generation tests in `tools/diffimg/tests/` to
  validate the CLI tool's handling of spatial shifts and dithering.
2026-03-25 00:31:18 +00:00
Moomba
e22588c4e1 Mark provider creator methods as public in TextureProvider.h (#9819) 2026-03-24 23:13:08 +00:00
Powei Feng
1dcc3c35ae vk: enable depth/stencil readback in VulkanReadPixels (#9823)
This change uses buffers for readback as oppose to image. This
allows for a shared path between color and depth readback.
2026-03-24 20:55:23 +00:00
Powei Feng
aa238b6c53 backend: fix platform getDeviceInfo test (#9827)
The previous test was no op because we didn't go through creating
a driver, which is necessary for both vulkan and gl.
2026-03-24 20:11:47 +00:00
Filament Bot
b0ac4b9c40 [automated] Updating /docs due to commit 9dfd3f7
Full commit hash is 9dfd3f73bc

DOCS_ALLOW_DIRECT_EDITS
2026-03-24 17:03:50 +00:00
Powei Feng
9dfd3f73bc Release Filament 1.70.1 rc/1.70.2-cut 2026-03-24 10:00:22 -07:00
Powei Feng
a102daed53 Update MATERIAL_VERSION to 70 2026-03-23 15:20:26 -07:00
Sungun Park
859d930f60 Fix race condition between program caching and backend's modifying (#9821)
The previous implementation allowed the backend thread to modify the
program state while it was still being cached on the compiler thread.
This could lead to potential data corruption or inconsistent cache
blobs.

To ensure data integrity, the program blob is now cached before the
signal is dispatched. This prevents the receiving thread from modifying
the program (e.g., via glUniformBlockBinding) until the caching process
is fully finalized.

BUGS=[491819760]
2026-03-23 16:12:39 +00:00
Powei Feng
5177b5c973 vk: make fbo eviction time configurable (#9808)
The previous eviction time is too large (40), then causes memory
to bloat over time. We set the default to 3 (as in triple
buffering), but make it a configurable option via VulkanPlatform.

Fixes #9786
2026-03-21 00:57:27 +00:00
Mathias Agopian
6416cf1eaa remove sampleDepth(), inline the code instead. (#9806)
This hides less what actually happens, and allows us to save
a few calls to saturate().
2026-03-20 16:56:55 -07:00
Powei Feng
ddb2de1649 github: support ARM linux in backend and renderdiff tests (#9817)
- Update get-mesa.sh to query dpkg --print-architecture to install
  the correct packages dynamically, enabling aarch64 support.
- Update get-vulkan-sdk.sh to install via apt-get on Linux
  (libvulkan-dev, vulkan-validationlayers, glslang-tools,
  spirv-tools) instead of downloading LunarG's x86_64 tarball.
- Add runner architecture to Mesa and Vulkan SDK GitHub Action cache
  keys to prevent collision.
- Update test.sh and preamble.sh to detect aarch64 and point to
  the appropriate aarch64-linux-gnu libraries.
- Fix typos and some renaming
2026-03-20 22:46:44 +00:00
Patrick Ribas
20aa91edc9 remove sunDisk in skybox at FL0 (#9675) 2026-03-20 10:54:43 -07:00
Powei Feng
d65589bf77 android: [render-validation] add more test result details (#9812)
Add the following information:
 - Android build fingerprint, version
 - GPU driver name, info, vendor name
 - Time elapsed for test
 - Rendered images (as oppose to diff image)

filament-utils:
 - Add DeviceUtils to hook into Platform methods for reading out
   strings about gpu vendor, driver.

Fix "tolerance" in test definition
2026-03-19 23:03:00 +00:00
Powei Feng
81961f6d49 github: [renderdiff] ensure right clang (#9816)
For renderdiff, we compile mesa using brew's llvm/clang, but
we compile filament with the system clang (AppleClang).

This is to prevent compiling filament with brew's clang (which
can cause unexpected compilation error).
2026-03-19 15:29:47 -07:00
Powei Feng
9fbf438baa github: [mesa] ensure right llvm is linked on macos (#9815) 2026-03-19 11:43:03 -07:00
Powei Feng
5007b4e428 android: allow modelviewer to reset (#9813)
- Add reset functionality to ModelViewer
 - We use this reset in render-validation to not have to reload
   the scene in runs that use the same model.
 - Fix a bug where the camera manipulator is disabling setting
   the camera via view config.
2026-03-19 18:11:46 +00:00
Sungun Park
0d2ecb5436 Relocate the read-only property to OpenGLContext (#9811)
This is a preparatory cleanup step to resolve a TSan warning ahead of a
planned refactor of the OpenGLContext class.

BUGS=[491522442]
2026-03-19 03:54:57 +00:00
Sungun Park
f24db4633e Fix crash in OpenGLDriver::destroyStream (#9801)
Fixes a SIGSEGV crash that occurs during
`ExternalStreamManagerAndroid::release()` when users provide a custom
Platform instance during Engine creation.

When a custom Platform is used, ExternalStreamManagerAndroid is
instantiated on the application's thread. Its constructor was caching a
C++ reference (`VirtualMachineEnv& mVm`) to the `thread_local`
VirtualMachineEnv instance belonging to the application thread.

Later, when the Filament backend thread executed `release()`, it
accessed this cached reference. This caused the backend thread to
retrieve the `JNIEnv*` from the application thread's `thread_local`
instance, and subsequently call `env->DeleteGlobalRef()`.  A thread must
use its own `JNIEnv` pointer, so using the application thread's pointer
from the backend thread resulted in a crash.

BUGS=[489814416]
2026-03-19 02:26:58 +00:00
Patrick Ribas
45d92cac14 Silently disable MSAA for FL0. (#9807) 2026-03-18 16:29:36 -07:00
Eliza
c5e915b96c engine: panic if prepareProgram() fails (#9809)
This change crashes Filament with a helpful error message if we ever try to
prepare a program and fail.
2026-03-18 16:28:41 -07:00
Mathias Agopian
e2b195706a fix overdraw visualization in gltf_viewer (#9805) 2026-03-18 09:01:18 -07:00
Powei Feng
3ebb2086ed github: use arm linux instead of x86 whenever possible (#9794)
- Simplify getting cmake, ninja for linux
 - Move linux, web, webgpu builds to use arm (more cores for less)
 - Android cannot be moved due to Android SDK not available on
   arm linux yet.
 - Add Arm Linux release artifacts

Fixes #8674
2026-03-18 07:19:38 +00:00
Mathias Agopian
052092f553 remove the remaining instances of std::string (#9802)
libfilament (including libutils and libmath) are 100% std::string
free.

std::string is pulled in the .so (on android) through libc++ for 
exception handling, even if we're not using them. There is not much
we can do here, but at least, it's not because of us!

utils::ostream still references it but only as an inline function,
so if the inline is not called, std::string won't be pulled in.

It's also referenced from Path.cpp, but that's not included in
libfilament.
2026-03-17 15:27:12 -07:00
Mathias Agopian
7163aaa627 don't output the full shader when matc fails (#9803)
This made it nearly impossible to find the actual error. Now, we
output only the error from the compiler + the material name, variant
and shader stage all in one line.
2026-03-17 13:37:14 -07:00
Mathias Agopian
0c7ff3fcf4 store shadow atlas resolution in frameUniforms (#9804) 2026-03-17 13:36:58 -07:00
Powei Feng
962756e283 gl: add getter for GL_VERSION (#9798)
On Android, GL_VERSION contains information about the driver
version number.  This can be useful when debugging or running
tests.
2026-03-17 17:56:51 +00:00