Skip to content

Latest commit

 

History

History
4110 lines (3723 loc) · 157 KB

mojoshader.h

File metadata and controls

4110 lines (3723 loc) · 157 KB
 
Feb 10, 2008
Feb 10, 2008
1
/**
Mar 22, 2008
Mar 22, 2008
2
3
* MojoShader; generate shader programs from bytecode of compiled
* Direct3D shaders.
Feb 10, 2008
Feb 10, 2008
4
5
6
7
8
9
*
* Please see the file LICENSE.txt in the source's root directory.
*
* This file written by Ryan C. Gordon.
*/
Feb 12, 2009
Feb 12, 2009
10
11
#ifndef _INCL_MOJOSHADER_H_
#define _INCL_MOJOSHADER_H_
Feb 10, 2008
Feb 10, 2008
12
13
14
15
16
#ifdef __cplusplus
extern "C" {
#endif
Nov 6, 2008
Nov 6, 2008
17
18
19
/* You can define this if you aren't generating mojoshader_version.h */
#ifndef MOJOSHADER_NO_VERSION_INCLUDE
#include "mojoshader_version.h"
Dec 1, 2008
Dec 1, 2008
20
21
22
#endif
#ifndef MOJOSHADER_VERSION
Nov 6, 2008
Nov 6, 2008
23
#define MOJOSHADER_VERSION -1
Dec 1, 2008
Dec 1, 2008
24
25
26
#endif
#ifndef MOJOSHADER_CHANGESET
Nov 6, 2008
Nov 6, 2008
27
28
29
#define MOJOSHADER_CHANGESET "???"
#endif
Jan 1, 2016
Jan 1, 2016
30
31
32
33
34
35
36
37
38
39
#ifndef DECLSPEC
#ifdef _WIN32
#define DECLSPEC __declspec(dllexport)
#else
#define DECLSPEC
#endif
#endif
#ifndef MOJOSHADERCALL
#ifdef _WIN32
Apr 24, 2020
Apr 24, 2020
40
#define MOJOSHADERCALL __cdecl
Jan 1, 2016
Jan 1, 2016
41
42
43
44
45
#else
#define MOJOSHADERCALL
#endif
#endif
Apr 1, 2020
Apr 1, 2020
46
47
48
49
50
51
52
53
54
/* -Wpedantic nameless union/struct silencing */
#ifndef MOJOSHADERNAMELESS
#ifdef __GNUC__
#define MOJOSHADERNAMELESS __extension__
#else
#define MOJOSHADERNAMELESS
#endif /* __GNUC__ */
#endif /* MOJOSHADERNAMELESS */
Mar 16, 2008
Mar 16, 2008
55
/*
Mar 28, 2008
Mar 28, 2008
56
57
58
59
60
* For determining the version of MojoShader you are using:
* const int compiled_against = MOJOSHADER_VERSION;
* const int linked_against = MOJOSHADER_version();
*
* The version is a single integer that increments, not a major/minor value.
Mar 16, 2008
Mar 16, 2008
61
*/
Jan 1, 2016
Jan 1, 2016
62
DECLSPEC int MOJOSHADER_version(void);
Mar 16, 2008
Mar 16, 2008
63
Nov 6, 2008
Nov 6, 2008
64
/*
Feb 5, 2009
Feb 5, 2009
65
* For determining the revision control changeset of MojoShader you are using:
May 22, 2011
May 22, 2011
66
* const char *compiled_against = MOJOSHADER_CHANGESET;
Nov 6, 2008
Nov 6, 2008
67
68
69
70
71
72
73
74
* const char *linked_against = MOJOSHADER_changeset();
*
* The version is an arbitrary, null-terminated ASCII string. It is probably
* a hash that represents a revision control changeset, and can't be
* compared to any other string to determine chronology.
*
* Do not attempt to free this string; it's statically allocated.
*/
Jan 1, 2016
Jan 1, 2016
75
DECLSPEC const char *MOJOSHADER_changeset(void);
Nov 6, 2008
Nov 6, 2008
76
Mar 16, 2008
Mar 16, 2008
77
78
/*
* These allocators work just like the C runtime's malloc() and free()
Mar 28, 2008
Mar 28, 2008
79
80
* (in fact, they probably use malloc() and free() internally if you don't
* specify your own allocator, but don't rely on that behaviour).
Apr 4, 2008
Apr 4, 2008
81
82
83
* (data) is the pointer you supplied when specifying these allocator
* callbacks, in case you need instance-specific data...it is passed through
* to your allocator unmolested, and can be NULL if you like.
Mar 16, 2008
Mar 16, 2008
84
*/
Jan 1, 2016
Jan 1, 2016
85
86
typedef void *(MOJOSHADERCALL *MOJOSHADER_malloc)(int bytes, void *data);
typedef void (MOJOSHADERCALL *MOJOSHADER_free)(void *ptr, void *data);
Mar 14, 2008
Mar 14, 2008
87
Mar 28, 2008
Mar 28, 2008
88
89
90
91
92
93
94
95
96
97
98
/*
* These are enum values, but they also can be used in bitmasks, so we can
* test if an opcode is acceptable: if (op->shader_types & ourtype) {} ...
*/
typedef enum
{
MOJOSHADER_TYPE_UNKNOWN = 0,
MOJOSHADER_TYPE_PIXEL = (1 << 0),
MOJOSHADER_TYPE_VERTEX = (1 << 1),
MOJOSHADER_TYPE_GEOMETRY = (1 << 2), /* (not supported yet.) */
Apr 1, 2020
Apr 1, 2020
99
MOJOSHADER_TYPE_ANY = 0x7FFFFFFF /* used for bitmasks */
Mar 28, 2008
Mar 28, 2008
100
101
} MOJOSHADER_shaderType;
Apr 26, 2008
Apr 26, 2008
102
103
104
105
106
/*
* Data types for vertex attribute streams.
*/
typedef enum
{
Apr 28, 2008
Apr 28, 2008
107
MOJOSHADER_ATTRIBUTE_UNKNOWN = -1, /* housekeeping; not returned. */
Apr 26, 2008
Apr 26, 2008
108
109
110
111
112
113
114
MOJOSHADER_ATTRIBUTE_BYTE,
MOJOSHADER_ATTRIBUTE_UBYTE,
MOJOSHADER_ATTRIBUTE_SHORT,
MOJOSHADER_ATTRIBUTE_USHORT,
MOJOSHADER_ATTRIBUTE_INT,
MOJOSHADER_ATTRIBUTE_UINT,
MOJOSHADER_ATTRIBUTE_FLOAT,
Apr 28, 2008
Apr 28, 2008
115
MOJOSHADER_ATTRIBUTE_DOUBLE,
Apr 1, 2020
Apr 1, 2020
116
MOJOSHADER_ATTRIBUTE_HALF_FLOAT /* MAYBE available in your OpenGL! */
Apr 26, 2008
Apr 26, 2008
117
118
} MOJOSHADER_attributeType;
Apr 4, 2008
Apr 4, 2008
119
120
121
/*
* Data types for uniforms. See MOJOSHADER_uniform for more information.
*/
Apr 4, 2008
Apr 4, 2008
122
123
typedef enum
{
Apr 28, 2008
Apr 28, 2008
124
MOJOSHADER_UNIFORM_UNKNOWN = -1, /* housekeeping value; never returned. */
Apr 19, 2008
Apr 19, 2008
125
126
MOJOSHADER_UNIFORM_FLOAT,
MOJOSHADER_UNIFORM_INT,
Apr 1, 2020
Apr 1, 2020
127
MOJOSHADER_UNIFORM_BOOL
Apr 4, 2008
Apr 4, 2008
128
} MOJOSHADER_uniformType;
Apr 4, 2008
Apr 4, 2008
129
Apr 4, 2008
Apr 4, 2008
130
131
132
133
134
135
136
/*
* These are the uniforms to be set for a shader. "Uniforms" are what Direct3D
* calls "Constants" ... IDirect3DDevice::SetVertexShaderConstantF() would
* need this data, for example. These integers are register indexes. So if
* index==6 and type==MOJOSHADER_UNIFORM_FLOAT, that means we'd expect a
* 4-float vector to be specified for what would be register "c6" in D3D
* assembly language, before drawing with the shader.
May 5, 2008
May 5, 2008
137
138
139
140
141
142
143
144
* (array_count) means this is an array of uniforms...this happens in some
* profiles when we see a relative address ("c0[a0.x]", not the usual "c0").
* In those cases, the shader was built to set some range of constant
* registers as an array. You should set this array with (array_count)
* elements from the constant register file, starting at (index) instead of
* just a single uniform. To be extra difficult, you'll need to fill in the
* correct values from the MOJOSHADER_constant data into the appropriate
* parts of the array, overriding the constant register file. Fun!
Jul 31, 2008
Jul 31, 2008
145
146
147
148
* (constant) says whether this is a constant array; these need to be loaded
* once at creation time, from the constant list and not ever updated from
* the constant register file. This is a workaround for limitations in some
* profiles.
Apr 25, 2008
Apr 25, 2008
149
150
* (name) is a profile-specific variable name; it may be NULL if it isn't
* applicable to the requested profile.
Apr 4, 2008
Apr 4, 2008
151
*/
Dec 1, 2008
Dec 1, 2008
152
typedef struct MOJOSHADER_uniform
Apr 4, 2008
Apr 4, 2008
153
{
Apr 4, 2008
Apr 4, 2008
154
MOJOSHADER_uniformType type;
Apr 5, 2008
Apr 5, 2008
155
int index;
May 5, 2008
May 5, 2008
156
int array_count;
Jul 31, 2008
Jul 31, 2008
157
int constant;
Apr 25, 2008
Apr 25, 2008
158
const char *name;
Apr 4, 2008
Apr 4, 2008
159
160
} MOJOSHADER_uniform;
May 3, 2008
May 3, 2008
161
162
163
164
165
166
167
168
169
170
171
/*
* These are the constants defined in a shader. These are data values
* hardcoded in a shader (with the DEF, DEFI, DEFB instructions), which
* override your Uniforms. This data is largely for informational purposes,
* since they are compiled in and can't be changed, like Uniforms can be.
* These integers are register indexes. So if index==6 and
* type==MOJOSHADER_UNIFORM_FLOAT, that means we'd expect a 4-float vector
* to be specified for what would be register "c6" in D3D assembly language,
* before drawing with the shader.
* (value) is the value of the constant, unioned by type.
*/
Dec 1, 2008
Dec 1, 2008
172
typedef struct MOJOSHADER_constant
May 3, 2008
May 3, 2008
173
174
175
176
177
178
179
180
181
182
183
{
MOJOSHADER_uniformType type;
int index;
union
{
float f[4]; /* if type==MOJOSHADER_UNIFORM_FLOAT */
int i[4]; /* if type==MOJOSHADER_UNIFORM_INT */
int b; /* if type==MOJOSHADER_UNIFORM_BOOL */
} value;
} MOJOSHADER_constant;
Apr 19, 2008
Apr 19, 2008
184
185
186
187
188
/*
* Data types for samplers. See MOJOSHADER_sampler for more information.
*/
typedef enum
{
Apr 28, 2008
Apr 28, 2008
189
MOJOSHADER_SAMPLER_UNKNOWN = -1, /* housekeeping value; never returned. */
Apr 19, 2008
Apr 19, 2008
190
191
MOJOSHADER_SAMPLER_2D,
MOJOSHADER_SAMPLER_CUBE,
Apr 1, 2020
Apr 1, 2020
192
MOJOSHADER_SAMPLER_VOLUME
Apr 19, 2008
Apr 19, 2008
193
194
195
196
197
198
199
200
201
} MOJOSHADER_samplerType;
/*
* These are the samplers to be set for a shader. ...
* IDirect3DDevice::SetTexture() would need this data, for example.
* These integers are the sampler "stage". So if index==6 and
* type==MOJOSHADER_SAMPLER_2D, that means we'd expect a regular 2D texture
* to be specified for what would be register "s6" in D3D assembly language,
* before drawing with the shader.
Apr 25, 2008
Apr 25, 2008
202
203
* (name) is a profile-specific variable name; it may be NULL if it isn't
* applicable to the requested profile.
Apr 17, 2012
Apr 17, 2012
204
205
206
207
208
* (texbem) will be non-zero if a TEXBEM opcode references this sampler. This
* is only used in legacy shaders (ps_1_1 through ps_1_3), but it needs some
* special support to work, as we have to load a magic uniform behind the
* scenes to support it. Most code can ignore this field in general, and no
* one has to touch it unless they really know what they're doing.
Apr 19, 2008
Apr 19, 2008
209
*/
Dec 1, 2008
Dec 1, 2008
210
typedef struct MOJOSHADER_sampler
Apr 19, 2008
Apr 19, 2008
211
212
213
{
MOJOSHADER_samplerType type;
int index;
Apr 25, 2008
Apr 25, 2008
214
const char *name;
Apr 17, 2012
Apr 17, 2012
215
int texbem;
Apr 19, 2008
Apr 19, 2008
216
217
} MOJOSHADER_sampler;
May 29, 2012
May 29, 2012
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
/*
* This struct is used if you have to force a sampler to a specific type.
* Generally, you can ignore this, but if you have, say, a ps_1_1
* shader, you might need to specify what the samplers are meant to be
* to get correct results, as Shader Model 1 samples textures according
* to what is bound to a sampler at the moment instead of what the shader
* is hardcoded to expect.
*/
typedef struct MOJOSHADER_samplerMap
{
int index;
MOJOSHADER_samplerType type;
} MOJOSHADER_samplerMap;
Apr 5, 2008
Apr 5, 2008
233
234
235
236
237
/*
* Data types for attributes. See MOJOSHADER_attribute for more information.
*/
typedef enum
{
Apr 28, 2008
Apr 28, 2008
238
MOJOSHADER_USAGE_UNKNOWN = -1, /* housekeeping value; never returned. */
Jun 24, 2020
Jun 24, 2020
239
240
241
242
243
244
245
246
247
248
249
250
251
MOJOSHADER_USAGE_POSITION, /* 0-15 for Vertex, 1-15 for Pixel */
MOJOSHADER_USAGE_BLENDWEIGHT, /* 0-15 */
MOJOSHADER_USAGE_BLENDINDICES, /* 0-15 */
MOJOSHADER_USAGE_NORMAL, /* 0-15 */
MOJOSHADER_USAGE_POINTSIZE, /* 0-15 */
MOJOSHADER_USAGE_TEXCOORD, /* 0-15 */
MOJOSHADER_USAGE_TANGENT, /* 0-15 */
MOJOSHADER_USAGE_BINORMAL, /* 0-15 */
MOJOSHADER_USAGE_TESSFACTOR, /* 0 only */
MOJOSHADER_USAGE_POSITIONT, /* 0-15 for Vertex, 1-15 for Pixel */
MOJOSHADER_USAGE_COLOR, /* 0-15 but depends on MRT support */
MOJOSHADER_USAGE_FOG, /* 0-15 */
MOJOSHADER_USAGE_DEPTH, /* 0-15 */
Apr 19, 2008
Apr 19, 2008
252
MOJOSHADER_USAGE_SAMPLE,
Oct 12, 2017
Oct 12, 2017
253
MOJOSHADER_USAGE_TOTAL /* housekeeping value; never returned. */
Apr 5, 2008
Apr 5, 2008
254
255
256
257
258
259
260
261
262
263
} MOJOSHADER_usage;
/*
* These are the attributes to be set for a shader. "Attributes" are what
* Direct3D calls "Vertex Declarations Usages" ...
* IDirect3DDevice::CreateVertexDeclaration() would need this data, for
* example. Each attribute is associated with an array of data that uses one
* element per-vertex. So if usage==MOJOSHADER_USAGE_COLOR and index==1, that
* means we'd expect a secondary color array to be bound to this shader
* before drawing.
Apr 25, 2008
Apr 25, 2008
264
265
* (name) is a profile-specific variable name; it may be NULL if it isn't
* applicable to the requested profile.
Apr 5, 2008
Apr 5, 2008
266
*/
Dec 1, 2008
Dec 1, 2008
267
typedef struct MOJOSHADER_attribute
Apr 5, 2008
Apr 5, 2008
268
269
270
{
MOJOSHADER_usage usage;
int index;
Apr 25, 2008
Apr 25, 2008
271
const char *name;
Apr 5, 2008
Apr 5, 2008
272
} MOJOSHADER_attribute;
Mar 28, 2008
Mar 28, 2008
273
Aug 26, 2008
Aug 26, 2008
274
275
276
277
278
279
/*
* Use this if you want to specify newly-parsed code to swizzle incoming
* data. This can be useful if you know, at parse time, that a shader
* will be processing data on COLOR0 that should be RGBA, but you'll
* be passing it a vertex array full of ARGB instead.
*/
Dec 1, 2008
Dec 1, 2008
280
typedef struct MOJOSHADER_swizzle
Aug 26, 2008
Aug 26, 2008
281
282
283
284
285
286
287
{
MOJOSHADER_usage usage;
unsigned int index;
unsigned char swizzles[4]; /* {0,1,2,3} == .xyzw, {2,2,2,2} == .zzzz */
} MOJOSHADER_swizzle;
Dec 20, 2008
Dec 20, 2008
288
289
290
291
292
293
294
295
296
297
/*
* MOJOSHADER_symbol data.
*
* These are used to expose high-level information in shader bytecode.
* They associate HLSL variables with registers. This data is used for both
* debugging and optimization.
*/
typedef enum
{
Oct 12, 2017
Oct 12, 2017
298
MOJOSHADER_SYMREGSET_BOOL=0,
Dec 20, 2008
Dec 20, 2008
299
300
301
MOJOSHADER_SYMREGSET_INT4,
MOJOSHADER_SYMREGSET_FLOAT4,
MOJOSHADER_SYMREGSET_SAMPLER,
Oct 12, 2017
Oct 12, 2017
302
MOJOSHADER_SYMREGSET_TOTAL /* housekeeping value; never returned. */
Dec 20, 2008
Dec 20, 2008
303
304
305
306
} MOJOSHADER_symbolRegisterSet;
typedef enum
{
Oct 12, 2017
Oct 12, 2017
307
MOJOSHADER_SYMCLASS_SCALAR=0,
Dec 20, 2008
Dec 20, 2008
308
309
310
311
312
MOJOSHADER_SYMCLASS_VECTOR,
MOJOSHADER_SYMCLASS_MATRIX_ROWS,
MOJOSHADER_SYMCLASS_MATRIX_COLUMNS,
MOJOSHADER_SYMCLASS_OBJECT,
MOJOSHADER_SYMCLASS_STRUCT,
Oct 12, 2017
Oct 12, 2017
313
MOJOSHADER_SYMCLASS_TOTAL /* housekeeping value; never returned. */
Dec 20, 2008
Dec 20, 2008
314
315
316
317
} MOJOSHADER_symbolClass;
typedef enum
{
Oct 12, 2017
Oct 12, 2017
318
MOJOSHADER_SYMTYPE_VOID=0,
Dec 20, 2008
Dec 20, 2008
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
MOJOSHADER_SYMTYPE_BOOL,
MOJOSHADER_SYMTYPE_INT,
MOJOSHADER_SYMTYPE_FLOAT,
MOJOSHADER_SYMTYPE_STRING,
MOJOSHADER_SYMTYPE_TEXTURE,
MOJOSHADER_SYMTYPE_TEXTURE1D,
MOJOSHADER_SYMTYPE_TEXTURE2D,
MOJOSHADER_SYMTYPE_TEXTURE3D,
MOJOSHADER_SYMTYPE_TEXTURECUBE,
MOJOSHADER_SYMTYPE_SAMPLER,
MOJOSHADER_SYMTYPE_SAMPLER1D,
MOJOSHADER_SYMTYPE_SAMPLER2D,
MOJOSHADER_SYMTYPE_SAMPLER3D,
MOJOSHADER_SYMTYPE_SAMPLERCUBE,
MOJOSHADER_SYMTYPE_PIXELSHADER,
MOJOSHADER_SYMTYPE_VERTEXSHADER,
MOJOSHADER_SYMTYPE_PIXELFRAGMENT,
MOJOSHADER_SYMTYPE_VERTEXFRAGMENT,
MOJOSHADER_SYMTYPE_UNSUPPORTED,
Oct 12, 2017
Oct 12, 2017
338
MOJOSHADER_SYMTYPE_TOTAL /* housekeeping value; never returned. */
Dec 20, 2008
Dec 20, 2008
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
} MOJOSHADER_symbolType;
typedef struct MOJOSHADER_symbolStructMember MOJOSHADER_symbolStructMember;
typedef struct MOJOSHADER_symbolTypeInfo
{
MOJOSHADER_symbolClass parameter_class;
MOJOSHADER_symbolType parameter_type;
unsigned int rows;
unsigned int columns;
unsigned int elements;
unsigned int member_count;
MOJOSHADER_symbolStructMember *members;
} MOJOSHADER_symbolTypeInfo;
struct MOJOSHADER_symbolStructMember
{
const char *name;
MOJOSHADER_symbolTypeInfo info;
};
typedef struct MOJOSHADER_symbol
{
const char *name;
MOJOSHADER_symbolRegisterSet register_set;
unsigned int register_index;
unsigned int register_count;
MOJOSHADER_symbolTypeInfo info;
} MOJOSHADER_symbol;
Nov 11, 2010
Nov 11, 2010
370
371
372
373
374
375
376
/*
* These are used with MOJOSHADER_error as special case positions.
*/
#define MOJOSHADER_POSITION_NONE (-3)
#define MOJOSHADER_POSITION_BEFORE (-2)
#define MOJOSHADER_POSITION_AFTER (-1)
Feb 3, 2009
Feb 3, 2009
377
typedef struct MOJOSHADER_error
Mar 28, 2008
Mar 28, 2008
378
379
380
381
382
383
384
385
{
/*
* Human-readable error, if there is one. Will be NULL if there was no
* error. The string will be UTF-8 encoded, and English only. Most of
* these shouldn't be shown to the end-user anyhow.
*/
const char *error;
Feb 3, 2009
Feb 3, 2009
386
/*
Feb 12, 2009
Feb 12, 2009
387
388
* Filename where error happened. This can be NULL if the information
* isn't available.
Feb 3, 2009
Feb 3, 2009
389
390
391
*/
const char *filename;
Dec 19, 2008
Dec 19, 2008
392
/*
Nov 11, 2010
Nov 11, 2010
393
394
395
396
397
398
399
400
* Position of error, if there is one. Will be MOJOSHADER_POSITION_NONE if
* there was no error, MOJOSHADER_POSITION_BEFORE if there was an error
* before processing started, and MOJOSHADER_POSITION_AFTER if there was
* an error during final processing. If >= 0, MOJOSHADER_parse() sets
* this to the byte offset (starting at zero) into the bytecode you
* supplied, and MOJOSHADER_assemble(), MOJOSHADER_parseAst(), and
* MOJOSHADER_compile() sets this to a a line number in the source code
* you supplied (starting at one).
Dec 10, 2008
Dec 10, 2008
401
402
*/
int error_position;
Feb 3, 2009
Feb 3, 2009
403
404
} MOJOSHADER_error;
May 30, 2011
May 30, 2011
405
406
407
408
409
410
411
412
413
414
415
416
417
418
/* !!! FIXME: document me. */
typedef enum MOJOSHADER_preshaderOpcode
{
MOJOSHADER_PRESHADEROP_NOP,
MOJOSHADER_PRESHADEROP_MOV,
MOJOSHADER_PRESHADEROP_NEG,
MOJOSHADER_PRESHADEROP_RCP,
MOJOSHADER_PRESHADEROP_FRC,
MOJOSHADER_PRESHADEROP_EXP,
MOJOSHADER_PRESHADEROP_LOG,
MOJOSHADER_PRESHADEROP_RSQ,
MOJOSHADER_PRESHADEROP_SIN,
MOJOSHADER_PRESHADEROP_COS,
May 30, 2011
May 30, 2011
419
420
421
422
423
MOJOSHADER_PRESHADEROP_ASIN,
MOJOSHADER_PRESHADEROP_ACOS,
MOJOSHADER_PRESHADEROP_ATAN,
MOJOSHADER_PRESHADEROP_MIN,
MOJOSHADER_PRESHADEROP_MAX,
May 31, 2011
May 31, 2011
424
425
MOJOSHADER_PRESHADEROP_LT,
MOJOSHADER_PRESHADEROP_GE,
May 30, 2011
May 30, 2011
426
427
428
MOJOSHADER_PRESHADEROP_ADD,
MOJOSHADER_PRESHADEROP_MUL,
MOJOSHADER_PRESHADEROP_ATAN2,
May 31, 2011
May 31, 2011
429
MOJOSHADER_PRESHADEROP_DIV,
May 30, 2011
May 30, 2011
430
MOJOSHADER_PRESHADEROP_CMP,
May 31, 2011
May 31, 2011
431
MOJOSHADER_PRESHADEROP_MOVC,
May 30, 2011
May 30, 2011
432
MOJOSHADER_PRESHADEROP_DOT,
May 31, 2011
May 31, 2011
433
MOJOSHADER_PRESHADEROP_NOISE,
May 30, 2011
May 30, 2011
434
435
436
MOJOSHADER_PRESHADEROP_SCALAR_OPS,
MOJOSHADER_PRESHADEROP_MIN_SCALAR = MOJOSHADER_PRESHADEROP_SCALAR_OPS,
MOJOSHADER_PRESHADEROP_MAX_SCALAR,
May 31, 2011
May 31, 2011
437
438
MOJOSHADER_PRESHADEROP_LT_SCALAR,
MOJOSHADER_PRESHADEROP_GE_SCALAR,
May 30, 2011
May 30, 2011
439
440
441
MOJOSHADER_PRESHADEROP_ADD_SCALAR,
MOJOSHADER_PRESHADEROP_MUL_SCALAR,
MOJOSHADER_PRESHADEROP_ATAN2_SCALAR,
May 31, 2011
May 31, 2011
442
MOJOSHADER_PRESHADEROP_DIV_SCALAR,
May 30, 2011
May 30, 2011
443
MOJOSHADER_PRESHADEROP_DOT_SCALAR,
Apr 1, 2020
Apr 1, 2020
444
MOJOSHADER_PRESHADEROP_NOISE_SCALAR
May 30, 2011
May 30, 2011
445
446
447
448
449
450
451
} MOJOSHADER_preshaderOpcode;
typedef enum MOJOSHADER_preshaderOperandType
{
MOJOSHADER_PRESHADEROPERAND_INPUT,
MOJOSHADER_PRESHADEROPERAND_OUTPUT,
MOJOSHADER_PRESHADEROPERAND_LITERAL,
Apr 1, 2020
Apr 1, 2020
452
MOJOSHADER_PRESHADEROPERAND_TEMP
May 30, 2011
May 30, 2011
453
454
455
456
457
458
} MOJOSHADER_preshaderOperandType;
typedef struct MOJOSHADER_preshaderOperand
{
MOJOSHADER_preshaderOperandType type;
unsigned int index;
Jan 1, 2016
Jan 1, 2016
459
460
unsigned int array_register_count;
unsigned int *array_registers;
May 30, 2011
May 30, 2011
461
462
463
464
465
466
467
} MOJOSHADER_preshaderOperand;
typedef struct MOJOSHADER_preshaderInstruction
{
MOJOSHADER_preshaderOpcode opcode;
unsigned int element_count;
unsigned int operand_count;
Jan 1, 2016
Jan 1, 2016
468
MOJOSHADER_preshaderOperand operands[4];
May 30, 2011
May 30, 2011
469
470
471
472
473
474
475
} MOJOSHADER_preshaderInstruction;
typedef struct MOJOSHADER_preshader
{
unsigned int literal_count;
double *literals;
unsigned int temp_count; /* scalar, not vector! */
Jun 1, 2011
Jun 1, 2011
476
477
unsigned int symbol_count;
MOJOSHADER_symbol *symbols;
May 30, 2011
May 30, 2011
478
479
unsigned int instruction_count;
MOJOSHADER_preshaderInstruction *instructions;
Jan 1, 2016
Jan 1, 2016
480
481
unsigned int register_count;
float *registers;
May 28, 2016
May 28, 2016
482
483
484
MOJOSHADER_malloc malloc;
MOJOSHADER_free free;
void *malloc_data;
May 30, 2011
May 30, 2011
485
486
} MOJOSHADER_preshader;
Feb 3, 2009
Feb 3, 2009
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
/*
* Structure used to return data from parsing of a shader...
*/
/* !!! FIXME: most of these ints should be unsigned. */
typedef struct MOJOSHADER_parseData
{
/*
* The number of elements pointed to by (errors).
*/
int error_count;
/*
* (error_count) elements of data that specify errors that were generated
* by parsing this shader.
* This can be NULL if there were no errors or if (error_count) is zero.
*/
MOJOSHADER_error *errors;
Dec 10, 2008
Dec 10, 2008
504
Apr 23, 2008
Apr 23, 2008
505
506
507
508
509
/*
* The name of the profile used to parse the shader. Will be NULL on error.
*/
const char *profile;
Mar 28, 2008
Mar 28, 2008
510
511
512
513
514
515
516
517
518
/*
* Bytes of output from parsing. Most profiles produce a string of source
* code, but profiles that do binary output may not be text at all.
* Will be NULL on error.
*/
const char *output;
/*
* Byte count for output, not counting any null terminator. Most profiles
Apr 6, 2008
Apr 6, 2008
519
520
521
* produce an ASCII string of source code (which will be null-terminated
* even though that null char isn't included in output_len), but profiles
* that do binary output may not be text at all. Will be 0 on error.
Mar 28, 2008
Mar 28, 2008
522
523
524
525
*/
int output_len;
/*
Jun 3, 2008
Jun 3, 2008
526
* Count of Direct3D instruction slots used. This is meaningless in terms
Mar 28, 2008
Mar 28, 2008
527
528
* of the actual output, as the profile will probably grow or reduce
* the count (or for high-level languages, not have that information at
Jun 3, 2008
Jun 3, 2008
529
530
531
532
* all). Also, as with Microsoft's own assembler, this value is just a
* rough estimate, as unpredicable real-world factors make the actual
* value vary at least a little from this count. Still, it can give you
* a rough idea of the size of your shader. Will be zero on error.
Mar 28, 2008
Mar 28, 2008
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
*/
int instruction_count;
/*
* The type of shader we parsed. Will be MOJOSHADER_TYPE_UNKNOWN on error.
*/
MOJOSHADER_shaderType shader_type;
/*
* The shader's major version. If this was a "vs_3_0", this would be 3.
*/
int major_ver;
/*
* The shader's minor version. If this was a "ps_1_4", this would be 4.
* Two notes: for "vs_2_x", this is 1, and for "vs_3_sw", this is 255.
*/
int minor_ver;
Apr 25, 2016
Apr 25, 2016
552
/*
May 29, 2016
May 29, 2016
553
554
555
556
557
* This is the main function name of the shader. This will be the
* caller-supplied string even if a given profile ignores it (GLSL,
* for example, always uses "main" in the shader output out of necessity,
* and Direct3D assembly has no concept of a "main function", etc).
* Otherwise, it'll be a default name chosen by the profile ("main") or
Apr 25, 2016
Apr 25, 2016
558
559
560
561
* whatnot.
*/
const char *mainfn;
Apr 4, 2008
Apr 4, 2008
562
563
564
565
566
567
/*
* The number of elements pointed to by (uniforms).
*/
int uniform_count;
/*
Apr 4, 2008
Apr 4, 2008
568
569
* (uniform_count) elements of data that specify Uniforms to be set for
* this shader. See discussion on MOJOSHADER_uniform for details.
Apr 19, 2008
Apr 19, 2008
570
* This can be NULL on error or if (uniform_count) is zero.
Apr 4, 2008
Apr 4, 2008
571
572
573
*/
MOJOSHADER_uniform *uniforms;
May 3, 2008
May 3, 2008
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
/*
* The number of elements pointed to by (constants).
*/
int constant_count;
/*
* (constant_count) elements of data that specify constants used in
* this shader. See discussion on MOJOSHADER_constant for details.
* This can be NULL on error or if (constant_count) is zero.
* This is largely informational: constants are hardcoded into a shader.
* The constants that you can set like parameters are in the "uniforms"
* list.
*/
MOJOSHADER_constant *constants;
Apr 19, 2008
Apr 19, 2008
589
590
591
592
593
594
595
596
597
598
599
600
/*
* The number of elements pointed to by (samplers).
*/
int sampler_count;
/*
* (sampler_count) elements of data that specify Samplers to be set for
* this shader. See discussion on MOJOSHADER_sampler for details.
* This can be NULL on error or if (sampler_count) is zero.
*/
MOJOSHADER_sampler *samplers;
Jun 20, 2011
Jun 20, 2011
601
/* !!! FIXME: this should probably be "input" and not "attribute" */
Apr 5, 2008
Apr 5, 2008
602
603
604
605
606
/*
* The number of elements pointed to by (attributes).
*/
int attribute_count;
Jun 20, 2011
Jun 20, 2011
607
/* !!! FIXME: this should probably be "input" and not "attribute" */
Apr 5, 2008
Apr 5, 2008
608
609
610
/*
* (attribute_count) elements of data that specify Attributes to be set
* for this shader. See discussion on MOJOSHADER_attribute for details.
Apr 19, 2008
Apr 19, 2008
611
* This can be NULL on error or if (attribute_count) is zero.
Apr 5, 2008
Apr 5, 2008
612
613
614
*/
MOJOSHADER_attribute *attributes;
Jun 20, 2011
Jun 20, 2011
615
616
617
618
619
620
621
622
623
624
625
626
/*
* The number of elements pointed to by (outputs).
*/
int output_count;
/*
* (output_count) elements of data that specify outputs this shader
* writes to. See discussion on MOJOSHADER_attribute for details.
* This can be NULL on error or if (output_count) is zero.
*/
MOJOSHADER_attribute *outputs;
Aug 26, 2008
Aug 26, 2008
627
628
629
630
631
/*
* The number of elements pointed to by (swizzles).
*/
int swizzle_count;
Jun 20, 2011
Jun 20, 2011
632
/* !!! FIXME: this should probably be "input" and not "attribute" */
Aug 26, 2008
Aug 26, 2008
633
634
635
636
637
638
639
640
/*
* (swizzle_count) elements of data that specify swizzles the shader will
* apply to incoming attributes. This is a copy of what was passed to
* MOJOSHADER_parseData().
* This can be NULL on error or if (swizzle_count) is zero.
*/
MOJOSHADER_swizzle *swizzles;
Dec 20, 2008
Dec 20, 2008
641
642
643
644
645
646
647
648
649
650
651
652
653
654
/*
* The number of elements pointed to by (symbols).
*/
int symbol_count;
/*
* (symbol_count) elements of data that specify high-level symbol data
* for the shader. This will be parsed from the CTAB section
* in bytecode, and will be a copy of what you provide to
* MOJOSHADER_assemble(). This data is optional.
* This can be NULL on error or if (symbol_count) is zero.
*/
MOJOSHADER_symbol *symbols;
May 30, 2011
May 30, 2011
655
656
657
658
659
660
/*
* !!! FIXME: document me.
* This can be NULL on error or if no preshader was available.
*/
MOJOSHADER_preshader *preshader;
Mar 28, 2008
Mar 28, 2008
661
662
663
664
665
666
667
668
669
/*
* This is the malloc implementation you passed to MOJOSHADER_parse().
*/
MOJOSHADER_malloc malloc;
/*
* This is the free implementation you passed to MOJOSHADER_parse().
*/
MOJOSHADER_free free;
Apr 4, 2008
Apr 4, 2008
670
671
672
673
674
/*
* This is the pointer you passed as opaque data for your allocator.
*/
void *malloc_data;
Mar 28, 2008
Mar 28, 2008
675
676
677
678
679
680
681
682
} MOJOSHADER_parseData;
/*
* Profile string for Direct3D assembly language output.
*/
#define MOJOSHADER_PROFILE_D3D "d3d"
Apr 6, 2008
Apr 6, 2008
683
684
685
/*
* Profile string for passthrough of the original bytecode, unchanged.
*/
Dec 7, 2008
Dec 7, 2008
686
#define MOJOSHADER_PROFILE_BYTECODE "bytecode"
Apr 6, 2008
Apr 6, 2008
687
May 21, 2020
May 21, 2020
688
689
690
691
692
/*
* Profile string for HLSL Shader Model 4 output.
*/
#define MOJOSHADER_PROFILE_HLSL "hlsl"
Mar 28, 2008
Mar 28, 2008
693
694
695
696
697
/*
* Profile string for GLSL: OpenGL high-level shader language output.
*/
#define MOJOSHADER_PROFILE_GLSL "glsl"
Jun 29, 2008
Jun 29, 2008
698
699
700
701
702
/*
* Profile string for GLSL 1.20: minor improvements to base GLSL spec.
*/
#define MOJOSHADER_PROFILE_GLSL120 "glsl120"
Jan 1, 2016
Jan 1, 2016
703
704
705
706
707
/*
* Profile string for GLSL ES: minor changes to GLSL output for ES compliance.
*/
#define MOJOSHADER_PROFILE_GLSLES "glsles"
May 25, 2008
May 25, 2008
708
709
710
711
712
/*
* Profile string for OpenGL ARB 1.0 shaders: GL_ARB_(vertex|fragment)_program.
*/
#define MOJOSHADER_PROFILE_ARB1 "arb1"
Jun 18, 2008
Jun 18, 2008
713
714
715
716
717
718
719
720
721
722
/*
* Profile string for OpenGL ARB 1.0 shaders with Nvidia 2.0 extensions:
* GL_NV_vertex_program2_option and GL_NV_fragment_program2
*/
#define MOJOSHADER_PROFILE_NV2 "nv2"
/*
* Profile string for OpenGL ARB 1.0 shaders with Nvidia 3.0 extensions:
* GL_NV_vertex_program3 and GL_NV_fragment_program2
*/
Jul 3, 2008
Jul 3, 2008
723
#define MOJOSHADER_PROFILE_NV3 "nv3"
Jun 18, 2008
Jun 18, 2008
724
725
726
/*
* Profile string for OpenGL ARB 1.0 shaders with Nvidia 4.0 extensions:
Sep 24, 2008
Sep 24, 2008
727
* GL_NV_gpu_program4
Jun 18, 2008
Jun 18, 2008
728
*/
Jul 7, 2008
Jul 7, 2008
729
#define MOJOSHADER_PROFILE_NV4 "nv4"
Jun 18, 2008
Jun 18, 2008
730
Apr 25, 2016
Apr 25, 2016
731
732
733
734
735
/*
* Profile string for Metal: Apple's lowlevel API's high-level shader language.
*/
#define MOJOSHADER_PROFILE_METAL "metal"
Dec 31, 2019
Dec 31, 2019
736
737
738
739
740
/*
* Profile string for SPIR-V binary output
*/
#define MOJOSHADER_PROFILE_SPIRV "spirv"
Dec 31, 2019
Dec 31, 2019
741
742
743
744
745
/*
* Profile string for ARB_gl_spirv-friendly SPIR-V binary output
*/
#define MOJOSHADER_PROFILE_GLSPIRV "glspirv"
Nov 8, 2008
Nov 8, 2008
746
747
748
/*
* Determine the highest supported Shader Model for a profile.
*/
Jan 1, 2016
Jan 1, 2016
749
DECLSPEC int MOJOSHADER_maxShaderModel(const char *profile);
Nov 8, 2008
Nov 8, 2008
750
Apr 4, 2008
Apr 4, 2008
751
Mar 28, 2008
Mar 28, 2008
752
753
754
755
756
757
758
759
760
761
762
763
764
765
/*
* Parse a compiled Direct3D shader's bytecode.
*
* This is your primary entry point into MojoShader. You need to pass it
* a compiled D3D shader and tell it which "profile" you want to use to
* convert it into useful data.
*
* The available profiles are the set of MOJOSHADER_PROFILE_* defines.
* Note that MojoShader may be built without support for all listed
* profiles (in which case using one here will return with an error).
*
* As parsing requires some memory to be allocated, you may provide a custom
* allocator to this function, which will be used to allocate/free memory.
* They function just like malloc() and free(). We do not use realloc().
Apr 4, 2008
Apr 4, 2008
766
767
768
* If you don't care, pass NULL in for the allocator functions. If your
* allocator needs instance-specific data, you may supply it with the
* (d) parameter. This pointer is passed as-is to your (m) and (f) functions.
Mar 28, 2008
Mar 28, 2008
769
*
Apr 4, 2008
Apr 4, 2008
770
* This function returns a MOJOSHADER_parseData.
Mar 28, 2008
Mar 28, 2008
771
772
773
774
775
776
*
* This function will never return NULL, even if the system is completely
* out of memory upon entry (in which case, this function returns a static
* MOJOSHADER_parseData object, which is still safe to pass to
* MOJOSHADER_freeParseData()).
*
Aug 26, 2008
Aug 26, 2008
777
778
779
780
781
782
* You can tell the generated program to swizzle certain inputs. If you know
* that COLOR0 should be RGBA but you're passing in ARGB, you can specify
* a swizzle of { MOJOSHADER_USAGE_COLOR, 0, {1,2,3,0} } to (swiz). If the
* input register in the code would produce reg.ywzx, that swizzle would
* change it to reg.wzxy ... (swiz) can be NULL.
*
May 29, 2012
May 29, 2012
783
784
785
786
787
* You can force the shader to expect samplers of certain types. Generally
* you don't need this, as Shader Model 2 and later always specify what they
* expect samplers to be (2D, cubemap, etc). Shader Model 1, however, just
* uses whatever is bound to a given sampler at draw time, but this doesn't
* work in OpenGL, etc. In these cases, MojoShader will default to
May 29, 2012
May 29, 2012
788
789
790
791
792
793
794
* 2D texture sampling (or cubemap sampling, in cases where it makes sense,
* like the TEXM3X3TEX opcode), which works 75% of the time, but if you
* really needed something else, you'll need to specify it here. This can
* also be used, at your own risk, to override DCL opcodes in shaders: if
* the shader explicit says 2D, but you want Cubemap, for example, you can
* use this to override. If you aren't sure about any of this stuff, you can
* (and should) almost certainly ignore it: (smap) can be NULL.
May 29, 2012
May 29, 2012
795
*
Nov 23, 2014
Nov 23, 2014
796
797
798
799
800
* (bufsize) is the size in bytes of (tokenbuf). If (bufsize) is zero,
* MojoShader will attempt to figure out the size of the buffer, but you
* risk a buffer overflow if you have corrupt data, etc. Supply the value
* if you can.
*
Apr 25, 2016
Apr 25, 2016
801
802
803
804
805
806
* You should pass a name for your shader's main function in here, via the
* (mainfn) param. Some profiles need this name to be unique. Passing a NULL
* here will pick a reasonable default, and most profiles will ignore it
* anyhow. As the name of the shader's main function, etc, so make it a
* simple name that would match C's identifier rules. Keep it simple!
*
Apr 23, 2008
Apr 23, 2008
807
* This function is thread safe, so long as (m) and (f) are too, and that
Mar 28, 2008
Mar 28, 2008
808
809
810
* (tokenbuf) remains intact for the duration of the call. This allows you
* to parse several shaders on separate CPU cores at the same time.
*/
Jan 1, 2016
Jan 1, 2016
811
DECLSPEC const MOJOSHADER_parseData *MOJOSHADER_parse(const char *profile,
Apr 25, 2016
Apr 25, 2016
812
const char *mainfn,
Jan 1, 2016
Jan 1, 2016
813
814
815
816
817
818
819
820
821
822
const unsigned char *tokenbuf,
const unsigned int bufsize,
const MOJOSHADER_swizzle *swiz,
const unsigned int swizcount,
const MOJOSHADER_samplerMap *smap,
const unsigned int smapcount,
MOJOSHADER_malloc m,
MOJOSHADER_free f,
void *d);
Mar 28, 2008
Mar 28, 2008
823
824
825
826
827
828
829
830
831
832
/*
* Call this to dispose of parsing results when you are done with them.
* This will call the MOJOSHADER_free function you provided to
* MOJOSHADER_parse multiple times, if you provided one.
* Passing a NULL here is a safe no-op.
*
* This function is thread safe, so long as any allocator you passed into
* MOJOSHADER_parse() is, too.
*/
Jan 1, 2016
Jan 1, 2016
833
DECLSPEC void MOJOSHADER_freeParseData(const MOJOSHADER_parseData *data);
May 22, 2011
May 22, 2011
834
835
May 28, 2016
May 28, 2016
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
/*
* You almost certainly don't need this function, unless you absolutely know
* why you need it without hesitation. This is useful if you're doing
* extremely low-level shader work or building specialized tools.
*
* Parse a preshader structure. This expects a buffer of bytes that represents
* the preshader data starting with its magic number token and ending at
* the end of the comment tokens that contain this preshader. Note that it
* does _not_ start at the beginning of the comment tokens.
*
* On success, this will return a MOJOSHADER_preshader. This can be
* deallocated later by calling MOJOSHADER_freePreshader(). On failure,
* this will return NULL. Unlike other MojoShader APIs, this assumes you
* either have a complete and valid buffer of preshader tokens or you have
* incomplete/corrupted data, so there is no explicit error reporting. Please
* note that if the system runs out of memory, this function will also return
* NULL without distinction.
*
* This function is thread safe, so long as any allocator you passed into
* MOJOSHADER_parsePreshader() is, too.
*/
Jan 1, 2016
Jan 1, 2016
857
858
859
860
861
DECLSPEC const MOJOSHADER_preshader *MOJOSHADER_parsePreshader(const unsigned char *buf,
const unsigned int len,
MOJOSHADER_malloc m,
MOJOSHADER_free f,
void *d);
May 22, 2011
May 22, 2011
862
863
May 28, 2016
May 28, 2016
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
/*
* You almost certainly don't need this function, unless you absolutely know
* why you need it without hesitation. This is useful if you're doing
* extremely low-level shader work or building specialized tools.
*
* Call this to dispose of preshader parsing results when you are done with
* them. This will call the MOJOSHADER_free function you provided to
* MOJOSHADER_parsePreshader() multiple times, if you provided one.
* Passing a NULL here is a safe no-op.
*
* You only need to call this function for results from a call to
* MOJOSHADER_parsePreshader(). Other MojoShader structures with a preshader
* field, such as MOJOSHADER_parseData(), should not use this function, as
* the preshader will be deallocated with everything else in
* MOJOSHADER_freeParseData(), etc.
*
* This function is thread safe, so long as any allocator you passed into
* MOJOSHADER_parsePreshader() is, too.
*/
DECLSPEC void MOJOSHADER_freePreshader(const MOJOSHADER_preshader *preshader);
May 22, 2011
May 22, 2011
884
885
Feb 9, 2009
Feb 9, 2009
886
887
888
889
/* Preprocessor interface... */
/*
* Structure used to pass predefined macros. Maps to D3DXMACRO.
Feb 20, 2009
Feb 20, 2009
890
* You can have macro arguments: set identifier to "a(b, c)" or whatever.
Feb 9, 2009
Feb 9, 2009
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
*/
typedef struct MOJOSHADER_preprocessorDefine
{
const char *identifier;
const char *definition;
} MOJOSHADER_preprocessorDefine;
/*
* Used with the MOJOSHADER_includeOpen callback. Maps to D3DXINCLUDE_TYPE.
*/
typedef enum
{
MOJOSHADER_INCLUDETYPE_LOCAL, /* local header: #include "blah.h" */
MOJOSHADER_INCLUDETYPE_SYSTEM /* system header: #include <blah.h> */
} MOJOSHADER_includeType;
/*
* Structure used to return data from preprocessing of a shader...
*/
/* !!! FIXME: most of these ints should be unsigned. */
typedef struct MOJOSHADER_preprocessData
{
/*
* The number of elements pointed to by (errors).
*/
int error_count;
/*
* (error_count) elements of data that specify errors that were generated
* by parsing this shader.
* This can be NULL if there were no errors or if (error_count) is zero.
*/
MOJOSHADER_error *errors;
/*
Feb 12, 2009
Feb 12, 2009
927
* Bytes of output from preprocessing. This is a UTF-8 string. We
Feb 9, 2009
Feb 9, 2009
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
* guarantee it to be NULL-terminated. Will be NULL on error.
*/
const char *output;
/*
* Byte count for output, not counting any null terminator.
* Will be 0 on error.
*/
int output_len;
/*
* This is the malloc implementation you passed to MOJOSHADER_parse().
*/
MOJOSHADER_malloc malloc;
/*
* This is the free implementation you passed to MOJOSHADER_parse().
*/
MOJOSHADER_free free;
/*
* This is the pointer you passed as opaque data for your allocator.
*/
void *malloc_data;
} MOJOSHADER_preprocessData;
/*
* This callback allows an app to handle #include statements for the
* preprocessor. When the preprocessor sees an #include, it will call this
* function to obtain the contents of the requested file. This is optional;
Mar 24, 2009
Mar 24, 2009
959
* the preprocessor will open files directly if no callback is supplied, but
Feb 9, 2009
Feb 9, 2009
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
* this allows an app to retrieve data from something other than the
* traditional filesystem (for example, headers packed in a .zip file or
* headers generated on-the-fly).
*
* This function maps to ID3DXInclude::Open()
*
* (inctype) specifies the type of header we wish to include.
* (fname) specifies the name of the file specified on the #include line.
* (parent) is a string of the entire source file containing the include, in
* its original, not-yet-preprocessed state. Note that this is just the
* contents of the specific file, not all source code that the preprocessor
* has seen through other includes, etc.
* (outdata) will be set by the callback to a pointer to the included file's
* contents. The callback is responsible for allocating this however they
* see fit (we provide allocator functions, but you may ignore them). This
* pointer must remain valid until the includeClose callback runs. This
* string does not need to be NULL-terminated.
* (outbytes) will be set by the callback to the number of bytes pointed to
* by (outdata).
* (m),(f), and (d) are the allocator details that the application passed to
* MojoShader. If these were NULL, MojoShader may have replaced them with its
* own internal allocators.
*
* The callback returns zero on error, non-zero on success.
*
* If you supply an includeOpen callback, you must supply includeClose, too.
*/
Jan 1, 2016
Jan 1, 2016
987
typedef int (MOJOSHADERCALL *MOJOSHADER_includeOpen)(MOJOSHADER_includeType inctype,
Feb 9, 2009
Feb 9, 2009
988
989
990
991
992
993
994
995
996
997
998
999
1000
const char *fname, const char *parent,
const char **outdata, unsigned int *outbytes,
MOJOSHADER_malloc m, MOJOSHADER_free f, void *d);
/*
* This callback allows an app to clean up the results of a previous
* includeOpen callback.
*
* This function maps to ID3DXInclude::Close()
*
* (data) is the data that was returned from a previous call to includeOpen.
* It is now safe to deallocate this data.
* (m),(f), and (d) are the same allocator details that were passed to your