author | Ryan C. Gordon <icculus@icculus.org> |
Thu, 03 Apr 2008 08:21:03 -0400 | |
branch | trunk |
changeset 68 | f00ba7fcd0f8 |
parent 67 | cc42106d11ec |
child 69 | 73199b16b926 |
permissions | -rw-r--r-- |
7 | 1 |
/** |
35 | 2 |
* MojoShader; generate shader programs from bytecode of compiled |
3 |
* Direct3D shaders. |
|
7 | 4 |
* |
5 |
* Please see the file LICENSE.txt in the source's root directory. |
|
6 |
* |
|
7 |
* This file written by Ryan C. Gordon. |
|
8 |
*/ |
|
9 |
||
18
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
10 |
// !!! FIXME: I keep changing coding styles for symbols and typedefs. |
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
11 |
|
58 | 12 |
// !!! FIXME: do DEF* opcodes have to come before instructions? |
13 |
// !!! FIXME: my reading of the msdn spec suggests no, but it sounds like |
|
14 |
// !!! FIXME: something they'd require. DCL_* _does_ have to be first. |
|
15 |
||
31 | 16 |
|
7 | 17 |
// Shader bytecode format is described at MSDN: |
18 |
// http://msdn2.microsoft.com/en-us/library/ms800307.aspx |
|
19 |
||
1 | 20 |
#include <stdio.h> |
11
c9bb617d9b77
[svn] Pass around a context struct, so we can start tracking state, etc.
icculus
parents:
9
diff
changeset
|
21 |
#include <string.h> |
1 | 22 |
#include <stdlib.h> |
2
c37210f5e87b
[svn] Bunch More Work. Parse out instruction tokens, fail in a bunch of new stubs.
icculus
parents:
1
diff
changeset
|
23 |
#include <stdint.h> |
12
d81712dd1a46
[svn] Cleaned up and improved output and fail state.
icculus
parents:
11
diff
changeset
|
24 |
#include <stdarg.h> |
24 | 25 |
#include <assert.h> |
2
c37210f5e87b
[svn] Bunch More Work. Parse out instruction tokens, fail in a bunch of new stubs.
icculus
parents:
1
diff
changeset
|
26 |
|
35 | 27 |
#include "mojoshader.h" |
9 | 28 |
|
56
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
29 |
|
20
bb2e8f285acc
[svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents:
19
diff
changeset
|
30 |
// This is the highest shader version we currently support. |
bb2e8f285acc
[svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents:
19
diff
changeset
|
31 |
|
bb2e8f285acc
[svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents:
19
diff
changeset
|
32 |
#define MAX_SHADER_MAJOR 3 |
bb2e8f285acc
[svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents:
19
diff
changeset
|
33 |
#define MAX_SHADER_MINOR 0 |
bb2e8f285acc
[svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents:
19
diff
changeset
|
34 |
|
18
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
35 |
|
67 | 36 |
// If SUPPORT_PROFILE_* isn't defined, we assume an implicit desire to support. |
37 |
// You get all the profiles unless you go out of your way to disable them. |
|
18
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
38 |
|
14 | 39 |
#ifndef SUPPORT_PROFILE_D3D |
40 |
#define SUPPORT_PROFILE_D3D 1 |
|
41 |
#endif |
|
42 |
||
43 |
#ifndef SUPPORT_PROFILE_GLSL |
|
44 |
#define SUPPORT_PROFILE_GLSL 1 |
|
45 |
#endif |
|
46 |
||
18
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
47 |
|
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
48 |
// Get basic wankery out of the way here... |
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
49 |
|
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
50 |
typedef unsigned int uint; // this is a printf() helper. don't use for code. |
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
51 |
typedef uint8_t uint8; |
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
52 |
typedef uint32_t uint32; |
31 | 53 |
typedef int32_t int32; |
18
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
54 |
|
12
d81712dd1a46
[svn] Cleaned up and improved output and fail state.
icculus
parents:
11
diff
changeset
|
55 |
#ifdef __GNUC__ |
d81712dd1a46
[svn] Cleaned up and improved output and fail state.
icculus
parents:
11
diff
changeset
|
56 |
#define ISPRINTF(x,y) __attribute__((format (printf, x, y))) |
d81712dd1a46
[svn] Cleaned up and improved output and fail state.
icculus
parents:
11
diff
changeset
|
57 |
#else |
d81712dd1a46
[svn] Cleaned up and improved output and fail state.
icculus
parents:
11
diff
changeset
|
58 |
#define ISPRINTF(x,y) |
d81712dd1a46
[svn] Cleaned up and improved output and fail state.
icculus
parents:
11
diff
changeset
|
59 |
#endif |
d81712dd1a46
[svn] Cleaned up and improved output and fail state.
icculus
parents:
11
diff
changeset
|
60 |
|
14 | 61 |
#define STATICARRAYLEN(x) ( (sizeof ((x))) / (sizeof ((x)[0])) ) |
62 |
||
45 | 63 |
#ifdef _WINDOWS // !!! FIXME: bleh |
64 |
const char *endline_str = "\r\n"; |
|
65 |
#else |
|
66 |
const char *endline_str = "\n"; |
|
67 |
#endif |
|
68 |
||
69 |
||
56
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
70 |
// we need to reference this by explicit value occasionally. |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
71 |
#define OPCODE_RET 28 |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
72 |
|
14 | 73 |
|
7 | 74 |
// Byteswap magic... |
75 |
||
4 | 76 |
#if ((defined __GNUC__) && (defined __POWERPC__)) |
77 |
static inline uint32 SWAP32(uint32 x) |
|
78 |
{ |
|
79 |
__asm__ __volatile__("lwbrx %0,0,%1" : "=r" (x) : "r" (&x)); |
|
80 |
return x; |
|
81 |
} // SWAP32 |
|
82 |
#elif defined(__POWERPC__) |
|
83 |
static inline uint32 SWAP32(uint32 x) |
|
84 |
{ |
|
85 |
return ( (((x) >> 24) & 0x000000FF) | (((x) >> 8) & 0x0000FF00) | |
|
86 |
(((x) << 8) & 0x00FF0000) | (((x) << 24) & 0xFF000000) ); |
|
87 |
} // SWAP32 |
|
88 |
#else |
|
89 |
# define SWAP32(x) (x) |
|
90 |
#endif |
|
91 |
||
7 | 92 |
|
18
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
93 |
// predeclare. |
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
94 |
typedef struct Context Context; |
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
95 |
|
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
96 |
// one emit function for each opcode in each profile. |
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
97 |
typedef void (*emit_function)(Context *ctx); |
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
98 |
|
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
99 |
// one emit function for comments in each profile. |
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
100 |
typedef void (*emit_comment)(Context *ctx, const char *str); |
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
101 |
|
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
102 |
// one emit function for starting output in each profile. |
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
103 |
typedef void (*emit_start)(Context *ctx); |
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
104 |
|
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
105 |
// one emit function for ending output in each profile. |
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
106 |
typedef void (*emit_end)(Context *ctx); |
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
107 |
|
20
bb2e8f285acc
[svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents:
19
diff
changeset
|
108 |
// one args function for each possible sequence of opcode arguments. |
bb2e8f285acc
[svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents:
19
diff
changeset
|
109 |
typedef int (*args_function)(Context *ctx); |
bb2e8f285acc
[svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents:
19
diff
changeset
|
110 |
|
18
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
111 |
// one state function for each opcode where we have state machine updates. |
44
5d56cf8b4571
[svn] Cleaned up fail check, parse_args and state machine semantics, and added check
icculus
parents:
43
diff
changeset
|
112 |
typedef void (*state_function)(Context *ctx); |
18
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
113 |
|
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
114 |
typedef struct |
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
115 |
{ |
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
116 |
const char *name; |
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
117 |
emit_start start_emitter; |
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
118 |
emit_end end_emitter; |
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
119 |
emit_comment comment_emitter; |
34 | 120 |
} Profile; |
18
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
121 |
|
46 | 122 |
typedef MOJOSHADER_shaderType ShaderType; |
18
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
123 |
|
21
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
124 |
typedef enum |
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
125 |
{ |
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
126 |
REGISTER_TYPE_TEMP = 0, |
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
127 |
REGISTER_TYPE_INPUT = 1, |
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
128 |
REGISTER_TYPE_CONST = 2, |
56
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
129 |
REGISTER_TYPE_ADDRESS = 3, |
21
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
130 |
REGISTER_TYPE_TEXTURE = 3, // ALSO 3! |
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
131 |
REGISTER_TYPE_RASTOUT = 4, |
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
132 |
REGISTER_TYPE_ATTROUT = 5, |
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
133 |
REGISTER_TYPE_TEXCRDOUT = 6, |
56
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
134 |
REGISTER_TYPE_OUTPUT = 6, // ALSO 6! |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
135 |
REGISTER_TYPE_CONSTINT = 7, |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
136 |
REGISTER_TYPE_COLOROUT = 8, |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
137 |
REGISTER_TYPE_DEPTHOUT = 9, |
21
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
138 |
REGISTER_TYPE_SAMPLER = 10, |
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
139 |
REGISTER_TYPE_CONST2 = 11, |
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
140 |
REGISTER_TYPE_CONST3 = 12, |
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
141 |
REGISTER_TYPE_CONST4 = 13, |
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
142 |
REGISTER_TYPE_CONSTBOOL = 14, |
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
143 |
REGISTER_TYPE_LOOP = 15, |
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
144 |
REGISTER_TYPE_TEMPFLOAT16 = 16, |
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
145 |
REGISTER_TYPE_MISCTYPE = 17, |
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
146 |
REGISTER_TYPE_LABEL = 18, |
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
147 |
REGISTER_TYPE_PREDICATE = 19, |
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
148 |
REGISTER_TYPE_MAX = 19 |
34 | 149 |
} RegisterType; |
21
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
150 |
|
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
151 |
typedef enum |
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
152 |
{ |
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
153 |
RASTOUT_TYPE_POSITION = 0, |
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
154 |
RASTOUT_TYPE_FOG = 1, |
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
155 |
RASTOUT_TYPE_POINT_SIZE = 2, |
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
156 |
RASTOUT_TYPE_MAX = 2 |
34 | 157 |
} RastOutType; |
21
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
158 |
|
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
159 |
typedef enum |
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
160 |
{ |
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
161 |
MISCTYPE_TYPE_POSITION = 0, |
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
162 |
MISCTYPE_TYPE_FACE = 1, |
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
163 |
MISCTYPE_TYPE_MAX = 1 |
34 | 164 |
} MiscTypeType; |
21
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
165 |
|
31 | 166 |
typedef enum |
167 |
{ |
|
168 |
DECLUSAGE_POSITION = 0, |
|
169 |
DECLUSAGE_BLENDWEIGHT = 1, |
|
170 |
DECLUSAGE_BLENDINDICES = 2, |
|
171 |
DECLUSAGE_NORMAL = 3, |
|
172 |
DECLUSAGE_PSIZE = 4, |
|
173 |
DECLUSAGE_TEXCOORD = 5, |
|
174 |
DECLUSAGE_TANGENT = 6, |
|
175 |
DECLUSAGE_BINORMAL = 7, |
|
176 |
DECLUSAGE_TESSFACTOR = 8, |
|
177 |
DECLUSAGE_POSITIONT = 9, |
|
178 |
DECLUSAGE_COLOR = 10, |
|
179 |
DECLUSAGE_FOG = 11, |
|
180 |
DECLUSAGE_DEPTH = 12, |
|
181 |
DECLUSAGE_SAMPLE = 13 |
|
34 | 182 |
} DeclUsageType; |
31 | 183 |
|
184 |
typedef enum |
|
185 |
{ |
|
186 |
TEXTURE_TYPE_2D = 2, |
|
187 |
TEXTURE_TYPE_CUBE = 3, |
|
188 |
TEXTURE_TYPE_VOLUME = 4, |
|
34 | 189 |
} TextureType; |
31 | 190 |
|
18
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
191 |
|
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
192 |
// A simple linked list of strings, so we can build the final output without |
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
193 |
// realloc()ing for each new line, and easily insert lines into the middle |
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
194 |
// of the output without much trouble. |
54
b2b64d39df0f
[svn] Split up output into several lists, so GLSL profile can insert lines of text
icculus
parents:
51
diff
changeset
|
195 |
typedef struct OutputListNode |
b2b64d39df0f
[svn] Split up output into several lists, so GLSL profile can insert lines of text
icculus
parents:
51
diff
changeset
|
196 |
{ |
b2b64d39df0f
[svn] Split up output into several lists, so GLSL profile can insert lines of text
icculus
parents:
51
diff
changeset
|
197 |
char *str; |
b2b64d39df0f
[svn] Split up output into several lists, so GLSL profile can insert lines of text
icculus
parents:
51
diff
changeset
|
198 |
struct OutputListNode *next; |
b2b64d39df0f
[svn] Split up output into several lists, so GLSL profile can insert lines of text
icculus
parents:
51
diff
changeset
|
199 |
} OutputListNode; |
b2b64d39df0f
[svn] Split up output into several lists, so GLSL profile can insert lines of text
icculus
parents:
51
diff
changeset
|
200 |
|
18
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
201 |
typedef struct OutputList |
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
202 |
{ |
54
b2b64d39df0f
[svn] Split up output into several lists, so GLSL profile can insert lines of text
icculus
parents:
51
diff
changeset
|
203 |
OutputListNode head; |
b2b64d39df0f
[svn] Split up output into several lists, so GLSL profile can insert lines of text
icculus
parents:
51
diff
changeset
|
204 |
OutputListNode *tail; |
18
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
205 |
} OutputList; |
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
206 |
|
20
bb2e8f285acc
[svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents:
19
diff
changeset
|
207 |
|
21
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
208 |
// result modifiers. |
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
209 |
#define MOD_SATURATE 0x01 |
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
210 |
#define MOD_PP 0x02 |
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
211 |
#define MOD_CENTROID 0x04 |
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
212 |
|
24 | 213 |
// source modifiers. |
214 |
typedef enum |
|
215 |
{ |
|
216 |
SRCMOD_NONE, |
|
217 |
SRCMOD_NEGATE, |
|
218 |
SRCMOD_BIAS, |
|
219 |
SRCMOD_BIASNEGATE, |
|
220 |
SRCMOD_SIGN, |
|
221 |
SRCMOD_SIGNNEGATE, |
|
222 |
SRCMOD_COMPLEMENT, |
|
223 |
SRCMOD_X2, |
|
224 |
SRCMOD_X2NEGATE, |
|
225 |
SRCMOD_DZ, |
|
226 |
SRCMOD_DW, |
|
227 |
SRCMOD_ABS, |
|
228 |
SRCMOD_ABSNEGATE, |
|
229 |
SRCMOD_NOT, |
|
230 |
SRCMOD_TOTAL |
|
34 | 231 |
} SourceMod; |
24 | 232 |
|
21
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
233 |
|
20
bb2e8f285acc
[svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents:
19
diff
changeset
|
234 |
typedef struct |
bb2e8f285acc
[svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents:
19
diff
changeset
|
235 |
{ |
21
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
236 |
const uint32 *token; // this is the unmolested token in the stream. |
20
bb2e8f285acc
[svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents:
19
diff
changeset
|
237 |
int regnum; |
bb2e8f285acc
[svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents:
19
diff
changeset
|
238 |
int relative; |
21
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
239 |
int writemask; // xyzw or rgba (all four, not split out). |
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
240 |
int writemask0; // x or red |
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
241 |
int writemask1; // y or green |
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
242 |
int writemask2; // z or blue |
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
243 |
int writemask3; // w or alpha |
20
bb2e8f285acc
[svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents:
19
diff
changeset
|
244 |
int result_mod; |
bb2e8f285acc
[svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents:
19
diff
changeset
|
245 |
int result_shift; |
56
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
246 |
RegisterType regtype; |
20
bb2e8f285acc
[svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents:
19
diff
changeset
|
247 |
} DestArgInfo; |
bb2e8f285acc
[svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents:
19
diff
changeset
|
248 |
|
bb2e8f285acc
[svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents:
19
diff
changeset
|
249 |
typedef struct |
bb2e8f285acc
[svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents:
19
diff
changeset
|
250 |
{ |
21
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
251 |
const uint32 *token; // this is the unmolested token in the stream. |
20
bb2e8f285acc
[svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents:
19
diff
changeset
|
252 |
int regnum; |
bb2e8f285acc
[svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents:
19
diff
changeset
|
253 |
int relative; |
22 | 254 |
int swizzle; // xyzw (all four, not split out). |
20
bb2e8f285acc
[svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents:
19
diff
changeset
|
255 |
int swizzle_x; |
bb2e8f285acc
[svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents:
19
diff
changeset
|
256 |
int swizzle_y; |
bb2e8f285acc
[svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents:
19
diff
changeset
|
257 |
int swizzle_z; |
bb2e8f285acc
[svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents:
19
diff
changeset
|
258 |
int swizzle_w; |
bb2e8f285acc
[svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents:
19
diff
changeset
|
259 |
int src_mod; |
56
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
260 |
RegisterType regtype; |
20
bb2e8f285acc
[svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents:
19
diff
changeset
|
261 |
} SourceArgInfo; |
bb2e8f285acc
[svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents:
19
diff
changeset
|
262 |
|
bb2e8f285acc
[svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents:
19
diff
changeset
|
263 |
|
56
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
264 |
typedef enum |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
265 |
{ |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
266 |
CTX_FLAGS_GLSL_LIT_OPCODE = (1 << 0), |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
267 |
CTX_FLAGS_GLSL_DST_OPCODE = (1 << 1), |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
268 |
CTX_FLAGS_GLSL_LRP_OPCODE = (1 << 2), |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
269 |
CTX_FLAGS_MASK = 0xFFFFFFFF |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
270 |
} ContextFlags; |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
271 |
|
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
272 |
|
34 | 273 |
#define SCRATCH_BUFFER_SIZE 256 |
274 |
#define SCRATCH_BUFFERS 10 |
|
18
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
275 |
|
56
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
276 |
// !!! FIXME: labels_called and the scratch buffers make this pretty big. |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
277 |
// !!! FIXME: might be worth having one set of static scratch buffers that |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
278 |
// !!! FIXME: are mutex protected? |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
279 |
// !!! FIXME: and replace the bit array for labels_called with a linked list? |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
280 |
// !!! FIXME: maybe just malloc() the label list, since it can't be more than |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
281 |
// !!! FIXME: around (bytes_of_shader / 20) elements in the pathological case? |
18
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
282 |
// Context...this is state that changes as we parse through a shader... |
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
283 |
struct Context |
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
284 |
{ |
35 | 285 |
MOJOSHADER_malloc malloc; |
286 |
MOJOSHADER_free free; |
|
18
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
287 |
const uint32 *tokens; |
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
288 |
uint32 tokencount; |
54
b2b64d39df0f
[svn] Split up output into several lists, so GLSL profile can insert lines of text
icculus
parents:
51
diff
changeset
|
289 |
OutputList *output; |
b2b64d39df0f
[svn] Split up output into several lists, so GLSL profile can insert lines of text
icculus
parents:
51
diff
changeset
|
290 |
OutputList globals; |
56
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
291 |
OutputList helpers; |
54
b2b64d39df0f
[svn] Split up output into several lists, so GLSL profile can insert lines of text
icculus
parents:
51
diff
changeset
|
292 |
OutputList subroutines; |
b2b64d39df0f
[svn] Split up output into several lists, so GLSL profile can insert lines of text
icculus
parents:
51
diff
changeset
|
293 |
OutputList mainline; |
56
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
294 |
OutputList ignore; |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
295 |
OutputList *output_stack[2]; |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
296 |
int indent_stack[2]; |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
297 |
int output_stack_len; |
54
b2b64d39df0f
[svn] Split up output into several lists, so GLSL profile can insert lines of text
icculus
parents:
51
diff
changeset
|
298 |
int output_len; // total strlen; prevents walking the lists just to malloc. |
40
f54f1635ac8a
[svn] Filling in some initial GLSL output. Not even close to done!
icculus
parents:
39
diff
changeset
|
299 |
int indent; |
18
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
300 |
const char *endline; |
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
301 |
int endline_len; |
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
302 |
const char *failstr; |
34 | 303 |
char scratch[SCRATCH_BUFFERS][SCRATCH_BUFFER_SIZE]; |
18
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
304 |
int scratchidx; // current scratch buffer. |
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
305 |
int profileid; |
34 | 306 |
const Profile *profile; |
307 |
ShaderType shader_type; |
|
46 | 308 |
uint8 major_ver; |
309 |
uint8 minor_ver; |
|
20
bb2e8f285acc
[svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents:
19
diff
changeset
|
310 |
DestArgInfo dest_args[1]; |
56
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
311 |
SourceArgInfo source_args[5]; |
31 | 312 |
uint32 dwords[4]; |
46 | 313 |
int instruction_count; |
28 | 314 |
uint32 instruction_controls; |
56
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
315 |
uint32 previous_opcode; |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
316 |
ContextFlags flags; |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
317 |
uint8 labels_called[256]; |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
318 |
int loops; |
18
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
319 |
}; |
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
320 |
|
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
321 |
|
56
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
322 |
// jump between output sections in the context... |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
323 |
|
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
324 |
static inline void push_output(Context *ctx, OutputList *section) |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
325 |
{ |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
326 |
assert(ctx->output_stack_len < STATICARRAYLEN(ctx->output_stack)); |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
327 |
ctx->output_stack[ctx->output_stack_len] = ctx->output; |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
328 |
ctx->indent_stack[ctx->output_stack_len] = ctx->indent; |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
329 |
ctx->output_stack_len++; |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
330 |
ctx->output = section; |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
331 |
ctx->indent = 0; |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
332 |
} // push_output |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
333 |
|
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
334 |
static inline void pop_output(Context *ctx) |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
335 |
{ |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
336 |
assert(ctx->output_stack_len > 0); |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
337 |
ctx->output_stack_len--; |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
338 |
ctx->output = ctx->output_stack[ctx->output_stack_len]; |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
339 |
ctx->indent = ctx->indent_stack[ctx->output_stack_len]; |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
340 |
} // pop_output |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
341 |
|
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
342 |
|
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
343 |
|
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
344 |
// Shader model version magic... |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
345 |
|
43
2f5d9a656dff
[svn] Bunch More Work. Cleaned up some lingering opcode drama, and state machine
icculus
parents:
42
diff
changeset
|
346 |
static inline uint32 ver_ui32(const uint8 major, const uint8 minor) |
2f5d9a656dff
[svn] Bunch More Work. Cleaned up some lingering opcode drama, and state machine
icculus
parents:
42
diff
changeset
|
347 |
{ |
2f5d9a656dff
[svn] Bunch More Work. Cleaned up some lingering opcode drama, and state machine
icculus
parents:
42
diff
changeset
|
348 |
return ( (((uint32) major) << 16) | (((minor) == 0xFF) ? 0 : (minor)) ); |
2f5d9a656dff
[svn] Bunch More Work. Cleaned up some lingering opcode drama, and state machine
icculus
parents:
42
diff
changeset
|
349 |
} // version_ui32 |
2f5d9a656dff
[svn] Bunch More Work. Cleaned up some lingering opcode drama, and state machine
icculus
parents:
42
diff
changeset
|
350 |
|
2f5d9a656dff
[svn] Bunch More Work. Cleaned up some lingering opcode drama, and state machine
icculus
parents:
42
diff
changeset
|
351 |
static int shader_version_supported(uint8 maj, uint8 min) |
2f5d9a656dff
[svn] Bunch More Work. Cleaned up some lingering opcode drama, and state machine
icculus
parents:
42
diff
changeset
|
352 |
{ |
2f5d9a656dff
[svn] Bunch More Work. Cleaned up some lingering opcode drama, and state machine
icculus
parents:
42
diff
changeset
|
353 |
return (ver_ui32(maj,min) <= ver_ui32(MAX_SHADER_MAJOR, MAX_SHADER_MINOR)); |
2f5d9a656dff
[svn] Bunch More Work. Cleaned up some lingering opcode drama, and state machine
icculus
parents:
42
diff
changeset
|
354 |
} // shader_version_supported |
2f5d9a656dff
[svn] Bunch More Work. Cleaned up some lingering opcode drama, and state machine
icculus
parents:
42
diff
changeset
|
355 |
|
2f5d9a656dff
[svn] Bunch More Work. Cleaned up some lingering opcode drama, and state machine
icculus
parents:
42
diff
changeset
|
356 |
static int shader_version_atleast(const Context *ctx, uint8 maj, uint8 min) |
2f5d9a656dff
[svn] Bunch More Work. Cleaned up some lingering opcode drama, and state machine
icculus
parents:
42
diff
changeset
|
357 |
{ |
2f5d9a656dff
[svn] Bunch More Work. Cleaned up some lingering opcode drama, and state machine
icculus
parents:
42
diff
changeset
|
358 |
return (ver_ui32(ctx->major_ver, ctx->minor_ver) >= ver_ui32(maj, min)); |
2f5d9a656dff
[svn] Bunch More Work. Cleaned up some lingering opcode drama, and state machine
icculus
parents:
42
diff
changeset
|
359 |
} // shader_version_atleast |
2f5d9a656dff
[svn] Bunch More Work. Cleaned up some lingering opcode drama, and state machine
icculus
parents:
42
diff
changeset
|
360 |
|
2f5d9a656dff
[svn] Bunch More Work. Cleaned up some lingering opcode drama, and state machine
icculus
parents:
42
diff
changeset
|
361 |
|
56
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
362 |
// Bit arrays (for storing large arrays of booleans... |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
363 |
|
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
364 |
static void set_bit_array(uint8 *array, size_t arraylen, int index, int val) |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
365 |
{ |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
366 |
const int byteindex = index / 8; |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
367 |
const int bitindex = index % 8; |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
368 |
assert(byteindex < arraylen); |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
369 |
|
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
370 |
if (val) |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
371 |
array[byteindex] |= (1 << bitindex); |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
372 |
else |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
373 |
array[byteindex] &= ~(1 << bitindex); |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
374 |
} // set_bit_array |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
375 |
|
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
376 |
static int get_bit_array(const uint8 *array, size_t arraylen, int index) |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
377 |
{ |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
378 |
const int byteindex = index / 8; |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
379 |
const int bitindex = index % 8; |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
380 |
assert(byteindex < arraylen); |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
381 |
const uint8 byte = array[byteindex]; |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
382 |
return (byte & (1 << bitindex)) ? 1 : 0; |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
383 |
} // get_bit_array |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
384 |
|
43
2f5d9a656dff
[svn] Bunch More Work. Cleaned up some lingering opcode drama, and state machine
icculus
parents:
42
diff
changeset
|
385 |
|
18
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
386 |
static inline char *get_scratch_buffer(Context *ctx) |
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
387 |
{ |
34 | 388 |
ctx->scratchidx = (ctx->scratchidx + 1) % SCRATCH_BUFFERS; |
18
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
389 |
return ctx->scratch[ctx->scratchidx]; |
12
d81712dd1a46
[svn] Cleaned up and improved output and fail state.
icculus
parents:
11
diff
changeset
|
390 |
} // get_scratch_buffer |
d81712dd1a46
[svn] Cleaned up and improved output and fail state.
icculus
parents:
11
diff
changeset
|
391 |
|
d81712dd1a46
[svn] Cleaned up and improved output and fail state.
icculus
parents:
11
diff
changeset
|
392 |
|
7 | 393 |
// Special-case return values from the parsing pipeline... |
12
d81712dd1a46
[svn] Cleaned up and improved output and fail state.
icculus
parents:
11
diff
changeset
|
394 |
#define FAIL (-1) |
43
2f5d9a656dff
[svn] Bunch More Work. Cleaned up some lingering opcode drama, and state machine
icculus
parents:
42
diff
changeset
|
395 |
#define NOFAIL (-2) |
2f5d9a656dff
[svn] Bunch More Work. Cleaned up some lingering opcode drama, and state machine
icculus
parents:
42
diff
changeset
|
396 |
#define END_OF_STREAM (-3) |
12
d81712dd1a46
[svn] Cleaned up and improved output and fail state.
icculus
parents:
11
diff
changeset
|
397 |
|
48 | 398 |
static inline int isfail(const Context *ctx) |
44
5d56cf8b4571
[svn] Cleaned up fail check, parse_args and state machine semantics, and added check
icculus
parents:
43
diff
changeset
|
399 |
{ |
5d56cf8b4571
[svn] Cleaned up fail check, parse_args and state machine semantics, and added check
icculus
parents:
43
diff
changeset
|
400 |
return (ctx->failstr != NULL); |
5d56cf8b4571
[svn] Cleaned up fail check, parse_args and state machine semantics, and added check
icculus
parents:
43
diff
changeset
|
401 |
} // isfail |
5d56cf8b4571
[svn] Cleaned up fail check, parse_args and state machine semantics, and added check
icculus
parents:
43
diff
changeset
|
402 |
|
5d56cf8b4571
[svn] Cleaned up fail check, parse_args and state machine semantics, and added check
icculus
parents:
43
diff
changeset
|
403 |
|
46 | 404 |
static MOJOSHADER_parseData out_of_mem_data = { |
405 |
"Out of memory", 0, 0, 0, MOJOSHADER_TYPE_UNKNOWN, 0, 0, 0, 0 |
|
406 |
}; |
|
407 |
||
408 |
static const char *out_of_mem_str = "Out of memory"; |
|
18
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
409 |
static inline int out_of_memory(Context *ctx) |
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
410 |
{ |
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
411 |
if (ctx->failstr == NULL) |
46 | 412 |
ctx->failstr = out_of_mem_str; // fail() would call malloc(). |
18
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
413 |
return FAIL; |
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
414 |
} // out_of_memory |
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
415 |
|
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
416 |
|
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
417 |
static int failf(Context *ctx, const char *fmt, ...) ISPRINTF(2,3); |
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
418 |
static int failf(Context *ctx, const char *fmt, ...) |
12
d81712dd1a46
[svn] Cleaned up and improved output and fail state.
icculus
parents:
11
diff
changeset
|
419 |
{ |
d81712dd1a46
[svn] Cleaned up and improved output and fail state.
icculus
parents:
11
diff
changeset
|
420 |
if (ctx->failstr == NULL) // don't change existing error. |
d81712dd1a46
[svn] Cleaned up and improved output and fail state.
icculus
parents:
11
diff
changeset
|
421 |
{ |
18
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
422 |
char *scratch = get_scratch_buffer(ctx); |
12
d81712dd1a46
[svn] Cleaned up and improved output and fail state.
icculus
parents:
11
diff
changeset
|
423 |
va_list ap; |
d81712dd1a46
[svn] Cleaned up and improved output and fail state.
icculus
parents:
11
diff
changeset
|
424 |
va_start(ap, fmt); |
34 | 425 |
const int len = vsnprintf(scratch,SCRATCH_BUFFER_SIZE,fmt,ap); |
12
d81712dd1a46
[svn] Cleaned up and improved output and fail state.
icculus
parents:
11
diff
changeset
|
426 |
va_end(ap); |
d81712dd1a46
[svn] Cleaned up and improved output and fail state.
icculus
parents:
11
diff
changeset
|
427 |
|
18
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
428 |
char *failstr = (char *) ctx->malloc(len + 1); |
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
429 |
if (failstr == NULL) |
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
430 |
out_of_memory(ctx); |
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
431 |
else |
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
432 |
{ |
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
433 |
// see comments about scratch buffer overflow in output_line(). |
34 | 434 |
if (len < SCRATCH_BUFFER_SIZE) |
18
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
435 |
strcpy(failstr, scratch); // copy it over. |
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
436 |
else |
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
437 |
{ |
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
438 |
va_start(ap, fmt); |
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
439 |
vsnprintf(failstr, len + 1, fmt, ap); // rebuild it. |
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
440 |
va_end(ap); |
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
441 |
} // else |
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
442 |
ctx->failstr = failstr; |
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
443 |
} // else |
12
d81712dd1a46
[svn] Cleaned up and improved output and fail state.
icculus
parents:
11
diff
changeset
|
444 |
} // if |
d81712dd1a46
[svn] Cleaned up and improved output and fail state.
icculus
parents:
11
diff
changeset
|
445 |
|
d81712dd1a46
[svn] Cleaned up and improved output and fail state.
icculus
parents:
11
diff
changeset
|
446 |
return FAIL; |
d81712dd1a46
[svn] Cleaned up and improved output and fail state.
icculus
parents:
11
diff
changeset
|
447 |
} // failf |
d81712dd1a46
[svn] Cleaned up and improved output and fail state.
icculus
parents:
11
diff
changeset
|
448 |
|
d81712dd1a46
[svn] Cleaned up and improved output and fail state.
icculus
parents:
11
diff
changeset
|
449 |
|
18
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
450 |
static inline int fail(Context *ctx, const char *reason) |
12
d81712dd1a46
[svn] Cleaned up and improved output and fail state.
icculus
parents:
11
diff
changeset
|
451 |
{ |
d81712dd1a46
[svn] Cleaned up and improved output and fail state.
icculus
parents:
11
diff
changeset
|
452 |
return failf(ctx, "%s", reason); |
d81712dd1a46
[svn] Cleaned up and improved output and fail state.
icculus
parents:
11
diff
changeset
|
453 |
} // fail |
d81712dd1a46
[svn] Cleaned up and improved output and fail state.
icculus
parents:
11
diff
changeset
|
454 |
|
d81712dd1a46
[svn] Cleaned up and improved output and fail state.
icculus
parents:
11
diff
changeset
|
455 |
|
18
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
456 |
static int output_line(Context *ctx, const char *fmt, ...) ISPRINTF(2,3); |
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
457 |
static int output_line(Context *ctx, const char *fmt, ...) |
7 | 458 |
{ |
54
b2b64d39df0f
[svn] Split up output into several lists, so GLSL profile can insert lines of text
icculus
parents:
51
diff
changeset
|
459 |
OutputListNode *item = NULL; |
b2b64d39df0f
[svn] Split up output into several lists, so GLSL profile can insert lines of text
icculus
parents:
51
diff
changeset
|
460 |
|
44
5d56cf8b4571
[svn] Cleaned up fail check, parse_args and state machine semantics, and added check
icculus
parents:
43
diff
changeset
|
461 |
if (isfail(ctx)) |
12
d81712dd1a46
[svn] Cleaned up and improved output and fail state.
icculus
parents:
11
diff
changeset
|
462 |
return FAIL; // we failed previously, don't go on... |
d81712dd1a46
[svn] Cleaned up and improved output and fail state.
icculus
parents:
11
diff
changeset
|
463 |
|
18
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
464 |
char *scratch = get_scratch_buffer(ctx); |
40
f54f1635ac8a
[svn] Filling in some initial GLSL output. Not even close to done!
icculus
parents:
39
diff
changeset
|
465 |
|
f54f1635ac8a
[svn] Filling in some initial GLSL output. Not even close to done!
icculus
parents:
39
diff
changeset
|
466 |
const int indent = ctx->indent; |
41 | 467 |
if (indent > 0) |
468 |
memset(scratch, '\t', indent); |
|
56
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
469 |
|
12
d81712dd1a46
[svn] Cleaned up and improved output and fail state.
icculus
parents:
11
diff
changeset
|
470 |
va_list ap; |
d81712dd1a46
[svn] Cleaned up and improved output and fail state.
icculus
parents:
11
diff
changeset
|
471 |
va_start(ap, fmt); |
40
f54f1635ac8a
[svn] Filling in some initial GLSL output. Not even close to done!
icculus
parents:
39
diff
changeset
|
472 |
const int len = vsnprintf(scratch+indent, SCRATCH_BUFFER_SIZE-indent, fmt, ap) + indent; |
12
d81712dd1a46
[svn] Cleaned up and improved output and fail state.
icculus
parents:
11
diff
changeset
|
473 |
va_end(ap); |
d81712dd1a46
[svn] Cleaned up and improved output and fail state.
icculus
parents:
11
diff
changeset
|
474 |
|
56
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
475 |
item = (OutputListNode *) ctx->malloc(sizeof (OutputListNode)); |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
476 |
if (item == NULL) |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
477 |
return out_of_memory(ctx); |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
478 |
|
18
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
479 |
item->str = (char *) ctx->malloc(len + 1); |
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
480 |
if (item->str == NULL) |
12
d81712dd1a46
[svn] Cleaned up and improved output and fail state.
icculus
parents:
11
diff
changeset
|
481 |
{ |
18
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
482 |
free(item); |
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
483 |
return out_of_memory(ctx); |
12
d81712dd1a46
[svn] Cleaned up and improved output and fail state.
icculus
parents:
11
diff
changeset
|
484 |
} // if |
d81712dd1a46
[svn] Cleaned up and improved output and fail state.
icculus
parents:
11
diff
changeset
|
485 |
|
18
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
486 |
// If we overflowed our scratch buffer, that's okay. We were going to |
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
487 |
// allocate anyhow...the scratch buffer just lets us avoid a second |
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
488 |
// run of vsnprintf(). |
34 | 489 |
if (len < SCRATCH_BUFFER_SIZE) |
18
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
490 |
strcpy(item->str, scratch); // copy it over. |
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
491 |
else |
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
492 |
{ |
41 | 493 |
if (indent > 0) |
494 |
memset(item->str, '\t', indent); |
|
18
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
495 |
va_start(ap, fmt); |
40
f54f1635ac8a
[svn] Filling in some initial GLSL output. Not even close to done!
icculus
parents:
39
diff
changeset
|
496 |
vsnprintf(item->str+indent, len + 1, fmt, ap); // rebuild it. |
18
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
497 |
va_end(ap); |
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
498 |
} // else |
12
d81712dd1a46
[svn] Cleaned up and improved output and fail state.
icculus
parents:
11
diff
changeset
|
499 |
|
18
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
500 |
item->next = NULL; |
54
b2b64d39df0f
[svn] Split up output into several lists, so GLSL profile can insert lines of text
icculus
parents:
51
diff
changeset
|
501 |
|
b2b64d39df0f
[svn] Split up output into several lists, so GLSL profile can insert lines of text
icculus
parents:
51
diff
changeset
|
502 |
ctx->output->tail->next = item; |
b2b64d39df0f
[svn] Split up output into several lists, so GLSL profile can insert lines of text
icculus
parents:
51
diff
changeset
|
503 |
ctx->output->tail = item; |
18
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
504 |
ctx->output_len += len + ctx->endline_len; |
54
b2b64d39df0f
[svn] Split up output into several lists, so GLSL profile can insert lines of text
icculus
parents:
51
diff
changeset
|
505 |
|
12
d81712dd1a46
[svn] Cleaned up and improved output and fail state.
icculus
parents:
11
diff
changeset
|
506 |
return 0; |
d81712dd1a46
[svn] Cleaned up and improved output and fail state.
icculus
parents:
11
diff
changeset
|
507 |
} // output_line |
d81712dd1a46
[svn] Cleaned up and improved output and fail state.
icculus
parents:
11
diff
changeset
|
508 |
|
d81712dd1a46
[svn] Cleaned up and improved output and fail state.
icculus
parents:
11
diff
changeset
|
509 |
|
56
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
510 |
// this is just to stop gcc whining. |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
511 |
static inline int output_blank_line(Context *ctx) |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
512 |
{ |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
513 |
return output_line(ctx, "%s", ""); |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
514 |
} // output_blank_line |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
515 |
|
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
516 |
|
43
2f5d9a656dff
[svn] Bunch More Work. Cleaned up some lingering opcode drama, and state machine
icculus
parents:
42
diff
changeset
|
517 |
// !!! FIXME: this is sort of nasty. |
2f5d9a656dff
[svn] Bunch More Work. Cleaned up some lingering opcode drama, and state machine
icculus
parents:
42
diff
changeset
|
518 |
static void floatstr(Context *ctx, char *buf, size_t bufsize, float f) |
2f5d9a656dff
[svn] Bunch More Work. Cleaned up some lingering opcode drama, and state machine
icculus
parents:
42
diff
changeset
|
519 |
{ |
2f5d9a656dff
[svn] Bunch More Work. Cleaned up some lingering opcode drama, and state machine
icculus
parents:
42
diff
changeset
|
520 |
const size_t len = snprintf(buf, bufsize, "%f", f); |
2f5d9a656dff
[svn] Bunch More Work. Cleaned up some lingering opcode drama, and state machine
icculus
parents:
42
diff
changeset
|
521 |
if (len >= bufsize) |
2f5d9a656dff
[svn] Bunch More Work. Cleaned up some lingering opcode drama, and state machine
icculus
parents:
42
diff
changeset
|
522 |
fail(ctx, "BUG: internal buffer is too small"); |
2f5d9a656dff
[svn] Bunch More Work. Cleaned up some lingering opcode drama, and state machine
icculus
parents:
42
diff
changeset
|
523 |
else |
2f5d9a656dff
[svn] Bunch More Work. Cleaned up some lingering opcode drama, and state machine
icculus
parents:
42
diff
changeset
|
524 |
{ |
2f5d9a656dff
[svn] Bunch More Work. Cleaned up some lingering opcode drama, and state machine
icculus
parents:
42
diff
changeset
|
525 |
char *end = buf + len; |
2f5d9a656dff
[svn] Bunch More Work. Cleaned up some lingering opcode drama, and state machine
icculus
parents:
42
diff
changeset
|
526 |
char *ptr = strchr(buf, '.'); |
2f5d9a656dff
[svn] Bunch More Work. Cleaned up some lingering opcode drama, and state machine
icculus
parents:
42
diff
changeset
|
527 |
if (ptr == NULL) |
2f5d9a656dff
[svn] Bunch More Work. Cleaned up some lingering opcode drama, and state machine
icculus
parents:
42
diff
changeset
|
528 |
return; // done. |
2f5d9a656dff
[svn] Bunch More Work. Cleaned up some lingering opcode drama, and state machine
icculus
parents:
42
diff
changeset
|
529 |
|
2f5d9a656dff
[svn] Bunch More Work. Cleaned up some lingering opcode drama, and state machine
icculus
parents:
42
diff
changeset
|
530 |
while (--end != ptr) |
2f5d9a656dff
[svn] Bunch More Work. Cleaned up some lingering opcode drama, and state machine
icculus
parents:
42
diff
changeset
|
531 |
{ |
2f5d9a656dff
[svn] Bunch More Work. Cleaned up some lingering opcode drama, and state machine
icculus
parents:
42
diff
changeset
|
532 |
if (*end != '0') |
2f5d9a656dff
[svn] Bunch More Work. Cleaned up some lingering opcode drama, and state machine
icculus
parents:
42
diff
changeset
|
533 |
{ |
2f5d9a656dff
[svn] Bunch More Work. Cleaned up some lingering opcode drama, and state machine
icculus
parents:
42
diff
changeset
|
534 |
end++; |
2f5d9a656dff
[svn] Bunch More Work. Cleaned up some lingering opcode drama, and state machine
icculus
parents:
42
diff
changeset
|
535 |
break; |
2f5d9a656dff
[svn] Bunch More Work. Cleaned up some lingering opcode drama, and state machine
icculus
parents:
42
diff
changeset
|
536 |
} // if |
2f5d9a656dff
[svn] Bunch More Work. Cleaned up some lingering opcode drama, and state machine
icculus
parents:
42
diff
changeset
|
537 |
} // while |
2f5d9a656dff
[svn] Bunch More Work. Cleaned up some lingering opcode drama, and state machine
icculus
parents:
42
diff
changeset
|
538 |
*end = '\0'; // chop extra '0' or all decimal places off. |
2f5d9a656dff
[svn] Bunch More Work. Cleaned up some lingering opcode drama, and state machine
icculus
parents:
42
diff
changeset
|
539 |
} // else |
2f5d9a656dff
[svn] Bunch More Work. Cleaned up some lingering opcode drama, and state machine
icculus
parents:
42
diff
changeset
|
540 |
} // floatstr |
2f5d9a656dff
[svn] Bunch More Work. Cleaned up some lingering opcode drama, and state machine
icculus
parents:
42
diff
changeset
|
541 |
|
17 | 542 |
|
67 | 543 |
// This is used in more than just the d3d profile. |
24 | 544 |
static const char *get_D3D_register_string(Context *ctx, |
34 | 545 |
RegisterType regtype, |
24 | 546 |
int regnum, char *regnum_str, |
547 |
size_t regnum_size) |
|
548 |
{ |
|
549 |
const char *retval = NULL; |
|
31 | 550 |
int has_number = 1; |
24 | 551 |
|
552 |
switch (regtype) |
|
553 |
{ |
|
554 |
case REGISTER_TYPE_TEMP: |
|
555 |
retval = "r"; |
|
556 |
break; |
|
557 |
||
558 |
case REGISTER_TYPE_INPUT: |
|
559 |
retval = "v"; |
|
560 |
break; |
|
561 |
||
562 |
case REGISTER_TYPE_CONST: |
|
31 | 563 |
retval = "c"; |
564 |
break; |
|
565 |
||
24 | 566 |
case REGISTER_TYPE_CONST2: |
31 | 567 |
retval = "c"; |
568 |
regnum += 2048; |
|
569 |
break; |
|
570 |
||
24 | 571 |
case REGISTER_TYPE_CONST3: |
31 | 572 |
retval = "c"; |
573 |
regnum += 4096; |
|
574 |
break; |
|
575 |
||
24 | 576 |
case REGISTER_TYPE_CONST4: |
577 |
retval = "c"; |
|
31 | 578 |
regnum += 6144; |
24 | 579 |
break; |
580 |
||
56
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
581 |
case REGISTER_TYPE_ADDRESS: // (or REGISTER_TYPE_TEXTURE, same value.) |
46 | 582 |
retval = (ctx->shader_type == MOJOSHADER_TYPE_VERTEX) ? "a" : "t"; |
24 | 583 |
break; |
584 |
||
585 |
case REGISTER_TYPE_RASTOUT: |
|
34 | 586 |
switch ((RastOutType) regnum) |
24 | 587 |
{ |
588 |
case RASTOUT_TYPE_POSITION: retval = "oPos"; break; |
|
589 |
case RASTOUT_TYPE_FOG: retval = "oFog"; break; |
|
590 |
case RASTOUT_TYPE_POINT_SIZE: retval = "oPts"; break; |
|
591 |
} // switch |
|
31 | 592 |
has_number = 0; |
24 | 593 |
break; |
594 |
||
595 |
case REGISTER_TYPE_ATTROUT: |
|
596 |
retval = "oD"; |
|
597 |
break; |
|
598 |
||
56
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
599 |
case REGISTER_TYPE_OUTPUT: // (or REGISTER_TYPE_TEXCRDOUT, same value.) |
46 | 600 |
if ((ctx->shader_type==MOJOSHADER_TYPE_VERTEX) && (ctx->major_ver>=3)) |
24 | 601 |
retval = "o"; |
602 |
else |
|
603 |
retval = "oT"; |
|
604 |
break; |
|
605 |
||
606 |
case REGISTER_TYPE_CONSTINT: |
|
607 |
retval = "i"; |
|
608 |
break; |
|
609 |
||
610 |
case REGISTER_TYPE_COLOROUT: |
|
611 |
retval = "oC"; |
|
612 |
break; |
|
613 |
||
614 |
case REGISTER_TYPE_DEPTHOUT: |
|
615 |
retval = "oDepth"; |
|
31 | 616 |
has_number = 0; |
24 | 617 |
break; |
618 |
||
619 |
case REGISTER_TYPE_SAMPLER: |
|
620 |
retval = "s"; |
|
621 |
break; |
|
622 |
||
623 |
case REGISTER_TYPE_CONSTBOOL: |
|
624 |
retval = "b"; |
|
625 |
break; |
|
626 |
||
627 |
case REGISTER_TYPE_LOOP: |
|
628 |
retval = "aL"; |
|
31 | 629 |
has_number = 0; |
24 | 630 |
break; |
631 |
||
632 |
// !!! FIXME: don't know what the asm string is for this.. |
|
48 | 633 |
case REGISTER_TYPE_TEMPFLOAT16: |
67 | 634 |
fail(ctx, "don't know the ASM for tempfloat16 register"); |
48 | 635 |
retval = "???"; |
636 |
has_number = 0; |
|
637 |
break; |
|
24 | 638 |
|
639 |
case REGISTER_TYPE_MISCTYPE: |
|
34 | 640 |
switch ((MiscTypeType) regnum) |
24 | 641 |
{ |
642 |
case MISCTYPE_TYPE_POSITION: retval = "vPos"; break; |
|
643 |
case MISCTYPE_TYPE_FACE: retval = "vFace"; break; |
|
644 |
} // switch |
|
31 | 645 |
has_number = 0; |
24 | 646 |
break; |
647 |
||
648 |
case REGISTER_TYPE_LABEL: |
|
649 |
retval = "l"; |
|
650 |
break; |
|
651 |
||
652 |
case REGISTER_TYPE_PREDICATE: |
|
653 |
retval = "p"; |
|
654 |
break; |
|
655 |
} // switch |
|
656 |
||
31 | 657 |
if (has_number) |
658 |
snprintf(regnum_str, regnum_size, "%u", (uint) regnum); |
|
659 |
else |
|
660 |
regnum_str[0] = '\0'; |
|
661 |
||
24 | 662 |
return retval; |
663 |
} // get_D3D_register_string |
|
664 |
||
665 |
||
67 | 666 |
|
667 |
#define AT_LEAST_ONE_PROFILE 0 |
|
668 |
||
669 |
#if !SUPPORT_PROFILE_D3D |
|
670 |
#define PROFILE_EMITTER_D3D(op) |
|
671 |
#else |
|
672 |
#undef AT_LEAST_ONE_PROFILE |
|
673 |
#define AT_LEAST_ONE_PROFILE 1 |
|
674 |
#define PROFILE_EMITTER_D3D(op) emit_D3D_##op, |
|
675 |
||
68
f00ba7fcd0f8
Better const char * correction.
Ryan C. Gordon <icculus@icculus.org>
parents:
67
diff
changeset
|
676 |
static const char *make_D3D_destarg_string(Context *ctx, const int idx) |
15 | 677 |
{ |
20
bb2e8f285acc
[svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents:
19
diff
changeset
|
678 |
if (idx >= STATICARRAYLEN(ctx->dest_args)) |
bb2e8f285acc
[svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents:
19
diff
changeset
|
679 |
{ |
bb2e8f285acc
[svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents:
19
diff
changeset
|
680 |
fail(ctx, "Too many destination args"); |
68
f00ba7fcd0f8
Better const char * correction.
Ryan C. Gordon <icculus@icculus.org>
parents:
67
diff
changeset
|
681 |
return ""; |
20
bb2e8f285acc
[svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents:
19
diff
changeset
|
682 |
} // if |
16 | 683 |
|
21
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
684 |
const DestArgInfo *arg = &ctx->dest_args[idx]; |
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
685 |
|
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
686 |
const char *result_shift_str = ""; |
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
687 |
switch (arg->result_shift) |
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
688 |
{ |
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
689 |
case 0x1: result_shift_str = "_x2"; break; |
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
690 |
case 0x2: result_shift_str = "_x4"; break; |
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
691 |
case 0x3: result_shift_str = "_x8"; break; |
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
692 |
case 0xD: result_shift_str = "_d8"; break; |
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
693 |
case 0xE: result_shift_str = "_d4"; break; |
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
694 |
case 0xF: result_shift_str = "_d2"; break; |
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
695 |
} // switch |
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
696 |
|
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
697 |
const char *sat_str = (arg->result_mod & MOD_SATURATE) ? "_sat" : ""; |
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
698 |
const char *pp_str = (arg->result_mod & MOD_PP) ? "_pp" : ""; |
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
699 |
const char *cent_str = (arg->result_mod & MOD_CENTROID) ? "_centroid" : ""; |
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
700 |
|
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
701 |
char regnum_str[16]; |
56
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
702 |
const char *regtype_str = get_D3D_register_string(ctx, arg->regtype, |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
703 |
arg->regnum, regnum_str, |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
704 |
sizeof (regnum_str)); |
21
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
705 |
if (regtype_str == NULL) |
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
706 |
{ |
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
707 |
fail(ctx, "Unknown destination register type."); |
68
f00ba7fcd0f8
Better const char * correction.
Ryan C. Gordon <icculus@icculus.org>
parents:
67
diff
changeset
|
708 |
return ""; |
21
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
709 |
} // if |
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
710 |
|
27 | 711 |
char writemask_str[6]; |
712 |
int i = 0; |
|
713 |
if (arg->writemask != 0xF) // 0xF == 1111. No explicit mask. |
|
714 |
{ |
|
715 |
writemask_str[i++] = '.'; |
|
716 |
if (arg->writemask0) writemask_str[i++] = 'x'; |
|
717 |
if (arg->writemask1) writemask_str[i++] = 'y'; |
|
718 |
if (arg->writemask2) writemask_str[i++] = 'z'; |
|
719 |
if (arg->writemask3) writemask_str[i++] = 'w'; |
|
720 |
} // if |
|
721 |
writemask_str[i] = '\0'; |
|
722 |
assert(i < sizeof (writemask_str)); |
|
21
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
723 |
|
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
724 |
// may turn out something like "_x2_sat_pp_centroid r0.xyzw" ... |
68
f00ba7fcd0f8
Better const char * correction.
Ryan C. Gordon <icculus@icculus.org>
parents:
67
diff
changeset
|
725 |
char *retval = get_scratch_buffer(ctx); |
34 | 726 |
snprintf(retval, SCRATCH_BUFFER_SIZE, "%s%s%s%s %s%s%s", |
21
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
727 |
result_shift_str, sat_str, pp_str, cent_str, |
27 | 728 |
regtype_str, regnum_str, writemask_str); |
67 | 729 |
// !!! FIXME: make sure the scratch buffer was large enough. |
17 | 730 |
return retval; |
20
bb2e8f285acc
[svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents:
19
diff
changeset
|
731 |
} // make_D3D_destarg_string |
16 | 732 |
|
733 |
||
68
f00ba7fcd0f8
Better const char * correction.
Ryan C. Gordon <icculus@icculus.org>
parents:
67
diff
changeset
|
734 |
static const char *make_D3D_sourcearg_string(Context *ctx, const int idx) |
16 | 735 |
{ |
20
bb2e8f285acc
[svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents:
19
diff
changeset
|
736 |
if (idx >= STATICARRAYLEN(ctx->source_args)) |
bb2e8f285acc
[svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents:
19
diff
changeset
|
737 |
{ |
bb2e8f285acc
[svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents:
19
diff
changeset
|
738 |
fail(ctx, "Too many source args"); |
68
f00ba7fcd0f8
Better const char * correction.
Ryan C. Gordon <icculus@icculus.org>
parents:
67
diff
changeset
|
739 |
return ""; |
20
bb2e8f285acc
[svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents:
19
diff
changeset
|
740 |
} // if |
16 | 741 |
|
24 | 742 |
const SourceArgInfo *arg = &ctx->source_args[idx]; |
743 |
||
744 |
const char *premod_str = ""; |
|
745 |
const char *postmod_str = ""; |
|
34 | 746 |
switch ((SourceMod) arg->src_mod) |
24 | 747 |
{ |
748 |
case SRCMOD_NEGATE: |
|
749 |
premod_str = "-"; |
|
750 |
break; |
|
751 |
||
752 |
case SRCMOD_BIASNEGATE: |
|
753 |
premod_str = "-"; |
|
754 |
// fall through. |
|
755 |
case SRCMOD_BIAS: |
|
756 |
postmod_str = "_bias"; |
|
757 |
break; |
|
758 |
||
759 |
case SRCMOD_SIGNNEGATE: |
|
760 |
premod_str = "-"; |
|
761 |
// fall through. |
|
762 |
case SRCMOD_SIGN: |
|
763 |
postmod_str = "_bx2"; |
|
764 |
break; |
|
765 |
||
766 |
case SRCMOD_COMPLEMENT: |
|
767 |
premod_str = "1-"; |
|
768 |
break; |
|
769 |
||
770 |
case SRCMOD_X2NEGATE: |
|
771 |
premod_str = "-"; |
|
772 |
// fall through. |
|
773 |
case SRCMOD_X2: |
|
774 |
postmod_str = "_x2"; |
|
775 |
break; |
|
776 |
||
777 |
case SRCMOD_DZ: |
|
778 |
postmod_str = "_dz"; |
|
779 |
break; |
|
780 |
||
781 |
case SRCMOD_DW: |
|
782 |
postmod_str = "_dw"; |
|
783 |
break; |
|
784 |
||
785 |
case SRCMOD_ABSNEGATE: |
|
786 |
premod_str = "-"; |
|
787 |
// fall through. |
|
788 |
case SRCMOD_ABS: |
|
789 |
postmod_str = "_abs"; |
|
790 |
break; |
|
791 |
||
792 |
case SRCMOD_NOT: |
|
793 |
premod_str = "!"; |
|
794 |
break; |
|
48 | 795 |
|
796 |
case SRCMOD_NONE: |
|
797 |
case SRCMOD_TOTAL: |
|
798 |
break; // stop compiler whining. |
|
24 | 799 |
} // switch |
800 |
||
801 |
||
802 |
char regnum_str[16]; |
|
56
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
803 |
const char *regtype_str = get_D3D_register_string(ctx, arg->regtype, |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
804 |
arg->regnum, regnum_str, |
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
805 |
sizeof (regnum_str)); |
24 | 806 |
|
807 |
if (regtype_str == NULL) |
|
808 |
{ |
|
809 |
fail(ctx, "Unknown source register type."); |
|
68
f00ba7fcd0f8
Better const char * correction.
Ryan C. Gordon <icculus@icculus.org>
parents:
67
diff
changeset
|
810 |
return ""; |
24 | 811 |
} // if |
812 |
||
813 |
char swizzle_str[6]; |
|
814 |
int i = 0; |
|
26 | 815 |
if (arg->swizzle != 0xE4) // 0xE4 == 11100100 ... 3 2 1 0. No swizzle. |
24 | 816 |
{ |
817 |
static const char channel[] = { 'x', 'y', 'z', 'w' }; |
|
818 |
swizzle_str[i++] = '.'; |
|
25 | 819 |
swizzle_str[i++] = channel[arg->swizzle_x]; |
820 |
swizzle_str[i++] = channel[arg->swizzle_y]; |
|
821 |
swizzle_str[i++] = channel[arg->swizzle_z]; |
|
822 |
swizzle_str[i++] = channel[arg->swizzle_w]; |
|
24 | 823 |
|
25 | 824 |
// .xyzz is the same as .xyz, .z is the same as .zzzz, etc. |
825 |
while (swizzle_str[i-1] == swizzle_str[i-2]) |
|
826 |
i--; |
|
24 | 827 |
} // if |
828 |
swizzle_str[i] = '\0'; |
|
829 |
assert(i < sizeof (swizzle_str)); |
|
830 |
||
68
f00ba7fcd0f8
Better const char * correction.
Ryan C. Gordon <icculus@icculus.org>
parents:
67
diff
changeset
|
831 |
char *retval = get_scratch_buffer(ctx); |
38 | 832 |
snprintf(retval, SCRATCH_BUFFER_SIZE, "%s%s%s%s%s", |
833 |
premod_str, regtype_str, regnum_str, postmod_str, swizzle_str); |
|
67 | 834 |
// !!! FIXME: make sure the scratch buffer was large enough. |
17 | 835 |
return retval; |
20
bb2e8f285acc
[svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents:
19
diff
changeset
|
836 |
} // make_D3D_sourcearg_string |
16 | 837 |
|
838 |
||
18
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
839 |
static void emit_D3D_start(Context *ctx) |
16 | 840 |
{ |
841 |
const uint major = (uint) ctx->major_ver; |
|
842 |
const uint minor = (uint) ctx->minor_ver; |
|
24 | 843 |
const char *shadertype_str = NULL; |
844 |
char minor_str[16]; |
|
845 |
||
846 |
if (minor == 0xFF) |
|
847 |
strcpy(minor_str, "sw"); |
|
848 |
else if (minor == 0x1) // apparently this is "vs_2_x". Weird. |
|
849 |
strcpy(minor_str, "x"); |
|
850 |
else |
|
851 |
snprintf(minor_str, sizeof (minor_str), "%u", (uint) minor); |
|
19
8bca9cb2252f
[svn] Fixed output for software vertex shader versions.
icculus
parents:
18
diff
changeset
|
852 |
|
46 | 853 |
if (ctx->shader_type == MOJOSHADER_TYPE_PIXEL) |
24 | 854 |
shadertype_str = "ps"; |
46 | 855 |
else if (ctx->shader_type == MOJOSHADER_TYPE_VERTEX) |
24 | 856 |
shadertype_str = "vs"; |
15 | 857 |
else |
16 | 858 |
{ |
859 |
failf(ctx, "Shader type %u unsupported in this profile.", |
|
860 |
(uint) ctx->shader_type); |
|
24 | 861 |
return; |
16 | 862 |
} // else |
24 | 863 |
|
864 |
output_line(ctx, "%s_%u_%s", shadertype_str, major, minor_str); |
|
15 | 865 |
} // emit_D3D_start |
866 |
||
17 | 867 |
|
18
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
868 |
static void emit_D3D_end(Context *ctx) |
15 | 869 |
{ |
30 | 870 |
output_line(ctx, "end"); |
15 | 871 |
} // emit_D3D_end |
14 | 872 |
|
17 | 873 |
|
18
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
874 |
static void emit_D3D_comment(Context *ctx, const char *str) |
2
c37210f5e87b
[svn] Bunch More Work. Parse out instruction tokens, fail in a bunch of new stubs.
icculus
parents:
1
diff
changeset
|
875 |
{ |
14 | 876 |
output_line(ctx, "; %s", str); |
877 |
} // emit_D3D_comment |
|
2
c37210f5e87b
[svn] Bunch More Work. Parse out instruction tokens, fail in a bunch of new stubs.
icculus
parents:
1
diff
changeset
|
878 |
|
14 | 879 |
|
18
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
880 |
static void emit_D3D_RESERVED(Context *ctx) |
2
c37210f5e87b
[svn] Bunch More Work. Parse out instruction tokens, fail in a bunch of new stubs.
icculus
parents:
1
diff
changeset
|
881 |
{ |
14 | 882 |
// do nothing; fails in the state machine. |
883 |
} // emit_D3D_RESERVED |
|
884 |
||
17 | 885 |
|
886 |
// Generic D3D opcode emitters. A list of macros generate all the entry points |
|
887 |
// that call into these... |
|
888 |
||
30 | 889 |
static char *lowercase(char *dst, const char *src) |
890 |
{ |
|
891 |
int i = 0; |
|
892 |
do |
|
893 |
{ |
|
894 |
const char ch = src[i]; |
|
895 |
dst[i] = (((ch >= 'A') && (ch <= 'Z')) ? (ch - ('A' - 'a')) : ch); |
|
896 |
} while (src[i++]); |
|
897 |
return dst; |
|
898 |
} // lowercase |
|
899 |
||
900 |
||
18
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
901 |
static void emit_D3D_opcode_d(Context *ctx, const char *opcode) |
17 | 902 |
{ |
20
bb2e8f285acc
[svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents:
19
diff
changeset
|
903 |
const char *dst0 = make_D3D_destarg_string(ctx, 0); |
30 | 904 |
opcode = lowercase(get_scratch_buffer(ctx), opcode); |
21
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
905 |
output_line(ctx, "%s%s", opcode, dst0); |
17 | 906 |
} // emit_D3D_opcode_d |
907 |
||
908 |
||
18
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
909 |
static void emit_D3D_opcode_s(Context *ctx, const char *opcode) |
17 | 910 |
{ |
56
1e8b180d3eb1
[svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents:
55
diff
changeset
|
911 |
const char *src0 = make_D3D_sourcearg_string(ctx, 0); |
30 | 912 |
opcode = lowercase(get_scratch_buffer(ctx), opcode); |
20
bb2e8f285acc
[svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents:
19
diff
changeset
|
913 |
output_line(ctx, "%s %s", opcode, src0); |
17 | 914 |
} // emit_D3D_opcode_s |
915 |
||
916 |
||
18
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
917 |
static void emit_D3D_opcode_ss(Context *ctx, const char *opcode) |
17 | 918 |
{ |
20
bb2e8f285acc
[svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents:
19
diff
changeset
|
919 |
const char *src0 = make_D3D_sourcearg_string(ctx, 0); |
bb2e8f285acc
[svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents:
19
diff
changeset
|
920 |
const char *src1 = make_D3D_sourcearg_string(ctx, 1); |
30 | 921 |
opcode = lowercase(get_scratch_buffer(ctx), opcode); |
20
bb2e8f285acc
[svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents:
19
diff
changeset
|
922 |
output_line(ctx, "%s %s, %s", opcode, src0, src1); |
39 | 923 |
} // emit_D3D_opcode_ss |
17 | 924 |
|
925 |
||
18
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
926 |
static void emit_D3D_opcode_ds(Context *ctx, const char *opcode) |
17 | 927 |
{ |
20
bb2e8f285acc
[svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents:
19
diff
changeset
|
928 |
const char *dst0 = make_D3D_destarg_string(ctx, 0); |
bb2e8f285acc
[svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents:
19
diff
changeset
|
929 |
const char *src0 = make_D3D_sourcearg_string(ctx, 0); |
30 | 930 |
opcode = lowercase(get_scratch_buffer(ctx), opcode); |
21
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
931 |
output_line(ctx, "%s%s, %s", opcode, dst0, src0); |
17 | 932 |
} // emit_D3D_opcode_ds |
933 |
||
934 |
||
18
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
935 |
static void emit_D3D_opcode_dss(Context *ctx, const char *opcode) |
17 | 936 |
{ |
20
bb2e8f285acc
[svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents:
19
diff
changeset
|
937 |
const char *dst0 = make_D3D_destarg_string(ctx, 0); |
bb2e8f285acc
[svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents:
19
diff
changeset
|
938 |
const char *src0 = make_D3D_sourcearg_string(ctx, 0); |
bb2e8f285acc
[svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents:
19
diff
changeset
|
939 |
const char *src1 = make_D3D_sourcearg_string(ctx, 1); |
30 | 940 |
opcode = lowercase(get_scratch_buffer(ctx), opcode); |
21
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
941 |
output_line(ctx, "%s%s, %s, %s", opcode, dst0, src0, src1); |
17 | 942 |
} // emit_D3D_opcode_dss |
943 |
||
944 |
||
18
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
945 |
static void emit_D3D_opcode_dsss(Context *ctx, const char *opcode) |
17 | 946 |
{ |
20
bb2e8f285acc
[svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents:
19
diff
changeset
|
947 |
const char *dst0 = make_D3D_destarg_string(ctx, 0); |
bb2e8f285acc
[svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents:
19
diff
changeset
|
948 |
const char *src0 = make_D3D_sourcearg_string(ctx, 0); |
bb2e8f285acc
[svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents:
19
diff
changeset
|
949 |
const char *src1 = make_D3D_sourcearg_string(ctx, 1); |
bb2e8f285acc
[svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents:
19
diff
changeset
|
950 |
const char *src2 = make_D3D_sourcearg_string(ctx, 2); |
30 | 951 |
opcode = lowercase(get_scratch_buffer(ctx), opcode); |
21
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
952 |
output_line(ctx, "%s%s, %s, %s, %s", opcode, dst0, src0, src1, src2); |
17 | 953 |
} // emit_D3D_opcode_dsss |
954 |
||
955 |
||
18
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
956 |
static void emit_D3D_opcode_dssss(Context *ctx, const char *opcode) |
17 | 957 |
{ |
20
bb2e8f285acc
[svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents:
19
diff
changeset
|
958 |
const char *dst0 = make_D3D_destarg_string(ctx, 0); |
bb2e8f285acc
[svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents:
19
diff
changeset
|
959 |
const char *src0 = make_D3D_sourcearg_string(ctx, 0); |
bb2e8f285acc
[svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents:
19
diff
changeset
|
960 |
const char *src1 = make_D3D_sourcearg_string(ctx, 1); |
bb2e8f285acc
[svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents:
19
diff
changeset
|
961 |
const char *src2 = make_D3D_sourcearg_string(ctx, 2); |
bb2e8f285acc
[svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents:
19
diff
changeset
|
962 |
const char *src3 = make_D3D_sourcearg_string(ctx, 3); |
30 | 963 |
opcode = lowercase(get_scratch_buffer(ctx), opcode); |
21
d43449cf3cb2
[svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents:
20
diff
changeset
|
964 |
output_line(ctx,"%s%s, %s, %s, %s, %s",opcode,dst0,src0,src1,src2,src3); |
17 | 965 |
} // emit_D3D_opcode_dssss |
966 |
||
967 |
||
30 | 968 |
static void emit_D3D_opcode(Context *ctx, const char *opcode) |
969 |
{ |
|
970 |
opcode = lowercase(get_scratch_buffer(ctx), opcode); |
|
971 |
output_line(ctx, "%s", opcode); |
|
972 |
} // emit_D3D_opcode_dssss |
|
973 |
||
974 |
||
17 | 975 |
#define EMIT_D3D_OPCODE_FUNC(op) \ |
18
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
976 |
static void emit_D3D_##op(Context *ctx) { \ |
30 | 977 |
emit_D3D_opcode(ctx, #op); \ |
17 | 978 |
} |
979 |
#define EMIT_D3D_OPCODE_D_FUNC(op) \ |
|
18
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
980 |
static void emit_D3D_##op(Context *ctx) { \ |
17 | 981 |
emit_D3D_opcode_d(ctx, #op); \ |
982 |
} |
|
983 |
#define EMIT_D3D_OPCODE_S_FUNC(op) \ |
|
18
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
984 |
static void emit_D3D_##op(Context *ctx) { \ |
17 | 985 |
emit_D3D_opcode_s(ctx, #op); \ |
986 |
} |
|
987 |
#define EMIT_D3D_OPCODE_SS_FUNC(op) \ |
|
18
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
988 |
static void emit_D3D_##op(Context *ctx) { \ |
17 | 989 |
emit_D3D_opcode_ss(ctx, #op); \ |
990 |
} |
|
991 |
#define EMIT_D3D_OPCODE_DS_FUNC(op) \ |
|
18
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
992 |
static void emit_D3D_##op(Context *ctx) { \ |
17 | 993 |
emit_D3D_opcode_ds(ctx, #op); \ |
994 |
} |
|
995 |
#define EMIT_D3D_OPCODE_DSS_FUNC(op) \ |
|
18
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
996 |
static void emit_D3D_##op(Context *ctx) { \ |
17 | 997 |
emit_D3D_opcode_dss(ctx, #op); \ |
998 |
} |
|
999 |
#define EMIT_D3D_OPCODE_DSSS_FUNC(op) \ |
|
18
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
1000 |
static void emit_D3D_##op(Context *ctx) { \ |
17 | 1001 |
emit_D3D_opcode_dsss(ctx, #op); \ |
1002 |
} |
|
1003 |
#define EMIT_D3D_OPCODE_DSSSS_FUNC(op) \ |
|
18
0dbdb2be8bf8
[svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents:
17
diff
changeset
|
1004 |
static void emit_D3D_##op(Context *ctx) { \ |
17 | 1005 |
emit_D3D_opcode_dssss(ctx, #op); \ |
1006 |
} |
|
1007 |
||
1008 |
EMIT_D3D_OPCODE_FUNC(NOP) |
|
1009 |
EMIT_D3D_OPCODE_DS_FUNC(MOV) |
|
1010 |
EMIT_D3D_OPCODE_DSS_FUNC(ADD) |
|
1011 |
EMIT_D3D_OPCODE_DSS_FUNC(SUB) |
|
1012 |
EMIT_D3D_OPCODE_DSSS_FUNC(MAD) |
|
1013 |
EMIT_D3D_OPCODE_DSS_FUNC(MUL) |
|
1014 |
EMIT_D3D_OPCODE_DS_FUNC(RCP) |
|
1015 |
EMIT_D3D_OPCODE_DS_FUNC(RSQ) |
|
1016 |
EMIT_D3D_OPCODE_DSS_FUNC(DP3) |
|
1017 |
EMIT_D3D_OPCODE_DSS_FUNC(DP4) |
|
1018 |
EMIT_D3D_OPCODE_DSS_FUNC(MIN) |
|
1019 |
EMIT_D3D_OPCODE_DSS_FUNC(MAX) |
|
1020 |
EMIT_D3D_OPCODE_DSS_FUNC(SLT) |
|
1021 |
EMIT_D3D_OPCODE_DSS_FUNC(SGE) |
|
1022 |
EMIT_D3D_OPCODE_DS_FUNC(EXP) |
|
1023 |
EMIT_D3D_OPCODE_DS_FUNC(LOG) |
|
1024 |
EMIT_D3D_OPCODE_DS_FUNC(LIT) |
|
1025 |
EMIT_D3D_OPCODE_DSS_FUNC(DST) |
|
1026 |
EMIT_D3D_OPCODE_DSSS_FUNC(LRP) |
|
1027 |
EMIT_D3D_OPCODE_DS_FUNC(FRC) |
|
1028 |
EMIT_D3D_OPCODE_DSS_FUNC(M4X4) |
|
1029 |
EMIT_D3D_OPCODE_DSS_FUNC(M4X3) |
|
1030 |
EMIT_D3D_OPCODE_DSS_FUNC(M3X4) |
|
1031 |
EMIT_D3D_OPCODE_DSS_FUNC(M3X3) |
|
1032 |
EMIT_D3D_OPCODE_DSS_FUNC(M3X2) |
|
1033 |
EMIT_D3D_OPCODE_S_FUNC(CALL) |
|
1034 |
EMIT_D3D_OPCODE_SS_FUNC(CALLNZ) |
|
20
bb2e8f285acc
[svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents:
19
diff
changeset
|
1035 |
EMIT_D3D_OPCODE_SS_FUNC(LOOP) |
17 | 1036 |
EMIT_D3D_OPCODE_FUNC(RET) |
1037 |
EMIT_D3D_OPCODE_FUNC(ENDLOOP) |
|
1038 |
EMIT_D3D_OPCODE_S_FUNC(LABEL) |
|
1039 |
EMIT_D3D_OPCODE_DSS_FUNC(POW) |
|
1040 |
EMIT_D3D_OPCODE_DSS_FUNC(CRS) |
|
1041 |
EMIT_D3D_OPCODE_DSSS_FUNC(SGN) |
|
1042 |
EMIT_D3D_OPCODE_DS_FUNC(ABS) |
|
1043 |
EMIT_D3D_OPCODE_DS_FUNC(NRM) |
|
1044 |
EMIT_D3D_OPCODE_DS_FUNC(SINCOS) |
|
1045 |
EMIT_D3D_OPCODE_S_FUNC(REP) |
|
1046 |
EMIT_D3D_OPCODE_FUNC(ENDREP) |
|
1047 |
EMIT_D3D_OPCODE_S_FUNC(IF) |
|
1048 |
EMIT_D3D_OPCODE_FUNC(ELSE) |
|
1049 |
EMIT_D3D_OPCODE_FUNC(ENDIF) |
|
1050 |
EMIT_D3D_OPCODE_FUNC(BREAK) |
|
1051 |
EMIT_D3D_OPCODE_DS_FUNC(MOVA) |
|
1052 |
EMIT_D3D_OPCODE_D_FUNC(TEXKILL) |
|
1053 |
EMIT_D3D_OPCODE_DS_FUNC(TEXBEM) |
|
1054 |
EMIT_D3D_OPCODE_DS_FUNC(TEXBEML) |
|
1055 |
EMIT_D3D_OPCODE_DS_FUNC(TEXREG2AR) |
|
1056 |
EMIT_D3D_OPCODE_DS_FUNC(TEXREG2GB) |
|
1057 |
EMIT_D3D_OPCODE_DS_FUNC(TEXM3X2PAD) |
|
1058 |
EMIT_D3D_OPCODE_DS_FUNC(TEXM3X2TEX) |
|
1059 |
EMIT_D3D_OPCODE_DS_FUNC(TEXM3X3PAD) |
|
1060 |
EMIT_D3D_OPCODE_DS_FUNC(TEXM3X3TEX) |
|
1061 |
EMIT_D3D_OPCODE_DSS_FUNC(TEXM3X3SPEC) |
|
1062 |
EMIT_D3D_OPCODE_DS_FUNC(TEXM3X3VSPEC) |
|
1063 |
EMIT_D3D_OPCODE_DS_FUNC(EXPP) |
|
1064 |
EMIT_D3D_OPCODE_DS_FUNC(LOGP) |
|
1065 |
EMIT_D3D_OPCODE_DSSS_FUNC(CND) |
|
1066 |
EMIT_D3D_OPCODE_DS_FUNC(TEXREG2RGB) |
|
1067 |
EMIT_D3D_OPCODE_DS_FUNC(TEXDP3TEX) |
|
1068 |
EMIT_D3D_OPCODE_DS_FUNC(TEXM3X2DEPTH) |
|
1069 |
EMIT_D3D_OPCODE_DS_FUNC(TEXDP3) |
|
1070 |
EMIT_D3D_OPCODE_DS_FUNC(TEXM3X3) |
|
1071 |
EMIT_D3D_OPCODE_D_FUNC(TEXDEPTH) |
|
1072 |
EMIT_D3D_OPCODE_DSSS_FUNC(CMP) |
|
1073 |
EMIT_D3D_OPCODE_DSS_FUNC(BEM) |
|
1074 |
EMIT_D3D_OPCODE_DSSS_FUNC(DP2ADD) |
|
1075 |
EMIT_D3D_OPCODE_DS_FUNC(DSX) |
|
1076 |
EMIT_D3D_OPCODE_DS_FUNC(DSY) |
|
1077 |
EMIT_D3D_OPCODE_DSSSS_FUNC(TEXLDD) |
|
1078 |
EMIT_D3D_OPCODE_DSS_FUNC(TEXLDL) |
|
20
bb2e8f285acc
[svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents:
19
diff
changeset
|
1079 |
EMIT_D3D_OPCODE_S_FUNC(BREAKP) |
17 | 1080 |
|
28 | 1081 |
// special cases for comparison opcodes... |
1082 |
static const char *get_D3D_comparison_string(Context *ctx) |
|
1083 |
{ |
|
1084 |
static const char *comps[] = { |
|
1085 |
"", "_gt", "_eq", "_ge", "_lt", "_ne", "_le" |
|
1086 |
}; |
|
1087 |
||
1088 |
if (ctx->instruction_controls >= STATICARRAYLEN(comps)) |
|
1089 |
{ |
|
1090 |
fail(ctx, "unknown comparison control"); |
|
1091 |
return ""; |
|
1092 |
} // if |
|
1093 |
||
1094 |
return comps[ctx->instruction_controls]; |
|
1095 |
} // get_D3D_comparison_string |
|
1096 |
||
1097 |
static void emit_D3D_BREAKC(Context *ctx) |
|
1098 |
{ |
|
1099 |
char op[16]; |
|
30 | 1100 |
snprintf(op, sizeof (op), "break%s", get_D3D_comparison_string(ctx)); |
28 | 1101 |
emit_D3D_opcode_ss(ctx, op); |
1102 |
} // emit_D3D_BREAKC |
|
1103 |
||
1104 |
static void emit_D3D_IFC(Context *ctx) |
|
1105 |
{ |
|
1106 |
char op[16]; |
|
30 | 1107 |
snprintf(op, sizeof (op), "if%s", get_D3D_comparison_string(ctx)); |
28 | 1108 |
emit_D3D_opcode_ss(ctx, op); |
1109 |
} // emit_D3D_IFC |
|
1110 |
||
1111 |
static void emit_D3D_SETP(Context *ctx) |
|
1112 |
{ |
|
1113 |
char op[16]; |
|
30 | 1114 |
snprintf(op, sizeof (op), "setp%s", get_D3D_comparison_string(ctx)); |
28 | 1115 |
emit_D3D_opcode_dss(ctx, op); |
1116 |
} // emit_D3D_SETP |
|
1117 |
||
31 | 1118 |
static void emit_D3D_DEF(Context *ctx) |
1119 |
{ |
|
1120 |
const char *dst0 = make_D3D_destarg_string(ctx, 0); |
|
33
8b71012ebf65
[svn] Some heroic coding, since I can't figure out how to get printf() to output
icculus
parents:
32
diff
changeset
|
1121 |
const float *val = (const float *) ctx->dwords; // !!! FIXME: could be int? |
8b71012ebf65
[svn] Some heroic coding, since I can't figure out how to get printf() to output
icculus
parents:
32
diff
changeset
|
1122 |
char val0[32]; |
8b71012ebf65
[svn] Some heroic coding, since I can't figure out how to get printf() to output
icculus
parents:
32
diff
changeset
|
1123 |
char val1[32]; |
8b71012ebf65
[svn] Some heroic coding, since I can't figure out how to get printf() to output
icculus
parents:
32
diff
changeset
|
1124 |
char val2[32]; |
8b71012ebf65
[svn] Some heroic coding, since I can't figure out how to get printf() to output
icculus
parents:
32
diff
changeset
|
1125 |
char val3[32]; |
8b71012ebf65
[svn] Some heroic coding, since I can't figure out how to get printf() to output
icculus
parents:
32
diff
changeset
|
1126 |
floatstr(ctx, val0, sizeof (val0), val[0]); |
8b71012ebf65
[svn] Some heroic coding, since I can't figure out how to get printf() to output
icculus
parents:
32
diff
changeset
|
1127 |
floatstr(ctx, val1, sizeof (val1), val[1]); |
8b71012ebf65
[svn] Some heroic coding, since I can't figure out how to get printf() to output
icculus
parents:
32
diff
changeset
|
1128 |
floatstr(ctx, val2, sizeof (val2), val[2]); |
8b71012ebf65
[svn] Some heroic coding, since I can't figure out how to get printf() to output
icculus
parents:
32
diff
changeset
|
1129 |
floatstr(ctx, val3, sizeof (val3), val[3]); |
8b71012ebf65
[svn] Some heroic coding, since I can't figure out how to get printf() to output
icculus
parents:
32
diff
changeset
|
1130 |
output_line(ctx, "def%s, %s, %s, %s, %s", dst0, val0, val1, val2, val3); |
31 | 1131 |
} // emit_D3D_DEF |
1132 |
||
1133 |
static void emit_D3D_DEFI(Context *ctx) |
|
1134 |
{ |
|
1135 |
const char *dst0 = make_D3D_destarg_string(ctx, 0); |
|
1136 |
const int32 *x = (const int32 *) ctx->dwords; |
|
1137 |
output_line(ctx, "defi%s, %d, %d, %d, %d", dst0, |
|
1138 |
(int) x[0], (int) x[1], (int) x[2], (int) x[3]); |
|
1139 |
} // emit_D3D_DEFI |
|
1140 |
||
1141 |
static void emit_D3D_DEFB(Context *ctx) |
|
1142 |
{ |
|
1143 |
const char *dst0 = make_D3D_destarg_string(ctx, 0); |
|
32 | 1144 |
output_line(ctx, "defb%s, %s", dst0, ctx->dwords[0] ? "true" : "false"); |
31 | 1145 |
} // emit_D3D_DEFB |
1146 |
||
1147 |
||
1148 |
static void emit_D3D_DCL(Context *ctx) |
|
1149 |
{ |
|
1150 |
const char *dst0 = make_D3D_destarg_string(ctx, 0); |
|
1151 |
const DestArgInfo *arg = &ctx->dest_args[0]; |
|
1152 |
const char *usage_str = ""; |
|
1153 |
char index_str[16] = { '\0' }; |
|
1154 |
||
46 | 1155 |
if (ctx->shader_type == MOJOSHADER_TYPE_VERTEX) |
31 | 1156 |
{ |
1157 |
static const char *usagestrs[] = { |
|
1158 |
"_position", "_blendweight", "_blendindices", "_normal", |
|
1159 |
"_psize", "_texcoord", "_tangent", "_binormal", "_tessfactor", |
|
1160 |
"_positiont", "_color", "_fog", "_depth", "_sample" |
|
1161 |
}; |
|
1162 |
||
1163 |
const uint32 usage = ctx->dwords[0]; |
|
1164 |
const uint32 index = ctx->dwords[1]; |
|
1165 |
||
1166 |
if (usage >= STATICARRAYLEN(usagestrs)) |
|
1167 |
{ |
|
1168 |
fail(ctx, "unknown DCL usage"); |
|
1169 |
return; |
|
1170 |
} // if |
|
1171 |
||
1172 |
usage_str = usagestrs[usage]; |
|
1173 |
||
1174 |
if (index != 0) |
|
1175 |
snprintf(index_str, sizeof (index_str), "%u", (uint) index); |
|
1176 |
} // if |
|
1177 |
||
1178 |
else if (arg->regtype == REGISTER_TYPE_SAMPLER) |
|
1179 |
{ |
|
34 | 1180 |
switch ((const TextureType) ctx->dwords[0]) |
31 | 1181 |
{ |
1182 |
case TEXTURE_TYPE_2D: usage_str = "_2d"; break; |
|
1183 |
case TEXTURE_TYPE_CUBE: usage_str = "_cube"; break; |
|
1184 |
case TEXTURE_TYPE_VOLUME: usage_str = "_volume"; break; |
|
1185 |
default: fail(ctx, "unknown sampler texture type"); return; |
|
1186 |
} // switch |
|
1187 |
} // else if |
|
1188 |
||
1189 |
output_line(ctx, "dcl%s%s%s", usage_str, index_str, dst0); |
|
1190 |
} // emit_D3D_DCL |
|
1191 |
||
28 | 1192 |
|
43
2f5d9a656dff
[svn] Bunch More Work. Cleaned up some lingering opcode drama, and state machine
icculus
parents:
42
diff
changeset
|
1193 |
static void emit_D3D_TEXCOORD(Context *ctx) |
2f5d9a656dff
[svn] Bunch More Work. Cleaned up some lingering opcode drama, and state machine
icculus
parents:
42
diff
changeset
|
1194 |
{ |
2f5d9a656dff
[svn] Bunch More Work. Cleaned up some lingering opcode drama, and state machine
icculus
parents:
42
diff
changeset
|
1195 |
// this opcode looks and acts differently depending on the shader model. |
2f5d9a656dff
[svn] Bunch More Work. Cleaned up some lingering opcode drama, and state machine
icculus
parents:
42
diff
changeset
|
1196 |
if (shader_version_atleast(ctx, 1, 4)) |
2f5d9a656dff
[svn] Bunch More Work. Cleaned up some lingering opcode drama, and state machine
icculus
parents:
42
diff
changeset
|
1197 |
emit_D3D_opcode_ds(ctx, "texcrd"); |
2f5d9a656dff
[svn] Bunch More Work. Cleaned up some lingering opcode drama, and state machine
icculus
parents:
42
diff
changeset
|
1198 |
else |
2f5d9a656dff
[svn] Bunch More Work. Cleaned up some lingering opcode drama, and state machine
icculus
parents:
42
diff
changeset
|
1199 |
emit_D3D_opcode_d(ctx, "texcoord"); |
2f5d9a656dff
[svn] Bunch More Work. Cleaned up some lingering opcode drama, and state machine
icculus
parents:
42
diff
changeset
|
1200 |
} // emit_D3D_TEXCOORD |
2f5d9a656dff
[svn] Bunch More Work. Cleaned up some lingering opcode drama, and state machine
icculus
parents:
42
diff
changeset
|
1201 |
|
2f5d9a656dff
[svn] Bunch More Work. Cleaned up some lingering opcode drama, and state machine
icculus
parents:
42
diff
changeset
|
1202 |
static void emit_D3D_TEX(Context *ctx) |
2f5d9a656dff
[svn] Bunch More Work. Cleaned up some lingering opcode drama, and state machine
icculus
parents:
42
diff
changeset
|
1203 |
{ |
2f5d9a656dff
[svn] Bunch More Work. Cleaned up some lingering opcode drama, and state machine
icculus
parents:
42
diff
changeset
|
1204 |
// this opcode looks and acts differently depending on the shader model. |
2f5d9a656dff
[svn] Bunch More Work. Cleaned up some lingering opcode drama, and state machine
icculus
parents:
42
diff
changeset
|
1205 |
if (shader_version_atleast(ctx, 1, 4)) |
2f5d9a656dff
[svn] Bunch More Work. Cleaned up some lingering opcode drama, and state machine
icculus
parents:
42
diff
changeset
|
1206 |
emit_D3D_opcode_ds(ctx, "tex"); |
2f5d9a656dff
[svn] Bunch More Work. Cleaned up some lingering opcode drama, and state machine
icculus
parents:
42
diff
changeset
|
1207 |
else |
2f5d9a656dff
[svn] Bunch More Work. Cleaned up some lingering opcode drama, and state machine
icculus
parents:
42
diff
changeset
|
1208 |
emit_D3D_opcode_d(ctx, "texld"); |
2f5d9a656dff
[svn] Bunch More Work. Cleaned up some lingering opcode drama, and state machine
icculus
parents:
42
diff
changeset
|
1209 |
} // emit_D3D_TEX |
2f5d9a656dff
[svn] Bunch More Work. Cleaned up some lingering opcode drama, and state machine
icculus
parents:
42
diff
changeset
|
1210 |
|
2f5d9a656dff
[svn] Bunch More Work. Cleaned up some lingering opcode drama, and state machine
icculus
parents:
42
diff
changeset
|
1211 |
|
17 | 1212 |
#undef EMIT_D3D_OPCODE_FUNC |
1213 |
#undef EMIT_D3D_OPCODE_D_FUNC |
|
1214 |
#undef EMIT_D3D_OPCODE_S_FUNC |
|
1215 |
#undef EMIT_D3D_OPCODE_SS_FUNC |
|
1216 |
#undef EMIT_D3D_OPCODE_DS_FUNC |
|
1217 |
#undef EMIT_D3D_OPCODE_DSS_FUNC |
|
1218 |
#undef EMIT_D3D_OPCODE_DSSS_FUNC |
|
1219 |
#undef EMIT_D3D_OPCODE_DSSSS_FUNC |
|
1220 |
||
14 | 1221 |
#endif // SUPPORT_PROFILE_D3D |
1222 |
||
1223 |
||
2
c37210f5e87b
[svn] Bunch More Work. Parse out instruction tokens, fail in a bunch of new stubs.
icculus
parents:
1
diff
changeset
|
1224 |
|
14 | 1225 |
#if !SUPPORT_PROFILE_GLSL |
15 | 1226 |
#define PROFILE_EMITTER_GLSL(op) |
14 | 1227 |
#else |
1228 |
#undef AT_LEAST_ONE_PROFILE |
|
1229 |
#define AT_LEAST_ONE_PROFILE 1 |
|
15 | 1230 |
#define PROFILE_EMITTER_GLSL(op) emit_GLSL_##op, |
1231 |
||
67 | 1232 |
const char *get_GLSL_register_string(Context *ctx, RegisterType regtype, |
1233 |
int regnum, char *regnum_str, int len) |
|
1234 |
{ |
|
1235 |
||
1236 |
const char *retval = get_D3D_register_string(ctx, regtype, regnum, |
|
1237 |
regnum_str, len); |
|
1238 |
if (retval == NULL) |
|
1239 |
{ |
|
1240 |
fail(ctx, "Unknown D3D register type."); |
|
1241 |
return ""; |
|
1242 |
} // if |
|
1243 |
||
1244 |
return retval; |
|
1245 |
} // get_GLSL_register_string |
|
1246 |
||
1247 |
||
1248 |
const char *get_GLSL_destarg_varname(Context *ctx, int idx) |
|
1249 |
{ |
|
1250 |
if (idx >= STATICARRAYLEN(ctx->dest_args)) |
|
1251 |
{ |
|
1252 |
fail(ctx, "Too many destination args"); |
|
1253 |
return ""; |
|
1254 |
} // if |
|
1255 |
||
1256 |
const DestArgInfo *arg = &ctx->dest_args[idx]; |
|
1257 |
char regnum_str[16]; |
|
1258 |
const char *regtype_str = get_GLSL_register_string(ctx, arg->regtype, |
|
1259 |
arg->regnum, regnum_str, |
|
1260 |
sizeof (regnum_str)); |
|
1261 |
||
1262 |
char *retval = get_scratch_buffer(ctx); |
|
1263 |
snprintf(retval, SCRATCH_BUFFER_SIZE, "%s%s", regtype_str, regnum_str); |
|
1264 |
return retval; |
|
1265 |
} // get_GLSL_destarg_varname |
|
1266 |
||
1267 |
||
1268 |
||
1269 |
static const char *make_GLSL_destarg_assign(Context *, const int, const char *, ...) ISPRINTF(3,4); |
|
1270 |
static const char *make_GLSL_destarg_assign(Context *ctx, const int idx, |
|
1271 |
const char *fmt, ...) |
|
40
f54f1635ac8a
[svn] Filling in some initial GLSL output. Not even close to done!
icculus
parents:
39
diff
changeset
|
1272 |
{ |
f54f1635ac8a
[svn] Filling in some initial GLSL output. Not even close to done!
icculus
parents:
39
diff
changeset
|
1273 |
if (idx >= STATICARRAYLEN(ctx->dest_args)) |
f54f1635ac8a
[svn] Filling in some initial GLSL output. Not even close to done!
icculus
parents:
39
diff
changeset
|
1274 |
{ |
f54f1635ac8a
[svn] Filling in some initial GLSL output. Not even close to done!
icculus
parents:
39
diff
changeset
|
1275 |
fail(ctx, "Too many destination args"); |
f54f1635ac8a
[svn] Filling in some initial GLSL output. Not even close to done!
icculus
parents:
39
diff
changeset
|
1276 |
return ""; |
f54f1635ac8a
[svn] Filling in some initial GLSL output. Not even close to done!
icculus
parents:
39
diff
changeset
|
1277 |
} // if |
f54f1635ac8a
[svn] Filling in some initial GLSL output. Not even close to done!
icculus
parents:
39
diff
changeset
|
1278 |
|
67 | 1279 |
int need_parens = 0; |
1280 |
const DestArgInfo *arg = &ctx->dest_args[idx]; |
|
1281 |
char *operation = get_scratch_buffer(ctx); |
|
1282 |
va_list ap; |
|
1283 |
va_start(ap, fmt); |
|
1284 |
const int len = vsnprintf(operation, SCRATCH_BUFFER_SIZE, fmt, ap); |
|
1285 |
va_end(ap); |
|
1286 |
if (len >= SCRATCH_BUFFER_SIZE) |
|
1287 |
{ |
|
1288 |
fail(ctx, "operation string too large"); // I'm lazy. :P |
|
1289 |
return ""; |
|
1290 |
} // if |
|
1291 |
||
1292 |
const char *result_shift_str = ""; |
|
1293 |
switch (arg->result_shift) |
|
1294 |
{ |
|
1295 |
case 0x1: result_shift_str = " * 2"; break; |
|
1296 |
case 0x2: result_shift_str = " * 4"; break; |
|
1297 |
case 0x3: result_shift_str = " * 8"; break; |
|
1298 |
case 0xD: result_shift_str = " / 8"; break; |
|
1299 |
case 0xE: result_shift_str = " / 4"; break; |
|
1300 |
case 0xF: result_shift_str = " / 2"; break; |
|
1301 |
} // switch |
|
1302 |
need_parens |= (result_shift_str[0] != '\0'); |
|
1303 |
||
1304 |
// !!! FIXME |
|
1305 |
// const char *sat_str = (arg->result_mod & MOD_SATURATE) ? "_sat" : ""; |
|
1306 |
// const char *pp_str = (arg->result_mod & MOD_PP) ? "_pp" : ""; |
|
1307 |
// const char *cent_str = (arg->result_mod & MOD_CENTROID) ? "_centroid" : ""; |
|
1308 |
||
1309 |
// !!! FIXME: use get_GLSL_destarg_varname() here? |
|
1310 |
char regnum_str[16]; |
|
1311 |
const char *regtype_str = get_GLSL_register_string(ctx, arg->regtype, |
|
1312 |
arg->regnum, regnum_str, |
|
1313 |
sizeof (regnum_str)); |
|
1314 |
char writemask_str[6]; |
|
1315 |
int i = 0; |
|
1316 |
if (arg->writemask != 0xF) // 0xF == 1111. No explicit mask. |
|
1317 |
{ |
|
1318 |
writemask_str[i++] = '.'; |
|
1319 |
if (arg->writemask0) writemask_str[i++] = 'x'; |
|
1320 |
if (arg->writemask1) writemask_str[i++] = 'y'; |
|
1321 |
if (arg->writemask2) writemask_str[i++] = 'z'; |
|
1322 |
if (arg->writemask3) writemask_str[i++] = 'w'; |
|
1323 |
} // if |
|
1324 |
writemask_str[i] = '\0'; |
|
1325 |
assert(i < sizeof (writemask_str)); |
|
1326 |
||