1//===- HLSLRuntime.h - HLSL Runtime -----------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9/// \file
10/// Defines helper utilities for supporting the HLSL runtime environment.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef CLANG_BASIC_HLSLRUNTIME_H
15#define CLANG_BASIC_HLSLRUNTIME_H
16
17#include "clang/Basic/LangOptions.h"
18#include <cstdint>
19
20namespace clang {
21namespace hlsl {
22
23constexpr ShaderStage
24getStageFromEnvironment(const llvm::Triple::EnvironmentType &E) {
25 uint32_t Pipeline =
26 static_cast<uint32_t>(E) - static_cast<uint32_t>(llvm::Triple::Pixel);
27
28 if (Pipeline > (uint32_t)ShaderStage::Invalid)
29 return ShaderStage::Invalid;
30 return static_cast<ShaderStage>(Pipeline);
31}
32
33#define ENUM_COMPARE_ASSERT(Value) \
34 static_assert( \
35 getStageFromEnvironment(llvm::Triple::Value) == ShaderStage::Value, \
36 "Mismatch between llvm::Triple and clang::ShaderStage for " #Value);
37
38ENUM_COMPARE_ASSERT(Pixel)
39ENUM_COMPARE_ASSERT(Vertex)
40ENUM_COMPARE_ASSERT(Geometry)
41ENUM_COMPARE_ASSERT(Hull)
42ENUM_COMPARE_ASSERT(Domain)
43ENUM_COMPARE_ASSERT(Compute)
44ENUM_COMPARE_ASSERT(Library)
45ENUM_COMPARE_ASSERT(RayGeneration)
46ENUM_COMPARE_ASSERT(Intersection)
47ENUM_COMPARE_ASSERT(AnyHit)
48ENUM_COMPARE_ASSERT(ClosestHit)
49ENUM_COMPARE_ASSERT(Miss)
50ENUM_COMPARE_ASSERT(Callable)
51ENUM_COMPARE_ASSERT(Mesh)
52ENUM_COMPARE_ASSERT(Amplification)
53
54static_assert(getStageFromEnvironment(E: llvm::Triple::UnknownEnvironment) ==
55 ShaderStage::Invalid,
56 "Mismatch between llvm::Triple and "
57 "clang::ShaderStage for Invalid");
58static_assert(getStageFromEnvironment(E: llvm::Triple::MSVC) ==
59 ShaderStage::Invalid,
60 "Mismatch between llvm::Triple and "
61 "clang::ShaderStage for Invalid");
62
63} // namespace hlsl
64} // namespace clang
65
66#endif // CLANG_BASIC_HLSLRUNTIME_H
67

source code of clang/include/clang/Basic/HLSLRuntime.h