d3d11: Use ARRAY_SIZE() macro.
[wine.git] / dlls / wined3d / shader_sm4.c
blob770ef18292076134fc76ac8637b1454d5471c754
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_MODIFIER_AOFFIMMI 0x1
30 #define WINED3D_SM4_AOFFIMMI_U_SHIFT 9
31 #define WINED3D_SM4_AOFFIMMI_U_MASK (0xfu << WINED3D_SM4_AOFFIMMI_U_SHIFT)
32 #define WINED3D_SM4_AOFFIMMI_V_SHIFT 13
33 #define WINED3D_SM4_AOFFIMMI_V_MASK (0xfu << WINED3D_SM4_AOFFIMMI_V_SHIFT)
34 #define WINED3D_SM4_AOFFIMMI_W_SHIFT 17
35 #define WINED3D_SM4_AOFFIMMI_W_MASK (0xfu << WINED3D_SM4_AOFFIMMI_W_SHIFT)
37 #define WINED3D_SM4_INSTRUCTION_LENGTH_SHIFT 24
38 #define WINED3D_SM4_INSTRUCTION_LENGTH_MASK (0x1fu << WINED3D_SM4_INSTRUCTION_LENGTH_SHIFT)
40 #define WINED3D_SM4_INSTRUCTION_FLAGS_SHIFT 11
41 #define WINED3D_SM4_INSTRUCTION_FLAGS_MASK (0x7u << WINED3D_SM4_INSTRUCTION_FLAGS_SHIFT)
43 #define WINED3D_SM4_RESOURCE_TYPE_SHIFT 11
44 #define WINED3D_SM4_RESOURCE_TYPE_MASK (0xfu << WINED3D_SM4_RESOURCE_TYPE_SHIFT)
46 #define WINED3D_SM4_PRIMITIVE_TYPE_SHIFT 11
47 #define WINED3D_SM4_PRIMITIVE_TYPE_MASK (0x7u << WINED3D_SM4_PRIMITIVE_TYPE_SHIFT)
49 #define WINED3D_SM4_INDEX_TYPE_SHIFT 11
50 #define WINED3D_SM4_INDEX_TYPE_MASK (0x1u << WINED3D_SM4_INDEX_TYPE_SHIFT)
52 #define WINED3D_SM4_SAMPLER_MODE_SHIFT 11
53 #define WINED3D_SM4_SAMPLER_MODE_MASK (0xfu << WINED3D_SM4_SAMPLER_MODE_SHIFT)
55 #define WINED3D_SM4_SHADER_DATA_TYPE_SHIFT 11
56 #define WINED3D_SM4_SHADER_DATA_TYPE_MASK (0xfu << WINED3D_SM4_SHADER_DATA_TYPE_SHIFT)
58 #define WINED3D_SM4_INTERPOLATION_MODE_SHIFT 11
59 #define WINED3D_SM4_INTERPOLATION_MODE_MASK (0xfu << WINED3D_SM4_INTERPOLATION_MODE_SHIFT)
61 #define WINED3D_SM4_GLOBAL_FLAGS_SHIFT 11
62 #define WINED3D_SM4_GLOBAL_FLAGS_MASK (0xffu << WINED3D_SM4_GLOBAL_FLAGS_SHIFT)
64 #define WINED3D_SM5_CONTROL_POINT_COUNT_SHIFT 11
65 #define WINED3D_SM5_CONTROL_POINT_COUNT_MASK (0xffu << WINED3D_SM5_CONTROL_POINT_COUNT_SHIFT)
67 #define WINED3D_SM5_FP_ARRAY_SIZE_SHIFT 16
68 #define WINED3D_SM5_FP_TABLE_COUNT_MASK 0xffffu
70 #define WINED3D_SM5_UAV_FLAGS_SHIFT 15
71 #define WINED3D_SM5_UAV_FLAGS_MASK (0x1ffu << WINED3D_SM5_UAV_FLAGS_SHIFT)
73 #define WINED3D_SM5_SYNC_FLAGS_SHIFT 11
74 #define WINED3D_SM5_SYNC_FLAGS_MASK (0xffu << WINED3D_SM5_SYNC_FLAGS_SHIFT)
76 #define WINED3D_SM5_TESSELLATOR_SHIFT 11
77 #define WINED3D_SM5_TESSELLATOR_MASK (0xfu << WINED3D_SM5_TESSELLATOR_SHIFT)
79 #define WINED3D_SM4_OPCODE_MASK 0xff
81 #define WINED3D_SM4_REGISTER_MODIFIER (0x1u << 31)
83 #define WINED3D_SM4_ADDRESSING_SHIFT1 25
84 #define WINED3D_SM4_ADDRESSING_MASK1 (0x3u << WINED3D_SM4_ADDRESSING_SHIFT1)
86 #define WINED3D_SM4_ADDRESSING_SHIFT0 22
87 #define WINED3D_SM4_ADDRESSING_MASK0 (0x3u << WINED3D_SM4_ADDRESSING_SHIFT0)
89 #define WINED3D_SM4_REGISTER_ORDER_SHIFT 20
90 #define WINED3D_SM4_REGISTER_ORDER_MASK (0x3u << WINED3D_SM4_REGISTER_ORDER_SHIFT)
92 #define WINED3D_SM4_REGISTER_TYPE_SHIFT 12
93 #define WINED3D_SM4_REGISTER_TYPE_MASK (0xffu << WINED3D_SM4_REGISTER_TYPE_SHIFT)
95 #define WINED3D_SM4_SWIZZLE_TYPE_SHIFT 2
96 #define WINED3D_SM4_SWIZZLE_TYPE_MASK (0x3u << WINED3D_SM4_SWIZZLE_TYPE_SHIFT)
98 #define WINED3D_SM4_IMMCONST_TYPE_SHIFT 0
99 #define WINED3D_SM4_IMMCONST_TYPE_MASK (0x3u << WINED3D_SM4_IMMCONST_TYPE_SHIFT)
101 #define WINED3D_SM4_WRITEMASK_SHIFT 4
102 #define WINED3D_SM4_WRITEMASK_MASK (0xfu << WINED3D_SM4_WRITEMASK_SHIFT)
104 #define WINED3D_SM4_SWIZZLE_SHIFT 4
105 #define WINED3D_SM4_SWIZZLE_MASK (0xffu << WINED3D_SM4_SWIZZLE_SHIFT)
107 #define WINED3D_SM4_VERSION_MAJOR(version) (((version) >> 4) & 0xf)
108 #define WINED3D_SM4_VERSION_MINOR(version) (((version) >> 0) & 0xf)
110 #define WINED3D_SM4_ADDRESSING_RELATIVE 0x2
111 #define WINED3D_SM4_ADDRESSING_OFFSET 0x1
113 #define WINED3D_SM4_INSTRUCTION_FLAG_SATURATE 0x4
115 #define WINED3D_SM4_CONDITIONAL_NZ (0x1u << 18)
117 enum wined3d_sm4_opcode
119 WINED3D_SM4_OP_ADD = 0x00,
120 WINED3D_SM4_OP_AND = 0x01,
121 WINED3D_SM4_OP_BREAK = 0x02,
122 WINED3D_SM4_OP_BREAKC = 0x03,
123 WINED3D_SM4_OP_CASE = 0x06,
124 WINED3D_SM4_OP_CONTINUE = 0x07,
125 WINED3D_SM4_OP_CUT = 0x09,
126 WINED3D_SM4_OP_DEFAULT = 0x0a,
127 WINED3D_SM4_OP_DERIV_RTX = 0x0b,
128 WINED3D_SM4_OP_DERIV_RTY = 0x0c,
129 WINED3D_SM4_OP_DISCARD = 0x0d,
130 WINED3D_SM4_OP_DIV = 0x0e,
131 WINED3D_SM4_OP_DP2 = 0x0f,
132 WINED3D_SM4_OP_DP3 = 0x10,
133 WINED3D_SM4_OP_DP4 = 0x11,
134 WINED3D_SM4_OP_ELSE = 0x12,
135 WINED3D_SM4_OP_EMIT = 0x13,
136 WINED3D_SM4_OP_ENDIF = 0x15,
137 WINED3D_SM4_OP_ENDLOOP = 0x16,
138 WINED3D_SM4_OP_ENDSWITCH = 0x17,
139 WINED3D_SM4_OP_EQ = 0x18,
140 WINED3D_SM4_OP_EXP = 0x19,
141 WINED3D_SM4_OP_FRC = 0x1a,
142 WINED3D_SM4_OP_FTOI = 0x1b,
143 WINED3D_SM4_OP_FTOU = 0x1c,
144 WINED3D_SM4_OP_GE = 0x1d,
145 WINED3D_SM4_OP_IADD = 0x1e,
146 WINED3D_SM4_OP_IF = 0x1f,
147 WINED3D_SM4_OP_IEQ = 0x20,
148 WINED3D_SM4_OP_IGE = 0x21,
149 WINED3D_SM4_OP_ILT = 0x22,
150 WINED3D_SM4_OP_IMAD = 0x23,
151 WINED3D_SM4_OP_IMAX = 0x24,
152 WINED3D_SM4_OP_IMIN = 0x25,
153 WINED3D_SM4_OP_IMUL = 0x26,
154 WINED3D_SM4_OP_INE = 0x27,
155 WINED3D_SM4_OP_INEG = 0x28,
156 WINED3D_SM4_OP_ISHL = 0x29,
157 WINED3D_SM4_OP_ISHR = 0x2a,
158 WINED3D_SM4_OP_ITOF = 0x2b,
159 WINED3D_SM4_OP_LABEL = 0x2c,
160 WINED3D_SM4_OP_LD = 0x2d,
161 WINED3D_SM4_OP_LD2DMS = 0x2e,
162 WINED3D_SM4_OP_LOG = 0x2f,
163 WINED3D_SM4_OP_LOOP = 0x30,
164 WINED3D_SM4_OP_LT = 0x31,
165 WINED3D_SM4_OP_MAD = 0x32,
166 WINED3D_SM4_OP_MIN = 0x33,
167 WINED3D_SM4_OP_MAX = 0x34,
168 WINED3D_SM4_OP_SHADER_DATA = 0x35,
169 WINED3D_SM4_OP_MOV = 0x36,
170 WINED3D_SM4_OP_MOVC = 0x37,
171 WINED3D_SM4_OP_MUL = 0x38,
172 WINED3D_SM4_OP_NE = 0x39,
173 WINED3D_SM4_OP_NOT = 0x3b,
174 WINED3D_SM4_OP_OR = 0x3c,
175 WINED3D_SM4_OP_RESINFO = 0x3d,
176 WINED3D_SM4_OP_RET = 0x3e,
177 WINED3D_SM4_OP_ROUND_NE = 0x40,
178 WINED3D_SM4_OP_ROUND_NI = 0x41,
179 WINED3D_SM4_OP_ROUND_PI = 0x42,
180 WINED3D_SM4_OP_ROUND_Z = 0x43,
181 WINED3D_SM4_OP_RSQ = 0x44,
182 WINED3D_SM4_OP_SAMPLE = 0x45,
183 WINED3D_SM4_OP_SAMPLE_C = 0x46,
184 WINED3D_SM4_OP_SAMPLE_C_LZ = 0x47,
185 WINED3D_SM4_OP_SAMPLE_LOD = 0x48,
186 WINED3D_SM4_OP_SAMPLE_GRAD = 0x49,
187 WINED3D_SM4_OP_SAMPLE_B = 0x4a,
188 WINED3D_SM4_OP_SQRT = 0x4b,
189 WINED3D_SM4_OP_SWITCH = 0x4c,
190 WINED3D_SM4_OP_SINCOS = 0x4d,
191 WINED3D_SM4_OP_UDIV = 0x4e,
192 WINED3D_SM4_OP_ULT = 0x4f,
193 WINED3D_SM4_OP_UGE = 0x50,
194 WINED3D_SM4_OP_UMUL = 0x51,
195 WINED3D_SM4_OP_UMAX = 0x53,
196 WINED3D_SM4_OP_UMIN = 0x54,
197 WINED3D_SM4_OP_USHR = 0x55,
198 WINED3D_SM4_OP_UTOF = 0x56,
199 WINED3D_SM4_OP_XOR = 0x57,
200 WINED3D_SM4_OP_DCL_RESOURCE = 0x58,
201 WINED3D_SM4_OP_DCL_CONSTANT_BUFFER = 0x59,
202 WINED3D_SM4_OP_DCL_SAMPLER = 0x5a,
203 WINED3D_SM4_OP_DCL_INDEX_RANGE = 0x5b,
204 WINED3D_SM4_OP_DCL_OUTPUT_TOPOLOGY = 0x5c,
205 WINED3D_SM4_OP_DCL_INPUT_PRIMITIVE = 0x5d,
206 WINED3D_SM4_OP_DCL_VERTICES_OUT = 0x5e,
207 WINED3D_SM4_OP_DCL_INPUT = 0x5f,
208 WINED3D_SM4_OP_DCL_INPUT_SGV = 0x60,
209 WINED3D_SM4_OP_DCL_INPUT_SIV = 0x61,
210 WINED3D_SM4_OP_DCL_INPUT_PS = 0x62,
211 WINED3D_SM4_OP_DCL_INPUT_PS_SGV = 0x63,
212 WINED3D_SM4_OP_DCL_INPUT_PS_SIV = 0x64,
213 WINED3D_SM4_OP_DCL_OUTPUT = 0x65,
214 WINED3D_SM4_OP_DCL_OUTPUT_SIV = 0x67,
215 WINED3D_SM4_OP_DCL_TEMPS = 0x68,
216 WINED3D_SM4_OP_DCL_INDEXABLE_TEMP = 0x69,
217 WINED3D_SM4_OP_DCL_GLOBAL_FLAGS = 0x6a,
218 WINED3D_SM4_OP_LOD = 0x6c,
219 WINED3D_SM4_OP_GATHER4 = 0x6d,
220 WINED3D_SM4_OP_SAMPLE_POS = 0x6e,
221 WINED3D_SM4_OP_SAMPLE_INFO = 0x6f,
222 WINED3D_SM5_OP_HS_DECLS = 0x71,
223 WINED3D_SM5_OP_HS_CONTROL_POINT_PHASE = 0x72,
224 WINED3D_SM5_OP_HS_FORK_PHASE = 0x73,
225 WINED3D_SM5_OP_HS_JOIN_PHASE = 0x74,
226 WINED3D_SM5_OP_EMIT_STREAM = 0x75,
227 WINED3D_SM5_OP_CUT_STREAM = 0x76,
228 WINED3D_SM5_OP_FCALL = 0x78,
229 WINED3D_SM5_OP_BUFINFO = 0x79,
230 WINED3D_SM5_OP_DERIV_RTX_COARSE = 0x7a,
231 WINED3D_SM5_OP_DERIV_RTX_FINE = 0x7b,
232 WINED3D_SM5_OP_DERIV_RTY_COARSE = 0x7c,
233 WINED3D_SM5_OP_DERIV_RTY_FINE = 0x7d,
234 WINED3D_SM5_OP_GATHER4_C = 0x7e,
235 WINED3D_SM5_OP_RCP = 0x81,
236 WINED3D_SM5_OP_F32TOF16 = 0x82,
237 WINED3D_SM5_OP_F16TOF32 = 0x83,
238 WINED3D_SM5_OP_COUNTBITS = 0x86,
239 WINED3D_SM5_OP_FIRSTBIT_HI = 0x87,
240 WINED3D_SM5_OP_FIRSTBIT_LO = 0x88,
241 WINED3D_SM5_OP_FIRSTBIT_SHI = 0x89,
242 WINED3D_SM5_OP_UBFE = 0x8a,
243 WINED3D_SM5_OP_BFI = 0x8c,
244 WINED3D_SM5_OP_BFREV = 0x8d,
245 WINED3D_SM5_OP_SWAPC = 0x8e,
246 WINED3D_SM5_OP_DCL_STREAM = 0x8f,
247 WINED3D_SM5_OP_DCL_FUNCTION_BODY = 0x90,
248 WINED3D_SM5_OP_DCL_FUNCTION_TABLE = 0x91,
249 WINED3D_SM5_OP_DCL_INTERFACE = 0x92,
250 WINED3D_SM5_OP_DCL_INPUT_CONTROL_POINT_COUNT = 0x93,
251 WINED3D_SM5_OP_DCL_OUTPUT_CONTROL_POINT_COUNT = 0x94,
252 WINED3D_SM5_OP_DCL_TESSELLATOR_DOMAIN = 0x95,
253 WINED3D_SM5_OP_DCL_TESSELLATOR_PARTITIONING = 0x96,
254 WINED3D_SM5_OP_DCL_TESSELLATOR_OUTPUT_PRIMITIVE = 0x97,
255 WINED3D_SM5_OP_DCL_HS_MAX_TESSFACTOR = 0x98,
256 WINED3D_SM5_OP_DCL_HS_FORK_PHASE_INSTANCE_COUNT = 0x99,
257 WINED3D_SM5_OP_DCL_HS_JOIN_PHASE_INSTANCE_COUNT = 0x9a,
258 WINED3D_SM5_OP_DCL_THREAD_GROUP = 0x9b,
259 WINED3D_SM5_OP_DCL_UAV_TYPED = 0x9c,
260 WINED3D_SM5_OP_DCL_UAV_RAW = 0x9d,
261 WINED3D_SM5_OP_DCL_UAV_STRUCTURED = 0x9e,
262 WINED3D_SM5_OP_DCL_TGSM_RAW = 0x9f,
263 WINED3D_SM5_OP_DCL_TGSM_STRUCTURED = 0xa0,
264 WINED3D_SM5_OP_DCL_RESOURCE_RAW = 0xa1,
265 WINED3D_SM5_OP_DCL_RESOURCE_STRUCTURED = 0xa2,
266 WINED3D_SM5_OP_LD_UAV_TYPED = 0xa3,
267 WINED3D_SM5_OP_STORE_UAV_TYPED = 0xa4,
268 WINED3D_SM5_OP_LD_RAW = 0xa5,
269 WINED3D_SM5_OP_STORE_RAW = 0xa6,
270 WINED3D_SM5_OP_LD_STRUCTURED = 0xa7,
271 WINED3D_SM5_OP_STORE_STRUCTURED = 0xa8,
272 WINED3D_SM5_OP_ATOMIC_AND = 0xa9,
273 WINED3D_SM5_OP_ATOMIC_OR = 0xaa,
274 WINED3D_SM5_OP_ATOMIC_XOR = 0xab,
275 WINED3D_SM5_OP_ATOMIC_CMP_STORE = 0xac,
276 WINED3D_SM5_OP_ATOMIC_IADD = 0xad,
277 WINED3D_SM5_OP_ATOMIC_IMAX = 0xae,
278 WINED3D_SM5_OP_ATOMIC_IMIN = 0xaf,
279 WINED3D_SM5_OP_ATOMIC_UMAX = 0xb0,
280 WINED3D_SM5_OP_ATOMIC_UMIN = 0xb1,
281 WINED3D_SM5_OP_IMM_ATOMIC_ALLOC = 0xb2,
282 WINED3D_SM5_OP_IMM_ATOMIC_CONSUME = 0xb3,
283 WINED3D_SM5_OP_IMM_ATOMIC_IADD = 0xb4,
284 WINED3D_SM5_OP_IMM_ATOMIC_AND = 0xb5,
285 WINED3D_SM5_OP_IMM_ATOMIC_OR = 0xb6,
286 WINED3D_SM5_OP_IMM_ATOMIC_XOR = 0xb7,
287 WINED3D_SM5_OP_IMM_ATOMIC_EXCH = 0xb8,
288 WINED3D_SM5_OP_IMM_ATOMIC_CMP_EXCH = 0xb9,
289 WINED3D_SM5_OP_IMM_ATOMIC_IMAX = 0xba,
290 WINED3D_SM5_OP_IMM_ATOMIC_IMIN = 0xbb,
291 WINED3D_SM5_OP_IMM_ATOMIC_UMAX = 0xbc,
292 WINED3D_SM5_OP_IMM_ATOMIC_UMIN = 0xbd,
293 WINED3D_SM5_OP_SYNC = 0xbe,
296 enum wined3d_sm4_register_type
298 WINED3D_SM4_RT_TEMP = 0x00,
299 WINED3D_SM4_RT_INPUT = 0x01,
300 WINED3D_SM4_RT_OUTPUT = 0x02,
301 WINED3D_SM4_RT_INDEXABLE_TEMP = 0x03,
302 WINED3D_SM4_RT_IMMCONST = 0x04,
303 WINED3D_SM4_RT_SAMPLER = 0x06,
304 WINED3D_SM4_RT_RESOURCE = 0x07,
305 WINED3D_SM4_RT_CONSTBUFFER = 0x08,
306 WINED3D_SM4_RT_IMMCONSTBUFFER = 0x09,
307 WINED3D_SM4_RT_PRIMID = 0x0b,
308 WINED3D_SM4_RT_DEPTHOUT = 0x0c,
309 WINED3D_SM4_RT_NULL = 0x0d,
310 WINED3D_SM4_RT_OMASK = 0x0f,
311 WINED3D_SM5_RT_STREAM = 0x10,
312 WINED3D_SM5_RT_FUNCTION_BODY = 0x11,
313 WINED3D_SM5_RT_FUNCTION_POINTER = 0x13,
314 WINED3D_SM5_RT_OUTPUT_CONTROL_POINT_ID = 0x16,
315 WINED3D_SM5_RT_FORK_INSTANCE_ID = 0x17,
316 WINED3D_SM5_RT_JOIN_INSTANCE_ID = 0x18,
317 WINED3D_SM5_RT_INPUT_CONTROL_POINT = 0x19,
318 WINED3D_SM5_RT_OUTPUT_CONTROL_POINT = 0x1a,
319 WINED3D_SM5_RT_PATCH_CONSTANT_DATA = 0x1b,
320 WINED3D_SM5_RT_DOMAIN_LOCATION = 0x1c,
321 WINED3D_SM5_RT_UAV = 0x1e,
322 WINED3D_SM5_RT_SHARED_MEMORY = 0x1f,
323 WINED3D_SM5_RT_THREAD_ID = 0x20,
324 WINED3D_SM5_RT_THREAD_GROUP_ID = 0x21,
325 WINED3D_SM5_RT_LOCAL_THREAD_ID = 0x22,
326 WINED3D_SM5_RT_COVERAGE = 0x23,
327 WINED3D_SM5_RT_LOCAL_THREAD_INDEX = 0x24,
330 enum wined3d_sm4_output_primitive_type
332 WINED3D_SM4_OUTPUT_PT_POINTLIST = 0x1,
333 WINED3D_SM4_OUTPUT_PT_LINELIST = 0x3,
334 WINED3D_SM4_OUTPUT_PT_TRIANGLESTRIP = 0x5,
337 enum wined3d_sm4_input_primitive_type
339 WINED3D_SM4_INPUT_PT_POINT = 0x1,
340 WINED3D_SM4_INPUT_PT_LINE = 0x2,
341 WINED3D_SM4_INPUT_PT_TRIANGLE = 0x3,
342 WINED3D_SM4_INPUT_PT_LINEADJ = 0x6,
343 WINED3D_SM4_INPUT_PT_TRIANGLEADJ = 0x7,
346 enum wined3d_sm4_swizzle_type
348 WINED3D_SM4_SWIZZLE_NONE = 0x0,
349 WINED3D_SM4_SWIZZLE_VEC4 = 0x1,
350 WINED3D_SM4_SWIZZLE_SCALAR = 0x2,
353 enum wined3d_sm4_immconst_type
355 WINED3D_SM4_IMMCONST_SCALAR = 0x1,
356 WINED3D_SM4_IMMCONST_VEC4 = 0x2,
359 enum wined3d_sm4_resource_type
361 WINED3D_SM4_RESOURCE_BUFFER = 0x1,
362 WINED3D_SM4_RESOURCE_TEXTURE_1D = 0x2,
363 WINED3D_SM4_RESOURCE_TEXTURE_2D = 0x3,
364 WINED3D_SM4_RESOURCE_TEXTURE_2DMS = 0x4,
365 WINED3D_SM4_RESOURCE_TEXTURE_3D = 0x5,
366 WINED3D_SM4_RESOURCE_TEXTURE_CUBE = 0x6,
367 WINED3D_SM4_RESOURCE_TEXTURE_1DARRAY = 0x7,
368 WINED3D_SM4_RESOURCE_TEXTURE_2DARRAY = 0x8,
369 WINED3D_SM4_RESOURCE_TEXTURE_2DMSARRAY = 0x9,
370 WINED3D_SM4_RESOURCE_TEXTURE_CUBEARRAY = 0xa,
373 enum wined3d_sm4_data_type
375 WINED3D_SM4_DATA_UNORM = 0x1,
376 WINED3D_SM4_DATA_SNORM = 0x2,
377 WINED3D_SM4_DATA_INT = 0x3,
378 WINED3D_SM4_DATA_UINT = 0x4,
379 WINED3D_SM4_DATA_FLOAT = 0x5,
382 enum wined3d_sm4_sampler_mode
384 WINED3D_SM4_SAMPLER_DEFAULT = 0x0,
385 WINED3D_SM4_SAMPLER_COMPARISON = 0x1,
388 enum wined3d_sm4_shader_data_type
390 WINED3D_SM4_SHADER_DATA_IMMEDIATE_CONSTANT_BUFFER = 0x3,
391 WINED3D_SM4_SHADER_DATA_MESSAGE = 0x4,
394 struct wined3d_shader_src_param_entry
396 struct list entry;
397 struct wined3d_shader_src_param param;
400 struct wined3d_sm4_data
402 struct wined3d_shader_version shader_version;
403 const DWORD *start, *end;
405 unsigned int output_map[MAX_REG_OUTPUT];
407 struct wined3d_shader_src_param src_param[5];
408 struct wined3d_shader_dst_param dst_param[2];
409 struct list src_free;
410 struct list src;
411 struct wined3d_shader_immediate_constant_buffer icb;
414 struct wined3d_sm4_opcode_info
416 enum wined3d_sm4_opcode opcode;
417 enum WINED3D_SHADER_INSTRUCTION_HANDLER handler_idx;
418 const char *dst_info;
419 const char *src_info;
420 void (*read_opcode_func)(struct wined3d_shader_instruction *ins,
421 DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
422 struct wined3d_sm4_data *priv);
425 static const enum wined3d_primitive_type output_primitive_type_table[] =
427 /* UNKNOWN */ WINED3D_PT_UNDEFINED,
428 /* WINED3D_SM4_OUTPUT_PT_POINTLIST */ WINED3D_PT_POINTLIST,
429 /* UNKNOWN */ WINED3D_PT_UNDEFINED,
430 /* WINED3D_SM4_OUTPUT_PT_LINELIST */ WINED3D_PT_LINELIST,
431 /* UNKNOWN */ WINED3D_PT_UNDEFINED,
432 /* WINED3D_SM4_OUTPUT_PT_TRIANGLESTRIP */ WINED3D_PT_TRIANGLESTRIP,
435 static const enum wined3d_primitive_type input_primitive_type_table[] =
437 /* UNKNOWN */ WINED3D_PT_UNDEFINED,
438 /* WINED3D_SM4_INPUT_PT_POINT */ WINED3D_PT_POINTLIST,
439 /* WINED3D_SM4_INPUT_PT_LINE */ WINED3D_PT_LINELIST,
440 /* WINED3D_SM4_INPUT_PT_TRIANGLE */ WINED3D_PT_TRIANGLELIST,
441 /* UNKNOWN */ WINED3D_PT_UNDEFINED,
442 /* UNKNOWN */ WINED3D_PT_UNDEFINED,
443 /* WINED3D_SM4_INPUT_PT_LINEADJ */ WINED3D_PT_LINELIST_ADJ,
444 /* WINED3D_SM4_INPUT_PT_TRIANGLEADJ */ WINED3D_PT_TRIANGLELIST_ADJ,
447 static const enum wined3d_shader_resource_type resource_type_table[] =
449 /* 0 */ WINED3D_SHADER_RESOURCE_NONE,
450 /* WINED3D_SM4_RESOURCE_BUFFER */ WINED3D_SHADER_RESOURCE_BUFFER,
451 /* WINED3D_SM4_RESOURCE_TEXTURE_1D */ WINED3D_SHADER_RESOURCE_TEXTURE_1D,
452 /* WINED3D_SM4_RESOURCE_TEXTURE_2D */ WINED3D_SHADER_RESOURCE_TEXTURE_2D,
453 /* WINED3D_SM4_RESOURCE_TEXTURE_2DMS */ WINED3D_SHADER_RESOURCE_TEXTURE_2DMS,
454 /* WINED3D_SM4_RESOURCE_TEXTURE_3D */ WINED3D_SHADER_RESOURCE_TEXTURE_3D,
455 /* WINED3D_SM4_RESOURCE_TEXTURE_CUBE */ WINED3D_SHADER_RESOURCE_TEXTURE_CUBE,
456 /* WINED3D_SM4_RESOURCE_TEXTURE_1DARRAY */ WINED3D_SHADER_RESOURCE_TEXTURE_1DARRAY,
457 /* WINED3D_SM4_RESOURCE_TEXTURE_2DARRAY */ WINED3D_SHADER_RESOURCE_TEXTURE_2DARRAY,
458 /* WINED3D_SM4_RESOURCE_TEXTURE_2DMSARRAY */ WINED3D_SHADER_RESOURCE_TEXTURE_2DMSARRAY,
459 /* WINED3D_SM4_RESOURCE_TEXTURE_CUBEARRAY */ WINED3D_SHADER_RESOURCE_TEXTURE_CUBEARRAY,
462 static const enum wined3d_data_type data_type_table[] =
464 /* 0 */ WINED3D_DATA_FLOAT,
465 /* WINED3D_SM4_DATA_UNORM */ WINED3D_DATA_UNORM,
466 /* WINED3D_SM4_DATA_SNORM */ WINED3D_DATA_SNORM,
467 /* WINED3D_SM4_DATA_INT */ WINED3D_DATA_INT,
468 /* WINED3D_SM4_DATA_UINT */ WINED3D_DATA_UINT,
469 /* WINED3D_SM4_DATA_FLOAT */ WINED3D_DATA_FLOAT,
472 static BOOL shader_sm4_read_src_param(struct wined3d_sm4_data *priv, const DWORD **ptr,
473 enum wined3d_data_type data_type, struct wined3d_shader_src_param *src_param);
474 static BOOL shader_sm4_read_dst_param(struct wined3d_sm4_data *priv, const DWORD **ptr,
475 enum wined3d_data_type data_type, struct wined3d_shader_dst_param *dst_param);
477 static void shader_sm4_read_conditional_op(struct wined3d_shader_instruction *ins,
478 DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
479 struct wined3d_sm4_data *priv)
481 shader_sm4_read_src_param(priv, &tokens, WINED3D_DATA_UINT, &priv->src_param[0]);
482 ins->flags = (opcode_token & WINED3D_SM4_CONDITIONAL_NZ) ?
483 WINED3D_SHADER_CONDITIONAL_OP_NZ : WINED3D_SHADER_CONDITIONAL_OP_Z;
486 static void shader_sm4_read_shader_data(struct wined3d_shader_instruction *ins,
487 DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
488 struct wined3d_sm4_data *priv)
490 enum wined3d_sm4_shader_data_type type;
491 unsigned int icb_size;
493 type = (opcode_token & WINED3D_SM4_SHADER_DATA_TYPE_MASK) >> WINED3D_SM4_SHADER_DATA_TYPE_SHIFT;
494 if (type != WINED3D_SM4_SHADER_DATA_IMMEDIATE_CONSTANT_BUFFER)
496 FIXME("Unhandled shader data type %#x.\n", type);
497 ins->handler_idx = WINED3DSIH_TABLE_SIZE;
498 return;
501 ++tokens;
502 icb_size = token_count - 1;
503 if (icb_size % 4 || icb_size > MAX_IMMEDIATE_CONSTANT_BUFFER_SIZE)
505 FIXME("Unexpected immediate constant buffer size %u.\n", icb_size);
506 ins->handler_idx = WINED3DSIH_TABLE_SIZE;
507 return;
510 priv->icb.vec4_count = icb_size / 4;
511 memcpy(priv->icb.data, tokens, sizeof(*tokens) * icb_size);
512 ins->declaration.icb = &priv->icb;
515 static void shader_sm4_read_dcl_resource(struct wined3d_shader_instruction *ins,
516 DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
517 struct wined3d_sm4_data *priv)
519 enum wined3d_sm4_resource_type resource_type;
520 enum wined3d_sm4_data_type data_type;
521 enum wined3d_data_type reg_data_type;
522 DWORD components;
524 resource_type = (opcode_token & WINED3D_SM4_RESOURCE_TYPE_MASK) >> WINED3D_SM4_RESOURCE_TYPE_SHIFT;
525 if (!resource_type || (resource_type >= ARRAY_SIZE(resource_type_table)))
527 FIXME("Unhandled resource type %#x.\n", resource_type);
528 ins->declaration.semantic.resource_type = WINED3D_SHADER_RESOURCE_NONE;
530 else
532 ins->declaration.semantic.resource_type = resource_type_table[resource_type];
534 reg_data_type = opcode == WINED3D_SM4_OP_DCL_RESOURCE ? WINED3D_DATA_RESOURCE : WINED3D_DATA_UAV;
535 shader_sm4_read_dst_param(priv, &tokens, reg_data_type, &ins->declaration.semantic.reg);
537 components = *tokens++;
538 if ((components & 0xfff0) != (components & 0xf) * 0x1110)
539 FIXME("Components (%#x) have different data types.\n", components);
540 data_type = components & 0xf;
542 if (!data_type || (data_type >= ARRAY_SIZE(data_type_table)))
544 FIXME("Unhandled data type %#x.\n", data_type);
545 ins->declaration.semantic.resource_data_type = WINED3D_DATA_FLOAT;
547 else
549 ins->declaration.semantic.resource_data_type = data_type_table[data_type];
552 if (reg_data_type == WINED3D_DATA_UAV)
553 ins->flags = (opcode_token & WINED3D_SM5_UAV_FLAGS_MASK) >> WINED3D_SM5_UAV_FLAGS_SHIFT;
556 static void shader_sm4_read_dcl_constant_buffer(struct wined3d_shader_instruction *ins,
557 DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
558 struct wined3d_sm4_data *priv)
560 shader_sm4_read_src_param(priv, &tokens, WINED3D_DATA_FLOAT, &ins->declaration.src);
561 if (opcode_token & WINED3D_SM4_INDEX_TYPE_MASK)
562 ins->flags |= WINED3DSI_INDEXED_DYNAMIC;
565 static void shader_sm4_read_dcl_sampler(struct wined3d_shader_instruction *ins,
566 DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
567 struct wined3d_sm4_data *priv)
569 ins->flags = (opcode_token & WINED3D_SM4_SAMPLER_MODE_MASK) >> WINED3D_SM4_SAMPLER_MODE_SHIFT;
570 if (ins->flags & ~WINED3D_SM4_SAMPLER_COMPARISON)
571 FIXME("Unhandled sampler mode %#x.\n", ins->flags);
572 shader_sm4_read_dst_param(priv, &tokens, WINED3D_DATA_SAMPLER, &ins->declaration.dst);
575 static void shader_sm4_read_dcl_index_range(struct wined3d_shader_instruction *ins,
576 DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
577 struct wined3d_sm4_data *priv)
579 shader_sm4_read_dst_param(priv, &tokens, WINED3D_DATA_OPAQUE, &ins->declaration.index_range.first_register);
580 ins->declaration.index_range.last_register = *tokens;
583 static void shader_sm4_read_dcl_output_topology(struct wined3d_shader_instruction *ins,
584 DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
585 struct wined3d_sm4_data *priv)
587 enum wined3d_sm4_output_primitive_type primitive_type;
589 primitive_type = (opcode_token & WINED3D_SM4_PRIMITIVE_TYPE_MASK) >> WINED3D_SM4_PRIMITIVE_TYPE_SHIFT;
590 if (primitive_type >= sizeof(output_primitive_type_table) / sizeof(*output_primitive_type_table))
592 FIXME("Unhandled output primitive type %#x.\n", primitive_type);
593 ins->declaration.primitive_type = WINED3D_PT_UNDEFINED;
595 else
597 ins->declaration.primitive_type = output_primitive_type_table[primitive_type];
601 static void shader_sm4_read_dcl_input_primitive(struct wined3d_shader_instruction *ins,
602 DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
603 struct wined3d_sm4_data *priv)
605 enum wined3d_sm4_input_primitive_type primitive_type;
607 primitive_type = (opcode_token & WINED3D_SM4_PRIMITIVE_TYPE_MASK) >> WINED3D_SM4_PRIMITIVE_TYPE_SHIFT;
608 if (primitive_type >= sizeof(input_primitive_type_table) / sizeof(*input_primitive_type_table))
610 FIXME("Unhandled input primitive type %#x.\n", primitive_type);
611 ins->declaration.primitive_type = WINED3D_PT_UNDEFINED;
613 else
615 ins->declaration.primitive_type = input_primitive_type_table[primitive_type];
619 static void shader_sm4_read_declaration_count(struct wined3d_shader_instruction *ins,
620 DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
621 struct wined3d_sm4_data *priv)
623 ins->declaration.count = *tokens;
626 static void shader_sm4_read_declaration_dst(struct wined3d_shader_instruction *ins,
627 DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
628 struct wined3d_sm4_data *priv)
630 shader_sm4_read_dst_param(priv, &tokens, WINED3D_DATA_FLOAT, &ins->declaration.dst);
633 static void shader_sm4_read_declaration_register_semantic(struct wined3d_shader_instruction *ins,
634 DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
635 struct wined3d_sm4_data *priv)
637 shader_sm4_read_dst_param(priv, &tokens, WINED3D_DATA_FLOAT, &ins->declaration.register_semantic.reg);
638 ins->declaration.register_semantic.sysval_semantic = *tokens;
641 static void shader_sm4_read_dcl_input_ps(struct wined3d_shader_instruction *ins,
642 DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
643 struct wined3d_sm4_data *priv)
645 ins->flags = (opcode_token & WINED3D_SM4_INTERPOLATION_MODE_MASK) >> WINED3D_SM4_INTERPOLATION_MODE_SHIFT;
646 shader_sm4_read_dst_param(priv, &tokens, WINED3D_DATA_FLOAT, &ins->declaration.dst);
649 static void shader_sm4_read_dcl_input_ps_siv(struct wined3d_shader_instruction *ins,
650 DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
651 struct wined3d_sm4_data *priv)
653 ins->flags = (opcode_token & WINED3D_SM4_INTERPOLATION_MODE_MASK) >> WINED3D_SM4_INTERPOLATION_MODE_SHIFT;
654 shader_sm4_read_dst_param(priv, &tokens, WINED3D_DATA_FLOAT, &ins->declaration.register_semantic.reg);
655 ins->declaration.register_semantic.sysval_semantic = *tokens;
658 static void shader_sm4_read_dcl_indexable_temp(struct wined3d_shader_instruction *ins,
659 DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
660 struct wined3d_sm4_data *priv)
662 ins->declaration.indexable_temp.register_idx = *tokens++;
663 ins->declaration.indexable_temp.register_size = *tokens++;
664 ins->declaration.indexable_temp.component_count = *tokens;
667 static void shader_sm4_read_dcl_global_flags(struct wined3d_shader_instruction *ins,
668 DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
669 struct wined3d_sm4_data *priv)
671 ins->flags = (opcode_token & WINED3D_SM4_GLOBAL_FLAGS_MASK) >> WINED3D_SM4_GLOBAL_FLAGS_SHIFT;
674 static void shader_sm5_read_fcall(struct wined3d_shader_instruction *ins,
675 DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
676 struct wined3d_sm4_data *priv)
678 priv->src_param[0].reg.u.fp_body_idx = *tokens++;
679 shader_sm4_read_src_param(priv, &tokens, WINED3D_DATA_OPAQUE, &priv->src_param[0]);
682 static void shader_sm5_read_dcl_function_body(struct wined3d_shader_instruction *ins,
683 DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
684 struct wined3d_sm4_data *priv)
686 ins->declaration.index = *tokens;
689 static void shader_sm5_read_dcl_function_table(struct wined3d_shader_instruction *ins,
690 DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
691 struct wined3d_sm4_data *priv)
693 ins->declaration.index = *tokens++;
694 FIXME("Ignoring set of function bodies (count %u).\n", *tokens);
697 static void shader_sm5_read_dcl_interface(struct wined3d_shader_instruction *ins,
698 DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
699 struct wined3d_sm4_data *priv)
701 ins->declaration.fp.index = *tokens++;
702 ins->declaration.fp.body_count = *tokens++;
703 ins->declaration.fp.array_size = *tokens >> WINED3D_SM5_FP_ARRAY_SIZE_SHIFT;
704 ins->declaration.fp.table_count = *tokens++ & WINED3D_SM5_FP_TABLE_COUNT_MASK;
705 FIXME("Ignoring set of function tables (count %u).\n", ins->declaration.fp.table_count);
708 static void shader_sm5_read_control_point_count(struct wined3d_shader_instruction *ins,
709 DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
710 struct wined3d_sm4_data *priv)
712 ins->declaration.count = (opcode_token & WINED3D_SM5_CONTROL_POINT_COUNT_MASK)
713 >> WINED3D_SM5_CONTROL_POINT_COUNT_SHIFT;
716 static void shader_sm5_read_dcl_tessellator_domain(struct wined3d_shader_instruction *ins,
717 DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
718 struct wined3d_sm4_data *priv)
720 ins->declaration.tessellator_domain = (opcode_token & WINED3D_SM5_TESSELLATOR_MASK)
721 >> WINED3D_SM5_TESSELLATOR_SHIFT;
724 static void shader_sm5_read_dcl_tessellator_partitioning(struct wined3d_shader_instruction *ins,
725 DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
726 struct wined3d_sm4_data *priv)
728 ins->declaration.tessellator_partitioning = (opcode_token & WINED3D_SM5_TESSELLATOR_MASK)
729 >> WINED3D_SM5_TESSELLATOR_SHIFT;
732 static void shader_sm5_read_dcl_tessellator_output_primitive(struct wined3d_shader_instruction *ins,
733 DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
734 struct wined3d_sm4_data *priv)
736 ins->declaration.tessellator_output_primitive = (opcode_token & WINED3D_SM5_TESSELLATOR_MASK)
737 >> WINED3D_SM5_TESSELLATOR_SHIFT;
740 static void shader_sm5_read_dcl_hs_max_tessfactor(struct wined3d_shader_instruction *ins,
741 DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
742 struct wined3d_sm4_data *priv)
744 ins->declaration.max_tessellation_factor = *(float *)tokens;
747 static void shader_sm5_read_dcl_thread_group(struct wined3d_shader_instruction *ins,
748 DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
749 struct wined3d_sm4_data *priv)
751 ins->declaration.thread_group_size.x = *tokens++;
752 ins->declaration.thread_group_size.y = *tokens++;
753 ins->declaration.thread_group_size.z = *tokens++;
756 static void shader_sm5_read_dcl_uav_raw(struct wined3d_shader_instruction *ins,
757 DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
758 struct wined3d_sm4_data *priv)
760 shader_sm4_read_dst_param(priv, &tokens, WINED3D_DATA_UAV, &ins->declaration.dst);
761 ins->flags = (opcode_token & WINED3D_SM5_UAV_FLAGS_MASK) >> WINED3D_SM5_UAV_FLAGS_SHIFT;
764 static void shader_sm5_read_dcl_uav_structured(struct wined3d_shader_instruction *ins,
765 DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
766 struct wined3d_sm4_data *priv)
768 shader_sm4_read_dst_param(priv, &tokens, WINED3D_DATA_UAV, &ins->declaration.structured_resource.reg);
769 ins->flags = (opcode_token & WINED3D_SM5_UAV_FLAGS_MASK) >> WINED3D_SM5_UAV_FLAGS_SHIFT;
770 ins->declaration.structured_resource.byte_stride = *tokens;
771 if (ins->declaration.structured_resource.byte_stride % 4)
772 FIXME("Byte stride %u is not multiple of 4.\n", ins->declaration.structured_resource.byte_stride);
775 static void shader_sm5_read_dcl_tgsm_raw(struct wined3d_shader_instruction *ins,
776 DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
777 struct wined3d_sm4_data *priv)
779 shader_sm4_read_dst_param(priv, &tokens, WINED3D_DATA_FLOAT, &ins->declaration.tgsm_raw.reg);
780 ins->declaration.tgsm_raw.byte_count = *tokens;
781 if (ins->declaration.tgsm_raw.byte_count % 4)
782 FIXME("Byte count %u is not multiple of 4.\n", ins->declaration.tgsm_raw.byte_count);
785 static void shader_sm5_read_dcl_tgsm_structured(struct wined3d_shader_instruction *ins,
786 DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
787 struct wined3d_sm4_data *priv)
789 shader_sm4_read_dst_param(priv, &tokens, WINED3D_DATA_FLOAT, &ins->declaration.tgsm_structured.reg);
790 ins->declaration.tgsm_structured.byte_stride = *tokens++;
791 ins->declaration.tgsm_structured.structure_count = *tokens;
792 if (ins->declaration.tgsm_structured.byte_stride % 4)
793 FIXME("Byte stride %u is not multiple of 4.\n", ins->declaration.tgsm_structured.byte_stride);
796 static void shader_sm5_read_dcl_resource_structured(struct wined3d_shader_instruction *ins,
797 DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
798 struct wined3d_sm4_data *priv)
800 shader_sm4_read_dst_param(priv, &tokens, WINED3D_DATA_RESOURCE, &ins->declaration.structured_resource.reg);
801 ins->declaration.structured_resource.byte_stride = *tokens;
802 if (ins->declaration.structured_resource.byte_stride % 4)
803 FIXME("Byte stride %u is not multiple of 4.\n", ins->declaration.structured_resource.byte_stride);
806 static void shader_sm5_read_dcl_resource_raw(struct wined3d_shader_instruction *ins,
807 DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
808 struct wined3d_sm4_data *priv)
810 shader_sm4_read_dst_param(priv, &tokens, WINED3D_DATA_RESOURCE, &ins->declaration.dst);
813 static void shader_sm5_read_sync(struct wined3d_shader_instruction *ins,
814 DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
815 struct wined3d_sm4_data *priv)
817 ins->flags = (opcode_token & WINED3D_SM5_SYNC_FLAGS_MASK) >> WINED3D_SM5_SYNC_FLAGS_SHIFT;
821 * f -> WINED3D_DATA_FLOAT
822 * i -> WINED3D_DATA_INT
823 * u -> WINED3D_DATA_UINT
824 * O -> WINED3D_DATA_OPAQUE
825 * R -> WINED3D_DATA_RESOURCE
826 * S -> WINED3D_DATA_SAMPLER
827 * U -> WINED3D_DATA_UAV
829 static const struct wined3d_sm4_opcode_info opcode_table[] =
831 {WINED3D_SM4_OP_ADD, WINED3DSIH_ADD, "f", "ff"},
832 {WINED3D_SM4_OP_AND, WINED3DSIH_AND, "u", "uu"},
833 {WINED3D_SM4_OP_BREAK, WINED3DSIH_BREAK, "", ""},
834 {WINED3D_SM4_OP_BREAKC, WINED3DSIH_BREAKP, "", "u",
835 shader_sm4_read_conditional_op},
836 {WINED3D_SM4_OP_CASE, WINED3DSIH_CASE, "", "u"},
837 {WINED3D_SM4_OP_CONTINUE, WINED3DSIH_CONTINUE, "", ""},
838 {WINED3D_SM4_OP_CUT, WINED3DSIH_CUT, "", ""},
839 {WINED3D_SM4_OP_DEFAULT, WINED3DSIH_DEFAULT, "", ""},
840 {WINED3D_SM4_OP_DERIV_RTX, WINED3DSIH_DSX, "f", "f"},
841 {WINED3D_SM4_OP_DERIV_RTY, WINED3DSIH_DSY, "f", "f"},
842 {WINED3D_SM4_OP_DISCARD, WINED3DSIH_TEXKILL, "", "u"},
843 {WINED3D_SM4_OP_DIV, WINED3DSIH_DIV, "f", "ff"},
844 {WINED3D_SM4_OP_DP2, WINED3DSIH_DP2, "f", "ff"},
845 {WINED3D_SM4_OP_DP3, WINED3DSIH_DP3, "f", "ff"},
846 {WINED3D_SM4_OP_DP4, WINED3DSIH_DP4, "f", "ff"},
847 {WINED3D_SM4_OP_ELSE, WINED3DSIH_ELSE, "", ""},
848 {WINED3D_SM4_OP_EMIT, WINED3DSIH_EMIT, "", ""},
849 {WINED3D_SM4_OP_ENDIF, WINED3DSIH_ENDIF, "", ""},
850 {WINED3D_SM4_OP_ENDLOOP, WINED3DSIH_ENDLOOP, "", ""},
851 {WINED3D_SM4_OP_ENDSWITCH, WINED3DSIH_ENDSWITCH, "", ""},
852 {WINED3D_SM4_OP_EQ, WINED3DSIH_EQ, "u", "ff"},
853 {WINED3D_SM4_OP_EXP, WINED3DSIH_EXP, "f", "f"},
854 {WINED3D_SM4_OP_FRC, WINED3DSIH_FRC, "f", "f"},
855 {WINED3D_SM4_OP_FTOI, WINED3DSIH_FTOI, "i", "f"},
856 {WINED3D_SM4_OP_FTOU, WINED3DSIH_FTOU, "u", "f"},
857 {WINED3D_SM4_OP_GE, WINED3DSIH_GE, "u", "ff"},
858 {WINED3D_SM4_OP_IADD, WINED3DSIH_IADD, "i", "ii"},
859 {WINED3D_SM4_OP_IF, WINED3DSIH_IF, "", "u",
860 shader_sm4_read_conditional_op},
861 {WINED3D_SM4_OP_IEQ, WINED3DSIH_IEQ, "u", "ii"},
862 {WINED3D_SM4_OP_IGE, WINED3DSIH_IGE, "u", "ii"},
863 {WINED3D_SM4_OP_ILT, WINED3DSIH_ILT, "u", "ii"},
864 {WINED3D_SM4_OP_IMAD, WINED3DSIH_IMAD, "i", "iii"},
865 {WINED3D_SM4_OP_IMAX, WINED3DSIH_IMAX, "i", "ii"},
866 {WINED3D_SM4_OP_IMIN, WINED3DSIH_IMIN, "i", "ii"},
867 {WINED3D_SM4_OP_IMUL, WINED3DSIH_IMUL, "ii", "ii"},
868 {WINED3D_SM4_OP_INE, WINED3DSIH_INE, "u", "ii"},
869 {WINED3D_SM4_OP_INEG, WINED3DSIH_INEG, "i", "i"},
870 {WINED3D_SM4_OP_ISHL, WINED3DSIH_ISHL, "i", "ii"},
871 {WINED3D_SM4_OP_ISHR, WINED3DSIH_ISHR, "i", "ii"},
872 {WINED3D_SM4_OP_ITOF, WINED3DSIH_ITOF, "f", "i"},
873 {WINED3D_SM4_OP_LABEL, WINED3DSIH_LABEL, "", "O"},
874 {WINED3D_SM4_OP_LD, WINED3DSIH_LD, "u", "iR"},
875 {WINED3D_SM4_OP_LD2DMS, WINED3DSIH_LD2DMS, "u", "iRi"},
876 {WINED3D_SM4_OP_LOG, WINED3DSIH_LOG, "f", "f"},
877 {WINED3D_SM4_OP_LOOP, WINED3DSIH_LOOP, "", ""},
878 {WINED3D_SM4_OP_LT, WINED3DSIH_LT, "u", "ff"},
879 {WINED3D_SM4_OP_MAD, WINED3DSIH_MAD, "f", "fff"},
880 {WINED3D_SM4_OP_MIN, WINED3DSIH_MIN, "f", "ff"},
881 {WINED3D_SM4_OP_MAX, WINED3DSIH_MAX, "f", "ff"},
882 {WINED3D_SM4_OP_SHADER_DATA, WINED3DSIH_DCL_IMMEDIATE_CONSTANT_BUFFER, "", "",
883 shader_sm4_read_shader_data},
884 {WINED3D_SM4_OP_MOV, WINED3DSIH_MOV, "f", "f"},
885 {WINED3D_SM4_OP_MOVC, WINED3DSIH_MOVC, "f", "uff"},
886 {WINED3D_SM4_OP_MUL, WINED3DSIH_MUL, "f", "ff"},
887 {WINED3D_SM4_OP_NE, WINED3DSIH_NE, "u", "ff"},
888 {WINED3D_SM4_OP_NOT, WINED3DSIH_NOT, "u", "u"},
889 {WINED3D_SM4_OP_OR, WINED3DSIH_OR, "u", "uu"},
890 {WINED3D_SM4_OP_RESINFO, WINED3DSIH_RESINFO, "f", "iR"},
891 {WINED3D_SM4_OP_RET, WINED3DSIH_RET, "", ""},
892 {WINED3D_SM4_OP_ROUND_NE, WINED3DSIH_ROUND_NE, "f", "f"},
893 {WINED3D_SM4_OP_ROUND_NI, WINED3DSIH_ROUND_NI, "f", "f"},
894 {WINED3D_SM4_OP_ROUND_PI, WINED3DSIH_ROUND_PI, "f", "f"},
895 {WINED3D_SM4_OP_ROUND_Z, WINED3DSIH_ROUND_Z, "f", "f"},
896 {WINED3D_SM4_OP_RSQ, WINED3DSIH_RSQ, "f", "f"},
897 {WINED3D_SM4_OP_SAMPLE, WINED3DSIH_SAMPLE, "u", "fRS"},
898 {WINED3D_SM4_OP_SAMPLE_C, WINED3DSIH_SAMPLE_C, "f", "fRSf"},
899 {WINED3D_SM4_OP_SAMPLE_C_LZ, WINED3DSIH_SAMPLE_C_LZ, "f", "fRSf"},
900 {WINED3D_SM4_OP_SAMPLE_LOD, WINED3DSIH_SAMPLE_LOD, "u", "fRSf"},
901 {WINED3D_SM4_OP_SAMPLE_GRAD, WINED3DSIH_SAMPLE_GRAD, "u", "fRSff"},
902 {WINED3D_SM4_OP_SAMPLE_B, WINED3DSIH_SAMPLE_B, "u", "fRSf"},
903 {WINED3D_SM4_OP_SQRT, WINED3DSIH_SQRT, "f", "f"},
904 {WINED3D_SM4_OP_SWITCH, WINED3DSIH_SWITCH, "", "u"},
905 {WINED3D_SM4_OP_SINCOS, WINED3DSIH_SINCOS, "ff", "f"},
906 {WINED3D_SM4_OP_UDIV, WINED3DSIH_UDIV, "uu", "uu"},
907 {WINED3D_SM4_OP_ULT, WINED3DSIH_ULT, "u", "uu"},
908 {WINED3D_SM4_OP_UGE, WINED3DSIH_UGE, "u", "uu"},
909 {WINED3D_SM4_OP_UMUL, WINED3DSIH_UMUL, "uu", "uu"},
910 {WINED3D_SM4_OP_UMAX, WINED3DSIH_UMAX, "u", "uu"},
911 {WINED3D_SM4_OP_UMIN, WINED3DSIH_UMIN, "u", "uu"},
912 {WINED3D_SM4_OP_USHR, WINED3DSIH_USHR, "u", "uu"},
913 {WINED3D_SM4_OP_UTOF, WINED3DSIH_UTOF, "f", "u"},
914 {WINED3D_SM4_OP_XOR, WINED3DSIH_XOR, "u", "uu"},
915 {WINED3D_SM4_OP_DCL_RESOURCE, WINED3DSIH_DCL, "R", "",
916 shader_sm4_read_dcl_resource},
917 {WINED3D_SM4_OP_DCL_CONSTANT_BUFFER, WINED3DSIH_DCL_CONSTANT_BUFFER, "", "",
918 shader_sm4_read_dcl_constant_buffer},
919 {WINED3D_SM4_OP_DCL_SAMPLER, WINED3DSIH_DCL_SAMPLER, "", "",
920 shader_sm4_read_dcl_sampler},
921 {WINED3D_SM4_OP_DCL_INDEX_RANGE, WINED3DSIH_DCL_INDEX_RANGE, "", "",
922 shader_sm4_read_dcl_index_range},
923 {WINED3D_SM4_OP_DCL_OUTPUT_TOPOLOGY, WINED3DSIH_DCL_OUTPUT_TOPOLOGY, "", "",
924 shader_sm4_read_dcl_output_topology},
925 {WINED3D_SM4_OP_DCL_INPUT_PRIMITIVE, WINED3DSIH_DCL_INPUT_PRIMITIVE, "", "",
926 shader_sm4_read_dcl_input_primitive},
927 {WINED3D_SM4_OP_DCL_VERTICES_OUT, WINED3DSIH_DCL_VERTICES_OUT, "", "",
928 shader_sm4_read_declaration_count},
929 {WINED3D_SM4_OP_DCL_INPUT, WINED3DSIH_DCL_INPUT, "", "",
930 shader_sm4_read_declaration_dst},
931 {WINED3D_SM4_OP_DCL_INPUT_SGV, WINED3DSIH_DCL_INPUT_SGV, "", "",
932 shader_sm4_read_declaration_register_semantic},
933 {WINED3D_SM4_OP_DCL_INPUT_SIV, WINED3DSIH_DCL_INPUT_SIV, "", "",
934 shader_sm4_read_declaration_register_semantic},
935 {WINED3D_SM4_OP_DCL_INPUT_PS, WINED3DSIH_DCL_INPUT_PS, "", "",
936 shader_sm4_read_dcl_input_ps},
937 {WINED3D_SM4_OP_DCL_INPUT_PS_SGV, WINED3DSIH_DCL_INPUT_PS_SGV, "", "",
938 shader_sm4_read_declaration_register_semantic},
939 {WINED3D_SM4_OP_DCL_INPUT_PS_SIV, WINED3DSIH_DCL_INPUT_PS_SIV, "", "",
940 shader_sm4_read_dcl_input_ps_siv},
941 {WINED3D_SM4_OP_DCL_OUTPUT, WINED3DSIH_DCL_OUTPUT, "", "",
942 shader_sm4_read_declaration_dst},
943 {WINED3D_SM4_OP_DCL_OUTPUT_SIV, WINED3DSIH_DCL_OUTPUT_SIV, "", "",
944 shader_sm4_read_declaration_register_semantic},
945 {WINED3D_SM4_OP_DCL_TEMPS, WINED3DSIH_DCL_TEMPS, "", "",
946 shader_sm4_read_declaration_count},
947 {WINED3D_SM4_OP_DCL_INDEXABLE_TEMP, WINED3DSIH_DCL_INDEXABLE_TEMP, "", "",
948 shader_sm4_read_dcl_indexable_temp},
949 {WINED3D_SM4_OP_DCL_GLOBAL_FLAGS, WINED3DSIH_DCL_GLOBAL_FLAGS, "", "",
950 shader_sm4_read_dcl_global_flags},
951 {WINED3D_SM4_OP_LOD, WINED3DSIH_LOD, "f", "fRS"},
952 {WINED3D_SM4_OP_GATHER4, WINED3DSIH_GATHER4, "u", "fRS"},
953 {WINED3D_SM4_OP_SAMPLE_POS, WINED3DSIH_SAMPLE_POS, "f", "Ru"},
954 {WINED3D_SM4_OP_SAMPLE_INFO, WINED3DSIH_SAMPLE_INFO, "f", "R"},
955 {WINED3D_SM5_OP_HS_DECLS, WINED3DSIH_HS_DECLS, "", ""},
956 {WINED3D_SM5_OP_HS_CONTROL_POINT_PHASE, WINED3DSIH_HS_CONTROL_POINT_PHASE, "", ""},
957 {WINED3D_SM5_OP_HS_FORK_PHASE, WINED3DSIH_HS_FORK_PHASE, "", ""},
958 {WINED3D_SM5_OP_HS_JOIN_PHASE, WINED3DSIH_HS_JOIN_PHASE, "", ""},
959 {WINED3D_SM5_OP_EMIT_STREAM, WINED3DSIH_EMIT_STREAM, "", "f"},
960 {WINED3D_SM5_OP_CUT_STREAM, WINED3DSIH_CUT_STREAM, "", "f"},
961 {WINED3D_SM5_OP_FCALL, WINED3DSIH_FCALL, "", "O",
962 shader_sm5_read_fcall},
963 {WINED3D_SM5_OP_BUFINFO, WINED3DSIH_BUFINFO, "i", "U"},
964 {WINED3D_SM5_OP_DERIV_RTX_COARSE, WINED3DSIH_DSX_COARSE, "f", "f"},
965 {WINED3D_SM5_OP_DERIV_RTX_FINE, WINED3DSIH_DSX_FINE, "f", "f"},
966 {WINED3D_SM5_OP_DERIV_RTY_COARSE, WINED3DSIH_DSY_COARSE, "f", "f"},
967 {WINED3D_SM5_OP_DERIV_RTY_FINE, WINED3DSIH_DSY_FINE, "f", "f"},
968 {WINED3D_SM5_OP_GATHER4_C, WINED3DSIH_GATHER4_C, "f", "fRSf"},
969 {WINED3D_SM5_OP_RCP, WINED3DSIH_RCP, "f", "f"},
970 {WINED3D_SM5_OP_F32TOF16, WINED3DSIH_F32TOF16, "u", "f"},
971 {WINED3D_SM5_OP_F16TOF32, WINED3DSIH_F16TOF32, "f", "u"},
972 {WINED3D_SM5_OP_COUNTBITS, WINED3DSIH_COUNTBITS, "u", "u"},
973 {WINED3D_SM5_OP_FIRSTBIT_HI, WINED3DSIH_FIRSTBIT_HI, "u", "u"},
974 {WINED3D_SM5_OP_FIRSTBIT_LO, WINED3DSIH_FIRSTBIT_LO, "u", "u"},
975 {WINED3D_SM5_OP_FIRSTBIT_SHI, WINED3DSIH_FIRSTBIT_SHI, "u", "i"},
976 {WINED3D_SM5_OP_UBFE, WINED3DSIH_UBFE, "u", "iiu"},
977 {WINED3D_SM5_OP_BFI, WINED3DSIH_BFI, "u", "iiuu"},
978 {WINED3D_SM5_OP_BFREV, WINED3DSIH_BFREV, "u", "u"},
979 {WINED3D_SM5_OP_SWAPC, WINED3DSIH_SWAPC, "ff", "uff"},
980 {WINED3D_SM5_OP_DCL_STREAM, WINED3DSIH_DCL_STREAM, "", "O"},
981 {WINED3D_SM5_OP_DCL_FUNCTION_BODY, WINED3DSIH_DCL_FUNCTION_BODY, "", "",
982 shader_sm5_read_dcl_function_body},
983 {WINED3D_SM5_OP_DCL_FUNCTION_TABLE, WINED3DSIH_DCL_FUNCTION_TABLE, "", "",
984 shader_sm5_read_dcl_function_table},
985 {WINED3D_SM5_OP_DCL_INTERFACE, WINED3DSIH_DCL_INTERFACE, "", "",
986 shader_sm5_read_dcl_interface},
987 {WINED3D_SM5_OP_DCL_INPUT_CONTROL_POINT_COUNT, WINED3DSIH_DCL_INPUT_CONTROL_POINT_COUNT, "", "",
988 shader_sm5_read_control_point_count},
989 {WINED3D_SM5_OP_DCL_OUTPUT_CONTROL_POINT_COUNT, WINED3DSIH_DCL_OUTPUT_CONTROL_POINT_COUNT, "", "",
990 shader_sm5_read_control_point_count},
991 {WINED3D_SM5_OP_DCL_TESSELLATOR_DOMAIN, WINED3DSIH_DCL_TESSELLATOR_DOMAIN, "", "",
992 shader_sm5_read_dcl_tessellator_domain},
993 {WINED3D_SM5_OP_DCL_TESSELLATOR_PARTITIONING, WINED3DSIH_DCL_TESSELLATOR_PARTITIONING, "", "",
994 shader_sm5_read_dcl_tessellator_partitioning},
995 {WINED3D_SM5_OP_DCL_TESSELLATOR_OUTPUT_PRIMITIVE, WINED3DSIH_DCL_TESSELLATOR_OUTPUT_PRIMITIVE, "", "",
996 shader_sm5_read_dcl_tessellator_output_primitive},
997 {WINED3D_SM5_OP_DCL_HS_MAX_TESSFACTOR, WINED3DSIH_DCL_HS_MAX_TESSFACTOR, "", "",
998 shader_sm5_read_dcl_hs_max_tessfactor},
999 {WINED3D_SM5_OP_DCL_HS_FORK_PHASE_INSTANCE_COUNT, WINED3DSIH_DCL_HS_FORK_PHASE_INSTANCE_COUNT, "", "",
1000 shader_sm4_read_declaration_count},
1001 {WINED3D_SM5_OP_DCL_HS_JOIN_PHASE_INSTANCE_COUNT, WINED3DSIH_DCL_HS_JOIN_PHASE_INSTANCE_COUNT, "", "",
1002 shader_sm4_read_declaration_count},
1003 {WINED3D_SM5_OP_DCL_THREAD_GROUP, WINED3DSIH_DCL_THREAD_GROUP, "", "",
1004 shader_sm5_read_dcl_thread_group},
1005 {WINED3D_SM5_OP_DCL_UAV_TYPED, WINED3DSIH_DCL_UAV_TYPED, "", "",
1006 shader_sm4_read_dcl_resource},
1007 {WINED3D_SM5_OP_DCL_UAV_RAW, WINED3DSIH_DCL_UAV_RAW, "", "",
1008 shader_sm5_read_dcl_uav_raw},
1009 {WINED3D_SM5_OP_DCL_UAV_STRUCTURED, WINED3DSIH_DCL_UAV_STRUCTURED, "", "",
1010 shader_sm5_read_dcl_uav_structured},
1011 {WINED3D_SM5_OP_DCL_TGSM_RAW, WINED3DSIH_DCL_TGSM_RAW, "", "",
1012 shader_sm5_read_dcl_tgsm_raw},
1013 {WINED3D_SM5_OP_DCL_TGSM_STRUCTURED, WINED3DSIH_DCL_TGSM_STRUCTURED, "", "",
1014 shader_sm5_read_dcl_tgsm_structured},
1015 {WINED3D_SM5_OP_DCL_RESOURCE_RAW, WINED3DSIH_DCL_RESOURCE_RAW, "", "",
1016 shader_sm5_read_dcl_resource_raw},
1017 {WINED3D_SM5_OP_DCL_RESOURCE_STRUCTURED, WINED3DSIH_DCL_RESOURCE_STRUCTURED, "", "",
1018 shader_sm5_read_dcl_resource_structured},
1019 {WINED3D_SM5_OP_LD_UAV_TYPED, WINED3DSIH_LD_UAV_TYPED, "u", "iU"},
1020 {WINED3D_SM5_OP_STORE_UAV_TYPED, WINED3DSIH_STORE_UAV_TYPED, "U", "iu"},
1021 {WINED3D_SM5_OP_LD_RAW, WINED3DSIH_LD_RAW, "u", "iU"},
1022 {WINED3D_SM5_OP_STORE_RAW, WINED3DSIH_STORE_RAW, "U", "iu"},
1023 {WINED3D_SM5_OP_LD_STRUCTURED, WINED3DSIH_LD_STRUCTURED, "u", "iiR"},
1024 {WINED3D_SM5_OP_STORE_STRUCTURED, WINED3DSIH_STORE_STRUCTURED, "U", "iiu"},
1025 {WINED3D_SM5_OP_ATOMIC_AND, WINED3DSIH_ATOMIC_AND, "U", "iu"},
1026 {WINED3D_SM5_OP_ATOMIC_OR, WINED3DSIH_ATOMIC_OR, "U", "iu"},
1027 {WINED3D_SM5_OP_ATOMIC_XOR, WINED3DSIH_ATOMIC_XOR, "U", "iu"},
1028 {WINED3D_SM5_OP_ATOMIC_CMP_STORE, WINED3DSIH_ATOMIC_CMP_STORE, "U", "iuu"},
1029 {WINED3D_SM5_OP_ATOMIC_IADD, WINED3DSIH_ATOMIC_IADD, "U", "ii"},
1030 {WINED3D_SM5_OP_ATOMIC_IMAX, WINED3DSIH_ATOMIC_IMAX, "U", "ii"},
1031 {WINED3D_SM5_OP_ATOMIC_IMIN, WINED3DSIH_ATOMIC_IMIN, "U", "ii"},
1032 {WINED3D_SM5_OP_ATOMIC_UMAX, WINED3DSIH_ATOMIC_UMAX, "U", "iu"},
1033 {WINED3D_SM5_OP_ATOMIC_UMIN, WINED3DSIH_ATOMIC_UMIN, "U", "iu"},
1034 {WINED3D_SM5_OP_IMM_ATOMIC_ALLOC, WINED3DSIH_IMM_ATOMIC_ALLOC, "u", "U"},
1035 {WINED3D_SM5_OP_IMM_ATOMIC_CONSUME, WINED3DSIH_IMM_ATOMIC_CONSUME, "u", "U"},
1036 {WINED3D_SM5_OP_IMM_ATOMIC_IADD, WINED3DSIH_IMM_ATOMIC_IADD, "uU", "ii"},
1037 {WINED3D_SM5_OP_IMM_ATOMIC_AND, WINED3DSIH_IMM_ATOMIC_AND, "uU", "iu"},
1038 {WINED3D_SM5_OP_IMM_ATOMIC_OR, WINED3DSIH_IMM_ATOMIC_OR, "uU", "iu"},
1039 {WINED3D_SM5_OP_IMM_ATOMIC_XOR, WINED3DSIH_IMM_ATOMIC_XOR, "uU", "iu"},
1040 {WINED3D_SM5_OP_IMM_ATOMIC_EXCH, WINED3DSIH_IMM_ATOMIC_EXCH, "uU", "iu"},
1041 {WINED3D_SM5_OP_IMM_ATOMIC_CMP_EXCH, WINED3DSIH_IMM_ATOMIC_CMP_EXCH, "uU", "iuu"},
1042 {WINED3D_SM5_OP_IMM_ATOMIC_IMAX, WINED3DSIH_IMM_ATOMIC_IMAX, "iU", "ii"},
1043 {WINED3D_SM5_OP_IMM_ATOMIC_IMIN, WINED3DSIH_IMM_ATOMIC_IMIN, "iU", "ii"},
1044 {WINED3D_SM5_OP_IMM_ATOMIC_UMAX, WINED3DSIH_IMM_ATOMIC_UMAX, "uU", "iu"},
1045 {WINED3D_SM5_OP_IMM_ATOMIC_UMIN, WINED3DSIH_IMM_ATOMIC_UMIN, "uU", "iu"},
1046 {WINED3D_SM5_OP_SYNC, WINED3DSIH_SYNC, "", "",
1047 shader_sm5_read_sync},
1050 static const enum wined3d_shader_register_type register_type_table[] =
1052 /* WINED3D_SM4_RT_TEMP */ WINED3DSPR_TEMP,
1053 /* WINED3D_SM4_RT_INPUT */ WINED3DSPR_INPUT,
1054 /* WINED3D_SM4_RT_OUTPUT */ WINED3DSPR_OUTPUT,
1055 /* WINED3D_SM4_RT_INDEXABLE_TEMP */ WINED3DSPR_IDXTEMP,
1056 /* WINED3D_SM4_RT_IMMCONST */ WINED3DSPR_IMMCONST,
1057 /* UNKNOWN */ ~0u,
1058 /* WINED3D_SM4_RT_SAMPLER */ WINED3DSPR_SAMPLER,
1059 /* WINED3D_SM4_RT_RESOURCE */ WINED3DSPR_RESOURCE,
1060 /* WINED3D_SM4_RT_CONSTBUFFER */ WINED3DSPR_CONSTBUFFER,
1061 /* WINED3D_SM4_RT_IMMCONSTBUFFER */ WINED3DSPR_IMMCONSTBUFFER,
1062 /* UNKNOWN */ ~0u,
1063 /* WINED3D_SM4_RT_PRIMID */ WINED3DSPR_PRIMID,
1064 /* WINED3D_SM4_RT_DEPTHOUT */ WINED3DSPR_DEPTHOUT,
1065 /* WINED3D_SM4_RT_NULL */ WINED3DSPR_NULL,
1066 /* UNKNOWN */ ~0u,
1067 /* WINED3D_SM4_RT_OMASK */ WINED3DSPR_SAMPLEMASK,
1068 /* WINED3D_SM5_RT_STREAM */ WINED3DSPR_STREAM,
1069 /* WINED3D_SM5_RT_FUNCTION_BODY */ WINED3DSPR_FUNCTIONBODY,
1070 /* UNKNOWN */ ~0u,
1071 /* WINED3D_SM5_RT_FUNCTION_POINTER */ WINED3DSPR_FUNCTIONPOINTER,
1072 /* UNKNOWN */ ~0u,
1073 /* UNKNOWN */ ~0u,
1074 /* WINED3D_SM5_RT_OUTPUT_CONTROL_POINT_ID */ WINED3DSPR_OUTPOINTID,
1075 /* WINED3D_SM5_RT_FORK_INSTANCE_ID */ WINED3DSPR_FORKINSTID,
1076 /* WINED3D_SM5_RT_JOIN_INSTANCE_ID */ WINED3DSPR_JOININSTID,
1077 /* WINED3D_SM5_RT_INPUT_CONTROL_POINT */ WINED3DSPR_INCONTROLPOINT,
1078 /* WINED3D_SM5_RT_OUTPUT_CONTROL_POINT */ WINED3DSPR_OUTCONTROLPOINT,
1079 /* WINED3D_SM5_RT_PATCH_CONSTANT_DATA */ WINED3DSPR_PATCHCONST,
1080 /* WINED3D_SM5_RT_DOMAIN_LOCATION */ WINED3DSPR_TESSCOORD,
1081 /* UNKNOWN */ ~0u,
1082 /* WINED3D_SM5_RT_UAV */ WINED3DSPR_UAV,
1083 /* WINED3D_SM5_RT_SHARED_MEMORY */ WINED3DSPR_GROUPSHAREDMEM,
1084 /* WINED3D_SM5_RT_THREAD_ID */ WINED3DSPR_THREADID,
1085 /* WINED3D_SM5_RT_THREAD_GROUP_ID */ WINED3DSPR_THREADGROUPID,
1086 /* WINED3D_SM5_RT_LOCAL_THREAD_ID */ WINED3DSPR_LOCALTHREADID,
1087 /* WINED3D_SM5_RT_COVERAGE */ WINED3DSPR_COVERAGE,
1088 /* WINED3D_SM5_RT_LOCAL_THREAD_INDEX */ WINED3DSPR_LOCALTHREADINDEX,
1091 static const struct wined3d_sm4_opcode_info *get_opcode_info(enum wined3d_sm4_opcode opcode)
1093 unsigned int i;
1095 for (i = 0; i < sizeof(opcode_table) / sizeof(*opcode_table); ++i)
1097 if (opcode == opcode_table[i].opcode) return &opcode_table[i];
1100 return NULL;
1103 static void map_register(const struct wined3d_sm4_data *priv, struct wined3d_shader_register *reg)
1105 switch (priv->shader_version.type)
1107 case WINED3D_SHADER_TYPE_PIXEL:
1108 if (reg->type == WINED3DSPR_OUTPUT)
1110 unsigned int reg_idx = reg->idx[0].offset;
1112 if (reg_idx >= ARRAY_SIZE(priv->output_map))
1114 ERR("Invalid output index %u.\n", reg_idx);
1115 break;
1118 reg->type = WINED3DSPR_COLOROUT;
1119 reg->idx[0].offset = priv->output_map[reg_idx];
1121 break;
1123 default:
1124 break;
1128 static enum wined3d_data_type map_data_type(char t)
1130 switch (t)
1132 case 'f':
1133 return WINED3D_DATA_FLOAT;
1134 case 'i':
1135 return WINED3D_DATA_INT;
1136 case 'u':
1137 return WINED3D_DATA_UINT;
1138 case 'O':
1139 return WINED3D_DATA_OPAQUE;
1140 case 'R':
1141 return WINED3D_DATA_RESOURCE;
1142 case 'S':
1143 return WINED3D_DATA_SAMPLER;
1144 case 'U':
1145 return WINED3D_DATA_UAV;
1146 default:
1147 ERR("Invalid data type '%c'.\n", t);
1148 return WINED3D_DATA_FLOAT;
1152 static void *shader_sm4_init(const DWORD *byte_code, size_t byte_code_size,
1153 const struct wined3d_shader_signature *output_signature)
1155 DWORD version_token, token_count;
1156 struct wined3d_sm4_data *priv;
1157 unsigned int i;
1159 if (byte_code_size / sizeof(*byte_code) < 2)
1161 WARN("Invalid byte code size %lu.\n", (long)byte_code_size);
1162 return NULL;
1165 version_token = byte_code[0];
1166 TRACE("Version: 0x%08x.\n", version_token);
1167 token_count = byte_code[1];
1168 TRACE("Token count: %u.\n", token_count);
1170 if (token_count < 2 || byte_code_size / sizeof(*byte_code) < token_count)
1172 WARN("Invalid token count %u.\n", token_count);
1173 return NULL;
1176 if (!(priv = HeapAlloc(GetProcessHeap(), 0, sizeof(*priv))))
1178 ERR("Failed to allocate private data\n");
1179 return NULL;
1182 priv->start = &byte_code[2];
1183 priv->end = &byte_code[token_count];
1185 switch (version_token >> 16)
1187 case WINED3D_SM4_PS:
1188 priv->shader_version.type = WINED3D_SHADER_TYPE_PIXEL;
1189 break;
1191 case WINED3D_SM4_VS:
1192 priv->shader_version.type = WINED3D_SHADER_TYPE_VERTEX;
1193 break;
1195 case WINED3D_SM4_GS:
1196 priv->shader_version.type = WINED3D_SHADER_TYPE_GEOMETRY;
1197 break;
1199 case WINED3D_SM5_HS:
1200 priv->shader_version.type = WINED3D_SHADER_TYPE_HULL;
1201 break;
1203 case WINED3D_SM5_DS:
1204 priv->shader_version.type = WINED3D_SHADER_TYPE_DOMAIN;
1205 break;
1207 case WINED3D_SM5_CS:
1208 priv->shader_version.type = WINED3D_SHADER_TYPE_COMPUTE;
1209 break;
1211 default:
1212 FIXME("Unrecognised shader type %#x.\n", version_token >> 16);
1214 priv->shader_version.major = WINED3D_SM4_VERSION_MAJOR(version_token);
1215 priv->shader_version.minor = WINED3D_SM4_VERSION_MINOR(version_token);
1217 memset(priv->output_map, 0xff, sizeof(priv->output_map));
1218 for (i = 0; i < output_signature->element_count; ++i)
1220 struct wined3d_shader_signature_element *e = &output_signature->elements[i];
1222 if (e->register_idx >= ARRAY_SIZE(priv->output_map))
1224 WARN("Invalid output index %u.\n", e->register_idx);
1225 continue;
1228 priv->output_map[e->register_idx] = e->semantic_idx;
1231 list_init(&priv->src_free);
1232 list_init(&priv->src);
1234 return priv;
1237 static void shader_sm4_free(void *data)
1239 struct wined3d_shader_src_param_entry *e1, *e2;
1240 struct wined3d_sm4_data *priv = data;
1242 list_move_head(&priv->src_free, &priv->src);
1243 LIST_FOR_EACH_ENTRY_SAFE(e1, e2, &priv->src_free, struct wined3d_shader_src_param_entry, entry)
1245 HeapFree(GetProcessHeap(), 0, e1);
1247 HeapFree(GetProcessHeap(), 0, priv);
1250 static struct wined3d_shader_src_param *get_src_param(struct wined3d_sm4_data *priv)
1252 struct wined3d_shader_src_param_entry *e;
1253 struct list *elem;
1255 if (!list_empty(&priv->src_free))
1257 elem = list_head(&priv->src_free);
1258 list_remove(elem);
1260 else
1262 if (!(e = HeapAlloc(GetProcessHeap(), 0, sizeof(*e))))
1263 return NULL;
1264 elem = &e->entry;
1267 list_add_tail(&priv->src, elem);
1268 e = LIST_ENTRY(elem, struct wined3d_shader_src_param_entry, entry);
1269 return &e->param;
1272 static void shader_sm4_read_header(void *data, const DWORD **ptr, struct wined3d_shader_version *shader_version)
1274 struct wined3d_sm4_data *priv = data;
1276 *ptr = priv->start;
1277 *shader_version = priv->shader_version;
1280 static BOOL shader_sm4_read_reg_idx(struct wined3d_sm4_data *priv, const DWORD **ptr,
1281 DWORD addressing, struct wined3d_shader_register_index *reg_idx)
1283 if (addressing & WINED3D_SM4_ADDRESSING_RELATIVE)
1285 struct wined3d_shader_src_param *rel_addr = get_src_param(priv);
1287 if (!(reg_idx->rel_addr = rel_addr))
1289 ERR("Failed to get src param for relative addressing.\n");
1290 return FALSE;
1293 if (addressing & WINED3D_SM4_ADDRESSING_OFFSET)
1294 reg_idx->offset = *(*ptr)++;
1295 else
1296 reg_idx->offset = 0;
1297 shader_sm4_read_src_param(priv, ptr, WINED3D_DATA_INT, rel_addr);
1299 else
1301 reg_idx->rel_addr = NULL;
1302 reg_idx->offset = *(*ptr)++;
1305 return TRUE;
1308 static BOOL shader_sm4_read_param(struct wined3d_sm4_data *priv, const DWORD **ptr,
1309 enum wined3d_data_type data_type, struct wined3d_shader_register *param,
1310 enum wined3d_shader_src_modifier *modifier)
1312 enum wined3d_sm4_register_type register_type;
1313 DWORD token = *(*ptr)++;
1314 DWORD order;
1316 register_type = (token & WINED3D_SM4_REGISTER_TYPE_MASK) >> WINED3D_SM4_REGISTER_TYPE_SHIFT;
1317 if (register_type >= sizeof(register_type_table) / sizeof(*register_type_table)
1318 || register_type_table[register_type] == ~0u)
1320 FIXME("Unhandled register type %#x.\n", register_type);
1321 param->type = WINED3DSPR_TEMP;
1323 else
1325 param->type = register_type_table[register_type];
1327 param->data_type = data_type;
1329 if (token & WINED3D_SM4_REGISTER_MODIFIER)
1331 DWORD m = *(*ptr)++;
1333 switch (m)
1335 case 0x41:
1336 *modifier = WINED3DSPSM_NEG;
1337 break;
1339 case 0x81:
1340 *modifier = WINED3DSPSM_ABS;
1341 break;
1343 case 0xc1:
1344 *modifier = WINED3DSPSM_ABSNEG;
1345 break;
1347 default:
1348 FIXME("Skipping modifier 0x%08x.\n", m);
1349 *modifier = WINED3DSPSM_NONE;
1350 break;
1353 else
1355 *modifier = WINED3DSPSM_NONE;
1358 order = (token & WINED3D_SM4_REGISTER_ORDER_MASK) >> WINED3D_SM4_REGISTER_ORDER_SHIFT;
1360 if (order < 1)
1361 param->idx[0].offset = ~0U;
1362 else
1364 DWORD addressing = (token & WINED3D_SM4_ADDRESSING_MASK0) >> WINED3D_SM4_ADDRESSING_SHIFT0;
1365 if (!(shader_sm4_read_reg_idx(priv, ptr, addressing, &param->idx[0])))
1367 ERR("Failed to read register index.\n");
1368 return FALSE;
1372 if (order < 2)
1373 param->idx[1].offset = ~0U;
1374 else
1376 DWORD addressing = (token & WINED3D_SM4_ADDRESSING_MASK1) >> WINED3D_SM4_ADDRESSING_SHIFT1;
1377 if (!(shader_sm4_read_reg_idx(priv, ptr, addressing, &param->idx[1])))
1379 ERR("Failed to read register index.\n");
1380 return FALSE;
1384 if (order > 2)
1385 FIXME("Unhandled order %u.\n", order);
1387 if (register_type == WINED3D_SM4_RT_IMMCONST)
1389 enum wined3d_sm4_immconst_type immconst_type =
1390 (token & WINED3D_SM4_IMMCONST_TYPE_MASK) >> WINED3D_SM4_IMMCONST_TYPE_SHIFT;
1392 switch (immconst_type)
1394 case WINED3D_SM4_IMMCONST_SCALAR:
1395 param->immconst_type = WINED3D_IMMCONST_SCALAR;
1396 memcpy(param->u.immconst_data, *ptr, 1 * sizeof(DWORD));
1397 *ptr += 1;
1398 break;
1400 case WINED3D_SM4_IMMCONST_VEC4:
1401 param->immconst_type = WINED3D_IMMCONST_VEC4;
1402 memcpy(param->u.immconst_data, *ptr, 4 * sizeof(DWORD));
1403 *ptr += 4;
1404 break;
1406 default:
1407 FIXME("Unhandled immediate constant type %#x.\n", immconst_type);
1408 break;
1412 map_register(priv, param);
1414 return TRUE;
1417 static BOOL shader_sm4_read_src_param(struct wined3d_sm4_data *priv, const DWORD **ptr,
1418 enum wined3d_data_type data_type, struct wined3d_shader_src_param *src_param)
1420 DWORD token = **ptr;
1422 if (!shader_sm4_read_param(priv, ptr, data_type, &src_param->reg, &src_param->modifiers))
1424 ERR("Failed to read parameter.\n");
1425 return FALSE;
1428 if (src_param->reg.type == WINED3DSPR_IMMCONST)
1430 src_param->swizzle = WINED3DSP_NOSWIZZLE;
1432 else
1434 enum wined3d_sm4_swizzle_type swizzle_type =
1435 (token & WINED3D_SM4_SWIZZLE_TYPE_MASK) >> WINED3D_SM4_SWIZZLE_TYPE_SHIFT;
1437 switch (swizzle_type)
1439 case WINED3D_SM4_SWIZZLE_NONE:
1440 src_param->swizzle = WINED3DSP_NOSWIZZLE;
1441 break;
1443 case WINED3D_SM4_SWIZZLE_SCALAR:
1444 src_param->swizzle = (token & WINED3D_SM4_SWIZZLE_MASK) >> WINED3D_SM4_SWIZZLE_SHIFT;
1445 src_param->swizzle = (src_param->swizzle & 0x3) * 0x55;
1446 break;
1448 case WINED3D_SM4_SWIZZLE_VEC4:
1449 src_param->swizzle = (token & WINED3D_SM4_SWIZZLE_MASK) >> WINED3D_SM4_SWIZZLE_SHIFT;
1450 break;
1452 default:
1453 FIXME("Unhandled swizzle type %#x.\n", swizzle_type);
1454 break;
1458 return TRUE;
1461 static BOOL shader_sm4_read_dst_param(struct wined3d_sm4_data *priv, const DWORD **ptr,
1462 enum wined3d_data_type data_type, struct wined3d_shader_dst_param *dst_param)
1464 enum wined3d_shader_src_modifier modifier;
1465 DWORD token = **ptr;
1467 if (!shader_sm4_read_param(priv, ptr, data_type, &dst_param->reg, &modifier))
1469 ERR("Failed to read parameter.\n");
1470 return FALSE;
1473 if (modifier != WINED3DSPSM_NONE)
1475 ERR("Invalid source modifier %#x on destination register.\n", modifier);
1476 return FALSE;
1479 dst_param->write_mask = (token & WINED3D_SM4_WRITEMASK_MASK) >> WINED3D_SM4_WRITEMASK_SHIFT;
1480 dst_param->modifiers = 0;
1481 dst_param->shift = 0;
1483 return TRUE;
1486 static void shader_sm4_read_instruction_modifier(DWORD modifier, struct wined3d_shader_instruction *ins)
1488 static const DWORD recognized_bits = WINED3D_SM4_INSTRUCTION_MODIFIER
1489 | WINED3D_SM4_MODIFIER_AOFFIMMI
1490 | WINED3D_SM4_AOFFIMMI_U_MASK
1491 | WINED3D_SM4_AOFFIMMI_V_MASK
1492 | WINED3D_SM4_AOFFIMMI_W_MASK;
1494 if (modifier & ~recognized_bits)
1496 FIXME("Unhandled modifier 0x%08x.\n", modifier);
1498 else
1500 /* Bit fields are used for sign extension */
1501 struct
1503 int u : 4;
1504 int v : 4;
1505 int w : 4;
1507 aoffimmi;
1508 aoffimmi.u = (modifier & WINED3D_SM4_AOFFIMMI_U_MASK) >> WINED3D_SM4_AOFFIMMI_U_SHIFT;
1509 aoffimmi.v = (modifier & WINED3D_SM4_AOFFIMMI_V_MASK) >> WINED3D_SM4_AOFFIMMI_V_SHIFT;
1510 aoffimmi.w = (modifier & WINED3D_SM4_AOFFIMMI_W_MASK) >> WINED3D_SM4_AOFFIMMI_W_SHIFT;
1511 ins->texel_offset.u = aoffimmi.u;
1512 ins->texel_offset.v = aoffimmi.v;
1513 ins->texel_offset.w = aoffimmi.w;
1517 static void shader_sm4_read_instruction(void *data, const DWORD **ptr, struct wined3d_shader_instruction *ins)
1519 const struct wined3d_sm4_opcode_info *opcode_info;
1520 DWORD opcode_token, opcode, previous_token;
1521 struct wined3d_sm4_data *priv = data;
1522 unsigned int i, len;
1523 SIZE_T remaining;
1524 const DWORD *p;
1526 list_move_head(&priv->src_free, &priv->src);
1528 if (*ptr >= priv->end)
1530 WARN("End of byte-code, failed to read opcode.\n");
1531 goto fail;
1533 remaining = priv->end - *ptr;
1535 opcode_token = *(*ptr)++;
1536 opcode = opcode_token & WINED3D_SM4_OPCODE_MASK;
1538 len = ((opcode_token & WINED3D_SM4_INSTRUCTION_LENGTH_MASK) >> WINED3D_SM4_INSTRUCTION_LENGTH_SHIFT);
1539 if (!len)
1541 if (remaining < 2)
1543 WARN("End of byte-code, failed to read length token.\n");
1544 goto fail;
1546 len = **ptr;
1548 if (!len || remaining < len)
1550 WARN("Read invalid length %u (remaining %lu).\n", len, remaining);
1551 goto fail;
1553 --len;
1555 if (TRACE_ON(d3d_bytecode))
1557 TRACE_(d3d_bytecode)("[ %08x ", opcode_token);
1558 for (i = 0; i < len; ++i)
1560 TRACE_(d3d_bytecode)("%08x ", (*ptr)[i]);
1562 TRACE_(d3d_bytecode)("]\n");
1565 if (!(opcode_info = get_opcode_info(opcode)))
1567 FIXME("Unrecognized opcode %#x, opcode_token 0x%08x.\n", opcode, opcode_token);
1568 ins->handler_idx = WINED3DSIH_TABLE_SIZE;
1569 *ptr += len;
1570 return;
1573 ins->handler_idx = opcode_info->handler_idx;
1574 ins->flags = 0;
1575 ins->coissue = 0;
1576 ins->predicate = NULL;
1577 ins->dst_count = strlen(opcode_info->dst_info);
1578 ins->dst = priv->dst_param;
1579 ins->src_count = strlen(opcode_info->src_info);
1580 ins->src = priv->src_param;
1581 memset(&ins->texel_offset, 0, sizeof(ins->texel_offset));
1583 p = *ptr;
1584 *ptr += len;
1586 if (opcode_info->read_opcode_func)
1588 opcode_info->read_opcode_func(ins, opcode, opcode_token, p, len, priv);
1590 else
1592 enum wined3d_shader_dst_modifier instruction_dst_modifier = WINED3DSPDM_NONE;
1594 previous_token = opcode_token;
1595 while (previous_token & WINED3D_SM4_INSTRUCTION_MODIFIER && p != *ptr)
1596 shader_sm4_read_instruction_modifier(previous_token = *p++, ins);
1598 ins->flags = (opcode_token & WINED3D_SM4_INSTRUCTION_FLAGS_MASK) >> WINED3D_SM4_INSTRUCTION_FLAGS_SHIFT;
1600 if (ins->flags & WINED3D_SM4_INSTRUCTION_FLAG_SATURATE)
1602 ins->flags &= ~WINED3D_SM4_INSTRUCTION_FLAG_SATURATE;
1603 instruction_dst_modifier = WINED3DSPDM_SATURATE;
1606 for (i = 0; i < ins->dst_count; ++i)
1608 if (!(shader_sm4_read_dst_param(priv, &p, map_data_type(opcode_info->dst_info[i]), &priv->dst_param[i])))
1610 ins->handler_idx = WINED3DSIH_TABLE_SIZE;
1611 return;
1613 priv->dst_param[i].modifiers |= instruction_dst_modifier;
1616 for (i = 0; i < ins->src_count; ++i)
1618 if (!(shader_sm4_read_src_param(priv, &p, map_data_type(opcode_info->src_info[i]), &priv->src_param[i])))
1620 ins->handler_idx = WINED3DSIH_TABLE_SIZE;
1621 return;
1626 return;
1628 fail:
1629 *ptr = priv->end;
1630 ins->handler_idx = WINED3DSIH_TABLE_SIZE;
1631 return;
1634 static BOOL shader_sm4_is_end(void *data, const DWORD **ptr)
1636 struct wined3d_sm4_data *priv = data;
1637 return *ptr == priv->end;
1640 const struct wined3d_shader_frontend sm4_shader_frontend =
1642 shader_sm4_init,
1643 shader_sm4_free,
1644 shader_sm4_read_header,
1645 shader_sm4_read_instruction,
1646 shader_sm4_is_end,