diff --git a/docs/ReleaseNotes.md b/docs/ReleaseNotes.md index f39f77f041..c228188ae9 100644 --- a/docs/ReleaseNotes.md +++ b/docs/ReleaseNotes.md @@ -22,6 +22,13 @@ The included licenses apply to the following files: Place release notes for the upcoming release below this line and remove this line upon naming the release. Refer to previous for appropriate section names. +#### Other Changes + +- Built-in HLSL headers are now embedded in the dxcompiler library so that users do not need to copy headers around with the toolchain. +- vector_utils.h and enable_if.h are renamed to vector_utils and enable_if respectively in alignment with TC57 decision on standard header files to exclude file extensions (See: https://github.com/hlsl-tc57/tc57/blob/main/docs/DesignConsiderations.md#minor-details). + +### Version 1.10.2605 + #### Experimental Shader Model 6.10 - Removed experimental Cooperative Vector, this has been replaced by LinAlg matrix. diff --git a/tools/clang/lib/Headers/hlsl/dx/.clang-format b/tools/clang/lib/Headers/hlsl/.clang-format similarity index 100% rename from tools/clang/lib/Headers/hlsl/dx/.clang-format rename to tools/clang/lib/Headers/hlsl/.clang-format diff --git a/tools/clang/lib/Headers/hlsl/dx/linalg.h b/tools/clang/lib/Headers/hlsl/dx/linalg.h index 44c1e96c37..144def3f05 100644 --- a/tools/clang/lib/Headers/hlsl/dx/linalg.h +++ b/tools/clang/lib/Headers/hlsl/dx/linalg.h @@ -1,4 +1,16 @@ -// Header for HLSL Linear Algebra Matrix APIs. +//===----------------------------------------------------------------------===// +// +// Part of the DirectXShaderCompiler, under the Apache License v2.0 with LLVM +// Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// DirectX Shader Model 6.10 Linear Algebra objects and APIs. +//===----------------------------------------------------------------------===// + +#include +#include #if ((__SHADER_TARGET_MAJOR > 6) || \ (__SHADER_TARGET_MAJOR == 6 && __SHADER_TARGET_MINOR >= 10)) && \ @@ -7,56 +19,8 @@ #pragma dxc diagnostic push #pragma dxc diagnostic ignored "-Whlsl-groupshared-202x" -namespace hlsl { - #define SIZE_TYPE int -template struct is_arithmetic { - static const bool value = false; -}; - -#define __ARITHMETIC_TYPE(type) \ - template <> struct is_arithmetic { \ - static const bool value = true; \ - }; - -#if __HLSL_ENABLE_16_BIT -__ARITHMETIC_TYPE(uint16_t) -__ARITHMETIC_TYPE(int16_t) -#endif -__ARITHMETIC_TYPE(uint) -__ARITHMETIC_TYPE(int) -__ARITHMETIC_TYPE(uint64_t) -__ARITHMETIC_TYPE(int64_t) -__ARITHMETIC_TYPE(half) -__ARITHMETIC_TYPE(float) -__ARITHMETIC_TYPE(double) - -template struct is_signed { - static const bool value = true; -}; - -#define __UNSIGNED_TYPE(type) \ - template <> struct is_signed { \ - static const bool value = false; \ - }; - -#if __HLSL_ENABLE_16_BIT -__UNSIGNED_TYPE(uint16_t) -#endif -__UNSIGNED_TYPE(uint) -__UNSIGNED_TYPE(uint64_t) - -#undef __UNSIGNED_TYPE - -template struct enable_if {}; - -template struct enable_if { - using type = T; -}; - -} // namespace hlsl - namespace dxil { // This enum must _exactly_ match the DXIL constants. diff --git a/tools/clang/lib/Headers/hlsl/enable_if b/tools/clang/lib/Headers/hlsl/enable_if new file mode 100644 index 0000000000..d63354f2cb --- /dev/null +++ b/tools/clang/lib/Headers/hlsl/enable_if @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// Part of the DirectXShaderCompiler, under the Apache License v2.0 with LLVM +// Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// SFINAE construct for enable_if to enable and disable declarations. +//===----------------------------------------------------------------------===// + +#ifndef __HLSL_ENABLE_IF +#define __HLSL_ENABLE_IF + +#if __HLSL_VERSION >= 2021 + +namespace hlsl { + +template struct enable_if {}; + +template struct enable_if { + using type = T; +}; + +} // namespace hlsl + +#endif // __HLSL_VERSION >= 2021 + +#endif // __HLSL_ENABLE_IF diff --git a/tools/clang/lib/Headers/hlsl/enable_if.h b/tools/clang/lib/Headers/hlsl/enable_if.h deleted file mode 100644 index b182ac28cf..0000000000 --- a/tools/clang/lib/Headers/hlsl/enable_if.h +++ /dev/null @@ -1,17 +0,0 @@ -// Header for enable_if APIs. - -#if ((__SHADER_TARGET_MAJOR > 6) || \ - (__SHADER_TARGET_MAJOR == 6 && __SHADER_TARGET_MINOR >= 9)) && \ - (__HLSL_VERSION >= 2021) - -namespace hlsl { - -template struct enable_if {}; - -template struct enable_if { - using type = T; -}; - -} // namespace hlsl - -#endif diff --git a/tools/clang/lib/Headers/hlsl/type_traits b/tools/clang/lib/Headers/hlsl/type_traits new file mode 100644 index 0000000000..24d711cc78 --- /dev/null +++ b/tools/clang/lib/Headers/hlsl/type_traits @@ -0,0 +1,60 @@ +//===----------------------------------------------------------------------===// +// +// Part of the DirectXShaderCompiler, under the Apache License v2.0 with LLVM +// Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// Template trait constructs for driving template specialization. +//===----------------------------------------------------------------------===// + +#ifndef __HLSL_TYPE_TRAITS +#define __HLSL_TYPE_TRAITS + +#if __HLSL_VERSION >= 2021 + +namespace hlsl { + +template struct is_arithmetic { + static const bool value = false; +}; + +#define __ARITHMETIC_TYPE(type) \ + template <> struct is_arithmetic { \ + static const bool value = true; \ + }; + +#if __HLSL_ENABLE_16_BIT +__ARITHMETIC_TYPE(uint16_t) +__ARITHMETIC_TYPE(int16_t) +#endif +__ARITHMETIC_TYPE(uint) +__ARITHMETIC_TYPE(int) +__ARITHMETIC_TYPE(uint64_t) +__ARITHMETIC_TYPE(int64_t) +__ARITHMETIC_TYPE(half) +__ARITHMETIC_TYPE(float) +__ARITHMETIC_TYPE(double) + +template struct is_signed { + static const bool value = true; +}; + +#define __UNSIGNED_TYPE(type) \ + template <> struct is_signed { \ + static const bool value = false; \ + }; + +#if __HLSL_ENABLE_16_BIT +__UNSIGNED_TYPE(uint16_t) +#endif +__UNSIGNED_TYPE(uint) +__UNSIGNED_TYPE(uint64_t) + +#undef __UNSIGNED_TYPE + +} // namespace hlsl + +#endif // __HLSL_VERSION >= 2021 +#endif // __HLSL_TYPE_TRAITS diff --git a/tools/clang/lib/Headers/hlsl/vector_utils b/tools/clang/lib/Headers/hlsl/vector_utils new file mode 100644 index 0000000000..54f9116470 --- /dev/null +++ b/tools/clang/lib/Headers/hlsl/vector_utils @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// Part of the DirectXShaderCompiler, under the Apache License v2.0 with LLVM +// Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// Header for vector template utility functions for operating on vector +// templates. +//===----------------------------------------------------------------------===// + +#ifndef __HLSL_VECTOR_UTILS +#define __HLSL_VECTOR_UTILS + +#if __HLSL_VERSION >= 2021 + +#include + +namespace hlsl { + +template +typename hlsl::enable_if >::type +slice(vector In) { + vector Result = (vector)0; + + [unroll] + for (int I = 0; I < OSz; ++I) + Result[I] = In[I + Off]; + + return Result; +} + +template +vector slice(vector In) { + return slice<0, OSz, T, ISz>(In); +} + +} // namespace hlsl + +#endif // __HLSL_VERSION >= 2021 +#endif // __HLSL_VECTOR_UTILS diff --git a/tools/clang/lib/Headers/hlsl/vector_utils.h b/tools/clang/lib/Headers/hlsl/vector_utils.h deleted file mode 100644 index eaad67f62c..0000000000 --- a/tools/clang/lib/Headers/hlsl/vector_utils.h +++ /dev/null @@ -1,32 +0,0 @@ -// Header for long vector APIs. - -#if ((__SHADER_TARGET_MAJOR > 6) || \ - (__SHADER_TARGET_MAJOR == 6 && __SHADER_TARGET_MINOR >= 9)) && \ - (__HLSL_VERSION >= 2021) - -#include - -namespace hlsl { - -// clang-format off -template -typename hlsl::enable_if >::type -slice(vector In) { - vector Result = (vector)0; - - [unroll] - for (int I = 0; I < OSz; ++I) - Result[I] = In[I + Off]; - - return Result; -} -// clang-format on - -template -vector slice(vector In) { - return slice<0, OSz, T, ISz>(In); -} - -} // namespace hlsl - -#endif diff --git a/tools/clang/lib/Lex/CMakeLists.txt b/tools/clang/lib/Lex/CMakeLists.txt index 7d4b227390..99ea78d2d3 100644 --- a/tools/clang/lib/Lex/CMakeLists.txt +++ b/tools/clang/lib/Lex/CMakeLists.txt @@ -40,8 +40,9 @@ set(generate_embedded_headers_script "${LLVM_MAIN_SRC_DIR}/utils/generate_hlsl_embedded_headers.py") set(hlsl_embedded_inputs - enable_if.h - vector_utils.h + enable_if + type_traits + vector_utils dx/linalg.h ) diff --git a/tools/clang/test/CodeGenDXIL/templates/vector_slice_6_0.hlsl b/tools/clang/test/CodeGenDXIL/templates/vector_slice_6_0.hlsl new file mode 100644 index 0000000000..2ad7028237 --- /dev/null +++ b/tools/clang/test/CodeGenDXIL/templates/vector_slice_6_0.hlsl @@ -0,0 +1,25 @@ +// RUN: %dxc -T ps_6_0 -E main %s | FileCheck %s + +#include + +RWByteAddressBuffer buf; + +float4 main(uint4 id: IN0) : SV_Target +{ + vector fVec = buf.Load >(0); + + float2 lhs = hlsl::slice<1, 2>(fVec); + float2 rhs = hlsl::slice<2>(fVec); + + // CHECK: [[Val:%.*]] = call %dx.types.ResRet.f32 @dx.op.bufferLoad.f32 + // CHECK: [[V0:%.*]] = extractvalue %dx.types.ResRet.f32 [[Val]], 0 + // CHECK: [[V1:%.*]] = extractvalue %dx.types.ResRet.f32 [[Val]], 1 + // CHECK: [[V2:%.*]] = extractvalue %dx.types.ResRet.f32 [[Val]], 2 + // CHECK: call void @dx.op.storeOutput.f32(i32 5, i32 0, i32 0, i8 0, float [[V1]]) + // CHECK: call void @dx.op.storeOutput.f32(i32 5, i32 0, i32 0, i8 1, float [[V2]]) + // CHECK: call void @dx.op.storeOutput.f32(i32 5, i32 0, i32 0, i8 2, float [[V0]]) + // CHECK: call void @dx.op.storeOutput.f32(i32 5, i32 0, i32 0, i8 3, float [[V1]]) + + float4 res = {lhs, rhs}; + return res; +} diff --git a/tools/clang/test/SemaHLSL/hlsl/embedded_headers/Inputs/enable_if.h b/tools/clang/test/SemaHLSL/hlsl/embedded_headers/Inputs/enable_if similarity index 100% rename from tools/clang/test/SemaHLSL/hlsl/embedded_headers/Inputs/enable_if.h rename to tools/clang/test/SemaHLSL/hlsl/embedded_headers/Inputs/enable_if diff --git a/tools/clang/test/SemaHLSL/hlsl/embedded_headers/embedded_header.hlsl b/tools/clang/test/SemaHLSL/hlsl/embedded_headers/embedded_header.hlsl index bbde8d1015..7d9d4c3a6e 100644 --- a/tools/clang/test/SemaHLSL/hlsl/embedded_headers/embedded_header.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/embedded_headers/embedded_header.hlsl @@ -1,15 +1,15 @@ // RUN: %dxc -T ps_6_0 -E main -M %s | FileCheck %s // RUN: %dxc -T ps_6_0 -E main -verify %s -// Verify that the bundled HLSL header tools/clang/lib/Headers/hlsl/enable_if.h +// Verify that the bundled HLSL header tools/clang/lib/Headers/hlsl/enable_if // is found via the angled-#include "embedded headers" path even when no -I // search path points at the hlsl/ directory. // expected-no-diagnostics -#include +#include float4 main() : SV_Target { return 0; } -// CHECK: /enable_if.h +// CHECK: /enable_if diff --git a/tools/clang/test/SemaHLSL/hlsl/embedded_headers/embedded_header_include_path.hlsl b/tools/clang/test/SemaHLSL/hlsl/embedded_headers/embedded_header_include_path.hlsl index d9470e5cfd..5f58f99483 100644 --- a/tools/clang/test/SemaHLSL/hlsl/embedded_headers/embedded_header_include_path.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/embedded_headers/embedded_header_include_path.hlsl @@ -9,10 +9,10 @@ // expected-no-diagnostics -#include +#include #ifndef HLSL_OVERLAY_ENABLE_IF -#error "Expected the on-disk overlay enable_if.h to take precedence over the embedded copy." +#error "Expected the on-disk overlay enable_if to take precedence over the embedded copy." #endif float4 main() : SV_Target { return 0; } @@ -20,4 +20,4 @@ float4 main() : SV_Target { return 0; } // The dependency dump must list the on-disk overlay path and must not // reference the virtual built-in:hlsl filename used for embedded headers. // CHECK-NOT: -// CHECK: Inputs{{[/\\]}}enable_if.h +// CHECK: Inputs{{[/\\]}}enable_if diff --git a/tools/clang/test/SemaHLSL/hlsl/vectors/slice-errors.hlsl b/tools/clang/test/SemaHLSL/hlsl/vectors/slice-errors.hlsl index 603a69a417..0a6ea185ca 100644 --- a/tools/clang/test/SemaHLSL/hlsl/vectors/slice-errors.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/vectors/slice-errors.hlsl @@ -1,6 +1,6 @@ // RUN: %dxc -T ps_6_9 -E main -verify %s -#include +#include RWByteAddressBuffer buf; @@ -15,8 +15,8 @@ float4 main(uint4 id: IN0) : SV_Target // expected-error@+1 {{no matching function for call to 'slice'}} float4 rhs = hlsl::slice<2, 4>(fVec); - // expected-note@vector_utils.h:13 {{candidate template ignored: disabled by 'enable_if' [with Off = 2, OSz = 4, T = float, ISz = 4]}} - // expected-note@vector_utils.h:26 {{candidate template ignored: invalid explicitly-specified argument for template parameter 'T'}} + // expected-note@vector_utils:23 {{candidate template ignored: disabled by 'enable_if' [with Off = 2, OSz = 4, T = float, ISz = 4]}} + // expected-note@vector_utils:35 {{candidate template ignored: invalid explicitly-specified argument for template parameter 'T'}} return lhs + rhs; } diff --git a/tools/clang/test/SemaHLSL/hlsl/vectors/slice.hlsl b/tools/clang/test/SemaHLSL/hlsl/vectors/slice.hlsl index e4c545d0ae..c7b939c238 100644 --- a/tools/clang/test/SemaHLSL/hlsl/vectors/slice.hlsl +++ b/tools/clang/test/SemaHLSL/hlsl/vectors/slice.hlsl @@ -1,7 +1,7 @@ // REQUIRES: dxil-1-9 // RUN: %dxc -T ps_6_9 -E main %s | FileCheck %s -#include +#include RWByteAddressBuffer buf;