1 | /*
|
---|
2 | * Copyright 2002-2003 Jason Edmeades
|
---|
3 | * Copyright 2002-2003 Raphael Junqueira
|
---|
4 | * Copyright 2004 Christian Costa
|
---|
5 | * Copyright 2005 Oliver Stieber
|
---|
6 | * Copyright 2006 Ivan Gyurdiev
|
---|
7 | * Copyright 2007-2008 Stefan Dösinger for CodeWeavers
|
---|
8 | * Copyright 2009 Henri Verbeet for CodeWeavers
|
---|
9 | *
|
---|
10 | * This library is free software; you can redistribute it and/or
|
---|
11 | * modify it under the terms of the GNU Lesser General Public
|
---|
12 | * License as published by the Free Software Foundation; either
|
---|
13 | * version 2.1 of the License, or (at your option) any later version.
|
---|
14 | *
|
---|
15 | * This library is distributed in the hope that it will be useful,
|
---|
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
18 | * Lesser General Public License for more details.
|
---|
19 | *
|
---|
20 | * You should have received a copy of the GNU Lesser General Public
|
---|
21 | * License along with this library; if not, write to the Free Software
|
---|
22 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
---|
23 | */
|
---|
24 |
|
---|
25 | /*
|
---|
26 | * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
|
---|
27 | * other than GPL or LGPL is available it will apply instead, Sun elects to use only
|
---|
28 | * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
|
---|
29 | * a choice of LGPL license versions is made available with the language indicating
|
---|
30 | * that LGPLv2 or any later version may be used, or where a choice of which version
|
---|
31 | * of the LGPL is applied is otherwise unspecified.
|
---|
32 | */
|
---|
33 |
|
---|
34 | #include "config.h"
|
---|
35 | #include "wine/port.h"
|
---|
36 |
|
---|
37 | #include "wined3d_private.h"
|
---|
38 |
|
---|
39 | WINE_DEFAULT_DEBUG_CHANNEL(d3d_shader);
|
---|
40 |
|
---|
41 | /* DCL usage masks */
|
---|
42 | #define WINED3DSP_DCL_USAGE_SHIFT 0
|
---|
43 | #define WINED3DSP_DCL_USAGE_MASK (0xf << WINED3DSP_DCL_USAGE_SHIFT)
|
---|
44 | #define WINED3DSP_DCL_USAGEINDEX_SHIFT 16
|
---|
45 | #define WINED3DSP_DCL_USAGEINDEX_MASK (0xf << WINED3DSP_DCL_USAGEINDEX_SHIFT)
|
---|
46 |
|
---|
47 | /* DCL sampler type */
|
---|
48 | #define WINED3DSP_TEXTURETYPE_SHIFT 27
|
---|
49 | #define WINED3DSP_TEXTURETYPE_MASK (0xf << WINED3DSP_TEXTURETYPE_SHIFT)
|
---|
50 |
|
---|
51 | /* Opcode-related masks */
|
---|
52 | #define WINED3DSI_OPCODE_MASK 0x0000ffff
|
---|
53 |
|
---|
54 | #define WINED3D_OPCODESPECIFICCONTROL_SHIFT 16
|
---|
55 | #define WINED3D_OPCODESPECIFICCONTROL_MASK (0xff << WINED3D_OPCODESPECIFICCONTROL_SHIFT)
|
---|
56 |
|
---|
57 | #define WINED3DSI_INSTLENGTH_SHIFT 24
|
---|
58 | #define WINED3DSI_INSTLENGTH_MASK (0xf << WINED3DSI_INSTLENGTH_SHIFT)
|
---|
59 |
|
---|
60 | #define WINED3DSI_COISSUE (1 << 30)
|
---|
61 |
|
---|
62 | #define WINED3DSI_COMMENTSIZE_SHIFT 16
|
---|
63 | #define WINED3DSI_COMMENTSIZE_MASK (0x7fff << WINED3DSI_COMMENTSIZE_SHIFT)
|
---|
64 |
|
---|
65 | #define WINED3DSHADER_INSTRUCTION_PREDICATED (1 << 28)
|
---|
66 |
|
---|
67 | /* Register number mask */
|
---|
68 | #define WINED3DSP_REGNUM_MASK 0x000007ff
|
---|
69 |
|
---|
70 | /* Register type masks */
|
---|
71 | #define WINED3DSP_REGTYPE_SHIFT 28
|
---|
72 | #define WINED3DSP_REGTYPE_MASK (0x7 << WINED3DSP_REGTYPE_SHIFT)
|
---|
73 | #define WINED3DSP_REGTYPE_SHIFT2 8
|
---|
74 | #define WINED3DSP_REGTYPE_MASK2 (0x18 << WINED3DSP_REGTYPE_SHIFT2)
|
---|
75 |
|
---|
76 | /* Relative addressing mask */
|
---|
77 | #define WINED3DSHADER_ADDRESSMODE_SHIFT 13
|
---|
78 | #define WINED3DSHADER_ADDRESSMODE_MASK (1 << WINED3DSHADER_ADDRESSMODE_SHIFT)
|
---|
79 |
|
---|
80 | /* Destination modifier mask */
|
---|
81 | #define WINED3DSP_DSTMOD_SHIFT 20
|
---|
82 | #define WINED3DSP_DSTMOD_MASK (0xf << WINED3DSP_DSTMOD_SHIFT)
|
---|
83 |
|
---|
84 | /* Destination shift mask */
|
---|
85 | #define WINED3DSP_DSTSHIFT_SHIFT 24
|
---|
86 | #define WINED3DSP_DSTSHIFT_MASK (0xf << WINED3DSP_DSTSHIFT_SHIFT)
|
---|
87 |
|
---|
88 | /* Write mask */
|
---|
89 | #define WINED3D_SM1_WRITEMASK_SHIFT 16
|
---|
90 | #define WINED3D_SM1_WRITEMASK_MASK (0xf << WINED3D_SM1_WRITEMASK_SHIFT)
|
---|
91 |
|
---|
92 | /* Swizzle mask */
|
---|
93 | #define WINED3DSP_SWIZZLE_SHIFT 16
|
---|
94 | #define WINED3DSP_SWIZZLE_MASK (0xff << WINED3DSP_SWIZZLE_SHIFT)
|
---|
95 |
|
---|
96 | /* Source modifier mask */
|
---|
97 | #define WINED3DSP_SRCMOD_SHIFT 24
|
---|
98 | #define WINED3DSP_SRCMOD_MASK (0xf << WINED3DSP_SRCMOD_SHIFT)
|
---|
99 |
|
---|
100 | #define WINED3DSP_END 0x0000ffff
|
---|
101 |
|
---|
102 | #define WINED3D_SM1_VERSION_MAJOR(version) (((version) >> 8) & 0xff)
|
---|
103 | #define WINED3D_SM1_VERSION_MINOR(version) (((version) >> 0) & 0xff)
|
---|
104 |
|
---|
105 | enum WINED3DSHADER_ADDRESSMODE_TYPE
|
---|
106 | {
|
---|
107 | WINED3DSHADER_ADDRMODE_ABSOLUTE = 0 << WINED3DSHADER_ADDRESSMODE_SHIFT,
|
---|
108 | WINED3DSHADER_ADDRMODE_RELATIVE = 1 << WINED3DSHADER_ADDRESSMODE_SHIFT,
|
---|
109 | };
|
---|
110 |
|
---|
111 | struct wined3d_sm1_opcode_info
|
---|
112 | {
|
---|
113 | unsigned int opcode;
|
---|
114 | UINT dst_count;
|
---|
115 | UINT param_count;
|
---|
116 | enum WINED3D_SHADER_INSTRUCTION_HANDLER handler_idx;
|
---|
117 | DWORD min_version;
|
---|
118 | DWORD max_version;
|
---|
119 | };
|
---|
120 |
|
---|
121 | struct wined3d_sm1_data
|
---|
122 | {
|
---|
123 | struct wined3d_shader_version shader_version;
|
---|
124 | const struct wined3d_sm1_opcode_info *opcode_table;
|
---|
125 | };
|
---|
126 |
|
---|
127 | /* This table is not order or position dependent. */
|
---|
128 | static const struct wined3d_sm1_opcode_info vs_opcode_table[] =
|
---|
129 | {
|
---|
130 | /* Arithmetic */
|
---|
131 | {WINED3DSIO_NOP, 0, 0, WINED3DSIH_NOP, 0, 0 },
|
---|
132 | {WINED3DSIO_MOV, 1, 2, WINED3DSIH_MOV, 0, 0 },
|
---|
133 | {WINED3DSIO_MOVA, 1, 2, WINED3DSIH_MOVA, WINED3D_SHADER_VERSION(2,0), -1 },
|
---|
134 | {WINED3DSIO_ADD, 1, 3, WINED3DSIH_ADD, 0, 0 },
|
---|
135 | {WINED3DSIO_SUB, 1, 3, WINED3DSIH_SUB, 0, 0 },
|
---|
136 | {WINED3DSIO_MAD, 1, 4, WINED3DSIH_MAD, 0, 0 },
|
---|
137 | {WINED3DSIO_MUL, 1, 3, WINED3DSIH_MUL, 0, 0 },
|
---|
138 | {WINED3DSIO_RCP, 1, 2, WINED3DSIH_RCP, 0, 0 },
|
---|
139 | {WINED3DSIO_RSQ, 1, 2, WINED3DSIH_RSQ, 0, 0 },
|
---|
140 | {WINED3DSIO_DP3, 1, 3, WINED3DSIH_DP3, 0, 0 },
|
---|
141 | {WINED3DSIO_DP4, 1, 3, WINED3DSIH_DP4, 0, 0 },
|
---|
142 | {WINED3DSIO_MIN, 1, 3, WINED3DSIH_MIN, 0, 0 },
|
---|
143 | {WINED3DSIO_MAX, 1, 3, WINED3DSIH_MAX, 0, 0 },
|
---|
144 | {WINED3DSIO_SLT, 1, 3, WINED3DSIH_SLT, 0, 0 },
|
---|
145 | {WINED3DSIO_SGE, 1, 3, WINED3DSIH_SGE, 0, 0 },
|
---|
146 | {WINED3DSIO_ABS, 1, 2, WINED3DSIH_ABS, 0, 0 },
|
---|
147 | {WINED3DSIO_EXP, 1, 2, WINED3DSIH_EXP, 0, 0 },
|
---|
148 | {WINED3DSIO_LOG, 1, 2, WINED3DSIH_LOG, 0, 0 },
|
---|
149 | {WINED3DSIO_EXPP, 1, 2, WINED3DSIH_EXPP, 0, 0 },
|
---|
150 | {WINED3DSIO_LOGP, 1, 2, WINED3DSIH_LOGP, 0, 0 },
|
---|
151 | {WINED3DSIO_LIT, 1, 2, WINED3DSIH_LIT, 0, 0 },
|
---|
152 | {WINED3DSIO_DST, 1, 3, WINED3DSIH_DST, 0, 0 },
|
---|
153 | {WINED3DSIO_LRP, 1, 4, WINED3DSIH_LRP, 0, 0 },
|
---|
154 | {WINED3DSIO_FRC, 1, 2, WINED3DSIH_FRC, 0, 0 },
|
---|
155 | {WINED3DSIO_POW, 1, 3, WINED3DSIH_POW, 0, 0 },
|
---|
156 | {WINED3DSIO_CRS, 1, 3, WINED3DSIH_CRS, 0, 0 },
|
---|
157 | {WINED3DSIO_SGN, 1, 2, WINED3DSIH_SGN, 0, 0 },
|
---|
158 | {WINED3DSIO_NRM, 1, 2, WINED3DSIH_NRM, 0, 0 },
|
---|
159 | {WINED3DSIO_SINCOS, 1, 4, WINED3DSIH_SINCOS, WINED3D_SHADER_VERSION(2,0), WINED3D_SHADER_VERSION(2,1)},
|
---|
160 | {WINED3DSIO_SINCOS, 1, 2, WINED3DSIH_SINCOS, WINED3D_SHADER_VERSION(3,0), -1 },
|
---|
161 | /* Matrix */
|
---|
162 | {WINED3DSIO_M4x4, 1, 3, WINED3DSIH_M4x4, 0, 0 },
|
---|
163 | {WINED3DSIO_M4x3, 1, 3, WINED3DSIH_M4x3, 0, 0 },
|
---|
164 | {WINED3DSIO_M3x4, 1, 3, WINED3DSIH_M3x4, 0, 0 },
|
---|
165 | {WINED3DSIO_M3x3, 1, 3, WINED3DSIH_M3x3, 0, 0 },
|
---|
166 | {WINED3DSIO_M3x2, 1, 3, WINED3DSIH_M3x2, 0, 0 },
|
---|
167 | /* Declare registers */
|
---|
168 | {WINED3DSIO_DCL, 0, 2, WINED3DSIH_DCL, 0, 0 },
|
---|
169 | /* Constant definitions */
|
---|
170 | {WINED3DSIO_DEF, 1, 5, WINED3DSIH_DEF, 0, 0 },
|
---|
171 | {WINED3DSIO_DEFB, 1, 2, WINED3DSIH_DEFB, 0, 0 },
|
---|
172 | {WINED3DSIO_DEFI, 1, 5, WINED3DSIH_DEFI, 0, 0 },
|
---|
173 | /* Flow control */
|
---|
174 | {WINED3DSIO_REP, 0, 1, WINED3DSIH_REP, WINED3D_SHADER_VERSION(2,0), -1 },
|
---|
175 | {WINED3DSIO_ENDREP, 0, 0, WINED3DSIH_ENDREP, WINED3D_SHADER_VERSION(2,0), -1 },
|
---|
176 | {WINED3DSIO_IF, 0, 1, WINED3DSIH_IF, WINED3D_SHADER_VERSION(2,0), -1 },
|
---|
177 | {WINED3DSIO_IFC, 0, 2, WINED3DSIH_IFC, WINED3D_SHADER_VERSION(2,1), -1 },
|
---|
178 | {WINED3DSIO_ELSE, 0, 0, WINED3DSIH_ELSE, WINED3D_SHADER_VERSION(2,0), -1 },
|
---|
179 | {WINED3DSIO_ENDIF, 0, 0, WINED3DSIH_ENDIF, WINED3D_SHADER_VERSION(2,0), -1 },
|
---|
180 | {WINED3DSIO_BREAK, 0, 0, WINED3DSIH_BREAK, WINED3D_SHADER_VERSION(2,1), -1 },
|
---|
181 | {WINED3DSIO_BREAKC, 0, 2, WINED3DSIH_BREAKC, WINED3D_SHADER_VERSION(2,1), -1 },
|
---|
182 | {WINED3DSIO_BREAKP, 0, 1, WINED3DSIH_BREAKP, 0, 0 },
|
---|
183 | {WINED3DSIO_CALL, 0, 1, WINED3DSIH_CALL, WINED3D_SHADER_VERSION(2,0), -1 },
|
---|
184 | {WINED3DSIO_CALLNZ, 0, 2, WINED3DSIH_CALLNZ, WINED3D_SHADER_VERSION(2,0), -1 },
|
---|
185 | {WINED3DSIO_LOOP, 0, 2, WINED3DSIH_LOOP, WINED3D_SHADER_VERSION(2,0), -1 },
|
---|
186 | {WINED3DSIO_RET, 0, 0, WINED3DSIH_RET, WINED3D_SHADER_VERSION(2,0), -1 },
|
---|
187 | {WINED3DSIO_ENDLOOP, 0, 0, WINED3DSIH_ENDLOOP, WINED3D_SHADER_VERSION(2,0), -1 },
|
---|
188 | {WINED3DSIO_LABEL, 0, 1, WINED3DSIH_LABEL, WINED3D_SHADER_VERSION(2,0), -1 },
|
---|
189 |
|
---|
190 | {WINED3DSIO_SETP, 1, 3, WINED3DSIH_SETP, 0, 0 },
|
---|
191 | {WINED3DSIO_TEXLDL, 1, 3, WINED3DSIH_TEXLDL, WINED3D_SHADER_VERSION(3,0), -1 },
|
---|
192 | {0, 0, 0, WINED3DSIH_TABLE_SIZE, 0, 0 },
|
---|
193 | };
|
---|
194 |
|
---|
195 | static const struct wined3d_sm1_opcode_info ps_opcode_table[] =
|
---|
196 | {
|
---|
197 | /* Arithmetic */
|
---|
198 | {WINED3DSIO_NOP, 0, 0, WINED3DSIH_NOP, 0, 0 },
|
---|
199 | {WINED3DSIO_MOV, 1, 2, WINED3DSIH_MOV, 0, 0 },
|
---|
200 | {WINED3DSIO_ADD, 1, 3, WINED3DSIH_ADD, 0, 0 },
|
---|
201 | {WINED3DSIO_SUB, 1, 3, WINED3DSIH_SUB, 0, 0 },
|
---|
202 | {WINED3DSIO_MAD, 1, 4, WINED3DSIH_MAD, 0, 0 },
|
---|
203 | {WINED3DSIO_MUL, 1, 3, WINED3DSIH_MUL, 0, 0 },
|
---|
204 | {WINED3DSIO_RCP, 1, 2, WINED3DSIH_RCP, 0, 0 },
|
---|
205 | {WINED3DSIO_RSQ, 1, 2, WINED3DSIH_RSQ, 0, 0 },
|
---|
206 | {WINED3DSIO_DP3, 1, 3, WINED3DSIH_DP3, 0, 0 },
|
---|
207 | {WINED3DSIO_DP4, 1, 3, WINED3DSIH_DP4, 0, 0 },
|
---|
208 | {WINED3DSIO_MIN, 1, 3, WINED3DSIH_MIN, 0, 0 },
|
---|
209 | {WINED3DSIO_MAX, 1, 3, WINED3DSIH_MAX, 0, 0 },
|
---|
210 | {WINED3DSIO_SLT, 1, 3, WINED3DSIH_SLT, 0, 0 },
|
---|
211 | {WINED3DSIO_SGE, 1, 3, WINED3DSIH_SGE, 0, 0 },
|
---|
212 | {WINED3DSIO_ABS, 1, 2, WINED3DSIH_ABS, 0, 0 },
|
---|
213 | {WINED3DSIO_EXP, 1, 2, WINED3DSIH_EXP, 0, 0 },
|
---|
214 | {WINED3DSIO_LOG, 1, 2, WINED3DSIH_LOG, 0, 0 },
|
---|
215 | {WINED3DSIO_EXPP, 1, 2, WINED3DSIH_EXPP, 0, 0 },
|
---|
216 | {WINED3DSIO_LOGP, 1, 2, WINED3DSIH_LOGP, 0, 0 },
|
---|
217 | {WINED3DSIO_DST, 1, 3, WINED3DSIH_DST, 0, 0 },
|
---|
218 | {WINED3DSIO_LRP, 1, 4, WINED3DSIH_LRP, 0, 0 },
|
---|
219 | {WINED3DSIO_FRC, 1, 2, WINED3DSIH_FRC, 0, 0 },
|
---|
220 | {WINED3DSIO_CND, 1, 4, WINED3DSIH_CND, WINED3D_SHADER_VERSION(1,0), WINED3D_SHADER_VERSION(1,4)},
|
---|
221 | {WINED3DSIO_CMP, 1, 4, WINED3DSIH_CMP, WINED3D_SHADER_VERSION(1,2), WINED3D_SHADER_VERSION(3,0)},
|
---|
222 | {WINED3DSIO_POW, 1, 3, WINED3DSIH_POW, 0, 0 },
|
---|
223 | {WINED3DSIO_CRS, 1, 3, WINED3DSIH_CRS, 0, 0 },
|
---|
224 | {WINED3DSIO_NRM, 1, 2, WINED3DSIH_NRM, 0, 0 },
|
---|
225 | {WINED3DSIO_SINCOS, 1, 4, WINED3DSIH_SINCOS, WINED3D_SHADER_VERSION(2,0), WINED3D_SHADER_VERSION(2,1)},
|
---|
226 | {WINED3DSIO_SINCOS, 1, 2, WINED3DSIH_SINCOS, WINED3D_SHADER_VERSION(3,0), -1 },
|
---|
227 | {WINED3DSIO_DP2ADD, 1, 4, WINED3DSIH_DP2ADD, WINED3D_SHADER_VERSION(2,0), -1 },
|
---|
228 | /* Matrix */
|
---|
229 | {WINED3DSIO_M4x4, 1, 3, WINED3DSIH_M4x4, 0, 0 },
|
---|
230 | {WINED3DSIO_M4x3, 1, 3, WINED3DSIH_M4x3, 0, 0 },
|
---|
231 | {WINED3DSIO_M3x4, 1, 3, WINED3DSIH_M3x4, 0, 0 },
|
---|
232 | {WINED3DSIO_M3x3, 1, 3, WINED3DSIH_M3x3, 0, 0 },
|
---|
233 | {WINED3DSIO_M3x2, 1, 3, WINED3DSIH_M3x2, 0, 0 },
|
---|
234 | /* Register declarations */
|
---|
235 | {WINED3DSIO_DCL, 0, 2, WINED3DSIH_DCL, 0, 0 },
|
---|
236 | /* Flow control */
|
---|
237 | {WINED3DSIO_REP, 0, 1, WINED3DSIH_REP, WINED3D_SHADER_VERSION(2,1), -1 },
|
---|
238 | {WINED3DSIO_ENDREP, 0, 0, WINED3DSIH_ENDREP, WINED3D_SHADER_VERSION(2,1), -1 },
|
---|
239 | {WINED3DSIO_IF, 0, 1, WINED3DSIH_IF, WINED3D_SHADER_VERSION(2,1), -1 },
|
---|
240 | {WINED3DSIO_IFC, 0, 2, WINED3DSIH_IFC, WINED3D_SHADER_VERSION(2,1), -1 },
|
---|
241 | {WINED3DSIO_ELSE, 0, 0, WINED3DSIH_ELSE, WINED3D_SHADER_VERSION(2,1), -1 },
|
---|
242 | {WINED3DSIO_ENDIF, 0, 0, WINED3DSIH_ENDIF, WINED3D_SHADER_VERSION(2,1), -1 },
|
---|
243 | {WINED3DSIO_BREAK, 0, 0, WINED3DSIH_BREAK, WINED3D_SHADER_VERSION(2,1), -1 },
|
---|
244 | {WINED3DSIO_BREAKC, 0, 2, WINED3DSIH_BREAKC, WINED3D_SHADER_VERSION(2,1), -1 },
|
---|
245 | {WINED3DSIO_BREAKP, 0, 1, WINED3DSIH_BREAKP, 0, 0 },
|
---|
246 | {WINED3DSIO_CALL, 0, 1, WINED3DSIH_CALL, WINED3D_SHADER_VERSION(2,1), -1 },
|
---|
247 | {WINED3DSIO_CALLNZ, 0, 2, WINED3DSIH_CALLNZ, WINED3D_SHADER_VERSION(2,1), -1 },
|
---|
248 | {WINED3DSIO_LOOP, 0, 2, WINED3DSIH_LOOP, WINED3D_SHADER_VERSION(3,0), -1 },
|
---|
249 | {WINED3DSIO_RET, 0, 0, WINED3DSIH_RET, WINED3D_SHADER_VERSION(2,1), -1 },
|
---|
250 | {WINED3DSIO_ENDLOOP, 0, 0, WINED3DSIH_ENDLOOP, WINED3D_SHADER_VERSION(3,0), -1 },
|
---|
251 | {WINED3DSIO_LABEL, 0, 1, WINED3DSIH_LABEL, WINED3D_SHADER_VERSION(2,1), -1 },
|
---|
252 | /* Constant definitions */
|
---|
253 | {WINED3DSIO_DEF, 1, 5, WINED3DSIH_DEF, 0, 0 },
|
---|
254 | {WINED3DSIO_DEFB, 1, 2, WINED3DSIH_DEFB, 0, 0 },
|
---|
255 | {WINED3DSIO_DEFI, 1, 5, WINED3DSIH_DEFI, 0, 0 },
|
---|
256 | /* Texture */
|
---|
257 | {WINED3DSIO_TEXCOORD, 1, 1, WINED3DSIH_TEXCOORD, 0, WINED3D_SHADER_VERSION(1,3)},
|
---|
258 | {WINED3DSIO_TEXCOORD, 1, 2, WINED3DSIH_TEXCOORD, WINED3D_SHADER_VERSION(1,4), WINED3D_SHADER_VERSION(1,4)},
|
---|
259 | {WINED3DSIO_TEXKILL, 1, 1, WINED3DSIH_TEXKILL, WINED3D_SHADER_VERSION(1,0), WINED3D_SHADER_VERSION(3,0)},
|
---|
260 | {WINED3DSIO_TEX, 1, 1, WINED3DSIH_TEX, 0, WINED3D_SHADER_VERSION(1,3)},
|
---|
261 | {WINED3DSIO_TEX, 1, 2, WINED3DSIH_TEX, WINED3D_SHADER_VERSION(1,4), WINED3D_SHADER_VERSION(1,4)},
|
---|
262 | {WINED3DSIO_TEX, 1, 3, WINED3DSIH_TEX, WINED3D_SHADER_VERSION(2,0), -1 },
|
---|
263 | {WINED3DSIO_TEXBEM, 1, 2, WINED3DSIH_TEXBEM, 0, WINED3D_SHADER_VERSION(1,3)},
|
---|
264 | {WINED3DSIO_TEXBEML, 1, 2, WINED3DSIH_TEXBEML, WINED3D_SHADER_VERSION(1,0), WINED3D_SHADER_VERSION(1,3)},
|
---|
265 | {WINED3DSIO_TEXREG2AR, 1, 2, WINED3DSIH_TEXREG2AR, WINED3D_SHADER_VERSION(1,0), WINED3D_SHADER_VERSION(1,3)},
|
---|
266 | {WINED3DSIO_TEXREG2GB, 1, 2, WINED3DSIH_TEXREG2GB, WINED3D_SHADER_VERSION(1,0), WINED3D_SHADER_VERSION(1,3)},
|
---|
267 | {WINED3DSIO_TEXREG2RGB, 1, 2, WINED3DSIH_TEXREG2RGB, WINED3D_SHADER_VERSION(1,2), WINED3D_SHADER_VERSION(1,3)},
|
---|
268 | {WINED3DSIO_TEXM3x2PAD, 1, 2, WINED3DSIH_TEXM3x2PAD, WINED3D_SHADER_VERSION(1,0), WINED3D_SHADER_VERSION(1,3)},
|
---|
269 | {WINED3DSIO_TEXM3x2TEX, 1, 2, WINED3DSIH_TEXM3x2TEX, WINED3D_SHADER_VERSION(1,0), WINED3D_SHADER_VERSION(1,3)},
|
---|
270 | {WINED3DSIO_TEXM3x3PAD, 1, 2, WINED3DSIH_TEXM3x3PAD, WINED3D_SHADER_VERSION(1,0), WINED3D_SHADER_VERSION(1,3)},
|
---|
271 | {WINED3DSIO_TEXM3x3DIFF, 1, 2, WINED3DSIH_TEXM3x3DIFF, WINED3D_SHADER_VERSION(0,0), WINED3D_SHADER_VERSION(0,0)},
|
---|
272 | {WINED3DSIO_TEXM3x3SPEC, 1, 3, WINED3DSIH_TEXM3x3SPEC, WINED3D_SHADER_VERSION(1,0), WINED3D_SHADER_VERSION(1,3)},
|
---|
273 | {WINED3DSIO_TEXM3x3VSPEC, 1, 2, WINED3DSIH_TEXM3x3VSPEC, WINED3D_SHADER_VERSION(1,0), WINED3D_SHADER_VERSION(1,3)},
|
---|
274 | {WINED3DSIO_TEXM3x3TEX, 1, 2, WINED3DSIH_TEXM3x3TEX, WINED3D_SHADER_VERSION(1,0), WINED3D_SHADER_VERSION(1,3)},
|
---|
275 | {WINED3DSIO_TEXDP3TEX, 1, 2, WINED3DSIH_TEXDP3TEX, WINED3D_SHADER_VERSION(1,2), WINED3D_SHADER_VERSION(1,3)},
|
---|
276 | {WINED3DSIO_TEXM3x2DEPTH, 1, 2, WINED3DSIH_TEXM3x2DEPTH, WINED3D_SHADER_VERSION(1,3), WINED3D_SHADER_VERSION(1,3)},
|
---|
277 | {WINED3DSIO_TEXDP3, 1, 2, WINED3DSIH_TEXDP3, WINED3D_SHADER_VERSION(1,2), WINED3D_SHADER_VERSION(1,3)},
|
---|
278 | {WINED3DSIO_TEXM3x3, 1, 2, WINED3DSIH_TEXM3x3, WINED3D_SHADER_VERSION(1,2), WINED3D_SHADER_VERSION(1,3)},
|
---|
279 | {WINED3DSIO_TEXDEPTH, 1, 1, WINED3DSIH_TEXDEPTH, WINED3D_SHADER_VERSION(1,4), WINED3D_SHADER_VERSION(1,4)},
|
---|
280 | {WINED3DSIO_BEM, 1, 3, WINED3DSIH_BEM, WINED3D_SHADER_VERSION(1,4), WINED3D_SHADER_VERSION(1,4)},
|
---|
281 | {WINED3DSIO_DSX, 1, 2, WINED3DSIH_DSX, WINED3D_SHADER_VERSION(2,1), -1 },
|
---|
282 | {WINED3DSIO_DSY, 1, 2, WINED3DSIH_DSY, WINED3D_SHADER_VERSION(2,1), -1 },
|
---|
283 | {WINED3DSIO_TEXLDD, 1, 5, WINED3DSIH_TEXLDD, WINED3D_SHADER_VERSION(2,1), -1 },
|
---|
284 | {WINED3DSIO_SETP, 1, 3, WINED3DSIH_SETP, 0, 0 },
|
---|
285 | {WINED3DSIO_TEXLDL, 1, 3, WINED3DSIH_TEXLDL, WINED3D_SHADER_VERSION(3,0), -1 },
|
---|
286 | {WINED3DSIO_PHASE, 0, 0, WINED3DSIH_PHASE, 0, 0 },
|
---|
287 | {0, 0, 0, WINED3DSIH_TABLE_SIZE, 0, 0 },
|
---|
288 | };
|
---|
289 |
|
---|
290 | /* Read a parameter opcode from the input stream,
|
---|
291 | * and possibly a relative addressing token.
|
---|
292 | * Return the number of tokens read */
|
---|
293 | static int shader_get_param(const struct wined3d_sm1_data *priv, const DWORD *ptr, DWORD *token, DWORD *addr_token)
|
---|
294 | {
|
---|
295 | UINT count = 1;
|
---|
296 |
|
---|
297 | *token = *ptr;
|
---|
298 |
|
---|
299 | /* PS >= 3.0 have relative addressing (with token)
|
---|
300 | * VS >= 2.0 have relative addressing (with token)
|
---|
301 | * VS >= 1.0 < 2.0 have relative addressing (without token)
|
---|
302 | * The version check below should work in general */
|
---|
303 | if (*ptr & WINED3DSHADER_ADDRMODE_RELATIVE)
|
---|
304 | {
|
---|
305 | if (priv->shader_version.major < 2)
|
---|
306 | {
|
---|
307 | *addr_token = (1 << 31)
|
---|
308 | | ((WINED3DSPR_ADDR << WINED3DSP_REGTYPE_SHIFT2) & WINED3DSP_REGTYPE_MASK2)
|
---|
309 | | ((WINED3DSPR_ADDR << WINED3DSP_REGTYPE_SHIFT) & WINED3DSP_REGTYPE_MASK)
|
---|
310 | | (WINED3DSP_NOSWIZZLE << WINED3DSP_SWIZZLE_SHIFT);
|
---|
311 | }
|
---|
312 | else
|
---|
313 | {
|
---|
314 | *addr_token = *(ptr + 1);
|
---|
315 | ++count;
|
---|
316 | }
|
---|
317 | }
|
---|
318 |
|
---|
319 | return count;
|
---|
320 | }
|
---|
321 |
|
---|
322 | static const struct wined3d_sm1_opcode_info *shader_get_opcode(const struct wined3d_sm1_data *priv, DWORD code)
|
---|
323 | {
|
---|
324 | DWORD shader_version = WINED3D_SHADER_VERSION(priv->shader_version.major, priv->shader_version.minor);
|
---|
325 | const struct wined3d_sm1_opcode_info *opcode_table = priv->opcode_table;
|
---|
326 | DWORD i = 0;
|
---|
327 |
|
---|
328 | while (opcode_table[i].handler_idx != WINED3DSIH_TABLE_SIZE)
|
---|
329 | {
|
---|
330 | if ((code & WINED3DSI_OPCODE_MASK) == opcode_table[i].opcode
|
---|
331 | && shader_version >= opcode_table[i].min_version
|
---|
332 | && (!opcode_table[i].max_version || shader_version <= opcode_table[i].max_version))
|
---|
333 | {
|
---|
334 | return &opcode_table[i];
|
---|
335 | }
|
---|
336 | ++i;
|
---|
337 | }
|
---|
338 |
|
---|
339 | FIXME("Unsupported opcode %#x(%d) masked %#x, shader version %#x\n",
|
---|
340 | code, code, code & WINED3DSI_OPCODE_MASK, shader_version);
|
---|
341 |
|
---|
342 | return NULL;
|
---|
343 | }
|
---|
344 |
|
---|
345 | /* Return the number of parameters to skip for an opcode */
|
---|
346 | static int shader_skip_opcode(const struct wined3d_sm1_data *priv,
|
---|
347 | const struct wined3d_sm1_opcode_info *opcode_info, DWORD opcode_token)
|
---|
348 | {
|
---|
349 | /* Shaders >= 2.0 may contain address tokens, but fortunately they
|
---|
350 | * have a useful length mask - use it here. Shaders 1.0 contain no such tokens */
|
---|
351 | return (priv->shader_version.major >= 2)
|
---|
352 | ? ((opcode_token & WINED3DSI_INSTLENGTH_MASK) >> WINED3DSI_INSTLENGTH_SHIFT) : opcode_info->param_count;
|
---|
353 | }
|
---|
354 |
|
---|
355 | static void shader_parse_src_param(DWORD param, const struct wined3d_shader_src_param *rel_addr,
|
---|
356 | struct wined3d_shader_src_param *src)
|
---|
357 | {
|
---|
358 | src->reg.type = ((param & WINED3DSP_REGTYPE_MASK) >> WINED3DSP_REGTYPE_SHIFT)
|
---|
359 | | ((param & WINED3DSP_REGTYPE_MASK2) >> WINED3DSP_REGTYPE_SHIFT2);
|
---|
360 | src->reg.idx = param & WINED3DSP_REGNUM_MASK;
|
---|
361 | src->swizzle = (param & WINED3DSP_SWIZZLE_MASK) >> WINED3DSP_SWIZZLE_SHIFT;
|
---|
362 | src->modifiers = (param & WINED3DSP_SRCMOD_MASK) >> WINED3DSP_SRCMOD_SHIFT;
|
---|
363 | src->reg.rel_addr = rel_addr;
|
---|
364 | }
|
---|
365 |
|
---|
366 | static void shader_parse_dst_param(DWORD param, const struct wined3d_shader_src_param *rel_addr,
|
---|
367 | struct wined3d_shader_dst_param *dst)
|
---|
368 | {
|
---|
369 | dst->reg.type = ((param & WINED3DSP_REGTYPE_MASK) >> WINED3DSP_REGTYPE_SHIFT)
|
---|
370 | | ((param & WINED3DSP_REGTYPE_MASK2) >> WINED3DSP_REGTYPE_SHIFT2);
|
---|
371 | dst->reg.idx = param & WINED3DSP_REGNUM_MASK;
|
---|
372 | dst->write_mask = (param & WINED3D_SM1_WRITEMASK_MASK) >> WINED3D_SM1_WRITEMASK_SHIFT;
|
---|
373 | dst->modifiers = (param & WINED3DSP_DSTMOD_MASK) >> WINED3DSP_DSTMOD_SHIFT;
|
---|
374 | dst->shift = (param & WINED3DSP_DSTSHIFT_MASK) >> WINED3DSP_DSTSHIFT_SHIFT;
|
---|
375 | dst->reg.rel_addr = rel_addr;
|
---|
376 | }
|
---|
377 |
|
---|
378 | /* Read the parameters of an unrecognized opcode from the input stream
|
---|
379 | * Return the number of tokens read.
|
---|
380 | *
|
---|
381 | * Note: This function assumes source or destination token format.
|
---|
382 | * It will not work with specially-formatted tokens like DEF or DCL,
|
---|
383 | * but hopefully those would be recognized */
|
---|
384 | static int shader_skip_unrecognized(const struct wined3d_sm1_data *priv, const DWORD *ptr)
|
---|
385 | {
|
---|
386 | int tokens_read = 0;
|
---|
387 | int i = 0;
|
---|
388 |
|
---|
389 | /* TODO: Think of a good name for 0x80000000 and replace it with a constant */
|
---|
390 | while (*ptr & 0x80000000)
|
---|
391 | {
|
---|
392 | DWORD token, addr_token = 0;
|
---|
393 | struct wined3d_shader_src_param rel_addr;
|
---|
394 |
|
---|
395 | tokens_read += shader_get_param(priv, ptr, &token, &addr_token);
|
---|
396 | ptr += tokens_read;
|
---|
397 |
|
---|
398 | FIXME("Unrecognized opcode param: token=0x%08x addr_token=0x%08x name=", token, addr_token);
|
---|
399 |
|
---|
400 | if (token & WINED3DSHADER_ADDRMODE_RELATIVE) shader_parse_src_param(addr_token, NULL, &rel_addr);
|
---|
401 |
|
---|
402 | if (!i)
|
---|
403 | {
|
---|
404 | struct wined3d_shader_dst_param dst;
|
---|
405 |
|
---|
406 | shader_parse_dst_param(token, token & WINED3DSHADER_ADDRMODE_RELATIVE ? &rel_addr : NULL, &dst);
|
---|
407 | shader_dump_dst_param(&dst, &priv->shader_version);
|
---|
408 | }
|
---|
409 | else
|
---|
410 | {
|
---|
411 | struct wined3d_shader_src_param src;
|
---|
412 |
|
---|
413 | shader_parse_src_param(token, token & WINED3DSHADER_ADDRMODE_RELATIVE ? &rel_addr : NULL, &src);
|
---|
414 | shader_dump_src_param(&src, &priv->shader_version);
|
---|
415 | }
|
---|
416 | FIXME("\n");
|
---|
417 | ++i;
|
---|
418 | }
|
---|
419 | return tokens_read;
|
---|
420 | }
|
---|
421 |
|
---|
422 | static void *shader_sm1_init(const DWORD *byte_code, const struct wined3d_shader_signature *output_signature)
|
---|
423 | {
|
---|
424 | struct wined3d_sm1_data *priv = HeapAlloc(GetProcessHeap(), 0, sizeof(*priv));
|
---|
425 | if (!priv)
|
---|
426 | {
|
---|
427 | ERR("Failed to allocate private data\n");
|
---|
428 | return NULL;
|
---|
429 | }
|
---|
430 |
|
---|
431 | if (output_signature)
|
---|
432 | {
|
---|
433 | FIXME("SM 1-3 shader shouldn't have output signatures.\n");
|
---|
434 | }
|
---|
435 |
|
---|
436 | switch (*byte_code >> 16)
|
---|
437 | {
|
---|
438 | case WINED3D_SM1_VS:
|
---|
439 | priv->shader_version.type = WINED3D_SHADER_TYPE_VERTEX;
|
---|
440 | priv->opcode_table = vs_opcode_table;
|
---|
441 | break;
|
---|
442 |
|
---|
443 | case WINED3D_SM1_PS:
|
---|
444 | priv->shader_version.type = WINED3D_SHADER_TYPE_PIXEL;
|
---|
445 | priv->opcode_table = ps_opcode_table;
|
---|
446 | break;
|
---|
447 |
|
---|
448 | default:
|
---|
449 | FIXME("Unrecognized shader type %#x\n", *byte_code >> 16);
|
---|
450 | HeapFree(GetProcessHeap(), 0, priv);
|
---|
451 | return NULL;
|
---|
452 | }
|
---|
453 |
|
---|
454 | return priv;
|
---|
455 | }
|
---|
456 |
|
---|
457 | static void shader_sm1_free(void *data)
|
---|
458 | {
|
---|
459 | HeapFree(GetProcessHeap(), 0, data);
|
---|
460 | }
|
---|
461 |
|
---|
462 | static void shader_sm1_read_header(void *data, const DWORD **ptr, struct wined3d_shader_version *shader_version)
|
---|
463 | {
|
---|
464 | struct wined3d_sm1_data *priv = data;
|
---|
465 | DWORD version_token;
|
---|
466 |
|
---|
467 | version_token = *(*ptr)++;
|
---|
468 | TRACE("version: 0x%08x\n", version_token);
|
---|
469 |
|
---|
470 | priv->shader_version.major = WINED3D_SM1_VERSION_MAJOR(version_token);
|
---|
471 | priv->shader_version.minor = WINED3D_SM1_VERSION_MINOR(version_token);
|
---|
472 | *shader_version = priv->shader_version;
|
---|
473 | }
|
---|
474 |
|
---|
475 | static void shader_sm1_read_opcode(void *data, const DWORD **ptr, struct wined3d_shader_instruction *ins,
|
---|
476 | UINT *param_size)
|
---|
477 | {
|
---|
478 | struct wined3d_sm1_data *priv = data;
|
---|
479 | const struct wined3d_sm1_opcode_info *opcode_info;
|
---|
480 | DWORD opcode_token;
|
---|
481 |
|
---|
482 | opcode_token = *(*ptr)++;
|
---|
483 | opcode_info = shader_get_opcode(priv, opcode_token);
|
---|
484 | if (!opcode_info)
|
---|
485 | {
|
---|
486 | FIXME("Unrecognized opcode: token=0x%08x\n", opcode_token);
|
---|
487 | ins->handler_idx = WINED3DSIH_TABLE_SIZE;
|
---|
488 | *param_size = shader_skip_unrecognized(priv, *ptr);
|
---|
489 | return;
|
---|
490 | }
|
---|
491 |
|
---|
492 | ins->handler_idx = opcode_info->handler_idx;
|
---|
493 | ins->flags = (opcode_token & WINED3D_OPCODESPECIFICCONTROL_MASK) >> WINED3D_OPCODESPECIFICCONTROL_SHIFT;
|
---|
494 | ins->coissue = opcode_token & WINED3DSI_COISSUE;
|
---|
495 | ins->predicate = opcode_token & WINED3DSHADER_INSTRUCTION_PREDICATED;
|
---|
496 | ins->dst_count = opcode_info->dst_count ? 1 : 0;
|
---|
497 | ins->src_count = opcode_info->param_count - opcode_info->dst_count;
|
---|
498 | *param_size = shader_skip_opcode(priv, opcode_info, opcode_token);
|
---|
499 | }
|
---|
500 |
|
---|
501 | static void shader_sm1_read_src_param(void *data, const DWORD **ptr, struct wined3d_shader_src_param *src_param,
|
---|
502 | struct wined3d_shader_src_param *src_rel_addr)
|
---|
503 | {
|
---|
504 | struct wined3d_sm1_data *priv = data;
|
---|
505 | DWORD token, addr_token;
|
---|
506 |
|
---|
507 | *ptr += shader_get_param(priv, *ptr, &token, &addr_token);
|
---|
508 | if (token & WINED3DSHADER_ADDRMODE_RELATIVE)
|
---|
509 | {
|
---|
510 | shader_parse_src_param(addr_token, NULL, src_rel_addr);
|
---|
511 | shader_parse_src_param(token, src_rel_addr, src_param);
|
---|
512 | }
|
---|
513 | else
|
---|
514 | {
|
---|
515 | shader_parse_src_param(token, NULL, src_param);
|
---|
516 | }
|
---|
517 | }
|
---|
518 |
|
---|
519 | static void shader_sm1_read_dst_param(void *data, const DWORD **ptr, struct wined3d_shader_dst_param *dst_param,
|
---|
520 | struct wined3d_shader_src_param *dst_rel_addr)
|
---|
521 | {
|
---|
522 | struct wined3d_sm1_data *priv = data;
|
---|
523 | DWORD token, addr_token;
|
---|
524 |
|
---|
525 | *ptr += shader_get_param(priv, *ptr, &token, &addr_token);
|
---|
526 | if (token & WINED3DSHADER_ADDRMODE_RELATIVE)
|
---|
527 | {
|
---|
528 | shader_parse_src_param(addr_token, NULL, dst_rel_addr);
|
---|
529 | shader_parse_dst_param(token, dst_rel_addr, dst_param);
|
---|
530 | }
|
---|
531 | else
|
---|
532 | {
|
---|
533 | shader_parse_dst_param(token, NULL, dst_param);
|
---|
534 | }
|
---|
535 | }
|
---|
536 |
|
---|
537 | static void shader_sm1_read_semantic(const DWORD **ptr, struct wined3d_shader_semantic *semantic)
|
---|
538 | {
|
---|
539 | DWORD usage_token = *(*ptr)++;
|
---|
540 | DWORD dst_token = *(*ptr)++;
|
---|
541 |
|
---|
542 | semantic->usage = (usage_token & WINED3DSP_DCL_USAGE_MASK) >> WINED3DSP_DCL_USAGE_SHIFT;
|
---|
543 | semantic->usage_idx = (usage_token & WINED3DSP_DCL_USAGEINDEX_MASK) >> WINED3DSP_DCL_USAGEINDEX_SHIFT;
|
---|
544 | semantic->sampler_type = (usage_token & WINED3DSP_TEXTURETYPE_MASK) >> WINED3DSP_TEXTURETYPE_SHIFT;
|
---|
545 | shader_parse_dst_param(dst_token, NULL, &semantic->reg);
|
---|
546 | }
|
---|
547 |
|
---|
548 | static void shader_sm1_read_comment(const DWORD **ptr, const char **comment)
|
---|
549 | {
|
---|
550 | DWORD token = **ptr;
|
---|
551 |
|
---|
552 | if ((token & WINED3DSI_OPCODE_MASK) != WINED3DSIO_COMMENT)
|
---|
553 | {
|
---|
554 | *comment = NULL;
|
---|
555 | return;
|
---|
556 | }
|
---|
557 |
|
---|
558 | *comment = (const char *)++(*ptr);
|
---|
559 | *ptr += (token & WINED3DSI_COMMENTSIZE_MASK) >> WINED3DSI_COMMENTSIZE_SHIFT;
|
---|
560 | }
|
---|
561 |
|
---|
562 | static BOOL shader_sm1_is_end(void *data, const DWORD **ptr)
|
---|
563 | {
|
---|
564 | if (**ptr == WINED3DSP_END)
|
---|
565 | {
|
---|
566 | ++(*ptr);
|
---|
567 | return TRUE;
|
---|
568 | }
|
---|
569 |
|
---|
570 | return FALSE;
|
---|
571 | }
|
---|
572 |
|
---|
573 | const struct wined3d_shader_frontend sm1_shader_frontend =
|
---|
574 | {
|
---|
575 | shader_sm1_init,
|
---|
576 | shader_sm1_free,
|
---|
577 | shader_sm1_read_header,
|
---|
578 | shader_sm1_read_opcode,
|
---|
579 | shader_sm1_read_src_param,
|
---|
580 | shader_sm1_read_dst_param,
|
---|
581 | shader_sm1_read_semantic,
|
---|
582 | shader_sm1_read_comment,
|
---|
583 | shader_sm1_is_end,
|
---|
584 | };
|
---|