Skip to content

Commit c41af93

Browse files
s-perronKeenuts
authored andcommitted
[HLSL][Driver] Make vk1.3 the default. (llvm#143384)
The HLSL driver currently defaults the triple to an unversioned os and subarch when targeting SPIR-V. This means the SPIR-V backend decides the default value. That is not a great option because a change the backend could cause a change in Clang. Now that we want to choose the default we need to consider the best option. DXC currently defaults to Vulkan1.0. We are planning on not supporting Vulkan1.0 in the Clang HLSL compiler because it is newer versions of Vulkan are commonly supported on nearly all hardware, so users do not use it. Since we have to change from DXC anyway, we are using VK1.3. It has been out long enough to be commonly available, and the initial implementation of SPIR-V features for HLSL are assuming Vulkan 1.3. --------- Co-authored-by: Nathan Gauër <[email protected]>
1 parent c42e957 commit c41af93

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1596,28 +1596,27 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
15961596
A->claim();
15971597

15981598
if (Args.hasArg(options::OPT_spirv)) {
1599+
const llvm::StringMap<llvm::Triple::SubArchType> ValidTargets = {
1600+
{"vulkan1.2", llvm::Triple::SPIRVSubArch_v15},
1601+
{"vulkan1.3", llvm::Triple::SPIRVSubArch_v16}};
15991602
llvm::Triple T(TargetTriple);
1600-
T.setArch(llvm::Triple::spirv);
1601-
T.setOS(llvm::Triple::Vulkan);
16021603

1603-
// Set specific Vulkan version if applicable.
1604+
// Set specific Vulkan version. Default to vulkan1.3.
1605+
auto TargetInfo = ValidTargets.find("vulkan1.3");
1606+
assert(TargetInfo != ValidTargets.end());
16041607
if (const Arg *A = Args.getLastArg(options::OPT_fspv_target_env_EQ)) {
1605-
const llvm::StringMap<llvm::Triple::SubArchType> ValidTargets = {
1606-
{"vulkan1.2", llvm::Triple::SPIRVSubArch_v15},
1607-
{"vulkan1.3", llvm::Triple::SPIRVSubArch_v16}};
1608-
1609-
auto TargetInfo = ValidTargets.find(A->getValue());
1610-
if (TargetInfo != ValidTargets.end()) {
1611-
T.setOSName(TargetInfo->getKey());
1612-
T.setArch(llvm::Triple::spirv, TargetInfo->getValue());
1613-
} else {
1608+
TargetInfo = ValidTargets.find(A->getValue());
1609+
if (TargetInfo == ValidTargets.end()) {
16141610
Diag(diag::err_drv_invalid_value)
16151611
<< A->getAsString(Args) << A->getValue();
16161612
}
16171613
A->claim();
16181614
}
1619-
1620-
TargetTriple = T.str();
1615+
if (TargetInfo != ValidTargets.end()) {
1616+
T.setOSName(TargetInfo->getKey());
1617+
T.setArch(llvm::Triple::spirv, TargetInfo->getValue());
1618+
TargetTriple = T.str();
1619+
}
16211620
}
16221621
} else {
16231622
Diag(diag::err_drv_dxc_missing_target_profile);

clang/test/Driver/dxc_spirv.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// RUN: %clang_dxc -T cs_6_0 -spirv -fspv-target-env=vulkan1.3 -### %s 2>&1 | FileCheck %s --check-prefix=CHECK-VULKAN13
44
// RUN: not %clang_dxc -T cs_6_0 -spirv -fspv-target-env=vulkan1.0 -### %s 2>&1 | FileCheck %s --check-prefix=CHECK-ERROR
55

6-
// CHECK: "-triple" "spirv-unknown-vulkan-compute"
6+
// CHECK: "-triple" "spirv1.6-unknown-vulkan1.3-compute"
77
// CHECK-SAME: "-x" "hlsl"
88

99
// CHECK-VULKAN12: "-triple" "spirv1.5-unknown-vulkan1.2-compute"

0 commit comments

Comments
 (0)