VirtualBox

source: vbox/trunk/src/VBox/Devices/Graphics/shaderlib/shader_sm1.c@ 86679

Last change on this file since 86679 was 82722, checked in by vboxsync, 5 years ago

3D: Corrected r135648 to fix blank guest screen, bugref:9613

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 36.3 KB
Line 
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 * Oracle 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, Oracle 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
39WINE_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
105enum WINED3DSHADER_ADDRESSMODE_TYPE
106{
107 WINED3DSHADER_ADDRMODE_ABSOLUTE = 0 << WINED3DSHADER_ADDRESSMODE_SHIFT,
108 WINED3DSHADER_ADDRMODE_RELATIVE = 1 << WINED3DSHADER_ADDRESSMODE_SHIFT,
109};
110
111enum wined3d_sm1_opcode
112{
113 WINED3D_SM1_OP_NOP = 0x00,
114 WINED3D_SM1_OP_MOV = 0x01,
115 WINED3D_SM1_OP_ADD = 0x02,
116 WINED3D_SM1_OP_SUB = 0x03,
117 WINED3D_SM1_OP_MAD = 0x04,
118 WINED3D_SM1_OP_MUL = 0x05,
119 WINED3D_SM1_OP_RCP = 0x06,
120 WINED3D_SM1_OP_RSQ = 0x07,
121 WINED3D_SM1_OP_DP3 = 0x08,
122 WINED3D_SM1_OP_DP4 = 0x09,
123 WINED3D_SM1_OP_MIN = 0x0a,
124 WINED3D_SM1_OP_MAX = 0x0b,
125 WINED3D_SM1_OP_SLT = 0x0c,
126 WINED3D_SM1_OP_SGE = 0x0d,
127 WINED3D_SM1_OP_EXP = 0x0e,
128 WINED3D_SM1_OP_LOG = 0x0f,
129 WINED3D_SM1_OP_LIT = 0x10,
130 WINED3D_SM1_OP_DST = 0x11,
131 WINED3D_SM1_OP_LRP = 0x12,
132 WINED3D_SM1_OP_FRC = 0x13,
133 WINED3D_SM1_OP_M4x4 = 0x14,
134 WINED3D_SM1_OP_M4x3 = 0x15,
135 WINED3D_SM1_OP_M3x4 = 0x16,
136 WINED3D_SM1_OP_M3x3 = 0x17,
137 WINED3D_SM1_OP_M3x2 = 0x18,
138 WINED3D_SM1_OP_CALL = 0x19,
139 WINED3D_SM1_OP_CALLNZ = 0x1a,
140 WINED3D_SM1_OP_LOOP = 0x1b,
141 WINED3D_SM1_OP_RET = 0x1c,
142 WINED3D_SM1_OP_ENDLOOP = 0x1d,
143 WINED3D_SM1_OP_LABEL = 0x1e,
144 WINED3D_SM1_OP_DCL = 0x1f,
145 WINED3D_SM1_OP_POW = 0x20,
146 WINED3D_SM1_OP_CRS = 0x21,
147 WINED3D_SM1_OP_SGN = 0x22,
148 WINED3D_SM1_OP_ABS = 0x23,
149 WINED3D_SM1_OP_NRM = 0x24,
150 WINED3D_SM1_OP_SINCOS = 0x25,
151 WINED3D_SM1_OP_REP = 0x26,
152 WINED3D_SM1_OP_ENDREP = 0x27,
153 WINED3D_SM1_OP_IF = 0x28,
154 WINED3D_SM1_OP_IFC = 0x29,
155 WINED3D_SM1_OP_ELSE = 0x2a,
156 WINED3D_SM1_OP_ENDIF = 0x2b,
157 WINED3D_SM1_OP_BREAK = 0x2c,
158 WINED3D_SM1_OP_BREAKC = 0x2d,
159 WINED3D_SM1_OP_MOVA = 0x2e,
160 WINED3D_SM1_OP_DEFB = 0x2f,
161 WINED3D_SM1_OP_DEFI = 0x30,
162
163 WINED3D_SM1_OP_TEXCOORD = 0x40,
164 WINED3D_SM1_OP_TEXKILL = 0x41,
165 WINED3D_SM1_OP_TEX = 0x42,
166 WINED3D_SM1_OP_TEXBEM = 0x43,
167 WINED3D_SM1_OP_TEXBEML = 0x44,
168 WINED3D_SM1_OP_TEXREG2AR = 0x45,
169 WINED3D_SM1_OP_TEXREG2GB = 0x46,
170 WINED3D_SM1_OP_TEXM3x2PAD = 0x47,
171 WINED3D_SM1_OP_TEXM3x2TEX = 0x48,
172 WINED3D_SM1_OP_TEXM3x3PAD = 0x49,
173 WINED3D_SM1_OP_TEXM3x3TEX = 0x4a,
174 WINED3D_SM1_OP_TEXM3x3DIFF = 0x4b,
175 WINED3D_SM1_OP_TEXM3x3SPEC = 0x4c,
176 WINED3D_SM1_OP_TEXM3x3VSPEC = 0x4d,
177 WINED3D_SM1_OP_EXPP = 0x4e,
178 WINED3D_SM1_OP_LOGP = 0x4f,
179 WINED3D_SM1_OP_CND = 0x50,
180 WINED3D_SM1_OP_DEF = 0x51,
181 WINED3D_SM1_OP_TEXREG2RGB = 0x52,
182 WINED3D_SM1_OP_TEXDP3TEX = 0x53,
183 WINED3D_SM1_OP_TEXM3x2DEPTH = 0x54,
184 WINED3D_SM1_OP_TEXDP3 = 0x55,
185 WINED3D_SM1_OP_TEXM3x3 = 0x56,
186 WINED3D_SM1_OP_TEXDEPTH = 0x57,
187 WINED3D_SM1_OP_CMP = 0x58,
188 WINED3D_SM1_OP_BEM = 0x59,
189 WINED3D_SM1_OP_DP2ADD = 0x5a,
190 WINED3D_SM1_OP_DSX = 0x5b,
191 WINED3D_SM1_OP_DSY = 0x5c,
192 WINED3D_SM1_OP_TEXLDD = 0x5d,
193 WINED3D_SM1_OP_SETP = 0x5e,
194 WINED3D_SM1_OP_TEXLDL = 0x5f,
195 WINED3D_SM1_OP_BREAKP = 0x60,
196
197 WINED3D_SM1_OP_PHASE = 0xfffd,
198 WINED3D_SM1_OP_COMMENT = 0xfffe,
199 WINED3D_SM1_OP_END = 0Xffff,
200};
201
202struct wined3d_sm1_opcode_info
203{
204 enum wined3d_sm1_opcode opcode;
205 UINT dst_count;
206 UINT param_count;
207 enum WINED3D_SHADER_INSTRUCTION_HANDLER handler_idx;
208 DWORD min_version;
209 DWORD max_version;
210};
211
212struct wined3d_sm1_data
213{
214 struct wined3d_shader_version shader_version;
215 const DWORD *end;
216 DWORD tokens_num;
217 const struct wined3d_sm1_opcode_info *opcode_table;
218};
219
220/* This table is not order or position dependent. */
221static const struct wined3d_sm1_opcode_info vs_opcode_table[] =
222{
223 /* Arithmetic */
224 {WINED3D_SM1_OP_NOP, 0, 0, WINED3DSIH_NOP, 0, 0 },
225 {WINED3D_SM1_OP_MOV, 1, 2, WINED3DSIH_MOV, 0, 0 },
226 {WINED3D_SM1_OP_MOVA, 1, 2, WINED3DSIH_MOVA, WINED3D_SHADER_VERSION(2,0), -1 },
227 {WINED3D_SM1_OP_ADD, 1, 3, WINED3DSIH_ADD, 0, 0 },
228 {WINED3D_SM1_OP_SUB, 1, 3, WINED3DSIH_SUB, 0, 0 },
229 {WINED3D_SM1_OP_MAD, 1, 4, WINED3DSIH_MAD, 0, 0 },
230 {WINED3D_SM1_OP_MUL, 1, 3, WINED3DSIH_MUL, 0, 0 },
231 {WINED3D_SM1_OP_RCP, 1, 2, WINED3DSIH_RCP, 0, 0 },
232 {WINED3D_SM1_OP_RSQ, 1, 2, WINED3DSIH_RSQ, 0, 0 },
233 {WINED3D_SM1_OP_DP3, 1, 3, WINED3DSIH_DP3, 0, 0 },
234 {WINED3D_SM1_OP_DP4, 1, 3, WINED3DSIH_DP4, 0, 0 },
235 {WINED3D_SM1_OP_MIN, 1, 3, WINED3DSIH_MIN, 0, 0 },
236 {WINED3D_SM1_OP_MAX, 1, 3, WINED3DSIH_MAX, 0, 0 },
237 {WINED3D_SM1_OP_SLT, 1, 3, WINED3DSIH_SLT, 0, 0 },
238 {WINED3D_SM1_OP_SGE, 1, 3, WINED3DSIH_SGE, 0, 0 },
239 {WINED3D_SM1_OP_ABS, 1, 2, WINED3DSIH_ABS, 0, 0 },
240 {WINED3D_SM1_OP_EXP, 1, 2, WINED3DSIH_EXP, 0, 0 },
241 {WINED3D_SM1_OP_LOG, 1, 2, WINED3DSIH_LOG, 0, 0 },
242 {WINED3D_SM1_OP_EXPP, 1, 2, WINED3DSIH_EXPP, 0, 0 },
243 {WINED3D_SM1_OP_LOGP, 1, 2, WINED3DSIH_LOGP, 0, 0 },
244 {WINED3D_SM1_OP_LIT, 1, 2, WINED3DSIH_LIT, 0, 0 },
245 {WINED3D_SM1_OP_DST, 1, 3, WINED3DSIH_DST, 0, 0 },
246 {WINED3D_SM1_OP_LRP, 1, 4, WINED3DSIH_LRP, 0, 0 },
247 {WINED3D_SM1_OP_FRC, 1, 2, WINED3DSIH_FRC, 0, 0 },
248 {WINED3D_SM1_OP_POW, 1, 3, WINED3DSIH_POW, 0, 0 },
249 {WINED3D_SM1_OP_CRS, 1, 3, WINED3DSIH_CRS, 0, 0 },
250#ifdef VBOX_WITH_VMSVGA /* appears incorrect */
251 {WINED3D_SM1_OP_SGN, 1, 4, WINED3DSIH_SGN, 0, 0 },
252#else
253 {WINED3D_SM1_OP_SGN, 1, 4, WINED3DSIH_SGN, WINED3D_SHADER_VERSION(2,0), WINED3D_SHADER_VERSION(2,1)},
254 {WINED3D_SM1_OP_SGN, 1, 2, WINED3DSIH_SGN, WINED3D_SHADER_VERSION(3,0), -1 },
255#endif
256 {WINED3D_SM1_OP_NRM, 1, 2, WINED3DSIH_NRM, 0, 0 },
257 {WINED3D_SM1_OP_SINCOS, 1, 4, WINED3DSIH_SINCOS, WINED3D_SHADER_VERSION(2,0), WINED3D_SHADER_VERSION(2,1)},
258 {WINED3D_SM1_OP_SINCOS, 1, 2, WINED3DSIH_SINCOS, WINED3D_SHADER_VERSION(3,0), -1 },
259 /* Matrix */
260 {WINED3D_SM1_OP_M4x4, 1, 3, WINED3DSIH_M4x4, 0, 0 },
261 {WINED3D_SM1_OP_M4x3, 1, 3, WINED3DSIH_M4x3, 0, 0 },
262 {WINED3D_SM1_OP_M3x4, 1, 3, WINED3DSIH_M3x4, 0, 0 },
263 {WINED3D_SM1_OP_M3x3, 1, 3, WINED3DSIH_M3x3, 0, 0 },
264 {WINED3D_SM1_OP_M3x2, 1, 3, WINED3DSIH_M3x2, 0, 0 },
265 /* Declare registers */
266 {WINED3D_SM1_OP_DCL, 0, 2, WINED3DSIH_DCL, 0, 0 },
267 /* Constant definitions */
268 {WINED3D_SM1_OP_DEF, 1, 5, WINED3DSIH_DEF, 0, 0 },
269 {WINED3D_SM1_OP_DEFB, 1, 2, WINED3DSIH_DEFB, 0, 0 },
270 {WINED3D_SM1_OP_DEFI, 1, 5, WINED3DSIH_DEFI, 0, 0 },
271 /* Flow control */
272 {WINED3D_SM1_OP_REP, 0, 1, WINED3DSIH_REP, WINED3D_SHADER_VERSION(2,0), -1 },
273 {WINED3D_SM1_OP_ENDREP, 0, 0, WINED3DSIH_ENDREP, WINED3D_SHADER_VERSION(2,0), -1 },
274 {WINED3D_SM1_OP_IF, 0, 1, WINED3DSIH_IF, WINED3D_SHADER_VERSION(2,0), -1 },
275 {WINED3D_SM1_OP_IFC, 0, 2, WINED3DSIH_IFC, WINED3D_SHADER_VERSION(2,0), -1 },
276 {WINED3D_SM1_OP_ELSE, 0, 0, WINED3DSIH_ELSE, WINED3D_SHADER_VERSION(2,0), -1 },
277 {WINED3D_SM1_OP_ENDIF, 0, 0, WINED3DSIH_ENDIF, WINED3D_SHADER_VERSION(2,0), -1 },
278 {WINED3D_SM1_OP_BREAK, 0, 0, WINED3DSIH_BREAK, WINED3D_SHADER_VERSION(2,1), -1 },
279 {WINED3D_SM1_OP_BREAKC, 0, 2, WINED3DSIH_BREAKC, WINED3D_SHADER_VERSION(2,1), -1 },
280 {WINED3D_SM1_OP_BREAKP, 0, 1, WINED3DSIH_BREAKP, 0, 0 },
281 {WINED3D_SM1_OP_CALL, 0, 1, WINED3DSIH_CALL, WINED3D_SHADER_VERSION(2,0), -1 },
282 {WINED3D_SM1_OP_CALLNZ, 0, 2, WINED3DSIH_CALLNZ, WINED3D_SHADER_VERSION(2,0), -1 },
283 {WINED3D_SM1_OP_LOOP, 0, 2, WINED3DSIH_LOOP, WINED3D_SHADER_VERSION(2,0), -1 },
284 {WINED3D_SM1_OP_RET, 0, 0, WINED3DSIH_RET, WINED3D_SHADER_VERSION(2,0), -1 },
285 {WINED3D_SM1_OP_ENDLOOP, 0, 0, WINED3DSIH_ENDLOOP, WINED3D_SHADER_VERSION(2,0), -1 },
286 {WINED3D_SM1_OP_LABEL, 0, 1, WINED3DSIH_LABEL, WINED3D_SHADER_VERSION(2,0), -1 },
287
288 {WINED3D_SM1_OP_SETP, 1, 3, WINED3DSIH_SETP, 0, 0 },
289 {WINED3D_SM1_OP_TEXLDL, 1, 3, WINED3DSIH_TEXLDL, WINED3D_SHADER_VERSION(3,0), -1 },
290 {0, 0, 0, WINED3DSIH_TABLE_SIZE, 0, 0 },
291};
292
293static const struct wined3d_sm1_opcode_info ps_opcode_table[] =
294{
295 /* Arithmetic */
296 {WINED3D_SM1_OP_NOP, 0, 0, WINED3DSIH_NOP, 0, 0 },
297 {WINED3D_SM1_OP_MOV, 1, 2, WINED3DSIH_MOV, 0, 0 },
298 {WINED3D_SM1_OP_ADD, 1, 3, WINED3DSIH_ADD, 0, 0 },
299 {WINED3D_SM1_OP_SUB, 1, 3, WINED3DSIH_SUB, 0, 0 },
300 {WINED3D_SM1_OP_MAD, 1, 4, WINED3DSIH_MAD, 0, 0 },
301 {WINED3D_SM1_OP_MUL, 1, 3, WINED3DSIH_MUL, 0, 0 },
302 {WINED3D_SM1_OP_RCP, 1, 2, WINED3DSIH_RCP, 0, 0 },
303 {WINED3D_SM1_OP_RSQ, 1, 2, WINED3DSIH_RSQ, 0, 0 },
304 {WINED3D_SM1_OP_DP3, 1, 3, WINED3DSIH_DP3, 0, 0 },
305 {WINED3D_SM1_OP_DP4, 1, 3, WINED3DSIH_DP4, 0, 0 },
306 {WINED3D_SM1_OP_MIN, 1, 3, WINED3DSIH_MIN, 0, 0 },
307 {WINED3D_SM1_OP_MAX, 1, 3, WINED3DSIH_MAX, 0, 0 },
308 {WINED3D_SM1_OP_SLT, 1, 3, WINED3DSIH_SLT, 0, 0 },
309 {WINED3D_SM1_OP_SGE, 1, 3, WINED3DSIH_SGE, 0, 0 },
310 {WINED3D_SM1_OP_ABS, 1, 2, WINED3DSIH_ABS, 0, 0 },
311 {WINED3D_SM1_OP_EXP, 1, 2, WINED3DSIH_EXP, 0, 0 },
312 {WINED3D_SM1_OP_LOG, 1, 2, WINED3DSIH_LOG, 0, 0 },
313 {WINED3D_SM1_OP_EXPP, 1, 2, WINED3DSIH_EXPP, 0, 0 },
314 {WINED3D_SM1_OP_LOGP, 1, 2, WINED3DSIH_LOGP, 0, 0 },
315 {WINED3D_SM1_OP_DST, 1, 3, WINED3DSIH_DST, 0, 0 },
316 {WINED3D_SM1_OP_LRP, 1, 4, WINED3DSIH_LRP, 0, 0 },
317 {WINED3D_SM1_OP_FRC, 1, 2, WINED3DSIH_FRC, 0, 0 },
318 {WINED3D_SM1_OP_CND, 1, 4, WINED3DSIH_CND, WINED3D_SHADER_VERSION(1,0), WINED3D_SHADER_VERSION(1,4)},
319 {WINED3D_SM1_OP_CMP, 1, 4, WINED3DSIH_CMP, WINED3D_SHADER_VERSION(1,2), WINED3D_SHADER_VERSION(3,0)},
320 {WINED3D_SM1_OP_POW, 1, 3, WINED3DSIH_POW, 0, 0 },
321 {WINED3D_SM1_OP_CRS, 1, 3, WINED3DSIH_CRS, 0, 0 },
322 {WINED3D_SM1_OP_NRM, 1, 2, WINED3DSIH_NRM, 0, 0 },
323 {WINED3D_SM1_OP_SINCOS, 1, 4, WINED3DSIH_SINCOS, WINED3D_SHADER_VERSION(2,0), WINED3D_SHADER_VERSION(2,1)},
324 {WINED3D_SM1_OP_SINCOS, 1, 2, WINED3DSIH_SINCOS, WINED3D_SHADER_VERSION(3,0), -1 },
325 {WINED3D_SM1_OP_DP2ADD, 1, 4, WINED3DSIH_DP2ADD, WINED3D_SHADER_VERSION(2,0), -1 },
326 /* Matrix */
327 {WINED3D_SM1_OP_M4x4, 1, 3, WINED3DSIH_M4x4, 0, 0 },
328 {WINED3D_SM1_OP_M4x3, 1, 3, WINED3DSIH_M4x3, 0, 0 },
329 {WINED3D_SM1_OP_M3x4, 1, 3, WINED3DSIH_M3x4, 0, 0 },
330 {WINED3D_SM1_OP_M3x3, 1, 3, WINED3DSIH_M3x3, 0, 0 },
331 {WINED3D_SM1_OP_M3x2, 1, 3, WINED3DSIH_M3x2, 0, 0 },
332 /* Register declarations */
333 {WINED3D_SM1_OP_DCL, 0, 2, WINED3DSIH_DCL, 0, 0 },
334 /* Flow control */
335 {WINED3D_SM1_OP_REP, 0, 1, WINED3DSIH_REP, WINED3D_SHADER_VERSION(2,1), -1 },
336 {WINED3D_SM1_OP_ENDREP, 0, 0, WINED3DSIH_ENDREP, WINED3D_SHADER_VERSION(2,1), -1 },
337 {WINED3D_SM1_OP_IF, 0, 1, WINED3DSIH_IF, WINED3D_SHADER_VERSION(2,1), -1 },
338 {WINED3D_SM1_OP_IFC, 0, 2, WINED3DSIH_IFC, WINED3D_SHADER_VERSION(2,1), -1 },
339 {WINED3D_SM1_OP_ELSE, 0, 0, WINED3DSIH_ELSE, WINED3D_SHADER_VERSION(2,1), -1 },
340 {WINED3D_SM1_OP_ENDIF, 0, 0, WINED3DSIH_ENDIF, WINED3D_SHADER_VERSION(2,1), -1 },
341 {WINED3D_SM1_OP_BREAK, 0, 0, WINED3DSIH_BREAK, WINED3D_SHADER_VERSION(2,1), -1 },
342 {WINED3D_SM1_OP_BREAKC, 0, 2, WINED3DSIH_BREAKC, WINED3D_SHADER_VERSION(2,1), -1 },
343 {WINED3D_SM1_OP_BREAKP, 0, 1, WINED3DSIH_BREAKP, 0, 0 },
344 {WINED3D_SM1_OP_CALL, 0, 1, WINED3DSIH_CALL, WINED3D_SHADER_VERSION(2,1), -1 },
345 {WINED3D_SM1_OP_CALLNZ, 0, 2, WINED3DSIH_CALLNZ, WINED3D_SHADER_VERSION(2,1), -1 },
346 {WINED3D_SM1_OP_LOOP, 0, 2, WINED3DSIH_LOOP, WINED3D_SHADER_VERSION(3,0), -1 },
347 {WINED3D_SM1_OP_RET, 0, 0, WINED3DSIH_RET, WINED3D_SHADER_VERSION(2,1), -1 },
348 {WINED3D_SM1_OP_ENDLOOP, 0, 0, WINED3DSIH_ENDLOOP, WINED3D_SHADER_VERSION(3,0), -1 },
349 {WINED3D_SM1_OP_LABEL, 0, 1, WINED3DSIH_LABEL, WINED3D_SHADER_VERSION(2,1), -1 },
350 /* Constant definitions */
351 {WINED3D_SM1_OP_DEF, 1, 5, WINED3DSIH_DEF, 0, 0 },
352 {WINED3D_SM1_OP_DEFB, 1, 2, WINED3DSIH_DEFB, 0, 0 },
353 {WINED3D_SM1_OP_DEFI, 1, 5, WINED3DSIH_DEFI, 0, 0 },
354 /* Texture */
355 {WINED3D_SM1_OP_TEXCOORD, 1, 1, WINED3DSIH_TEXCOORD, 0, WINED3D_SHADER_VERSION(1,3)},
356 {WINED3D_SM1_OP_TEXCOORD, 1, 2, WINED3DSIH_TEXCOORD, WINED3D_SHADER_VERSION(1,4), WINED3D_SHADER_VERSION(1,4)},
357 {WINED3D_SM1_OP_TEXKILL, 1, 1, WINED3DSIH_TEXKILL, WINED3D_SHADER_VERSION(1,0), WINED3D_SHADER_VERSION(3,0)},
358 {WINED3D_SM1_OP_TEX, 1, 1, WINED3DSIH_TEX, 0, WINED3D_SHADER_VERSION(1,3)},
359 {WINED3D_SM1_OP_TEX, 1, 2, WINED3DSIH_TEX, WINED3D_SHADER_VERSION(1,4), WINED3D_SHADER_VERSION(1,4)},
360 {WINED3D_SM1_OP_TEX, 1, 3, WINED3DSIH_TEX, WINED3D_SHADER_VERSION(2,0), -1 },
361 {WINED3D_SM1_OP_TEXBEM, 1, 2, WINED3DSIH_TEXBEM, 0, WINED3D_SHADER_VERSION(1,3)},
362 {WINED3D_SM1_OP_TEXBEML, 1, 2, WINED3DSIH_TEXBEML, WINED3D_SHADER_VERSION(1,0), WINED3D_SHADER_VERSION(1,3)},
363 {WINED3D_SM1_OP_TEXREG2AR, 1, 2, WINED3DSIH_TEXREG2AR, WINED3D_SHADER_VERSION(1,0), WINED3D_SHADER_VERSION(1,3)},
364 {WINED3D_SM1_OP_TEXREG2GB, 1, 2, WINED3DSIH_TEXREG2GB, WINED3D_SHADER_VERSION(1,0), WINED3D_SHADER_VERSION(1,3)},
365 {WINED3D_SM1_OP_TEXREG2RGB, 1, 2, WINED3DSIH_TEXREG2RGB, WINED3D_SHADER_VERSION(1,2), WINED3D_SHADER_VERSION(1,3)},
366 {WINED3D_SM1_OP_TEXM3x2PAD, 1, 2, WINED3DSIH_TEXM3x2PAD, WINED3D_SHADER_VERSION(1,0), WINED3D_SHADER_VERSION(1,3)},
367 {WINED3D_SM1_OP_TEXM3x2TEX, 1, 2, WINED3DSIH_TEXM3x2TEX, WINED3D_SHADER_VERSION(1,0), WINED3D_SHADER_VERSION(1,3)},
368 {WINED3D_SM1_OP_TEXM3x3PAD, 1, 2, WINED3DSIH_TEXM3x3PAD, WINED3D_SHADER_VERSION(1,0), WINED3D_SHADER_VERSION(1,3)},
369 {WINED3D_SM1_OP_TEXM3x3DIFF, 1, 2, WINED3DSIH_TEXM3x3DIFF, WINED3D_SHADER_VERSION(0,0), WINED3D_SHADER_VERSION(0,0)},
370 {WINED3D_SM1_OP_TEXM3x3SPEC, 1, 3, WINED3DSIH_TEXM3x3SPEC, WINED3D_SHADER_VERSION(1,0), WINED3D_SHADER_VERSION(1,3)},
371 {WINED3D_SM1_OP_TEXM3x3VSPEC, 1, 2, WINED3DSIH_TEXM3x3VSPEC, WINED3D_SHADER_VERSION(1,0), WINED3D_SHADER_VERSION(1,3)},
372 {WINED3D_SM1_OP_TEXM3x3TEX, 1, 2, WINED3DSIH_TEXM3x3TEX, WINED3D_SHADER_VERSION(1,0), WINED3D_SHADER_VERSION(1,3)},
373 {WINED3D_SM1_OP_TEXDP3TEX, 1, 2, WINED3DSIH_TEXDP3TEX, WINED3D_SHADER_VERSION(1,2), WINED3D_SHADER_VERSION(1,3)},
374 {WINED3D_SM1_OP_TEXM3x2DEPTH, 1, 2, WINED3DSIH_TEXM3x2DEPTH, WINED3D_SHADER_VERSION(1,3), WINED3D_SHADER_VERSION(1,3)},
375 {WINED3D_SM1_OP_TEXDP3, 1, 2, WINED3DSIH_TEXDP3, WINED3D_SHADER_VERSION(1,2), WINED3D_SHADER_VERSION(1,3)},
376 {WINED3D_SM1_OP_TEXM3x3, 1, 2, WINED3DSIH_TEXM3x3, WINED3D_SHADER_VERSION(1,2), WINED3D_SHADER_VERSION(1,3)},
377 {WINED3D_SM1_OP_TEXDEPTH, 1, 1, WINED3DSIH_TEXDEPTH, WINED3D_SHADER_VERSION(1,4), WINED3D_SHADER_VERSION(1,4)},
378 {WINED3D_SM1_OP_BEM, 1, 3, WINED3DSIH_BEM, WINED3D_SHADER_VERSION(1,4), WINED3D_SHADER_VERSION(1,4)},
379 {WINED3D_SM1_OP_DSX, 1, 2, WINED3DSIH_DSX, WINED3D_SHADER_VERSION(2,1), -1 },
380 {WINED3D_SM1_OP_DSY, 1, 2, WINED3DSIH_DSY, WINED3D_SHADER_VERSION(2,1), -1 },
381 {WINED3D_SM1_OP_TEXLDD, 1, 5, WINED3DSIH_TEXLDD, WINED3D_SHADER_VERSION(2,1), -1 },
382 {WINED3D_SM1_OP_SETP, 1, 3, WINED3DSIH_SETP, 0, 0 },
383 {WINED3D_SM1_OP_TEXLDL, 1, 3, WINED3DSIH_TEXLDL, WINED3D_SHADER_VERSION(3,0), -1 },
384 {WINED3D_SM1_OP_PHASE, 0, 0, WINED3DSIH_PHASE, 0, 0 },
385 {0, 0, 0, WINED3DSIH_TABLE_SIZE, 0, 0 },
386};
387
388/* Read a parameter opcode from the input stream,
389 * and possibly a relative addressing token.
390 * Return the number of tokens read */
391static int shader_get_param(const struct wined3d_sm1_data *priv, const DWORD *ptr, DWORD *token, DWORD *addr_token)
392{
393 UINT count = 1;
394
395 *token = *ptr;
396
397 /* PS >= 3.0 have relative addressing (with token)
398 * VS >= 2.0 have relative addressing (with token)
399 * VS >= 1.0 < 2.0 have relative addressing (without token)
400 * The version check below should work in general */
401 if (*ptr & WINED3DSHADER_ADDRMODE_RELATIVE)
402 {
403 if (priv->shader_version.major < 2)
404 {
405 *addr_token = (1 << 31)
406 | ((WINED3DSPR_ADDR << WINED3DSP_REGTYPE_SHIFT2) & WINED3DSP_REGTYPE_MASK2)
407 | ((WINED3DSPR_ADDR << WINED3DSP_REGTYPE_SHIFT) & WINED3DSP_REGTYPE_MASK)
408 | (WINED3DSP_NOSWIZZLE << WINED3DSP_SWIZZLE_SHIFT);
409 }
410 else
411 {
412 *addr_token = *(ptr + 1);
413 ++count;
414 }
415 }
416
417 return count;
418}
419
420static const struct wined3d_sm1_opcode_info *shader_get_opcode(const struct wined3d_sm1_data *priv, DWORD code)
421{
422 DWORD shader_version = WINED3D_SHADER_VERSION(priv->shader_version.major, priv->shader_version.minor);
423 const struct wined3d_sm1_opcode_info *opcode_table = priv->opcode_table;
424 DWORD i = 0;
425
426 while (opcode_table[i].handler_idx != WINED3DSIH_TABLE_SIZE)
427 {
428 if ((code & WINED3DSI_OPCODE_MASK) == (DWORD)opcode_table[i].opcode
429 && shader_version >= opcode_table[i].min_version
430 && (!opcode_table[i].max_version || shader_version <= opcode_table[i].max_version))
431 {
432 return &opcode_table[i];
433 }
434 ++i;
435 }
436
437 FIXME("Unsupported opcode %#x(%d) masked %#x, shader version %#x\n",
438 code, code, code & WINED3DSI_OPCODE_MASK, shader_version);
439
440 return NULL;
441}
442
443/* Return the number of parameters to skip for an opcode */
444static int shader_skip_opcode(const struct wined3d_sm1_data *priv,
445 const struct wined3d_sm1_opcode_info *opcode_info, DWORD opcode_token)
446{
447 /* Shaders >= 2.0 may contain address tokens, but fortunately they
448 * have a useful length mask - use it here. Shaders 1.0 contain no such tokens */
449 return (priv->shader_version.major >= 2)
450 ? ((opcode_token & WINED3DSI_INSTLENGTH_MASK) >> WINED3DSI_INSTLENGTH_SHIFT) : opcode_info->param_count;
451}
452
453static void shader_parse_src_param(DWORD param, const struct wined3d_shader_src_param *rel_addr,
454 struct wined3d_shader_src_param *src)
455{
456 src->reg.type = ((param & WINED3DSP_REGTYPE_MASK) >> WINED3DSP_REGTYPE_SHIFT)
457 | ((param & WINED3DSP_REGTYPE_MASK2) >> WINED3DSP_REGTYPE_SHIFT2);
458 src->reg.idx = param & WINED3DSP_REGNUM_MASK;
459 src->reg.array_idx = ~0U;
460 src->swizzle = (param & WINED3DSP_SWIZZLE_MASK) >> WINED3DSP_SWIZZLE_SHIFT;
461 src->modifiers = (param & WINED3DSP_SRCMOD_MASK) >> WINED3DSP_SRCMOD_SHIFT;
462 src->reg.rel_addr = rel_addr;
463}
464
465static void shader_parse_dst_param(DWORD param, const struct wined3d_shader_src_param *rel_addr,
466 struct wined3d_shader_dst_param *dst)
467{
468 dst->reg.type = ((param & WINED3DSP_REGTYPE_MASK) >> WINED3DSP_REGTYPE_SHIFT)
469 | ((param & WINED3DSP_REGTYPE_MASK2) >> WINED3DSP_REGTYPE_SHIFT2);
470 dst->reg.idx = param & WINED3DSP_REGNUM_MASK;
471 dst->reg.array_idx = ~0U;
472 dst->write_mask = (param & WINED3D_SM1_WRITEMASK_MASK) >> WINED3D_SM1_WRITEMASK_SHIFT;
473 dst->modifiers = (param & WINED3DSP_DSTMOD_MASK) >> WINED3DSP_DSTMOD_SHIFT;
474 dst->shift = (param & WINED3DSP_DSTSHIFT_MASK) >> WINED3DSP_DSTSHIFT_SHIFT;
475 dst->reg.rel_addr = rel_addr;
476}
477
478/* Read the parameters of an unrecognized opcode from the input stream
479 * Return the number of tokens read.
480 *
481 * Note: This function assumes source or destination token format.
482 * It will not work with specially-formatted tokens like DEF or DCL,
483 * but hopefully those would be recognized */
484static int shader_skip_unrecognized(const struct wined3d_sm1_data *priv, const DWORD *ptr)
485{
486 int tokens_read = 0;
487 int i = 0;
488
489 /* TODO: Think of a good name for 0x80000000 and replace it with a constant */
490 while (*ptr & 0x80000000)
491 {
492 DWORD token, addr_token = 0;
493 struct wined3d_shader_src_param rel_addr;
494
495 tokens_read += shader_get_param(priv, ptr, &token, &addr_token);
496 ptr += tokens_read;
497
498 FIXME("Unrecognized opcode param: token=0x%08x addr_token=0x%08x name=", token, addr_token);
499
500 if (token & WINED3DSHADER_ADDRMODE_RELATIVE) shader_parse_src_param(addr_token, NULL, &rel_addr);
501
502 if (!i)
503 {
504 struct wined3d_shader_dst_param dst;
505
506 shader_parse_dst_param(token, token & WINED3DSHADER_ADDRMODE_RELATIVE ? &rel_addr : NULL, &dst);
507 shader_dump_dst_param(&dst, &priv->shader_version);
508 }
509 else
510 {
511 struct wined3d_shader_src_param src;
512
513 shader_parse_src_param(token, token & WINED3DSHADER_ADDRMODE_RELATIVE ? &rel_addr : NULL, &src);
514 shader_dump_src_param(&src, &priv->shader_version);
515 }
516 FIXME("\n");
517 ++i;
518 }
519 return tokens_read;
520}
521
522static void *shader_sm1_init(const DWORD *byte_code, DWORD tokens_num, const struct wined3d_shader_signature *output_signature)
523{
524 struct wined3d_sm1_data *priv;
525 BYTE major, minor;
526
527 major = WINED3D_SM1_VERSION_MAJOR(*byte_code);
528 minor = WINED3D_SM1_VERSION_MINOR(*byte_code);
529 if (WINED3D_SHADER_VERSION(major, minor) > WINED3D_SHADER_VERSION(3, 0))
530 {
531 WARN("Invalid shader version %u.%u (%#x).\n", major, minor, *byte_code);
532 return NULL;
533 }
534
535 priv = HeapAlloc(GetProcessHeap(), 0, sizeof(*priv));
536 if (!priv)
537 {
538 ERR("Failed to allocate private data\n");
539 return NULL;
540 }
541
542 priv->end = NULL;
543 priv->tokens_num = tokens_num;
544
545 if (output_signature)
546 {
547 FIXME("SM 1-3 shader shouldn't have output signatures.\n");
548 }
549
550 switch (*byte_code >> 16)
551 {
552 case WINED3D_SM1_VS:
553 priv->shader_version.type = WINED3D_SHADER_TYPE_VERTEX;
554 priv->opcode_table = vs_opcode_table;
555 break;
556
557 case WINED3D_SM1_PS:
558 priv->shader_version.type = WINED3D_SHADER_TYPE_PIXEL;
559 priv->opcode_table = ps_opcode_table;
560 break;
561
562 default:
563 FIXME("Unrecognized shader type %#x\n", *byte_code >> 16);
564 HeapFree(GetProcessHeap(), 0, priv);
565 return NULL;
566 }
567
568 return priv;
569}
570
571static void shader_sm1_free(void *data)
572{
573 HeapFree(GetProcessHeap(), 0, data);
574}
575
576static void shader_sm1_read_header(void *data, const DWORD **ptr, struct wined3d_shader_version *shader_version)
577{
578 struct wined3d_sm1_data *priv = data;
579 DWORD version_token;
580
581 priv->end = *ptr + priv->tokens_num;
582
583 version_token = *(*ptr)++;
584 TRACE("version: 0x%08x\n", version_token);
585
586 priv->shader_version.major = WINED3D_SM1_VERSION_MAJOR(version_token);
587 priv->shader_version.minor = WINED3D_SM1_VERSION_MINOR(version_token);
588 *shader_version = priv->shader_version;
589}
590
591static void shader_sm1_read_opcode(void *data, const DWORD **ptr, struct wined3d_shader_instruction *ins,
592 UINT *param_size)
593{
594 struct wined3d_sm1_data *priv = data;
595 const struct wined3d_sm1_opcode_info *opcode_info;
596 DWORD opcode_token;
597
598 opcode_token = *(*ptr)++;
599 opcode_info = shader_get_opcode(priv, opcode_token);
600 if (!opcode_info)
601 {
602 FIXME("Unrecognized opcode: token=0x%08x\n", opcode_token);
603 ins->handler_idx = WINED3DSIH_TABLE_SIZE;
604 *param_size = shader_skip_unrecognized(priv, *ptr);
605 return;
606 }
607
608 ins->handler_idx = opcode_info->handler_idx;
609 ins->flags = (opcode_token & WINED3D_OPCODESPECIFICCONTROL_MASK) >> WINED3D_OPCODESPECIFICCONTROL_SHIFT;
610 ins->coissue = opcode_token & WINED3DSI_COISSUE;
611 ins->predicate = opcode_token & WINED3DSHADER_INSTRUCTION_PREDICATED;
612 ins->dst_count = opcode_info->dst_count ? 1 : 0;
613 ins->src_count = opcode_info->param_count - opcode_info->dst_count;
614 *param_size = shader_skip_opcode(priv, opcode_info, opcode_token);
615}
616
617static void shader_sm1_read_src_param(void *data, const DWORD **ptr, struct wined3d_shader_src_param *src_param,
618 struct wined3d_shader_src_param *src_rel_addr)
619{
620 struct wined3d_sm1_data *priv = data;
621 DWORD token, addr_token;
622
623 *ptr += shader_get_param(priv, *ptr, &token, &addr_token);
624 if (token & WINED3DSHADER_ADDRMODE_RELATIVE)
625 {
626 shader_parse_src_param(addr_token, NULL, src_rel_addr);
627 shader_parse_src_param(token, src_rel_addr, src_param);
628 }
629 else
630 {
631 shader_parse_src_param(token, NULL, src_param);
632 }
633}
634
635static void shader_sm1_read_dst_param(void *data, const DWORD **ptr, struct wined3d_shader_dst_param *dst_param,
636 struct wined3d_shader_src_param *dst_rel_addr)
637{
638 struct wined3d_sm1_data *priv = data;
639 DWORD token, addr_token;
640
641 *ptr += shader_get_param(priv, *ptr, &token, &addr_token);
642 if (token & WINED3DSHADER_ADDRMODE_RELATIVE)
643 {
644 shader_parse_src_param(addr_token, NULL, dst_rel_addr);
645 shader_parse_dst_param(token, dst_rel_addr, dst_param);
646 }
647 else
648 {
649 shader_parse_dst_param(token, NULL, dst_param);
650 }
651}
652
653static void shader_sm1_read_semantic(const DWORD **ptr, struct wined3d_shader_semantic *semantic)
654{
655 DWORD usage_token = *(*ptr)++;
656 DWORD dst_token = *(*ptr)++;
657
658 semantic->usage = (usage_token & WINED3DSP_DCL_USAGE_MASK) >> WINED3DSP_DCL_USAGE_SHIFT;
659 semantic->usage_idx = (usage_token & WINED3DSP_DCL_USAGEINDEX_MASK) >> WINED3DSP_DCL_USAGEINDEX_SHIFT;
660 semantic->sampler_type = (usage_token & WINED3DSP_TEXTURETYPE_MASK) >> WINED3DSP_TEXTURETYPE_SHIFT;
661 shader_parse_dst_param(dst_token, NULL, &semantic->reg);
662}
663
664static void shader_sm1_read_comment(const DWORD **ptr, const char **comment, UINT *comment_size)
665{
666 DWORD token = **ptr;
667 UINT size;
668
669 if ((token & WINED3DSI_OPCODE_MASK) != WINED3D_SM1_OP_COMMENT)
670 {
671 *comment = NULL;
672 return;
673 }
674
675 size = (token & WINED3DSI_COMMENTSIZE_MASK) >> WINED3DSI_COMMENTSIZE_SHIFT;
676 *comment = (const char *)++(*ptr);
677 *comment_size = size * sizeof(DWORD);
678 *ptr += size;
679}
680
681static BOOL shader_sm1_is_end(void *data, const DWORD **ptr)
682{
683 struct wined3d_sm1_data *priv = data;
684
685 if (**ptr == WINED3DSP_END)
686 {
687 ++(*ptr);
688 return TRUE;
689 }
690
691 AssertMsgReturn(*ptr < priv->end, ("End-of-bytecode token is missing"), TRUE);
692
693 return FALSE;
694}
695
696const struct wined3d_shader_frontend sm1_shader_frontend =
697{
698 shader_sm1_init,
699 shader_sm1_free,
700 shader_sm1_read_header,
701 shader_sm1_read_opcode,
702 shader_sm1_read_src_param,
703 shader_sm1_read_dst_param,
704 shader_sm1_read_semantic,
705 shader_sm1_read_comment,
706 shader_sm1_is_end,
707};
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette