Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:36:49

0001 //===- HLSLRuntime.h - HLSL Runtime -----------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 /// \file
0010 /// Defines helper utilities for supporting the HLSL runtime environment.
0011 //
0012 //===----------------------------------------------------------------------===//
0013 
0014 #ifndef CLANG_BASIC_HLSLRUNTIME_H
0015 #define CLANG_BASIC_HLSLRUNTIME_H
0016 
0017 #include "clang/Basic/LangOptions.h"
0018 #include <cstdint>
0019 
0020 namespace clang {
0021 namespace hlsl {
0022 
0023 constexpr ShaderStage
0024 getStageFromEnvironment(const llvm::Triple::EnvironmentType &E) {
0025   uint32_t Pipeline =
0026       static_cast<uint32_t>(E) - static_cast<uint32_t>(llvm::Triple::Pixel);
0027 
0028   if (Pipeline > (uint32_t)ShaderStage::Invalid)
0029     return ShaderStage::Invalid;
0030   return static_cast<ShaderStage>(Pipeline);
0031 }
0032 
0033 #define ENUM_COMPARE_ASSERT(Value)                                             \
0034   static_assert(                                                               \
0035       getStageFromEnvironment(llvm::Triple::Value) == ShaderStage::Value,      \
0036       "Mismatch between llvm::Triple and clang::ShaderStage for " #Value);
0037 
0038 ENUM_COMPARE_ASSERT(Pixel)
0039 ENUM_COMPARE_ASSERT(Vertex)
0040 ENUM_COMPARE_ASSERT(Geometry)
0041 ENUM_COMPARE_ASSERT(Hull)
0042 ENUM_COMPARE_ASSERT(Domain)
0043 ENUM_COMPARE_ASSERT(Compute)
0044 ENUM_COMPARE_ASSERT(Library)
0045 ENUM_COMPARE_ASSERT(RayGeneration)
0046 ENUM_COMPARE_ASSERT(Intersection)
0047 ENUM_COMPARE_ASSERT(AnyHit)
0048 ENUM_COMPARE_ASSERT(ClosestHit)
0049 ENUM_COMPARE_ASSERT(Miss)
0050 ENUM_COMPARE_ASSERT(Callable)
0051 ENUM_COMPARE_ASSERT(Mesh)
0052 ENUM_COMPARE_ASSERT(Amplification)
0053 
0054 static_assert(getStageFromEnvironment(llvm::Triple::UnknownEnvironment) ==
0055                   ShaderStage::Invalid,
0056               "Mismatch between llvm::Triple and "
0057               "clang::ShaderStage for Invalid");
0058 static_assert(getStageFromEnvironment(llvm::Triple::MSVC) ==
0059                   ShaderStage::Invalid,
0060               "Mismatch between llvm::Triple and "
0061               "clang::ShaderStage for Invalid");
0062 
0063 } // namespace hlsl
0064 } // namespace clang
0065 
0066 #endif // CLANG_BASIC_HLSLRUNTIME_H