@@ -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) {
@@ -16651,8 +16667,12 @@ bool SpirvEmitter::spirvToolsOptimize(std::vector<uint32_t> *mod,
1665116667 options.set_max_id_bound(spirvOptions.maxId);
1665216668
1665316669 if (spirvOptions.optConfig.empty()) {
16654- // Add performance passes.
16655- optimizer.RegisterPerformancePasses(spirvOptions.preserveInterface);
16670+ if (useSpirvFastCompileProfile()) {
16671+ optimizer.RegisterPerformancePassesFastCompile(
16672+ spirvOptions.preserveInterface);
16673+ } else {
16674+ optimizer.RegisterPerformancePasses(spirvOptions.preserveInterface);
16675+ }
1665616676
1665716677 // Add propagation of volatile semantics passes.
1665816678 optimizer.RegisterPass(spvtools::CreateSpreadVolatileSemanticsPass());
@@ -16672,6 +16692,11 @@ bool SpirvEmitter::spirvToolsOptimize(std::vector<uint32_t> *mod,
1667216692 return optimizer.Run(mod->data(), mod->size(), mod, options);
1667316693}
1667416694
16695+ bool SpirvEmitter::useSpirvFastCompileProfile() const {
16696+ return spirvOptions.o1ExperimentalFastCompile &&
16697+ spirvOptions.optConfig.empty();
16698+ }
16699+
1667516700bool SpirvEmitter::spirvToolsLegalize(std::vector<uint32_t> *mod,
1667616701 std::string *messages,
1667716702 const std::vector<DescriptorSetAndBinding>
@@ -16697,15 +16722,19 @@ bool SpirvEmitter::spirvToolsLegalize(std::vector<uint32_t> *mod,
1669716722 optimizer.RegisterPass(
1669816723 spvtools::CreateInterfaceVariableScalarReplacementPass());
1669916724 }
16700- auto legalizationSsaRewriteMode = spvtools::SSARewriteMode::None;
16701- if (needsLegalizationLoopUnroll) {
16702- legalizationSsaRewriteMode = spvtools::SSARewriteMode::All;
16703- } else if (needsLegalizationSsaRewrite) {
16704- legalizationSsaRewriteMode = spvtools::SSARewriteMode::OpaqueOnly;
16725+ if (useSpirvFastCompileProfile()) {
16726+ auto legalizationSsaRewriteMode = spvtools::SSARewriteMode::None;
16727+ if (needsLegalizationLoopUnroll) {
16728+ legalizationSsaRewriteMode = spvtools::SSARewriteMode::All;
16729+ } else if (needsLegalizationSsaRewrite) {
16730+ legalizationSsaRewriteMode = spvtools::SSARewriteMode::OpaqueOnly;
16731+ }
16732+ optimizer.RegisterLegalizationPasses(
16733+ spirvOptions.preserveInterface, needsLegalizationLoopUnroll,
16734+ legalizationSsaRewriteMode);
16735+ } else {
16736+ optimizer.RegisterLegalizationPasses(spirvOptions.preserveInterface);
1670516737 }
16706- optimizer.RegisterLegalizationPasses(
16707- spirvOptions.preserveInterface, needsLegalizationLoopUnroll,
16708- legalizationSsaRewriteMode);
1670916738 // Add flattening of resources if needed.
1671016739 if (spirvOptions.flattenResourceArrays) {
1671116740 optimizer.RegisterPass(
0 commit comments