@@ -593,6 +593,7 @@ SpirvEmitter::SpirvEmitter(CompilerInstance &ci)
593593 constEvaluator(astContext, spvBuilder), entryFunction(nullptr),
594594 curFunction(nullptr), curThis(nullptr), seenPushConstantAt(),
595595 isSpecConstantMode(false), needsLegalization(false),
596+ needsLegalizationLoopUnroll(false),
596597 beforeHlslLegalization(false), mainSourceFile(nullptr) {
597598
598599 // Get ShaderModel from command line hlsl profile option.
@@ -5823,8 +5824,10 @@ SpirvInstruction *SpirvEmitter::createImageSample(
58235824 SpirvInstruction *minLod, SpirvInstruction *residencyCodeId,
58245825 SourceLocation loc, SourceRange range) {
58255826
5826- if (varOffset)
5827+ if (varOffset) {
58275828 needsLegalization = true;
5829+ needsLegalizationLoopUnroll = true;
5830+ }
58285831
58295832 // SampleDref* instructions in SPIR-V always return a scalar.
58305833 // They also have the correct type in HLSL.
@@ -16665,7 +16668,8 @@ bool SpirvEmitter::spirvToolsLegalize(std::vector<uint32_t> *mod,
1666516668 optimizer.RegisterPass(
1666616669 spvtools::CreateInterfaceVariableScalarReplacementPass());
1666716670 }
16668- optimizer.RegisterLegalizationPasses(spirvOptions.preserveInterface);
16671+ optimizer.RegisterLegalizationPasses(spirvOptions.preserveInterface,
16672+ needsLegalizationLoopUnroll);
1666916673 // Add flattening of resources if needed.
1667016674 if (spirvOptions.flattenResourceArrays) {
1667116675 optimizer.RegisterPass(
0 commit comments