yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
368ddbb7b
master
1// slang-platform.h 2#ifndef SLANG_CORE_PLATFORM_H 3#define SLANG_CORE_PLATFORM_H 4 5#include "../core/slang-string.h" 6#include "slang.h" 7 8namespace Slang 9{ 10enum class PlatformKind :uint8_t 11{ 12Unknown , 13WinRT , 14XBoxOne , 15Win64 , 16Win32 , 17X360 , 18Android , 19Linux , 20IOS , 21OSX , 22PS3 , 23PS4 , 24PSP2 , 25WIIU , 26CountOf , 27}; 28 29typedef uint32_t PlatformFlags ; 30struct PlatformFlag 31{ 32enum Enum 33 { 34Unknown = 1 <<int (PlatformKind ::Unknown ), 35WinRT = 1 <<int (PlatformKind ::WinRT ), 36XBoxOne = 1 <<int (PlatformKind ::XBoxOne ), 37Win64 = 1 <<int (PlatformKind ::Win64 ), 38Win32 = 1 <<int (PlatformKind ::Win32 ), 39X360 = 1 <<int (PlatformKind ::X360 ), 40Android = 1 <<int (PlatformKind ::Android ), 41Linux = 1 <<int (PlatformKind ::Linux ), 42IOS = 1 <<int (PlatformKind ::IOS ), 43OSX = 1 <<int (PlatformKind ::OSX ), 44PS3 = 1 <<int (PlatformKind ::PS3 ), 45PS4 = 1 <<int (PlatformKind ::PS4 ), 46PSP2 = 1 <<int (PlatformKind ::PSP2 ), 47WIIU = 1 <<int (PlatformKind ::WIIU ), 48 }; 49}; 50 51enum class PlatformFamily :uint8_t 52{ 53Unknown , 54Windows , 55Microsoft , 56Linux , 57Apple , 58Unix , 59CountOf , 60}; 61 62// Interface for working with shared libraries 63// in a platform-independent fashion. 64struct SharedLibrary 65{ 66typedef struct SharedLibraryImpl * Handle ; 67 68typedef void (* FuncPtr )(void ); 69 70/// Load via an unadorned path/filename. 71/// 72/// The unadorned path here means without a path without any platform specific filename 73/// elements. This typically means no extension and no prefix. On windows this means without the 74/// '.dll' extension. On linux this means without the 'lib' prefix and '.so' extension. To load 75/// with a platform specific filename use the 'loadWithPlatformFilename' API Most platforms have 76/// a built in mechanism to search for shared libraries, such that shared libraries are often 77/// just passed by filename. 78/// 79/// @param the unadorned filename/path 80/// @return Returns a non null handle for the shared library on success. nullptr indicated 81/// failure 82static SlangResult load (const char * path ,Handle & handleOut ); 83 84/// Attempt to load a shared library for 85/// the current platform. Returns null handle on failure 86/// The platform specific filename can be generated from a call to appendPlatformFileName 87/// 88/// @param platform the platform specific file name/ or path 89/// @return Returns a non null handle for the shared library on success. nullptr indicated 90/// failure 91static SlangResult loadWithPlatformPath (char const * platformPath ,Handle & handleOut ); 92 93/// Unload the library that was returned from load as handle 94/// @param The valid handle returned from load 95static void unload (Handle handle ); 96 97/// Given a shared library handle and a name, return the associated object 98/// Return nullptr if object is not found 99/// @param The shared library handle as returned by loadPlatformLibrary 100static void * findSymbolAddressByName (Handle handle ,char const * name ); 101 102/// Append to the end of dst, the name, with any platform specific additions 103/// The input name should be unadorned with any 'lib' prefix or extension 104static void appendPlatformFileName (const UnownedStringSlice & name ,StringBuilder & dst ); 105 106/// Given a path, calculate that path with the filename replaced with the platform filename 107/// (using appendPlatformFilename) 108static String calcPlatformPath (const UnownedStringSlice & path ); 109static void calcPlatformPath (const UnownedStringSlice & path ,StringBuilder & outBuilder ); 110 111 112private : 113/// Not constructible! 114SharedLibrary (); 115}; 116 117struct PlatformUtil 118{ 119/// Appends a text interpretation of a result (as defined by supporting OS) 120/// @param res Result to produce a string for 121/// @param builderOut Append the string produced to builderOut 122/// @return SLANG_OK if string is found and appended. Fail otherwise. SLANG_E_NOT_IMPLEMENTED if 123/// there is no impl for this platform. 124static SlangResult appendResult (SlangResult res ,StringBuilder & builderOut ); 125 126/// Get the platform kind as determined at compile time 127static PlatformKind getPlatformKind (); 128 129/// Get the platforms that make up a family 130static PlatformFlags getPlatformFlags (PlatformFamily family ); 131 132/// True if the kind is part of the family 133static bool isFamily (PlatformFamily family ,PlatformKind kind ) 134 { 135return (getPlatformFlags (family )& (PlatformFlags (1 ) <<int (kind )))!= 0 ; 136 } 137 138/// Given an environment name returns the set system variable. 139/// Will return SLANG_E_NOT_FOUND if the variable is not set 140static SlangResult getEnvironmentVariable (const UnownedStringSlice & name ,StringBuilder & out ); 141 142/// Get the path to this instance (the path to the dll/executable/shared library the call is in) 143/// NOTE! This is not supported on all platforms, and will return SLANG_E_NOT_IMPLEMENTED in 144/// that scenario 145static SlangResult getInstancePath (StringBuilder & out ); 146 147/// Outputs message to a debug stream. Not all platforms support 148/// this feature. 149/// 150/// @param text Text to be displayed in 'debugger output' 151/// @return SLANG_E_NOT_AVAILABLE if not on this platform, and potentially other errors 152static SlangResult outputDebugMessage (const char * text ); 153 154/// Print a stack trace to stderr for debugging purposes. 155/// Only available on Linux family platforms. 156static void backtrace (); 157}; 158 159#ifndef _MSC_VER 160#define _fileno fileno 161#define _isatty isatty 162#define _setmode setmode 163#define _O_BINARY O_BINARY 164#endif 165}// namespace Slang 166 167#endif