yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
ab5a81529
master
1#ifndef SLANG_CPP_PRELUDE_H 2#define SLANG_CPP_PRELUDE_H 3 4// Because the signature of isnan, isfinite, and is isinf changed in C++, we use the macro 5// to use the version in the std namespace. 6// https://stackoverflow.com/questions/39130040/cmath-hides-isnan-in-math-h-in-c14-c11 7 8#ifdef SLANG_LLVM 9#include "slang-llvm.h" 10#else // SLANG_LLVM 11#if SLANG_GCC_FAMILY && __GNUC__ < 6 12#include <cmath> 13#define SLANG_PRELUDE_STD std:: 14#else 15#include <math.h> 16#define SLANG_PRELUDE_STD 17#endif 18 19#include <assert.h> 20#include <stdint.h> 21#include <stdlib.h> 22#include <string.h> 23#endif // SLANG_LLVM 24 25// Is intptr_t not equal to equal-width sized integer type? 26#if defined(__APPLE__ ) 27#define SLANG_INTPTR_TYPE_IS_DISTINCT 1 28#else 29#define SLANG_INTPTR_TYPE_IS_DISTINCT 0 30#endif 31 32#if defined(_MSC_VER ) 33#define SLANG_PRELUDE_SHARED_LIB_EXPORT __declspec(dllexport) 34#else 35#define SLANG_PRELUDE_SHARED_LIB_EXPORT __attribute__((__visibility__("default"))) 36// # define SLANG_PRELUDE_SHARED_LIB_EXPORT __attribute__ ((dllexport)) 37// __attribute__((__visibility__("default"))) 38#endif 39 40#ifdef __cplusplus 41#define SLANG_PRELUDE_EXTERN_C extern "C" 42#define SLANG_PRELUDE_EXTERN_C_START \ 43 extern "C" \ 44 { 45#define SLANG_PRELUDE_EXTERN_C_END } 46#else 47#define SLANG_PRELUDE_EXTERN_C 48#define SLANG_PRELUDE_EXTERN_C_START 49#define SLANG_PRELUDE_EXTERN_C_END 50#endif 51 52#define SLANG_PRELUDE_EXPORT SLANG_PRELUDE_EXTERN_C SLANG_PRELUDE_SHARED_LIB_EXPORT 53#define SLANG_PRELUDE_EXPORT_START SLANG_PRELUDE_EXTERN_C_START SLANG_PRELUDE_SHARED_LIB_EXPORT 54#define SLANG_PRELUDE_EXPORT_END SLANG_PRELUDE_EXTERN_C_END 55 56#ifndef INFINITY 57// Must overflow for double 58#define INFINITY float(1e+300 * 1e+300) 59#endif 60 61#ifndef SLANG_INFINITY 62#define SLANG_INFINITY INFINITY 63#endif 64 65// Detect the compiler type 66 67#ifndef SLANG_COMPILER 68#define SLANG_COMPILER 69 70/* 71Compiler defines, see http://sourceforge.net/p/predef/wiki/Compilers/ 72NOTE that SLANG_VC holds the compiler version - not just 1 or 0 73*/ 74#if defined(_MSC_VER ) 75#if _MSC_VER >=1900 76#define SLANG_VC 14 77#elif _MSC_VER >=1800 78#define SLANG_VC 12 79#elif _MSC_VER >=1700 80#define SLANG_VC 11 81#elif _MSC_VER >=1600 82#define SLANG_VC 10 83#elif _MSC_VER >=1500 84#define SLANG_VC 9 85#else 86#error "unknown version of Visual C++ compiler" 87#endif 88#elif defined(__clang__ ) 89#define SLANG_CLANG 1 90#elif defined(__SNC__ ) 91#define SLANG_SNC 1 92#elif defined(__ghs__ ) 93#define SLANG_GHS 1 94#elif defined(__GNUC__ )/* note: __clang__, __SNC__, or __ghs__ imply __GNUC__ */ 95#define SLANG_GCC 1 96#else 97#error "unknown compiler" 98#endif 99/* 100Any compilers not detected by the above logic are now now explicitly zeroed out. 101*/ 102#ifndef SLANG_VC 103#define SLANG_VC 0 104#endif 105#ifndef SLANG_CLANG 106#define SLANG_CLANG 0 107#endif 108#ifndef SLANG_SNC 109#define SLANG_SNC 0 110#endif 111#ifndef SLANG_GHS 112#define SLANG_GHS 0 113#endif 114#ifndef SLANG_GCC 115#define SLANG_GCC 0 116#endif 117#endif /* SLANG_COMPILER */ 118 119/* 120The following section attempts to detect the target platform being compiled for. 121 122If an application defines `SLANG_PLATFORM` before including this header, 123they take responsibility for setting any compiler-dependent macros 124used later in the file. 125 126Most applications should not need to touch this section. 127*/ 128#ifndef SLANG_PLATFORM 129#define SLANG_PLATFORM 130/** 131Operating system defines, see http://sourceforge.net/p/predef/wiki/OperatingSystems/ 132*/ 133#if defined(WINAPI_FAMILY )&& WINAPI_FAMILY == WINAPI_PARTITION_APP 134#define SLANG_WINRT 1/* Windows Runtime, either on Windows RT or Windows 8 */ 135#elif defined(XBOXONE ) 136#define SLANG_XBOXONE 1 137#elif defined(_WIN64 )/* note: XBOXONE implies _WIN64 */ 138#define SLANG_WIN64 1 139#elif defined(_M_PPC ) 140#define SLANG_X360 1 141#elif defined(_WIN32 )/* note: _M_PPC implies _WIN32 */ 142#define SLANG_WIN32 1 143#elif defined(__ANDROID__ ) 144#define SLANG_ANDROID 1 145#elif defined(__linux__ )|| defined(__CYGWIN__ )/* note: __ANDROID__ implies __linux__ */ 146#define SLANG_LINUX 1 147#elif defined(__APPLE__ )&& !defined(SLANG_LLVM ) 148#include "TargetConditionals.h" 149#if TARGET_OS_MAC 150#define SLANG_OSX 1 151#else 152#define SLANG_IOS 1 153#endif 154#elif defined(__APPLE__ ) 155// On `slang-llvm` we can't inclue "TargetConditionals.h" in general, so for now assume its 156// OSX. 157#define SLANG_OSX 1 158#elif defined(__CELLOS_LV2__ ) 159#define SLANG_PS3 1 160#elif defined(__ORBIS__ ) 161#define SLANG_PS4 1 162#elif defined(__SNC__ )&& defined(__arm__ ) 163#define SLANG_PSP2 1 164#elif defined(__ghs__ ) 165#define SLANG_WIIU 1 166#else 167#error "unknown target platform" 168#endif 169 170 171/* 172Any platforms not detected by the above logic are now now explicitly zeroed out. 173*/ 174#ifndef SLANG_WINRT 175#define SLANG_WINRT 0 176#endif 177#ifndef SLANG_XBOXONE 178#define SLANG_XBOXONE 0 179#endif 180#ifndef SLANG_WIN64 181#define SLANG_WIN64 0 182#endif 183#ifndef SLANG_X360 184#define SLANG_X360 0 185#endif 186#ifndef SLANG_WIN32 187#define SLANG_WIN32 0 188#endif 189#ifndef SLANG_ANDROID 190#define SLANG_ANDROID 0 191#endif 192#ifndef SLANG_LINUX 193#define SLANG_LINUX 0 194#endif 195#ifndef SLANG_IOS 196#define SLANG_IOS 0 197#endif 198#ifndef SLANG_OSX 199#define SLANG_OSX 0 200#endif 201#ifndef SLANG_PS3 202#define SLANG_PS3 0 203#endif 204#ifndef SLANG_PS4 205#define SLANG_PS4 0 206#endif 207#ifndef SLANG_PSP2 208#define SLANG_PSP2 0 209#endif 210#ifndef SLANG_WIIU 211#define SLANG_WIIU 0 212#endif 213#endif /* SLANG_PLATFORM */ 214 215/* Shorthands for "families" of compilers/platforms */ 216#define SLANG_GCC_FAMILY (SLANG_CLANG || SLANG_SNC || SLANG_GHS || SLANG_GCC) 217#define SLANG_WINDOWS_FAMILY (SLANG_WINRT || SLANG_WIN32 || SLANG_WIN64) 218#define SLANG_MICROSOFT_FAMILY (SLANG_XBOXONE || SLANG_X360 || SLANG_WINDOWS_FAMILY) 219#define SLANG_LINUX_FAMILY (SLANG_LINUX || SLANG_ANDROID) 220#define SLANG_APPLE_FAMILY (SLANG_IOS || SLANG_OSX)/* equivalent to #if __APPLE__ */ 221#define SLANG_UNIX_FAMILY \ 222 (SLANG_LINUX_FAMILY || SLANG_APPLE_FAMILY)/* shortcut for unix/posix platforms */ 223 224// GCC Specific 225#if SLANG_GCC_FAMILY 226 227#if INTPTR_MAX == INT64_MAX 228#define SLANG_64BIT 1 229#else 230#define SLANG_64BIT 0 231#endif 232 233#define SLANG_BREAKPOINT (id ) __builtin_trap() 234 235// Use this macro instead of offsetof, because gcc produces warning if offsetof is used on a 236// non POD type, even though it produces the correct result 237#define SLANG_OFFSET_OF (T ,ELEMENT ) (size_t(&((T*)1)->ELEMENT) - 1) 238#endif // SLANG_GCC_FAMILY 239 240// Microsoft VC specific 241#if SLANG_VC 242 243#define SLANG_BREAKPOINT (id ) __debugbreak(); 244 245#endif // SLANG_VC 246 247// Default impls 248 249#ifndef SLANG_OFFSET_OF 250#define SLANG_OFFSET_OF (X ,Y ) offsetof(X, Y) 251#endif 252 253#ifndef SLANG_BREAKPOINT 254// Make it crash with a write to 0! 255#define SLANG_BREAKPOINT (id ) (*((int*)0) = int(id)); 256#endif 257 258// If slang.h has been included we don't need any of these definitions 259#ifndef SLANG_H 260 261/* Macro for declaring if a method is no throw. Should be set before the return parameter. */ 262#ifndef SLANG_NO_THROW 263#if SLANG_WINDOWS_FAMILY && !defined(SLANG_DISABLE_EXCEPTIONS ) 264#define SLANG_NO_THROW __declspec(nothrow) 265#endif 266#endif 267#ifndef SLANG_NO_THROW 268#define SLANG_NO_THROW 269#endif 270 271/* The `SLANG_STDCALL` and `SLANG_MCALL` defines are used to set the calling 272convention for interface methods. 273*/ 274#ifndef SLANG_STDCALL 275#if SLANG_MICROSOFT_FAMILY 276#define SLANG_STDCALL __stdcall 277#else 278#define SLANG_STDCALL 279#endif 280#endif 281#ifndef SLANG_MCALL 282#define SLANG_MCALL SLANG_STDCALL 283#endif 284 285#ifndef SLANG_FORCE_INLINE 286#define SLANG_FORCE_INLINE inline 287#endif 288 289// TODO(JS): Should these be in slang-cpp-types.h? 290// They are more likely to clash with slang.h 291 292struct SlangUUID 293{ 294uint32_t data1 ; 295uint16_t data2 ; 296uint16_t data3 ; 297uint8_t data4 [8 ]; 298}; 299 300typedef int32_t SlangResult ; 301 302struct ISlangUnknown 303{ 304virtual SLANG_NO_THROW SlangResult SLANG_MCALL 305queryInterface (SlangUUID const & uuid ,void ** outObject )= 0 ; 306virtual SLANG_NO_THROW uint32_t SLANG_MCALL addRef ()= 0 ; 307virtual SLANG_NO_THROW uint32_t SLANG_MCALL release ()= 0 ; 308}; 309 310#define SLANG_COM_INTERFACE (a ,b ,c ,d0 ,d1 ,d2 ,d3 ,d4 ,d5 ,d6 ,d7 ) \ 311public: \ 312 SLANG_FORCE_INLINE static const SlangUUID& getTypeGuid() \ 313 { \ 314 static const SlangUUID guid = {a, b, c, d0, d1, d2, d3, d4, d5, d6, d7}; \ 315 return guid; \ 316 } 317#endif // SLANG_H 318 319// Includes 320 321#include "slang-cpp-scalar-intrinsics.h" 322#include "slang-cpp-types.h" 323 324// TODO(JS): Hack! Output C++ code from slang can copy uninitialized variables. 325#if defined(_MSC_VER ) 326#pragma warning(disable : 4700) 327#endif 328 329#ifndef SLANG_UNROLL 330#define SLANG_UNROLL 331#endif 332 333#endif