summaryrefslogtreecommitdiff
path: root/tools/render-test/slang-support.h
blob: 916166c3a878e7c5cc71f952cf520a7133b4bddd (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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// slang-support.h
#pragma once

#include "options.h"
#include "shader-input-layout.h"
#include "slang.h"

#include <slang-rhi.h>

namespace renderer_test
{

struct ShaderCompileRequest
{
    struct SourceInfo
    {
        char const* path;

        // The data may either be source text (in which
        // case it can be assumed to be nul-terminated with
        // `dataEnd` pointing at the terminator), or
        // raw binary data (in which case `dataEnd` points
        // at the end of the buffer).
        char const* dataBegin;
        char const* dataEnd;
    };

    struct EntryPoint
    {
        char const* name = nullptr;
        SlangStage slangStage;
    };

    struct TypeConformance
    {
    public:
        Slang::String derivedTypeName;
        Slang::String baseTypeName;
        Slang::Int idOverride;
    };

    SourceInfo source;
    Slang::List<EntryPoint> entryPoints;

    Slang::List<Slang::String> globalSpecializationArgs;
    Slang::List<Slang::String> entryPointSpecializationArgs;
    Slang::List<TypeConformance> typeConformances;
};


struct ShaderCompilerUtil
{
    struct Input
    {
        SlangCompileTarget target;
        SlangSourceLanguage sourceLanguage;
        SlangPassThrough passThrough;
        Slang::String profile;
    };

    struct Output
    {
        void set(slang::IComponentType* slangProgram);
        void reset();
        ~Output() { reset(); }

        ComPtr<slang::IComponentType> slangProgram;
        ShaderProgramDesc desc = {};

        ComPtr<slang::ISession> m_session = nullptr;

        slang::IGlobalSession* globalSession = nullptr;
    };

    struct OutputAndLayout
    {
        Output output;
        ShaderInputLayout layout;
        Slang::String sourcePath;
    };

    // Wrapper for compileProgram
    static SlangResult compileWithLayout(
        slang::IGlobalSession* globalSession,
        const Options& options,
        const ShaderCompilerUtil::Input& input,
        OutputAndLayout& output);
};


} // namespace renderer_test