diff --git a/clang/lib/Headers/hlsl/hlsl_basic_types.h b/clang/lib/Headers/hlsl/hlsl_basic_types.h --- a/clang/lib/Headers/hlsl/hlsl_basic_types.h +++ b/clang/lib/Headers/hlsl/hlsl_basic_types.h @@ -9,6 +9,7 @@ #ifndef _HLSL_HLSL_BASIC_TYPES_H_ #define _HLSL_HLSL_BASIC_TYPES_H_ +namespace hlsl { // built-in scalar data types: #ifdef __HLSL_ENABLE_16_BIT @@ -61,4 +62,6 @@ typedef vector double3; typedef vector double4; +} // namespace hlsl + #endif //_HLSL_HLSL_BASIC_TYPES_H_ diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h b/clang/lib/Headers/hlsl/hlsl_intrinsics.h --- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h +++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h @@ -9,6 +9,8 @@ #ifndef _HLSL_HLSL_INTRINSICS_H_ #define _HLSL_HLSL_INTRINSICS_H_ +namespace hlsl { + __attribute__((availability(shadermodel, introduced = 6.0))) __attribute__((clang_builtin_alias(__builtin_hlsl_wave_active_count_bits))) uint WaveActiveCountBits(bool bBit); @@ -99,4 +101,6 @@ __attribute__((clang_builtin_alias(__builtin_elementwise_ceil))) double4 ceil(double4); +} // namespace hlsl + #endif //_HLSL_HLSL_INTRINSICS_H_ diff --git a/clang/test/CodeGenHLSL/basic_types.hlsl b/clang/test/CodeGenHLSL/basic_types.hlsl --- a/clang/test/CodeGenHLSL/basic_types.hlsl +++ b/clang/test/CodeGenHLSL/basic_types.hlsl @@ -1,6 +1,9 @@ // RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \ // RUN: dxil-pc-shadermodel6.3-library %s -fnative-half-type \ // RUN: -emit-llvm -disable-llvm-passes -o - | FileCheck %s +// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \ +// RUN: dxil-pc-shadermodel6.3-library %s -fnative-half-type \ +// RUN: -emit-llvm -disable-llvm-passes -o - -DNAMESPACED| FileCheck %s // CHECK:"?uint16_t_Val@@3GA" = global i16 0, align 2 @@ -36,7 +39,11 @@ // CHECK:"?double3_Val@@3T?$__vector@N$02@__clang@@A" = global <3 x double> zeroinitializer, align 32 // CHECK:"?double4_Val@@3T?$__vector@N$03@__clang@@A" = global <4 x double> zeroinitializer, align 32 +#ifdef NAMESPACED +#define TYPE_DECL(T) hlsl::T T##_Val +#else #define TYPE_DECL(T) T T##_Val +#endif #ifdef __HLSL_ENABLE_16_BIT TYPE_DECL(uint16_t); diff --git a/clang/test/CodeGenHLSL/builtins/abs.hlsl b/clang/test/CodeGenHLSL/builtins/abs.hlsl --- a/clang/test/CodeGenHLSL/builtins/abs.hlsl +++ b/clang/test/CodeGenHLSL/builtins/abs.hlsl @@ -5,6 +5,7 @@ // RUN: dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes \ // RUN: -D__HLSL_ENABLE_16_BIT -o - | FileCheck %s --check-prefix=NO_HALF +using hlsl::abs; // CHECK: define noundef signext i16 @ // FIXME: int16_t is promoted to i32 now. Change to abs.i16 once it is fixed. diff --git a/clang/test/CodeGenHLSL/builtins/ceil.hlsl b/clang/test/CodeGenHLSL/builtins/ceil.hlsl --- a/clang/test/CodeGenHLSL/builtins/ceil.hlsl +++ b/clang/test/CodeGenHLSL/builtins/ceil.hlsl @@ -5,6 +5,8 @@ // RUN: dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes \ // RUN: -D__HLSL_ENABLE_16_BIT -o - | FileCheck %s --check-prefix=NO_HALF +using hlsl::ceil; + // CHECK: define noundef half @ // CHECK: call half @llvm.ceil.f16( // NO_HALF: define noundef float @"?test_ceil_half@@YA$halff@$halff@@Z"( diff --git a/clang/test/CodeGenHLSL/builtins/sqrt.hlsl b/clang/test/CodeGenHLSL/builtins/sqrt.hlsl --- a/clang/test/CodeGenHLSL/builtins/sqrt.hlsl +++ b/clang/test/CodeGenHLSL/builtins/sqrt.hlsl @@ -5,6 +5,8 @@ // RUN: dxil-pc-shadermodel6.2-library %s -emit-llvm -disable-llvm-passes \ // RUN: -o - | FileCheck %s --check-prefix=NO_HALF +using hlsl::sqrt; + double sqrt_d(double x) { return sqrt(x); diff --git a/clang/test/SemaHLSL/Wave.hlsl b/clang/test/SemaHLSL/Wave.hlsl --- a/clang/test/SemaHLSL/Wave.hlsl +++ b/clang/test/SemaHLSL/Wave.hlsl @@ -4,5 +4,5 @@ // expected-no-diagnostics unsigned foo(bool b) { - return WaveActiveCountBits(b); + return hlsl::WaveActiveCountBits(b); } diff --git a/clang/test/SemaHLSL/WaveBuiltinAvailability.hlsl b/clang/test/SemaHLSL/WaveBuiltinAvailability.hlsl --- a/clang/test/SemaHLSL/WaveBuiltinAvailability.hlsl +++ b/clang/test/SemaHLSL/WaveBuiltinAvailability.hlsl @@ -5,5 +5,5 @@ // 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 + return hlsl::WaveActiveCountBits(b); // #site }