Enable optimization passes on materials with external samplers (#605)

* Enable optimization passes on materials with external samplers

Because external samplers are not properly supported by SPIRV and
associated library (spirv-cross and spirv-tools) we currently disable
all optimizations when we encounter a material with external samplers.

This however causes issues on some misbehaved drivers (not running
the optimizations has a side effect which causes a crash). To enable
the optimization pass we simply rely on the Vulkan codegen target to
substitute samplerExternal with sampler2D. We then analyze the output
GLSL (post-optimization) and revert the relevants sampler2D declarations
to samplerExternal declarations.

This fixup only occurs after optimization and for mobile targets and
if external samplers were declared.

* Address review comments
This commit is contained in:
Romain Guy
2018-12-10 12:02:59 -08:00
committed by GitHub
parent 3c89f901af
commit e41dd027ab
10 changed files with 101 additions and 23 deletions
+2 -2
View File
@@ -206,7 +206,7 @@ bool GLSLPostProcessor::process(const std::string& inputShader,
}
void GLSLPostProcessor::preprocessOptimization(glslang::TShader& tShader,
const filament::driver::ShaderModel shaderModel) const {
filament::driver::ShaderModel shaderModel) const {
using TargetApi = MaterialBuilder::TargetApi;
std::string glsl;
@@ -246,7 +246,7 @@ void GLSLPostProcessor::preprocessOptimization(glslang::TShader& tShader,
}
void GLSLPostProcessor::fullOptimization(const TShader& tShader,
const filament::driver::ShaderModel shaderModel) const {
filament::driver::ShaderModel shaderModel) const {
SpirvBlob spirv;
// Compile GLSL to to SPIR-V