don't precompile variants in gltfio
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
This commit is contained in:
committed by
Mathias Agopian
parent
edbfefda0a
commit
a900bc69fb
@@ -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];
|
||||
|
||||
@@ -60,6 +60,7 @@
|
||||
#include <array>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
#include "generated/resources/gltf_demo.h"
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user