Commit Graph

2187 Commits

Author SHA1 Message Date
Powei Feng
3294bb64a5 Revert "Make matc workarounds default to NONE again" (#9295)
This reverts commit d11a6b4467.

Breakage detailed in following bug

BUGS=449740720
2025-10-07 18:50:34 +00:00
yein
f52476a323 Use utils::Status in MaterialParser (#9285)
* Use utils::Status in MaterialParser

* Use utils::sstream instead of std::stringstream

* Remove remaining std::cerr and dep; update MaterialParser::reflectParameters

* make error message in utils::Status more generic

---------

Co-authored-by: Powei Feng <powei@google.com>
2025-10-07 11:27:11 -07:00
Mathias Agopian
2deafc6b81 fix matc -E (preprocessor) option (#9292)
this option was ignored and treated as -O0.
2025-10-03 20:15:05 -07:00
Mathias Agopian
31d66002a9 optional per-channel depth clear (#9287)
- increase the number of channels from 4 to 8
- new api on View to enable per-channel depth clear
FIXES=[447648764]
2025-10-03 14:25:02 -07:00
Mathias Agopian
f2ed382cf1 New ImmutableCString string class (#9291)
ImmutableCString is a string class similar to CString except it's
immutable. ImmutableCString occupies 16 bytes instead of 8 for CString.

However, ImmutableCString is able to avoid memory allocation when
constructed from a string literal, and in that way it us similar
to StaticString.

ImmutableCString can be auto converted from StaticString.

The backend tag tracking is updated to use ImmutableCString and
the FrameGraph resource manager us updated to use StaticString.

Together these changes significantly cut down heap allocations due to
internal tagging.


We also add optional tracking to {Immutable}CString.
2025-10-03 14:23:36 -07:00
yein
a4746eab0c Minor changes in utils::Status (#9288)
* Minor changes in utils::Status

- << operator doesn't have to be friend
- simplify getErrorMessage to not use strlen internally

* Replace std::ostream to utils::io::ostream
2025-10-03 12:53:46 -07:00
Eliza
7fe1ee3fd5 utils: RefCountedInternPool/RefCountedMap (#9284)
* utils: RefCountedInternPool/RefCountedMap

First, introduce RefCountedInternPool, a reference counted intern pool of
Slice<const T>. Just acquire() a slice that you want and you're guaranteed to
get exactly one canonical value-equal Slice<const T> back.

Additionally, introduce the concept of NullValue to RefCountedMap. A NullValue
defines what should be considered an uninitialized value; by default, it's the
default value of that type (0 for ints, nullptr for pointers, etc). This allows
us to lazily-initialize values in the map. A client can acquire() a bunch of
different resources which will be initialized only when get(factory) is called.
If a client attempts to get() a value without specifying a factory, and the
value is not initialized (i.e. equal to NullValue{}()), RefCountedMap will
panic.

* utils: add unit tests for ref-counted collections

* utils: remove C++20 features, fix memory issue

* utils: remove RefCounted from InternPool
2025-10-03 11:21:02 -07:00
Eliza
075726db8b engine: change spec constants to simple list (#9283)
* engine: change spec constants to simple list

For a shader program cache to be keyed on the set of spec constants that a
program has set, we need to know full exact list of constants, including their
default values. If we're going to always hold a list of all constants all the
time, then we may as well store them as a simple list where each index is the ID
number of the spec constant.

As part of this change, we now write the default values of spec constants into
the material file metadata.

* fix indent

* engine: fix sRGB swapchain emulation
2025-10-02 23:48:11 +00:00
Sungun Park
bc794bbf7b Fix public headers check on github (#9286) 2025-10-01 23:36:26 -07:00
Eliza
8e5dabfa8e utils: split Slice into mutable and constant types (#9276)
* slice: fix memory semantics

* slice: prefer passing slice by value

This lets us do nice things like coercing Slice<T> to Slice<const T>, etc.

* slice: fix unit tests

* slice: fix copy/assignment, hash function

Don't attempt to define a copy constructor/assignment operator which would
convert a constant type to a mutable type.

Additionally, fix the hash function such that we're hashing U instead of const
U.
2025-10-01 22:40:50 +00:00
Mathias Agopian
e974989a95 new utility AsyncJobQueue (#9278)
* new utility AsyncJobQueue

this is a very simple job queue, it spawns a thread and runs the jobs
pushed to the queue in sequence.

* use AsyncJobQueue in OpenGLTimerQuery
2025-10-01 14:54:34 -07:00
yein
057ce2ea4b Introduce utils::Status (#9279)
* Introduce utils::Status

* Replace std::string with utils::CString in utils::Status

* Update unit tests
2025-10-01 14:53:51 -07:00
Sungun Park
3dc3c78901 Support C++17 for RefCountedMap (#9274)
Some of our users are sticking to C++17 for a while.
2025-09-30 11:45:51 -07:00
Mathias Agopian
98f8c93950 in-place CString replace when possible 2025-09-26 08:07:55 -07:00
Mathias Agopian
d11a6b4467 Make matc workarounds default to NONE again 2025-09-25 16:37:50 -07:00
Mathias Agopian
8af1cb3489 fix build warning (#9263) 2025-09-25 16:37:24 -07:00
Mathias Agopian
a1b825b5b4 performance improvements to CString (#9259)
- make sure CString("foo") calls the literal constructor
- avoid memory allocations when comparing to a literal
2025-09-25 13:57:53 -07:00
Mathias Agopian
db96b262a2 fix another matdbg build breakage (#9255) 2025-09-24 23:13:10 -07:00
Eliza
5516cd92e7 materials: introduce MaterialCache (#9205)
* materials: introduce MaterialCache

Presently, Filament Materials are instantiated by first parsing a bunch of
read-only data from a material file, then applying a bunch of options from its
Builder before settling on a final, immutable Material object. If two different
Material instances need to be parameterized differently, e.g. setting their spec
constants independently, each has to do all of these steps independently for
each variation.

This change introduces two new concepts: MaterialDefinition, representing the
deserialized, read-only state of a material file, and MaterialCache, a
reference-counted system responsible for managing the lifetimes of
MaterialDefinitions. Now, each Material asks the cache if a MaterialDefinition
exists for the particular UUID of the data it's trying to read; if not,
MaterialCache creates a new entry transparently. If a hundred different
Materials all try to load the same material data, only one
MaterialDefinition (and its associated GPU resources) will be created.

This first PR is the least possible invasive implementation of this feature.
There are a lot of room for improvements (and more planned). For example, each
Material still manages its own compiled shader program cache, but we can easily
move this to the MaterialCache in future PRs, further enabling the planned
mutable spec constants feature.

Additionally, there's room here to add a Material::toBuilder() method, which
could take an extant material and create a Builder object from it already
parameterized with all of the same options, a la the prototype design pattern.

* material cache: key on crc32

* material cache: make materialParser private

* move RefCountedMap to utils and add unit tests

* material cache: make create functions private

* material cache: fix broken tests on iOS/web

* material cache: address more comments
2025-09-24 00:35:59 +00:00
Sungun Park
fdc0bc472d Revert workaround default to ALL (#9233)
This makes artifacts on certain mobile devices. Revert them back to ALL.

BUGS=[445721121]
2025-09-18 23:45:08 -07:00
Mathias Agopian
a791665a2c remove the limit to 48 material parameters
FIXES=[445698638]
2025-09-18 17:28:20 -07:00
Mathias Agopian
10f4632c88 small math::mat3f to GL mat3 optimizations 2025-09-18 12:15:56 -07:00
Sungun Park
06c8fc39c2 Update MATERIAL_VERSION to 64 2025-09-16 10:08:23 -07:00
Ivan Mikhalchuk
6ac5f26bb5 fix UB in AtomicFreeList::push and FreeList::push: access to non-static data member without proper lifetime management 2025-09-15 08:50:02 -07:00
Powei Feng
480b0878d7 vk: fix validation warnings (#9207)
- Remove extensions that have been promoted to 1.1
- Use vkCreateMetalSurfaceEXT instead of the deprecated
   vkCreateMacOSSurfaceMVK
2025-09-11 23:59:25 +00:00
Yein Jo
ff4be0be48 Lift the logic to resolve inclues in shader to MaterialCompiler
- Move the file check & dir resolution to MaterialCompiler
- Move DirIncluder back to matc
FIXES=440579712
2025-09-08 10:37:16 -07:00
Mathias Agopian
c4f083cfba matc and MaterialBuilder workaround options NONE by default
The workaround option is now set to none by default. Use

```
matc -Wall
```

if you want to restore the previous behavior.

Current material workarounds:
- remove MergeReturnPass (except on Metal)
- remove SimplificationPass (except on Metal)

There are reason to believe these workarounds are no longer needed,
due to changes in spirv-opt.

It's possible that older devices might still need them.

These workaround affect *all* devices, this is why it is important
to disable them if not needed.
2025-09-07 23:52:14 -07:00
Sungun Park
b31a42a1d0 Improve getEyeFromViewMatrix() (#9184)
Make the size of PerViewUib 2KiB again.

Add overloading functions for getEyeFromViewMatrix() and
getClipFromWorldMatrix().

BUGS=[441127971]
2025-09-04 18:58:14 +00:00
Mathias Agopian
4c91d48ed3 Revert "use fmin/fmax for floating-point"
This reverts commit a032190b24.
2025-09-04 00:08:30 -07:00
Mathias Agopian
a032190b24 use fmin/fmax for floating-point
On ARM this generates the fmin/fmax instruction, which avoids
branches.
2025-09-03 22:30:09 -07:00
Mathias Agopian
639cdc3e5c add option to disable perfetto on android
The new cmake FILAMENT_ENABLE_PERFETTO must be set to enable 
perfetto traces on Android. It is disabled by default on release
builds, enabled otherwise.

The reason for this is that the perfetto SDK adds about 800K of code
to the library. The text section goes from 2.2 to 1.4 MB
2025-09-03 16:16:46 -07:00
Sungun Park
b0f8e1be7a Add getEyeFromViewMatrix() for vertex shader (#9175)
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]
2025-09-03 18:05:34 +00:00
Ben Doherty
3bd6412780 Remove the setDebugTag API in favor of tagged create API (#9011) 2025-09-03 11:14:33 -04:00
Mathias Agopian
d3ff60af21 remove all uses of std::string in filament
- libbackend (except webgpu)
- libfilament
- libutils

std::string generates a lot of code bloat, we use CString instead.

We also update CString to be more compatible with std::string's api.
2025-09-02 11:47:58 -07:00
Powei Feng
19e1287392 Fix minor typo and styling issues (#9172) 2025-09-02 18:11:09 +00:00
Mathias Agopian
05a6198443 froxelization optimizations
- by limiting the maximum number of point light to 255 instead of 256,
  we can simplify some loops.

- hint the compiler that certain loop counters are multiple of 16 and 
non 0, which helps vectorizing.
2025-08-29 14:46:14 -07:00
Mathias Agopian
88fa99d782 The Record buffer is now dynamically sized.
The record buffer is were we store the light indices, its maximum
size is 65536 entries, but is often limited to 16384 on about 30%
of Android devices because of the 16KB UBO limit.

This PR makes the record buffer use up to 64K entries when allowed
but the h/w.

The record buffer can be a limiting factor when many lights are used
with many froxels. With the minimum of 4096 froxels and a 16KB record 
buffer we get an average of 4 lights per froxel. With our maximum of
8192 froxels and a 64KB record buffer we get 8 lights in average per
froxel.
2025-08-29 14:46:14 -07:00
Juan Caldas
74ba3eb00c webgpu: Support skinning on WebGPU (#9137)
BUGS = [436886048]
2025-08-29 00:24:14 +00:00
Powei Feng
088900e6e0 Fix bones indices and weights sampler + descriptor set (#9154)
In some places, this sampler was incorrectly assumed to be
sampler2darray, but it should be just a sampler2d.  Additionally,
sampling from it should produce unfiltered values - this has been
changed accordingly.
2025-08-28 14:05:16 -07:00
Doris Wu
ff394f7c1b feat: Add Visibility Bitmask method for GTAO (#9101)
* Quick test

* Fix incorrect logic and add some comments

* Set thickness parameter

* refactoring

* Update

* Generated files

* Some comments

* Update

* Update generated files

* Update

* Update

* Add comments
2025-08-26 23:27:02 +00:00
Mathias Agopian
15bb295ec6 A new froxel grid vizualization for FilamentApp
FilamentApp now has debugging options to enable or disable the
camera and directional shadow frustums, as well as the new
"froxel grid" visualization.

"froxel grid" is automatically enabled when "froxel debugging" is
enabled in the debug gui in gltf_viewer.


New corresponding debugging APIs were added to View.
2025-08-22 15:55:46 -07:00
Mathias Agopian
cea178a40c froxel vizualization can now be turned on/off per view
Before this change once the froxel vizualizaition was enabled via
the Engine debug framework, it applied to all views. This adds a
debug API on View to control whether the view will display this
vizualization.
2025-08-22 15:55:46 -07:00
Mathias Agopian
f34bb3d775 ViewerGui: hide stereo options when stereo is not enabled 2025-08-22 15:37:06 -07:00
Mathias Agopian
9aaa1bf413 FilamentApp: fix projection matrix
For some reason we were not setting the aspect-ratio to 1 and scaling 
the clip-space instead. This could lead to lighting and clipping
issues.
2025-08-22 15:37:06 -07:00
Doris Wu
e3384feee0 Clamp before assign to uint (#9132) (b/440220363) 2025-08-22 03:51:11 +00:00
Powei Feng
60bdbb3d1f matdbg: fix matinfo no variants bug (#9127)
matinfo -w doesn't show the variants for any backend other than
metal.  The reason is that the code for updating the variant
list wasn't being triggered on currentBackend changes.
2025-08-21 11:04:59 -07:00
Mathias Agopian
96b26b85cc add a --workarounds option to matc
Currently the only values possible are 'none' and 'all'. 'all' is the
default. This option will be used to control code generation
workarounds individually. Currently 'all' disable the
MergeReturn and Simplification passes, which have causes issues in
the past on some older Android devices.
2025-08-19 22:10:46 -07:00
Powei Feng
45fcea101f webgpu: enable choosing vulkan backend on MacOS (#9106)
- Add a Configuration struct to the WebGPUPlatform class.  This
   allows for client-side setting of WebGPU backend configurations.
 - Add a configuration for forcing the wgpu backend to pick a
   certain backend.
 - Add Vulkan as a potential backend for WebGPU + MacOS.
 - Locally modify Dawn so that it does not assume only switfshader
   is available for Vulkan on MacOS.
 - Enable vulkan support for Dawn (third_party/dawn/tnt/CMakeLists.txt)
 - Plumb option to pick different WebGPU backend through
   FilamentApp and gltf_viewer.
2025-08-20 04:50:17 +00:00
Sungun Park
bcea4ef75d Update MATERIAL_VERSION to 64 2025-08-18 09:45:08 -07:00
Sungun Park
0ef7507464 mat: Store matc parameters in material packages (#9070)
This commit enhances the material compilation process by embedding the
`matc` command-line parameters directly into the compiled material file.
This feature is valuable for debugging, as it allows developers to
inspect the exact compilation settings used for a given material.

A key consideration is the potential for personally identifiable
information (PII) in the command-line arguments (e.g., file paths). To
address this, a `toPIISafeString` method has been implemented to filter
out PII-sensitive options before they are stored in the material.

With this change, the matc command below
    /path/to/matc -a opengl --api vulkan -p desktop -g -o /path/to/my.filamat /path/to/my.mat

is stored to the package as below. (veryfied by running `matinfo my.filamat`)
    Compilation Parameters:         -a opengl --api vulkan -p desktop -g
2025-08-17 19:25:37 +00:00