updated some printfs, added comment about sched_yield
[mesa.git] / src / mesa / shader / slang / Public / ShaderLang.h
1 /*
2 //Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
3 //All rights reserved.
4 //
5 //Redistribution and use in source and binary forms, with or without
6 //modification, are permitted provided that the following conditions
7 //are met:
8 //
9 // Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 //
12 // Redistributions in binary form must reproduce the above
13 // copyright notice, this list of conditions and the following
14 // disclaimer in the documentation and/or other materials provided
15 // with the distribution.
16 //
17 // Neither the name of 3Dlabs Inc. Ltd. nor the names of its
18 // contributors may be used to endorse or promote products derived
19 // from this software without specific prior written permission.
20 //
21 //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 //"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 //LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 //FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 //COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 //INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 //BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 //LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 //CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 //LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 //ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 //POSSIBILITY OF SUCH DAMAGE.
33 */
34 #ifndef _COMPILER_INTERFACE_INCLUDED_
35 #define _COMPILER_INTERFACE_INCLUDED_
36
37 #include "../Include/ResourceLimits.h"
38
39 #ifdef _WIN32
40 #define C_DECL __cdecl
41 /*#ifdef SH_EXPORTING
42 #define SH_IMPORT_EXPORT __declspec(dllexport)
43 #else
44 #define SH_IMPORT_EXPORT __declspec(dllimport)
45 #endif*/
46 /* disable DLL linking */
47 #define SH_IMPORT_EXPORT
48 #else
49 #define SH_IMPORT_EXPORT
50 #define __fastcall
51 #define C_DECL
52 #endif
53
54 /*
55 // This is the platform independent interface between an OGL driver
56 // and the shading language compiler/linker.
57 */
58
59 #ifdef __cplusplus
60 extern "C" {
61 #endif
62
63 /*
64 // Driver must call this first, once, before doing any other
65 // compiler/linker operations.
66 */
67 SH_IMPORT_EXPORT int ShInitialize();
68 /*
69 // Driver should call this at shutdown.
70 */
71 SH_IMPORT_EXPORT int __fastcall ShFinalize();
72
73 /*
74 // Types of languages the compiler can consume.
75 */
76 typedef enum {
77 EShLangVertex,
78 EShLangFragment,
79 EShLangPack,
80 EShLangUnpack,
81 EShLangCount
82 } EShLanguage;
83
84 /*
85 // Types of output the linker will create.
86 */
87 typedef enum {
88 EShExVertexFragment,
89 EShExPackFragment,
90 EShExUnpackFragment,
91 EShExFragment
92 } EShExecutable;
93
94 /*
95 // Optimization level for the compiler.
96 */
97 typedef enum {
98 EShOptNoGeneration,
99 EShOptNone,
100 EShOptSimple, /* Optimizations that can be done quickly */
101 EShOptFull /* Optimizations that will take more time */
102 } EShOptimizationLevel;
103
104 /*
105 // Build a table for bindings. This can be used for locating
106 // attributes, uniforms, globals, etc., as needed.
107 */
108 typedef struct {
109 char* name;
110 int binding;
111 } ShBinding;
112
113 typedef struct {
114 int numBindings;
115 ShBinding* bindings; /* array of bindings */
116 } ShBindingTable;
117
118 /*
119 // ShHandle held by but opaque to the driver. It is allocated,
120 // managed, and de-allocated by the compiler/linker. It's contents
121 // are defined by and used by the compiler and linker. For example,
122 // symbol table information and object code passed from the compiler
123 // to the linker can be stored where ShHandle points.
124 //
125 // If handle creation fails, 0 will be returned.
126 */
127 typedef void* ShHandle;
128
129 /*
130 // Driver calls these to create and destroy compiler/linker
131 // objects.
132 */
133 SH_IMPORT_EXPORT ShHandle ShConstructCompiler(const EShLanguage, int debugOptions); /* one per shader */
134 SH_IMPORT_EXPORT ShHandle ShConstructLinker(const EShExecutable, int debugOptions); /* one per shader pair */
135 SH_IMPORT_EXPORT ShHandle ShConstructUniformMap(); /* one per uniform namespace (currently entire program object) */
136 SH_IMPORT_EXPORT void ShDestruct(ShHandle);
137
138 /*
139 // The return value of ShCompile is boolean, indicating
140 // success or failure.
141 //
142 // The info-log should be written by ShCompile into
143 // ShHandle, so it can answer future queries.
144 */
145 SH_IMPORT_EXPORT int ShCompile(
146 const ShHandle,
147 const char* const shaderStrings[],
148 const int numStrings,
149 const EShOptimizationLevel,
150 const TBuiltInResource *resources,
151 int debugOptions
152 );
153
154
155 /*
156 // Similar to ShCompile, but accepts an opaque handle to an
157 // intermediate language structure.
158 */
159 SH_IMPORT_EXPORT int ShCompileIntermediate(
160 ShHandle compiler,
161 ShHandle intermediate,
162 const EShOptimizationLevel,
163 int debuggable /* boolean */
164 );
165
166 SH_IMPORT_EXPORT int ShLink(
167 const ShHandle, /* linker object */
168 const ShHandle h[], /* compiler objects to link together */
169 const int numHandles,
170 ShHandle uniformMap, /* updated with new uniforms */
171 short int** uniformsAccessed, /* returned with indexes of uniforms accessed */
172 int* numUniformsAccessed);
173
174 /*
175 // ShSetEncrpytionMethod is a place-holder for specifying
176 // how source code is encrypted.
177 */
178 SH_IMPORT_EXPORT void ShSetEncryptionMethod(ShHandle);
179
180 /*
181 // All the following return 0 if the information is not
182 // available in the object passed down, or the object is bad.
183 */
184 SH_IMPORT_EXPORT const char* ShGetInfoLog(const ShHandle);
185 SH_IMPORT_EXPORT const void* ShGetExecutable(const ShHandle);
186 SH_IMPORT_EXPORT int ShSetVirtualAttributeBindings(const ShHandle, const ShBindingTable*); /* to detect user aliasing */
187 SH_IMPORT_EXPORT int ShSetFixedAttributeBindings(const ShHandle, const ShBindingTable*); /* to force any physical mappings */
188 SH_IMPORT_EXPORT int ShGetPhysicalAttributeBindings(const ShHandle, const ShBindingTable**); /* for all attributes */
189 /*
190 // Tell the linker to never assign a vertex attribute to this list of physical attributes
191 */
192 SH_IMPORT_EXPORT int ShExcludeAttributes(const ShHandle, int *attributes, int count);
193
194 /*
195 // Returns the location ID of the named uniform.
196 // Returns -1 if error.
197 */
198 SH_IMPORT_EXPORT int ShGetUniformLocation(const ShHandle uniformMap, const char* name);
199
200 enum TDebugOptions {
201 EDebugOpNone = 0x000,
202 EDebugOpIntermediate = 0x001,
203 EDebugOpAssembly = 0x002,
204 EDebugOpObjectCode = 0x004,
205 EDebugOpLinkMaps = 0x008
206 };
207
208 #ifdef __cplusplus
209 }
210 #endif
211
212 #endif /* _COMPILER_INTERFACE_INCLUDED_ */