Skip to content

Commit

Permalink
don't precompile variants in gltfio
Browse files Browse the repository at this point in the history
we recently added calls to Material::compile in gltfio to precompile
materials are they are discovered. that wasn't a good call, because 
this should be the responsibility of the app, not of gltfio, at least
not without an option.

This is now done in gltf_viewer. We need something similar for 
Android.

Bugs #7318, #7336
  • Loading branch information
pixelflinger committed Nov 10, 2023
1 parent edbfefd commit a900bc6
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 15 deletions.
15 changes: 0 additions & 15 deletions libs/gltfio/src/ArchiveCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,21 +118,6 @@ Material* ArchiveCache::getMaterial(const ArchiveRequirements& reqs) {
mMaterials[i] = Material::Builder()
.package(spec.package, spec.packageByteCount)
.build(mEngine);

// Don't attempt to precompile shaders on WebGL.
// Chrome already suffers from slow shader compilation:
// https://github.com/google/filament/issues/6615
// Precompiling shaders exacerbates the problem.
#if !defined(__EMSCRIPTEN__)
// First compile high priority variants
mMaterials[i]->compile(Material::CompilerPriorityQueue::HIGH,
UserVariantFilterBit::DIRECTIONAL_LIGHTING |
UserVariantFilterBit::DYNAMIC_LIGHTING |
UserVariantFilterBit::SHADOW_RECEIVER);

// and then, everything else at low priority
mMaterials[i]->compile(Material::CompilerPriorityQueue::LOW);
#endif
}

return mMaterials[i];
Expand Down
36 changes: 36 additions & 0 deletions samples/gltf_viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
#include <array>
#include <fstream>
#include <iostream>
#include <set>
#include <string>

#include "generated/resources/gltf_demo.h"
Expand Down Expand Up @@ -597,6 +598,41 @@ int main(int argc, char** argv) {
exit(1);
}

// pre-compile all material variants
std::set<Material*> materials;
RenderableManager const& rcm = app.engine->getRenderableManager();
Slice<Entity> const renderables{
app.asset->getRenderableEntities(), app.asset->getRenderableEntityCount() };
for (Entity const e: renderables) {
auto ri = rcm.getInstance(e);
size_t const c = rcm.getPrimitiveCount(ri);
for (size_t i = 0; i < c; i++) {
MaterialInstance* const mi = rcm.getMaterialInstanceAt(ri, i);
Material* ma = const_cast<Material *>(mi->getMaterial());
materials.insert(ma);
}
}
for (Material* ma : materials) {
// Don't attempt to precompile shaders on WebGL.
// Chrome already suffers from slow shader compilation:
// https://github.com/google/filament/issues/6615
// Precompiling shaders exacerbates the problem.
#if !defined(__EMSCRIPTEN__)
// First compile high priority variants
ma->compile(Material::CompilerPriorityQueue::HIGH,
UserVariantFilterBit::DIRECTIONAL_LIGHTING |
UserVariantFilterBit::DYNAMIC_LIGHTING |
UserVariantFilterBit::SHADOW_RECEIVER);

// and then, everything else at low priority, except STE, which is very uncommon.
ma->compile(Material::CompilerPriorityQueue::LOW,
UserVariantFilterBit::FOG |
UserVariantFilterBit::SKINNING |
UserVariantFilterBit::SSR |
UserVariantFilterBit::VSM);
#endif
}

app.instance = app.asset->getInstance();
buffer.clear();
buffer.shrink_to_fit();
Expand Down

0 comments on commit a900bc6

Please sign in to comment.