CInterface: replaced tabs with spaces
[platform/upstream/glslang.git] / glslang / Include / glslang_c_interface.h
1 /**
2     This code is based on the glslang_c_interface implementation by Viktor Latypov
3 **/
4
5 /**
6 BSD 2-Clause License
7
8 Copyright (c) 2019, Viktor Latypov
9 All rights reserved.
10
11 Redistribution and use in source and binary forms, with or without
12 modification, are permitted provided that the following conditions are met:
13
14 1. Redistributions of source code must retain the above copyright notice, this
15    list of conditions and the following disclaimer.
16
17 2. Redistributions in binary form must reproduce the above copyright notice,
18    this list of conditions and the following disclaimer in the documentation
19    and/or other materials provided with the distribution.
20
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 **/
32
33 #ifndef GLSLANG_C_IFACE_H_INCLUDED
34 #define GLSLANG_C_IFACE_H_INCLUDED
35
36 #include <stdlib.h>
37
38 #include "glslang_c_shader_types.h"
39
40 typedef struct glslang_shader_s glslang_shader_t;
41 typedef struct glslang_program_s glslang_program_t;
42
43 typedef struct glslang_input_s {
44     glslang_source_t language;
45     glslang_stage_t stage;
46     glslang_client_t client;
47     glslang_target_client_version_t client_version;
48     glslang_target_language_t target_language;
49     glslang_target_language_version_t target_language_version;
50     /** Shader source code */
51     const char* code;
52     int default_version;
53     glslang_profile_t default_profile;
54     int force_default_version_and_profile;
55     int forward_compatible;
56     glslang_messages_t messages;
57 } glslang_input_t;
58
59 /* Inclusion result structure allocated by C include_local/include_system callbacks */
60 typedef struct glsl_include_result_s {
61     /* Header file name or NULL if inclusion failed */
62     const char* header_name;
63
64     /* Header contents or NULL */
65     const char* header_data;
66     size_t header_length;
67
68 } glsl_include_result_t;
69
70 /* Callback for local file inclusion */
71 typedef glsl_include_result_t* (*glsl_include_local_func)(void* ctx, const char* header_name, const char* includer_name,
72                                                           size_t include_depth);
73
74 /* Callback for system file inclusion */
75 typedef glsl_include_result_t* (*glsl_include_system_func)(void* ctx, const char* header_name,
76                                                            const char* includer_name, size_t include_depth);
77
78 /* Callback for include result destruction */
79 typedef int (*glsl_free_include_result_func)(void* ctx, glsl_include_result_t* result);
80
81 /* Collection of callbacks for GLSL preprocessor */
82 typedef struct glsl_include_callbacks_s {
83     glsl_include_system_func include_system;
84     glsl_include_local_func include_local;
85     glsl_free_include_result_func free_include_result;
86 } glsl_include_callbacks_t;
87
88 #ifdef __cplusplus
89 extern "C" {
90 #endif
91
92 int glslang_initialize_process();
93 void glslang_finalize_process();
94
95 glslang_shader_t* glslang_shader_create(const glslang_input_t* input);
96 void glslang_shader_delete(glslang_shader_t* shader);
97 int glslang_shader_preprocess(glslang_shader_t* shader, const glslang_input_t* input);
98 int glslang_shader_parse(glslang_shader_t* shader, const glslang_input_t* input);
99 const char* glslang_shader_get_preprocessed_code(glslang_shader_t* shader);
100 const char* glslang_shader_get_info_log(glslang_shader_t* shader);
101 const char* glslang_shader_get_info_debug_log(glslang_shader_t* shader);
102
103 glslang_program_t* glslang_program_create();
104 void glslang_program_delete(glslang_program_t* program);
105 void glslang_program_add_shader(glslang_program_t* program, glslang_shader_t* shader);
106 int glslang_program_link(glslang_program_t* program, int messages); // glslang_messages_t
107 void glslang_program_SPIRV_generate(glslang_program_t* program, glslang_stage_t stage);
108 size_t glslang_program_SPIRV_get_size(glslang_program_t* program);
109 void glslang_program_SPIRV_get(glslang_program_t* program, unsigned int*);
110 unsigned int* glslang_program_SPIRV_get_ptr(glslang_program_t* program);
111 const char* glslang_program_SPIRV_get_messages(glslang_program_t* program);
112 const char* glslang_program_get_info_log(glslang_program_t* program);
113 const char* glslang_program_get_info_debug_log(glslang_program_t* program);
114
115 #ifdef __cplusplus
116 }
117 #endif
118
119 #endif /* #ifdef GLSLANG_C_IFACE_INCLUDED */