@@ -595,6 +595,7 @@ SpirvEmitter::SpirvEmitter(CompilerInstance &ci)
595595 isSpecConstantMode(false), needsLegalization(false),
596596 needsLegalizationLoopUnroll(false),
597597 needsLegalizationSsaRewrite(false),
598+ sawExplicitUnrollHint(false),
598599 beforeHlslLegalization(false), mainSourceFile(nullptr) {
599600
600601 // Get ShaderModel from command line hlsl profile option.
@@ -920,6 +921,20 @@ void SpirvEmitter::HandleTranslationUnit(ASTContext &context) {
920921 }
921922 }
922923
924+ if (useSpirvFastCompileProfile() &&
925+ (needsLegalizationLoopUnroll || sawExplicitUnrollHint)) {
926+ if (featureManager.isTargetEnvVulkan() &&
927+ !featureManager.isTargetEnvVulkan1p1OrAbove()) {
928+ emitFatalError(
929+ "-O1experimental requires -fspv-target-env=vulkan1.1 or above "
930+ "when the generated module needs VariablePointers",
931+ {});
932+ return;
933+ }
934+
935+ spvBuilder.requireCapability(spv::Capability::VariablePointers);
936+ }
937+
923938 // Output the constructed module.
924939 std::vector<uint32_t> m = spvBuilder.takeModule();
925940 if (context.getDiagnostics().hasErrorOccurred())
@@ -2289,6 +2304,7 @@ spv::LoopControlMask SpirvEmitter::translateLoopAttribute(const Stmt *stmt,
22892304 case attr::HLSLFastOpt:
22902305 return spv::LoopControlMask::DontUnroll;
22912306 case attr::HLSLUnroll:
2307+ sawExplicitUnrollHint = true;
22922308 return spv::LoopControlMask::Unroll;
22932309 case attr::HLSLAllowUAVCondition:
22942310 if (!spirvOptions.noWarnIgnoredFeatures) {
@@ -16627,8 +16643,12 @@ bool SpirvEmitter::spirvToolsOptimize(std::vector<uint32_t> *mod,
1662716643 options.set_max_id_bound(spirvOptions.maxId);
1662816644
1662916645 if (spirvOptions.optConfig.empty()) {
16630- // Add performance passes.
16631- optimizer.RegisterPerformancePasses(spirvOptions.preserveInterface);
16646+ if (useSpirvFastCompileProfile()) {
16647+ optimizer.RegisterPerformancePassesFastCompile(
16648+ spirvOptions.preserveInterface);
16649+ } else {
16650+ optimizer.RegisterPerformancePasses(spirvOptions.preserveInterface);
16651+ }
1663216652
1663316653 // Add propagation of volatile semantics passes.
1663416654 optimizer.RegisterPass(spvtools::CreateSpreadVolatileSemanticsPass());
@@ -16648,6 +16668,11 @@ bool SpirvEmitter::spirvToolsOptimize(std::vector<uint32_t> *mod,
1664816668 return optimizer.Run(mod->data(), mod->size(), mod, options);
1664916669}
1665016670
16671+ bool SpirvEmitter::useSpirvFastCompileProfile() const {
16672+ return spirvOptions.o1ExperimentalFastCompile &&
16673+ spirvOptions.optConfig.empty();
16674+ }
16675+
1665116676bool SpirvEmitter::spirvToolsLegalize(std::vector<uint32_t> *mod,
1665216677 std::string *messages,
1665316678 const std::vector<DescriptorSetAndBinding>
@@ -16673,15 +16698,19 @@ bool SpirvEmitter::spirvToolsLegalize(std::vector<uint32_t> *mod,
1667316698 optimizer.RegisterPass(
1667416699 spvtools::CreateInterfaceVariableScalarReplacementPass());
1667516700 }
16676- auto legalizationSsaRewriteMode = spvtools::SSARewriteMode::None;
16677- if (needsLegalizationLoopUnroll) {
16678- legalizationSsaRewriteMode = spvtools::SSARewriteMode::All;
16679- } else if (needsLegalizationSsaRewrite) {
16680- legalizationSsaRewriteMode = spvtools::SSARewriteMode::OpaqueOnly;
16701+ if (useSpirvFastCompileProfile()) {
16702+ auto legalizationSsaRewriteMode = spvtools::SSARewriteMode::None;
16703+ if (needsLegalizationLoopUnroll) {
16704+ legalizationSsaRewriteMode = spvtools::SSARewriteMode::All;
16705+ } else if (needsLegalizationSsaRewrite) {
16706+ legalizationSsaRewriteMode = spvtools::SSARewriteMode::OpaqueOnly;
16707+ }
16708+ optimizer.RegisterLegalizationPasses(
16709+ spirvOptions.preserveInterface, needsLegalizationLoopUnroll,
16710+ legalizationSsaRewriteMode);
16711+ } else {
16712+ optimizer.RegisterLegalizationPasses(spirvOptions.preserveInterface);
1668116713 }
16682- optimizer.RegisterLegalizationPasses(
16683- spirvOptions.preserveInterface, needsLegalizationLoopUnroll,
16684- legalizationSsaRewriteMode);
1668516714 // Add flattening of resources if needed.
1668616715 if (spirvOptions.flattenResourceArrays) {
1668716716 optimizer.RegisterPass(
0 commit comments