[PATCH] D132056: [HLSL] Restrict to supported targets
This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rG10194a51a9d3: [HLSL] Restrict to supported targets (authored by beanz). Changed prior to commit: https://reviews.llvm.org/D132056?vs=456746=457655#toc Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D132056/new/ https://reviews.llvm.org/D132056 Files: clang/include/clang/Basic/DiagnosticDriverKinds.td clang/lib/Frontend/CompilerInvocation.cpp clang/test/CodeGenHLSL/validator_version.hlsl clang/test/Driver/hlsl-lang-targets.hlsl clang/test/Preprocessor/predefined-macros-hlsl.hlsl Index: clang/test/Preprocessor/predefined-macros-hlsl.hlsl === --- clang/test/Preprocessor/predefined-macros-hlsl.hlsl +++ clang/test/Preprocessor/predefined-macros-hlsl.hlsl @@ -29,20 +29,20 @@ // PIXEL: #define __SHADER_TARGET_STAGE 0 // VERTEX: #define __SHADER_TARGET_STAGE 1 -// RUN: %clang_cc1 %s -E -dM -o - -std=hlsl2015 | FileCheck -match-full-lines %s --check-prefixes=STD2015 +// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library %s -E -dM -o - -x hlsl -std=hlsl2015 | FileCheck -match-full-lines %s --check-prefixes=STD2015 // STD2015: #define __HLSL_VERSION 2015 -// RUN: %clang_cc1 %s -E -dM -o - -std=hlsl2016 | FileCheck -match-full-lines %s --check-prefixes=STD2016 +// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library %s -E -dM -o - -x hlsl -std=hlsl2016 | FileCheck -match-full-lines %s --check-prefixes=STD2016 // STD2016: #define __HLSL_VERSION 2016 -// RUN: %clang_cc1 %s -E -dM -o - -std=hlsl2017 | FileCheck -match-full-lines %s --check-prefixes=STD2017 +// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library %s -E -dM -o - -x hlsl -std=hlsl2017 | FileCheck -match-full-lines %s --check-prefixes=STD2017 // STD2017: #define __HLSL_VERSION 2017 -// RUN: %clang_cc1 %s -E -dM -o - -std=hlsl2018 | FileCheck -match-full-lines %s --check-prefixes=STD2018 +// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library %s -E -dM -o - -x hlsl -std=hlsl2018 | FileCheck -match-full-lines %s --check-prefixes=STD2018 // STD2018: #define __HLSL_VERSION 2018 -// RUN: %clang_cc1 %s -E -dM -o - -std=hlsl2021 | FileCheck -match-full-lines %s --check-prefixes=STD2021 +// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library %s -E -dM -o - -x hlsl -std=hlsl2021 | FileCheck -match-full-lines %s --check-prefixes=STD2021 // STD2021: #define __HLSL_VERSION 2021 -// RUN: %clang_cc1 %s -E -dM -o - -std=hlsl202x | FileCheck -match-full-lines %s --check-prefixes=STD202x +// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library %s -E -dM -o - -x hlsl -std=hlsl202x | FileCheck -match-full-lines %s --check-prefixes=STD202x // STD202x: #define __HLSL_VERSION 2029 Index: clang/test/Driver/hlsl-lang-targets.hlsl === --- /dev/null +++ clang/test/Driver/hlsl-lang-targets.hlsl @@ -0,0 +1,14 @@ +// RUN: not %clang -target x86_64-unknown-unknown %s 2>&1 | FileCheck %s --check-prefix=X86 +// RUN: not %clang -target dxil-unknown-unknown %s 2>&1 | FileCheck %s --check-prefix=DXIL +// RUN: not %clang -target x86_64-unknown-shadermodel %s 2>&1 | FileCheck %s --check-prefix=SM +// RUN: not %clang -target spirv64-unknown-unknown %s 2>&1 | FileCheck %s --check-prefix=SPIRV + + +// A completely unsupported target... +// X86: error: HLSL code generation is unsupported for target 'x86_64-unknown-unknown' + +// Poorly specified targets +// DXIL: error: HLSL code generation is unsupported for target 'dxil-unknown-unknown' +// SM: error: HLSL code generation is unsupported for target 'x86_64-unknown-shadermodel' + +// FIXME// SPIRV: error: HLSL code generation is unsupported for target 'spirv64-unknown-unknown' Index: clang/test/CodeGenHLSL/validator_version.hlsl === --- clang/test/CodeGenHLSL/validator_version.hlsl +++ clang/test/CodeGenHLSL/validator_version.hlsl @@ -1,5 +1,7 @@ // RUN: %clang -cc1 -S -triple dxil-pc-shadermodel6.3-library -S -emit-llvm -xhlsl -validator-version 1.1 -o - %s | FileCheck %s -// RUN: %clang -cc1 -S -triple spirv32 -S -emit-llvm -xhlsl -validator-version 1.1 -o - %s | FileCheck %s --check-prefix=NOT_DXIL + +// FIXME:The following line should work once SPIR-V support for HLSL is added. +// DISABLED: %clang -cc1 -S -triple spirv32 -S -emit-llvm -xhlsl -validator-version 1.1 -o - %s | FileCheck %s --check-prefix=NOT_DXIL // CHECK:!dx.valver = !{![[valver:[0-9]+]]} // CHECK:![[valver]] = !{i32 1, i32 1} Index: clang/lib/Frontend/CompilerInvocation.cpp === --- clang/lib/Frontend/CompilerInvocation.cpp +++ clang/lib/Frontend/CompilerInvocation.cpp @@ -4107,6 +4107,14 @@ if (const Arg *A =
[PATCH] D132056: [HLSL] Restrict to supported targets
Anastasia accepted this revision. Anastasia added a comment. This makes sense. I believe the same applies to some other languages i.e. OpenCL, as the way clang evolved currently not all targets are compatible with all languages. In the future we might want to generalize this diagnostics to use in other cases too. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D132056/new/ https://reviews.llvm.org/D132056 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D132056: [HLSL] Restrict to supported targets
jcranmer-intel accepted this revision. jcranmer-intel added a comment. This revision is now accepted and ready to land. I don't necessarily know clang-specific code to have that valuable an opinion here, but I don't see anything wrong. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D132056/new/ https://reviews.llvm.org/D132056 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D132056: [HLSL] Restrict to supported targets
beanz updated this revision to Diff 456746. beanz added a comment. Adding the FIXME suggested by @aaron.ballman. Thanks! Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D132056/new/ https://reviews.llvm.org/D132056 Files: clang/include/clang/Basic/DiagnosticDriverKinds.td clang/lib/Frontend/CompilerInvocation.cpp clang/test/Driver/hlsl-lang-targets.hlsl clang/test/Preprocessor/predefined-macros-hlsl.c Index: clang/test/Preprocessor/predefined-macros-hlsl.c === --- clang/test/Preprocessor/predefined-macros-hlsl.c +++ clang/test/Preprocessor/predefined-macros-hlsl.c @@ -29,20 +29,20 @@ // PIXEL: #define __SHADER_TARGET_STAGE 0 // VERTEX: #define __SHADER_TARGET_STAGE 1 -// RUN: %clang_cc1 %s -E -dM -o - -x hlsl -std=hlsl2015 | FileCheck -match-full-lines %s --check-prefixes=STD2015 +// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library %s -E -dM -o - -x hlsl -std=hlsl2015 | FileCheck -match-full-lines %s --check-prefixes=STD2015 // STD2015: #define __HLSL_VERSION 2015 -// RUN: %clang_cc1 %s -E -dM -o - -x hlsl -std=hlsl2016 | FileCheck -match-full-lines %s --check-prefixes=STD2016 +// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library %s -E -dM -o - -x hlsl -std=hlsl2016 | FileCheck -match-full-lines %s --check-prefixes=STD2016 // STD2016: #define __HLSL_VERSION 2016 -// RUN: %clang_cc1 %s -E -dM -o - -x hlsl -std=hlsl2017 | FileCheck -match-full-lines %s --check-prefixes=STD2017 +// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library %s -E -dM -o - -x hlsl -std=hlsl2017 | FileCheck -match-full-lines %s --check-prefixes=STD2017 // STD2017: #define __HLSL_VERSION 2017 -// RUN: %clang_cc1 %s -E -dM -o - -x hlsl -std=hlsl2018 | FileCheck -match-full-lines %s --check-prefixes=STD2018 +// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library %s -E -dM -o - -x hlsl -std=hlsl2018 | FileCheck -match-full-lines %s --check-prefixes=STD2018 // STD2018: #define __HLSL_VERSION 2018 -// RUN: %clang_cc1 %s -E -dM -o - -x hlsl -std=hlsl2021 | FileCheck -match-full-lines %s --check-prefixes=STD2021 +// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library %s -E -dM -o - -x hlsl -std=hlsl2021 | FileCheck -match-full-lines %s --check-prefixes=STD2021 // STD2021: #define __HLSL_VERSION 2021 -// RUN: %clang_cc1 %s -E -dM -o - -x hlsl -std=hlsl202x | FileCheck -match-full-lines %s --check-prefixes=STD202x +// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library %s -E -dM -o - -x hlsl -std=hlsl202x | FileCheck -match-full-lines %s --check-prefixes=STD202x // STD202x: #define __HLSL_VERSION 2029 Index: clang/test/Driver/hlsl-lang-targets.hlsl === --- /dev/null +++ clang/test/Driver/hlsl-lang-targets.hlsl @@ -0,0 +1,14 @@ +// RUN: not %clang -target x86_64-unknown-unknown %s 2>&1 | FileCheck %s --check-prefix=X86 +// RUN: not %clang -target dxil-unknown-unknown %s 2>&1 | FileCheck %s --check-prefix=DXIL +// RUN: not %clang -target x86_64-unknown-shadermodel %s 2>&1 | FileCheck %s --check-prefix=SM +// RUN: not %clang -target spirv64-unknown-unknown %s 2>&1 | FileCheck %s --check-prefix=SPIRV + + +// A completely unsupported target... +// X86: error: HLSL code generation is unsupported for target 'x86_64-unknown-unknown' + +// Poorly specified targets +// DXIL: error: HLSL code generation is unsupported for target 'dxil-unknown-unknown' +// SM: error: HLSL code generation is unsupported for target 'x86_64-unknown-shadermodel' + +// FIXME// SPIRV: error: HLSL code generation is unsupported for target 'spirv64-unknown-unknown' Index: clang/lib/Frontend/CompilerInvocation.cpp === --- clang/lib/Frontend/CompilerInvocation.cpp +++ clang/lib/Frontend/CompilerInvocation.cpp @@ -4111,6 +4111,14 @@ if (const Arg *A = Args.getLastArg(OPT_frandomize_layout_seed_EQ)) Opts.RandstructSeed = A->getValue(0); + // Validate options for HLSL + if (Opts.HLSL) { +bool SupportedTarget = T.getArch() == llvm::Triple::dxil && + T.getOS() == llvm::Triple::ShaderModel; +if (!SupportedTarget) + Diags.Report(diag::err_drv_hlsl_unsupported_target) << T.str(); + } + return Diags.getNumErrors() == NumErrorsBefore; } Index: clang/include/clang/Basic/DiagnosticDriverKinds.td === --- clang/include/clang/Basic/DiagnosticDriverKinds.td +++ clang/include/clang/Basic/DiagnosticDriverKinds.td @@ -668,6 +668,8 @@ "invalid profile : %0">; def err_drv_dxc_missing_target_profile : Error< "target profile option (-T) is missing">; +def err_drv_hlsl_unsupported_target : Error< + "HLSL code generation is unsupported for target '%0'">; def err_drv_invalid_range_dxil_validator_version : Error< "invalid validator version : %0\n" Index:
[PATCH] D132056: [HLSL] Restrict to supported targets
aaron.ballman added reviewers: ABataev, Anastasia. aaron.ballman added a comment. I don't have particular concerns FWIW, but I'm not certain if others have opinions so I'm holding off on accepting for a bit. Comment at: clang/test/Driver/hlsl-lang-targets.hlsl:14 + +// Maybe someday +// SPIRV: error: HLSL code generation is unsupported for target 'spirv64-unknown-unknown' Thoughts on this change? Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D132056/new/ https://reviews.llvm.org/D132056 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D132056: [HLSL] Restrict to supported targets
beanz created this revision. beanz added reviewers: aaron.ballman, bogner, python3kgae, pow2clk, jcranmer-intel. Herald added subscribers: Anastasia, JDevlieghere. Herald added a project: All. beanz requested review of this revision. Herald added a project: clang. Someday we would like to support HLSL on a wider range of targets, but today targeting anything other than `dxil` is likly to cause lots of headaches. This adds an error and tests to validate that the expected target is `dxil-?-shadermodel`. We will continue to do a best effort to ensure the code we write makes it easy to support other targets (like SPIR-V), but this error will prevent users from hitting frustrating errors for unsupported cases. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D132056 Files: clang/include/clang/Basic/DiagnosticDriverKinds.td clang/lib/Frontend/CompilerInvocation.cpp clang/test/Driver/hlsl-lang-targets.hlsl clang/test/Preprocessor/predefined-macros-hlsl.c Index: clang/test/Preprocessor/predefined-macros-hlsl.c === --- clang/test/Preprocessor/predefined-macros-hlsl.c +++ clang/test/Preprocessor/predefined-macros-hlsl.c @@ -29,20 +29,20 @@ // PIXEL: #define __SHADER_TARGET_STAGE 0 // VERTEX: #define __SHADER_TARGET_STAGE 1 -// RUN: %clang_cc1 %s -E -dM -o - -x hlsl -std=hlsl2015 | FileCheck -match-full-lines %s --check-prefixes=STD2015 +// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library %s -E -dM -o - -x hlsl -std=hlsl2015 | FileCheck -match-full-lines %s --check-prefixes=STD2015 // STD2015: #define __HLSL_VERSION 2015 -// RUN: %clang_cc1 %s -E -dM -o - -x hlsl -std=hlsl2016 | FileCheck -match-full-lines %s --check-prefixes=STD2016 +// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library %s -E -dM -o - -x hlsl -std=hlsl2016 | FileCheck -match-full-lines %s --check-prefixes=STD2016 // STD2016: #define __HLSL_VERSION 2016 -// RUN: %clang_cc1 %s -E -dM -o - -x hlsl -std=hlsl2017 | FileCheck -match-full-lines %s --check-prefixes=STD2017 +// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library %s -E -dM -o - -x hlsl -std=hlsl2017 | FileCheck -match-full-lines %s --check-prefixes=STD2017 // STD2017: #define __HLSL_VERSION 2017 -// RUN: %clang_cc1 %s -E -dM -o - -x hlsl -std=hlsl2018 | FileCheck -match-full-lines %s --check-prefixes=STD2018 +// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library %s -E -dM -o - -x hlsl -std=hlsl2018 | FileCheck -match-full-lines %s --check-prefixes=STD2018 // STD2018: #define __HLSL_VERSION 2018 -// RUN: %clang_cc1 %s -E -dM -o - -x hlsl -std=hlsl2021 | FileCheck -match-full-lines %s --check-prefixes=STD2021 +// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library %s -E -dM -o - -x hlsl -std=hlsl2021 | FileCheck -match-full-lines %s --check-prefixes=STD2021 // STD2021: #define __HLSL_VERSION 2021 -// RUN: %clang_cc1 %s -E -dM -o - -x hlsl -std=hlsl202x | FileCheck -match-full-lines %s --check-prefixes=STD202x +// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library %s -E -dM -o - -x hlsl -std=hlsl202x | FileCheck -match-full-lines %s --check-prefixes=STD202x // STD202x: #define __HLSL_VERSION 2029 Index: clang/test/Driver/hlsl-lang-targets.hlsl === --- /dev/null +++ clang/test/Driver/hlsl-lang-targets.hlsl @@ -0,0 +1,15 @@ +// RUN: not %clang -target x86_64-unknown-unknown %s 2>&1 | FileCheck %s --check-prefix=X86 +// RUN: not %clang -target dxil-unknown-unknown %s 2>&1 | FileCheck %s --check-prefix=DXIL +// RUN: not %clang -target x86_64-unknown-shadermodel %s 2>&1 | FileCheck %s --check-prefix=SM +// RUN: not %clang -target spirv64-unknown-unknown %s 2>&1 | FileCheck %s --check-prefix=SPIRV + + +// A completely unsupported target... +// X86: error: HLSL code generation is unsupported for target 'x86_64-unknown-unknown' + +// Poorly specified targets +// DXIL: error: HLSL code generation is unsupported for target 'dxil-unknown-unknown' +// SM: error: HLSL code generation is unsupported for target 'x86_64-unknown-shadermodel' + +// Maybe someday +// SPIRV: error: HLSL code generation is unsupported for target 'spirv64-unknown-unknown' Index: clang/lib/Frontend/CompilerInvocation.cpp === --- clang/lib/Frontend/CompilerInvocation.cpp +++ clang/lib/Frontend/CompilerInvocation.cpp @@ -4111,6 +4111,14 @@ if (const Arg *A = Args.getLastArg(OPT_frandomize_layout_seed_EQ)) Opts.RandstructSeed = A->getValue(0); + // Validate options for HLSL + if (Opts.HLSL) { +bool SupportedTarget = T.getArch() == llvm::Triple::dxil && + T.getOS() == llvm::Triple::ShaderModel; +if (!SupportedTarget) + Diags.Report(diag::err_drv_hlsl_unsupported_target) << T.str(); + } + return Diags.getNumErrors() == NumErrorsBefore; } Index: clang/include/clang/Basic/DiagnosticDriverKinds.td