Skip to content

Commit e6a466c

Browse files
committed
Wire legalization loop unroll requirement
1 parent 54afd2c commit e6a466c

5 files changed

Lines changed: 58652 additions & 2 deletions

File tree

tools/clang/lib/SPIRV/SpirvEmitter.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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(

tools/clang/lib/SPIRV/SpirvEmitter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1578,6 +1578,7 @@ class SpirvEmitter : public ASTConsumer {
15781578
///
15791579
/// Note: legalization specific code
15801580
bool needsLegalization;
1581+
bool needsLegalizationLoopUnroll;
15811582

15821583
/// Whether the translated SPIR-V binary passes --before-hlsl-legalization
15831584
/// option to spirv-val because of illegal function parameter scope.

tools/perf-repros/unroll/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
This directory contains the shader payload and arguments used to investigate the SPIR-V loop unroll bottleneck on large preprocessed HLSL inputs.
2+
3+
Use `godbolt_o5xf1hq36.hlsl` together with `godbolt_o5xf1hq36.args.txt`.
4+
5+
Example:
6+
7+
```text
8+
dxc @tools/perf-repros/unroll/godbolt_o5xf1hq36.args.txt -Fo out.spv tools/perf-repros/unroll/godbolt_o5xf1hq36.hlsl
9+
```
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-T lib_6_8 -spirv -Zpr -enable-16bit-types -fvk-use-scalar-layout -Wno-c++11-extensions -Wno-c++1z-extensions -Wno-c++14-extensions -Wno-gnu-static-float-init -fspv-target-env=vulkan1.3 -HV 202x -fspv-debug=source -fspv-debug=tool

0 commit comments

Comments
 (0)