Commit Graph

28 Commits

Author SHA1 Message Date
Powei Feng
5c371089f2 Add GEN_MIPMAPPABLE TextureUsage (#9042)
This will allow for more backend-specific usage mapping then before - where BLIT_SRC and BLIT_DST are assumed for textures whose mipmaps will be generated.

These mappings have been introduced in metal, vulkan, webgpu.
2025-08-07 18:14:49 +00:00
Doris Wu
433fded025 Workaround the skybox issue on webgl build (#8974) (BUGS=419664914)
* duplicate the material instance in webgl

* Use default instance

* Update comments

* Update

* Address the comments

* Update the naming
2025-07-31 01:56:07 +00:00
Mathias Agopian
a1e0cfa33c fix a few noexcept through out the code base 2025-05-27 10:18:12 -07:00
Mathias Agopian
5286dec70b Make sure that all descriptors are always initialized (#8739)
* Make sure that all descriptors are always initialized

* improvements to committing material instances

- from now on, only MaterialDomain::SURFACE material instances are
  automatically committed by FEngine at the beginning of a frame.
  COMPUTE and POST_PROCESS domains must be committed manually via
  a new API on MaterialInstance. Both domains are not public APIs so
  this shouldn't have an impact anywhere.


- DescriptorSet now validates that all descriptors are set and emits
  an error in the log if not.

- these changes prevent PostProcess material instances to be committed
  before all descriptors are set.

* Update filament/src/details/Engine.cpp

Co-authored-by: Powei Feng <powei@google.com>

---------

Co-authored-by: Powei Feng <powei@google.com>
2025-05-15 15:38:16 -07:00
Mathias Agopian
bbabf3480b re-do "Use the Perfetto SDK instead of ATRACE" (#8701) (#8728)
* re-do "Use the Perfetto SDK instead of ATRACE" (#8701)

This time we create an entirely new private header: Tracing.h which
uses the perfetto SDK instead of ATRACE. The old Systrace.h is
unchanged to presever backward compatibility but is essentially
deprecated and no longer used within the filament repo.

The new TRACING_ macros use an explicit CATEGORY parameter, which is
declared in Tracing.h.

Moreover, tracing can be compiled out by defining
FILAMENT_TRACING_ENABLED to false before including Tracing.h

iOS tracing is still supported and still controlled via
FILAMENT_APPLE_SYSTRACE.

There are three perfetto categories defined:

- "filament/filament"
- "filament/jobsystem"
- "filament/gltfio"

The "filament/jobsystem" category is compiled out by default.

And they can be enabled in AGI / perfetto by adding:

```
data_sources {
  config {
    name: "track_event"
    track_event_config {
      disabled_categories: "*"
      enabled_categories: "filament/filament"
      enabled_categories: "filament/jobsystem"
      enabled_categories: "filament/gltfio"
    }
  }
}
```

* Update libs/utils/include/private/utils/Tracing.h

Co-authored-by: Powei Feng <powei@google.com>

* Update libs/utils/src/android/Tracing.cpp

Co-authored-by: Powei Feng <powei@google.com>

* remove all references to SYSTRACE_TAG

---------

Co-authored-by: Powei Feng <powei@google.com>
2025-05-14 20:51:57 -07:00
Mathias Agopian
1747ae8f5a validate MaterialInstance references when destroyed (#8366)
* validate MaterialInstance references when destroyed

With this change we now enforce two things:
- All MaterialInstance of a Material must be destroyed when
  destroying said Material. This has always been a documented 
  requirement of the public API, but wasn't enforced (only
  a warning was printed).
  This new assertion is unconditional.

- A MaterialInstance, when destroyed is no longer in use by any
  Renderable.

So before destroying a MaterialInstance, the user of API needs to 
ensure that either all Renderable using that MaterialInstance in one
of their Render Primitives are  destroyed, or, that these Renderable
using that MaterialInstance are reset to another one or to null.

There is a new RenderableManager::clearMaterialInstanceAt() that can
be used to clear a MaterialInstance on a Render Primitive.
  
Additionally, a Render Primitive with a null MaterialInstance is now
silently skipped during rendering, instead of a null-dereference.

Finally, that second assert is protected by a new feature flag: 
"features.engine.debug.assert_material_instance_in_use". This flag is
enabled on DEBUG builds and disabled on RELEASE builds by default.
The flag can be changed at any time using `Engine::setFeatureFlag()`.

BUGS=[333907416]

* Update filament/src/components/RenderableManager.cpp

Co-authored-by: Powei Feng <powei@google.com>

---------

Co-authored-by: Powei Feng <powei@google.com>
2025-01-17 14:15:15 -08:00
Powei Feng
2cade209b5 Add Descriptor Sets to Filament (#8165)
We add the concept of the descriptor set as a way to describe
shader resources into Filament. This is a comprehensive change
across Filament.

Info on descriptor sets is available here:
https://docs.vulkan.org/spec/latest/chapters/descriptorsets.html

Co-authored-by: Benjamin Doherty <bendoherty@google.com>
Co-authored-by: Mathias Agopian <mathias@google.com>
Co-authored-by: Sungun Park <sungunpark@google.com>
2024-09-27 23:20:20 -07:00
Ben Doherty
cf91e42847 Switch ASSERT macros to new stream API (#7881) 2024-05-24 20:46:34 +00:00
Mathias Agopian
075f3d0869 fix another ibl-prefilter bug introduced recently
The top and bottom faces were swapped in the reflection map.

FIXES=[333421281]
2024-04-15 10:25:52 -07:00
Mathias Agopian
3644e7f808 Fixes IBL prefilter has floor and ceiling flipped
FIXES=[330603077]
2024-03-21 13:28:24 -07:00
Mathias Agopian
434c226e8a IBLs were mirrored when using IBLPrefilter
cmgen mirrors environment maps by default so that the reflection map
appears un-mirrored. IBLPrefilter didn't do that. 

EquirectangularToCubemap now takes a Config parameter that allows to
specify the mirroring, which is enabled by default.


FIXES=[320856413]
2024-03-06 15:04:30 -08:00
Mathias Agopian
368fa2bf39 fix IBLPrefilterContext::EquirectangularToCubemap
it was incorrectly mapping the equirect image to a cubemap due to a
typo in our overload of atan2 which was swapping its parameters.

atan2 is now removed, and we use atan(y,x) instead. Also modified the
code slightly so it matches almost exactly cmgen's.

FIXES=[320856413]
2024-01-18 21:10:21 -08:00
Mathias Agopian
b1f7731dbe fix max lod level computation in IBLPrefilter
FIXES=[308012116]
2023-10-27 15:28:24 -07:00
Mathias Agopian
a9763376b7 IBLPrefilter can now generate the irradiance texture 2023-05-23 15:52:22 -07:00
Mathias Agopian
2709533fb1 Fix texture coordinate calculations in post-process materials
The most important change here is that we no longer apply the
backend (e.g. Metal/Vulkan) UV transformation before calling the
user's vertex shader. This is an API change for post-process materials
(but they're not public).
Now the user is responsible for using uvToRenderTargetUV() in their
shaders (either in the fragment or vertex as appropriate).

This makes it easier to handle offsets/transforms with all APIs.

Conceptually, the only thing that is needed is to call 
uvToRenderTargetUV() just before making a texture call.


This fixes a couple of issues:
- some image shifting in metal/vk
- flare in metal/vk was upside down

We also simplify the DoF code quite a bit now that we can rely on the
rendertargets begin multiple of 16.

We also "fix" SSAO that was working by accident on  metal/vk. The UV
correction was applied 3 times 2 of which were canceling each other.
2022-05-12 13:42:13 -07:00
Mathias Agopian
85617c96a2 shrink post-process materials a bit
post-process materials don't need common_shadowing nor common_shading.

also don't rely on MIN_ROUGHNESS in .mat files, because it's not public.
2022-04-28 10:13:20 -07:00
Mathias Agopian
b73caceb1f fix libibl on mobile
- the hammersley sequence was completely wrong because of a missing
  highp precision qualifier

- roughness 0 was also wrong because of divide-by-0

Fixes #4668
2021-12-08 00:17:29 -06:00
Mathias Agopian
82623c8fd4 IBLPrefilter relied on finalizer which could cause crashes
The finalizer can't be used to dispose of filament resource, because
it runs on its own thread.

Added a destroy() method to all IBLPrefilter related classes that must
be called once the object is no longer needed.

note: Resources will be freed eventually anyways when the Engine itself is
destroyed.


fixes #4633
2021-09-17 14:34:31 -07:00
Mathias Agopian
1e1542fe16 ipbprefilter: simplify cpu side
- move kernel weight computation to the gpu side as a small cost, in
order to simplify the CPU side and reduce the binary size.

- skip samples with a weight of 0, which is a completely coherent 
check.

- fix a typo in move ctor
2021-05-04 13:12:39 -07:00
Mathias Agopian
02c1e1dc60 Improve libiblprefilter
- move public headers from filament/foo to filament-foo/
  to avoid confusion with libfilament's headers
- add support for equirectangular to cubemap conversion
- add support for using an .hdr file directly in all our samples
2021-04-26 12:17:42 -07:00
Mathias Agopian
9575a7453e add an option to control the strength of the importance sampling
This is very useful either with a low sample count, or with a very
HDR image.
2021-04-21 15:41:43 -07:00
Mathias Agopian
cfd9689444 fix several bugs in the gpu prefilter code
- the miplevel wasn't computed correctly
- the random rotation was incorrect
- the default HDR compression was too aggressive
- better validation of the input cubemap
2021-04-21 15:41:43 -07:00
Mathias Agopian
0427787cb7 Generate the kernel texture on the GPU
This avoids having to upload data from the cpu.
2021-04-21 15:41:43 -07:00
Mathias Agopian
e372cc25f2 more fixes from review comments
- get rid of createREflectionsTextures public api
- use default material instance
2021-04-21 15:41:43 -07:00
Mathias Agopian
91b08705da rename library to filament-iblprefilter 2021-04-21 15:41:43 -07:00
Mathias Agopian
503abb3c94 rename a few things 2021-04-21 15:41:43 -07:00
Mathias Agopian
4b8d98af8c compute all lod kernel at once
we now store the kernel for each lod in a texture, this has several
advantages:
- the texture can be reused, so we can amortize that cost a bit
- we could generate the texture with a shader, so that we don't
  have to do any texture uplaod (TBD).
2021-04-21 15:41:43 -07:00
Mathias Agopian
ced6c3de1f GPU based IBL prefiltering library 2021-04-21 15:41:43 -07:00