summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to 'source')
-rw-r--r--source/slang-glslang/slang-glslang.cpp66
-rw-r--r--source/slang/slang-compiler.cpp9
2 files changed, 59 insertions, 16 deletions
diff --git a/source/slang-glslang/slang-glslang.cpp b/source/slang-glslang/slang-glslang.cpp
index 7976ffac2..b82b21f20 100644
--- a/source/slang-glslang/slang-glslang.cpp
+++ b/source/slang-glslang/slang-glslang.cpp
@@ -161,6 +161,17 @@ static void glslang_optimizeSPIRV(std::vector<unsigned int>& spirv, spv_target_e
spvtools::OptimizerOptions spvOptOptions;
+ // To compile some large shaders the default is not enough.
+ // That although this limit is exceeded, the final optimized output is typically well
+ // within the range.
+ //
+ // See kDefaultMaxIdBound for description of this limit.
+ //
+ // If a compilation produces a warning like
+ // `0:0: ID overflow. Try running compact-ids.`
+ // it might be fixable by raising the multiplier to a larger value.
+ spvOptOptions.set_max_id_bound(kDefaultMaxIdBound * 4);
+
// TODO confirm which passes we want to invoke for each level
switch (optimizationLevel)
{
@@ -182,7 +193,47 @@ static void glslang_optimizeSPIRV(std::vector<unsigned int>& spirv, spv_target_e
optimizer.RegisterPass(spvtools::CreateLocalAccessChainConvertPass());
optimizer.RegisterPass(spvtools::CreateAggressiveDCEPass());
}
-#endif
+#elif 1
+ // 6Mb 27 secs (all passes up to 9)
+ // 9Mb 25 secs (all passes up to 7)
+ // 8Mb 15 secs (all passes) -(5,6,7)
+ // 6Mb 15 secs (all passes) -(6,7)
+
+ // This list of passes takes the previous 'default optimization'
+ // passes (as listed above) and tries to combine them in order with the 'new' passes below.
+ // The issue with the passes below is that although it produces smaller SPIR-V fairly quickly
+ // it can cause serious problem on some drivers.
+ //
+ // Across a wide range of compilations this produced SPIR-V that is less than half size of the
+ // previous -O1 passes above.
+ {
+ optimizer.RegisterPass(spvtools::CreateWrapOpKillPass()); // 1
+ optimizer.RegisterPass(spvtools::CreateDeadBranchElimPass()); // 2
+
+ optimizer.RegisterPass(spvtools::CreateMergeReturnPass());
+ optimizer.RegisterPass(spvtools::CreateInlineExhaustivePass());
+
+ optimizer.RegisterPass(spvtools::CreateEliminateDeadFunctionsPass()); // 3
+
+ optimizer.RegisterPass(spvtools::CreateAggressiveDCEPass());
+ optimizer.RegisterPass(spvtools::CreatePrivateToLocalPass());
+
+ optimizer.RegisterPass(spvtools::CreateScalarReplacementPass(100));
+
+ optimizer.RegisterPass(spvtools::CreateCCPPass()); // 4 *
+ optimizer.RegisterPass(spvtools::CreateSimplificationPass()); // 5
+ //optimizer.RegisterPass(spvtools::CreateIfConversionPass()); // 6
+ //optimizer.RegisterPass(spvtools::CreateBlockMergePass()); // 7 *
+
+ optimizer.RegisterPass(spvtools::CreateLocalAccessChainConvertPass());
+
+ optimizer.RegisterPass(spvtools::CreateLocalSingleBlockLoadStoreElimPass()); // 8
+
+ optimizer.RegisterPass(spvtools::CreateAggressiveDCEPass());
+
+ optimizer.RegisterPass(spvtools::CreateVectorDCEPass()); // 9
+ }
+#else
// The following selection of passes was created by
// 1) Taking the list of passes from optimizer.RegisterSizePasses
// 2) Disable/enable passes to try to produce some reasonable combination of low SPIR-V output size and compilation speed
@@ -242,6 +293,7 @@ static void glslang_optimizeSPIRV(std::vector<unsigned int>& spirv, spv_target_e
optimizer.RegisterPass(spvtools::CreateAggressiveDCEPass());
optimizer.RegisterPass(spvtools::CreateCFGCleanupPass());
}
+#endif
break;
case SLANG_OPTIMIZATION_LEVEL_HIGH:
@@ -256,17 +308,7 @@ static void glslang_optimizeSPIRV(std::vector<unsigned int>& spirv, spv_target_e
// Use the same passes when specifying the "-O" flag in spirv-opt
// Roughly equivalent to `RegisterPerformancePasses`
- // To compile some large shaders the default is not enough.
- // That although this limit is exceeded, the final optimized output is typically well
- // within the range.
- //
- // See kDefaultMaxIdBound for description of this limit.
- //
- // If a compilation produces a warning like
- // `0:0: ID overflow. Try running compact-ids.`
- // it might be fixable by raising the multiplier to a larger value.
- spvOptOptions.set_max_id_bound(kDefaultMaxIdBound * 4);
-
+
optimizer.RegisterPass(spvtools::CreateWrapOpKillPass());
optimizer.RegisterPass(spvtools::CreateDeadBranchElimPass());
optimizer.RegisterPass(spvtools::CreateMergeReturnPass());
diff --git a/source/slang/slang-compiler.cpp b/source/slang/slang-compiler.cpp
index 5d0ae2f8d..0a9180b30 100644
--- a/source/slang/slang-compiler.cpp
+++ b/source/slang/slang-compiler.cpp
@@ -2094,10 +2094,6 @@ namespace Slang
SerialContainerUtil::WriteOptions options;
options.compressionType = linkage->serialCompressionType;
- if (linkage->debugInfoLevel != DebugInfoLevel::None)
- {
- options.optionFlags |= SerialOptionFlag::SourceLocation;
- }
if (linkage->m_obfuscateCode)
{
// If code is obfuscated, we *disable* AST output as it is not obfuscated and will reveal
@@ -2105,6 +2101,11 @@ namespace Slang
// Also currently only IR is needed.
options.optionFlags &= ~SerialOptionFlag::ASTModule;
}
+ else if (linkage->debugInfoLevel != DebugInfoLevel::None && linkage->getSourceManager())
+ {
+ options.optionFlags |= SerialOptionFlag::SourceLocation;
+ options.sourceManager = linkage->getSourceManager();
+ }
{
RiffContainer container;