bogner created this revision.
bogner added reviewers: aaron.ballman, beanz.
Herald added subscribers: Anastasia, mcrosier.
Herald added a project: All.
bogner requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.
This adds more validation that a dxil triple is actually useable when
compiling HLSL.
The OS field of the triple needs to be a versioned shader model.
Later, we should set a default if this is empty and check that the
version is a shader model we can actually handle.
The Environment field of the triple needs to be specified and be a
valid shader stage. I'd like to allow this to be empty and treat it
like library, but allowing that currently crashes in DXIL metadata
handling.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D159103
Files:
clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/lib/Frontend/CompilerInvocation.cpp
clang/lib/Sema/SemaDecl.cpp
clang/test/Driver/hlsl-lang-targets.hlsl
llvm/include/llvm/TargetParser/Triple.h
Index: llvm/include/llvm/TargetParser/Triple.h
===================================================================
--- llvm/include/llvm/TargetParser/Triple.h
+++ llvm/include/llvm/TargetParser/Triple.h
@@ -271,7 +271,9 @@
Callable,
Mesh,
Amplification,
+
OpenHOS,
+
LastEnvironmentType = OpenHOS
};
enum ObjectFormatType {
@@ -756,6 +758,22 @@
return getArch() == Triple::dxil;
}
+ bool isShaderModelOS() const {
+ return getOS() == Triple::ShaderModel;
+ }
+
+ bool isShaderStageEnvironment() const {
+ EnvironmentType Env = getEnvironment();
+ return Env == Triple::Pixel || Env == Triple::Vertex ||
+ Env == Triple::Geometry || Env == Triple::Hull ||
+ Env == Triple::Domain || Env == Triple::Compute ||
+ Env == Triple::Library || Env == Triple::RayGeneration ||
+ Env == Triple::Intersection || Env == Triple::AnyHit ||
+ Env == Triple::ClosestHit || Env == Triple::Miss ||
+ Env == Triple::Callable || Env == Triple::Mesh ||
+ Env == Triple::Amplification;
+ }
+
/// Tests whether the target is SPIR (32- or 64-bit).
bool isSPIR() const {
return getArch() == Triple::spir || getArch() == Triple::spir64;
Index: clang/test/Driver/hlsl-lang-targets.hlsl
===================================================================
--- clang/test/Driver/hlsl-lang-targets.hlsl
+++ clang/test/Driver/hlsl-lang-targets.hlsl
@@ -1,14 +1,52 @@
-// 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
+// Supported targets
+//
+// RUN: %clang -target dxil--shadermodel6.2-pixel %s -S -o /dev/null 2>&1 | FileCheck --check-prefix=CHECK-VALID %s
+// RUN: %clang -target dxil-unknown-shadermodel6.2-pixel %s -S -o /dev/null 2>&1 | FileCheck --check-prefix=CHECK-VALID %s
+// RUN: %clang -target dxil--shadermodel6.2-library %s -S -o /dev/null 2>&1 | FileCheck --check-prefix=CHECK-VALID %s
+// RUN: %clang -target dxil-unknown-shadermodel6.2-library %s -S -o /dev/null 2>&1 | FileCheck --check-prefix=CHECK-VALID %s
+// Empty shader model
+//
+// RUN: not %clang -target dxil %s -S -o /dev/null 2>&1 | FileCheck --check-prefix=CHECK-NO-OS %s
-// A completely unsupported target...
-// X86: error: HLSL code generation is unsupported for target 'x86_64-unknown-unknown'
+// Invalid shader models
+//
+// RUN: not %clang -target dxil--linux %s -S -o /dev/null 2>&1 | FileCheck --check-prefix=CHECK-BAD-OS %s
+// RUN: not %clang -target dxil--win32 %s -S -o /dev/null 2>&1 | FileCheck --check-prefix=CHECK-BAD-OS %s
+// RUN: not %clang -target dxil--unknown %s -S -o /dev/null 2>&1 | FileCheck --check-prefix=CHECK-BAD-OS %s
+// RUN: not %clang -target dxil--invalidos %s -S -o /dev/null 2>&1 | FileCheck --check-prefix=CHECK-BAD-OS %s
-// 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'
+// Bad shader model versions. Currently we just check for any version at all.
+//
+// RUN: not %clang -target dxil--shadermodel %s -S -o /dev/null 2>&1 | FileCheck --check-prefix=CHECK-BAD-OS %s
+// RUN: not %clang -target dxil--shadermodel0.0 %s -S -o /dev/null 2>&1 | FileCheck --check-prefix=CHECK-BAD-OS %s
-// FIXME// SPIRV: error: HLSL code generation is unsupported for target 'spirv64-unknown-unknown'
+// Empty shader stage
+//
+// RUN: not %clang -target dxil-shadermodel6.2 %s -S -o /dev/null 2>&1 | FileCheck --check-prefix=CHECK-NO-ENV %s
+// RUN: not %clang -target dxil--shadermodel6.2 %s -S -o /dev/null 2>&1 | FileCheck --check-prefix=CHECK-NO-ENV %s
+// RUN: not %clang -target dxil--shadermodel6.2 %s -S -o /dev/null 2>&1 | FileCheck --check-prefix=CHECK-NO-ENV %s
+
+// Invalid shader stages
+//
+// RUN: not %clang -target dxil--shadermodel6.2-unknown %s -S -o /dev/null 2>&1 | FileCheck --check-prefix=CHECK-BAD-ENV %s
+// RUN: not %clang -target dxil--shadermodel6.2-invalidenvironment %s -S -o /dev/null 2>&1 | FileCheck --check-prefix=CHECK-BAD-ENV %s
+// RUN: not %clang -target dxil--shadermodel6.2-eabi %s -S -o /dev/null 2>&1 | FileCheck --check-prefix=CHECK-BAD-ENV %s
+// RUN: not %clang -target dxil--shadermodel6.2-msvc %s -S -o /dev/null 2>&1 | FileCheck --check-prefix=CHECK-BAD-ENV %s
+
+// Non-dxil targets
+//
+// RUN: not %clang -target x86_64-unknown-unknown %s -S -o /dev/null 2>&1 | FileCheck --check-prefix=CHECK-BAD-TARGET %s
+// RUN: not %clang -target x86_64-linux %s -S -o /dev/null 2>&1 | FileCheck --check-prefix=CHECK-BAD-TARGET %s
+// RUN: not %clang -target amdgcn %s -S -o /dev/null 2>&1 | FileCheck --check-prefix=CHECK-BAD-TARGET %s
+// RUN: not %clang -target spirv64-unknown-unknown %s -S -o /dev/null 2>&1 | FileCheck --check-prefix=CHECK-BAD-TARGET %s
+
+// CHECK-VALID-NOT: error:
+// CHECK-NO-OS: error: Shader model is required in target '{{.*}}' for DXIL generation
+// CHECK-BAD-OS: error: Shader model '{{.*}}' in target '{{.*}}' is invalid for DXIL generation
+// CHECK-NO-ENV: error: Shader stage is required in target '{{.*}}' for DXIL generation
+// CHECK-BAD-ENV: error: Shader stage '{{.*}}' in target '{{.*}}' is invalid for DXIL generation
+// CHECK-BAD-TARGET: error: HLSL code generation is unsupported for target '{{.*}}'
+
+[shader("pixel")]
+void main() {}
Index: clang/lib/Sema/SemaDecl.cpp
===================================================================
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -12392,10 +12392,7 @@
case llvm::Triple::Library:
break;
default:
- // TODO: This should probably just be llvm_unreachable and we should
- // reject triples with random ABIs and such when we build the target.
- // For now, crash.
- llvm::report_fatal_error("Unhandled environment in triple");
+ llvm_unreachable("Unhandled environment in triple");
}
}
}
Index: clang/lib/Frontend/CompilerInvocation.cpp
===================================================================
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -4049,9 +4049,19 @@
// Validate options for HLSL
if (Opts.HLSL) {
- bool SupportedTarget = T.getArch() == llvm::Triple::dxil &&
- T.getOS() == llvm::Triple::ShaderModel;
- if (!SupportedTarget)
+ if (T.isDXIL()) {
+ if (T.getOSName().empty()) {
+ Diags.Report(diag::err_drv_dxil_missing_shader_model) << T.str();
+ } else if (!T.isShaderModelOS() || T.getOSVersion() == VersionTuple(0)) {
+ Diags.Report(diag::err_drv_dxil_unsupported_shader_model)
+ << T.getOSName() << T.str();
+ } else if (T.getEnvironmentName().empty()) {
+ Diags.Report(diag::err_drv_dxil_missing_shader_stage) << T.str();
+ } else if (!T.isShaderStageEnvironment()) {
+ Diags.Report(diag::err_drv_dxil_unsupported_shader_stage)
+ << T.getEnvironmentName() << T.str();
+ }
+ } else
Diags.Report(diag::err_drv_hlsl_unsupported_target) << T.str();
}
Index: clang/include/clang/Basic/DiagnosticDriverKinds.td
===================================================================
--- clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -706,6 +706,14 @@
"target profile option (-T) is missing">;
def err_drv_hlsl_unsupported_target : Error<
"HLSL code generation is unsupported for target '%0'">;
+def err_drv_dxil_missing_shader_model : Error<
+ "Shader model is required in target '%0' for DXIL generation">;
+def err_drv_dxil_unsupported_shader_model : Error<
+ "Shader model '%0' in target '%1' is invalid for DXIL generation">;
+def err_drv_dxil_missing_shader_stage : Error<
+ "Shader stage is required in target '%0' for DXIL generation">;
+def err_drv_dxil_unsupported_shader_stage : Error<
+ "Shader stage '%0' in target '%1' is invalid for DXIL 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<DXILValidation>;
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits