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
The DebugShadowCasacade material was dependent on frameUniforms,
instead we use material parameters. We also pass all the informations
relative to cascades (it's not used yet, but will be in the future).
- In finish(), instead of block to wait for read pixels to finish,
we poll the state of the counter to ensure that all the readbacks
are complete. This allows us to complete the readpixel callbacks
by advancing webgpu's internal callback counter.
- Remove all the redundant flushes that are no longer needed now
that buffer upload is put on the command queue.
- Add a convenience method for getting swapchain dimensions. Will
be useful.
- Add webgpu as a valid backend for running backend tests on linux
(now that it no longer deadlocks).
- In finish(), instead of block to wait for read pixels to finish,
we poll the state of the counter to ensure that all the readbacks
are complete. This allows us to complete the readpixel callbacks
by advancing webgpu's internal callback counter.
- Remove all the redundant flushes that are no longer needed now
that buffer upload is put on the command queue.
- Add a convenience method for getting swapchain dimensions. Will
be useful.
- Add webgpu as a valid backend for running backend tests on linux
(now that it no longer deadlocks).
This commit addresses a critical security vulnerability (OOB write) and
several stability issues in the Radiance HDR parser.
Primary Fix:
* Fixed a heap buffer overflow in the RLE decoding loop (Issue #9748).
The decoder previously failed to verify if a run-length chunk exceeded
the remaining space in the scanline buffer. Added strict bounds checking
(`num_bytes + run_length > width`) before executing `memset` or
`mStream.read` to prevent arbitrary memory corruption.
Additional Security & Stability Improvements:
* Prevented an infinite loop (DoS) in header parsing. Replaced the
`do { ... } while(true);` loop with proper stream state checking
(`while (mStream.getline(...))`) to handle unexpected EOFs gracefully.
* Mitigated integer overflow and Out-Of-Memory (OOM) vulnerabilities by
enforcing maximum sane dimensions (`MAX_IMAGE_DIMENSION` and
`MAX_IMAGE_PIXELS`). This prevents catastrophic memory allocations
triggered by maliciously crafted width/height values.
* Initialized local variables and buffers (`buf`, `gamma`, `exposure`) to
prevent undefined behavior and parsing of stack garbage upon stream read
failures.
Fixes#9748
Keeping ShaderLanguage::UNSPECIFIED will return metal library
as the preferred language on metal. Here we just make it more
explicit that matdbg needs msl.
Fixes#9372
The toggle for animation was added recently to Settings and default
to false. This differs from before where animation is always assumed
to be enabled.
For gltf_viewer's interactive mode, we enable animation. (Batch mode
will still have animation off).
Fixes#9775
- Include gl_headers.h since it defines BACKEND_OPENGL_VERSION_GL(ES)
depending on which headers are available.
- Don't assume glGetString(GL_EXTENSIONS) returns a non-null value as
null is a possible return value for OpenGL (desktop).
We add the ability for the maniuplator to be null. If it is null,
then the camera settings won't be determined by the manipulator.
This is useful for when we want to set the camera parameters
outside of the modelviewer, but still use it to do everything else.
The init block of addPass will be executed immediately, which means
that even for passes that are culled, we will trip on incorrect format
given to the pass.
We move the stencil check to the execute block of addPass so that
it'll only assert when the pass is actually present in the graph.
FIXES=489437881
* engine: encapsulate material cache handling
We will soon allow `MaterialInstance` to override the value of spec constants.
To avoid code duplication, we introduce a new class `MaterialPrograms` which
handles the chunky bits of managing the program cache and values of the spec
constants.
* MaterialPrograms: add explicit initialize method
* MaterialPrograms: backport fixes, address comments
* MaterialPrograms: set all constants at once
* MaterialPrograms: rename to LocalProgramCache
* utils: add LRU cache to RefCountedMap
This change introduces a new data structure LruCache and uses it in
RefCountedMap to keep a fixed number of cache entries alive after their
reference count has dropped to zero in the main map.
* utils: address LRU cache comments
The FBO cache uses imageviews as its cache key. To ensure that these
views are valid for the lifetime of a key-value pair in the cache, we
need to also reference the rendertarget in the value part of the pair.
The RT contains attachments, which are wrappers around
which own the image views.
Fixes#9680
When more than one external sampler are present the
flow will clone the descriptor set twice and make a copy
of a binding that requires an immutable sampler. The copy
of this binding will cause a crash in some adreno GPUs.
This change will make sure the descriptor set is only cloned one
and after that only update binding operations are done for the
external sampled bindings.
Not all component managers are thread-safe for garbage-collection. In
particular, some need to access the DriverAPI which is never
thread-safe.
We refactor the garbage-collection code into FEngine, so it's not
duplicated in FRenderer. We make it more explicit that
FRenderableManager::destroyComponent() needs the DriverAPI, and we
don't call its gc() from a job.
Besides the refactoring, the only change in this CL is that
FRenderableManager::gc() is no longer called from a job.
FIXES=[489134910]
- refactoring/clecanup to make some changes easier
- VSM mipmap generation was mistakenly disable when blur radius was 0
- analytic variance was disabled because the math only worked for VSM. Fixed the math.
- better handling of large blurs when using fp32
- implement EVSM equivalent of receiver plane normal bias
- use correct EVSM clearing color
- mipmapping with point lights works much better (no seams)
- min variance is computed automatically
- custom high precision mipmaping shader for VSM
Android App:
- Refactored activity_main.xml to use modern Material 3 components.
- Grouped Export/Help buttons logically and moved ADB instructions
to dedicated info icons.
- Added an in-app "Load Test" button to explicitly pick test bundles.
- Updated ValidationInputManager.kt to gracefully handle relative
zip_path intent execution via ADB targeting app external storage.
Tooling & Documentation:
- Added a Python Textual TUI (validation_app.py) to automate device
discovery, test execution, bundling, renaming, and
downloading/uploading.
- Added README.md in test/render-validation documenting ADB intent
parameter capabilities and TUI dashboard setup.
The problem is that we might flush when resizing happens. So
we need to ask for the command buffer "after" the resize/acquire
swapchain logic.
Fixes#9718
It's no longer necessary to preallocate a "tag" to reuse a material
instance. Instead, we can simply pass a unique tag when getting the
instance from the pool.
* Provide thread name when attaching to JVM on Android
When calling AttachCurrentThread on Android, pass a JavaVMAttachArgs structure. This allows providing the thread name, which is retrieved using pthread_getname_np, to the JVM.
* Fix Android build error: pthread_getname_np requires API 26+
---------
Co-authored-by: Mathias Agopian <mathias@google.com>
The VSM variant bit was overloaded, it meant two different things
depending on the DEP bit (depth).
For standard variants (DEP = 0), it decides the type of the shadow
sampler used (PCF or 2D).
For depth variants (DEP = 1), it decides what is written during the
shadow pass (nothing, i.e. depth only, or EVSM depth moments).
We now clearly separate the two bits throughout the code.
This change should be purely source-cosmetic, there shouldn't be any
behavior changes.
Co-authored-by: Powei Feng <powei@google.com>
The previous code used the max of the texel's width or height footprint
in world space to compute the offset; this could both overestimate or
underestimate the bias causing some peter panning or acne.
The new code replaces a sqrt with a dot, but is otherwise similar.
The previous code was a bit clunky and not generic, it made assumptions
about the shape of the projection matrix.
This just uses the generic, correct calculation.
In addition the previous code used the wrong matrix, it assumed that
Wp wasn't needed, but it was because translations do change the
jacobian value at a given point.
RDIFF_ACCEPT_NEW_GOLDENS
- Introduces the `RDIFF_ACCEPT_NEW_GOLDENS` commit message tag.
- Conditionally skip the `test-renderdiff` presubmit comparison
if this tag is present.
- Extracts renderdiff generation into a reusable
`.github/actions/renderdiff-generate` composite action.
- Modifies `postsubmit-main.yml` to automatically generate new
goldens and push them to a temporary
`accept-goldens-<short-hash>` branch before merging them into
`main` when the tag is found.
If a framebuffer is destroyed while a command buffer is in flight (e.g.
during a window resize), it's possible for a command buffer to try to
use a framebuffer that no longer exists. This encapsulates framebuffers
and render passes in resource_ptr, to ensure they are never reclaimed
prematurely.
The previous datareshaper change used too multiple parameters
in templates in an attempt to reduce conditionals in the hot-loop.
However, this dramatically increased the binary size.
This change keeps the original intention of not having conditional
in the inner loop, but isolate small sections that need to be
templated into separate components.
* Adding the begin frame message for later xtrace post processing.
* Add the flags.
* Cleanup
* Cleanup
---------
Co-authored-by: Powei Feng <powei@google.com>
- Add a presubmit check after the android build to check the
built artifact sizes against previous build sizes.
- If the size built is +20K over the previous, then the test
fails.
- This prevents dramatic size increases of our mobile build
- add half float as source type
- gray-scaled output when src-channel=1 and dest-channel=3 or 4
- Ensure that per-pixel work is as-constexpr-as-possible
* fixbug:"debug error, reason: The material 'Material_MR' has not been compiled to include the required GLSL or SPIR-V chunks for the vertex shader (variant=5, filtered=5)",Because the member variable mVariantFilter is not initialized, random values will appear on Windows 10 or others platform, which eventually causes some variants to be filtered out by this mVariantFilter.
* fix:Fix morph target loading for accessors without buffer_view
Morph targets were not working because ResourceLoader skipped all
accessors without buffer_view. For morph targets, the data can be
accessed directly via cgltf_accessor_unpack_floats().
This fix properly unpacks and uploads morph target vertex data to the
GPU, enabling blendshapes and facial deformation to work correctly.
Steps to Reproduce
1、In Unity (2022.3.11): Create a Prefab with Blend Shapes (Morph Targets) and an Animator to control them (e.g., an animation clip that makes the eyes squint).
2、Export: Use the UnityGLTF tool to export the model as a .glb file (including the Animator and Morph Target tracks).
3、In Filament: Load and play the animation.
4、Result: The skeletal animation (bone-based) may play, but the Morph Target effect (squinting) is missing or static.
- Update UI
- Wait for resources to finish loading before testing
- Refactor validation to input/output
- Move assets to be generated from the repo
- Fix AutomationEngine java binding to add missing fields
- Add a script to test/sizeguard to compute sizes of artifacts
within a compressed file.
- Add a step to postsubmit-main.yml that will run the above
script on every commit to main.
This will enable us to add a presubmit step to guard against
dramatic size increases in the Android build.
This fixes#9701 by replacing shell execution (`shell=True` and
`os.system`) with direct subprocess calls using argument lists in
`tools/zbloat/zbloat.py`
Previously, the script used f-strings to pass paths directly into a
shell command, which created an unnecessary risk: if an external archive
contained files with shell metacharacters, it could lead to accidental
or malicious command execution during analysis.
By passing arguments as lists, the subprocess module maps them directly
to the executable, bypassing the system shell and eliminating the
vulnerability.
When UboManager::reallocate() is triggered, a large number of material instances may be invalidated simultaneously. This leads to a massive spike in descriptor set updates and command generation, which can overflow the circular buffer.
To prevent this, we now flush commands in batches, we trigger a flush whenever the command buffer usage exceeds half of its capacity. (Like what RenderPass::Executor::execute does)
BUGS = [474264976, 479079631]
When UboManager::reallocate() is triggered, a large number of material instances may be invalidated simultaneously. This leads to a massive spike in descriptor set updates and command generation, which can overflow the circular buffer.
To prevent this, we now flush commands in batches, we trigger a flush whenever the command buffer usage exceeds half of its capacity. (Like what RenderPass::Executor::execute does)
BUGS = [474264976, 479079631]
In some cases the external image to be imported is
flagged as using a sRGB dataspace but when the AHB
is imported its actual format is UNDEFINED and
requires an external sampler.
In these cases, its not valid to set the
VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT flag.
See VUID-VkImageCreateInfo-pNext-02396
FIXES=[483456747]
Introduce a new cube sample that utilizes the feature level 0 (FL0) on
the web. The `Engine.create` method accepts `config` as an argument,
allowing users to explicitly request a GLES 2.0 context.
In addition, this change helps a future implementation of asynchronous
support for web, allowing the asynchronous mode to be turned on via the
configuration setting.
BUGS=[476134614]
* VK: Fix the descriptor set layout mismatch errors
Depending on how the descriptor sets and external
sampled images are used is possible to get a lot of
errors about the pipeline layout and the descriptor
set layouts dont match with the validation layers.
This causes flicking artifacts and textures not being
displayed.
This is a partial rewrite of the implementation when
using external samplers through a MaterialInstance.
* Addressing review comments
This tool uses existing libraries: image, imageio, imageio-lite,
imagediff to perform difference comparison for on-disk images.
We refactor renderdiff to use this tool instead of using
python dependencies.
Co-authored-by: Ben Doherty <bendoherty@google.com>
These three formats would likely break even if used on a device where
they are supported, as we reshape all 3-channel buffers to 4 channel.
The data would be in the wrong format.
We will have to follow-up, as there are other formats that are affected,
but those formats likely have better driver support, as they are better
aligned formats (e.g. 16-bit, 32-bit). These three formats were 96-bit
formats, which we've remapped to 128-bit.
These three formats would likely break even if used on a device where
they are supported, as we reshape all 3-channel buffers to 4 channel.
The data would be in the wrong format.
We will have to follow-up, as there are other formats that are affected,
but those formats likely have better driver support, as they are better
aligned formats (e.g. 16-bit, 32-bit). These three formats were 96-bit
formats, which we've remapped to 128-bit.
the current swapchain is associated to the default rendertarget, but
the later doesn't know which attachments the swapchain actually has.
it used to hardcode COLOR and DEPTH, but it's possible for the
swapchain to have a STENCIL attachment.
The proper way to do this is to use the swapchain's attachments when
the default rendertarget is used (which means the swapchain is used).
FIXES=[482120868]
- This is an initial implementation, not yet complete
- Goal of this sample is to run a series of offscreen single
frame captures, and capmre the result against a set of golden
images
- Uses existing scene description in libs/viewer and
test/renderdiff
- Uses existing image difference description/implementation in
libs/imagediff
- Add imagediff API to filament-utils-android
Enables the multiview implementation as the default for stereoscopic
rendering. Now all STE variants use the multiview path.
This change removes all CMake configurations, build scripts, and C++
preprocessors previously used for selecting stereoscopic rendering
modes. And, all shaders are now compiled for multiview.
The instanced rendering implementation is going to be removed. Note that
this commit only handles switching the default. The actual removal of
instanced rendering code will be submitted as a separate follow-up
commit.
BUGS=[470198472]
* implement some missing javascript bindings
DOCS_FORCE
* use exclusively javadoc comments in Options.h
This is because this file is currently used to generate java and
javascript bindings and doxygen can ingest javadoc.
And regenerate javascript and java bindings
* add missing java bindings
View::setChannelDepthClearEnabled utilizes `clearDepth.mat` internally,
which is not compatible with multiview since clearDepth is
post-process.
This update converts clearDepth.mat into a surface shader, allowing it
to hold the STE variant. This change enables the shader to function
correctly in multiview.
BUGS=[470198472]
1. Iterate over system displays using eglQueryDevicesEXT and try to initialize them.
2. If no display initialized, then try to initialize the DEFAULT display.
FIXES=[478925865]
Patching a fix for the external sampler use case where the same sampler is bound to two different indices. As it stands, the code fails to differentiate between the two layouts.
* fix artifacts on mobile
* feat(skybox): Add moon and milky way rendering
This commit enhances the simulated skybox with the following features:
- **Moon Rendering:** A textured moon with normal mapping has been added. The moon's phase is calculated and rendered correctly. Earthshine is also simulated.
- **Milky Way Background:** An equirectangular milky way texture is now rendered in the background. The intensity and saturation of the milky way can be adjusted.
- **Asset Processing Scripts:** Python scripts have been added to download and process the moon and milky way textures. This includes generating a normal map from a displacement map for the moon.
- **GUI Controls:** The GUI has been updated to include controls for the moon (azimuth, height, intensity, radius) and the milky way (intensity, saturation, sidereal time, latitude).
- **Real-time Sync:** The application can now use the user's geolocation to automatically set the position of the sun and moon.
- **Sun/Moon Calculation:** The library has been added to calculate the position of the sun and moon.
DOCS_FORCE
A preliminary commit to add a websocket server to the DebugServer.
This will enable us to transfer large data (like images) across
to the frontend.
This is part of the work to enable viewing intermediate
render buffers in fgviewer.
Instead of computing the fog "inline", in the forward pass, we can
instead compute it as post-process pass that is applied with a
simple fullscreen quad blending. On tilers, the operation entirely
stays in the tile, on desktop GPU it is a blending operation.
This works only for opaque materials.
The benefit is that fog will become immune to overdraw, and the forward
pass shader will be simplified, hopefully leading to less register
pressure. Overall performance should be improved.
Another benefit is that it will allow us to free the "fog" texture
slot from all opaque materials.
Transparent materials are unchanged.
This feature is currently DISABLED, and still work in progress; but it
should be mostly functional.
To test it:
```
env material.enable_fog_as_postprocess=true ./out/samples/gltf_viewer
```
This change refactor the fog code, but shouldn't have any impact on the
current behavior.
- Add new library to do tiff import/export. This library is
different from imageio in that it doesn't pull in additional
3p libraries. This reduces binary size and reduces
complexity in maintaining the android build (which depends
on libs/viewer).
- The encode() code has been moved from libs/viewer to
libs/imageio-lite
- encode/decode only handles the simplest case of uncompressed
rgba.
Patching a fix for the external sampler use case where the same sampler is bound to two different indices. As it stands, the code fails to differentiate between the two layouts.
1. Iterate over system displays using eglQueryDevicesEXT and try to initialize them.
2. If no display initialized, then try to initialize the DEFAULT display.
FIXES=[478925865]
Because of an improper boundary check caused a possible unsigned
integer overflow, it was possible to overrun the command stream
buffer in RenderPass::execute().
It would happen when the batch size was larger than the buffer
capacity (usually a few MB).
FIXES=[474264976]
Because of an improper boundary check caused a possible unsigned
integer overflow, it was possible to overrun the command stream
buffer in RenderPass::execute().
It would happen when the batch size was larger than the buffer
capacity (usually a few MB).
FIXES=[474264976]
- Fix Moon normal calculation in shader (was inverted).
- Implement physically based Earthshine (dynamic based on phase).
- Add Moon scattering to Water reflection.
- Fix Star occlusion (masked by Moon).
- Improved Stars
- Add mobile touch support (Orbit control) to Camera.
DOCS_FORCE
However, the change also pulled in filament-android-release-linux.tgz,
which already contains the same content, into the release.
Here we just rename filament-android-release-linux.tgz to the
expected .tgz output file in the release build.
Fixes#9647
- **Key Minification**: Refactored serialization to use short keys
(e.g., `p`, `c`, `w`) instead of verbose property names, reducing URL
size by ~50%.
- **State Optimization**: Removed redundant `sunDirection` from
serialized state.
- **Cleanup**: Removed backward compatibility for verbose keys
- **Bug Fix**: Fixed a regression where UI sliders failed to update on
load by ensuring array properties (e.g., `sunHalo`) are mutated
in-place rather than replaced.
DOCS_FORCE
- **State Management**:
- Refactored main.js to expose local UI parameter objects as class
properties for serialization.
- Implemented getURLState() to capture complete scene configuration
(Sky, Clouds, Water, Stars, Camera, Bloom).
- Implemented applyURLState() to restore settings and synchronize
the UI.
- **URL Sharing**:
- Added "Share Configuration" button to the UI.
- Configuration is Base64-encoded into a `config` URL query parameter.
- App now automatically parses and applies the `config` parameter
on startup, allowing for stateful deep linking.
DOCS_FORCE
* engine: add program cache
This is another chunky change.
The core of this change is to cache programs in MaterialCache according to a
"specialization" (ProgramSpecialization) which is defined as the program cache
ID (the same key used for the OpenGL binary blob cache), the variant, and the
set of spec constants.
As part of this change, a lot of the implementation details of shader
compilation were refactored from Material to MaterialDefinition. The resulting
flow is a lot cleaner and easier to reason about, since shader compilation is
now a pure function of the MaterialDefinition + ProgramSpecialization.
Since the global cache program lookups might take a bit of time to compute
hashes, etc, I left the set of cached programs in Material as well, which kind
of acts like an L1 cache. The effect is that prepareProgram() and getProgram()
should be no slower than HEAD, even with the more complex caching requirements.
I'm planning on writing a document about this (and all changes up until this
point), but I'm being asked to work on higher priority things and I wanted to
have this PR out for review in the meantime so it doesn't bitrot.
* engine: fix unit tests
* engine: fix spec constants intern pool memory leak
* engine: address program cache comments
* engine: address more program cache comments
* engine: matdbg support for program cache
* engine: reinstate descriptorLayout calls
* engine: address bitrot
* engine: add feature flag to disable program cache
* engine: use material CRC32 for program cache
The "cache ID" of a material is supposed to uniquely identify a shader program
and all its variants. This is true to a certain extent, but does not account for
the code generation that happens at runtime. Two materials may have "identical"
shader programs, but due to each material's differing unique metadata, the final
compiled programs may end up very different. Unfortunately, this means we cannot
rely on the "cache ID" alone to determine a shader program's reusability.
Ideally, we should hash this "cache ID" with the exact set of changes to each
shader program so that we could reuse programs across materials. Instead, as a
stopgap solution, use the material's CRC32 instead.
* engine: fix double-free in program cache
* engine: address comments
* engine: assert_invariant empty material cache
- we were setting the tag of the descriptor set to its layout, so
both tags were incorrect.
- added in debug build we now store the tag of the bound descriptor
sets in the current bindings structure.
This change upgrades AtlasAllocator from a simple linear allocator
(reset-only) to a full Buddy Allocator capable of both allocation and
deallocation. This enables persistent shadow map management where
individual shadow maps can be updated or resized without rebuilding the
entire atlas every frame.
Key changes:
- Implemented AtlasAllocator::free():
- Uses the existing QuadTree structure to track allocations.
- Automatically coalesces empty sibling nodes back into larger
parent blocks (standard Buddy Allocator behavior).
- Optimized to be allocation-free and recursion-free, using direct
array indexing.
- Added comprehensive unit tests
Updated documentation.
The QuadTreeArray implementation remains unchanged but is now fully
utilized for bidirectional tree traversal (down for alloc, up for free).
This change will later allow us to cache shadow-maps.
The AtlasAlocator is currently disabled by a feature flag.
In the cases where a frame takes more than the vsync
time, we start seeing some rendering artifacts because
we write to a buffer that is currently in flight.
Not 100% sure why the current approach fails but for
now, the staging buffer is bypassed only when the buffer
is not in use or referenced by any other resource.
FIXED=[445455050]
FIXED=[477305399]
- Extended Settings to include properties for Camera, Animation, Lights,
and Render options.
- Moved camera options from Viewer options to Camera options
- Implemented generic JSON parsing for these new settings in Settings.cpp.
- Updated AutomationEngine to apply these settings, including dynamic
creation of lights.
- Fixed a JSON parsing bug in AutomationSpec that failed on nested objects.
- Updated gltf_viewer to use the new settings and correctly initialize
AutomationEngine context.
- Add test for new json changes
- Add README to libs/viewer
- Link libs/viewer/README.md to official doc
- Remove unused libs/viewer/schemas
- Updated remote web assets (because the viewer/settings json needs to
match)
- **Stars**:
- Implemented procedural stars using hash-based noise.
- Added UI controls for Star Density and Enable/Disable.
- Tuned star brightness (reduced intensity) and refined twilight fade timing (visible during nautical twilight).
- Improved compositing with aggressive cloud occlusion and non-linear fade.
- Added star reflections to water, strictly masked to the horizon line.
- **Heat Shimmer**:
- Fixed horizon artifacts by decoupling shimmer from atmospheric density (Mie scattering).
- Implemented FBM-based view distortion for heat waves.
- Added sun elevation fade (shimmer fades out as sun rises > 30°).
- **Water**:
- Implemented Finite Difference normal calculation as a high-quality fallback when "Derivative Trick" is disabled.
- Added "Octaves" parameter to control wave detail.
- Refined reflection logic to handle stars and sun disk properly.
- **System**:
- Updated [simulated_skybox.mat](cci:7://file:///Users/mathias/sources/git/filament/docs_src/src_raw/wip/sky/simulated_skybox.mat:0:0-0:0) with new material parameters (`starControl`, `waterControl`).
- Refactored JS bindings in [SimulatedSkybox.js](cci:7://file:///Users/mathias/sources/git/filament/docs_src/src_raw/wip/sky/SimulatedSkybox.js:0:0-0:0) and organized `main.js` UI into logical folders.
DOCS_FORCE
PerformanceHint manager needs a java thread during initialization,
so we need to attach a jvm to the thread that's going to be used.
That thread is the filament backend thread, not necessarily the thread
the platform is created on.
So we make sure to do that from the backend thread.
FIXES=[427945768]
Currently, in Vulkan, we set the pipeline layout when binding the
pipeline, which doesn't happen until draw time when external samplers
are present. In cases like that, we push constants with the layout
VK_NULL_HANDLE, which is not valid. Instead, we can wait until the
pipeline layout is known, and then flush all push constants.
The command batching logic in RenderPass::Executor::execute calculates a
conservative `maxCommandSizeInBytes` to determine how many commands can
safely fit in the driver's circular buffer.
However, this calculation failed to account for the dynamic memory
allocation incurred by the Per-Material descriptor set binding (via
`MaterialInstance::use`). This binding allocates a `DescriptorSetOffsetArray`
in the command stream, which was unbudgeted.
In scenarios with frequent material and scissor changes, the accumulated
deficit from these unbudgeted allocations could exceed the buffer
capacity, leading to a crash.
This change:
1. Adds the missing accounting for the Per-Material dynamic allocation
to `maxCommandSizeInBytes`.
2. Adds a 20% safety margin to the calculated size to robustly handle
alignment padding and worst-case scenarios.
FIXES=[474264976]
- Add plumbing to add more information about rendertargets
(including discard flags and pass id) to the fgviewer pass
struct.
- Add UI to display information about a selected pass
- Highlight a selected resource or pass
The new tone mapper, dubbed "GT7" in the code, is based on
the Gran Turismo 7 tone mapper, as described in the SIGGRAPH
2025 presentation called "Driving Toward Reality: Physically
Based Tone Mapping and Perceptual Fidelity in Gran Turismo 7".
This tone mapper exhibits fewer hue skews than the other tone
mappers, at the exception of PBR Neutral. The GT7 tone mapper
is however better at preserving the perception of high
dynamic range.
The tone mapper, as implemented, targets an SDR paper white
of 250 nits, using 100 cd/m^2 as the reference luminance (for
values of 1.0 in the linear HDR framebuffer). This can result
in an overall darker image compared to the other tone mappers
but this can be controlled through camera settings, post-
processing exposure, or lighting intensity.
The GT7 tone mapper also allows to target HDR output, and
could be made customizable via APIs if desired. The current
implementation offers a fixed aesthetic solution.
- Add documentation for specgen along with proper math rendering
- Adjust the heading size, capitalization of various READMEs.
- Add backend test README to the doc
- Rename the CI related tests to have prefix "CI:"
Introduces a new sample application demonstrating asynchronous resource
management. It shows how to asynchronously create and update Filament
resources (Textures, VertexBuffers, IndexBuffers) and provides examples
of managing chains of asynchronous operations effectively.
BUGS=[442921995]
- Pick a default view when database is filled.
- Fix d3, d3-graphviz depdency.
- reduce the size into a smaller table (to avoid scrolling)
- slant the pass items to allow smaller cells for the table.
- make subresource rendering the same as regular resource
rendering with a color hint.
- Use color-only to indicate resource/pass interaction (read,
write, read-write, no-access)
- add tooltip to indicate resource action
Right now, if a material is destroyed just after creation, it's possible
for prewarm to attempt to use destroyed shader modules. This ensures
that the resources are kept until after any queued jobs have run.
While it is likely ideal to properly cancel the prewarm if the program
has been destroyed, this seems like a rare occurrence in practice.
Right now, if a material is destroyed just after creation, it's possible
for prewarm to attempt to use destroyed shader modules. This ensures
that the resources are kept until after any queued jobs have run.
While it is likely ideal to properly cancel the prewarm if the program
has been destroyed, this seems like a rare occurrence in practice.
When an asynchronous object is destroyed immediately after creation, the
background creation process may still be active, holding a reference to
the object. We now defer destruction in these cases until the creation
process completes to ensure the reference remains valid.
Implementation details:
1. Add a mechanism to stop the ServiceThread to drain pending
asynchronous tasks earlier. This ensures the mCreationComplete flag
in the frontend object is set to true.
2. Later, the engine's terminate performs garbage collection for the
deferred destruction. All of them must be successfully processed.
BUGS=[442921995]
- Reorder the release-related documents into one heading.
- Added CocoaPods README as part of the documentation.
- Fixed typo for renderdiff doc
- Added backend test doc
Certain older compilers (e.g. clang in NDK 25.1.8937393) cannot
handle the c++ stylistic changes that were recently added
(though they are correct by spec).
- In Engine.cpp, .find() cannot automatically infer the right type
(std::string_view vs. utils::CString).
- In fg/framegraph, various templated short-hands still require
typename.
* feat(engine): Add automatic frame skipping to manage CPU/GPU latency
Introduces a new feature, disabled by default, that allows the engine to automatically skip frames when the CPU gets too far ahead of the display's refresh rate. This helps to reduce overall latency by preventing a backlog of frames from building up in the driver queue.
The feature can be enabled with the "engine.skip_frame_when_cpu_ahead_of_display" property.
To implement this, the compositor timing mechanism has been refactored. Instead of reporting an absolute `expectedPresentTime`, the backend now provides an `expectedPresentLatency` relative to vsync. This is more robust against synchronization issues with platform callbacks (like Android's Choreographer), as the latency is generally a constant value.
BUGS=[474599530]
Removed implicit dependency on FEngine::getDriverApi() in critical
rendering paths. This change makes the DriverApi dependency explicit by
passing it as a parameter.
Key changes:
- FRenderer: Now accepts DriverApi& in renderInternal and renderJob.
Caches feature levels and capability flags in the constructor.
- PostProcessManager: Caches feature flags and workaround flags in
init(). Updated PostProcessMaterial and configure* methods to accept
DriverApi&.
- FMaterial: Caches support flags (stereo, parallel shader compile) and
default material pointer in the constructor.
Updated precacheDepthVariants and prepareProgram to rely on these
cached values or passed parameters.
- ShadowMapManager: Caches workaround flags in the constructor.
- FEngine: Updated prepare() to accept DriverApi&.
- RenderPass: Updated to accept DriverApi& in constructor and
appendCommands.
- Removed implicit DriverApi calls from hot paths to reduce overhead
and improve safety.
One common pattern in this change is to cache getters in constructors
so that we don't need the DriverApi dependency later during rendering.
The intention here is to remove DriverApi& from as many places as
possible so that we can later have multithreading for command
recording.
This PR should not change any behavior.
This commit clarifies and corrects documentation in several public header
files. The changes include fixing typos, improving wording, and adding
missing details to make the API easier to understand and use.
No functional changes are included in this commit.
Provides logic to load and check for external format ids, and
build fake pipelines against them when relevant, to prevent
hitching when using external formats.
For now, we're going to use upto five likely types of YCbCr
conversions, which seem to cover all usecases encountered. This
means we might compile pipelines with external samplers a total of
4 additional times on top of the baseline (5 in total), or 3 additional
times on the devices we're currently testing (4 in total).
* Add base pipeline prewarm call for ext samplers
This is necessary because in some cases, a material that supports
external samplers will use RGB inputs instead of YCbCr inputs, and will
miss the cache.
Provides logic to load and check for external format ids, and
build fake pipelines against them when relevant, to prevent
hitching when using external formats.
For now, we're going to use upto five likely types of YCbCr
conversions, which seem to cover all usecases encountered. This
means we might compile pipelines with external samplers a total of
4 additional times on top of the baseline (5 in total), or 3 additional
times on the devices we're currently testing (4 in total).
* Add base pipeline prewarm call for ext samplers
This is necessary because in some cases, a material that supports
external samplers will use RGB inputs instead of YCbCr inputs, and will
miss the cache.
* split FeatureFlagManager out of FEngine
- Separate the Feature flags management from FEngine.
- Make FeatureFlagManager available to backends through DriverConfig
- add a way to override a feature flag value at runtime using
environment variables or system properties (on Android).
e.g.:
```
env "feature.name=true" gltf_viewer
```
or
```
adb shell setprop debug.feature.name true
```
Co-authored-by: Powei Feng <powei@google.com>
- Add code for handling empty/null constant name
- Use glUniform1ui() instead of glUniform1i() to workaround
crash on macbook pro (m4).
- Fully specify the constant name in the test (e.g.
`pushConstantsF.red` instead of `red`).
- Make sure that the uniform names are different between
vertex and fragment in the test. This is due to different
constant structs being defined between the two stages.
FIXES=453757504
Prevents hitching for most pipelines, on certain devices with Turnip-based drivers
This does not address external samplers yet. This simply handles the
case where we want to prewarm a pipeline with the base configuration.
Refactor program's descriptor set layout bindings, clean up some leaking
resources
This commit introduces a significant rework of the Temporal Anti-Aliasing (TAA) system, focusing on improving reconstruction quality, robustness, and introducing flexible upscaling.
Core TAA Algorithm improvements:
- Replaced the Catmull-Rom filter with a more efficient 5-tap Lanczos filter for history sampling, which includes deringing to reduce artifacts.
- The input color buffer is now properly "unjittered" using a Lanczos reconstruction filter.
- Improved the history rejection algorithm by skipping the expensive accurate clipping when the history sample is already within the neighborhood's color gamut.
- Added a new `hdr` option to properly handle HDR content by tonemapping colors before blending and untonemapping the result.
- Removed the ineffective `VARIANCE` only history rejection method.
- Added protection against negative numbers in `sqrt()` for increased stability.
TAA Upscaling:
- Replaced the boolean `upscaling` flag with a float factor, allowing for variable upscaling ratios (e.g., 1.5x, 2x).
- Upscaling now correctly adjusts viewport and projection settings.
- The TAA shader now receives viewport and resolution information to correctly handle upscaled rendering.
API and Configuration Changes:
- Deprecated the `filterWidth` TAA option as it no longer has an effect.
- Introduced the `upscaling` float property to `TemporalAntiAliasingOptions`.
- Added the `hdr` boolean property to `TemporalAntiAliasingOptions`.
Other Changes:
- Updated UI elements in the viewer and material sandbox to reflect the new TAA options.
- Updated Javascript bindings and TypeScript definitions for the new TAA settings.
- Refactored shader code for clarity and performance.
makeCurrent is not meant to acquire the swapchain; we should
do so at the momemnt we need it, to shorten the amount of time
a swapchain image/buffer needs to be held.
Since the struct refers to descriptors as opposed to specifically
bindings (although they do contain binding information as well), this
name is more appropriate.
- spectral reconstructions with 4 samples
- unroll the whole dispersion computation to improve performance
(batch texture fetches and reuse common values)
- tool to generate the matrices for spectral integration
This commit simplifies and unifies the FrameGraph's `addPass` API.
Key changes:
- The `addPass` method now uses a single, more flexible implementation
that handles different lambda signatures for both the setup and
execute stages.
- The execute lambda can now optionally omit the `DriverApi&` parameter,
reducing boilerplate for simple passes.
- The `addTrivialSideEffectPass` helper has been removed.
Side-effect-only passes can now be created directly with `addPass`
- Add support for vector parameters (float2, float3, float4) in the
parameters file using `{x, y, z}` syntax.
- Allow comments (`#`, `//`) and empty lines in the parameters file.
- Make the end value optional in the parameters file
(defaults to start value).
- Add `--size` / `-S` option to specify viewport dimensions.
- Optimize rendering by pre-filtering active material parameters.
- Remove hardcoded default parameters and silently ignore missing
parameters to support shared configuration files.
- Add documentation for the parameters file format.
- Split the function so that the 3-components loop is more apparent.
- Factored out the parts of the computation that don't depend on the
index of refraction, so they're only computed once.
- Moved the lod-from-roughness computation out of the loop as well.
It does depend on the IOR, but so little that it's not worth it.
The most important result of this change is that the code is now in
good shape if we wanted to change the implementation of dispersion for
these cases (for e.g.) :
- do the computation in the XYZ space
- use more than 3 wavelengths samples
- or use a stochastic approach, trading banding for noise
RDIFF_BRANCH=ma/better-dispersion
* Update createPipeline to have pipeline key input
Right now, createPipeline in VulkanPipelineCache assumes that you are
building a pipeline using mPipelineRequirements as the key, and that it
should be stored in the cache. In the case of the pipeline prewarming
change, this is not going to be the case; sometimes, the pipeline will
be stored in the cache, and sometimes it will be deleted immediately.
Also, the prewarmed pipelines will be created using separately defined
keys.
* Add knobs for enabling / disabling prewarm
* Add thread pool to VulkanPipelineCache
* Fix dynamic rendering enablement check
Query device features to ensure it is supported / we don't just have the
extension. Also, proactively enable dynamic rendering when creating the
device.
Currently only uniform buffers benefit from the bypass,
but this can also be extended to others buffers too.
This also help trying to match the performance of the
GL backend in Android.
FIXES=[470138463]
Co-authored-by: Serge Metral <sergemetral@google.com>
Api level is now enforced when generating code by appending #defines of client requested and unstable apis.
This ensures that the client can only use unstable apis when they explicitly add `apiLevel` in their .mat file.
FIXES=468340631
* rename ResourceAllocator to TextureCache
This better represents what this class is for.
* Make FrameGraph resource management extensible
This refactors the FrameGraph's resource management to allow for
user-defined custom resources.
A new `ResourceAllocator` template abstracts the creation and
destruction of resources, with specializations for different resource
types (e.g., generic, backend-dependent, textures).
This removes hardcoded resource management logic from the `FrameGraph`
execution loop.
A `ResourceCreationContext` is introduced to provide the necessary
context for resource allocation.
Tests for generic and backend custom resources have been added to
validate the new system.
* Update filament/src/fg/FrameGraphDummyLink.h
Co-authored-by: Powei Feng <powei@google.com>
---------
Co-authored-by: Powei Feng <powei@google.com>
This commit introduces async methods and functions across both the
public and backend APIs, enabling non-blocking creation and updates for
Texture, VertexBuffer, and IndexBuffer resources.
Asynchronous resource management is disabled by default. Users should
enable this to use the feature.
Java bindings and a C++ code sample will follow in subsequent PRs.
BUGS=[442921995]
- add a flag to run the sample using regular, non-external
texture as render target.
- Add a non-external version of the material
- vk: fix y-flipping issue with uvToRenderTargetUV()
The main goal of this CL is to break the dependency of RenderPassBuilder
on DriverApi. The dependency only existed for the auto-instancing
feature, which needed to allocate and update a UBO on the fly.
We want to break that dependency so that RenderPassBuilder::build().
which is an expensive call, could run on a separate thread. In the
future this could allow, for example, shadow and ssao passes to
run in parallel.
A new method RenderPass::finalize(DriverApi&) is added which *must* be
called before calling getExecutor(), this is where the temporary
UBO is allocated and updated. We need a new method because this must be
called on the main thread before a render pass is started.
This implementation stores the UBO data needed for instancing until
finalize() is called, if any.
We introduce a compact() utility that efficiently scans a range finding
"equivalent" consecutive objects and removes duplicates. The previous
code did that with an extra remove pass which invalidated all
iterators.
* VK: Refactor platform Vulkan initialization
Refactor the platform code to allow overriding
how the vkInstance, vkPhysicalDevice and vkDevice
are created.
This refactor will also consolidate where the extensions
and features are enabled/disabled into VulkanPlatform,
instead of each platform doing its own individual setup
if needed. It also address knowing if a feature or
extension has been enabled, unless we keep adding
entries to the SharedContext which is not scalable.
The createDriver function now have a more defined structure,
mostly how and where features are queried and enabled.
- Get shared context data.
- Create instance if missing.
- Select physical device if missing.
- Query physical device support and set supported
engine features into the VulkanContext.
- Select the queues
- Create the device and queues
* Address review comments
Added some documentation on the new functions
Move the querying and config of features into its
own function.
* Workaround for harmless warning about descriptor sets
The proper fix is difficult and will be handled later. Here we simply
suppress the warning at FL0.
BUGS=[468072646]
* Apply suggestions from code review
The "const char*" used for the string literal parameter of the `feature`
method becomes invalid once it passes outside the Java binding scope,
leading to invalid data access. This fix ensures the string is safely
stored.
Add support for heterogeneous lookup in associative containers that
use CString keys. Add conversion operators for std::string_view and
raw string literals to CString.
When emulating UBOs for feature level 0, we need to use packed
mat33 as source of glUniformMatrix3fv which doesn't expect the std140
alignments of UBOs.
FIXES=[468092808]
For reasons unknown, selenium will freeze when trying to make
request to the local server serving the markdown files. We add
a delay between the server and the selenium driver to hopefully
address this.
DOCS_FORCE
webgpu: refactors WebGPU Platform so each OS environment has its own WebGPU Platform
class derived from the same base, and use virtual functions for their own implementations.
The breakage is due to breaking changes in the latest version.
We use the repo checked-in version instead.
Also make sure postsubmit.sh script exits on any error
* add support for AHardwareBuffer to the java bindings
Texture.setEXternalIamge() now can take a AHArdwreBuffer Java object
as a parameter.
* add an API to set the priority of the Skybox
by default the skybox is always drawn last (priority 7) in order to
reduce overdraw. however, when depth culling is not enabled, it
needs to be drawn first. The new Builder::priority() allows to set
an arbitrary priority for the skybox.
* add rendertarget support for external textures
This was in fact mostly already supported, we just were artificially
preventing that usage. It is supported by the EGL_external_image
extension.
It's the responsibility of the caller/user to not attempt to use an
incompatible format, which has undefined behavior.
FIXES=[466395306]
* add a new android sample to test the AHardwareBuffer as render target
---------
Co-authored-by: Powei Feng <powei@google.com>
This change adds support for the KHR_materials_dispersion glTF extension, which introduces a dispersion property for refractive materials.
The dispersion property controls the angular separation of colors transmitting through a refractive object, allowing for more realistic rendering of materials like glass and diamonds.
Changes include:
- Added a dispersion property to the material definition.
- Updated the shaders to incorporate the dispersion effect in the refraction calculations.
- Added a new test case for dispersion.
- Updated the material documentation to include the new dispersion property.
this is not an error that should warrant an assertion, since it's
possible for fences to not be supported at all.
FIXES=[467782111]
Co-authored-by: Powei Feng <powei@google.com>
Seems to actually be initializing an engine
Failed with
reason: /Users/runner/work/filament/filament/filament/backend/src/opengl/platforms/PlatformCocoaGL.mm:177: failed assertion 'success == kCVReturnSuccess'
A. Move filament_test_material.cpp to be part of test_filament
(This won't be triggered during the windows build)
B. Add chaining dependencies in third_party/draco/tnt so that
there is no race in writing/reading generate.stamp
-------------
Failures
-------------
A.
C:\a\filament\filament\out\cmake-mtd\filament\test\resources\filament_test_resources.c(1,1): error C1083: Cannot open source file: 'C:\a\filament\filament\out\cmake-mtd\filament\test\resources\filament_test_resources.c': Permission denied [C:\a\filament\filament\out\cmake-mtd\filament\test\test_material_parser.vcxproj]
B.
CUSTOMBUILD : CMake error : Cannot restore timestamp "C:/a/filament/filament/out/cmake-mtd/third_party/draco/tnt/CMakeFiles/generate.stamp": Access is denied. [C:\a\filament\filament\out\cmake-mtd\third_party\draco\tnt\draco_compression_bit_coders.vcxproj]
- Fix Android build in build.sh so that the tools dir are
properly set to corresponding folders for debug vs. release.
- Update/consolidate documentation to explain the Android Studio
workflow better.
- Move documentation from outdated apps folder to BUILDING.md
- only MapAsync the staging buffers that are not being used by any command anymore (the commands have finished executing on GPU)
- additionally, in WebGPUQueueManager, create a blank new submission state when a new command encoder is generated instead of in submit()
BUGS=450620535
When the frame history's circular queue is full and the oldest
frame is not yet ready to be processed, we must skip the current
frame.
This change ensures that if `beginFrame` is skipped, the
corresponding `endFrame` is also skipped. This prevents data
corruption in the frame history.
Address potential issues in FrameInfoImpl and FrameInfoManager:
- Modify FrameInfoManager::beginFrame to handle cases where the
circular queue is full and the oldest frame is not yet ready,
logging a warning and skipping the frame.
This prevents potential use-after-free or data corruption by
ensuring only ready frames are removed from the history.
FIXES=[466081317]
PlatformEGLAndroid holds onto the current swapchain in order to use
it when beginFrame is called. Usually the swapchain is set just before
beginFrame is called. However, that's not the case for standalone
views. These are independent of the swapchain and doing "swapchain
stuff" for them is nonsensical.
So make sure that:
1. PlatfromEGLAndroid doesn't hold onto a dangling pointer when the
swapchain is destroyed. And add proper null checks.
2. Don't do the "swapchain stuff" when beginFrame is called in the
context of a standalone view.
We now reserve frameID 0 for that purpose (meaning the frameid is
non sensical for these).
We're currently relying on frameID to not wrap-around. At 120 fps,
that's about 1 year. This will be addressed in a later PR.
FIXES=[462827028, 461399487]
PlatformEGLAndroid holds onto the current swapchain in order to use
it when beginFrame is called. Usually the swapchain is set just before
beginFrame is called. However, that's not the case for standalone
views. These are independent of the swapchain and doing "swapchain
stuff" for them is nonsensical.
So make sure that:
1. PlatfromEGLAndroid doesn't hold onto a dangling pointer when the
swapchain is destroyed. And add proper null checks.
2. Don't do the "swapchain stuff" when beginFrame is called in the
context of a standalone view.
We now reserve frameID 0 for that purpose (meaning the frameid is
non sensical for these).
We're currently relying on frameID to not wrap-around. At 120 fps,
that's about 1 year. This will be addressed in a later PR.
FIXES=[462827028, 461399487]
filament_test_material should not need to depend on a "fixed"
(or checked in) material.
Now the dependent .filamat is generated as needed as is
packaged with the checked-in test_material.filamat as before.
also
- update the android build script to pull the version from
build/common/versions
- remove the ability to specify your own ndk version (this was
undocumented and not fully implemented)
The NDK version now needs to appear in two place (unfortunately):
1. build/common/versions
2. build/android/build.sh
`-mcpu` is intended to target a specific CPU instruction set and
optimization. That's not what we want to do here. What we want is
target an architecture, specifically armv8-a. So we use `-march`
instead. On 64 bits builds, we tune for cortex-a78, which is the
df the Pixel7 era. This doesn't mater much, but might give a little
boost on newer CPU cores. The idea here is that we care "less" about
older CPUs.
- Make sure that renderdiff fails when either building or
rendering fails (the previous problem was in the use of &&
that masked the non-zero exit).
- Make sure that golden branch is properly parsed in
postsubmit.yml
- Disable vk loader debug by default
This change fixes an intermittent crash caused by a thread race
condition.
The crash happened when a CallbackHandler::Callback (triggered by
engine.flush()) attempted to create an instance of a Structure of Arrays
(SoA) like TransformManager, which adds items to SoA) at the same time
that the garbage collection job (FEngine::gc, which removes items from
SoA) was running.
This conflict is resolved by modifying the logic to ensure that the
garbage collection task completes synchronously before the callback
operations begin.
* Adding the begin frame message for later xtrace post processing.
* First commit
* This is not needed
* Bypass the AHB* issue.
* Typo: Forgot to remove the function.
* Typo: No const specifier.
* Removing the const.
* no exception
* Feedback from discussions with Powei.
* Making the changes discussed with the team.
* Removing useless comments.
* Adding the required methods for allocation.
* Forgot one more switch case.
* Moving the resource to fvkmemory::Resource type.
* Adding streamed set.
* Allocating every frame for streamed textures.
* Changing the binding logic.
* Proper checks for the streamed texture.
* Cleanup.
* Chaning the logic of the state tracking for streamed textures.
* Fixed full screen bug.
* Refactoring of the code.
* Typo.
* GitHub feedback.
* Github feedback
* feedback.
* Typo
* Feedback.
* Feedback.
* Feedback
* Feedback
* Feedback
* Fixing the Android path.
* Fixing the Android path.
* Feedback.
* feedback
* Feedback.
* Nit
* Feedback
* Feedback
* Feedback
* vk: fix update after bind (wrt descriptor set) validation error
In filament, once a descriptor set is bound, we no longer make updates
to it. However, this guarrantee was broken in the external sampler/image
because a colorspace change might necessitate a layout change, and
thereby a new descriptor needs to be generated with the appropriate
externally sampled image updated in the new set.
Another use case is the Stream API, where each frame we might be
getting a different AHardwareBuffer, meaning we need to update one
or multiple sampler bindings in a set that might have been bound in
a previous frame.
In this change, we always create a new set when there's a change
in the image currently bound to an existing set (while accounting for
whether we need to use a new externally sampled layout or not).
* Removing the decision on whether to use external format or not out of the streamed texture manager. The issue is that all textures are external, not all are using external format. But it's more robust to let the external format image manager rely on the AHB* to decide if the format is external or not. Regardless (because the memory is external) we need to send this to the external image manager.
* Fixing the validation layer in the Stream CL.
* Typo and comment clarification.
---------
Co-authored-by: Powei Feng <powei@google.com>
- this is not true fro headless swapchains
- and potentially some timings might not be available on a given nativewindow
Previously the code would handle these errors gracefully, but the
errors were still generated. Now, we query the availability and only
make the calls if supported.
Also on EGL, we don't attempt to use private APIs -- this code path
should never be used anyways.
Depth testing come with a cost, so when the depth
test is marked to always pass and writting to depth
buffer is disable, just disable the feature.
This will also match the GL backend behavior.
- this is not true fro headless swapchains
- and potentially some timings might not be available on a given nativewindow
Previously the code would handle these errors gracefully, but the
errors were still generated. Now, we query the availability and only
make the calls if supported.
Also on EGL, we don't attempt to use private APIs -- this code path
should never be used anyways.
The frameId coming from a Renderer must be monotonic when seen from
a SwapChain (Specifically a ANativeWindow on Android), if it's not
the case, we must clear that part of the history.
This can happen if a SwapChain is used with two different Renderer; at
this point that SwapChain's history is no longer connected to that
Renderer.
The frameId coming from a Renderer must be monotonic when seen from
a SwapChain (Specifically a ANativeWindow on Android), if it's not
the case, we must clear that part of the history.
This can happen if a SwapChain is used with two different Renderer; at
this point that SwapChain's history is no longer connected to that
Renderer.
- Adjust order of destroy call in both headless and platform
swapchains. We need to be careful of the order due to
assumptions made by the base class's destroy().
- remove `=0` since VulkanPlatformSwapChainBase::destroy() has
an implementation.
Fixes#9403
* HandleAllocator::deallocate() was unsafe
It needs to know the concrete type to call the proper destructor, so
if it was given a base type handle (e.g. Handle<HwFoo>) it would not
destroy it properly.
* add AsyncJobQueue::cancelAll()
* Fix a race condition when tearing down FrameInfo
It is actually invalid to destroy a Handle<HwFence> while inside
fenceWait().
Updated the HwFence implementations so that they don't pretend they can
handle being destroyed during fenceWait(), they can't.
FrameInfo now cancels all the pending callbacks and waits for the
currently executing one to terminate, *before* destroying the
handles.
Reenable the gpuFrameComplete metric, as it should be working now.
With minSDK less than 26, it's unsafe to use APIs in nativewindow.h
that appeared at API 26 or more, even when using the weak symbol
technique. This is because pre 26, libnativewindow.h didn't exist and
therefore the build system cannot link against it.
Currently Filament's minSdk is 21, which means we should never use
nativewindow.h API after 26.
In this PR we chose the strategy at compile time; either the more
modern weak symbol or the old way with dlsym based on __ANDROID_API__.
queryFrameTimestamps() and queryCompositorTiming() are both
synchronous APIs, but VuklanSwapchain is not a thread-safe
ref-counted handle (i.e. fvkmemory::ThreadSafeResource). We move
the Platform::SwapChain* pointers to a thread-safe map that is
mapped by the handle id.
* Check for null fences to avoid segfault in tests
In some test environments, creating a sync or fence backed by an Android
fence returns null. In order to avoid NPEs, cover this scenario with a
null check.
* Address PR - add log statement
Log that native fences are not supported when unable to create a native
sync fence.
The deadlock happened because FrameInfoManager needs to wait that all
fences have signaled before it can be destroyed.
The fix here is simply to destroy the fence without waiting (for safety
we do wait after we destroy them).
This uncovered another problem where all backends didn't handle this
correctly.
We now explicitly handle this when destroying a fence: we make sure it
unblocks all the waiters and returns an error.
FIXES=[457243841]
This is needed to instantiate `std::streampos`. It currently relies on transitive header inclusion to get that, which is going away for libc++ in ebcf1bf2ec.
The parser object was accessed to generate a key after being passed to
the lambda using std::move(). This led to a crash on certain platforms
(at least on Windows).
This change fixes it by creating key first before moving the parser
object into the lambda.
This new method, intended for the vertex shader, returns a matrix that
transforms vertices from view space (also known as head space) to the
current eye space.
BUGS=[441127971]
In ZstdHelper::isCompressed call, `src` may not be aligned to 4 bytes,
which is violating the alignment requirement of
`UndefinedBehaviorSanitizer: misaligned-pointer-use`, thereby resuling
in a runtime failure with UBSan enabled. So reconstruct the 32-bit
integer as a workaround.
In EGLAndroid, external textures imported from an AHB
that dont use a SAMPLER_EXTERNAL are not properly destroyed,
causing a memory leak that eventually leads to an OOM.
- add conveniences function to make LineDictionary look like a vector
- a pattern must start on a word boundary but "_" wasn't treated as one
- getIndices() must return the empty vector when any of the substring
is not found
We link the behavior of certain precondition/postcondition checks to feature flag states.
- If provided *flag* is true, then this macro will assert when the *condition* is false.
- If provided *flag* is fase, then this macro will output a warning when the condition is false.
- If the condition is true, then neither of the above will happen
These two macros will enable us to provide less restrictive behavior for certain correctness assertions, allowing clients to modify their before enabling these assertions by default.
* gl: Enhance error reporting for asynchronous shader operations
When ShaderCompilerService asynchronously compiles and links shaders,
unexpected errors (e.g., GL_CONTEXT_LOST) can occur after the initial GL
call, complicating diagnostics.
This change improves error context by collecting the GL error status
when querying shader compilation and program link statuses. This
provides a more detailed understanding of error origins.
BUGS=[373396840]
* feedback
When a program was created directly from a cached blob in
`ShaderCompilerService`, its associated token was not signaled as ready
in the THREAD_POOL mode. This oversight caused a deadlock at the
`token->wait()` call during program destruction.
This commit resolves the issue by skipping the token's readiness check
upon destruction if the program was created from the cache blob.
BUGS=[423221474]
This reverts a behavioral regression introduced in commit c3542b135e,
which deferred callback submission until the program was first used.
This commit restores the correct behavior by submitting the callback
handle as soon as the token's work is complete. This occurs either upon
successful `gl.program` population or via cancellation, ensuring the
caller is properly notified that the resource loading operation has
concluded.
The addition JobSystem.cpp allows for defining
FILAMENT_TRACING_ENABLED across targets.
Addingin FILAMENT_TRACING_ENABLED to the #if in Tracing.h prevents
perfetto from being included.
There was several issues:
1) when we're switching contexts (e.g. between protect and regular) we
needed up reattach all SurfaceView (i.e. streams), because they need
to be attached on currently active context.
2) reattaching, because it's implemented as detach + attach, would
destroy the current gl texture id and create a new one. However,
because of the way descriptor-sets were implemented, that GL
texture id was kept inside the descriptor, later leading to using
a destroyed texture id.
The fix here is to store texture handles in descriptors, so that
we can update the id independently.
3) we also needed to invalidate all bound descriptor sets because it's
now possible for descriptor sets to have outdated descriptors
- Some tests require textures larger than 2048. Change the minimum
to 4096 for now, and file proper bugs for tests.
- The introduction of uint8_t to DescriptorSetLayoutBinding
caused unintended padding with using this struct as a hash key.
We comment out the relevent code for now.
Just like mCulling, mShadowCulling needs to be inherited from the
material.
Fix breakage introduced in #8422 with attempted fix in #8475 and
caused by an uninitialized variable (mShadowCulling).
BUGS=[391679058]
If FXAA is the last post process effect (i.e. no upscaling), and
color grading produced a luma channel, then FXAA needs to reset the
alpha channel to 1.
This will allow a more lenient rollout of the assertion, which
otherwise will increase crashes for current clients.
We also disable features.engine.debug.assert_material_instance_in_use
by default (it was enabled for debug builds).
If the shared osmesa lib is not found, then we assume that the
library has been compile-time linked via the linker. This is to
accommodate build frameworks where compile-time linking is
preferred.
This restores the old behavior with depth variant caching. We pay the
price at engine init time, instead of when the variant is needed the
first time. We can revisit this later.
Note that the default material doesn't have all possible depth variants
(e.g. VSM), but that pre-caches the most popular ones.
BUGS=[381946222]
On ES2 devices (or in forceES2 mode), we emulate the sRGB swapchain
in the shader if the h/w doesn't support it. In that case, the emulation
is controlled by a uniform that technically lives in the frameUniforms
block. However, the frameUniforms buffer is not updated, instead,
the uniform is manually set. Unfortunately, the UBO emulation
overrides it with the uninitialized variable.
BUGS=[377913730]
Mesa always clears the generic binding if the buffer deleted
is bound to an indexed binding, even if it's not bound to the
generic binding.
BUGS=[371324321]
- We change GLDescriptorSet::Buffer default constructor to
workaround a client's compiler set up issue.
- We removed the assert_invariant that checks that ubo/samplers
are not changed after committed in DescriptorSet. This caused
an existing client's build to crash.
Found through testing that renderStandaloneView+vk+swiftshader
seems to cause synchronization issues, which results in incorrect
rendering. Here we workaround the issue by forcibly flush and
wait per renderStandaloneView call.
BUG=361822355
`DebugRegistry::setProperty` is no longer just applicable to debug
builds.
This change was previously added in 6c0bd36 but then reverted
in a7317e7. We re-enable it and separate it from the shadow
changes in this commit.
This fixes a crash introduced by a8ace2891d
The refactored FrameInfoManager can cause a crash when IBL resource loading
happens because now the getLastFrameInfo() references an invalid value via the
`front` method. Return the default FrameInfo to resolve this.
Also fix a null pointer reference bug for OpenGLTimer::State, which
happenes when the renderer for IBLPrefilterContext is destroyed.
- remove deprecated morphing APIs
- repair gltfio, samples and tests
The new API doesn't allow a MorphTargetBuffer per RenderPrimitive,
instead the MorphTargetBuffer is specified per Renderable.
gltfio separates RenderPrimitives from Renderables, in particular all
RenderPrimitives are created before their Renderable; this was
problematic for this change because all primitives must share
a single MorphTargetBuffer living in the Renderable.
To fix this, we're no longer initializing the morphing paramters
at RenderPrimitive creation, instead we store a reference to the
BufferSlot in the Primtive structure, so that later, when the Renderable
is created we can finally retrieve the BufferSlot and initialize its
morphing paramters, which are not available. The "morphing parameters"
are now expanded to contain the MorphTargetBuffer as before (except now
it's always the same for all the primitives of a Rendrable), as well
as the offset within the buffer and the vertex count.
If a user is using `setFrameScheduledCallback()`, managing the provided PresentCallable during engine shutdown is tricky -- we'll likely get a final frame scheduled when we flush the engine's work queue, but the PresentCallable will schedule the final CAMetalDrawable to be released on main thread afterwards, even if we call `present(false)` to skip it. If the swap chain is destroyed before that main queue block gets executed, the mutex presenting that drawable will no longer exist, causing a crash.
To make things easier, store the std::mutex in a shared_ptr, so that a PresentCallable can safely outlive the FSwapChain instance that created it and clean itself up afterwards.
Alternatives considered, all of which seem unfortunate:
* Require users to clear out the callback before shutting down the engine, so that any final drawables are immediately discarded instead of using PresentCallable
* Require users to split up the engine teardown across two main queue blocks, ensuring that the PresentCallable cleanup executes before swapchains are destroyed
* Drop the PresentCallable on the ground and leak the memory
PresentDrawable was moved to main thread by default in google#7535 and stopped
most crashes when a drawable is released. But there still appears to be crashes
if a drawable is released on main thread at the same time that -nextDrawable is
called from the Filament render thread. (It's likely that the drawable pool in
CAMetalLayer is completely non-thread-safe.)
So, add a mutex to the swapchain and always acquire it before creating or
releasing a CAMetalDrawable.
Users can opt out of this behavior by passing
-DFILAMENT_LOCK_METAL_DRAWABLE_POOL=0.
Currently, if this fails we log the error message to stderr (which
doesn't get captured by most crash reporting systems) and then crash in
a postcondition assert. By including the error message in an exception
reason and throwing an ObjC exception, we get better discoverability of
error causes.
(Building a render pipeline state from shaders is usually when a shader
actually gets JITted from LLVM IR to GPU-specific code, so if we
accidentally used a feature that's not available on the local GPU, we'll
find out about it here.)
The current API allowed to have a buffer for each primitive in a
renderable. We instead restrict the API so that there is a single
MorphTargetBuffer for the whole renderable, shared by all primitives.
The buffer can be shared thanks to the "offset" parameter on
setMorphTargetBufferAt().
Also
- fix FMorphTargetBuffer::updateDataAt()
- add support for the "offset" parameter of setMorphTargetBufferAt()
If a .metallib was compiled with a target iOS version that's newer than
the current device, loading the .metallib may succeed, but finding main0
(or any other function in it) will fail. Currently, this causes a crash
due to an assert. Logging the error and returning
MetalFunctionBundle::error() makes the crash slightly easier to
diagnose.
(Note that in practice, this will probably be a useless "Compiler
encountered an internal error" message -- the GPU backend is crashing,
and the Metal stub library sees XPC_ERROR_CONNECTION_INTERRUPTED. It
retries up to 3 times (crashing each time) and then gives up.)
I was unfortunately naive about the way that Filament handled external textures
on non-GLES platforms. This fix restricts the changes to Android (which is the
only place this change is required in the first place). Long story short, the
change broke WebGL. Desktop seems to be unaffected.
the gl backend did some of its cleanup in the its destructor,
including calling into OpenGL, however, the destructor is called from
the main thread, not the GL thread, so these calls would be no-ops at
best, and crashes in the worst case.
This PR adds a new `pause()` option to the `Engine` `Builder` and a new function
`setPaused()` to the `Engine`. While paused, the rendering thread will pause
indefinitely for commands as if none are available. As soon as the rendering
thread is unpaused, the commands are immediately executed.
in case the swapchain creation fails, it will now return a swapchain
with an EGL_NO_SURFACE handle. this will avoid having to nullptr check
the pointer in various places and will revert to the previous behavior
on failure.
FIXES=[329659681]
Previous commit [1] changed the semantic of the index to
mBufferObjects. Here we just make sure that if a buffer has been
allocated, we don't allocate another (otherwise, we'd leak).
Also cleaned up `updateBoneIndicesAndWeights` indexing
[1]: a3131a64b6
The OOB would happen is the scene never had any renderables, in that
case the scene's SoA would stay unallocated, but the summedAreaTable
code relies on it have at least a capacity of 1.
It was incorrect to skip the RenderPass entirely because it might have
had some custom commands that needed to be executed (e.g. for applying
post-processing in subpass mode).
This has caused issues and over time we have reduced the use of
spinlocks, it was only used in few places and we still have evidence
that it's causing ANRs.
We use utils::Mutex instead which is a low overhead mutex implementation
on Linux systems.
FIXES=[321101014]
See #7415 for a more detailed description of why this change is necessary.
The remaining variants which are filtered from FL0 materials are all related to
lighting, so further hacks like this won't be necessary.
Future work involves properly supporting differing sets of variants based on
shader language.
Even if skinning is not fully implemented on FL0, we have clients which depend
on materials with skinning variants that otherwise could easily be converted to
FL0 materials. There are two proper ways to deal with this:
1. Support skinning/morphing in Feature Level 0.
2. Allow ESSL 1.0 code and ESSL 3.0 code to support different sets of variants.
However, the simplest solution is to just include skinning/morphing variants,
but disable codegen for ESSL 1.0 code, making them identical to the base
variants. This shouldn't increase the file size much due to the dictionary
deflation. Of course, skinning will not work correctly on FL0, but this has
always been the case. Future work here would be to properly implement one of the
two solutions described above.
Swiftshader runs spirv validation before compilation. However,
the validation does not like having Nop (no-op) in the input.
So we skip instructions instead of writing no-op for the
output of `workaroundSpecConstant`.
Also, fix issue to keep the value in the original shader if a
specialization wasn't provided.
The CL introducing the ESSL 1.0 chunk in materials inadvertently disabled
optimizations for said code. This commit reintroduces those optimizations and
fixes associated bugs which manifested. In particular, spirv-cross was
generating uints for bools; this has been fixed with a hack. Additionally,
spirv-cross is now compiled with exceptions enabled so that matc can gracefully
fail and show the code which failed to compile rather than abruptly aborting.
Since #7358 is blocked by an upstream spirv-cross issue, we can at least do a
bit of preprocessor optimization for ESSL 1.0 code in the meantime and introduce
the FILAMENT_EFFECTIVE_VERSION preprocessor definitions.
This change in glslang removes the include of "intermediate.h" from
GlslangToSpv.h:
62de186c33
As a result, the definition of "class TIntermediate" is removed, and
will fail compilation of MaterialCompiler.cpp when glslang is updated to
a version including the aforementioned change. We fix this by adding an
explicit include to this header in MaterialCompiler.cpp.
Co-authored-by: Powei Feng <powei@google.com>
- gltfio: Enable -Wall -Werror for gltfio_core
- gltfio: Fix various errors that were missed warnings
- matdbg: switch from std::atomic_uint64_t to
std::atomic<uint64_t> for older clang
- we were not using the correct field in ShadowMapManager
- we were not computing the transform correctly, it should applied
after the local transform, not before.
FIXES=[299310624]
We've seen hangs/ANR that are not well understood on that spinlock, so
for now we're going back to mutexes, which, on android, are very
efficient under low contention (no syscall).
FIXES=[308029108]
* prevent public classes from being created on the stack
- we used to to this by deleting operator delete, but this prevented
the internal "F" classes from being virtual; which can be useful
when using EntityManger::Listener.
now we just make the destructor protected in each class.
- EntityManger::Listener now has a virtual destructor so that
objects could be correctly destroyed from Listener*
* improve EntityManger and Component managers
- all component managers now have the same "base" API
- getComponentCount()
- empty()
- getEntity()
- getEntities()
- Scene now has getEntityCount()
- EntityManager now has getEntityCount()
- all component manager implement gc() the same way, by calling destroy()
- SingleInstanceComponentManager::gc() that calls removeComponent() has
been removed because it's dangerous. removeComponent() is often
not enough, some additional cleanup might be needed.
CameraManager creates a Transform component for each Camera component
is not already present. However, it didn't destroy the transform
component when it's itself destroyed. the leaked transform component
would eventually be garbage collected, but caused significant
slow down and memory pressure. This is because camera components are
created every frame for the shadow maps.
FIXES=[303914944]
- the insert and retrieve handlers can now be set/unset independently.
this could be useful for debugging.
- program caching is disabled if the GL implementation doesn't support it.
- removed unused code
FIXES=[307549547]
This reverts most of commit 9a6b8bf24e. The hello
triangle sample remains unreverted.
The original commit inadvertently broke screen space reflections, and perhaps
other features when the default material was used. The source of the issue is
that MaterialBuilder.cpp (correctly) filters out variants that aren't supported
in feature level 0 materials, including screen space reflections.
Unfortunately, while the "feature level 0 compatibility" feature itself was
intended to make creating duplicate materials like this redundant in client
code, unfortunately, it seems the best solution for resolving this issue is to
simply keep these redundant materials in the core.
To elaborate: clients should expect that feature level 0 materials that they
create work on /all/ feature levels /exactly/ or /close to exactly/ identically.
This includes restricting more advanced features that theoretically could be
available on a higher feature level, like SSR. It's already true that if a user
would like to optionally opt-in to a more advanced material which takes
advantage of more advanced features, they would have to maintain two separate
versions of that material: one for feature level 3 and one for feature level 1.
It should be no different in this case.
However, the materials built into the engine core are an exception to this
expectation. Given that feature level 0 was tacked on after the fact with fewer
features, there must /by necessity/ have been a new material introduced for both
the default material and the default skybox specifically for feature level 0
with fewer features than extant client apps expected to be included by default.
I imagine if filament were to be rebuilt from the ground up, this exception
wouldn't exist. However, the end result is this somewhat messy redundancy.
We wrote a bool directly into 4 bytes (as the first byte). This has two issues:
- the other 3 bytes are not initialized
- should be writing VK_TRUE/FALSE instead
This reverts commit 58f96be2c4.
This caused material files to increase in size significantly. It turns
out that glslang has to generate a copy for each parameter that is
passed to a function as a non-const parameter.
This revert will break IMG devices again, but that should be the case
only on debug builds. Release builds lose the const qualifier by
virtue of going through spirv. We'll try to address this some other
way later.
This reverts commit 58f96be2c4.
This caused material files to increase in size significantly. It turns
out that glslang has to generate a copy for each parameter that is
passed to a function as a non-const parameter.
This revert will break IMG devices again, but that should be the case
only on debug builds. Release builds lose the const qualifier by
virtue of going through spirv. We'll try to address this some other
way later.
Previously, we have a VulkanSync with a default constructor that
allows us to have sync objects that returns error when
actual fences are not yet present. We need to replicate that
with VulkanFence since sync objects have been removed from the
API.
Fixes#7034
this is needed on armv7 because we use alignas to get strcture-alignment,
but that also implies (to the compiler) that the structure itself
is aligned properly.
There was two related issues:
- we need to "latch" the new TextureView size when its resized. That
can only be done by recreating the EGLSurface (i.e. recreating the
SwapChain). UiHelper now calls onNativeWindowChanged in the case of
the TextureView resize, so clients can recreate their SwapChain.
- we also needed to make sure that all current filament frames have
finished to render (i.e. the last eglSwapBuffers has been called) so
that they don't pick-up a new size (this happens after
eglSwapBuffers) that doesn't match the viewport.
Fixes b/282220665
- flush() and wait() before destroying a swapchain
- Make sure the debug marker extension is enabled under correct
circumstances.
- Change shared_ptrs to unique_ptrs and raw pointers.
- Rename most teardown methods to terminate()
Since cmake 3.25 LINUX is automatically set based on CMAKE_SYSTEM_NAME,
which the android cmake files are setting to "Linux". This created an
inconsistant state in our build system.
Since cmake 3.25 LINUX is automatically set based on CMAKE_SYSTEM_NAME,
which the android cmake files are setting to "Linux". This created an
inconsistant state in our build system.
WebGL complained about:
Precisions of uniform block 'ShadowUniforms' member
'ShadowUniforms.shadows.texelSizeAtOneMeter' differ between VERTEX and
FRAGMENT shaders.
this field didn't have a precision qualifier, this might be specific to
WebGL or a Chrome bug, unsure. Either we fix it by specifying all
qualifiers.
WebGL complained about:
Precisions of uniform block 'ShadowUniforms' member
'ShadowUniforms.shadows.texelSizeAtOneMeter' differ between VERTEX and
FRAGMENT shaders.
this field didn't have a precision qualifier, this might be specific to
WebGL or a Chrome bug, unsure. Either we fix it by specifying all
qualifiers.
glDispatchCompute requires Android API level 21, however bumping our
required minimum from 19 to 21 caused some clients' builds to fail.
Commenting-out that line for now to proceed with the 1.28.0 upgrade.
The VulkanProgram constructor was bailing out early and emitting a
warning because it saw that one of the stages wasn't fulfilled.
However it's okay for a pipeline to be missing a compute program.
Fixes regression that started with fabba73b1.
to emulate the bindless API in the gl backend we always used the highest
texture unit available. However at feature level 3, we support up to 62
textures, so the that max was bumped to 62 -- however, where we're not
on a feature level 2 device, that texture unit doesn't exist.
Instead we now always use binding 31, which is guaranteed to exist by
EGL's minspec.
This broke asyncGetLoadProgress() and caused WebGL to crash reliably
because ResourceLoader got destroyed too soon.
Bug was introduced with de7dfc2ea6.
I intend to cherry pick this to rc/1.27.0, which is where it was
introduced, so there's no need to update the release notes.
Filament does not yet fully support threads with WASM, but this is a
baby step in that direction.
To enable experimental pthreads support, enable the WEBGL_PTHREADS CMake
option. This will enable pthreads support in `gltfio` and `utils`, which
is known to work, but not when served with GitHub Pages.
The web server must emit COOP, COEP and CORP headers, so our build
instructions now recommend the use of `emrun` for local testing.
This also changes our demos so that they do not use unpkg, which
does not work when using `emrun`, due to cross-origin restrictions.
I have disabled building SDL with headless EGL, because
SDL_config_minimal.h doesn't work with EGL, and I don't know how to
implement a an SDL config that would work with EGL.
I have verified that this works in a separate project, and that it
compiles in this project.
```
$ ./build.sh -e release
$ find ./out/ -name "*EGL*"
./out/cmake-release/filament/backend/CMakeFiles/backend.dir/src/opengl/platforms/PlatformEGL.cpp.o
./out/cmake-release/filament/backend/CMakeFiles/backend.dir/src/opengl/platforms/PlatformEGLHeadless.cpp.o
./out/cmake-release/libs/bluegl/CMakeFiles/bluegl.dir/src/BlueGLLinuxEGL.cpp.o
```
Reflects a change from Betty and should be cherry picked to v1.23.3
Users could customize the ImGuiHelper camera, but they had no control
over the scissor coordinates. This allows them to use vertically flipped
coordinates, which, unfortunately, is required for MediaPipe
integration.
a 64 bytes pool seems to work with both clang and msvc, unfortunately,
c++ doesn't let us know the allocator object size at compile time
for map containers, so we have to guess.
This is a temporary workaround for a memory corruption issue observed on
some devices from a specific vendor. We will try to make this workaround
more targeted in a subequent change.
Partial revert for b2cdf9f2b4.
This fixes the emscripten binding errors that we've been seeing
with the <filament-viewer> test page, which prevented us from
including web in the last few Filament releases.
The binding errors were caused by double-initializing the emscripten
module.
I fixed this by allowing clients (e.g. FilamentViewer) to call
Filament.init() more than once. We now accumulate a list of "on ready"
callbacks that get triggered after the emscripten module becomes ready.
As far as I can tell, multiple canvases were actually always broken, and
the viewer test page worked in the past only because we got lucky.
The previous code would convert each element of the source data
into 8 bit-per-element, but we wnat to preserve the original format
that the user provides.
The new solution is to use `slice()` which is a robust way to clone
all the data in a typed array.
This fixes the new regression with Triangle that Ben caught.
If emscripten grows the heap inside one of our BufferDescriptor binding
functions, then the old heap becomes "detached" and an error can
occur.
This fixes the issue seen with the Parquet demo that Ben caught.
All three types of caches (descriptor sets, pipelines, and pipeline
layouts) are now managed in exactly the same way. They all use an LRU
eviction scheme that is based on a count of command buffer flush
events.
Vulkan objects can only be destroyed if there are no in-flight command
buffers that reference them, so an easy way to know when it is safe to
evict a given entry is to wait for "N" flushes after its last use, where
"N" is the number of command buffers in the command buffer ring.
Another big simplification is that there are no more dirty flags,
instead we store two sets of state vectors for each type of cache: the
"currently bound" state, and the "current requirements" state.
Fixes#5142 by replacing unsafe pointers with map keys.
One of the differences between robin_map and unordered_map is the
following:
pointers to keys or values in the map are invalidated in the same
way as iterators to these keys-values
Therefore it is unsafe to track the pointer to a value that is stored
in a robin_map.
This is mostly just code cleanup. One actual bug was the fact that the
dummy sampler was re-created every time a new pipeline layout was
created.
It also felt strange to use `auto&` to refer to a C-style array. I
changed this into a `std::array` which is more consistent with other
fixed size arrays in this class.
Support legacy morphing (morphing with targets supplied via VertexAttributes) for older clients. This gives clients more time to transition over to the new MorphTargetBuffer API.
This allows `MorphStressTest` to work on Vulkan.
However, `Horse` is still broken because it provides positions but not
tangents. Separate fix for that is coming.
Partial fix for #5109.
This fixes validation errors and makes a first pass at simplification.
VulkanTexture now tracks image layout using RangeMap, which paves the
way for further simplification.
This will allow the Vulkan backend to efficiently track the subresource
image layouts for each texture.
This is a sparse container for a series of ordered non-overlapping
integer intervals, where each interval maps to a concrete value.
This is because we're using the same program variant for skinning
and morphing, in the skinning-only case, the buffer won't be accessed
in the shader, but it must be present.
fixes#5085
A recent refactor was causing the following error when the vertex domain
was set to `device`:
```
ERROR: main.vs:23: 'material' : undeclared identifier
ERROR: main.vs:23: 'materialVertex' : no matching overloaded function found
```
Bring color grading back into the Rec.709 color space to match
previous behaviors. This change also implements an exact inverse
tone map function for the "Filmic" operator.
SamplerGroup was comparing texture handles to decide if a texture needed
to be updated, however, texture handles are (quickly) recycled and
therefore can't be used for that purpose. e.g. if a texture is destroyed,
its handle could be reused quickly by another texture, if that texture
is now set on the SamplerGroup, it will ignore it, thinking it's not
different.
We were inserting the colorgrading subpass command between the
refracted and blended objects, instead of after all of them.
Another bad side effect of this was to trigger the refraction pass for
no reason.
The operator!= in std::array compares SPLIT_COUNT elements, which
is potentially greater than cascadeCount, which was the number of
initialized elements in splitPercentages.
std::allocator::deallocate() expects the same value that was given
during allocate().
Interestingly, this bug did not manifest any issues (even with ASAN) on
some platforms.
We should take care not to call glVertexAttribPointer when there is
no bound ARRAY_BUFFER (i.e. when its binding is zero).
This fixes the black screen seen with some WebGL samples after
the recent memory leak fix related to the new BufferObject API.
This leak was introduced in the following PR on April 7.
https://github.com/google/filament/pull/3775
The guilty party has been contacted and properly admonished for his
transgression.
This was tested by adding the following code after applyAnimation in
gltf_viewer.cpp
static int nframes = 0;
if (!gpath.empty() && nframes++ > 100) {
static int count = 0;
printf("reloading %d\n", count++);
nframes = 0;
app.resourceLoader->asyncCancelLoad();
app.resourceLoader->evictResourceData();
app.viewer->removeAsset();
app.assetLoader->destroyAsset(app.asset);
loadAsset(gpath, app);
loadResources(gpath, app);
}
The hang was caused by a subtle race. When a job is completed, its
thread must signal all the threads that might be waiting on this job.
The signaling code was attempting to signal only the minimum number
of threads -- this was important especially in the case where no threads
were waiting, then the call to notify() could be avoided.
Unfortunately, for performance reasons we're not calling notify() with
the condition lock held, this meant that between the time the number of
waiting threads was latched and the time of the notify() call, more
threads could enter their condition variable wait(), and it would
then be possible for these threads to wake up, instead of the thread
we were trying to wake up (the one waiting on the job).
It would then get stuck forever.
This bug was introduced in 2df639133b
Also add some debugging code for this kind of failure (disabled)
This wasn't very useful in the first place because we're recycling
handles very quickly. Additionally there was a race condition
which cause false positives.
This reverts commit bc6acd5c5a.
This reverts commit 3a15756c78.
When running semantic analysis on a material, we were arbitrarily choosing the first code gen permutation to analyze. So, running matc with arguments --api metal versus --api all would run analysis on slightly different shader code. This causes bugs when flags passed to glslang differ during semantic analysis. This change updates all semantic analysis to always use the same shader code.
When passing only 1 fence to vkWaitForFences, the `waitAll` argument
should not have any effect, but SwiftShader seems to skip the wait
when this argument is set to VK_FALSE.
More specifically, the failure to wait in `acquireWorkCommandBuffer`
causes the subsequent destruction of an in-use fence, which causes
a TSAN failure with Google's internal tests.
I am consulting with the SwiftShader team on a real fix, meanwhile
we can commit this easy workaround.
We have 5 usages of vkWaitForFences, one of which uses multiple fences
and should have used VK_TRUE anyway.
This prevents a SwiftShader crash and/or a slew of "no texture bound"
warnings that would appear when the client provides an IBL without
providing reflections texture, which should be a valid thing to do.
Note that it is okay to declare a sampler in GLSL that never gets bound,
as long as it is never sampled from. Since we always sample from the
IBL specular texture, we should always bind something to it.
With Vulkan, this warning would sometimes be a false positive. It could
trigger for internal samplers like `ssao` and `structure`, even though
they were not declared in SPIR-V.
With OpenGL, this warning would never be a false positive because it has
the luxury of calling `glGetUniformLocation`.
This adds a private attribute to our samplers called `strict` that
indicates whether or not a sampler should always have a bound texture.
For now the only strict samplers are the custom ones declared in the
user's material.
At some point I think we should consider adding `spirv-reflect` to our
tree to help with problems like this.
This fixes a bug seen with client applications that use ClearOptions
instead of Skybox, and one or more offscreen RenderTarget objects.
These apps would see junk pixels because Filament would only clear the
first render target in the frame.
The fix is to factor some the flag-setting logic in `beginFrame()` into
a private method, and call this method from `render()` each time
the user-level RenderTarget has been changed.
I wrote a simple C++ demo to reproduce the issue and to verify that
this fix works.
@@ -39,19 +39,18 @@ Here are all the libraries available in the group `com.google.android.filament`:
| Artifact | Description |
| ------------- | ------------- |
| [](https://maven-badges.herokuapp.com/maven-central/com.google.android.filament/filament-android) | The Filament rendering engine itself. |
| [](https://maven-badges.herokuapp.com/maven-central/com.google.android.filament/filament-android-debug) | Debug version of `filament-android`. |
| [](https://maven-badges.herokuapp.com/maven-central/com.google.android.filament/gltfio-android) | A glTF 2.0 loader for Filament, depends on `filament-android`. |
| [](https://maven-badges.herokuapp.com/maven-central/com.google.android.filament/filament-utils-android) | KTX loading, Kotlin math, and camera utilities, depends on `gltfio-android`. |
| [](https://maven-badges.herokuapp.com/maven-central/com.google.android.filament/filamat-android) | A runtime material builder/compiler. This library is large but contains a full shader compiler/validator/optimizer and supports both OpenGL and Vulkan. |
| [](https://maven-badges.herokuapp.com/maven-central/com.google.android.filament/filamat-android-lite) | A much smaller alternative to `filamat-android` that can only generate OpenGL shaders. It does not provide validation or optimizations. |
| [](https://mvnrepository.com/artifact/com.google.android.filament/filament-android) | The Filament rendering engine itself. |
| [](https://mvnrepository.com/artifact/com.google.android.filament/filament-android-debug) | Debug version of `filament-android`. |
| [](https://mvnrepository.com/artifact/com.google.android.filament/gltfio-android) | A glTF 2.0 loader for Filament, depends on `filament-android`. |
| [](https://mvnrepository.com/artifact/com.google.android.filament/filament-utils-android) | KTX loading, Kotlin math, and camera utilities, depends on `gltfio-android`. |
| [](https://mvnrepository.com/artifact/com.google.android.filament/filamat-android) | A runtime material builder/compiler. This library is large but contains a full shader compiler/validator/optimizer and supports both OpenGL and Vulkan. |
### iOS
iOS projects can use CocoaPods to install the latest release:
```shell
pod 'Filament', '~> 1.67.1'
pod 'Filament', '~> 1.70.1'
```
## Documentation
@@ -89,7 +88,8 @@ pod 'Filament', '~> 1.67.1'
- OpenGL ES 3.0+ for Android and iOS
- Metal for macOS and iOS
- Vulkan 1.0 for Android, Linux, macOS, and Windows
- WebGL 2.0 for all platforms
- WebGPU for Android, Linux, macOS, and Windows
- WebGL 2.0 for all browsers supporting it
### Rendering
@@ -124,7 +124,7 @@ pod 'Filament', '~> 1.67.1'
- HDR bloom
- Depth of field bokeh
- Multiple tone mappers: generic (customizable), ACES, filmic, etc.
- Multiple tone mappers: PBR Neutral, AgX, generic (customizable), ACES, filmic, etc.
- Color and tone management: luminance scaling, gamut mapping
- Color grading: exposure, night adaptation, white balance, channel mixer,
shadows/mid-tones/highlights, ASC CDL, contrast, saturation, etc.
@@ -158,15 +158,16 @@ pod 'Filament', '~> 1.67.1'
- [x] KHR_draco_mesh_compression
- [x] KHR_lights_punctual
- [x] KHR_materials_clearcoat
- [x] KHR_materials_dispersion
- [x] KHR_materials_emissive_strength
- [x] KHR_materials_ior
- [x] KHR_materials_pbrSpecularGlossiness
- [x] KHR_materials_sheen
- [x] KHR_materials_specular
- [x] KHR_materials_transmission
- [x] KHR_materials_unlit
- [x] KHR_materials_variants
- [x] KHR_materials_volume
- [x] KHR_materials_specular
- [x] KHR_mesh_quantization
- [x] KHR_texture_basisu
- [x] KHR_texture_transform
@@ -331,7 +332,7 @@ and tools.
- `filamesh`: Mesh converter
- `glslminifier`: Minifies GLSL source code
- `matc`: Material compiler
- `filament-matp`: Material parser
- `matedit`: Material editor for compiled materials
- `matinfo` Displays information about materials compiled with `matc`
- `mipgen` Generates a series of miplevels from a source image
Some files were not shown because too many files have changed in this diff
Show More
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.