mojoshader.h
author Ryan C. Gordon <icculus@icculus.org>
Thu, 23 Jul 2020 05:12:09 -0400
changeset 1298 b70ccc2c7a51
parent 1279 b1f51cfa8933
child 1304 d68910d81b6e
permissions -rw-r--r--
assembler: set the default source arg swizzle to the correct value.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
     1
/**
35
5749d174b537 [svn] Might as well keep the tradition alive.
icculus
parents: 20
diff changeset
     2
 * MojoShader; generate shader programs from bytecode of compiled
5749d174b537 [svn] Might as well keep the tradition alive.
icculus
parents: 20
diff changeset
     3
 *  Direct3D shaders.
7
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
     4
 *
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
     5
 * Please see the file LICENSE.txt in the source's root directory.
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
     6
 *
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
     7
 *  This file written by Ryan C. Gordon.
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
     8
 */
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
     9
592
ef8b7cc469da Removed an underscore.
Ryan C. Gordon <icculus@icculus.org>
parents: 579
diff changeset
    10
#ifndef _INCL_MOJOSHADER_H_
ef8b7cc469da Removed an underscore.
Ryan C. Gordon <icculus@icculus.org>
parents: 579
diff changeset
    11
#define _INCL_MOJOSHADER_H_
7
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
    12
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
    13
#ifdef __cplusplus
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
    14
extern "C" {
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
    15
#endif
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
    16
455
d99f47386d51 Generate MOJOSHADER_VERSION, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 454
diff changeset
    17
/* You can define this if you aren't generating mojoshader_version.h */
d99f47386d51 Generate MOJOSHADER_VERSION, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 454
diff changeset
    18
#ifndef MOJOSHADER_NO_VERSION_INCLUDE
d99f47386d51 Generate MOJOSHADER_VERSION, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 454
diff changeset
    19
#include "mojoshader_version.h"
461
892b408b5779 Only define MOJOSHADER_VERSION and MOJOSHADER_CHANGESET if required.
Ryan C. Gordon <icculus@icculus.org>
parents: 458
diff changeset
    20
#endif
892b408b5779 Only define MOJOSHADER_VERSION and MOJOSHADER_CHANGESET if required.
Ryan C. Gordon <icculus@icculus.org>
parents: 458
diff changeset
    21
892b408b5779 Only define MOJOSHADER_VERSION and MOJOSHADER_CHANGESET if required.
Ryan C. Gordon <icculus@icculus.org>
parents: 458
diff changeset
    22
#ifndef MOJOSHADER_VERSION
455
d99f47386d51 Generate MOJOSHADER_VERSION, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 454
diff changeset
    23
#define MOJOSHADER_VERSION -1
461
892b408b5779 Only define MOJOSHADER_VERSION and MOJOSHADER_CHANGESET if required.
Ryan C. Gordon <icculus@icculus.org>
parents: 458
diff changeset
    24
#endif
892b408b5779 Only define MOJOSHADER_VERSION and MOJOSHADER_CHANGESET if required.
Ryan C. Gordon <icculus@icculus.org>
parents: 458
diff changeset
    25
892b408b5779 Only define MOJOSHADER_VERSION and MOJOSHADER_CHANGESET if required.
Ryan C. Gordon <icculus@icculus.org>
parents: 458
diff changeset
    26
#ifndef MOJOSHADER_CHANGESET
455
d99f47386d51 Generate MOJOSHADER_VERSION, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 454
diff changeset
    27
#define MOJOSHADER_CHANGESET "???"
d99f47386d51 Generate MOJOSHADER_VERSION, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 454
diff changeset
    28
#endif
d99f47386d51 Generate MOJOSHADER_VERSION, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 454
diff changeset
    29
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1143
diff changeset
    30
#ifndef DECLSPEC
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1143
diff changeset
    31
#ifdef _WIN32
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1143
diff changeset
    32
#define DECLSPEC __declspec(dllexport)
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1143
diff changeset
    33
#else
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1143
diff changeset
    34
#define DECLSPEC
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1143
diff changeset
    35
#endif
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1143
diff changeset
    36
#endif
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1143
diff changeset
    37
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1143
diff changeset
    38
#ifndef MOJOSHADERCALL
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1143
diff changeset
    39
#ifdef _WIN32
1244
311c02c8475a Use __cdecl instead of __stdcall
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1235
diff changeset
    40
#define MOJOSHADERCALL __cdecl
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1143
diff changeset
    41
#else
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1143
diff changeset
    42
#define MOJOSHADERCALL
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1143
diff changeset
    43
#endif
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1143
diff changeset
    44
#endif
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1143
diff changeset
    45
1235
8fd6c5efe453 -Wpedantic fixes
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1229
diff changeset
    46
/* -Wpedantic nameless union/struct silencing */
8fd6c5efe453 -Wpedantic fixes
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1229
diff changeset
    47
#ifndef MOJOSHADERNAMELESS
8fd6c5efe453 -Wpedantic fixes
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1229
diff changeset
    48
#ifdef __GNUC__
8fd6c5efe453 -Wpedantic fixes
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1229
diff changeset
    49
#define MOJOSHADERNAMELESS __extension__
8fd6c5efe453 -Wpedantic fixes
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1229
diff changeset
    50
#else
8fd6c5efe453 -Wpedantic fixes
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1229
diff changeset
    51
#define MOJOSHADERNAMELESS
8fd6c5efe453 -Wpedantic fixes
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1229
diff changeset
    52
#endif /* __GNUC__ */
8fd6c5efe453 -Wpedantic fixes
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1229
diff changeset
    53
#endif /* MOJOSHADERNAMELESS */
8fd6c5efe453 -Wpedantic fixes
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1229
diff changeset
    54
20
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 18
diff changeset
    55
/*
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
    56
 * For determining the version of MojoShader you are using:
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
    57
 *    const int compiled_against = MOJOSHADER_VERSION;
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
    58
 *    const int linked_against = MOJOSHADER_version();
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
    59
 *
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
    60
 * The version is a single integer that increments, not a major/minor value.
20
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 18
diff changeset
    61
 */
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1143
diff changeset
    62
DECLSPEC int MOJOSHADER_version(void);
20
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 18
diff changeset
    63
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 18
diff changeset
    64
/*
552
40ca33bd5f88 Fixed a comment typo.
Ryan C. Gordon <icculus@icculus.org>
parents: 536
diff changeset
    65
 * For determining the revision control changeset of MojoShader you are using:
1017
5034d40d718a Fixed typo in documentation.
Ryan C. Gordon <icculus@icculus.org>
parents: 1014
diff changeset
    66
 *    const char *compiled_against = MOJOSHADER_CHANGESET;
455
d99f47386d51 Generate MOJOSHADER_VERSION, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 454
diff changeset
    67
 *    const char *linked_against = MOJOSHADER_changeset();
d99f47386d51 Generate MOJOSHADER_VERSION, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 454
diff changeset
    68
 *
d99f47386d51 Generate MOJOSHADER_VERSION, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 454
diff changeset
    69
 * The version is an arbitrary, null-terminated ASCII string. It is probably
d99f47386d51 Generate MOJOSHADER_VERSION, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 454
diff changeset
    70
 *  a hash that represents a revision control changeset, and can't be
d99f47386d51 Generate MOJOSHADER_VERSION, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 454
diff changeset
    71
 *  compared to any other string to determine chronology.
d99f47386d51 Generate MOJOSHADER_VERSION, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 454
diff changeset
    72
 *
d99f47386d51 Generate MOJOSHADER_VERSION, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 454
diff changeset
    73
 * Do not attempt to free this string; it's statically allocated.
d99f47386d51 Generate MOJOSHADER_VERSION, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 454
diff changeset
    74
 */
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1143
diff changeset
    75
DECLSPEC const char *MOJOSHADER_changeset(void);
455
d99f47386d51 Generate MOJOSHADER_VERSION, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 454
diff changeset
    76
d99f47386d51 Generate MOJOSHADER_VERSION, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 454
diff changeset
    77
/*
20
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 18
diff changeset
    78
 * These allocators work just like the C runtime's malloc() and free()
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
    79
 *  (in fact, they probably use malloc() and free() internally if you don't
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
    80
 *  specify your own allocator, but don't rely on that behaviour).
97
4a41e3d17297 Allow instance data to be passed to the allocator.
Ryan C. Gordon <icculus@icculus.org>
parents: 94
diff changeset
    81
 * (data) is the pointer you supplied when specifying these allocator
4a41e3d17297 Allow instance data to be passed to the allocator.
Ryan C. Gordon <icculus@icculus.org>
parents: 94
diff changeset
    82
 *  callbacks, in case you need instance-specific data...it is passed through
4a41e3d17297 Allow instance data to be passed to the allocator.
Ryan C. Gordon <icculus@icculus.org>
parents: 94
diff changeset
    83
 *  to your allocator unmolested, and can be NULL if you like.
20
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 18
diff changeset
    84
 */
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1143
diff changeset
    85
typedef void *(MOJOSHADERCALL *MOJOSHADER_malloc)(int bytes, void *data);
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1143
diff changeset
    86
typedef void (MOJOSHADERCALL *MOJOSHADER_free)(void *ptr, void *data);
18
0dbdb2be8bf8 [svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents: 14
diff changeset
    87
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
    88
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
    89
/*
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
    90
 * These are enum values, but they also can be used in bitmasks, so we can
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
    91
 *  test if an opcode is acceptable: if (op->shader_types & ourtype) {} ...
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
    92
 */
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
    93
typedef enum
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
    94
{
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
    95
    MOJOSHADER_TYPE_UNKNOWN  = 0,
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
    96
    MOJOSHADER_TYPE_PIXEL    = (1 << 0),
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
    97
    MOJOSHADER_TYPE_VERTEX   = (1 << 1),
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
    98
    MOJOSHADER_TYPE_GEOMETRY = (1 << 2),  /* (not supported yet.) */
1235
8fd6c5efe453 -Wpedantic fixes
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1229
diff changeset
    99
    MOJOSHADER_TYPE_ANY = 0x7FFFFFFF   /* used for bitmasks */
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   100
} MOJOSHADER_shaderType;
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   101
94
57adfb4769a0 Simplifed public uniform information.
Ryan C. Gordon <icculus@icculus.org>
parents: 92
diff changeset
   102
/*
196
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   103
 * Data types for vertex attribute streams.
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   104
 */
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   105
typedef enum
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   106
{
240
a945af028366 Added UNKNOWN value to the enums in the public API.
Ryan C. Gordon <icculus@icculus.org>
parents: 239
diff changeset
   107
    MOJOSHADER_ATTRIBUTE_UNKNOWN = -1,  /* housekeeping; not returned. */
196
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   108
    MOJOSHADER_ATTRIBUTE_BYTE,
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   109
    MOJOSHADER_ATTRIBUTE_UBYTE,
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   110
    MOJOSHADER_ATTRIBUTE_SHORT,
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   111
    MOJOSHADER_ATTRIBUTE_USHORT,
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   112
    MOJOSHADER_ATTRIBUTE_INT,
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   113
    MOJOSHADER_ATTRIBUTE_UINT,
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   114
    MOJOSHADER_ATTRIBUTE_FLOAT,
236
8e2fc535b210 Support for half-float attribute arrays.
Ryan C. Gordon <icculus@icculus.org>
parents: 219
diff changeset
   115
    MOJOSHADER_ATTRIBUTE_DOUBLE,
1235
8fd6c5efe453 -Wpedantic fixes
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1229
diff changeset
   116
    MOJOSHADER_ATTRIBUTE_HALF_FLOAT  /* MAYBE available in your OpenGL! */
196
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   117
} MOJOSHADER_attributeType;
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   118
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   119
/*
94
57adfb4769a0 Simplifed public uniform information.
Ryan C. Gordon <icculus@icculus.org>
parents: 92
diff changeset
   120
 * Data types for uniforms. See MOJOSHADER_uniform for more information.
57adfb4769a0 Simplifed public uniform information.
Ryan C. Gordon <icculus@icculus.org>
parents: 92
diff changeset
   121
 */
92
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
   122
typedef enum
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
   123
{
240
a945af028366 Added UNKNOWN value to the enums in the public API.
Ryan C. Gordon <icculus@icculus.org>
parents: 239
diff changeset
   124
    MOJOSHADER_UNIFORM_UNKNOWN = -1, /* housekeeping value; never returned. */
147
98043daf5027 Removed explicit numbers on enums in mojoshader.h.
Ryan C. Gordon <icculus@icculus.org>
parents: 146
diff changeset
   125
    MOJOSHADER_UNIFORM_FLOAT,
98043daf5027 Removed explicit numbers on enums in mojoshader.h.
Ryan C. Gordon <icculus@icculus.org>
parents: 146
diff changeset
   126
    MOJOSHADER_UNIFORM_INT,
1235
8fd6c5efe453 -Wpedantic fixes
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1229
diff changeset
   127
    MOJOSHADER_UNIFORM_BOOL
94
57adfb4769a0 Simplifed public uniform information.
Ryan C. Gordon <icculus@icculus.org>
parents: 92
diff changeset
   128
} MOJOSHADER_uniformType;
92
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
   129
94
57adfb4769a0 Simplifed public uniform information.
Ryan C. Gordon <icculus@icculus.org>
parents: 92
diff changeset
   130
/*
57adfb4769a0 Simplifed public uniform information.
Ryan C. Gordon <icculus@icculus.org>
parents: 92
diff changeset
   131
 * These are the uniforms to be set for a shader. "Uniforms" are what Direct3D
57adfb4769a0 Simplifed public uniform information.
Ryan C. Gordon <icculus@icculus.org>
parents: 92
diff changeset
   132
 *  calls "Constants" ... IDirect3DDevice::SetVertexShaderConstantF() would
57adfb4769a0 Simplifed public uniform information.
Ryan C. Gordon <icculus@icculus.org>
parents: 92
diff changeset
   133
 *  need this data, for example. These integers are register indexes. So if
57adfb4769a0 Simplifed public uniform information.
Ryan C. Gordon <icculus@icculus.org>
parents: 92
diff changeset
   134
 *  index==6 and type==MOJOSHADER_UNIFORM_FLOAT, that means we'd expect a
57adfb4769a0 Simplifed public uniform information.
Ryan C. Gordon <icculus@icculus.org>
parents: 92
diff changeset
   135
 *  4-float vector to be specified for what would be register "c6" in D3D
57adfb4769a0 Simplifed public uniform information.
Ryan C. Gordon <icculus@icculus.org>
parents: 92
diff changeset
   136
 *  assembly language, before drawing with the shader.
280
61b2abd9c927 Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 278
diff changeset
   137
 * (array_count) means this is an array of uniforms...this happens in some
61b2abd9c927 Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 278
diff changeset
   138
 *  profiles when we see a relative address ("c0[a0.x]", not the usual "c0").
61b2abd9c927 Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 278
diff changeset
   139
 *  In those cases, the shader was built to set some range of constant
61b2abd9c927 Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 278
diff changeset
   140
 *  registers as an array. You should set this array with (array_count)
61b2abd9c927 Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 278
diff changeset
   141
 *  elements from the constant register file, starting at (index) instead of
61b2abd9c927 Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 278
diff changeset
   142
 *  just a single uniform. To be extra difficult, you'll need to fill in the
61b2abd9c927 Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 278
diff changeset
   143
 *  correct values from the MOJOSHADER_constant data into the appropriate
61b2abd9c927 Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 278
diff changeset
   144
 *  parts of the array, overriding the constant register file. Fun!
438
73492129c1af Expose true constant arrays in parseData, load them at link time for GLSL.
Ryan C. Gordon <icculus@icculus.org>
parents: 431
diff changeset
   145
 * (constant) says whether this is a constant array; these need to be loaded
73492129c1af Expose true constant arrays in parseData, load them at link time for GLSL.
Ryan C. Gordon <icculus@icculus.org>
parents: 431
diff changeset
   146
 *  once at creation time, from the constant list and not ever updated from
73492129c1af Expose true constant arrays in parseData, load them at link time for GLSL.
Ryan C. Gordon <icculus@icculus.org>
parents: 431
diff changeset
   147
 *  the constant register file. This is a workaround for limitations in some
73492129c1af Expose true constant arrays in parseData, load them at link time for GLSL.
Ryan C. Gordon <icculus@icculus.org>
parents: 431
diff changeset
   148
 *  profiles.
190
2a2fb0f656cf Added profile-specific variable names to returned parse data.
Ryan C. Gordon <icculus@icculus.org>
parents: 187
diff changeset
   149
 * (name) is a profile-specific variable name; it may be NULL if it isn't
2a2fb0f656cf Added profile-specific variable names to returned parse data.
Ryan C. Gordon <icculus@icculus.org>
parents: 187
diff changeset
   150
 *  applicable to the requested profile.
94
57adfb4769a0 Simplifed public uniform information.
Ryan C. Gordon <icculus@icculus.org>
parents: 92
diff changeset
   151
 */
462
af8c1ff58453 Make the C struct definitions more C++ friendly.
Ryan C. Gordon <icculus@icculus.org>
parents: 461
diff changeset
   152
typedef struct MOJOSHADER_uniform
92
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
   153
{
100
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   154
    MOJOSHADER_uniformType type;
92
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
   155
    int index;
280
61b2abd9c927 Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 278
diff changeset
   156
    int array_count;
438
73492129c1af Expose true constant arrays in parseData, load them at link time for GLSL.
Ryan C. Gordon <icculus@icculus.org>
parents: 431
diff changeset
   157
    int constant;
190
2a2fb0f656cf Added profile-specific variable names to returned parse data.
Ryan C. Gordon <icculus@icculus.org>
parents: 187
diff changeset
   158
    const char *name;
92
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
   159
} MOJOSHADER_uniform;
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
   160
100
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   161
/*
278
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 276
diff changeset
   162
 * These are the constants defined in a shader. These are data values
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 276
diff changeset
   163
 *  hardcoded in a shader (with the DEF, DEFI, DEFB instructions), which
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 276
diff changeset
   164
 *  override your Uniforms. This data is largely for informational purposes,
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 276
diff changeset
   165
 *  since they are compiled in and can't be changed, like Uniforms can be.
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 276
diff changeset
   166
 * These integers are register indexes. So if index==6 and
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 276
diff changeset
   167
 *  type==MOJOSHADER_UNIFORM_FLOAT, that means we'd expect a 4-float vector
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 276
diff changeset
   168
 *  to be specified for what would be register "c6" in D3D assembly language,
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 276
diff changeset
   169
 *  before drawing with the shader.
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 276
diff changeset
   170
 * (value) is the value of the constant, unioned by type.
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 276
diff changeset
   171
 */
462
af8c1ff58453 Make the C struct definitions more C++ friendly.
Ryan C. Gordon <icculus@icculus.org>
parents: 461
diff changeset
   172
typedef struct MOJOSHADER_constant
278
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 276
diff changeset
   173
{
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 276
diff changeset
   174
    MOJOSHADER_uniformType type;
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 276
diff changeset
   175
    int index;
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 276
diff changeset
   176
    union
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 276
diff changeset
   177
    {
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 276
diff changeset
   178
        float f[4];  /* if type==MOJOSHADER_UNIFORM_FLOAT */
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 276
diff changeset
   179
        int i[4];    /* if type==MOJOSHADER_UNIFORM_INT */
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 276
diff changeset
   180
        int b;       /* if type==MOJOSHADER_UNIFORM_BOOL */
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 276
diff changeset
   181
    } value;
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 276
diff changeset
   182
} MOJOSHADER_constant;
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 276
diff changeset
   183
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 276
diff changeset
   184
/*
148
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   185
 * Data types for samplers. See MOJOSHADER_sampler for more information.
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   186
 */
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   187
typedef enum
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   188
{
240
a945af028366 Added UNKNOWN value to the enums in the public API.
Ryan C. Gordon <icculus@icculus.org>
parents: 239
diff changeset
   189
    MOJOSHADER_SAMPLER_UNKNOWN = -1, /* housekeeping value; never returned. */
148
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   190
    MOJOSHADER_SAMPLER_2D,
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   191
    MOJOSHADER_SAMPLER_CUBE,
1235
8fd6c5efe453 -Wpedantic fixes
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1229
diff changeset
   192
    MOJOSHADER_SAMPLER_VOLUME
148
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   193
} MOJOSHADER_samplerType;
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   194
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   195
/*
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   196
 * These are the samplers to be set for a shader. ...
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   197
 *  IDirect3DDevice::SetTexture() would need this data, for example.
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   198
 * These integers are the sampler "stage". So if index==6 and
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   199
 *  type==MOJOSHADER_SAMPLER_2D, that means we'd expect a regular 2D texture
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   200
 *  to be specified for what would be register "s6" in D3D assembly language,
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   201
 *  before drawing with the shader.
190
2a2fb0f656cf Added profile-specific variable names to returned parse data.
Ryan C. Gordon <icculus@icculus.org>
parents: 187
diff changeset
   202
 * (name) is a profile-specific variable name; it may be NULL if it isn't
2a2fb0f656cf Added profile-specific variable names to returned parse data.
Ryan C. Gordon <icculus@icculus.org>
parents: 187
diff changeset
   203
 *  applicable to the requested profile.
1090
636ffcd3f14a First shot at GLSL/ARB1 support for TEXBEM and TEXBEML opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1068
diff changeset
   204
 * (texbem) will be non-zero if a TEXBEM opcode references this sampler. This
636ffcd3f14a First shot at GLSL/ARB1 support for TEXBEM and TEXBEML opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1068
diff changeset
   205
 *  is only used in legacy shaders (ps_1_1 through ps_1_3), but it needs some
636ffcd3f14a First shot at GLSL/ARB1 support for TEXBEM and TEXBEML opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1068
diff changeset
   206
 *  special support to work, as we have to load a magic uniform behind the
636ffcd3f14a First shot at GLSL/ARB1 support for TEXBEM and TEXBEML opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1068
diff changeset
   207
 *  scenes to support it. Most code can ignore this field in general, and no
636ffcd3f14a First shot at GLSL/ARB1 support for TEXBEM and TEXBEML opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1068
diff changeset
   208
 *  one has to touch it unless they really know what they're doing.
148
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   209
 */
462
af8c1ff58453 Make the C struct definitions more C++ friendly.
Ryan C. Gordon <icculus@icculus.org>
parents: 461
diff changeset
   210
typedef struct MOJOSHADER_sampler
148
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   211
{
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   212
    MOJOSHADER_samplerType type;
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   213
    int index;
190
2a2fb0f656cf Added profile-specific variable names to returned parse data.
Ryan C. Gordon <icculus@icculus.org>
parents: 187
diff changeset
   214
    const char *name;
1090
636ffcd3f14a First shot at GLSL/ARB1 support for TEXBEM and TEXBEML opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1068
diff changeset
   215
    int texbem;
148
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   216
} MOJOSHADER_sampler;
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   217
1104
9147482e1ec7 Allow sampler type remapping.
Ryan C. Gordon <icculus@icculus.org>
parents: 1090
diff changeset
   218
9147482e1ec7 Allow sampler type remapping.
Ryan C. Gordon <icculus@icculus.org>
parents: 1090
diff changeset
   219
/*
9147482e1ec7 Allow sampler type remapping.
Ryan C. Gordon <icculus@icculus.org>
parents: 1090
diff changeset
   220
 * This struct is used if you have to force a sampler to a specific type.
9147482e1ec7 Allow sampler type remapping.
Ryan C. Gordon <icculus@icculus.org>
parents: 1090
diff changeset
   221
 *  Generally, you can ignore this, but if you have, say, a ps_1_1
9147482e1ec7 Allow sampler type remapping.
Ryan C. Gordon <icculus@icculus.org>
parents: 1090
diff changeset
   222
 *  shader, you might need to specify what the samplers are meant to be
9147482e1ec7 Allow sampler type remapping.
Ryan C. Gordon <icculus@icculus.org>
parents: 1090
diff changeset
   223
 *  to get correct results, as Shader Model 1 samples textures according
9147482e1ec7 Allow sampler type remapping.
Ryan C. Gordon <icculus@icculus.org>
parents: 1090
diff changeset
   224
 *  to what is bound to a sampler at the moment instead of what the shader
9147482e1ec7 Allow sampler type remapping.
Ryan C. Gordon <icculus@icculus.org>
parents: 1090
diff changeset
   225
 *  is hardcoded to expect.
9147482e1ec7 Allow sampler type remapping.
Ryan C. Gordon <icculus@icculus.org>
parents: 1090
diff changeset
   226
 */
9147482e1ec7 Allow sampler type remapping.
Ryan C. Gordon <icculus@icculus.org>
parents: 1090
diff changeset
   227
typedef struct MOJOSHADER_samplerMap
9147482e1ec7 Allow sampler type remapping.
Ryan C. Gordon <icculus@icculus.org>
parents: 1090
diff changeset
   228
{
9147482e1ec7 Allow sampler type remapping.
Ryan C. Gordon <icculus@icculus.org>
parents: 1090
diff changeset
   229
    int index;
9147482e1ec7 Allow sampler type remapping.
Ryan C. Gordon <icculus@icculus.org>
parents: 1090
diff changeset
   230
    MOJOSHADER_samplerType type;
9147482e1ec7 Allow sampler type remapping.
Ryan C. Gordon <icculus@icculus.org>
parents: 1090
diff changeset
   231
} MOJOSHADER_samplerMap;
9147482e1ec7 Allow sampler type remapping.
Ryan C. Gordon <icculus@icculus.org>
parents: 1090
diff changeset
   232
148
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   233
/*
100
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   234
 * Data types for attributes. See MOJOSHADER_attribute for more information.
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   235
 */
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   236
typedef enum
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   237
{
240
a945af028366 Added UNKNOWN value to the enums in the public API.
Ryan C. Gordon <icculus@icculus.org>
parents: 239
diff changeset
   238
    MOJOSHADER_USAGE_UNKNOWN = -1,  /* housekeeping value; never returned. */
1266
285a186ad69d Note the usage index range for MOJOSHADER_usage enum
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1256
diff changeset
   239
    MOJOSHADER_USAGE_POSITION,      /* 0-15 for Vertex, 1-15 for Pixel */
285a186ad69d Note the usage index range for MOJOSHADER_usage enum
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1256
diff changeset
   240
    MOJOSHADER_USAGE_BLENDWEIGHT,   /* 0-15 */
285a186ad69d Note the usage index range for MOJOSHADER_usage enum
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1256
diff changeset
   241
    MOJOSHADER_USAGE_BLENDINDICES,  /* 0-15 */
285a186ad69d Note the usage index range for MOJOSHADER_usage enum
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1256
diff changeset
   242
    MOJOSHADER_USAGE_NORMAL,        /* 0-15 */
285a186ad69d Note the usage index range for MOJOSHADER_usage enum
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1256
diff changeset
   243
    MOJOSHADER_USAGE_POINTSIZE,     /* 0-15 */
285a186ad69d Note the usage index range for MOJOSHADER_usage enum
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1256
diff changeset
   244
    MOJOSHADER_USAGE_TEXCOORD,      /* 0-15 */
285a186ad69d Note the usage index range for MOJOSHADER_usage enum
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1256
diff changeset
   245
    MOJOSHADER_USAGE_TANGENT,       /* 0-15 */
285a186ad69d Note the usage index range for MOJOSHADER_usage enum
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1256
diff changeset
   246
    MOJOSHADER_USAGE_BINORMAL,      /* 0-15 */
285a186ad69d Note the usage index range for MOJOSHADER_usage enum
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1256
diff changeset
   247
    MOJOSHADER_USAGE_TESSFACTOR,    /* 0 only */
285a186ad69d Note the usage index range for MOJOSHADER_usage enum
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1256
diff changeset
   248
    MOJOSHADER_USAGE_POSITIONT,     /* 0-15 for Vertex, 1-15 for Pixel */
285a186ad69d Note the usage index range for MOJOSHADER_usage enum
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1256
diff changeset
   249
    MOJOSHADER_USAGE_COLOR,         /* 0-15 but depends on MRT support */
285a186ad69d Note the usage index range for MOJOSHADER_usage enum
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1256
diff changeset
   250
    MOJOSHADER_USAGE_FOG,           /* 0-15 */
285a186ad69d Note the usage index range for MOJOSHADER_usage enum
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1256
diff changeset
   251
    MOJOSHADER_USAGE_DEPTH,         /* 0-15 */
147
98043daf5027 Removed explicit numbers on enums in mojoshader.h.
Ryan C. Gordon <icculus@icculus.org>
parents: 146
diff changeset
   252
    MOJOSHADER_USAGE_SAMPLE,
1180
8abc040525ed A bunch of fixes for bugs that that American Fuzzy Lop exposed.
Ryan C. Gordon <icculus@icculus.org>
parents: 1171
diff changeset
   253
    MOJOSHADER_USAGE_TOTAL   /* housekeeping value; never returned. */
100
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   254
} MOJOSHADER_usage;
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   255
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   256
/*
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   257
 * These are the attributes to be set for a shader. "Attributes" are what
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   258
 *  Direct3D calls "Vertex Declarations Usages" ...
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   259
 *  IDirect3DDevice::CreateVertexDeclaration() would need this data, for
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   260
 *  example. Each attribute is associated with an array of data that uses one
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   261
 *  element per-vertex. So if usage==MOJOSHADER_USAGE_COLOR and index==1, that
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   262
 *  means we'd expect a secondary color array to be bound to this shader
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   263
 *  before drawing.
190
2a2fb0f656cf Added profile-specific variable names to returned parse data.
Ryan C. Gordon <icculus@icculus.org>
parents: 187
diff changeset
   264
 * (name) is a profile-specific variable name; it may be NULL if it isn't
2a2fb0f656cf Added profile-specific variable names to returned parse data.
Ryan C. Gordon <icculus@icculus.org>
parents: 187
diff changeset
   265
 *  applicable to the requested profile.
100
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   266
 */
462
af8c1ff58453 Make the C struct definitions more C++ friendly.
Ryan C. Gordon <icculus@icculus.org>
parents: 461
diff changeset
   267
typedef struct MOJOSHADER_attribute
100
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   268
{
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   269
    MOJOSHADER_usage usage;
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   270
    int index;
190
2a2fb0f656cf Added profile-specific variable names to returned parse data.
Ryan C. Gordon <icculus@icculus.org>
parents: 187
diff changeset
   271
    const char *name;
100
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   272
} MOJOSHADER_attribute;
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   273
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   274
/*
450
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 438
diff changeset
   275
 * Use this if you want to specify newly-parsed code to swizzle incoming
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 438
diff changeset
   276
 *  data. This can be useful if you know, at parse time, that a shader
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 438
diff changeset
   277
 *  will be processing data on COLOR0 that should be RGBA, but you'll
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 438
diff changeset
   278
 *  be passing it a vertex array full of ARGB instead.
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 438
diff changeset
   279
 */
462
af8c1ff58453 Make the C struct definitions more C++ friendly.
Ryan C. Gordon <icculus@icculus.org>
parents: 461
diff changeset
   280
typedef struct MOJOSHADER_swizzle
450
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 438
diff changeset
   281
{
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 438
diff changeset
   282
    MOJOSHADER_usage usage;
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 438
diff changeset
   283
    unsigned int index;
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 438
diff changeset
   284
    unsigned char swizzles[4];  /* {0,1,2,3} == .xyzw, {2,2,2,2} == .zzzz */
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 438
diff changeset
   285
} MOJOSHADER_swizzle;
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 438
diff changeset
   286
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 438
diff changeset
   287
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 438
diff changeset
   288
/*
524
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   289
 * MOJOSHADER_symbol data.
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   290
 *
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   291
 * These are used to expose high-level information in shader bytecode.
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   292
 *  They associate HLSL variables with registers. This data is used for both
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   293
 *  debugging and optimization.
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   294
 */
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   295
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   296
typedef enum
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   297
{
1180
8abc040525ed A bunch of fixes for bugs that that American Fuzzy Lop exposed.
Ryan C. Gordon <icculus@icculus.org>
parents: 1171
diff changeset
   298
    MOJOSHADER_SYMREGSET_BOOL=0,
524
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   299
    MOJOSHADER_SYMREGSET_INT4,
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   300
    MOJOSHADER_SYMREGSET_FLOAT4,
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   301
    MOJOSHADER_SYMREGSET_SAMPLER,
1180
8abc040525ed A bunch of fixes for bugs that that American Fuzzy Lop exposed.
Ryan C. Gordon <icculus@icculus.org>
parents: 1171
diff changeset
   302
    MOJOSHADER_SYMREGSET_TOTAL    /* housekeeping value; never returned. */
524
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   303
} MOJOSHADER_symbolRegisterSet;
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   304
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   305
typedef enum
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   306
{
1180
8abc040525ed A bunch of fixes for bugs that that American Fuzzy Lop exposed.
Ryan C. Gordon <icculus@icculus.org>
parents: 1171
diff changeset
   307
    MOJOSHADER_SYMCLASS_SCALAR=0,
524
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   308
    MOJOSHADER_SYMCLASS_VECTOR,
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   309
    MOJOSHADER_SYMCLASS_MATRIX_ROWS,
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   310
    MOJOSHADER_SYMCLASS_MATRIX_COLUMNS,
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   311
    MOJOSHADER_SYMCLASS_OBJECT,
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   312
    MOJOSHADER_SYMCLASS_STRUCT,
1180
8abc040525ed A bunch of fixes for bugs that that American Fuzzy Lop exposed.
Ryan C. Gordon <icculus@icculus.org>
parents: 1171
diff changeset
   313
    MOJOSHADER_SYMCLASS_TOTAL    /* housekeeping value; never returned. */
524
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   314
} MOJOSHADER_symbolClass;
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   315
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   316
typedef enum
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   317
{
1180
8abc040525ed A bunch of fixes for bugs that that American Fuzzy Lop exposed.
Ryan C. Gordon <icculus@icculus.org>
parents: 1171
diff changeset
   318
    MOJOSHADER_SYMTYPE_VOID=0,
524
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   319
    MOJOSHADER_SYMTYPE_BOOL,
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   320
    MOJOSHADER_SYMTYPE_INT,
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   321
    MOJOSHADER_SYMTYPE_FLOAT,
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   322
    MOJOSHADER_SYMTYPE_STRING,
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   323
    MOJOSHADER_SYMTYPE_TEXTURE,
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   324
    MOJOSHADER_SYMTYPE_TEXTURE1D,
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   325
    MOJOSHADER_SYMTYPE_TEXTURE2D,
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   326
    MOJOSHADER_SYMTYPE_TEXTURE3D,
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   327
    MOJOSHADER_SYMTYPE_TEXTURECUBE,
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   328
    MOJOSHADER_SYMTYPE_SAMPLER,
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   329
    MOJOSHADER_SYMTYPE_SAMPLER1D,
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   330
    MOJOSHADER_SYMTYPE_SAMPLER2D,
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   331
    MOJOSHADER_SYMTYPE_SAMPLER3D,
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   332
    MOJOSHADER_SYMTYPE_SAMPLERCUBE,
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   333
    MOJOSHADER_SYMTYPE_PIXELSHADER,
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   334
    MOJOSHADER_SYMTYPE_VERTEXSHADER,
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   335
    MOJOSHADER_SYMTYPE_PIXELFRAGMENT,
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   336
    MOJOSHADER_SYMTYPE_VERTEXFRAGMENT,
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   337
    MOJOSHADER_SYMTYPE_UNSUPPORTED,
1180
8abc040525ed A bunch of fixes for bugs that that American Fuzzy Lop exposed.
Ryan C. Gordon <icculus@icculus.org>
parents: 1171
diff changeset
   338
    MOJOSHADER_SYMTYPE_TOTAL    /* housekeeping value; never returned. */
524
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   339
} MOJOSHADER_symbolType;
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   340
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   341
typedef struct MOJOSHADER_symbolStructMember MOJOSHADER_symbolStructMember;
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   342
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   343
typedef struct MOJOSHADER_symbolTypeInfo
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   344
{
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   345
    MOJOSHADER_symbolClass parameter_class;
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   346
    MOJOSHADER_symbolType parameter_type;
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   347
    unsigned int rows;
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   348
    unsigned int columns;
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   349
    unsigned int elements;
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   350
    unsigned int member_count;
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   351
    MOJOSHADER_symbolStructMember *members;
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   352
} MOJOSHADER_symbolTypeInfo;
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   353
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   354
struct MOJOSHADER_symbolStructMember
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   355
{
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   356
    const char *name;
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   357
    MOJOSHADER_symbolTypeInfo info;
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   358
};
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   359
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   360
typedef struct MOJOSHADER_symbol
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   361
{
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   362
    const char *name;
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   363
    MOJOSHADER_symbolRegisterSet register_set;
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   364
    unsigned int register_index;
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   365
    unsigned int register_count;
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   366
    MOJOSHADER_symbolTypeInfo info;
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   367
} MOJOSHADER_symbol;
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   368
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   369
947
16af6e2b2ada Cleaned up error position reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 939
diff changeset
   370
/*
16af6e2b2ada Cleaned up error position reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 939
diff changeset
   371
 * These are used with MOJOSHADER_error as special case positions.
16af6e2b2ada Cleaned up error position reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 939
diff changeset
   372
 */
16af6e2b2ada Cleaned up error position reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 939
diff changeset
   373
#define MOJOSHADER_POSITION_NONE (-3)
16af6e2b2ada Cleaned up error position reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 939
diff changeset
   374
#define MOJOSHADER_POSITION_BEFORE (-2)
16af6e2b2ada Cleaned up error position reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 939
diff changeset
   375
#define MOJOSHADER_POSITION_AFTER (-1)
16af6e2b2ada Cleaned up error position reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 939
diff changeset
   376
536
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 524
diff changeset
   377
typedef struct MOJOSHADER_error
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   378
{
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   379
    /*
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   380
     * Human-readable error, if there is one. Will be NULL if there was no
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   381
     *  error. The string will be UTF-8 encoded, and English only. Most of
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   382
     *  these shouldn't be shown to the end-user anyhow.
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   383
     */
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   384
    const char *error;
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   385
523
699696afd731 Allow errors to specify post-processing problems.
Ryan C. Gordon <icculus@icculus.org>
parents: 515
diff changeset
   386
    /*
578
6c8f73c845e7 Allow app to specify a base filename for error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 562
diff changeset
   387
     * Filename where error happened. This can be NULL if the information
6c8f73c845e7 Allow app to specify a base filename for error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 562
diff changeset
   388
     *  isn't available.
536
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 524
diff changeset
   389
     */
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 524
diff changeset
   390
    const char *filename;
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 524
diff changeset
   391
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 524
diff changeset
   392
    /*
947
16af6e2b2ada Cleaned up error position reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 939
diff changeset
   393
     * Position of error, if there is one. Will be MOJOSHADER_POSITION_NONE if
16af6e2b2ada Cleaned up error position reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 939
diff changeset
   394
     *  there was no error, MOJOSHADER_POSITION_BEFORE if there was an error
16af6e2b2ada Cleaned up error position reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 939
diff changeset
   395
     *  before processing started, and MOJOSHADER_POSITION_AFTER if there was
16af6e2b2ada Cleaned up error position reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 939
diff changeset
   396
     *  an error during final processing. If >= 0, MOJOSHADER_parse() sets
16af6e2b2ada Cleaned up error position reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 939
diff changeset
   397
     *  this to the byte offset (starting at zero) into the bytecode you
16af6e2b2ada Cleaned up error position reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 939
diff changeset
   398
     *  supplied, and MOJOSHADER_assemble(), MOJOSHADER_parseAst(), and
16af6e2b2ada Cleaned up error position reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 939
diff changeset
   399
     *  MOJOSHADER_compile() sets this to a a line number in the source code
16af6e2b2ada Cleaned up error position reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 939
diff changeset
   400
     *  you supplied (starting at one).
475
ea119c8ce5cd Added error position information to MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 470
diff changeset
   401
     */
ea119c8ce5cd Added error position information to MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 470
diff changeset
   402
    int error_position;
536
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 524
diff changeset
   403
} MOJOSHADER_error;
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 524
diff changeset
   404
1030
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   405
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   406
/* !!! FIXME: document me. */
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   407
typedef enum MOJOSHADER_preshaderOpcode
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   408
{
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   409
    MOJOSHADER_PRESHADEROP_NOP,
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   410
    MOJOSHADER_PRESHADEROP_MOV,
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   411
    MOJOSHADER_PRESHADEROP_NEG,
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   412
    MOJOSHADER_PRESHADEROP_RCP,
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   413
    MOJOSHADER_PRESHADEROP_FRC,
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   414
    MOJOSHADER_PRESHADEROP_EXP,
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   415
    MOJOSHADER_PRESHADEROP_LOG,
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   416
    MOJOSHADER_PRESHADEROP_RSQ,
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   417
    MOJOSHADER_PRESHADEROP_SIN,
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   418
    MOJOSHADER_PRESHADEROP_COS,
1032
464f38a2fb70 Added some more preshader opcodes, cleaned up opcode handling elsewhere.
Ryan C. Gordon <icculus@icculus.org>
parents: 1030
diff changeset
   419
    MOJOSHADER_PRESHADEROP_ASIN,
464f38a2fb70 Added some more preshader opcodes, cleaned up opcode handling elsewhere.
Ryan C. Gordon <icculus@icculus.org>
parents: 1030
diff changeset
   420
    MOJOSHADER_PRESHADEROP_ACOS,
464f38a2fb70 Added some more preshader opcodes, cleaned up opcode handling elsewhere.
Ryan C. Gordon <icculus@icculus.org>
parents: 1030
diff changeset
   421
    MOJOSHADER_PRESHADEROP_ATAN,
464f38a2fb70 Added some more preshader opcodes, cleaned up opcode handling elsewhere.
Ryan C. Gordon <icculus@icculus.org>
parents: 1030
diff changeset
   422
    MOJOSHADER_PRESHADEROP_MIN,
464f38a2fb70 Added some more preshader opcodes, cleaned up opcode handling elsewhere.
Ryan C. Gordon <icculus@icculus.org>
parents: 1030
diff changeset
   423
    MOJOSHADER_PRESHADEROP_MAX,
1035
5855d767e4b2 Changed CMPLT and CMPGE to LT and GE, to match what fxc spits out.
Ryan C. Gordon <icculus@icculus.org>
parents: 1034
diff changeset
   424
    MOJOSHADER_PRESHADEROP_LT,
5855d767e4b2 Changed CMPLT and CMPGE to LT and GE, to match what fxc spits out.
Ryan C. Gordon <icculus@icculus.org>
parents: 1034
diff changeset
   425
    MOJOSHADER_PRESHADEROP_GE,
1032
464f38a2fb70 Added some more preshader opcodes, cleaned up opcode handling elsewhere.
Ryan C. Gordon <icculus@icculus.org>
parents: 1030
diff changeset
   426
    MOJOSHADER_PRESHADEROP_ADD,
464f38a2fb70 Added some more preshader opcodes, cleaned up opcode handling elsewhere.
Ryan C. Gordon <icculus@icculus.org>
parents: 1030
diff changeset
   427
    MOJOSHADER_PRESHADEROP_MUL,
464f38a2fb70 Added some more preshader opcodes, cleaned up opcode handling elsewhere.
Ryan C. Gordon <icculus@icculus.org>
parents: 1030
diff changeset
   428
    MOJOSHADER_PRESHADEROP_ATAN2,
1033
b72073c4820e Added DIV preshader opcode.
Ryan C. Gordon <icculus@icculus.org>
parents: 1032
diff changeset
   429
    MOJOSHADER_PRESHADEROP_DIV,
1032
464f38a2fb70 Added some more preshader opcodes, cleaned up opcode handling elsewhere.
Ryan C. Gordon <icculus@icculus.org>
parents: 1030
diff changeset
   430
    MOJOSHADER_PRESHADEROP_CMP,
1034
549f160533fa Found, I think, the final preshader opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1033
diff changeset
   431
    MOJOSHADER_PRESHADEROP_MOVC,
1032
464f38a2fb70 Added some more preshader opcodes, cleaned up opcode handling elsewhere.
Ryan C. Gordon <icculus@icculus.org>
parents: 1030
diff changeset
   432
    MOJOSHADER_PRESHADEROP_DOT,
1034
549f160533fa Found, I think, the final preshader opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1033
diff changeset
   433
    MOJOSHADER_PRESHADEROP_NOISE,
1032
464f38a2fb70 Added some more preshader opcodes, cleaned up opcode handling elsewhere.
Ryan C. Gordon <icculus@icculus.org>
parents: 1030
diff changeset
   434
    MOJOSHADER_PRESHADEROP_SCALAR_OPS,
464f38a2fb70 Added some more preshader opcodes, cleaned up opcode handling elsewhere.
Ryan C. Gordon <icculus@icculus.org>
parents: 1030
diff changeset
   435
    MOJOSHADER_PRESHADEROP_MIN_SCALAR = MOJOSHADER_PRESHADEROP_SCALAR_OPS,
464f38a2fb70 Added some more preshader opcodes, cleaned up opcode handling elsewhere.
Ryan C. Gordon <icculus@icculus.org>
parents: 1030
diff changeset
   436
    MOJOSHADER_PRESHADEROP_MAX_SCALAR,
1035
5855d767e4b2 Changed CMPLT and CMPGE to LT and GE, to match what fxc spits out.
Ryan C. Gordon <icculus@icculus.org>
parents: 1034
diff changeset
   437
    MOJOSHADER_PRESHADEROP_LT_SCALAR,
5855d767e4b2 Changed CMPLT and CMPGE to LT and GE, to match what fxc spits out.
Ryan C. Gordon <icculus@icculus.org>
parents: 1034
diff changeset
   438
    MOJOSHADER_PRESHADEROP_GE_SCALAR,
1032
464f38a2fb70 Added some more preshader opcodes, cleaned up opcode handling elsewhere.
Ryan C. Gordon <icculus@icculus.org>
parents: 1030
diff changeset
   439
    MOJOSHADER_PRESHADEROP_ADD_SCALAR,
464f38a2fb70 Added some more preshader opcodes, cleaned up opcode handling elsewhere.
Ryan C. Gordon <icculus@icculus.org>
parents: 1030
diff changeset
   440
    MOJOSHADER_PRESHADEROP_MUL_SCALAR,
464f38a2fb70 Added some more preshader opcodes, cleaned up opcode handling elsewhere.
Ryan C. Gordon <icculus@icculus.org>
parents: 1030
diff changeset
   441
    MOJOSHADER_PRESHADEROP_ATAN2_SCALAR,
1033
b72073c4820e Added DIV preshader opcode.
Ryan C. Gordon <icculus@icculus.org>
parents: 1032
diff changeset
   442
    MOJOSHADER_PRESHADEROP_DIV_SCALAR,
1032
464f38a2fb70 Added some more preshader opcodes, cleaned up opcode handling elsewhere.
Ryan C. Gordon <icculus@icculus.org>
parents: 1030
diff changeset
   443
    MOJOSHADER_PRESHADEROP_DOT_SCALAR,
1235
8fd6c5efe453 -Wpedantic fixes
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1229
diff changeset
   444
    MOJOSHADER_PRESHADEROP_NOISE_SCALAR
1030
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   445
} MOJOSHADER_preshaderOpcode;
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   446
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   447
typedef enum MOJOSHADER_preshaderOperandType
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   448
{
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   449
    MOJOSHADER_PRESHADEROPERAND_INPUT,
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   450
    MOJOSHADER_PRESHADEROPERAND_OUTPUT,
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   451
    MOJOSHADER_PRESHADEROPERAND_LITERAL,
1235
8fd6c5efe453 -Wpedantic fixes
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1229
diff changeset
   452
    MOJOSHADER_PRESHADEROPERAND_TEMP
1030
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   453
} MOJOSHADER_preshaderOperandType;
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   454
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   455
typedef struct MOJOSHADER_preshaderOperand
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   456
{
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   457
    MOJOSHADER_preshaderOperandType type;
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   458
    unsigned int index;
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1143
diff changeset
   459
    unsigned int array_register_count;
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1143
diff changeset
   460
    unsigned int *array_registers;
1030
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   461
} MOJOSHADER_preshaderOperand;
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   462
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   463
typedef struct MOJOSHADER_preshaderInstruction
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   464
{
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   465
    MOJOSHADER_preshaderOpcode opcode;
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   466
    unsigned int element_count;
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   467
    unsigned int operand_count;
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1143
diff changeset
   468
    MOJOSHADER_preshaderOperand operands[4];
1030
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   469
} MOJOSHADER_preshaderInstruction;
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   470
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   471
typedef struct MOJOSHADER_preshader
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   472
{
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   473
    unsigned int literal_count;
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   474
    double *literals;
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   475
    unsigned int temp_count;  /* scalar, not vector! */
1042
cb6659f80bb9 Export symbol information for preshaders.
Ryan C. Gordon <icculus@icculus.org>
parents: 1040
diff changeset
   476
    unsigned int symbol_count;
cb6659f80bb9 Export symbol information for preshaders.
Ryan C. Gordon <icculus@icculus.org>
parents: 1040
diff changeset
   477
    MOJOSHADER_symbol *symbols;
1030
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   478
    unsigned int instruction_count;
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   479
    MOJOSHADER_preshaderInstruction *instructions;
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1143
diff changeset
   480
    unsigned int register_count;
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1143
diff changeset
   481
    float *registers;
1164
006194daea99 MOJOSHADER_parsePreshader() cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1156
diff changeset
   482
    MOJOSHADER_malloc malloc;
006194daea99 MOJOSHADER_parsePreshader() cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1156
diff changeset
   483
    MOJOSHADER_free free;
006194daea99 MOJOSHADER_parsePreshader() cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1156
diff changeset
   484
    void *malloc_data;
1030
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   485
} MOJOSHADER_preshader;
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   486
536
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 524
diff changeset
   487
/*
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 524
diff changeset
   488
 * Structure used to return data from parsing of a shader...
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 524
diff changeset
   489
 */
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 524
diff changeset
   490
/* !!! FIXME: most of these ints should be unsigned. */
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 524
diff changeset
   491
typedef struct MOJOSHADER_parseData
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 524
diff changeset
   492
{
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 524
diff changeset
   493
    /*
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 524
diff changeset
   494
     * The number of elements pointed to by (errors).
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 524
diff changeset
   495
     */
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 524
diff changeset
   496
    int error_count;
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 524
diff changeset
   497
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 524
diff changeset
   498
    /*
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 524
diff changeset
   499
     * (error_count) elements of data that specify errors that were generated
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 524
diff changeset
   500
     *  by parsing this shader.
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 524
diff changeset
   501
     * This can be NULL if there were no errors or if (error_count) is zero.
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 524
diff changeset
   502
     */
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 524
diff changeset
   503
    MOJOSHADER_error *errors;
475
ea119c8ce5cd Added error position information to MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 470
diff changeset
   504
ea119c8ce5cd Added error position information to MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 470
diff changeset
   505
    /*
187
1c709f65cf1b Store profile string in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   506
     * The name of the profile used to parse the shader. Will be NULL on error.
1c709f65cf1b Store profile string in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   507
     */
1c709f65cf1b Store profile string in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   508
    const char *profile;
1c709f65cf1b Store profile string in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   509
1c709f65cf1b Store profile string in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   510
    /*
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   511
     * Bytes of output from parsing. Most profiles produce a string of source
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   512
     *  code, but profiles that do binary output may not be text at all.
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   513
     *  Will be NULL on error.
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   514
     */
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   515
    const char *output;
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   516
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   517
    /*
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   518
     * Byte count for output, not counting any null terminator. Most profiles
113
8ebf445c5305 Print output in testparse.c byte-by-byte instead of as an ASCIZ string.
Ryan C. Gordon <icculus@icculus.org>
parents: 109
diff changeset
   519
     *  produce an ASCII string of source code (which will be null-terminated
8ebf445c5305 Print output in testparse.c byte-by-byte instead of as an ASCIZ string.
Ryan C. Gordon <icculus@icculus.org>
parents: 109
diff changeset
   520
     *  even though that null char isn't included in output_len), but profiles
8ebf445c5305 Print output in testparse.c byte-by-byte instead of as an ASCIZ string.
Ryan C. Gordon <icculus@icculus.org>
parents: 109
diff changeset
   521
     *  that do binary output may not be text at all. Will be 0 on error.
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   522
     */
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   523
    int output_len;
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   524
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   525
    /*
356
8e23d7eb90d9 Better attempt at instruction counts, with official numbers from msdn.
Ryan C. Gordon <icculus@icculus.org>
parents: 354
diff changeset
   526
     * Count of Direct3D instruction slots used. This is meaningless in terms
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   527
     *  of the actual output, as the profile will probably grow or reduce
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   528
     *  the count (or for high-level languages, not have that information at
356
8e23d7eb90d9 Better attempt at instruction counts, with official numbers from msdn.
Ryan C. Gordon <icculus@icculus.org>
parents: 354
diff changeset
   529
     *  all). Also, as with Microsoft's own assembler, this value is just a
8e23d7eb90d9 Better attempt at instruction counts, with official numbers from msdn.
Ryan C. Gordon <icculus@icculus.org>
parents: 354
diff changeset
   530
     *  rough estimate, as unpredicable real-world factors make the actual
8e23d7eb90d9 Better attempt at instruction counts, with official numbers from msdn.
Ryan C. Gordon <icculus@icculus.org>
parents: 354
diff changeset
   531
     *  value vary at least a little from this count. Still, it can give you
8e23d7eb90d9 Better attempt at instruction counts, with official numbers from msdn.
Ryan C. Gordon <icculus@icculus.org>
parents: 354
diff changeset
   532
     *  a rough idea of the size of your shader. Will be zero on error.
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   533
     */
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   534
    int instruction_count;
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   535
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   536
    /*
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   537
     * The type of shader we parsed. Will be MOJOSHADER_TYPE_UNKNOWN on error.
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   538
     */
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   539
    MOJOSHADER_shaderType shader_type;
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   540
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   541
    /*
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   542
     * The shader's major version. If this was a "vs_3_0", this would be 3.
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   543
     */
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   544
    int major_ver;
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   545
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   546
    /*
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   547
     * The shader's minor version. If this was a "ps_1_4", this would be 4.
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   548
     *  Two notes: for "vs_2_x", this is 1, and for "vs_3_sw", this is 255.
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   549
     */
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   550
    int minor_ver;
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   551
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   552
    /*
1171
9f27482a2f58 Report the main function name in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1164
diff changeset
   553
     * This is the main function name of the shader. This will be the
9f27482a2f58 Report the main function name in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1164
diff changeset
   554
     *  caller-supplied string even if a given profile ignores it (GLSL,
9f27482a2f58 Report the main function name in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1164
diff changeset
   555
     *  for example, always uses "main" in the shader output out of necessity,
9f27482a2f58 Report the main function name in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1164
diff changeset
   556
     *  and Direct3D assembly has no concept of a "main function", etc).
9f27482a2f58 Report the main function name in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1164
diff changeset
   557
     *  Otherwise, it'll be a default name chosen by the profile ("main") or
1156
6e760a19f456 Added support for producing shader language source code for Apple's Metal API.
Ryan C. Gordon <icculus@icculus.org>
parents: 1150
diff changeset
   558
     *  whatnot.
6e760a19f456 Added support for producing shader language source code for Apple's Metal API.
Ryan C. Gordon <icculus@icculus.org>
parents: 1150
diff changeset
   559
     */
6e760a19f456 Added support for producing shader language source code for Apple's Metal API.
Ryan C. Gordon <icculus@icculus.org>
parents: 1150
diff changeset
   560
    const char *mainfn;
6e760a19f456 Added support for producing shader language source code for Apple's Metal API.
Ryan C. Gordon <icculus@icculus.org>
parents: 1150
diff changeset
   561
6e760a19f456 Added support for producing shader language source code for Apple's Metal API.
Ryan C. Gordon <icculus@icculus.org>
parents: 1150
diff changeset
   562
    /*
92
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
   563
     * The number of elements pointed to by (uniforms).
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
   564
     */
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
   565
    int uniform_count;
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
   566
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
   567
    /*
94
57adfb4769a0 Simplifed public uniform information.
Ryan C. Gordon <icculus@icculus.org>
parents: 92
diff changeset
   568
     * (uniform_count) elements of data that specify Uniforms to be set for
57adfb4769a0 Simplifed public uniform information.
Ryan C. Gordon <icculus@icculus.org>
parents: 92
diff changeset
   569
     *  this shader. See discussion on MOJOSHADER_uniform for details.
145
5325c8d6077c Don't create unnecessary attributes.
Ryan C. Gordon <icculus@icculus.org>
parents: 113
diff changeset
   570
     * This can be NULL on error or if (uniform_count) is zero.
92
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
   571
     */
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
   572
    MOJOSHADER_uniform *uniforms;
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
   573
100
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   574
    /*
278
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 276
diff changeset
   575
     * The number of elements pointed to by (constants).
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 276
diff changeset
   576
     */
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 276
diff changeset
   577
    int constant_count;
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 276
diff changeset
   578
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 276
diff changeset
   579
    /*
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 276
diff changeset
   580
     * (constant_count) elements of data that specify constants used in
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 276
diff changeset
   581
     *  this shader. See discussion on MOJOSHADER_constant for details.
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 276
diff changeset
   582
     * This can be NULL on error or if (constant_count) is zero.
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 276
diff changeset
   583
     *  This is largely informational: constants are hardcoded into a shader.
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 276
diff changeset
   584
     *  The constants that you can set like parameters are in the "uniforms"
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 276
diff changeset
   585
     *  list.
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 276
diff changeset
   586
     */
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 276
diff changeset
   587
    MOJOSHADER_constant *constants;
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 276
diff changeset
   588
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 276
diff changeset
   589
    /*
148
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   590
     * The number of elements pointed to by (samplers).
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   591
     */
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   592
    int sampler_count;
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   593
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   594
    /*
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   595
     * (sampler_count) elements of data that specify Samplers to be set for
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   596
     *  this shader. See discussion on MOJOSHADER_sampler for details.
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   597
     * This can be NULL on error or if (sampler_count) is zero.
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   598
     */
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   599
    MOJOSHADER_sampler *samplers;
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   600
1055
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1043
diff changeset
   601
    /* !!! FIXME: this should probably be "input" and not "attribute" */
148
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   602
    /*
100
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   603
     * The number of elements pointed to by (attributes).
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   604
     */
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   605
    int attribute_count;
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   606
1055
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1043
diff changeset
   607
    /* !!! FIXME: this should probably be "input" and not "attribute" */
100
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   608
    /*
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   609
     * (attribute_count) elements of data that specify Attributes to be set
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   610
     *  for this shader. See discussion on MOJOSHADER_attribute for details.
145
5325c8d6077c Don't create unnecessary attributes.
Ryan C. Gordon <icculus@icculus.org>
parents: 113
diff changeset
   611
     * This can be NULL on error or if (attribute_count) is zero.
100
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   612
     */
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   613
    MOJOSHADER_attribute *attributes;
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   614
92
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
   615
    /*
1055
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1043
diff changeset
   616
     * The number of elements pointed to by (outputs).
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1043
diff changeset
   617
     */
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1043
diff changeset
   618
    int output_count;
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1043
diff changeset
   619
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1043
diff changeset
   620
    /*
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1043
diff changeset
   621
     * (output_count) elements of data that specify outputs this shader
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1043
diff changeset
   622
     *  writes to. See discussion on MOJOSHADER_attribute for details.
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1043
diff changeset
   623
     * This can be NULL on error or if (output_count) is zero.
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1043
diff changeset
   624
     */
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1043
diff changeset
   625
    MOJOSHADER_attribute *outputs;
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1043
diff changeset
   626
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1043
diff changeset
   627
    /*
450
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 438
diff changeset
   628
     * The number of elements pointed to by (swizzles).
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 438
diff changeset
   629
     */
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 438
diff changeset
   630
    int swizzle_count;
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 438
diff changeset
   631
1055
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1043
diff changeset
   632
    /* !!! FIXME: this should probably be "input" and not "attribute" */
450
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 438
diff changeset
   633
    /*
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 438
diff changeset
   634
     * (swizzle_count) elements of data that specify swizzles the shader will
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 438
diff changeset
   635
     *  apply to incoming attributes. This is a copy of what was passed to
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 438
diff changeset
   636
     *  MOJOSHADER_parseData().
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 438
diff changeset
   637
     * This can be NULL on error or if (swizzle_count) is zero.
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 438
diff changeset
   638
     */
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 438
diff changeset
   639
    MOJOSHADER_swizzle *swizzles;
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 438
diff changeset
   640
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 438
diff changeset
   641
    /*
524
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   642
     * The number of elements pointed to by (symbols).
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   643
     */
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   644
    int symbol_count;
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   645
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   646
    /*
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   647
     * (symbol_count) elements of data that specify high-level symbol data
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   648
     *  for the shader. This will be parsed from the CTAB section
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   649
     *  in bytecode, and will be a copy of what you provide to
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   650
     *  MOJOSHADER_assemble(). This data is optional.
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   651
     * This can be NULL on error or if (symbol_count) is zero.
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   652
     */
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   653
    MOJOSHADER_symbol *symbols;
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   654
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   655
    /*
1030
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   656
     * !!! FIXME: document me.
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   657
     * This can be NULL on error or if no preshader was available.
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   658
     */
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   659
    MOJOSHADER_preshader *preshader;
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   660
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   661
    /*
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   662
     * This is the malloc implementation you passed to MOJOSHADER_parse().
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   663
     */
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   664
    MOJOSHADER_malloc malloc;
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   665
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   666
    /*
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   667
     * This is the free implementation you passed to MOJOSHADER_parse().
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   668
     */
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   669
    MOJOSHADER_free free;
97
4a41e3d17297 Allow instance data to be passed to the allocator.
Ryan C. Gordon <icculus@icculus.org>
parents: 94
diff changeset
   670
4a41e3d17297 Allow instance data to be passed to the allocator.
Ryan C. Gordon <icculus@icculus.org>
parents: 94
diff changeset
   671
    /*
4a41e3d17297 Allow instance data to be passed to the allocator.
Ryan C. Gordon <icculus@icculus.org>
parents: 94
diff changeset
   672
     * This is the pointer you passed as opaque data for your allocator.
4a41e3d17297 Allow instance data to be passed to the allocator.
Ryan C. Gordon <icculus@icculus.org>
parents: 94
diff changeset
   673
     */
4a41e3d17297 Allow instance data to be passed to the allocator.
Ryan C. Gordon <icculus@icculus.org>
parents: 94
diff changeset
   674
    void *malloc_data;
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   675
} MOJOSHADER_parseData;
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   676
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   677
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   678
/*
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   679
 * Profile string for Direct3D assembly language output.
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   680
 */
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   681
#define MOJOSHADER_PROFILE_D3D "d3d"
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   682
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   683
/*
109
48e95cf41505 Added "passthrough" profile, which just sends the bytecode through unchanged;
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   684
 * Profile string for passthrough of the original bytecode, unchanged.
48e95cf41505 Added "passthrough" profile, which just sends the bytecode through unchanged;
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   685
 */
469
b8cfaae6c4af Renamed "passthrough" profile to "bytecode"
Ryan C. Gordon <icculus@icculus.org>
parents: 465
diff changeset
   686
#define MOJOSHADER_PROFILE_BYTECODE "bytecode"
109
48e95cf41505 Added "passthrough" profile, which just sends the bytecode through unchanged;
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   687
48e95cf41505 Added "passthrough" profile, which just sends the bytecode through unchanged;
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   688
/*
1255
0135d797e287 Implement HLSL emitter, MOJOSHADER_d3d11 API
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1245
diff changeset
   689
 * Profile string for HLSL Shader Model 4 output.
0135d797e287 Implement HLSL emitter, MOJOSHADER_d3d11 API
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1245
diff changeset
   690
 */
0135d797e287 Implement HLSL emitter, MOJOSHADER_d3d11 API
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1245
diff changeset
   691
#define MOJOSHADER_PROFILE_HLSL "hlsl"
0135d797e287 Implement HLSL emitter, MOJOSHADER_d3d11 API
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1245
diff changeset
   692
0135d797e287 Implement HLSL emitter, MOJOSHADER_d3d11 API
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1245
diff changeset
   693
/*
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   694
 * Profile string for GLSL: OpenGL high-level shader language output.
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   695
 */
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   696
#define MOJOSHADER_PROFILE_GLSL "glsl"
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   697
323
b60c88ec8182 Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 284
diff changeset
   698
/*
407
620d48c5d13a Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 361
diff changeset
   699
 * Profile string for GLSL 1.20: minor improvements to base GLSL spec.
620d48c5d13a Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 361
diff changeset
   700
 */
620d48c5d13a Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 361
diff changeset
   701
#define MOJOSHADER_PROFILE_GLSL120 "glsl120"
620d48c5d13a Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 361
diff changeset
   702
620d48c5d13a Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 361
diff changeset
   703
/*
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1143
diff changeset
   704
 * Profile string for GLSL ES: minor changes to GLSL output for ES compliance.
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1143
diff changeset
   705
 */
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1143
diff changeset
   706
#define MOJOSHADER_PROFILE_GLSLES "glsles"
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1143
diff changeset
   707
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1143
diff changeset
   708
/*
323
b60c88ec8182 Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 284
diff changeset
   709
 * Profile string for OpenGL ARB 1.0 shaders: GL_ARB_(vertex|fragment)_program.
b60c88ec8182 Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 284
diff changeset
   710
 */
b60c88ec8182 Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 284
diff changeset
   711
#define MOJOSHADER_PROFILE_ARB1 "arb1"
b60c88ec8182 Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 284
diff changeset
   712
361
9fa6652cacbd First (untested) work on nv2 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 356
diff changeset
   713
/*
9fa6652cacbd First (untested) work on nv2 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 356
diff changeset
   714
 * Profile string for OpenGL ARB 1.0 shaders with Nvidia 2.0 extensions:
9fa6652cacbd First (untested) work on nv2 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 356
diff changeset
   715
 *  GL_NV_vertex_program2_option and GL_NV_fragment_program2
9fa6652cacbd First (untested) work on nv2 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 356
diff changeset
   716
 */
9fa6652cacbd First (untested) work on nv2 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 356
diff changeset
   717
#define MOJOSHADER_PROFILE_NV2 "nv2"
9fa6652cacbd First (untested) work on nv2 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 356
diff changeset
   718
9fa6652cacbd First (untested) work on nv2 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 356
diff changeset
   719
/*
9fa6652cacbd First (untested) work on nv2 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 356
diff changeset
   720
 * Profile string for OpenGL ARB 1.0 shaders with Nvidia 3.0 extensions:
9fa6652cacbd First (untested) work on nv2 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 356
diff changeset
   721
 *  GL_NV_vertex_program3 and GL_NV_fragment_program2
9fa6652cacbd First (untested) work on nv2 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 356
diff changeset
   722
 */
421
bfd3d95273ec First piece of work on nv3 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 407
diff changeset
   723
#define MOJOSHADER_PROFILE_NV3 "nv3"
361
9fa6652cacbd First (untested) work on nv2 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 356
diff changeset
   724
9fa6652cacbd First (untested) work on nv2 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 356
diff changeset
   725
/*
9fa6652cacbd First (untested) work on nv2 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 356
diff changeset
   726
 * Profile string for OpenGL ARB 1.0 shaders with Nvidia 4.0 extensions:
454
70c9818840eb Happy September. Minor comment tweak.
Ryan C. Gordon <icculus@icculus.org>
parents: 450
diff changeset
   727
 *  GL_NV_gpu_program4
361
9fa6652cacbd First (untested) work on nv2 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 356
diff changeset
   728
 */
431
0d0cbe10db02 First shot at nv4 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 422
diff changeset
   729
#define MOJOSHADER_PROFILE_NV4 "nv4"
361
9fa6652cacbd First (untested) work on nv2 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 356
diff changeset
   730
458
b91904879798 Added MOJOSHADER_maxShaderModel().
Ryan C. Gordon <icculus@icculus.org>
parents: 455
diff changeset
   731
/*
1156
6e760a19f456 Added support for producing shader language source code for Apple's Metal API.
Ryan C. Gordon <icculus@icculus.org>
parents: 1150
diff changeset
   732
 * Profile string for Metal: Apple's lowlevel API's high-level shader language.
6e760a19f456 Added support for producing shader language source code for Apple's Metal API.
Ryan C. Gordon <icculus@icculus.org>
parents: 1150
diff changeset
   733
 */
6e760a19f456 Added support for producing shader language source code for Apple's Metal API.
Ryan C. Gordon <icculus@icculus.org>
parents: 1150
diff changeset
   734
#define MOJOSHADER_PROFILE_METAL "metal"
6e760a19f456 Added support for producing shader language source code for Apple's Metal API.
Ryan C. Gordon <icculus@icculus.org>
parents: 1150
diff changeset
   735
6e760a19f456 Added support for producing shader language source code for Apple's Metal API.
Ryan C. Gordon <icculus@icculus.org>
parents: 1150
diff changeset
   736
/*
1224
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1210
diff changeset
   737
 * Profile string for SPIR-V binary output
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1210
diff changeset
   738
 */
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1210
diff changeset
   739
#define MOJOSHADER_PROFILE_SPIRV "spirv"
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1210
diff changeset
   740
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1210
diff changeset
   741
/*
1225
50b8dd7e0b1a Add GLSPIRV profile, to allow for both GL- and VK-friendly SPIR-V output
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1224
diff changeset
   742
 * Profile string for ARB_gl_spirv-friendly SPIR-V binary output
50b8dd7e0b1a Add GLSPIRV profile, to allow for both GL- and VK-friendly SPIR-V output
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1224
diff changeset
   743
 */
50b8dd7e0b1a Add GLSPIRV profile, to allow for both GL- and VK-friendly SPIR-V output
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1224
diff changeset
   744
#define MOJOSHADER_PROFILE_GLSPIRV "glspirv"
50b8dd7e0b1a Add GLSPIRV profile, to allow for both GL- and VK-friendly SPIR-V output
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1224
diff changeset
   745
50b8dd7e0b1a Add GLSPIRV profile, to allow for both GL- and VK-friendly SPIR-V output
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1224
diff changeset
   746
/*
458
b91904879798 Added MOJOSHADER_maxShaderModel().
Ryan C. Gordon <icculus@icculus.org>
parents: 455
diff changeset
   747
 * Determine the highest supported Shader Model for a profile.
b91904879798 Added MOJOSHADER_maxShaderModel().
Ryan C. Gordon <icculus@icculus.org>
parents: 455
diff changeset
   748
 */
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1143
diff changeset
   749
DECLSPEC int MOJOSHADER_maxShaderModel(const char *profile);
458
b91904879798 Added MOJOSHADER_maxShaderModel().
Ryan C. Gordon <icculus@icculus.org>
parents: 455
diff changeset
   750
97
4a41e3d17297 Allow instance data to be passed to the allocator.
Ryan C. Gordon <icculus@icculus.org>
parents: 94
diff changeset
   751
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   752
/*
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   753
 * Parse a compiled Direct3D shader's bytecode.
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   754
 *
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   755
 * This is your primary entry point into MojoShader. You need to pass it
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   756
 *  a compiled D3D shader and tell it which "profile" you want to use to
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   757
 *  convert it into useful data.
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   758
 *
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   759
 * The available profiles are the set of MOJOSHADER_PROFILE_* defines.
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   760
 *  Note that MojoShader may be built without support for all listed
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   761
 *  profiles (in which case using one here will return with an error).
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   762
 *
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   763
 * As parsing requires some memory to be allocated, you may provide a custom
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   764
 *  allocator to this function, which will be used to allocate/free memory.
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   765
 *  They function just like malloc() and free(). We do not use realloc().
97
4a41e3d17297 Allow instance data to be passed to the allocator.
Ryan C. Gordon <icculus@icculus.org>
parents: 94
diff changeset
   766
 *  If you don't care, pass NULL in for the allocator functions. If your
4a41e3d17297 Allow instance data to be passed to the allocator.
Ryan C. Gordon <icculus@icculus.org>
parents: 94
diff changeset
   767
 *  allocator needs instance-specific data, you may supply it with the
4a41e3d17297 Allow instance data to be passed to the allocator.
Ryan C. Gordon <icculus@icculus.org>
parents: 94
diff changeset
   768
 *  (d) parameter. This pointer is passed as-is to your (m) and (f) functions.
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   769
 *
97
4a41e3d17297 Allow instance data to be passed to the allocator.
Ryan C. Gordon <icculus@icculus.org>
parents: 94
diff changeset
   770
 * This function returns a MOJOSHADER_parseData.
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   771
 *
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   772
 * This function will never return NULL, even if the system is completely
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   773
 *  out of memory upon entry (in which case, this function returns a static
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   774
 *  MOJOSHADER_parseData object, which is still safe to pass to
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   775
 *  MOJOSHADER_freeParseData()).
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   776
 *
450
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 438
diff changeset
   777
 * You can tell the generated program to swizzle certain inputs. If you know
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 438
diff changeset
   778
 *  that COLOR0 should be RGBA but you're passing in ARGB, you can specify
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 438
diff changeset
   779
 *  a swizzle of { MOJOSHADER_USAGE_COLOR, 0, {1,2,3,0} } to (swiz). If the
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 438
diff changeset
   780
 *  input register in the code would produce reg.ywzx, that swizzle would
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 438
diff changeset
   781
 *  change it to reg.wzxy ... (swiz) can be NULL.
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 438
diff changeset
   782
 *
1104
9147482e1ec7 Allow sampler type remapping.
Ryan C. Gordon <icculus@icculus.org>
parents: 1090
diff changeset
   783
 * You can force the shader to expect samplers of certain types. Generally
9147482e1ec7 Allow sampler type remapping.
Ryan C. Gordon <icculus@icculus.org>
parents: 1090
diff changeset
   784
 *  you don't need this, as Shader Model 2 and later always specify what they
9147482e1ec7 Allow sampler type remapping.
Ryan C. Gordon <icculus@icculus.org>
parents: 1090
diff changeset
   785
 *  expect samplers to be (2D, cubemap, etc). Shader Model 1, however, just
9147482e1ec7 Allow sampler type remapping.
Ryan C. Gordon <icculus@icculus.org>
parents: 1090
diff changeset
   786
 *  uses whatever is bound to a given sampler at draw time, but this doesn't
9147482e1ec7 Allow sampler type remapping.
Ryan C. Gordon <icculus@icculus.org>
parents: 1090
diff changeset
   787
 *  work in OpenGL, etc. In these cases, MojoShader will default to
1106
2bef26cc20f9 More work on sampler remapping...3D should probably default to cubemaps, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 1104
diff changeset
   788
 *  2D texture sampling (or cubemap sampling, in cases where it makes sense,
2bef26cc20f9 More work on sampler remapping...3D should probably default to cubemaps, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 1104
diff changeset
   789
 *  like the TEXM3X3TEX opcode), which works 75% of the time, but if you
2bef26cc20f9 More work on sampler remapping...3D should probably default to cubemaps, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 1104
diff changeset
   790
 *  really needed something else, you'll need to specify it here. This can
2bef26cc20f9 More work on sampler remapping...3D should probably default to cubemaps, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 1104
diff changeset
   791
 *  also be used, at your own risk, to override DCL opcodes in shaders: if
2bef26cc20f9 More work on sampler remapping...3D should probably default to cubemaps, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 1104
diff changeset
   792
 *  the shader explicit says 2D, but you want Cubemap, for example, you can
2bef26cc20f9 More work on sampler remapping...3D should probably default to cubemaps, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 1104
diff changeset
   793
 *  use this to override. If you aren't sure about any of this stuff, you can
2bef26cc20f9 More work on sampler remapping...3D should probably default to cubemaps, etc.
Ryan C. Gordon <icculus@icculus.org>
parents: 1104
diff changeset
   794
 *  (and should) almost certainly ignore it: (smap) can be NULL.
1104
9147482e1ec7 Allow sampler type remapping.
Ryan C. Gordon <icculus@icculus.org>
parents: 1090
diff changeset
   795
 *
1143
e4027cbe2116 Make parsing shaders possible without knowing the token buffer size.
Ryan C. Gordon <icculus@icculus.org>
parents: 1117
diff changeset
   796
 * (bufsize) is the size in bytes of (tokenbuf). If (bufsize) is zero,
e4027cbe2116 Make parsing shaders possible without knowing the token buffer size.
Ryan C. Gordon <icculus@icculus.org>
parents: 1117
diff changeset
   797
 *  MojoShader will attempt to figure out the size of the buffer, but you
e4027cbe2116 Make parsing shaders possible without knowing the token buffer size.
Ryan C. Gordon <icculus@icculus.org>
parents: 1117
diff changeset
   798
 *  risk a buffer overflow if you have corrupt data, etc. Supply the value
e4027cbe2116 Make parsing shaders possible without knowing the token buffer size.
Ryan C. Gordon <icculus@icculus.org>
parents: 1117
diff changeset
   799
 *  if you can.
e4027cbe2116 Make parsing shaders possible without knowing the token buffer size.
Ryan C. Gordon <icculus@icculus.org>
parents: 1117
diff changeset
   800
 *
1156
6e760a19f456 Added support for producing shader language source code for Apple's Metal API.
Ryan C. Gordon <icculus@icculus.org>
parents: 1150
diff changeset
   801
 * You should pass a name for your shader's main function in here, via the
6e760a19f456 Added support for producing shader language source code for Apple's Metal API.
Ryan C. Gordon <icculus@icculus.org>
parents: 1150
diff changeset
   802
 *  (mainfn) param. Some profiles need this name to be unique. Passing a NULL
6e760a19f456 Added support for producing shader language source code for Apple's Metal API.
Ryan C. Gordon <icculus@icculus.org>
parents: 1150
diff changeset
   803
 *  here will pick a reasonable default, and most profiles will ignore it
6e760a19f456 Added support for producing shader language source code for Apple's Metal API.
Ryan C. Gordon <icculus@icculus.org>
parents: 1150
diff changeset
   804
 *  anyhow. As the name of the shader's main function, etc, so make it a
6e760a19f456 Added support for producing shader language source code for Apple's Metal API.
Ryan C. Gordon <icculus@icculus.org>
parents: 1150
diff changeset
   805
 *  simple name that would match C's identifier rules. Keep it simple!
6e760a19f456 Added support for producing shader language source code for Apple's Metal API.
Ryan C. Gordon <icculus@icculus.org>
parents: 1150
diff changeset
   806
 *
187
1c709f65cf1b Store profile string in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   807
 * This function is thread safe, so long as (m) and (f) are too, and that
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   808
 *  (tokenbuf) remains intact for the duration of the call. This allows you
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   809
 *  to parse several shaders on separate CPU cores at the same time.
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   810
 */
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1143
diff changeset
   811
DECLSPEC const MOJOSHADER_parseData *MOJOSHADER_parse(const char *profile,
1156
6e760a19f456 Added support for producing shader language source code for Apple's Metal API.
Ryan C. Gordon <icculus@icculus.org>
parents: 1150
diff changeset
   812
                                                      const char *mainfn,
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1143
diff changeset
   813
                                                      const unsigned char *tokenbuf,
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1143
diff changeset
   814
                                                      const unsigned int bufsize,
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1143
diff changeset
   815
                                                      const MOJOSHADER_swizzle *swiz,
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1143
diff changeset
   816
                                                      const unsigned int swizcount,
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1143
diff changeset
   817
                                                      const MOJOSHADER_samplerMap *smap,
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1143
diff changeset
   818
                                                      const unsigned int smapcount,
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1143
diff changeset
   819
                                                      MOJOSHADER_malloc m,
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1143
diff changeset
   820
                                                      MOJOSHADER_free f,
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1143
diff changeset
   821
                                                      void *d);
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1143
diff changeset
   822
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   823
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   824
/*
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   825
 * Call this to dispose of parsing results when you are done with them.
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   826
 *  This will call the MOJOSHADER_free function you provided to
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   827
 *  MOJOSHADER_parse multiple times, if you provided one.
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   828
 *  Passing a NULL here is a safe no-op.
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   829
 *
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   830
 * This function is thread safe, so long as any allocator you passed into
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   831
 *  MOJOSHADER_parse() is, too.
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   832
 */
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1143
diff changeset
   833
DECLSPEC void MOJOSHADER_freeParseData(const MOJOSHADER_parseData *data);
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 1017
diff changeset
   834
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 1017
diff changeset
   835
1164
006194daea99 MOJOSHADER_parsePreshader() cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1156
diff changeset
   836
/*
006194daea99 MOJOSHADER_parsePreshader() cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1156
diff changeset
   837
 * You almost certainly don't need this function, unless you absolutely know
006194daea99 MOJOSHADER_parsePreshader() cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1156
diff changeset
   838
 *  why you need it without hesitation. This is useful if you're doing
006194daea99 MOJOSHADER_parsePreshader() cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1156
diff changeset
   839
 *  extremely low-level shader work or building specialized tools.
006194daea99 MOJOSHADER_parsePreshader() cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1156
diff changeset
   840
 *
006194daea99 MOJOSHADER_parsePreshader() cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1156
diff changeset
   841
 * Parse a preshader structure. This expects a buffer of bytes that represents
006194daea99 MOJOSHADER_parsePreshader() cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1156
diff changeset
   842
 *  the preshader data starting with its magic number token and ending at
006194daea99 MOJOSHADER_parsePreshader() cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1156
diff changeset
   843
 *  the end of the comment tokens that contain this preshader. Note that it
006194daea99 MOJOSHADER_parsePreshader() cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1156
diff changeset
   844
 *  does _not_ start at the beginning of the comment tokens.
006194daea99 MOJOSHADER_parsePreshader() cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1156
diff changeset
   845
 *
006194daea99 MOJOSHADER_parsePreshader() cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1156
diff changeset
   846
 * On success, this will return a MOJOSHADER_preshader. This can be
006194daea99 MOJOSHADER_parsePreshader() cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1156
diff changeset
   847
 *  deallocated later by calling MOJOSHADER_freePreshader(). On failure,
006194daea99 MOJOSHADER_parsePreshader() cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1156
diff changeset
   848
 *  this will return NULL. Unlike other MojoShader APIs, this assumes you
006194daea99 MOJOSHADER_parsePreshader() cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1156
diff changeset
   849
 *  either have a complete and valid buffer of preshader tokens or you have
006194daea99 MOJOSHADER_parsePreshader() cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1156
diff changeset
   850
 *  incomplete/corrupted data, so there is no explicit error reporting. Please
006194daea99 MOJOSHADER_parsePreshader() cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1156
diff changeset
   851
 *  note that if the system runs out of memory, this function will also return
006194daea99 MOJOSHADER_parsePreshader() cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1156
diff changeset
   852
 *  NULL without distinction.
006194daea99 MOJOSHADER_parsePreshader() cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1156
diff changeset
   853
 *
006194daea99 MOJOSHADER_parsePreshader() cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1156
diff changeset
   854
 * This function is thread safe, so long as any allocator you passed into
006194daea99 MOJOSHADER_parsePreshader() cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1156
diff changeset
   855
 *  MOJOSHADER_parsePreshader() is, too.
006194daea99 MOJOSHADER_parsePreshader() cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1156
diff changeset
   856
 */
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1143
diff changeset
   857
DECLSPEC const MOJOSHADER_preshader *MOJOSHADER_parsePreshader(const unsigned char *buf,
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1143
diff changeset
   858
                                                               const unsigned int len,
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1143
diff changeset
   859
                                                               MOJOSHADER_malloc m,
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1143
diff changeset
   860
                                                               MOJOSHADER_free f,
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1143
diff changeset
   861
                                                               void *d);
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1143
diff changeset
   862
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1143
diff changeset
   863
1164
006194daea99 MOJOSHADER_parsePreshader() cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1156
diff changeset
   864
/*
006194daea99 MOJOSHADER_parsePreshader() cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1156
diff changeset
   865
 * You almost certainly don't need this function, unless you absolutely know
006194daea99 MOJOSHADER_parsePreshader() cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1156
diff changeset
   866
 *  why you need it without hesitation. This is useful if you're doing
006194daea99 MOJOSHADER_parsePreshader() cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1156
diff changeset
   867
 *  extremely low-level shader work or building specialized tools.
006194daea99 MOJOSHADER_parsePreshader() cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1156
diff changeset
   868
 *
006194daea99 MOJOSHADER_parsePreshader() cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1156
diff changeset
   869
 * Call this to dispose of preshader parsing results when you are done with
006194daea99 MOJOSHADER_parsePreshader() cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1156
diff changeset
   870
 *  them. This will call the MOJOSHADER_free function you provided to
006194daea99 MOJOSHADER_parsePreshader() cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1156
diff changeset
   871
 *  MOJOSHADER_parsePreshader() multiple times, if you provided one.
006194daea99 MOJOSHADER_parsePreshader() cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1156
diff changeset
   872
 *  Passing a NULL here is a safe no-op.
006194daea99 MOJOSHADER_parsePreshader() cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1156
diff changeset
   873
 *
006194daea99 MOJOSHADER_parsePreshader() cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1156
diff changeset
   874
 * You only need to call this function for results from a call to
006194daea99 MOJOSHADER_parsePreshader() cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1156
diff changeset
   875
 *  MOJOSHADER_parsePreshader(). Other MojoShader structures with a preshader
006194daea99 MOJOSHADER_parsePreshader() cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1156
diff changeset
   876
 *  field, such as MOJOSHADER_parseData(), should not use this function, as
006194daea99 MOJOSHADER_parsePreshader() cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1156
diff changeset
   877
 *  the preshader will be deallocated with everything else in
006194daea99 MOJOSHADER_parsePreshader() cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1156
diff changeset
   878
 *  MOJOSHADER_freeParseData(), etc.
006194daea99 MOJOSHADER_parsePreshader() cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1156
diff changeset
   879
 *
006194daea99 MOJOSHADER_parsePreshader() cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1156
diff changeset
   880
 * This function is thread safe, so long as any allocator you passed into
006194daea99 MOJOSHADER_parsePreshader() cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1156
diff changeset
   881
 *  MOJOSHADER_parsePreshader() is, too.
006194daea99 MOJOSHADER_parsePreshader() cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1156
diff changeset
   882
 */
006194daea99 MOJOSHADER_parsePreshader() cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1156
diff changeset
   883
DECLSPEC void MOJOSHADER_freePreshader(const MOJOSHADER_preshader *preshader);
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1143
diff changeset
   884
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1143
diff changeset
   885
555
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   886
/* Preprocessor interface... */
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   887
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   888
/*
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   889
 * Structure used to pass predefined macros. Maps to D3DXMACRO.
675
e85587e4650d Fixing some comments.
Ryan C. Gordon <icculus@icculus.org>
parents: 658
diff changeset
   890
 *  You can have macro arguments: set identifier to "a(b, c)" or whatever.
555
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   891
 */
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   892
typedef struct MOJOSHADER_preprocessorDefine
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   893
{
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   894
    const char *identifier;
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   895
    const char *definition;
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   896
} MOJOSHADER_preprocessorDefine;
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   897
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   898
/*
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   899
 * Used with the MOJOSHADER_includeOpen callback. Maps to D3DXINCLUDE_TYPE.
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   900
 */
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   901
typedef enum
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   902
{
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   903
    MOJOSHADER_INCLUDETYPE_LOCAL,   /* local header: #include "blah.h" */
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   904
    MOJOSHADER_INCLUDETYPE_SYSTEM   /* system header: #include <blah.h> */
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   905
} MOJOSHADER_includeType;
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   906
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   907
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   908
/*
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   909
 * Structure used to return data from preprocessing of a shader...
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   910
 */
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   911
/* !!! FIXME: most of these ints should be unsigned. */
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   912
typedef struct MOJOSHADER_preprocessData
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   913
{
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   914
    /*
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   915
     * The number of elements pointed to by (errors).
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   916
     */
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   917
    int error_count;
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   918
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   919
    /*
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   920
     * (error_count) elements of data that specify errors that were generated
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   921
     *  by parsing this shader.
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   922
     * This can be NULL if there were no errors or if (error_count) is zero.
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   923
     */
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   924
    MOJOSHADER_error *errors;
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   925
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   926
    /*
579
e408bfc631f5 Replaced some "ASCII" comments with "UTF-8".
Ryan C. Gordon <icculus@icculus.org>
parents: 578
diff changeset
   927
     * Bytes of output from preprocessing. This is a UTF-8 string. We
555
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   928
     *  guarantee it to be NULL-terminated. Will be NULL on error.
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   929
     */
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   930
    const char *output;
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   931
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   932
    /*
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   933
     * Byte count for output, not counting any null terminator.
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   934
     *  Will be 0 on error.
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   935
     */
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   936
    int output_len;
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   937
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   938
    /*
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   939
     * This is the malloc implementation you passed to MOJOSHADER_parse().
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   940
     */
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   941
    MOJOSHADER_malloc malloc;
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   942
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   943
    /*
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   944
     * This is the free implementation you passed to MOJOSHADER_parse().
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   945
     */
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   946
    MOJOSHADER_free free;
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   947
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   948
    /*
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   949
     * This is the pointer you passed as opaque data for your allocator.
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   950
     */
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   951
    void *malloc_data;
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   952
} MOJOSHADER_preprocessData;
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   953
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   954
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   955
/*
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   956
 * This callback allows an app to handle #include statements for the
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   957
 *  preprocessor. When the preprocessor sees an #include, it will call this
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   958
 *  function to obtain the contents of the requested file. This is optional;
728
c37993f6f474 Fixed comment typo.
Ryan C. Gordon <icculus@icculus.org>
parents: 675
diff changeset
   959
 *  the preprocessor will open files directly if no callback is supplied, but
555
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   960
 *  this allows an app to retrieve data from something other than the
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   961
 *  traditional filesystem (for example, headers packed in a .zip file or
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   962
 *  headers generated on-the-fly).
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   963
 *
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   964
 * This function maps to ID3DXInclude::Open()
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   965
 *
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   966
 * (inctype) specifies the type of header we wish to include.
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   967
 * (fname) specifies the name of the file specified on the #include line.
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   968
 * (parent) is a string of the entire source file containing the include, in
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   969
 *  its original, not-yet-preprocessed state. Note that this is just the
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   970
 *  contents of the specific file, not all source code that the preprocessor
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   971
 *  has seen through other includes, etc.
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   972
 * (outdata) will be set by the callback to a pointer to the included file's
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   973
 *  contents. The callback is responsible for allocating this however they
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   974
 *  see fit (we provide allocator functions, but you may ignore them). This
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   975
 *  pointer must remain valid until the includeClose callback runs. This
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   976
 *  string does not need to be NULL-terminated.
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   977
 * (outbytes) will be set by the callback to the number of bytes pointed to
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   978
 *  by (outdata).
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   979
 * (m),(f), and (d) are the allocator details that the application passed to
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   980
 *  MojoShader. If these were NULL, MojoShader may have replaced them with its
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   981
 *  own internal allocators.
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   982
 *
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   983
 * The callback returns zero on error, non-zero on success.
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   984
 *
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   985
 * If you supply an includeOpen callback, you must supply includeClose, too.
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   986
 */
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1143
diff changeset
   987
typedef int (MOJOSHADERCALL *MOJOSHADER_includeOpen)(MOJOSHADER_includeType inctype,
555
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   988
                            const char *fname, const char *parent,
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   989
                            const char **outdata, unsigned int *outbytes,
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   990
                            MOJOSHADER_malloc m, MOJOSHADER_free f, void *d);
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   991
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   992
/*
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   993
 * This callback allows an app to clean up the results of a previous
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   994
 *  includeOpen callback.
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   995
 *
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   996
 * This function maps to ID3DXInclude::Close()
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   997
 *
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   998
 * (data) is the data that was returned from a previous call to includeOpen.
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
   999
 *  It is now safe to deallocate this data.
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1000
 * (m),(f), and (d) are the same allocator details that were passed to your
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1001
 *  includeOpen callback.
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1002
 *
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1003
 * If you supply an includeClose callback, you must supply includeOpen, too.
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1004
 */
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1143
diff changeset
  1005
typedef void (MOJOSHADERCALL *MOJOSHADER_includeClose)(const char *data,
555
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1006
                            MOJOSHADER_malloc m, MOJOSHADER_free f, void *d);
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1007
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1008
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1009
/*
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1010
 * This function is optional. Even if you are dealing with shader source
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1011
 *  code, you don't need to explicitly use the preprocessor, as the compiler
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1012
 *  and assembler will use it behind the scenes. In fact, you probably never
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1013
 *  need this function unless you are debugging a custom tool (or debugging
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1014
 *  MojoShader itself).
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1015
 *
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1016
 * Preprocessing roughly follows the syntax of an ANSI C preprocessor, as
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1017
 *  Microsoft's Direct3D assembler and HLSL compiler use this syntax. Please
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1018
 *  note that we try to match the output you'd get from Direct3D's
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1019
 *  preprocessor, which has some quirks if you're expecting output that matches
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1020
 *  a generic C preprocessor.
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1021
 *
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1022
 * This function maps to D3DXPreprocessShader().
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1023
 *
578
6c8f73c845e7 Allow app to specify a base filename for error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 562
diff changeset
  1024
 * (filename) is a NULL-terminated UTF-8 filename. It can be NULL. We do not
6c8f73c845e7 Allow app to specify a base filename for error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 562
diff changeset
  1025
 *  actually access this file, as we obtain our data from (source). This
6c8f73c845e7 Allow app to specify a base filename for error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 562
diff changeset
  1026
 *  string is copied when we need to report errors while processing (source),
6c8f73c845e7 Allow app to specify a base filename for error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 562
diff changeset
  1027
 *  as opposed to errors in a file referenced via the #include directive in
6c8f73c845e7 Allow app to specify a base filename for error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 562
diff changeset
  1028
 *  (source). If this is NULL, then errors will report the filename as NULL,
6c8f73c845e7 Allow app to specify a base filename for error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 562
diff changeset
  1029
 *  too.
6c8f73c845e7 Allow app to specify a base filename for error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 562
diff changeset
  1030
 *
6c8f73c845e7 Allow app to specify a base filename for error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 562
diff changeset
  1031
 * (source) is an string of UTF-8 text to preprocess. It does not need to be
555
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1032
 *  NULL-terminated.
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1033
 *
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1034
 * (sourcelen) is the length of the string pointed to by (source), in bytes.
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1035
 *
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1036
 * (defines) points to (define_count) preprocessor definitions, and can be
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1037
 *  NULL. These are treated by the preprocessor as if the source code started
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1038
 *  with one #define for each entry you pass in here.
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1039
 *
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1040
 * (include_open) and (include_close) let the app control the preprocessor's
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1041
 *  behaviour for #include statements. Both are optional and can be NULL, but
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1042
 *  both must be specified if either is specified.
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1043
 *
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1044
 * This will return a MOJOSHADER_preprocessorData. You should pass this
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1045
 *  return value to MOJOSHADER_freePreprocessData() when you are done with
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1046
 *  it.
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1047
 *
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1048
 * This function will never return NULL, even if the system is completely
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1049
 *  out of memory upon entry (in which case, this function returns a static
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1050
 *  MOJOSHADER_preprocessData object, which is still safe to pass to
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1051
 *  MOJOSHADER_freePreprocessData()).
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1052
 *
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1053
 * As preprocessing requires some memory to be allocated, you may provide a
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1054
 *  custom allocator to this function, which will be used to allocate/free
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1055
 *  memory. They function just like malloc() and free(). We do not use
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1056
 *  realloc(). If you don't care, pass NULL in for the allocator functions.
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1057
 *  If your allocator needs instance-specific data, you may supply it with the
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1058
 *  (d) parameter. This pointer is passed as-is to your (m) and (f) functions.
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1059
 *
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1060
 * This function is thread safe, so long as the various callback functions
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1061
 *  are, too, and that the parameters remains intact for the duration of the
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1062
 *  call. This allows you to preprocess several shaders on separate CPU cores
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1063
 *  at the same time.
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1064
 */
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1143
diff changeset
  1065
DECLSPEC const MOJOSHADER_preprocessData *MOJOSHADER_preprocess(const char *filename,
578
6c8f73c845e7 Allow app to specify a base filename for error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 562
diff changeset
  1066
                             const char *source, unsigned int sourcelen,
658
22695d3d6b98 Should be an array of structs, not an array of pointers to structs.
Ryan C. Gordon <icculus@icculus.org>
parents: 592
diff changeset
  1067
                             const MOJOSHADER_preprocessorDefine *defines,
555
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1068
                             unsigned int define_count,
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1069
                             MOJOSHADER_includeOpen include_open,
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1070
                             MOJOSHADER_includeClose include_close,
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1071
                             MOJOSHADER_malloc m, MOJOSHADER_free f, void *d);
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1072
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1073
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1074
/*
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1075
 * Call this to dispose of preprocessing results when you are done with them.
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1076
 *  This will call the MOJOSHADER_free function you provided to
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1077
 *  MOJOSHADER_preprocess() multiple times, if you provided one.
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1078
 *  Passing a NULL here is a safe no-op.
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1079
 *
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1080
 * This function is thread safe, so long as any allocator you passed into
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1081
 *  MOJOSHADER_preprocess() is, too.
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1082
 */
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1143
diff changeset
  1083
DECLSPEC void MOJOSHADER_freePreprocessData(const MOJOSHADER_preprocessData *data);
555
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1084
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 552
diff changeset
  1085
465
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 462
diff changeset
  1086
/* Assembler interface... */
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 462
diff changeset
  1087
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 462
diff changeset
  1088
/*
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 462
diff changeset
  1089
 * This function is optional. Use this to convert Direct3D shader assembly
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 462
diff changeset
  1090
 *  language into bytecode, which can be handled by MOJOSHADER_parse().
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 462
diff changeset
  1091
 *
578
6c8f73c845e7 Allow app to specify a base filename for error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 562
diff changeset
  1092
 * (filename) is a NULL-terminated UTF-8 filename. It can be NULL. We do not
6c8f73c845e7 Allow app to specify a base filename for error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 562
diff changeset
  1093
 *  actually access this file, as we obtain our data from (source). This
6c8f73c845e7 Allow app to specify a base filename for error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 562
diff changeset
  1094
 *  string is copied when we need to report errors while processing (source),
6c8f73c845e7 Allow app to specify a base filename for error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 562
diff changeset
  1095
 *  as opposed to errors in a file referenced via the #include directive in
6c8f73c845e7 Allow app to specify a base filename for error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 562
diff changeset
  1096
 *  (source). If this is NULL, then errors will report the filename as NULL,
6c8f73c845e7 Allow app to specify a base filename for error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 562
diff changeset
  1097
 *  too.
6c8f73c845e7 Allow app to specify a base filename for error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 562
diff changeset
  1098
 *
6c8f73c845e7 Allow app to specify a base filename for error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 562
diff changeset
  1099
 * (source) is an UTF-8 string of valid Direct3D shader assembly source code.
562
c9a2bc5129c9 First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 555
diff changeset
  1100
 *  It does not need to be NULL-terminated.
c9a2bc5129c9 First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 555
diff changeset
  1101
 *
c9a2bc5129c9 First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 555
diff changeset
  1102
 * (sourcelen) is the length of the string pointed to by (source), in bytes.
465
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 462
diff changeset
  1103
 *
579
e408bfc631f5 Replaced some "ASCII" comments with "UTF-8".
Ryan C. Gordon <icculus@icculus.org>
parents: 578
diff changeset
  1104
 * (comments) points to (comment_count) NULL-terminated UTF-8 strings, and
524
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
  1105
 *  can be NULL. These strings are inserted as comments in the bytecode.
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
  1106
 *
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
  1107
 * (symbols) points to (symbol_count) symbol structs, and can be NULL. These
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
  1108
 *  become a CTAB field in the bytecode. This is optional, but
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
  1109
 *  MOJOSHADER_parse() needs CTAB data for all arrays used in a program, or
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
  1110
 *  relative addressing will not be permitted, so you'll want to at least
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
  1111
 *  provide symbol information for those. The symbol data is 100% trusted
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
  1112
 *  at this time; it will not be checked to see if it matches what was
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
  1113
 *  assembled in any way whatsoever.
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
  1114
 *
562
c9a2bc5129c9 First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 555
diff changeset
  1115
 * (defines) points to (define_count) preprocessor definitions, and can be
c9a2bc5129c9 First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 555
diff changeset
  1116
 *  NULL. These are treated by the preprocessor as if the source code started
c9a2bc5129c9 First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 555
diff changeset
  1117
 *  with one #define for each entry you pass in here.
c9a2bc5129c9 First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 555
diff changeset
  1118
 *
c9a2bc5129c9 First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 555
diff changeset
  1119
 * (include_open) and (include_close) let the app control the preprocessor's
c9a2bc5129c9 First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 555
diff changeset
  1120
 *  behaviour for #include statements. Both are optional and can be NULL, but
c9a2bc5129c9 First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 555
diff changeset
  1121
 *  both must be specified if either is specified.
c9a2bc5129c9 First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 555
diff changeset
  1122
 *
c9a2bc5129c9 First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 555
diff changeset
  1123
 * This will return a MOJOSHADER_parseData, like MOJOSHADER_parse() would,
470
7d84d3452125 Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents: 469
diff changeset
  1124
 *  except the profile will be MOJOSHADER_PROFILE_BYTECODE and the output
7d84d3452125 Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents: 469
diff changeset
  1125
 *  will be the assembled bytecode instead of some other language. This output
7d84d3452125 Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents: 469
diff changeset
  1126
 *  can be pushed back through MOJOSHADER_parseData() with a different profile.
7d84d3452125 Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents: 469
diff changeset
  1127
 *
7d84d3452125 Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents: 469
diff changeset
  1128
 * This function will never return NULL, even if the system is completely
7d84d3452125 Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents: 469
diff changeset
  1129
 *  out of memory upon entry (in which case, this function returns a static
7d84d3452125 Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents: 469
diff changeset
  1130
 *  MOJOSHADER_parseData object, which is still safe to pass to
7d84d3452125 Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents: 469
diff changeset
  1131
 *  MOJOSHADER_freeParseData()).
7d84d3452125 Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents: 469
diff changeset
  1132
 *
465
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 462
diff changeset
  1133
 * As assembling requires some memory to be allocated, you may provide a
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 462
diff changeset