Commit Graph

438 Commits

Author SHA1 Message Date
yein
4773fc4647 Move the include resolution functionality to matp (#9414)
* Move the include resolution functionality to matp

- matp::MaterialParser now has a function resolveIncludes that returns a pair of status and resolve string.
- all the include resolution classes are moved to matp private src.
- matp::resolveIncludes is renamed to matp::resolveIncludesRecursively and only used internally.
- added insertLineDirectives and insertLineDirectiveChecks in Config; add those in the CommandlineConfig.
- moved output format to public use.

Note: MaterialParser::resolveIncludes could take a includer instead of the materialFilePath, but i decided
to go with the materialFilePath because the most common use case is resolving from the file's directory.
This allows the parser to just create the default DirIncluder internally, and we don't need to expose it publicly.

* add const to the buffer param
2025-11-07 15:23:54 -08:00
yein
2113e04aba Support returning a .mat file from matc (#9399) 2025-11-05 10:17:55 -08:00
yein
a5f949d30c Move resolving #includes from MaterialBuilder to MaterialCompiler (#9374)
* Move resolving #includes from MaterialBuilder to MaterialCompiler, before parsing the material.

- resolving #includes was happening after parsing, now moving before parsing.
this is because we could offload this resolution at build time for RuntimeMaterialCompiler
- filamat::resolveIncludes used to have an assumption where the given text was already
a shader block. this assumption is now broken so it finds the line offset internally.
thus the line offset field is removed from IncludeResult.

* Move include related classes to matc
2025-11-04 14:14:43 -08:00
haroonq
b950598d11 Various fixes to support gcc compilation. (#9323)
* Add missing includes.

* Add parenthesis around operators to suppress compiler warning.

* Remove duplicate definition of is_supported_aux_t.

* Explicitly create descriptions.

* Remove usage of anonymous struct with non-trivially constructible members.

This is an error on some compilers (e.g. gcc).

* Remove unnecessary rvalue-reference on pointer type.

* Explicitly construct SamplerParams to suppress compiler warnings.

* Place attribute specifier before declaration.

* Remove usage of anonymous struct with a non-trivially constructible member.

Replace the `array` union member with an `operator[]` to provide similar
functionality.

Some compilers (e.g. gcc) do not support this non-standard use-case.

* Use same warning settings as main filament project.
2025-10-20 09:10:08 -07: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
lyriccoder
14a460961c Signal handler calls non-async-safe function (std::cout) (#9227)
In the current implementation, the function std::cout is used inside a                                                                                                                                                                signal handler. This is problematic because std::cout is not
async-signal-safe. According to POSIX standards, only a small set of
functions are guaranteed to be safe when called from signal handlers,
and std::cout is not one of them. Using non-async-signal-safe functions
inside signal handlers leads to undefined behavior and can cause
crashes, deadlocks, or other unpredictable issues.

By making these changes, we avoid undefined behavior and ensure the
program can handle signals safely.
2025-09-30 00:23:09 -07: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
Mathias Agopian
d07c15dfc6 zbloat: modernize script
The script uses os.system to execute external commands like nm and 
objdump. Instead we use the subprocess module, which is the recommended 
approach in modern Python. 
Properly handle potential errors if nm or objdump fail.
2025-09-04 08:37:18 -07:00
Mathias Agopian
1422116242 zbloat: fix warnings 2025-09-04 08:37:18 -07:00
Mathias Agopian
28fcbe2b77 zbloat: add support for .a 2025-09-04 08:37:18 -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
Mathias Agopian
69fe317052 matc: add -O0 and -Os aliases for -g and -S 2025-08-19 22:10:46 -07:00
Mathias Agopian
9e16263876 matc: source cleanup 2025-08-19 22:10:46 -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
Ben Doherty
781083960c matp: Fix crash when reflecting parameters (#9089) 2025-08-12 13:50:17 -04:00
Sungun Park
05003ea358 mat: Add CRC32 validation for material packages (#9053)
This commit introduces a CRC32 checksum to material packages to ensure
data integrity.

When a material is loaded, this checksum is verified. If the check
fails, an error is logged, and the material fails to load. For older
material packages without a CRC32 checksum, a warning is logged and
proceed.

BUGS=[373396840]
2025-08-09 00:03:56 +00:00
Mathias Agopian
d1ca059dad resgen: add compression options
- with `-z` each resource is compressed individually
- with `-Z` the whole package is compressed
2025-08-07 14:58:18 -07:00
Mathias Agopian
c71a22914f small improvements to cmgen
- when generating the DFG LUT as a text file, make sure to faithfully
  reproduce the command used in the comments

- add a "bin" format that will output a headerless raw binary of the
  LUT data.
2025-08-07 14:58:18 -07:00
Yein Jo
d84e42861c Fix includes 2025-08-01 15:57:23 -07:00
Yein Jo
3a75dc6d2d Move some classes to private 2025-08-01 15:57:23 -07:00
Yein Jo
66b67849af Extract material parse logic to filament-matp 2025-08-01 15:57:23 -07:00
Ben Doherty
c25ac68a3a Better set default shader stages for samplers (#8992) 2025-07-29 10:01:36 -07:00
Mathias Agopian
ddca795cc9 cleanup resgen code
A test for how Gemini can clean-up code. Changes:

- Configuration Struct: Global variables have been grouped into an 
AppConfig struct. This makes the program's configuration explicit and 
avoids polluting the global namespace.

- Clearer Argument Parsing: The handleArguments function now returns an 
AppConfig object, encapsulating all parsing logic and making the main 
function cleaner.

- Helper Functions: Repetitive tasks like string replacement, file I/O, 
and writing file entries have been extracted into small, well-defined 
helper functions (replaceAll, openOutputFile, readFile, etc.).

- Simplified main Function: The main function is now a high-level 
coordinator, delegating work to helper functions. This makes the overall
 program flow much easier to follow.

- Modern C++ Idioms: The code now consistently uses C++ streams 
(std::cout, std::ofstream) and std::string objects, which is more 
idiomatic than a mix of C and C++ styles.

- added short comments
2025-07-22 16:52:11 -07:00
Powei Feng
329ca04248 Change unfilterable to filterable (#8932) 2025-07-16 23:46:20 +00:00
Mathias Agopian
34e2b81855 internal materials are now generated in different resources
instead of using a single resource binary for all materials, each
postfx set of materials (e.g. dof, bloom) gets its own resource file
based on the directory it is in.
2025-07-15 11:23:36 -07:00
Mathias Agopian
dd844b1183 resgen: output offset/size as constants instead of variables
resgen now generates the resources size/offset directly as #define
instead of as an `extern` variable. The assembly file also 
doesn't generate the corresponding global variables, saving some binary 
space.
2025-07-09 17:08:58 -07:00
Powei Feng
f096c4d8de Add unfilterable to Material sampler definition (#8873)
`unfiterable : true` indicates that the sampling of the texture
will not apply filtering.

This is mainly to satisfy the webgpu requirement for
bindGroupLayouts.

 - Documentation has been updated for both `unfilterable` and
   `multisample`.
 - Internal materials have been updated where necessary (depth
   samplers have to be marked as `unfilterable`.)
 - webgpu code has been changed appropriately.

BUGS=420745987
2025-06-18 21:14:42 +00:00
Sungun Park
09545690bf Revert "materials: introduce mutable spec constants (#8795)"
This reverts commit 8a1a0b0fd2.
2025-06-13 15:02:55 -07:00
Eliza
8a1a0b0fd2 materials: introduce mutable spec constants (#8795)
* materials: introduce mutable spec constants

Rationale & design of this feature has been discussed internally.

The current implementation uses a `FixedCapacityVector` to store the new program
handles, but I wouldn't object to replacing it with a hasmap as discussed
offline.

I have compiled but not tested this yet on Android, so I'm not certain that the
API bindings are correctly wired up.

* materials: mutable spec constant feedback

* materials: address mutable spec constant comments
2025-06-06 03:52:20 +00:00
Mathias Agopian
86a500c846 clean public header dependencies (#8725)
* remove io::ostream dependency from CString.h + clang tidy

* remove ostream.h dependency from Invocable.h

* remove Panic.h dependency from FixedCapacityVector.h

* remove ostream.h dependency from backend/ headers

* clang tidy Panic.h/Panic.cpp
2025-05-13 11:32:45 -07:00
Ben Doherty
7847220aba Materials: allow specifying the shader stages for samplers (#8720) 2025-05-12 14:20:11 -07:00
Mathias Agopian
8f58743405 support up to five custom varyings
Five custom variables (varyings) are now available on the condition that
the `color` attribute is not requested.

FIXES=[404930099]
2025-03-24 09:38:31 -07:00
Randy Reyes
5c811844ff webgpu: fix spacing 2025-03-18 10:25:10 -07:00
Randy Reyes
e6b18b4560 webgpu: enable unpacking WGSL code in filamat 2025-03-18 10:25:10 -07:00
Juan David Caldas
9c69cb8484 Enable WebGPU option for matc and add WGSL options for shader generation 2025-03-11 17:40:21 -04:00
Powei Feng
e825f43935 matdbg: indicate shader model (#8504)
Shader model (desktop or mobile) wasn't really accounted for
in the UI. This means that we will get shaders that look like
duplicates (same variant). In this work, we pass the current
shader model from engine into the frontend and filter out
variants of a different shader model.

Moreover, for matinfo, we use a specific dbg shader model (matinfo)
to indicate it is in that mode. We add UI in matinfo to show the
shadermodel.

So UI updates as well.
2025-03-07 23:54:22 +00:00
Ajmal Kunnummal
02223dcaab Add a way to specify an additional uniform name along with a sampler param for the associated transform matrix (#8490)
BUGS=[399959254]
2025-03-06 18:42:24 +00:00
Eliza Velasquez
40851f4b51 matdbg: add support for essl1 shader debugging
Fixes #8261
2025-01-31 11:44:51 -08:00
Mathias Agopian
7ea7fa18eb update beamsplitter template
the generated file was modified, which would be undo'ed next time
we run beamsplitter
2024-10-25 00:29:13 -07:00
Guilhem Saurel
38e59fbd6b add missing includes 2024-10-17 14:15:40 -07:00
Mathias Agopian
5e7106b521 custom variables can now have their precision specified
e.g.:

    variables : [
        {
            name : vertex,
            precision : medium,
         }
    ],
2024-08-22 13:08:48 -07:00
Mathias Agopian
a60fe41681 performance improvements to JobSystem
- reduce the number of calls to notify_one() and notify_all().
  notify_one() is not only called when running a new job, and
  notify_all() only when a job finishes.

- don't hold the condition lock while calling notify_*(), as it is not
  strictly needed, and because notify_*() can be very slow, there can
  be a lot of contention on this lock as a result; blocking the whole
  jobsystem thread pool.

- add a new version of run() that takes an opaque thread id that can
  be retrieved from a job's execute function; this is especially
  intended to be used by parallel_for(); it's just a more efficient
  version of run() that avoids a hashmap lookup.


Overall these change yield a significant performance boost:
- running + waiting a job: +200%
- running many jobs: +150%
- running many jobs in parallel: +50%
2024-07-22 11:12:51 -07:00
Ben Doherty
44b4de904e Add saveRawVariants flag to matc (#7949) 2024-06-27 14:36:03 -07:00
Minjae Kim
ddf1d422bc add explicit headers for supporting libstdc++ 2024-05-22 10:40:26 -07:00
Ben Doherty
b56379dc0f Add license information to matedit (#7790) 2024-04-23 14:05:53 -06:00
Ben Doherty
490e8cf0d0 Add option to preserve text shaders (#7786) 2024-04-23 10:38:23 -06:00
Benjamin Doherty
808b51c1cf matedit: fix use-after-free 2024-04-22 16:06:39 -06:00
Ben Doherty
afe292986e Introduce new matedit tool (#7759) 2024-04-18 12:18:29 -04:00
Ben Doherty
cddd22da28 Introduce a new precompiled Metal material chunk type (#7749)
This change introduces a new chunk type to material files for precompiled Metal libraries. Previously, SPIR-V was the only binary type, so there's also a couple of refactor commits present here. Nothing is changed in Filament or matc yet.

BUGS=[333547148]
2024-04-12 00:42:10 -04:00