summaryrefslogtreecommitdiff
path: root/tools/slang-test/render-api-util.h
blob: 0f941f05de0e8be6c8cacea4ba666b4d217f8f50 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#ifndef SLANG_RENDER_API_UTIL_H
#define SLANG_RENDER_API_UTIL_H

#include "../../source/core/slang-string.h"
#include "../../source/core/slang-result.h"


enum class RenderApiType
{
    Unknown = -1,
    OpenGl = 0,
    Vulkan,
    D3D12,
    D3D11,
    CountOf,
};

// Use a struct wrapped Enum instead of enum class, cos we want to be able to manipulate as integrals
struct RenderApiFlag
{
    enum Enum
    {
        OpenGl = 1 << int(RenderApiType::OpenGl),
        Vulkan = 1 << int(RenderApiType::Vulkan),
        D3D12 = 1 << int(RenderApiType::D3D12),
        D3D11 = 1 << int(RenderApiType::D3D11),
        AllOf = (1 << int(RenderApiType::CountOf)) - 1                   ///< All bits set
    };
};

struct RenderApiUtil
{
    struct Info
    {
        RenderApiType type;               ///< The type
        const char* names;          ///< Comma separated list of names associated with the type
    };

        /// Returns true if the API is available. 
    static bool calcHasApi(RenderApiType type);

        /// Returns a combination of RenderApiFlag bits which if set indicates that the API is available.
    static int getAvailableApis();

        /// Returns -1 if unknown
    static RenderApiType findApiTypeByName(const Slang::UnownedStringSlice& name);
        /// Returns 0 if none found.
    static int findApiFlagsByName(const Slang::UnownedStringSlice& name);

        /// Parse api flags string (comma delimited list of api names, or 'all' for all)
        /// For example "all,-dx12" would be all apis, except dx12
    static Slang::Result parseApiFlags(const Slang::UnownedStringSlice& text, int* apiBitsOut);

        /// Get information about a render API
    static const Info& getInfo(RenderApiType type) { return s_infos[int(type)]; }

        /// Static information about each render api
    static const Info s_infos[int(RenderApiType::CountOf)];
};

#endif // SLANG_RENDER_API_UTIL_H