Describe the bug
Sorry to bother again. I continue to play with macOS (Catalina) and noticed that if I try to create a material with a simple backedColor like below:
// matc -o bakedColor.inc -f header bakedColor.mat
static constexpr uint8_t BAKED_COLOR_PACKAGE[] = {
#include "bakedColor.inc"
};
...
filament::Material* pMaterial = filament::Material::Builder()
.package((void*) BAKED_COLOR_PACKAGE, sizeof(BAKED_COLOR_PACKAGE))
.build(*pEngine);
filament::MaterialInstance* pMaterialInstance = pMaterial->createInstance();
then in Metal mode the following error happens:
% ./demo
Filament library loaded.
FEngine (64 bits) created at 0x10ee10000 (threading is enabled)
FEngine resolved backend: Metal
N5utils18PostconditionPanicE
in static filament::MaterialParser *filament::details::FMaterial::createParser(backend::Backend, const void *, size_t):493
reason: could not parse the material package
libc++abi.dylib: terminating with uncaught exception of type utils::PostconditionPanic
zsh: abort ./demo
Note if I switch to OpenGL mode then the crash is gone.
To Reproduce
Steps to reproduce the behavior:
demo.cc
Makefile
filament/
bin/
include/
lib/
% make
libc++abi.dylib: terminating with uncaught exception of type utils::PostconditionPanic
zsh: abort ./demo
```
Expected behavior
The program is expected to run in both Metal and OpenGL mode.
Screenshots
n/a
Desktop (please complete the following information):
All of our Metal samples work (and they all load unlit materials). Did you build matc yourself or is it a prebuilt? We made recent changes to materials which breaks compatibility with older matc versions.
Although I think we stopped using the header file forma for materials, maybe there's something broken there? We now use resgen instead.
@romainguy I download the matc from the same artifact in #2173 and the program I build is linked to the same library in the artifact. The bakedColor.mat file is from the sample directory in filament (https://github.com/google/filament/blob/master/samples/materials/bakedColor.mat)
material {
name : bakedColor,
requires : [
color
],
shadingModel : unlit,
culling : none
}
fragment {
void material(inout MaterialInputs material) {
prepareMaterial(material);
material.baseColor = getColor();
}
}
Although I think we stopped using the header file forma for materials, maybe there's something broken there? We now use resgen instead.
@romainguy wondering if there is some "getting started" documentation about C++? I saw documentations in other languages but couldn't find a C++ documentation to get started. (The filament/samples directory has quite some library dependencies like SDL, not very easy to follow without prior background).
Unfortunately the best "getting started" is in our README and not terribly useful. Check out the README of resgen, it might explain how to use it (resgen generates a .S file and a header file from a binary — it can be a material or anything else — and thus offers a much more efficient way to embed binaries compared to the #include solution you're using).
By default, matc only compiles materials for the OpenGL backend. To compile for Metal as well, update the arguments to:
filament/bin/matc -a opengl -a metal -o bakedColor.inc -f header bakedColor.mat
That fixes the crash.
@bejado The updated command fixed the issue, thanks for the help!
@romainguy Thanks for the pointers. I will take a look at resgen.
@bejado We should probably improve the error message to indicate the material doesn't contain shaders for the selected backend (which I believe we used to have?)
Most helpful comment
By default,
matconly compiles materials for the OpenGL backend. To compile for Metal as well, update the arguments to:That fixes the crash.