wined3d: Make the "icb" field in struct wined3d_shader_instruction const.
[wine.git] / dlls / wined3d / shader_sm4.c
blob45bd9f0736afe0610eb522270d61942e06938d81
1 /*
2 * Copyright 2009 Henri Verbeet for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include "config.h"
20 #include "wine/port.h"
22 #include "wined3d_private.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(d3d_shader);
25 WINE_DECLARE_DEBUG_CHANNEL(d3d_bytecode);
27 #define WINED3D_SM4_INSTRUCTION_MODIFIER (0x1u << 31)
29 #define WINED3D_SM4_INSTRUCTION_LENGTH_SHIFT 24
30 #define WINED3D_SM4_INSTRUCTION_LENGTH_MASK (0x1fu << WINED3D_SM4_INSTRUCTION_LENGTH_SHIFT)
32 #define WINED3D_SM4_INSTRUCTION_FLAGS_SHIFT 11
33 #define WINED3D_SM4_INSTRUCTION_FLAGS_MASK (0x7u << WINED3D_SM4_INSTRUCTION_FLAGS_SHIFT)
35 #define WINED3D_SM4_RESOURCE_TYPE_SHIFT 11
36 #define WINED3D_SM4_RESOURCE_TYPE_MASK (0xfu << WINED3D_SM4_RESOURCE_TYPE_SHIFT)
38 #define WINED3D_SM4_PRIMITIVE_TYPE_SHIFT 11
39 #define WINED3D_SM4_PRIMITIVE_TYPE_MASK (0x7u << WINED3D_SM4_PRIMITIVE_TYPE_SHIFT)
41 #define WINED3D_SM4_INDEX_TYPE_SHIFT 11
42 #define WINED3D_SM4_INDEX_TYPE_MASK (0x1u << WINED3D_SM4_INDEX_TYPE_SHIFT)
44 #define WINED3D_SM4_SAMPLER_MODE_SHIFT 11
45 #define WINED3D_SM4_SAMPLER_MODE_MASK (0xfu << WINED3D_SM4_SAMPLER_MODE_SHIFT)
47 #define WINED3D_SM4_SHADER_DATA_TYPE_SHIFT 11
48 #define WINED3D_SM4_SHADER_DATA_TYPE_MASK (0xfu << WINED3D_SM4_SHADER_DATA_TYPE_SHIFT)
50 #define WINED3D_SM4_INTERPOLATION_MODE_SHIFT 11
51 #define WINED3D_SM4_INTERPOLATION_MODE_MASK (0xfu << WINED3D_SM4_INTERPOLATION_MODE_SHIFT)
53 #define WINED3D_SM4_GLOBAL_FLAGS_SHIFT 11
54 #define WINED3D_SM4_GLOBAL_FLAGS_MASK (0xffu << WINED3D_SM4_GLOBAL_FLAGS_SHIFT)
56 #define WINED3D_SM4_OPCODE_MASK 0xff
58 #define WINED3D_SM4_REGISTER_MODIFIER (0x1u << 31)
60 #define WINED3D_SM4_ADDRESSING_SHIFT1 25
61 #define WINED3D_SM4_ADDRESSING_MASK1 (0x3u << WINED3D_SM4_ADDRESSING_SHIFT1)
63 #define WINED3D_SM4_ADDRESSING_SHIFT0 22
64 #define WINED3D_SM4_ADDRESSING_MASK0 (0x3u << WINED3D_SM4_ADDRESSING_SHIFT0)
66 #define WINED3D_SM4_REGISTER_ORDER_SHIFT 20
67 #define WINED3D_SM4_REGISTER_ORDER_MASK (0x3u << WINED3D_SM4_REGISTER_ORDER_SHIFT)
69 #define WINED3D_SM4_REGISTER_TYPE_SHIFT 12
70 #define WINED3D_SM4_REGISTER_TYPE_MASK (0xfu << WINED3D_SM4_REGISTER_TYPE_SHIFT)
72 #define WINED3D_SM4_SWIZZLE_TYPE_SHIFT 2
73 #define WINED3D_SM4_SWIZZLE_TYPE_MASK (0x3u << WINED3D_SM4_SWIZZLE_TYPE_SHIFT)
75 #define WINED3D_SM4_IMMCONST_TYPE_SHIFT 0
76 #define WINED3D_SM4_IMMCONST_TYPE_MASK (0x3u << WINED3D_SM4_IMMCONST_TYPE_SHIFT)
78 #define WINED3D_SM4_WRITEMASK_SHIFT 4
79 #define WINED3D_SM4_WRITEMASK_MASK (0xfu << WINED3D_SM4_WRITEMASK_SHIFT)
81 #define WINED3D_SM4_SWIZZLE_SHIFT 4
82 #define WINED3D_SM4_SWIZZLE_MASK (0xffu << WINED3D_SM4_SWIZZLE_SHIFT)
84 #define WINED3D_SM4_VERSION_MAJOR(version) (((version) >> 4) & 0xf)
85 #define WINED3D_SM4_VERSION_MINOR(version) (((version) >> 0) & 0xf)
87 #define WINED3D_SM4_ADDRESSING_RELATIVE 0x2
88 #define WINED3D_SM4_ADDRESSING_OFFSET 0x1
90 #define WINED3D_SM4_INSTRUCTION_FLAG_SATURATE 0x4
92 enum wined3d_sm4_opcode
94 WINED3D_SM4_OP_ADD = 0x00,
95 WINED3D_SM4_OP_AND = 0x01,
96 WINED3D_SM4_OP_BREAK = 0x02,
97 WINED3D_SM4_OP_BREAKC = 0x03,
98 WINED3D_SM4_OP_CUT = 0x09,
99 WINED3D_SM4_OP_DERIV_RTX = 0x0b,
100 WINED3D_SM4_OP_DERIV_RTY = 0x0c,
101 WINED3D_SM4_OP_DISCARD = 0x0d,
102 WINED3D_SM4_OP_DIV = 0x0e,
103 WINED3D_SM4_OP_DP2 = 0x0f,
104 WINED3D_SM4_OP_DP3 = 0x10,
105 WINED3D_SM4_OP_DP4 = 0x11,
106 WINED3D_SM4_OP_ELSE = 0x12,
107 WINED3D_SM4_OP_EMIT = 0x13,
108 WINED3D_SM4_OP_ENDIF = 0x15,
109 WINED3D_SM4_OP_ENDLOOP = 0x16,
110 WINED3D_SM4_OP_EQ = 0x18,
111 WINED3D_SM4_OP_EXP = 0x19,
112 WINED3D_SM4_OP_FRC = 0x1a,
113 WINED3D_SM4_OP_FTOI = 0x1b,
114 WINED3D_SM4_OP_FTOU = 0x1c,
115 WINED3D_SM4_OP_GE = 0x1d,
116 WINED3D_SM4_OP_IADD = 0x1e,
117 WINED3D_SM4_OP_IF = 0x1f,
118 WINED3D_SM4_OP_IEQ = 0x20,
119 WINED3D_SM4_OP_IGE = 0x21,
120 WINED3D_SM4_OP_ILT = 0x22,
121 WINED3D_SM4_OP_IMAD = 0x23,
122 WINED3D_SM4_OP_IMAX = 0x24,
123 WINED3D_SM4_OP_IMIN = 0x25,
124 WINED3D_SM4_OP_IMUL = 0x26,
125 WINED3D_SM4_OP_INE = 0x27,
126 WINED3D_SM4_OP_INEG = 0x28,
127 WINED3D_SM4_OP_ISHL = 0x29,
128 WINED3D_SM4_OP_ITOF = 0x2b,
129 WINED3D_SM4_OP_LD = 0x2d,
130 WINED3D_SM4_OP_LOG = 0x2f,
131 WINED3D_SM4_OP_LOOP = 0x30,
132 WINED3D_SM4_OP_LT = 0x31,
133 WINED3D_SM4_OP_MAD = 0x32,
134 WINED3D_SM4_OP_MIN = 0x33,
135 WINED3D_SM4_OP_MAX = 0x34,
136 WINED3D_SM4_OP_SHADER_DATA = 0x35,
137 WINED3D_SM4_OP_MOV = 0x36,
138 WINED3D_SM4_OP_MOVC = 0x37,
139 WINED3D_SM4_OP_MUL = 0x38,
140 WINED3D_SM4_OP_NE = 0x39,
141 WINED3D_SM4_OP_NOT = 0x3b,
142 WINED3D_SM4_OP_OR = 0x3c,
143 WINED3D_SM4_OP_RESINFO = 0x3d,
144 WINED3D_SM4_OP_RET = 0x3e,
145 WINED3D_SM4_OP_ROUND_NI = 0x41,
146 WINED3D_SM4_OP_ROUND_PI = 0x42,
147 WINED3D_SM4_OP_ROUND_Z = 0x43,
148 WINED3D_SM4_OP_RSQ = 0x44,
149 WINED3D_SM4_OP_SAMPLE = 0x45,
150 WINED3D_SM4_OP_SAMPLE_C = 0x46,
151 WINED3D_SM4_OP_SAMPLE_C_LZ = 0x47,
152 WINED3D_SM4_OP_SAMPLE_LOD = 0x48,
153 WINED3D_SM4_OP_SAMPLE_GRAD = 0x49,
154 WINED3D_SM4_OP_SAMPLE_B = 0x4a,
155 WINED3D_SM4_OP_SQRT = 0x4b,
156 WINED3D_SM4_OP_SINCOS = 0x4d,
157 WINED3D_SM4_OP_UDIV = 0x4e,
158 WINED3D_SM4_OP_UGE = 0x50,
159 WINED3D_SM4_OP_USHR = 0x55,
160 WINED3D_SM4_OP_UTOF = 0x56,
161 WINED3D_SM4_OP_XOR = 0x57,
162 WINED3D_SM4_OP_DCL_RESOURCE = 0x58,
163 WINED3D_SM4_OP_DCL_CONSTANT_BUFFER = 0x59,
164 WINED3D_SM4_OP_DCL_SAMPLER = 0x5a,
165 WINED3D_SM4_OP_DCL_OUTPUT_TOPOLOGY = 0x5c,
166 WINED3D_SM4_OP_DCL_INPUT_PRIMITIVE = 0x5d,
167 WINED3D_SM4_OP_DCL_VERTICES_OUT = 0x5e,
168 WINED3D_SM4_OP_DCL_INPUT = 0x5f,
169 WINED3D_SM4_OP_DCL_INPUT_SGV = 0x60,
170 WINED3D_SM4_OP_DCL_INPUT_SIV = 0x61,
171 WINED3D_SM4_OP_DCL_INPUT_PS = 0x62,
172 WINED3D_SM4_OP_DCL_INPUT_PS_SGV = 0x63,
173 WINED3D_SM4_OP_DCL_INPUT_PS_SIV = 0x64,
174 WINED3D_SM4_OP_DCL_OUTPUT = 0x65,
175 WINED3D_SM4_OP_DCL_OUTPUT_SIV = 0x67,
176 WINED3D_SM4_OP_DCL_TEMPS = 0x68,
177 WINED3D_SM4_OP_DCL_GLOBAL_FLAGS = 0x6a,
180 enum wined3d_sm4_register_type
182 WINED3D_SM4_RT_TEMP = 0x0,
183 WINED3D_SM4_RT_INPUT = 0x1,
184 WINED3D_SM4_RT_OUTPUT = 0x2,
185 WINED3D_SM4_RT_IMMCONST = 0x4,
186 WINED3D_SM4_RT_SAMPLER = 0x6,
187 WINED3D_SM4_RT_RESOURCE = 0x7,
188 WINED3D_SM4_RT_CONSTBUFFER = 0x8,
189 WINED3D_SM4_RT_IMMCONSTBUFFER = 0x9,
190 WINED3D_SM4_RT_PRIMID = 0xb,
191 WINED3D_SM4_RT_DEPTHOUT = 0xc,
192 WINED3D_SM4_RT_NULL = 0xd,
195 enum wined3d_sm4_output_primitive_type
197 WINED3D_SM4_OUTPUT_PT_POINTLIST = 0x1,
198 WINED3D_SM4_OUTPUT_PT_LINELIST = 0x3,
199 WINED3D_SM4_OUTPUT_PT_TRIANGLESTRIP = 0x5,
202 enum wined3d_sm4_input_primitive_type
204 WINED3D_SM4_INPUT_PT_POINT = 0x1,
205 WINED3D_SM4_INPUT_PT_LINE = 0x2,
206 WINED3D_SM4_INPUT_PT_TRIANGLE = 0x3,
207 WINED3D_SM4_INPUT_PT_LINEADJ = 0x6,
208 WINED3D_SM4_INPUT_PT_TRIANGLEADJ = 0x7,
211 enum wined3d_sm4_swizzle_type
213 WINED3D_SM4_SWIZZLE_NONE = 0x0,
214 WINED3D_SM4_SWIZZLE_VEC4 = 0x1,
215 WINED3D_SM4_SWIZZLE_SCALAR = 0x2,
218 enum wined3d_sm4_immconst_type
220 WINED3D_SM4_IMMCONST_SCALAR = 0x1,
221 WINED3D_SM4_IMMCONST_VEC4 = 0x2,
224 enum wined3d_sm4_resource_type
226 WINED3D_SM4_RESOURCE_BUFFER = 0x1,
227 WINED3D_SM4_RESOURCE_TEXTURE_1D = 0x2,
228 WINED3D_SM4_RESOURCE_TEXTURE_2D = 0x3,
229 WINED3D_SM4_RESOURCE_TEXTURE_2DMS = 0x4,
230 WINED3D_SM4_RESOURCE_TEXTURE_3D = 0x5,
231 WINED3D_SM4_RESOURCE_TEXTURE_CUBE = 0x6,
232 WINED3D_SM4_RESOURCE_TEXTURE_1DARRAY = 0x7,
233 WINED3D_SM4_RESOURCE_TEXTURE_2DARRAY = 0x8,
234 WINED3D_SM4_RESOURCE_TEXTURE_2DMSARRAY = 0x9,
237 enum wined3d_sm4_data_type
239 WINED3D_SM4_DATA_UNORM = 0x1,
240 WINED3D_SM4_DATA_SNORM = 0x2,
241 WINED3D_SM4_DATA_INT = 0x3,
242 WINED3D_SM4_DATA_UINT = 0x4,
243 WINED3D_SM4_DATA_FLOAT = 0x5,
246 enum wined3d_sm4_sampler_mode
248 WINED3D_SM4_SAMPLER_DEFAULT = 0x0,
249 WINED3D_SM4_SAMPLER_COMPARISON = 0x1,
252 enum wined3d_sm4_shader_data_type
254 WINED3D_SM4_SHADER_DATA_IMMEDIATE_CONSTANT_BUFFER = 0x3,
255 WINED3D_SM4_SHADER_DATA_MESSAGE = 0x4,
258 struct wined3d_shader_src_param_entry
260 struct list entry;
261 struct wined3d_shader_src_param param;
264 struct wined3d_sm4_data
266 struct wined3d_shader_version shader_version;
267 const DWORD *end;
269 struct
271 enum wined3d_shader_register_type register_type;
272 UINT register_idx;
273 } output_map[MAX_REG_OUTPUT];
275 struct wined3d_shader_src_param src_param[5];
276 struct wined3d_shader_dst_param dst_param[2];
277 struct list src_free;
278 struct list src;
279 struct wined3d_shader_immediate_constant_buffer icb;
282 struct wined3d_sm4_opcode_info
284 enum wined3d_sm4_opcode opcode;
285 enum WINED3D_SHADER_INSTRUCTION_HANDLER handler_idx;
286 const char *dst_info;
287 const char *src_info;
290 struct sysval_map
292 enum wined3d_sysval_semantic sysval;
293 enum wined3d_shader_register_type register_type;
294 UINT register_idx;
298 * F -> WINED3D_DATA_FLOAT
299 * I -> WINED3D_DATA_INT
300 * R -> WINED3D_DATA_RESOURCE
301 * S -> WINED3D_DATA_SAMPLER
302 * U -> WINED3D_DATA_UINT
304 static const struct wined3d_sm4_opcode_info opcode_table[] =
306 {WINED3D_SM4_OP_ADD, WINED3DSIH_ADD, "F", "FF"},
307 {WINED3D_SM4_OP_AND, WINED3DSIH_AND, "U", "UU"},
308 {WINED3D_SM4_OP_BREAK, WINED3DSIH_BREAK, "", ""},
309 {WINED3D_SM4_OP_BREAKC, WINED3DSIH_BREAKP, "", "U"},
310 {WINED3D_SM4_OP_CUT, WINED3DSIH_CUT, "", ""},
311 {WINED3D_SM4_OP_DERIV_RTX, WINED3DSIH_DSX, "F", "F"},
312 {WINED3D_SM4_OP_DERIV_RTY, WINED3DSIH_DSY, "F", "F"},
313 {WINED3D_SM4_OP_DISCARD, WINED3DSIH_TEXKILL, "", "U"},
314 {WINED3D_SM4_OP_DIV, WINED3DSIH_DIV, "F", "FF"},
315 {WINED3D_SM4_OP_DP2, WINED3DSIH_DP2, "F", "FF"},
316 {WINED3D_SM4_OP_DP3, WINED3DSIH_DP3, "F", "FF"},
317 {WINED3D_SM4_OP_DP4, WINED3DSIH_DP4, "F", "FF"},
318 {WINED3D_SM4_OP_ELSE, WINED3DSIH_ELSE, "", ""},
319 {WINED3D_SM4_OP_EMIT, WINED3DSIH_EMIT, "", ""},
320 {WINED3D_SM4_OP_ENDIF, WINED3DSIH_ENDIF, "", ""},
321 {WINED3D_SM4_OP_ENDLOOP, WINED3DSIH_ENDLOOP, "", ""},
322 {WINED3D_SM4_OP_EQ, WINED3DSIH_EQ, "U", "FF"},
323 {WINED3D_SM4_OP_EXP, WINED3DSIH_EXP, "F", "F"},
324 {WINED3D_SM4_OP_FRC, WINED3DSIH_FRC, "F", "F"},
325 {WINED3D_SM4_OP_FTOI, WINED3DSIH_FTOI, "I", "F"},
326 {WINED3D_SM4_OP_FTOU, WINED3DSIH_FTOU, "U", "F"},
327 {WINED3D_SM4_OP_GE, WINED3DSIH_GE, "U", "FF"},
328 {WINED3D_SM4_OP_IADD, WINED3DSIH_IADD, "I", "II"},
329 {WINED3D_SM4_OP_IF, WINED3DSIH_IF, "", "U"},
330 {WINED3D_SM4_OP_IEQ, WINED3DSIH_IEQ, "U", "II"},
331 {WINED3D_SM4_OP_IGE, WINED3DSIH_IGE, "U", "II"},
332 {WINED3D_SM4_OP_ILT, WINED3DSIH_ILT, "U", "II"},
333 {WINED3D_SM4_OP_IMAD, WINED3DSIH_IMAD, "I", "III"},
334 {WINED3D_SM4_OP_IMAX, WINED3DSIH_IMAX, "I", "II"},
335 {WINED3D_SM4_OP_IMIN, WINED3DSIH_IMIN, "I", "II"},
336 {WINED3D_SM4_OP_IMUL, WINED3DSIH_IMUL, "II", "II"},
337 {WINED3D_SM4_OP_INE, WINED3DSIH_INE, "U", "II"},
338 {WINED3D_SM4_OP_INEG, WINED3DSIH_INEG, "I", "I"},
339 {WINED3D_SM4_OP_ISHL, WINED3DSIH_ISHL, "I", "II"},
340 {WINED3D_SM4_OP_ITOF, WINED3DSIH_ITOF, "F", "I"},
341 {WINED3D_SM4_OP_LD, WINED3DSIH_LD, "U", "IR"},
342 {WINED3D_SM4_OP_LOG, WINED3DSIH_LOG, "F", "F"},
343 {WINED3D_SM4_OP_LOOP, WINED3DSIH_LOOP, "", ""},
344 {WINED3D_SM4_OP_LT, WINED3DSIH_LT, "U", "FF"},
345 {WINED3D_SM4_OP_MAD, WINED3DSIH_MAD, "F", "FFF"},
346 {WINED3D_SM4_OP_MIN, WINED3DSIH_MIN, "F", "FF"},
347 {WINED3D_SM4_OP_MAX, WINED3DSIH_MAX, "F", "FF"},
348 {WINED3D_SM4_OP_SHADER_DATA, WINED3DSIH_DCL_IMMEDIATE_CONSTANT_BUFFER, "", ""},
349 {WINED3D_SM4_OP_MOV, WINED3DSIH_MOV, "F", "F"},
350 {WINED3D_SM4_OP_MOVC, WINED3DSIH_MOVC, "F", "UFF"},
351 {WINED3D_SM4_OP_MUL, WINED3DSIH_MUL, "F", "FF"},
352 {WINED3D_SM4_OP_NE, WINED3DSIH_NE, "U", "FF"},
353 {WINED3D_SM4_OP_NOT, WINED3DSIH_NOT, "U", "U"},
354 {WINED3D_SM4_OP_OR, WINED3DSIH_OR, "U", "UU"},
355 {WINED3D_SM4_OP_RESINFO, WINED3DSIH_RESINFO, "F", "IR"},
356 {WINED3D_SM4_OP_RET, WINED3DSIH_RET, "", ""},
357 {WINED3D_SM4_OP_ROUND_NI, WINED3DSIH_ROUND_NI, "F", "F"},
358 {WINED3D_SM4_OP_ROUND_PI, WINED3DSIH_ROUND_PI, "F", "F"},
359 {WINED3D_SM4_OP_ROUND_Z, WINED3DSIH_ROUND_Z, "F", "F"},
360 {WINED3D_SM4_OP_RSQ, WINED3DSIH_RSQ, "F", "F"},
361 {WINED3D_SM4_OP_SAMPLE, WINED3DSIH_SAMPLE, "U", "FRS"},
362 {WINED3D_SM4_OP_SAMPLE_C, WINED3DSIH_SAMPLE_C, "F", "FRSF"},
363 {WINED3D_SM4_OP_SAMPLE_C_LZ, WINED3DSIH_SAMPLE_C_LZ, "F", "FRSF"},
364 {WINED3D_SM4_OP_SAMPLE_LOD, WINED3DSIH_SAMPLE_LOD, "U", "FRSF"},
365 {WINED3D_SM4_OP_SAMPLE_GRAD, WINED3DSIH_SAMPLE_GRAD, "U", "FRSFF"},
366 {WINED3D_SM4_OP_SAMPLE_B, WINED3DSIH_SAMPLE_B, "U", "FRSF"},
367 {WINED3D_SM4_OP_SQRT, WINED3DSIH_SQRT, "F", "F"},
368 {WINED3D_SM4_OP_SINCOS, WINED3DSIH_SINCOS, "FF", "F"},
369 {WINED3D_SM4_OP_UDIV, WINED3DSIH_UDIV, "UU", "UU"},
370 {WINED3D_SM4_OP_UGE, WINED3DSIH_UGE, "U", "UU"},
371 {WINED3D_SM4_OP_USHR, WINED3DSIH_USHR, "U", "UU"},
372 {WINED3D_SM4_OP_UTOF, WINED3DSIH_UTOF, "F", "U"},
373 {WINED3D_SM4_OP_XOR, WINED3DSIH_XOR, "U", "UU"},
374 {WINED3D_SM4_OP_DCL_RESOURCE, WINED3DSIH_DCL, "R", ""},
375 {WINED3D_SM4_OP_DCL_CONSTANT_BUFFER, WINED3DSIH_DCL_CONSTANT_BUFFER, "", ""},
376 {WINED3D_SM4_OP_DCL_SAMPLER, WINED3DSIH_DCL_SAMPLER, "", ""},
377 {WINED3D_SM4_OP_DCL_OUTPUT_TOPOLOGY, WINED3DSIH_DCL_OUTPUT_TOPOLOGY, "", ""},
378 {WINED3D_SM4_OP_DCL_INPUT_PRIMITIVE, WINED3DSIH_DCL_INPUT_PRIMITIVE, "", ""},
379 {WINED3D_SM4_OP_DCL_VERTICES_OUT, WINED3DSIH_DCL_VERTICES_OUT, "", ""},
380 {WINED3D_SM4_OP_DCL_INPUT, WINED3DSIH_DCL_INPUT, "", ""},
381 {WINED3D_SM4_OP_DCL_INPUT_SGV, WINED3DSIH_DCL_INPUT_SGV, "", ""},
382 {WINED3D_SM4_OP_DCL_INPUT_SIV, WINED3DSIH_DCL_INPUT_SIV, "", ""},
383 {WINED3D_SM4_OP_DCL_INPUT_PS, WINED3DSIH_DCL_INPUT_PS, "", ""},
384 {WINED3D_SM4_OP_DCL_INPUT_PS_SGV, WINED3DSIH_DCL_INPUT_PS_SGV, "", ""},
385 {WINED3D_SM4_OP_DCL_INPUT_PS_SIV, WINED3DSIH_DCL_INPUT_PS_SIV, "", ""},
386 {WINED3D_SM4_OP_DCL_OUTPUT, WINED3DSIH_DCL_OUTPUT, "", ""},
387 {WINED3D_SM4_OP_DCL_OUTPUT_SIV, WINED3DSIH_DCL_OUTPUT_SIV, "", ""},
388 {WINED3D_SM4_OP_DCL_TEMPS, WINED3DSIH_DCL_TEMPS, "", ""},
389 {WINED3D_SM4_OP_DCL_GLOBAL_FLAGS, WINED3DSIH_DCL_GLOBAL_FLAGS, "", ""},
392 static const enum wined3d_shader_register_type register_type_table[] =
394 /* WINED3D_SM4_RT_TEMP */ WINED3DSPR_TEMP,
395 /* WINED3D_SM4_RT_INPUT */ WINED3DSPR_INPUT,
396 /* WINED3D_SM4_RT_OUTPUT */ WINED3DSPR_OUTPUT,
397 /* UNKNOWN */ 0,
398 /* WINED3D_SM4_RT_IMMCONST */ WINED3DSPR_IMMCONST,
399 /* UNKNOWN */ 0,
400 /* WINED3D_SM4_RT_SAMPLER */ WINED3DSPR_SAMPLER,
401 /* WINED3D_SM4_RT_RESOURCE */ WINED3DSPR_RESOURCE,
402 /* WINED3D_SM4_RT_CONSTBUFFER */ WINED3DSPR_CONSTBUFFER,
403 /* WINED3D_SM4_RT_IMMCONSTBUFFER */ WINED3DSPR_IMMCONSTBUFFER,
404 /* UNKNOWN */ 0,
405 /* WINED3D_SM4_RT_PRIMID */ WINED3DSPR_PRIMID,
406 /* WINED3D_SM4_RT_DEPTHOUT */ WINED3DSPR_DEPTHOUT,
407 /* WINED3D_SM4_RT_NULL */ WINED3DSPR_NULL,
410 static const enum wined3d_primitive_type output_primitive_type_table[] =
412 /* UNKNOWN */ WINED3D_PT_UNDEFINED,
413 /* WINED3D_SM4_OUTPUT_PT_POINTLIST */ WINED3D_PT_POINTLIST,
414 /* UNKNOWN */ WINED3D_PT_UNDEFINED,
415 /* WINED3D_SM4_OUTPUT_PT_LINELIST */ WINED3D_PT_LINELIST,
416 /* UNKNOWN */ WINED3D_PT_UNDEFINED,
417 /* WINED3D_SM4_OUTPUT_PT_TRIANGLESTRIP */ WINED3D_PT_TRIANGLESTRIP,
420 static const enum wined3d_primitive_type input_primitive_type_table[] =
422 /* UNKNOWN */ WINED3D_PT_UNDEFINED,
423 /* WINED3D_SM4_INPUT_PT_POINT */ WINED3D_PT_POINTLIST,
424 /* WINED3D_SM4_INPUT_PT_LINE */ WINED3D_PT_LINELIST,
425 /* WINED3D_SM4_INPUT_PT_TRIANGLE */ WINED3D_PT_TRIANGLELIST,
426 /* UNKNOWN */ WINED3D_PT_UNDEFINED,
427 /* UNKNOWN */ WINED3D_PT_UNDEFINED,
428 /* WINED3D_SM4_INPUT_PT_LINEADJ */ WINED3D_PT_LINELIST_ADJ,
429 /* WINED3D_SM4_INPUT_PT_TRIANGLEADJ */ WINED3D_PT_TRIANGLELIST_ADJ,
432 static const struct sysval_map sysval_map[] =
434 {WINED3D_SV_DEPTH, WINED3DSPR_DEPTHOUT, 0},
435 {WINED3D_SV_TARGET0, WINED3DSPR_COLOROUT, 0},
436 {WINED3D_SV_TARGET1, WINED3DSPR_COLOROUT, 1},
437 {WINED3D_SV_TARGET2, WINED3DSPR_COLOROUT, 2},
438 {WINED3D_SV_TARGET3, WINED3DSPR_COLOROUT, 3},
439 {WINED3D_SV_TARGET4, WINED3DSPR_COLOROUT, 4},
440 {WINED3D_SV_TARGET5, WINED3DSPR_COLOROUT, 5},
441 {WINED3D_SV_TARGET6, WINED3DSPR_COLOROUT, 6},
442 {WINED3D_SV_TARGET7, WINED3DSPR_COLOROUT, 7},
445 static const enum wined3d_shader_resource_type resource_type_table[] =
447 /* 0 */ WINED3D_SHADER_RESOURCE_NONE,
448 /* WINED3D_SM4_RESOURCE_BUFFER */ WINED3D_SHADER_RESOURCE_BUFFER,
449 /* WINED3D_SM4_RESOURCE_TEXTURE_1D */ WINED3D_SHADER_RESOURCE_TEXTURE_1D,
450 /* WINED3D_SM4_RESOURCE_TEXTURE_2D */ WINED3D_SHADER_RESOURCE_TEXTURE_2D,
451 /* WINED3D_SM4_RESOURCE_TEXTURE_2DMS */ WINED3D_SHADER_RESOURCE_TEXTURE_2DMS,
452 /* WINED3D_SM4_RESOURCE_TEXTURE_3D */ WINED3D_SHADER_RESOURCE_TEXTURE_3D,
453 /* WINED3D_SM4_RESOURCE_TEXTURE_CUBE */ WINED3D_SHADER_RESOURCE_TEXTURE_CUBE,
454 /* WINED3D_SM4_RESOURCE_TEXTURE_1DARRAY */ WINED3D_SHADER_RESOURCE_TEXTURE_1DARRAY,
455 /* WINED3D_SM4_RESOURCE_TEXTURE_2DARRAY */ WINED3D_SHADER_RESOURCE_TEXTURE_2DARRAY,
456 /* WINED3D_SM4_RESOURCE_TEXTURE_2DMSARRAY */ WINED3D_SHADER_RESOURCE_TEXTURE_2DMSARRAY,
459 static const enum wined3d_data_type data_type_table[] =
461 /* 0 */ WINED3D_DATA_FLOAT,
462 /* WINED3D_SM4_DATA_UNORM */ WINED3D_DATA_UNORM,
463 /* WINED3D_SM4_DATA_SNORM */ WINED3D_DATA_SNORM,
464 /* WINED3D_SM4_DATA_INT */ WINED3D_DATA_INT,
465 /* WINED3D_SM4_DATA_UINT */ WINED3D_DATA_UINT,
466 /* WINED3D_SM4_DATA_FLOAT */ WINED3D_DATA_FLOAT,
469 static BOOL shader_sm4_read_src_param(struct wined3d_sm4_data *priv, const DWORD **ptr,
470 enum wined3d_data_type data_type, struct wined3d_shader_src_param *src_param);
472 static const struct wined3d_sm4_opcode_info *get_opcode_info(enum wined3d_sm4_opcode opcode)
474 unsigned int i;
476 for (i = 0; i < sizeof(opcode_table) / sizeof(*opcode_table); ++i)
478 if (opcode == opcode_table[i].opcode) return &opcode_table[i];
481 return NULL;
484 static void map_register(const struct wined3d_sm4_data *priv, struct wined3d_shader_register *reg)
486 switch (priv->shader_version.type)
488 case WINED3D_SHADER_TYPE_PIXEL:
489 if (reg->type == WINED3DSPR_OUTPUT)
491 unsigned int reg_idx = reg->idx[0].offset;
493 if (reg_idx >= ARRAY_SIZE(priv->output_map))
495 ERR("Invalid output index %u.\n", reg_idx);
496 break;
499 reg->type = priv->output_map[reg_idx].register_type;
500 reg->idx[0].offset = priv->output_map[reg_idx].register_idx;
502 break;
504 default:
505 break;
509 static enum wined3d_data_type map_data_type(char t)
511 switch (t)
513 case 'F':
514 return WINED3D_DATA_FLOAT;
515 case 'I':
516 return WINED3D_DATA_INT;
517 case 'R':
518 return WINED3D_DATA_RESOURCE;
519 case 'S':
520 return WINED3D_DATA_SAMPLER;
521 case 'U':
522 return WINED3D_DATA_UINT;
523 default:
524 ERR("Invalid data type '%c'.\n", t);
525 return WINED3D_DATA_FLOAT;
529 static void *shader_sm4_init(const DWORD *byte_code, const struct wined3d_shader_signature *output_signature)
531 struct wined3d_sm4_data *priv;
532 unsigned int i, j;
534 if (!(priv = HeapAlloc(GetProcessHeap(), 0, sizeof(*priv))))
536 ERR("Failed to allocate private data\n");
537 return NULL;
540 memset(priv->output_map, 0xff, sizeof(priv->output_map));
541 for (i = 0; i < output_signature->element_count; ++i)
543 struct wined3d_shader_signature_element *e = &output_signature->elements[i];
545 if (e->register_idx >= ARRAY_SIZE(priv->output_map))
547 WARN("Invalid output index %u.\n", e->register_idx);
548 continue;
551 for (j = 0; j < ARRAY_SIZE(sysval_map); ++j)
553 if (e->sysval_semantic == sysval_map[j].sysval)
555 priv->output_map[e->register_idx].register_type = sysval_map[j].register_type;
556 priv->output_map[e->register_idx].register_idx = sysval_map[j].register_idx;
557 break;
562 list_init(&priv->src_free);
563 list_init(&priv->src);
565 return priv;
568 static void shader_sm4_free(void *data)
570 struct wined3d_shader_src_param_entry *e1, *e2;
571 struct wined3d_sm4_data *priv = data;
573 list_move_head(&priv->src_free, &priv->src);
574 LIST_FOR_EACH_ENTRY_SAFE(e1, e2, &priv->src_free, struct wined3d_shader_src_param_entry, entry)
576 HeapFree(GetProcessHeap(), 0, e1);
578 HeapFree(GetProcessHeap(), 0, priv);
581 static struct wined3d_shader_src_param *get_src_param(struct wined3d_sm4_data *priv)
583 struct wined3d_shader_src_param_entry *e;
584 struct list *elem;
586 if (!list_empty(&priv->src_free))
588 elem = list_head(&priv->src_free);
589 list_remove(elem);
591 else
593 if (!(e = HeapAlloc(GetProcessHeap(), 0, sizeof(*e))))
594 return NULL;
595 elem = &e->entry;
598 list_add_tail(&priv->src, elem);
599 e = LIST_ENTRY(elem, struct wined3d_shader_src_param_entry, entry);
600 return &e->param;
603 static void shader_sm4_read_header(void *data, const DWORD **ptr, struct wined3d_shader_version *shader_version)
605 struct wined3d_sm4_data *priv = data;
606 DWORD version_token;
608 priv->end = *ptr;
610 version_token = *(*ptr)++;
611 TRACE("version: 0x%08x\n", version_token);
613 TRACE("token count: %u\n", **ptr);
614 priv->end += *(*ptr)++;
616 switch (version_token >> 16)
618 case WINED3D_SM4_PS:
619 priv->shader_version.type = WINED3D_SHADER_TYPE_PIXEL;
620 break;
622 case WINED3D_SM4_VS:
623 priv->shader_version.type = WINED3D_SHADER_TYPE_VERTEX;
624 break;
626 case WINED3D_SM4_GS:
627 priv->shader_version.type = WINED3D_SHADER_TYPE_GEOMETRY;
628 break;
630 default:
631 FIXME("Unrecognized shader type %#x\n", version_token >> 16);
633 priv->shader_version.major = WINED3D_SM4_VERSION_MAJOR(version_token);
634 priv->shader_version.minor = WINED3D_SM4_VERSION_MINOR(version_token);
636 *shader_version = priv->shader_version;
639 static BOOL shader_sm4_read_reg_idx(struct wined3d_sm4_data *priv, const DWORD **ptr,
640 DWORD addressing, struct wined3d_shader_register_index *reg_idx)
642 if (addressing & WINED3D_SM4_ADDRESSING_RELATIVE)
644 struct wined3d_shader_src_param *rel_addr = get_src_param(priv);
646 if (!(reg_idx->rel_addr = rel_addr))
648 ERR("Failed to get src param for relative addressing.\n");
649 return FALSE;
652 if (addressing & WINED3D_SM4_ADDRESSING_OFFSET)
653 reg_idx->offset = *(*ptr)++;
654 else
655 reg_idx->offset = 0;
656 shader_sm4_read_src_param(priv, ptr, WINED3D_DATA_INT, rel_addr);
658 else
660 reg_idx->rel_addr = NULL;
661 reg_idx->offset = *(*ptr)++;
664 return TRUE;
667 static BOOL shader_sm4_read_param(struct wined3d_sm4_data *priv, const DWORD **ptr,
668 enum wined3d_data_type data_type, struct wined3d_shader_register *param,
669 enum wined3d_shader_src_modifier *modifier)
671 enum wined3d_sm4_register_type register_type;
672 DWORD token = *(*ptr)++;
673 DWORD order;
675 register_type = (token & WINED3D_SM4_REGISTER_TYPE_MASK) >> WINED3D_SM4_REGISTER_TYPE_SHIFT;
676 if (register_type >= sizeof(register_type_table) / sizeof(*register_type_table))
678 FIXME("Unhandled register type %#x.\n", register_type);
679 param->type = WINED3DSPR_TEMP;
681 else
683 param->type = register_type_table[register_type];
685 param->data_type = data_type;
687 if (token & WINED3D_SM4_REGISTER_MODIFIER)
689 DWORD m = *(*ptr)++;
691 switch (m)
693 case 0x41:
694 *modifier = WINED3DSPSM_NEG;
695 break;
697 case 0x81:
698 *modifier = WINED3DSPSM_ABS;
699 break;
701 case 0xc1:
702 *modifier = WINED3DSPSM_ABSNEG;
703 break;
705 default:
706 FIXME("Skipping modifier 0x%08x.\n", m);
707 *modifier = WINED3DSPSM_NONE;
708 break;
711 else
713 *modifier = WINED3DSPSM_NONE;
716 order = (token & WINED3D_SM4_REGISTER_ORDER_MASK) >> WINED3D_SM4_REGISTER_ORDER_SHIFT;
718 if (order < 1)
719 param->idx[0].offset = ~0U;
720 else
722 DWORD addressing = (token & WINED3D_SM4_ADDRESSING_MASK0) >> WINED3D_SM4_ADDRESSING_SHIFT0;
723 if (!(shader_sm4_read_reg_idx(priv, ptr, addressing, &param->idx[0])))
725 ERR("Failed to read register index.\n");
726 return FALSE;
730 if (order < 2)
731 param->idx[1].offset = ~0U;
732 else
734 DWORD addressing = (token & WINED3D_SM4_ADDRESSING_MASK1) >> WINED3D_SM4_ADDRESSING_SHIFT1;
735 if (!(shader_sm4_read_reg_idx(priv, ptr, addressing, &param->idx[1])))
737 ERR("Failed to read register index.\n");
738 return FALSE;
742 if (order > 2)
743 FIXME("Unhandled order %u.\n", order);
745 if (register_type == WINED3D_SM4_RT_IMMCONST)
747 enum wined3d_sm4_immconst_type immconst_type =
748 (token & WINED3D_SM4_IMMCONST_TYPE_MASK) >> WINED3D_SM4_IMMCONST_TYPE_SHIFT;
750 switch (immconst_type)
752 case WINED3D_SM4_IMMCONST_SCALAR:
753 param->immconst_type = WINED3D_IMMCONST_SCALAR;
754 memcpy(param->immconst_data, *ptr, 1 * sizeof(DWORD));
755 *ptr += 1;
756 break;
758 case WINED3D_SM4_IMMCONST_VEC4:
759 param->immconst_type = WINED3D_IMMCONST_VEC4;
760 memcpy(param->immconst_data, *ptr, 4 * sizeof(DWORD));
761 *ptr += 4;
762 break;
764 default:
765 FIXME("Unhandled immediate constant type %#x.\n", immconst_type);
766 break;
770 map_register(priv, param);
772 return TRUE;
775 static BOOL shader_sm4_read_src_param(struct wined3d_sm4_data *priv, const DWORD **ptr,
776 enum wined3d_data_type data_type, struct wined3d_shader_src_param *src_param)
778 DWORD token = **ptr;
780 if (!shader_sm4_read_param(priv, ptr, data_type, &src_param->reg, &src_param->modifiers))
782 ERR("Failed to read parameter.\n");
783 return FALSE;
786 if (src_param->reg.type == WINED3DSPR_IMMCONST)
788 src_param->swizzle = WINED3DSP_NOSWIZZLE;
790 else
792 enum wined3d_sm4_swizzle_type swizzle_type =
793 (token & WINED3D_SM4_SWIZZLE_TYPE_MASK) >> WINED3D_SM4_SWIZZLE_TYPE_SHIFT;
795 switch (swizzle_type)
797 case WINED3D_SM4_SWIZZLE_NONE:
798 src_param->swizzle = WINED3DSP_NOSWIZZLE;
799 break;
801 case WINED3D_SM4_SWIZZLE_SCALAR:
802 src_param->swizzle = (token & WINED3D_SM4_SWIZZLE_MASK) >> WINED3D_SM4_SWIZZLE_SHIFT;
803 src_param->swizzle = (src_param->swizzle & 0x3) * 0x55;
804 break;
806 case WINED3D_SM4_SWIZZLE_VEC4:
807 src_param->swizzle = (token & WINED3D_SM4_SWIZZLE_MASK) >> WINED3D_SM4_SWIZZLE_SHIFT;
808 break;
810 default:
811 FIXME("Unhandled swizzle type %#x.\n", swizzle_type);
812 break;
816 return TRUE;
819 static BOOL shader_sm4_read_dst_param(struct wined3d_sm4_data *priv, const DWORD **ptr,
820 enum wined3d_data_type data_type, struct wined3d_shader_dst_param *dst_param)
822 enum wined3d_shader_src_modifier modifier;
823 DWORD token = **ptr;
825 if (!shader_sm4_read_param(priv, ptr, data_type, &dst_param->reg, &modifier))
827 ERR("Failed to read parameter.\n");
828 return FALSE;
831 if (modifier != WINED3DSPSM_NONE)
833 ERR("Invalid source modifier %#x on destination register.\n", modifier);
834 return FALSE;
837 dst_param->write_mask = (token & WINED3D_SM4_WRITEMASK_MASK) >> WINED3D_SM4_WRITEMASK_SHIFT;
838 dst_param->modifiers = 0;
839 dst_param->shift = 0;
841 return TRUE;
844 static void shader_sm4_read_instruction(void *data, const DWORD **ptr, struct wined3d_shader_instruction *ins)
846 const struct wined3d_sm4_opcode_info *opcode_info;
847 struct wined3d_sm4_data *priv = data;
848 DWORD opcode_token, opcode;
849 const DWORD *p;
850 UINT i, len;
852 list_move_head(&priv->src_free, &priv->src);
854 opcode_token = *(*ptr)++;
855 opcode = opcode_token & WINED3D_SM4_OPCODE_MASK;
857 len = ((opcode_token & WINED3D_SM4_INSTRUCTION_LENGTH_MASK) >> WINED3D_SM4_INSTRUCTION_LENGTH_SHIFT);
858 if (!len)
859 len = **ptr;
860 --len;
862 if (TRACE_ON(d3d_bytecode))
864 TRACE_(d3d_bytecode)("[ %08x ", opcode_token);
865 for (i = 0; i < len; ++i)
867 TRACE_(d3d_bytecode)("%08x ", (*ptr)[i]);
869 TRACE_(d3d_bytecode)("]\n");
872 if (!(opcode_info = get_opcode_info(opcode)))
874 FIXME("Unrecognized opcode %#x, opcode_token 0x%08x.\n", opcode, opcode_token);
875 ins->handler_idx = WINED3DSIH_TABLE_SIZE;
876 *ptr += len;
877 return;
880 ins->handler_idx = opcode_info->handler_idx;
881 ins->flags = 0;
882 ins->coissue = 0;
883 ins->predicate = NULL;
884 ins->dst_count = strlen(opcode_info->dst_info);
885 ins->dst = priv->dst_param;
886 ins->src_count = strlen(opcode_info->src_info);
887 ins->src = priv->src_param;
889 p = *ptr;
890 *ptr += len;
892 if (opcode_token & WINED3D_SM4_INSTRUCTION_MODIFIER)
894 DWORD modifier = *p++;
895 FIXME("Skipping modifier 0x%08x.\n", modifier);
898 if (opcode == WINED3D_SM4_OP_SHADER_DATA)
900 unsigned int icb_size;
901 enum wined3d_sm4_shader_data_type type;
903 type = (opcode_token & WINED3D_SM4_SHADER_DATA_TYPE_MASK) >> WINED3D_SM4_SHADER_DATA_TYPE_SHIFT;
904 if (type != WINED3D_SM4_SHADER_DATA_IMMEDIATE_CONSTANT_BUFFER)
906 FIXME("Unhandled shader data type %#x.\n", type);
907 ins->handler_idx = WINED3DSIH_TABLE_SIZE;
908 return;
911 ++p;
912 icb_size = len - 1;
913 if (icb_size % 4 || icb_size > MAX_IMMEDIATE_CONSTANT_BUFFER_SIZE)
915 FIXME("Unexpected immediate constant buffer size %u.\n", len);
916 ins->handler_idx = WINED3DSIH_TABLE_SIZE;
917 return;
920 priv->icb.element_count = len;
921 memcpy(priv->icb.data, p, sizeof(*p) * icb_size);
922 ins->declaration.icb = &priv->icb;
924 else if (opcode == WINED3D_SM4_OP_DCL_RESOURCE)
926 enum wined3d_sm4_resource_type resource_type;
927 enum wined3d_sm4_data_type data_type;
928 DWORD components;
930 resource_type = (opcode_token & WINED3D_SM4_RESOURCE_TYPE_MASK) >> WINED3D_SM4_RESOURCE_TYPE_SHIFT;
931 if (!resource_type || (resource_type >= ARRAY_SIZE(resource_type_table)))
933 FIXME("Unhandled resource type %#x.\n", resource_type);
934 ins->declaration.semantic.resource_type = WINED3D_SHADER_RESOURCE_NONE;
936 else
938 ins->declaration.semantic.resource_type = resource_type_table[resource_type];
940 shader_sm4_read_dst_param(priv, &p, WINED3D_DATA_RESOURCE, &ins->declaration.semantic.reg);
942 components = *p++;
943 if ((components & 0xfff0) != (components & 0xf) * 0x1110)
944 FIXME("Components (%#x) have different data types.\n", components);
945 data_type = components & 0xf;
947 if (!data_type || (data_type >= ARRAY_SIZE(data_type_table)))
949 FIXME("Unhandled data type %#x.\n", data_type);
950 ins->declaration.semantic.resource_data_type = WINED3D_DATA_FLOAT;
952 else
954 ins->declaration.semantic.resource_data_type = data_type_table[data_type];
957 else if (opcode == WINED3D_SM4_OP_DCL_CONSTANT_BUFFER)
959 shader_sm4_read_src_param(priv, &p, WINED3D_DATA_FLOAT, &ins->declaration.src);
960 if (opcode_token & WINED3D_SM4_INDEX_TYPE_MASK)
961 ins->flags |= WINED3DSI_INDEXED_DYNAMIC;
963 else if (opcode == WINED3D_SM4_OP_DCL_SAMPLER)
965 ins->flags = (opcode_token & WINED3D_SM4_SAMPLER_MODE_MASK) >> WINED3D_SM4_SAMPLER_MODE_SHIFT;
966 if (ins->flags & ~WINED3D_SM4_SAMPLER_COMPARISON)
967 FIXME("Unhandled sampler mode %#x.\n", ins->flags);
968 shader_sm4_read_dst_param(priv, &p, WINED3D_DATA_SAMPLER, &ins->declaration.dst);
970 else if (opcode == WINED3D_SM4_OP_DCL_OUTPUT_TOPOLOGY)
972 enum wined3d_sm4_output_primitive_type primitive_type;
974 primitive_type = (opcode_token & WINED3D_SM4_PRIMITIVE_TYPE_MASK) >> WINED3D_SM4_PRIMITIVE_TYPE_SHIFT;
975 if (primitive_type >= sizeof(output_primitive_type_table) / sizeof(*output_primitive_type_table))
977 FIXME("Unhandled output primitive type %#x.\n", primitive_type);
978 ins->declaration.primitive_type = WINED3D_PT_UNDEFINED;
980 else
982 ins->declaration.primitive_type = output_primitive_type_table[primitive_type];
985 else if (opcode == WINED3D_SM4_OP_DCL_INPUT_PRIMITIVE)
987 enum wined3d_sm4_input_primitive_type primitive_type;
989 primitive_type = (opcode_token & WINED3D_SM4_PRIMITIVE_TYPE_MASK) >> WINED3D_SM4_PRIMITIVE_TYPE_SHIFT;
990 if (primitive_type >= sizeof(input_primitive_type_table) / sizeof(*input_primitive_type_table))
992 FIXME("Unhandled input primitive type %#x.\n", primitive_type);
993 ins->declaration.primitive_type = WINED3D_PT_UNDEFINED;
995 else
997 ins->declaration.primitive_type = input_primitive_type_table[primitive_type];
1000 else if (opcode == WINED3D_SM4_OP_DCL_INPUT_PS)
1002 ins->flags = (opcode_token & WINED3D_SM4_INTERPOLATION_MODE_MASK) >> WINED3D_SM4_INTERPOLATION_MODE_SHIFT;
1003 shader_sm4_read_dst_param(priv, &p, WINED3D_DATA_FLOAT, &ins->declaration.dst);
1005 else if (opcode == WINED3D_SM4_OP_DCL_INPUT_PS_SGV
1006 || opcode == WINED3D_SM4_OP_DCL_INPUT_SGV
1007 || opcode == WINED3D_SM4_OP_DCL_INPUT_SIV
1008 || opcode == WINED3D_SM4_OP_DCL_OUTPUT_SIV)
1010 shader_sm4_read_dst_param(priv, &p, WINED3D_DATA_FLOAT, &ins->declaration.register_semantic.reg);
1011 ins->declaration.register_semantic.sysval_semantic = *p++;
1013 else if (opcode == WINED3D_SM4_OP_DCL_INPUT_PS_SIV)
1015 ins->flags = (opcode_token & WINED3D_SM4_INTERPOLATION_MODE_MASK) >> WINED3D_SM4_INTERPOLATION_MODE_SHIFT;
1016 shader_sm4_read_dst_param(priv, &p, WINED3D_DATA_FLOAT, &ins->declaration.register_semantic.reg);
1017 ins->declaration.register_semantic.sysval_semantic = *p++;
1019 else if (opcode == WINED3D_SM4_OP_DCL_INPUT
1020 || opcode == WINED3D_SM4_OP_DCL_OUTPUT)
1022 shader_sm4_read_dst_param(priv, &p, WINED3D_DATA_FLOAT, &ins->declaration.dst);
1024 else if (opcode == WINED3D_SM4_OP_DCL_VERTICES_OUT
1025 || opcode == WINED3D_SM4_OP_DCL_TEMPS)
1027 ins->declaration.count = *p++;
1029 else if (opcode == WINED3D_SM4_OP_DCL_GLOBAL_FLAGS)
1031 ins->flags = (opcode_token & WINED3D_SM4_GLOBAL_FLAGS_MASK) >> WINED3D_SM4_GLOBAL_FLAGS_SHIFT;
1033 else
1035 enum wined3d_shader_dst_modifier instruction_dst_modifier = WINED3DSPDM_NONE;
1037 ins->flags = (opcode_token & WINED3D_SM4_INSTRUCTION_FLAGS_MASK) >> WINED3D_SM4_INSTRUCTION_FLAGS_SHIFT;
1039 if (ins->flags & WINED3D_SM4_INSTRUCTION_FLAG_SATURATE)
1041 ins->flags &= ~WINED3D_SM4_INSTRUCTION_FLAG_SATURATE;
1042 instruction_dst_modifier = WINED3DSPDM_SATURATE;
1045 for (i = 0; i < ins->dst_count; ++i)
1047 if (!(shader_sm4_read_dst_param(priv, &p, map_data_type(opcode_info->dst_info[i]), &priv->dst_param[i])))
1049 ins->handler_idx = WINED3DSIH_TABLE_SIZE;
1050 return;
1052 priv->dst_param[i].modifiers |= instruction_dst_modifier;
1055 for (i = 0; i < ins->src_count; ++i)
1057 if (!(shader_sm4_read_src_param(priv, &p, map_data_type(opcode_info->src_info[i]), &priv->src_param[i])))
1059 ins->handler_idx = WINED3DSIH_TABLE_SIZE;
1060 return;
1066 static BOOL shader_sm4_is_end(void *data, const DWORD **ptr)
1068 struct wined3d_sm4_data *priv = data;
1069 return *ptr == priv->end;
1072 const struct wined3d_shader_frontend sm4_shader_frontend =
1074 shader_sm4_init,
1075 shader_sm4_free,
1076 shader_sm4_read_header,
1077 shader_sm4_read_instruction,
1078 shader_sm4_is_end,