spirv.h 1.89 KB
Newer Older
Niklas Haas's avatar
Niklas Haas committed
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
/*
 * 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/>.
 */

#pragma once

#include "common.h"
#include "context.h"

enum glsl_shader_stage {
    GLSL_SHADER_VERTEX,
    GLSL_SHADER_FRAGMENT,
    GLSL_SHADER_COMPUTE,
};

#define SPIRV_NAME_MAX_LEN 32

struct spirv_compiler {
    char name[SPIRV_NAME_MAX_LEN]; // for cache invalidation
    struct pl_context *ctx;
    const struct spirv_compiler_fns *impl;

    // implementation-specific fields
    void *priv;
38
    struct pl_glsl_desc glsl;      // supported GLSL capabilities
Niklas Haas's avatar
Niklas Haas committed
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
    int compiler_version;          // for cache invalidation, may be left as 0
};

struct spirv_compiler_fns {
    const char *name;

    // Compile GLSL to SPIR-V, under GL_KHR_vulkan_glsl semantics.
    bool (*compile_glsl)(struct spirv_compiler *spirv, void *tactx,
                         enum glsl_shader_stage type, const char *glsl,
                         struct bstr *out_spirv);

    // Only needs to initialize the implementation-specific fields
    bool (*init)(struct spirv_compiler *spirv);
    void (*uninit)(struct spirv_compiler *spirv);
};

// Initialize a SPIR-V compiler instance, or returns NULL on failure.
struct spirv_compiler *spirv_compiler_create(struct pl_context *ctx);
void spirv_compiler_destroy(struct spirv_compiler **spirv);