From e504194d51e1f0f7ca5b684b4aa99db4940856c2 Mon Sep 17 00:00:00 2001 From: Justin Bogner Date: Tue, 29 Aug 2023 01:03:32 -0700 Subject: [Driver][HLSL] Improve diagnostics for invalid shader model and stage 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. Differential Revision: https://reviews.llvm.org/D159103 --- clang/lib/Frontend/CompilerInvocation.cpp | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'clang/lib/Frontend/CompilerInvocation.cpp') diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 73a3d31..730db8e 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -4143,10 +4143,24 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args, // Validate options for HLSL if (Opts.HLSL) { - bool SupportedTarget = (T.getArch() == llvm::Triple::dxil || - T.getArch() == llvm::Triple::spirv) && - T.getOS() == llvm::Triple::ShaderModel; - if (!SupportedTarget) + // 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 }; + 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(); + } else if (T.getEnvironmentName().empty()) { + Diags.Report(diag::err_drv_hlsl_bad_shader_required_in_target) + << ShaderStage << T.str(); + } else if (!T.isShaderStageEnvironment()) { + Diags.Report(diag::err_drv_hlsl_bad_shader_unsupported) + << ShaderStage << T.getEnvironmentName() << T.str(); + } + } else Diags.Report(diag::err_drv_hlsl_unsupported_target) << T.str(); } -- cgit v1.1