yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
f65d756bf
master
1#ifndef SLANG_CORE_RENDER_API_UTIL_H 2#define SLANG_CORE_RENDER_API_UTIL_H 3 4#include "../../source/core/slang-string.h" 5#include "slang-com-helper.h" 6 7namespace Slang 8{ 9 10enum class RenderApiType 11{ 12Unknown = -1 , 13Vulkan = 0 , 14D3D12 , 15D3D11 , 16Metal , 17CPU , 18CUDA , 19WebGPU , 20CountOf , 21}; 22 23// Use a struct wrapped Enum instead of enum class, cos we want to be able to manipulate as 24// integrals 25struct RenderApiFlag 26{ 27enum Enum 28 { 29Vulkan = 1 <<int (RenderApiType ::Vulkan ), 30D3D12 = 1 <<int (RenderApiType ::D3D12 ), 31D3D11 = 1 <<int (RenderApiType ::D3D11 ), 32Metal = 1 <<int (RenderApiType ::Metal ), 33CPU = 1 <<int (RenderApiType ::CPU ), 34CUDA = 1 <<int (RenderApiType ::CUDA ), 35WebGPU = 1 <<int (RenderApiType ::WebGPU ), 36AllOf = (1 <<int (RenderApiType ::CountOf ))- 1 ///< All bits set 37 }; 38}; 39typedef uint32_t RenderApiFlags ; 40 41struct RenderApiUtil 42{ 43struct Info 44 { 45RenderApiType type ;///< The type 46const char * names ;///< Comma separated list of names associated with the type 47const char * languageNames ;///< Comma separated list of target language names associated 48///< with the type 49 }; 50 51/// Returns true if the API is available. 52static bool calcHasApi (RenderApiType type ); 53 54/// Returns a combination of RenderApiFlag bits which if set indicates that the API is 55/// available. 56static int getAvailableApis (); 57 58/// Get the name 59static UnownedStringSlice getApiName (RenderApiType type ); 60 61/// Returns RenderApiType::Unknown if not found 62static RenderApiType findApiTypeByName (const Slang ::UnownedStringSlice & name ); 63/// FlagsOut will have flag/flags specified by a name if returns with successful result code. 64static Slang ::Result findApiFlagsByName ( 65const Slang ::UnownedStringSlice & name , 66RenderApiFlags * flagsOut ); 67 68/// Parse api flags string, returning SLANG_OK on success. 69/// If first character is + or - the flags will be applied to initialFlags, else initialFlags is 70/// ignored. For example "all-dx12" would be all apis, except dx12 -vk would be whatever is in 71/// initial flags, but not vulkan. 72static Slang ::Result parseApiFlags ( 73const Slang ::UnownedStringSlice & text , 74RenderApiFlags initialFlags , 75RenderApiFlags * apiBitsOut ); 76 77/// Gets the API type from a string, or returns RenderApiType::Unknown if not found 78static RenderApiType findRenderApiType (const Slang ::UnownedStringSlice & text ); 79 80static RenderApiType findImplicitLanguageRenderApiType (const Slang ::UnownedStringSlice & text ); 81 82/// Get information about a render API 83static const Info & getInfo (RenderApiType type ) {return s_infos [int (type )]; } 84 85/// Static information about each render api 86static const Info s_infos [int (RenderApiType ::CountOf )]; 87}; 88 89}// namespace Slang 90 91#endif // SLANG_RENDER_API_UTIL_H