summaryrefslogtreecommitdiffstats
path: root/src/glsl/spirv.c
blob: 8317ed74730a48ed371e5b865a45028256643cce (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
/*
 * This file is part of libplacebo.
 *
 * libplacebo is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * libplacebo is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with libplacebo. If not, see <http://www.gnu.org/licenses/>.
 */

#include "spirv.h"

extern const struct spirv_compiler pl_spirv_shaderc;
extern const struct spirv_compiler pl_spirv_glslang;

static const struct spirv_compiler *compilers[] = {
#ifdef PL_HAVE_SHADERC
    &pl_spirv_shaderc,
#endif
#ifdef PL_HAVE_GLSLANG
    &pl_spirv_glslang,
#endif
};

pl_spirv pl_spirv_create(pl_log log, struct pl_spirv_version spirv_ver)
{
    for (int i = 0; i < PL_ARRAY_SIZE(compilers); i++) {
        pl_spirv spirv = compilers[i]->create(log, spirv_ver);
        if (!spirv)
            continue;

        pl_info(log, "Initialized SPIR-V compiler '%s'", compilers[i]->name);
        return spirv;
    }

    pl_fatal(log, "Failed initializing any SPIR-V compiler! Maybe libplacebo "
             "was built without support for either libshaderc or glslang?");
    return NULL;
}

void pl_spirv_destroy(pl_spirv *pspirv)
{
    pl_spirv spirv = *pspirv;
    if (!spirv)
        return;

    spirv->impl->destroy(spirv);
    *pspirv = NULL;
}

pl_str pl_spirv_compile_glsl(pl_spirv spirv, void *alloc,
                             struct pl_glsl_version glsl,
                             enum glsl_shader_stage stage,
                             const char *shader)
{
    return spirv->impl->compile(spirv, alloc, glsl, stage, shader);
}