[clang] [llvm] [HLSL][SPIR-V] Add Vulkan to target triple (PR #76749)
https://github.com/sudonatalie closed https://github.com/llvm/llvm-project/pull/76749 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL][SPIR-V] Add Vulkan to target triple (PR #76749)
sudonatalie wrote: Rebased again and local `check-all` succeeds. https://github.com/llvm/llvm-project/pull/76749 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL][SPIR-V] Add Vulkan to target triple (PR #76749)
https://github.com/llvm-beanz approved this pull request. Sorry for my delayed review. LGTM. https://github.com/llvm/llvm-project/pull/76749 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL][SPIR-V] Add Vulkan to target triple (PR #76749)
https://github.com/sudonatalie edited https://github.com/llvm/llvm-project/pull/76749 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL][SPIR-V] Add Vulkan to target triple (PR #76749)
@@ -1,4 +1,4 @@ -// REQUIRES: dxil-registered-target sudonatalie wrote: This test wasn't being run for me before. I think this change is correct? https://github.com/llvm/llvm-project/pull/76749 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL][SPIR-V] Add Vulkan to target triple (PR #76749)
https://github.com/sudonatalie commented: Will wait for a +1 from @llvm-beanz or @bogner since I modified the error messages slightly for DXIL too https://github.com/llvm/llvm-project/pull/76749 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL][SPIR-V] Add Vulkan to target triple (PR #76749)
https://github.com/sudonatalie updated https://github.com/llvm/llvm-project/pull/76749 >From 6141382cebfe0a40c054b2ce7539ec6ff85f3c14 Mon Sep 17 00:00:00 2001 From: Natalie Chouinard Date: Fri, 15 Dec 2023 20:50:43 + Subject: [PATCH 1/4] [HLSL][SPIR-V] Add Vulkan to target triple Add support for specifying the logical SPIR-V target environment in the triple as Vulkan. When compiling HLSL, this replaces the DirectX Shader Model with a Vulkan environment instead. Currently, the only supported combinations of SPIR-V version and Vulkan environment are: - Vulkan 1.2 and SPIR-V 1.5 - Vulkan 1.3 and SPIR-V 1.6 Fixes #70051 --- .../clang/Basic/DiagnosticDriverKinds.td | 4 +- clang/lib/Basic/Targets/SPIR.h| 6 +- clang/lib/Frontend/CompilerInvocation.cpp | 27 +++-- .../test/Driver/hlsl-lang-targets-spirv.hlsl | 28 +++-- llvm/include/llvm/TargetParser/Triple.h | 10 +- llvm/lib/TargetParser/Triple.cpp | 32 +- llvm/unittests/TargetParser/TripleTest.cpp| 102 -- 7 files changed, 129 insertions(+), 80 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td index 676f1a62b49dd0..2e5ac4f349c0fd 100644 --- a/clang/include/clang/Basic/DiagnosticDriverKinds.td +++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td @@ -735,10 +735,10 @@ def err_drv_dxc_missing_target_profile : Error< def err_drv_hlsl_unsupported_target : Error< "HLSL code generation is unsupported for target '%0'">; def err_drv_hlsl_bad_shader_required_in_target : Error< - "shader %select{model|stage}0 is required in target '%1' for HLSL code generation">; + "%select{shader model|Vulkan environment|shader stage}0 is required as %select{OS|environment}1 in target '%2' for HLSL code generation">; def err_drv_hlsl_bad_shader_unsupported : Error< - "shader %select{model|stage}0 '%1' in target '%2' is invalid for HLSL code generation">; + "%select{shader model|Vulkan environment|shader stage}0 '%1' in target '%2' is invalid for HLSL code generation">; def warn_drv_dxc_missing_dxv : Warning<"dxv not found. " "Resulting DXIL will not be validated or signed for use in release environments.">, InGroup; diff --git a/clang/lib/Basic/Targets/SPIR.h b/clang/lib/Basic/Targets/SPIR.h index 9ab2b7c6093639..fa4a3bb1c82eed 100644 --- a/clang/lib/Basic/Targets/SPIR.h +++ b/clang/lib/Basic/Targets/SPIR.h @@ -17,6 +17,7 @@ #include "clang/Basic/TargetInfo.h" #include "clang/Basic/TargetOptions.h" #include "llvm/Support/Compiler.h" +#include "llvm/Support/VersionTuple.h" #include "llvm/TargetParser/Triple.h" #include @@ -301,8 +302,9 @@ class LLVM_LIBRARY_VISIBILITY SPIRVTargetInfo : public BaseSPIRVTargetInfo { : BaseSPIRVTargetInfo(Triple, Opts) { assert(Triple.getArch() == llvm::Triple::spirv && "Invalid architecture for Logical SPIR-V."); -assert(Triple.getOS() == llvm::Triple::ShaderModel && - "Logical SPIR-V requires a valid ShaderModel."); +assert(Triple.getOS() == llvm::Triple::Vulkan && + Triple.getVulkanVersion() != llvm::VersionTuple(0) && + "Logical SPIR-V requires a valid Vulkan environment."); assert(Triple.getEnvironment() >= llvm::Triple::Pixel && Triple.getEnvironment() <= llvm::Triple::Amplification && "Logical SPIR-V environment must be a valid shader stage."); diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 11f3f2c2d6425c..7e211ea24df2ae 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -4236,20 +4236,35 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args, // TODO: Revisit restricting SPIR-V to logical once we've figured out how to // handle PhysicalStorageBuffer64 memory model if (T.isDXIL() || T.isSPIRVLogical()) { - enum { ShaderModel, ShaderStage }; + enum { ShaderModel, VulkanEnv, ShaderStage }; + enum { OS, Environment }; + + int ExpectedOS = T.isSPIRVLogical() ? VulkanEnv : ShaderModel; + if (T.getOSName().empty()) { Diags.Report(diag::err_drv_hlsl_bad_shader_required_in_target) -<< ShaderModel << T.str(); - } else if (!T.isShaderModelOS() || T.getOSVersion() == VersionTuple(0)) { -Diags.Report(diag::err_drv_hlsl_bad_shader_unsupported) -<< ShaderModel << T.getOSName() << T.str(); +<< ExpectedOS << OS << T.str(); } else if (T.getEnvironmentName().empty()) { Diags.Report(diag::err_drv_hlsl_bad_shader_required_in_target) -<< ShaderStage << T.str(); +<< ShaderStage << Environment << T.str(); } else if (!T.isShaderStageEnvironment()) { Diags.Report(diag::err_drv_hlsl_bad_shader_unsupported) << ShaderStage << T.getEnvironmentName() << T.str(); } + + i
[clang] [llvm] [HLSL][SPIR-V] Add Vulkan to target triple (PR #76749)
https://github.com/michalpaszkowski approved this pull request. https://github.com/llvm/llvm-project/pull/76749 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL][SPIR-V] Add Vulkan to target triple (PR #76749)
https://github.com/Keenuts approved this pull request. https://github.com/llvm/llvm-project/pull/76749 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL][SPIR-V] Add Vulkan to target triple (PR #76749)
@@ -3,29 +3,39 @@ // Supported targets // // RUN: %clang -target dxil-unknown-shadermodel6.2-compute %s -S -o /dev/null 2>&1 | FileCheck --allow-empty --check-prefix=CHECK-VALID %s -// RUN: %clang -target spirv-unknown-shadermodel6.2-compute %s -S -o /dev/null 2>&1 | FileCheck --allow-empty --check-prefix=CHECK-VALID %s +// RUN: %clang -target spirv-unknown-vulkan-compute %s -S -o /dev/null 2>&1 | FileCheck --allow-empty --check-prefix=CHECK-VALID %s +// RUN: %clang -target spirv-unknown-vulkan1.2-compute %s -S -o /dev/null 2>&1 | FileCheck --allow-empty --check-prefix=CHECK-VALID %s +// RUN: %clang -target spirv-unknown-vulkan1.3-compute %s -S -o /dev/null 2>&1 | FileCheck --allow-empty --check-prefix=CHECK-VALID %s +// RUN: %clang -target spirv1.5-unknown-vulkan1.2-compute %s -S -o /dev/null 2>&1 | FileCheck --allow-empty --check-prefix=CHECK-VALID %s +// RUN: %clang -target spirv1.6-unknown-vulkan1.3-compute %s -S -o /dev/null 2>&1 | FileCheck --allow-empty --check-prefix=CHECK-VALID %s -// Empty shader model +// Empty Vulkan environment // // RUN: not %clang -target spirv %s -S -o /dev/null 2>&1 | FileCheck --check-prefix=CHECK-NO-OS %s -// Invalid shader models +// Invalid Vulkan environment // -// RUN: not %clang -target spirv--unknown %s -S -o /dev/null 2>&1 | FileCheck --check-prefix=CHECK-BAD-OS %s +// RUN: not %clang -target spirv--shadermodel %s -S -o /dev/null 2>&1 | FileCheck --check-prefix=CHECK-BAD-OS %s +// RUN: not %clang -target spirv-unknown-vulkan1.0-compute %s -S -o /dev/null 2>&1 | FileCheck --check-prefix=CHECK-BAD-OS %s Keenuts wrote: I wonder where we should document that we explicitly don't want to support vulkan < 1.2 for now, hence this limit. Maybe here a comment to say "vulkan1.0 is valid, but we chose not to support it?) Same for the tests which checks invalid spirv/vk mix? https://github.com/llvm/llvm-project/pull/76749 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL][SPIR-V] Add Vulkan to target triple (PR #76749)
@@ -4236,20 +4236,35 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args, // TODO: Revisit restricting SPIR-V to logical once we've figured out how to // handle PhysicalStorageBuffer64 memory model if (T.isDXIL() || T.isSPIRVLogical()) { - enum { ShaderModel, ShaderStage }; + enum { ShaderModel, VulkanEnv, ShaderStage }; + enum { OS, Environment }; + + int ExpectedOS = T.isSPIRVLogical() ? VulkanEnv : ShaderModel; + if (T.getOSName().empty()) { Diags.Report(diag::err_drv_hlsl_bad_shader_required_in_target) -<< ShaderModel << T.str(); - } else if (!T.isShaderModelOS() || T.getOSVersion() == VersionTuple(0)) { -Diags.Report(diag::err_drv_hlsl_bad_shader_unsupported) -<< ShaderModel << T.getOSName() << T.str(); +<< ExpectedOS << OS << T.str(); } else if (T.getEnvironmentName().empty()) { Diags.Report(diag::err_drv_hlsl_bad_shader_required_in_target) -<< ShaderStage << T.str(); +<< ShaderStage << Environment << T.str(); } else if (!T.isShaderStageEnvironment()) { Diags.Report(diag::err_drv_hlsl_bad_shader_unsupported) << ShaderStage << T.getEnvironmentName() << T.str(); } + + if (T.isDXIL()) { Keenuts wrote: Shall this be an: ```cpp if (T.isDXIL()) { else if (T.isSPIRVLogical()) { } else { llvm_unreachable(); } ``` (In case the condition line 4239 gets changed but not this) https://github.com/llvm/llvm-project/pull/76749 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL][SPIR-V] Add Vulkan to target triple (PR #76749)
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff fc9dbc999bc711a99b94b42453240b38a6509b0d 6141382cebfe0a40c054b2ce7539ec6ff85f3c14 -- clang/lib/Basic/Targets/SPIR.h clang/lib/Frontend/CompilerInvocation.cpp llvm/include/llvm/TargetParser/Triple.h llvm/lib/TargetParser/Triple.cpp llvm/unittests/TargetParser/TripleTest.cpp `` View the diff from clang-format here. ``diff diff --git a/llvm/include/llvm/TargetParser/Triple.h b/llvm/include/llvm/TargetParser/Triple.h index 4b3e87e1c3..c67c33444a 100644 --- a/llvm/include/llvm/TargetParser/Triple.h +++ b/llvm/include/llvm/TargetParser/Triple.h @@ -194,7 +194,7 @@ public: IOS, KFreeBSD, Linux, -Lv2,// PS3 +Lv2, // PS3 MacOSX, NetBSD, OpenBSD, @@ -204,17 +204,17 @@ public: ZOS, Haiku, RTEMS, -NaCl, // Native Client +NaCl, // Native Client AIX, -CUDA, // NVIDIA CUDA -NVCL, // NVIDIA OpenCL -AMDHSA, // AMD HSA Runtime +CUDA, // NVIDIA CUDA +NVCL, // NVIDIA OpenCL +AMDHSA, // AMD HSA Runtime PS4, PS5, ELFIAMCU, -TvOS, // Apple tvOS -WatchOS,// Apple watchOS -DriverKit, // Apple DriverKit +TvOS, // Apple tvOS +WatchOS, // Apple watchOS +DriverKit, // Apple DriverKit Mesa3D, AMDPAL, // AMD PAL Runtime HermitCore, // HermitCore Unikernel/Multikernel @@ -224,7 +224,7 @@ public: ShaderModel, // DirectX ShaderModel LiteOS, Serenity, -Vulkan, // Vulkan SPIR-V +Vulkan, // Vulkan SPIR-V LastOSType = Vulkan }; enum EnvironmentType { diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp index 7e8642bdb7..8b626f3872 100644 --- a/llvm/lib/TargetParser/Triple.cpp +++ b/llvm/lib/TargetParser/Triple.cpp @@ -274,7 +274,8 @@ StringRef Triple::getOSTypeName(OSType Kind) { case ZOS: return "zos"; case ShaderModel: return "shadermodel"; case LiteOS: return "liteos"; - case Vulkan: return "vulkan"; + case Vulkan: +return "vulkan"; } llvm_unreachable("Invalid OSType"); @@ -496,81 +497,82 @@ static Triple::ArchType parseARMArch(StringRef ArchName) { } static Triple::ArchType parseArch(StringRef ArchName) { - auto AT = StringSwitch(ArchName) -.Cases("i386", "i486", "i586", "i686", Triple::x86) -// FIXME: Do we need to support these? -.Cases("i786", "i886", "i986", Triple::x86) -.Cases("amd64", "x86_64", "x86_64h", Triple::x86_64) -.Cases("powerpc", "powerpcspe", "ppc", "ppc32", Triple::ppc) -.Cases("powerpcle", "ppcle", "ppc32le", Triple::ppcle) -.Cases("powerpc64", "ppu", "ppc64", Triple::ppc64) -.Cases("powerpc64le", "ppc64le", Triple::ppc64le) -.Case("xscale", Triple::arm) -.Case("xscaleeb", Triple::armeb) -.Case("aarch64", Triple::aarch64) -.Case("aarch64_be", Triple::aarch64_be) -.Case("aarch64_32", Triple::aarch64_32) -.Case("arc", Triple::arc) -.Case("arm64", Triple::aarch64) -.Case("arm64_32", Triple::aarch64_32) -.Case("arm64e", Triple::aarch64) -.Case("arm64ec", Triple::aarch64) -.Case("arm", Triple::arm) -.Case("armeb", Triple::armeb) -.Case("thumb", Triple::thumb) -.Case("thumbeb", Triple::thumbeb) -.Case("avr", Triple::avr) -.Case("m68k", Triple::m68k) -.Case("msp430", Triple::msp430) -.Cases("mips", "mipseb", "mipsallegrex", "mipsisa32r6", - "mipsr6", Triple::mips) -.Cases("mipsel", "mipsallegrexel", "mipsisa32r6el", "mipsr6el", - Triple::mipsel) -.Cases("mips64", "mips64eb", "mipsn32", "mipsisa64r6", - "mips64r6", "mipsn32r6", Triple::mips64) -.Cases("mips64el", "mipsn32el", "mipsisa64r6el", "mips64r6el", - "mipsn32r6el", Triple::mips64el) -.Case("r600", Triple::r600) -.Case("amdgcn", Triple::amdgcn) -.Case("riscv32", Triple::riscv32) -.Case("riscv64", Triple::riscv64) -.Case("hexagon", Triple::hexagon) -.Cases("s390x", "systemz", Triple::systemz) -.Case("sparc", Triple::sparc) -.Case("sparcel", Triple::sparcel) -.Cases("sparcv9", "sparc64", Triple::sparcv9) -.Case("tce", Triple::tce) -.Case("tcele", Triple::tcele) -.Case("xcore", Triple::xcore) -.Case("nvptx", Triple::nvptx) -.Case("nvptx64", Triple::nvptx64) -.Case("le32", Triple::le32) -.Case("le64", Triple::le64) -.Case("amdil", Triple::amdil) -.Case("amdil64", Triple::amdil64) -.Case("hsail", Triple::hsail) -.Case("hsail64", Triple::hsail64) -.Case("spir", Triple::spir) -.Case("spir64", Triple::spir64) -.Cases("spirv", "spirv1.5", "spirv1.6", Triple::spirv) -.Cases("spirv32", "spirv32v1.0", "spirv32v1.1", "spirv32v1.2", - "spirv32v1.3", "spirv32v1.4", "spirv32v1.5", Triple::spirv32) -.
[clang] [llvm] [HLSL][SPIR-V] Add Vulkan to target triple (PR #76749)
llvmbot wrote: @llvm/pr-subscribers-clang-driver Author: Natalie Chouinard (sudonatalie) Changes Add support for specifying the logical SPIR-V target environment in the triple as Vulkan. When compiling HLSL, this replaces the DirectX Shader Model with a Vulkan environment instead. Currently, the only supported combinations of SPIR-V version and Vulkan environment are: - Vulkan 1.2 and SPIR-V 1.5 - Vulkan 1.3 and SPIR-V 1.6 Fixes #70051 --- Full diff: https://github.com/llvm/llvm-project/pull/76749.diff 7 Files Affected: - (modified) clang/include/clang/Basic/DiagnosticDriverKinds.td (+2-2) - (modified) clang/lib/Basic/Targets/SPIR.h (+4-2) - (modified) clang/lib/Frontend/CompilerInvocation.cpp (+21-6) - (modified) clang/test/Driver/hlsl-lang-targets-spirv.hlsl (+19-9) - (modified) llvm/include/llvm/TargetParser/Triple.h (+9-1) - (modified) llvm/lib/TargetParser/Triple.cpp (+30-2) - (modified) llvm/unittests/TargetParser/TripleTest.cpp (+44-58) ``diff diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td index 676f1a62b49dd0..2e5ac4f349c0fd 100644 --- a/clang/include/clang/Basic/DiagnosticDriverKinds.td +++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td @@ -735,10 +735,10 @@ def err_drv_dxc_missing_target_profile : Error< def err_drv_hlsl_unsupported_target : Error< "HLSL code generation is unsupported for target '%0'">; def err_drv_hlsl_bad_shader_required_in_target : Error< - "shader %select{model|stage}0 is required in target '%1' for HLSL code generation">; + "%select{shader model|Vulkan environment|shader stage}0 is required as %select{OS|environment}1 in target '%2' for HLSL code generation">; def err_drv_hlsl_bad_shader_unsupported : Error< - "shader %select{model|stage}0 '%1' in target '%2' is invalid for HLSL code generation">; + "%select{shader model|Vulkan environment|shader stage}0 '%1' in target '%2' is invalid for HLSL code generation">; def warn_drv_dxc_missing_dxv : Warning<"dxv not found. " "Resulting DXIL will not be validated or signed for use in release environments.">, InGroup; diff --git a/clang/lib/Basic/Targets/SPIR.h b/clang/lib/Basic/Targets/SPIR.h index 9ab2b7c6093639..fa4a3bb1c82eed 100644 --- a/clang/lib/Basic/Targets/SPIR.h +++ b/clang/lib/Basic/Targets/SPIR.h @@ -17,6 +17,7 @@ #include "clang/Basic/TargetInfo.h" #include "clang/Basic/TargetOptions.h" #include "llvm/Support/Compiler.h" +#include "llvm/Support/VersionTuple.h" #include "llvm/TargetParser/Triple.h" #include @@ -301,8 +302,9 @@ class LLVM_LIBRARY_VISIBILITY SPIRVTargetInfo : public BaseSPIRVTargetInfo { : BaseSPIRVTargetInfo(Triple, Opts) { assert(Triple.getArch() == llvm::Triple::spirv && "Invalid architecture for Logical SPIR-V."); -assert(Triple.getOS() == llvm::Triple::ShaderModel && - "Logical SPIR-V requires a valid ShaderModel."); +assert(Triple.getOS() == llvm::Triple::Vulkan && + Triple.getVulkanVersion() != llvm::VersionTuple(0) && + "Logical SPIR-V requires a valid Vulkan environment."); assert(Triple.getEnvironment() >= llvm::Triple::Pixel && Triple.getEnvironment() <= llvm::Triple::Amplification && "Logical SPIR-V environment must be a valid shader stage."); diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 11f3f2c2d6425c..7e211ea24df2ae 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -4236,20 +4236,35 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args, // TODO: Revisit restricting SPIR-V to logical once we've figured out how to // handle PhysicalStorageBuffer64 memory model if (T.isDXIL() || T.isSPIRVLogical()) { - enum { ShaderModel, ShaderStage }; + enum { ShaderModel, VulkanEnv, ShaderStage }; + enum { OS, Environment }; + + int ExpectedOS = T.isSPIRVLogical() ? VulkanEnv : ShaderModel; + if (T.getOSName().empty()) { Diags.Report(diag::err_drv_hlsl_bad_shader_required_in_target) -<< ShaderModel << T.str(); - } else if (!T.isShaderModelOS() || T.getOSVersion() == VersionTuple(0)) { -Diags.Report(diag::err_drv_hlsl_bad_shader_unsupported) -<< ShaderModel << T.getOSName() << T.str(); +<< ExpectedOS << OS << T.str(); } else if (T.getEnvironmentName().empty()) { Diags.Report(diag::err_drv_hlsl_bad_shader_required_in_target) -<< ShaderStage << T.str(); +<< ShaderStage << Environment << T.str(); } else if (!T.isShaderStageEnvironment()) { Diags.Report(diag::err_drv_hlsl_bad_shader_unsupported) << ShaderStage << T.getEnvironmentName() << T.str(); } + + if (T.isDXIL()) { +if (!T.isShaderModelOS() || T.getOSVersion() == VersionTuple(0)) { + Diags.R
[clang] [llvm] [HLSL][SPIR-V] Add Vulkan to target triple (PR #76749)
https://github.com/sudonatalie created https://github.com/llvm/llvm-project/pull/76749 Add support for specifying the logical SPIR-V target environment in the triple as Vulkan. When compiling HLSL, this replaces the DirectX Shader Model with a Vulkan environment instead. Currently, the only supported combinations of SPIR-V version and Vulkan environment are: - Vulkan 1.2 and SPIR-V 1.5 - Vulkan 1.3 and SPIR-V 1.6 Fixes #70051 >From 6141382cebfe0a40c054b2ce7539ec6ff85f3c14 Mon Sep 17 00:00:00 2001 From: Natalie Chouinard Date: Fri, 15 Dec 2023 20:50:43 + Subject: [PATCH] [HLSL][SPIR-V] Add Vulkan to target triple Add support for specifying the logical SPIR-V target environment in the triple as Vulkan. When compiling HLSL, this replaces the DirectX Shader Model with a Vulkan environment instead. Currently, the only supported combinations of SPIR-V version and Vulkan environment are: - Vulkan 1.2 and SPIR-V 1.5 - Vulkan 1.3 and SPIR-V 1.6 Fixes #70051 --- .../clang/Basic/DiagnosticDriverKinds.td | 4 +- clang/lib/Basic/Targets/SPIR.h| 6 +- clang/lib/Frontend/CompilerInvocation.cpp | 27 +++-- .../test/Driver/hlsl-lang-targets-spirv.hlsl | 28 +++-- llvm/include/llvm/TargetParser/Triple.h | 10 +- llvm/lib/TargetParser/Triple.cpp | 32 +- llvm/unittests/TargetParser/TripleTest.cpp| 102 -- 7 files changed, 129 insertions(+), 80 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td index 676f1a62b49dd0..2e5ac4f349c0fd 100644 --- a/clang/include/clang/Basic/DiagnosticDriverKinds.td +++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td @@ -735,10 +735,10 @@ def err_drv_dxc_missing_target_profile : Error< def err_drv_hlsl_unsupported_target : Error< "HLSL code generation is unsupported for target '%0'">; def err_drv_hlsl_bad_shader_required_in_target : Error< - "shader %select{model|stage}0 is required in target '%1' for HLSL code generation">; + "%select{shader model|Vulkan environment|shader stage}0 is required as %select{OS|environment}1 in target '%2' for HLSL code generation">; def err_drv_hlsl_bad_shader_unsupported : Error< - "shader %select{model|stage}0 '%1' in target '%2' is invalid for HLSL code generation">; + "%select{shader model|Vulkan environment|shader stage}0 '%1' in target '%2' is invalid for HLSL code generation">; def warn_drv_dxc_missing_dxv : Warning<"dxv not found. " "Resulting DXIL will not be validated or signed for use in release environments.">, InGroup; diff --git a/clang/lib/Basic/Targets/SPIR.h b/clang/lib/Basic/Targets/SPIR.h index 9ab2b7c6093639..fa4a3bb1c82eed 100644 --- a/clang/lib/Basic/Targets/SPIR.h +++ b/clang/lib/Basic/Targets/SPIR.h @@ -17,6 +17,7 @@ #include "clang/Basic/TargetInfo.h" #include "clang/Basic/TargetOptions.h" #include "llvm/Support/Compiler.h" +#include "llvm/Support/VersionTuple.h" #include "llvm/TargetParser/Triple.h" #include @@ -301,8 +302,9 @@ class LLVM_LIBRARY_VISIBILITY SPIRVTargetInfo : public BaseSPIRVTargetInfo { : BaseSPIRVTargetInfo(Triple, Opts) { assert(Triple.getArch() == llvm::Triple::spirv && "Invalid architecture for Logical SPIR-V."); -assert(Triple.getOS() == llvm::Triple::ShaderModel && - "Logical SPIR-V requires a valid ShaderModel."); +assert(Triple.getOS() == llvm::Triple::Vulkan && + Triple.getVulkanVersion() != llvm::VersionTuple(0) && + "Logical SPIR-V requires a valid Vulkan environment."); assert(Triple.getEnvironment() >= llvm::Triple::Pixel && Triple.getEnvironment() <= llvm::Triple::Amplification && "Logical SPIR-V environment must be a valid shader stage."); diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 11f3f2c2d6425c..7e211ea24df2ae 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -4236,20 +4236,35 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args, // TODO: Revisit restricting SPIR-V to logical once we've figured out how to // handle PhysicalStorageBuffer64 memory model if (T.isDXIL() || T.isSPIRVLogical()) { - enum { ShaderModel, ShaderStage }; + enum { ShaderModel, VulkanEnv, ShaderStage }; + enum { OS, Environment }; + + int ExpectedOS = T.isSPIRVLogical() ? VulkanEnv : ShaderModel; + if (T.getOSName().empty()) { Diags.Report(diag::err_drv_hlsl_bad_shader_required_in_target) -<< ShaderModel << T.str(); - } else if (!T.isShaderModelOS() || T.getOSVersion() == VersionTuple(0)) { -Diags.Report(diag::err_drv_hlsl_bad_shader_unsupported) -<< ShaderModel << T.getOSName() << T.str(); +<< ExpectedOS << OS << T.str(); } else if (T.getEnvironmentName().empty()) { Diags.Report(d