Skip to content

Commit 350379d

Browse files
authored
[spirv] separate triggering legalization and passing before-legalize-hlsl (#3816)
`--before-legalize-hlsl` option for spirv-val must be used when the SPIR-V code has to be legalized by spirv-opt but it is not legalized i.e., "SPIR-V generated from HLSL before legalize". Therefore, we have to run the legalization or pass the `--before-legalize-hlsl` option to spirv-val but we do not need to do both. This CL lets DXC does not pass `--before-legalize-hlsl` option when it legalizes the SPIR-V code.
1 parent 77f146e commit 350379d

1 file changed

Lines changed: 13 additions & 15 deletions

File tree

tools/clang/lib/SPIRV/SpirvEmitter.cpp

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -664,14 +664,16 @@ void SpirvEmitter::HandleTranslationUnit(ASTContext &context) {
664664
// Output the constructed module.
665665
std::vector<uint32_t> m = spvBuilder.takeModule();
666666

667-
if (!spirvOptions.codeGenHighLevel) {
668-
// In order to flatten composite resources, we must also unroll loops.
669-
// Therefore we should run legalization before optimization.
670-
needsLegalization = needsLegalization ||
671-
declIdMapper.requiresLegalization() ||
672-
spirvOptions.flattenResourceArrays ||
673-
declIdMapper.requiresFlatteningCompositeResources();
674-
667+
// In order to flatten composite resources, we must also unroll loops.
668+
// Therefore we should run legalization before optimization.
669+
needsLegalization = needsLegalization ||
670+
declIdMapper.requiresLegalization() ||
671+
spirvOptions.flattenResourceArrays ||
672+
declIdMapper.requiresFlatteningCompositeResources();
673+
674+
if (spirvOptions.codeGenHighLevel) {
675+
beforeHlslLegalization = needsLegalization;
676+
} else {
675677
// Run legalization passes
676678
if (needsLegalization) {
677679
std::string messages;
@@ -2320,7 +2322,7 @@ SpirvInstruction *SpirvEmitter::processCall(const CallExpr *callExpr) {
23202322
// the legalization.
23212323
if (objInstr->getStorageClass() != spv::StorageClass::Function ||
23222324
!isMemoryObjectDeclaration(objInstr))
2323-
beforeHlslLegalization = true;
2325+
needsLegalization = true;
23242326

23252327
args.push_back(objInstr);
23262328
}
@@ -2372,7 +2374,7 @@ SpirvInstruction *SpirvEmitter::processCall(const CallExpr *callExpr) {
23722374
// to function. If we pass an argument that is not function scope
23732375
// or not memory object declaration, we need the legalization.
23742376
if (!argInfo || argInfo->getStorageClass() != spv::StorageClass::Function)
2375-
beforeHlslLegalization = true;
2377+
needsLegalization = true;
23762378

23772379
isTempVar.push_back(false);
23782380
args.push_back(argInst);
@@ -2423,9 +2425,6 @@ SpirvInstruction *SpirvEmitter::processCall(const CallExpr *callExpr) {
24232425
}
24242426
}
24252427

2426-
if (beforeHlslLegalization)
2427-
needsLegalization = true;
2428-
24292428
assert(vars.size() == isTempVar.size());
24302429
assert(vars.size() == args.size());
24312430

@@ -12305,8 +12304,7 @@ bool SpirvEmitter::spirvToolsValidate(std::vector<uint32_t> *mod,
1230512304
const char *message) { *messages += message; });
1230612305

1230712306
spvtools::ValidatorOptions options;
12308-
options.SetBeforeHlslLegalization(needsLegalization ||
12309-
declIdMapper.requiresLegalization());
12307+
options.SetBeforeHlslLegalization(beforeHlslLegalization);
1231012308
// GL: strict block layout rules
1231112309
// VK: relaxed block layout rules
1231212310
// DX: Skip block layout rules

0 commit comments

Comments
 (0)