summaryrefslogtreecommitdiff
path: root/tools/render-test/slang-support.h
blob: cd3223c878cdab607bd9f6b392da0c99138dcb61 (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
// slang-support.h
#pragma once

#include "render.h"

#include <slang.h>

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

namespace renderer_test {

struct ShaderCompilerUtil
{
    struct Input
    {
        SlangCompileTarget      target;
        SlangSourceLanguage     sourceLanguage;
        SlangPassThrough        passThrough;
        char const*             profile;
        const char**            args;
        int                     argCount;
    };

    struct Output
    {
        void set(PipelineType pipelineType, const ShaderProgram::KernelDesc* inKernelDescs, int kernelDescCount)
        {
            kernelDescs.clear();
            kernelDescs.addRange(inKernelDescs, kernelDescCount);
            desc.pipelineType = pipelineType;
            desc.kernels = kernelDescs.getBuffer();
            desc.kernelCount = kernelDescCount;
        }
        void reset()
        {
            {
                desc.pipelineType = PipelineType::Unknown;
                desc.kernels = nullptr;
                desc.kernelCount = 0;
            }

            kernelDescs.clear();
            if (request && session)
            {
                spDestroyCompileRequest(request);
            }
            session = nullptr;
            request = nullptr;
        }
        ~Output()
        {
            if (request && session)
            {
                 spDestroyCompileRequest(request);
            }
        }
        List<ShaderProgram::KernelDesc> kernelDescs;
        ShaderProgram::Desc desc;
        SlangCompileRequest* request = nullptr;
        SlangSession* session = nullptr;

    };

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

    static SlangResult compileWithLayout(SlangSession* session, const Slang::String& sourcePath, const Slang::List<Slang::CommandLine::Arg>& compileArgs, Options::ShaderProgramType shaderType, const ShaderCompilerUtil::Input& input, OutputAndLayout& output);

    static SlangResult readSource(const Slang::String& inSourcePath, List<char>& outSourceText);

    static SlangResult compileProgram(SlangSession* session, const Input& input, const ShaderCompileRequest& request, Output& out);
};


} // renderer_test