Skip to content

Commit b02b772

Browse files
committed
Signal legalization SSA rewrite needs
1 parent bd9a8b1 commit b02b772

File tree

5 files changed

+24
-21
lines changed

5 files changed

+24
-21
lines changed

tools/clang/lib/SPIRV/SpirvEmitter.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,7 @@ SpirvEmitter::SpirvEmitter(CompilerInstance &ci)
594594
curFunction(nullptr), curThis(nullptr), seenPushConstantAt(),
595595
isSpecConstantMode(false), needsLegalization(false),
596596
needsLegalizationLoopUnroll(false),
597+
needsLegalizationSsaRewrite(false),
597598
beforeHlslLegalization(false), mainSourceFile(nullptr) {
598599

599600
// Get ShaderModel from command line hlsl profile option.
@@ -955,6 +956,9 @@ void SpirvEmitter::HandleTranslationUnit(ASTContext &context) {
955956
declIdMapper.requiresFlatteningCompositeResources() ||
956957
!dsetbindingsToCombineImageSampler.empty() ||
957958
spirvOptions.signaturePacking;
959+
needsLegalizationSsaRewrite =
960+
needsLegalizationSsaRewrite ||
961+
!dsetbindingsToCombineImageSampler.empty();
958962

959963
// Run legalization passes
960964
if (spirvOptions.codeGenHighLevel) {
@@ -5827,6 +5831,7 @@ SpirvInstruction *SpirvEmitter::createImageSample(
58275831
if (varOffset) {
58285832
needsLegalization = true;
58295833
needsLegalizationLoopUnroll = true;
5834+
needsLegalizationSsaRewrite = true;
58305835
}
58315836

58325837
// SampleDref* instructions in SPIR-V always return a scalar.
@@ -16669,7 +16674,8 @@ bool SpirvEmitter::spirvToolsLegalize(std::vector<uint32_t> *mod,
1666916674
spvtools::CreateInterfaceVariableScalarReplacementPass());
1667016675
}
1667116676
optimizer.RegisterLegalizationPasses(spirvOptions.preserveInterface,
16672-
needsLegalizationLoopUnroll);
16677+
needsLegalizationLoopUnroll,
16678+
needsLegalizationSsaRewrite);
1667316679
// Add flattening of resources if needed.
1667416680
if (spirvOptions.flattenResourceArrays) {
1667516681
optimizer.RegisterPass(

tools/clang/lib/SPIRV/SpirvEmitter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1579,6 +1579,7 @@ class SpirvEmitter : public ASTConsumer {
15791579
/// Note: legalization specific code
15801580
bool needsLegalization;
15811581
bool needsLegalizationLoopUnroll;
1582+
bool needsLegalizationSsaRewrite;
15821583

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

tools/clang/test/CodeGenSPIRV/cast.flat-conversion.matrix.hlsl

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@ RWStructuredBuffer<T> t_output;
1616
// COL: OpMemberDecorate %S 0 RowMajor
1717
// ROW: OpMemberDecorate %S 0 ColMajor
1818

19-
// The DXIL generated for the two cases seem to produce the same results,
20-
// and this matches that behaviour.
21-
// CHECK: [[array_const:%[0-9]+]] = OpConstantComposite %_arr_float_uint_6 %float_0 %float_1 %float_2 %float_3 %float_4 %float_5
22-
// CHECK: [[t:%[0-9]+]] = OpConstantComposite %T [[array_const]]
23-
2419
// The DXIL that is generates different order for the values depending on
2520
// whether the matrix is column or row major. However, for SPIR-V, the value
2621
// stored in both cases is the same because the decoration, which is checked
@@ -40,13 +35,16 @@ void main() {
4035
s.a[i][j] = i*3+j;
4136
}
4237
}
43-
// CHECK: [[ac:%[0-9]+]] = OpAccessChain %_ptr_Uniform_T %t_output %int_0 %uint_0
44-
// CHECK: OpStore [[ac]] [[t]]
38+
// CHECK: [[tptr:%[0-9]+]] = OpAccessChain %_ptr_Uniform_T %t_output %int_0 %uint_0
39+
// CHECK: [[tarr:%[0-9]+]] = OpCompositeConstruct %_arr_float_uint_6
40+
// CHECK: [[tval:%[0-9]+]] = OpCompositeConstruct %T [[tarr]]
41+
// CHECK: OpStore [[tptr]] [[tval]]
4542
T t = (T)(s);
4643
t_output[0] = t;
4744

48-
// CHECK: [[ac:%[0-9]+]] = OpAccessChain %_ptr_Uniform_S %s_output %int_0 %uint_0
49-
// CHECK: OpStore [[ac]] [[s]]
45+
// CHECK: [[sptr:%[0-9]+]] = OpAccessChain %_ptr_Uniform_S %s_output %int_0 %uint_0
46+
// CHECK: [[sval:%[0-9]+]] = OpCompositeConstruct %S
47+
// CHECK: OpStore [[sptr]] [[sval]]
5048
s = (S)t;
5149
s_output[0] = s;
5250
}

tools/clang/test/CodeGenSPIRV/legal-examples/15-loop-var-unroll-ok.hlsl

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
// RUN: %dxc -T cs_6_0 -E main -O3 -Vd %s -spirv | FileCheck %s
22

3-
// CHECK: [[ptr:%[0-9]+]] = OpAccessChain %_ptr_Uniform_S %gSBuffer2
4-
// CHECK-NEXT: [[val:%[0-9]+]] = OpLoad %S [[ptr]]
5-
// CHECK-NEXT: [[ptr:%[0-9]+]] = OpAccessChain %_ptr_Uniform_S %gRWSBuffer
6-
// CHECK-NEXT: OpStore [[ptr]] [[val]]
7-
8-
// CHECK: [[ptr:%[0-9]+]] = OpAccessChain %_ptr_Uniform_S %gSBuffer2
9-
// CHECK-NEXT: [[val:%[0-9]+]] = OpLoad %S [[ptr]]
10-
// CHECK-NEXT: [[ptr:%[0-9]+]] = OpAccessChain %_ptr_Uniform_S %gRWSBuffer
11-
// CHECK-NEXT: OpStore [[ptr]] [[val]]
3+
// CHECK: OpLoopMerge {{%[0-9]+}} {{%[0-9]+}} Unroll
4+
// CHECK: [[which:%[0-9]+]] = OpSelect %_ptr_Uniform_type_StructuredBuffer_S {{%[0-9]+}} %gSBuffer1 %gSBuffer2
5+
// CHECK: [[idx:%[0-9]+]] = OpBitcast %uint {{%[0-9]+}}
6+
// CHECK: [[src:%[0-9]+]] = OpAccessChain %_ptr_Uniform_S [[which]] %int_0 [[idx]]
7+
// CHECK: [[val:%[0-9]+]] = OpLoad %S [[src]]
8+
// CHECK: [[dst:%[0-9]+]] = OpAccessChain %_ptr_Uniform_S %gRWSBuffer %int_0 [[idx]]
9+
// CHECK: OpStore [[dst]] [[val]]
1210

1311
struct S {
1412
float4 f;

tools/clang/test/CodeGenSPIRV/max_id.hlsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// CHECK-30: fatal error: failed to optimize SPIR-V: ID overflow. Try running compact-ids.
99

1010
// With a larger limit, the test case can compile successfully.
11-
// CHECK-400: Bound: 204
11+
// CHECK-400: Bound:
1212

1313

1414
RWStructuredBuffer<int> data;
@@ -20,4 +20,4 @@ void main(uint3 id : SV_DispatchThreadID)
2020
for( int i = 0; i < 64; i++ ) {
2121
data[i] = i;
2222
}
23-
}
23+
}

0 commit comments

Comments
 (0)