yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Ellie Hermaszewskaformatf65d756bf

master
2.9 KiB91 linesraw
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{
12    Unknown = -1,
13    Vulkan = 0,
14    D3D12,
15    D3D11,
16    Metal,
17    CPU,
18    CUDA,
19    WebGPU,
20    CountOf,
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{
27    enum Enum
28    {
29        Vulkan = 1 << int(RenderApiType::Vulkan),
30        D3D12 = 1 << int(RenderApiType::D3D12),
31        D3D11 = 1 << int(RenderApiType::D3D11),
32        Metal = 1 << int(RenderApiType::Metal),
33        CPU = 1 << int(RenderApiType::CPU),
34        CUDA = 1 << int(RenderApiType::CUDA),
35        WebGPU = 1 << int(RenderApiType::WebGPU),
36        AllOf = (1 << int(RenderApiType::CountOf)) - 1 ///< All bits set
37    };
38};
39typedef uint32_t RenderApiFlags;
40
41struct RenderApiUtil
42{
43    struct Info
44    {
45        RenderApiType type;        ///< The type
46        const char* names;         ///< Comma separated list of names associated with the type
47        const char* languageNames; ///< Comma separated list of target language names associated
48                                   ///< with the type
49    };
50
51    /// Returns true if the API is available.
52    static bool calcHasApi(RenderApiType type);
53
54    /// Returns a combination of RenderApiFlag bits which if set indicates that the API is
55    /// available.
56    static int getAvailableApis();
57
58    /// Get the name
59    static UnownedStringSlice getApiName(RenderApiType type);
60
61    /// Returns RenderApiType::Unknown if not found
62    static RenderApiType findApiTypeByName(const Slang::UnownedStringSlice& name);
63    /// FlagsOut will have flag/flags specified by a name if returns with successful result code.
64    static Slang::Result findApiFlagsByName(
65        const Slang::UnownedStringSlice& name,
66        RenderApiFlags* 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.
72    static Slang::Result parseApiFlags(
73        const Slang::UnownedStringSlice& text,
74        RenderApiFlags initialFlags,
75        RenderApiFlags* apiBitsOut);
76
77    /// Gets the API type from a string, or returns RenderApiType::Unknown if not found
78    static RenderApiType findRenderApiType(const Slang::UnownedStringSlice& text);
79
80    static RenderApiType findImplicitLanguageRenderApiType(const Slang::UnownedStringSlice& text);
81
82    /// Get information about a render API
83    static const Info& getInfo(RenderApiType type) { return s_infos[int(type)]; }
84
85    /// Static information about each render api
86    static const Info s_infos[int(RenderApiType::CountOf)];
87};
88
89} // namespace Slang
90
91#endif // SLANG_RENDER_API_UTIL_H