Enable preprocessor optimization of ESSL 1.0
Since #7358 is blocked by an upstream spirv-cross issue, we can at least do a bit of preprocessor optimization for ESSL 1.0 code in the meantime and introduce the FILAMENT_EFFECTIVE_VERSION preprocessor definitions.
This commit is contained in:
@@ -35,7 +35,7 @@ vertex {
|
||||
|
||||
fragment {
|
||||
void postProcess(inout PostProcessInputs postProcess) {
|
||||
#if __VERSION__ == 100
|
||||
#if FILAMENT_EFFECTIVE_VERSION == 100
|
||||
postProcess.color = texture2D(materialParams_color, variable_vertex.xy);
|
||||
#else
|
||||
postProcess.color = textureLod(materialParams_color, variable_vertex.xy, 0.0);
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include <spirv_glsl.hpp>
|
||||
#include <spirv_msl.hpp>
|
||||
|
||||
#include "backend/DriverEnums.h"
|
||||
#include "sca/builtinResource.h"
|
||||
#include "sca/GLSLTools.h"
|
||||
|
||||
@@ -395,7 +396,11 @@ bool GLSLPostProcessor::process(const std::string& inputShader, Config const& co
|
||||
break;
|
||||
case MaterialBuilder::Optimization::SIZE:
|
||||
case MaterialBuilder::Optimization::PERFORMANCE:
|
||||
fullOptimization(tShader, config, internalConfig);
|
||||
if (config.featureLevel == filament::backend::FeatureLevel::FEATURE_LEVEL_0) {
|
||||
preprocessOptimization(tShader, config, internalConfig);
|
||||
} else {
|
||||
fullOptimization(tShader, config, internalConfig);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -151,6 +151,36 @@ utils::io::sstream& CodeGenerator::generateProlog(utils::io::sstream& out, Shade
|
||||
out << "#define FILAMENT_HAS_FEATURE_INSTANCING\n";
|
||||
}
|
||||
|
||||
// During compilation and optimization, __VERSION__ reflects the shader language version of the
|
||||
// intermediate code, not the version of the final code. spirv-cross automatically adapts
|
||||
// certain language features (e.g. fragment output) but leaves others untouched (e.g. sampler
|
||||
// functions, bit shift operations). Client code may have to make decisions based on this
|
||||
// information, so define a FILAMENT_EFFECTIVE_VERSION constant.
|
||||
const char *effective_version;
|
||||
if (mTargetLanguage == TargetLanguage::GLSL) {
|
||||
effective_version = "__VERSION__";
|
||||
} else {
|
||||
switch (mShaderModel) {
|
||||
case ShaderModel::MOBILE:
|
||||
if (mFeatureLevel >= FeatureLevel::FEATURE_LEVEL_1) {
|
||||
effective_version = "300";
|
||||
} else {
|
||||
effective_version = "100";
|
||||
}
|
||||
break;
|
||||
case ShaderModel::DESKTOP:
|
||||
if (mFeatureLevel >= FeatureLevel::FEATURE_LEVEL_2) {
|
||||
effective_version = "450";
|
||||
} else {
|
||||
effective_version = "410";
|
||||
}
|
||||
break;
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
generateDefine(out, "FILAMENT_EFFECTIVE_VERSION", effective_version);
|
||||
|
||||
if (stage == ShaderStage::VERTEX) {
|
||||
CodeGenerator::generateDefine(out, "FLIP_UV_ATTRIBUTE", material.flipUV);
|
||||
CodeGenerator::generateDefine(out, "LEGACY_MORPHING", material.useLegacyMorphing);
|
||||
|
||||
@@ -57,7 +57,7 @@ void main() {
|
||||
fragColor.xy = computeDepthMomentsVSM(depth);
|
||||
fragColor.zw = computeDepthMomentsVSM(-1.0 / depth); // requires at least RGBA16F
|
||||
#elif defined(VARIANT_HAS_PICKING)
|
||||
#if MATERIAL_FEATURE_LEVEL == 0
|
||||
#if FILAMENT_EFFECTIVE_VERSION == 0
|
||||
outPicking.a = mod(float(object_uniforms_objectId / 65536), 256.0) / 255.0;
|
||||
outPicking.b = mod(float(object_uniforms_objectId / 256), 256.0) / 255.0;
|
||||
outPicking.g = mod(float(object_uniforms_objectId) , 256.0) / 255.0;
|
||||
|
||||
Reference in New Issue
Block a user