Some HLSL functionality is gated on the target shader model version.
Enabling the use of availability markup allows us to diagnose
availability issues easily in the frontend.
Reviewed By: erichkeane
Differential Revision: https://reviews.llvm.org/D134067
.Case("maccatalyst", "macCatalyst")
.Case("maccatalyst_app_extension", "macCatalyst (App Extension)")
.Case("swift", "Swift")
+ .Case("shadermodel", "HLSL ShaderModel")
.Default(llvm::StringRef());
}
static llvm::StringRef getPlatformNameSourceSpelling(llvm::StringRef Platform) {
.Case("maccatalyst", "macCatalyst")
.Case("maccatalyst_app_extension", "macCatalystApplicationExtension")
.Case("zos", "z/OS")
+ .Case("shadermodel", "ShaderModel")
.Default(Platform);
}
static llvm::StringRef canonicalizePlatformName(llvm::StringRef Platform) {
.Case("watchOSApplicationExtension", "watchos_app_extension")
.Case("macCatalyst", "maccatalyst")
.Case("macCatalystApplicationExtension", "maccatalyst_app_extension")
+ .Case("ShaderModel", "shadermodel")
.Default(Platform);
} }];
let HasCustomParsing = 1;
HasLegalHalfType = true;
HasFloat16 = true;
NoAsmVariants = true;
+ PlatformMinVersion = Triple.getOSVersion();
+ PlatformName = llvm::Triple::getOSTypeName(Triple.getOS());
resetDataLayout("e-m:e-p:32:32-i1:32-i8:8-i16:16-i32:32-i64:64-f16:16-f32:"
"32-f64:64-n8:16:32:64");
TheCXXABI.set(TargetCXXABI::Microsoft);
#ifndef _HLSL_HLSL_INTRINSICS_H_
#define _HLSL_HLSL_INTRINSICS_H_
+__attribute__((availability(shadermodel, introduced = 6.0)))
__attribute__((clang_builtin_alias(__builtin_hlsl_wave_active_count_bits))) uint
WaveActiveCountBits(bool bBit);
case llvm::Triple::MacOSX:
ForceAvailabilityFromVersion = VersionTuple(/*Major=*/10, /*Minor=*/13);
break;
+ case llvm::Triple::ShaderModel:
+ // Always enable availability diagnostics for shader models.
+ return true;
default:
// New targets should always warn about availability.
return Triple.getVendor() == llvm::Triple::Apple;
--- /dev/null
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel5.0-library -verify %s
+
+__attribute__((availability(shadermodel, introduced = 6.0)))
+unsigned fn6_0(); // #fn6_0
+
+__attribute__((availability(shadermodel, introduced = 5.1)))
+unsigned fn5_1(); // #fn5_1
+
+__attribute__((availability(shadermodel, introduced = 5.0)))
+unsigned fn5_0();
+
+void fn() {
+ // expected-warning@#fn6_0_site {{'fn6_0' is only available on HLSL ShaderModel 6.0 or newer}}
+ // expected-note@#fn6_0 {{'fn6_0' has been marked as being introduced in HLSL ShaderModel 6.0 here, but the deployment target is HLSL ShaderModel 5.0}}
+ // expected-note@#fn6_0_site {{enclose 'fn6_0' in a __builtin_available check to silence this warning}}
+ unsigned A = fn6_0(); // #fn6_0_site
+
+ // expected-warning@#fn5_1_site {{'fn5_1' is only available on HLSL ShaderModel 5.1 or newer}}
+ // expected-note@#fn5_1 {{'fn5_1' has been marked as being introduced in HLSL ShaderModel 5.1 here, but the deployment target is HLSL ShaderModel 5.0}}
+ // expected-note@#fn5_1_site {{enclose 'fn5_1' in a __builtin_available check to silence this warning}}
+ unsigned B = fn5_1(); // #fn5_1_site
+
+ unsigned C = fn5_0();
+}
+
--- /dev/null
+// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel5.0-library -verify %s
+// WaveActiveCountBits is unavailable before ShaderModel 6.0.
+
+unsigned foo(bool b) {
+ // expected-warning@#site {{'WaveActiveCountBits' is only available on HLSL ShaderModel 6.0 or newer}}
+ // expected-note@hlsl/hlsl_intrinsics.h:* {{'WaveActiveCountBits' has been marked as being introduced in HLSL ShaderModel 6.0 here, but the deployment target is HLSL ShaderModel 5.0}}
+ // expected-note@#site {{enclose 'WaveActiveCountBits' in a __builtin_available check to silence this warning}}
+ return WaveActiveCountBits(b); // #site
+}