wined3d: Rename shader_extract_from_dxbc to wined3d_shader_extract_from_dxbc.
[wine.git] / dlls / wined3d / shader_sm4.c
blob74391cc1be85b52a70d7ffff26c97fc917cd23ed
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 "wined3d_private.h"
20 #define LIBVKD3D_SHADER_SOURCE
21 #include <vkd3d_shader.h>
23 WINE_DEFAULT_DEBUG_CHANNEL(d3d_shader);
24 WINE_DECLARE_DEBUG_CHANNEL(d3d_bytecode);
26 #define WINED3D_SM4_INSTRUCTION_MODIFIER (0x1u << 31)
28 #define WINED3D_SM4_MODIFIER_MASK 0x3fu
30 #define WINED3D_SM5_MODIFIER_DATA_TYPE_SHIFT 6
31 #define WINED3D_SM5_MODIFIER_DATA_TYPE_MASK (0xffffu << WINED3D_SM5_MODIFIER_DATA_TYPE_SHIFT)
33 #define WINED3D_SM5_MODIFIER_RESOURCE_TYPE_SHIFT 6
34 #define WINED3D_SM5_MODIFIER_RESOURCE_TYPE_MASK (0xfu << WINED3D_SM5_MODIFIER_RESOURCE_TYPE_SHIFT)
36 #define WINED3D_SM4_AOFFIMMI_U_SHIFT 9
37 #define WINED3D_SM4_AOFFIMMI_U_MASK (0xfu << WINED3D_SM4_AOFFIMMI_U_SHIFT)
38 #define WINED3D_SM4_AOFFIMMI_V_SHIFT 13
39 #define WINED3D_SM4_AOFFIMMI_V_MASK (0xfu << WINED3D_SM4_AOFFIMMI_V_SHIFT)
40 #define WINED3D_SM4_AOFFIMMI_W_SHIFT 17
41 #define WINED3D_SM4_AOFFIMMI_W_MASK (0xfu << WINED3D_SM4_AOFFIMMI_W_SHIFT)
43 #define WINED3D_SM4_INSTRUCTION_LENGTH_SHIFT 24
44 #define WINED3D_SM4_INSTRUCTION_LENGTH_MASK (0x1fu << WINED3D_SM4_INSTRUCTION_LENGTH_SHIFT)
46 #define WINED3D_SM4_INSTRUCTION_FLAGS_SHIFT 11
47 #define WINED3D_SM4_INSTRUCTION_FLAGS_MASK (0x7u << WINED3D_SM4_INSTRUCTION_FLAGS_SHIFT)
49 #define WINED3D_SM4_RESOURCE_TYPE_SHIFT 11
50 #define WINED3D_SM4_RESOURCE_TYPE_MASK (0xfu << WINED3D_SM4_RESOURCE_TYPE_SHIFT)
52 #define WINED3D_SM4_RESOURCE_SAMPLE_COUNT_SHIFT 16
53 #define WINED3D_SM4_RESOURCE_SAMPLE_COUNT_MASK (0xfu << WINED3D_SM4_RESOURCE_SAMPLE_COUNT_SHIFT)
55 #define WINED3D_SM4_PRIMITIVE_TYPE_SHIFT 11
56 #define WINED3D_SM4_PRIMITIVE_TYPE_MASK (0x3fu << WINED3D_SM4_PRIMITIVE_TYPE_SHIFT)
58 #define WINED3D_SM4_INDEX_TYPE_SHIFT 11
59 #define WINED3D_SM4_INDEX_TYPE_MASK (0x1u << WINED3D_SM4_INDEX_TYPE_SHIFT)
61 #define WINED3D_SM4_SAMPLER_MODE_SHIFT 11
62 #define WINED3D_SM4_SAMPLER_MODE_MASK (0xfu << WINED3D_SM4_SAMPLER_MODE_SHIFT)
64 #define WINED3D_SM4_SHADER_DATA_TYPE_SHIFT 11
65 #define WINED3D_SM4_SHADER_DATA_TYPE_MASK (0xfu << WINED3D_SM4_SHADER_DATA_TYPE_SHIFT)
67 #define WINED3D_SM4_INTERPOLATION_MODE_SHIFT 11
68 #define WINED3D_SM4_INTERPOLATION_MODE_MASK (0xfu << WINED3D_SM4_INTERPOLATION_MODE_SHIFT)
70 #define WINED3D_SM4_GLOBAL_FLAGS_SHIFT 11
71 #define WINED3D_SM4_GLOBAL_FLAGS_MASK (0xffu << WINED3D_SM4_GLOBAL_FLAGS_SHIFT)
73 #define WINED3D_SM5_PRECISE_SHIFT 19
74 #define WINED3D_SM5_PRECISE_MASK (0xfu << WINED3D_SM5_PRECISE_SHIFT)
76 #define WINED3D_SM5_CONTROL_POINT_COUNT_SHIFT 11
77 #define WINED3D_SM5_CONTROL_POINT_COUNT_MASK (0xffu << WINED3D_SM5_CONTROL_POINT_COUNT_SHIFT)
79 #define WINED3D_SM5_FP_ARRAY_SIZE_SHIFT 16
80 #define WINED3D_SM5_FP_TABLE_COUNT_MASK 0xffffu
82 #define WINED3D_SM5_UAV_FLAGS_SHIFT 15
83 #define WINED3D_SM5_UAV_FLAGS_MASK (0x1ffu << WINED3D_SM5_UAV_FLAGS_SHIFT)
85 #define WINED3D_SM5_SYNC_FLAGS_SHIFT 11
86 #define WINED3D_SM5_SYNC_FLAGS_MASK (0xffu << WINED3D_SM5_SYNC_FLAGS_SHIFT)
88 #define WINED3D_SM5_TESSELLATOR_SHIFT 11
89 #define WINED3D_SM5_TESSELLATOR_MASK (0xfu << WINED3D_SM5_TESSELLATOR_SHIFT)
91 #define WINED3D_SM4_OPCODE_MASK 0xff
93 #define WINED3D_SM4_REGISTER_MODIFIER (0x1u << 31)
95 #define WINED3D_SM4_ADDRESSING_SHIFT1 25
96 #define WINED3D_SM4_ADDRESSING_MASK1 (0x3u << WINED3D_SM4_ADDRESSING_SHIFT1)
98 #define WINED3D_SM4_ADDRESSING_SHIFT0 22
99 #define WINED3D_SM4_ADDRESSING_MASK0 (0x3u << WINED3D_SM4_ADDRESSING_SHIFT0)
101 #define WINED3D_SM4_REGISTER_ORDER_SHIFT 20
102 #define WINED3D_SM4_REGISTER_ORDER_MASK (0x3u << WINED3D_SM4_REGISTER_ORDER_SHIFT)
104 #define WINED3D_SM4_REGISTER_TYPE_SHIFT 12
105 #define WINED3D_SM4_REGISTER_TYPE_MASK (0xffu << WINED3D_SM4_REGISTER_TYPE_SHIFT)
107 #define WINED3D_SM4_SWIZZLE_TYPE_SHIFT 2
108 #define WINED3D_SM4_SWIZZLE_TYPE_MASK (0x3u << WINED3D_SM4_SWIZZLE_TYPE_SHIFT)
110 #define WINED3D_SM4_DIMENSION_SHIFT 0
111 #define WINED3D_SM4_DIMENSION_MASK (0x3u << WINED3D_SM4_DIMENSION_SHIFT)
113 #define WINED3D_SM4_WRITEMASK_SHIFT 4
114 #define WINED3D_SM4_WRITEMASK_MASK (0xfu << WINED3D_SM4_WRITEMASK_SHIFT)
116 #define WINED3D_SM4_SWIZZLE_SHIFT 4
117 #define WINED3D_SM4_SWIZZLE_MASK (0xffu << WINED3D_SM4_SWIZZLE_SHIFT)
119 #define WINED3D_SM4_VERSION_MAJOR(version) (((version) >> 4) & 0xf)
120 #define WINED3D_SM4_VERSION_MINOR(version) (((version) >> 0) & 0xf)
122 #define WINED3D_SM4_ADDRESSING_RELATIVE 0x2
123 #define WINED3D_SM4_ADDRESSING_OFFSET 0x1
125 #define WINED3D_SM4_INSTRUCTION_FLAG_SATURATE 0x4
127 #define WINED3D_SM4_CONDITIONAL_NZ (0x1u << 18)
129 enum wined3d_sm4_opcode
131 WINED3D_SM4_OP_ADD = 0x00,
132 WINED3D_SM4_OP_AND = 0x01,
133 WINED3D_SM4_OP_BREAK = 0x02,
134 WINED3D_SM4_OP_BREAKC = 0x03,
135 WINED3D_SM4_OP_CASE = 0x06,
136 WINED3D_SM4_OP_CONTINUE = 0x07,
137 WINED3D_SM4_OP_CONTINUEC = 0x08,
138 WINED3D_SM4_OP_CUT = 0x09,
139 WINED3D_SM4_OP_DEFAULT = 0x0a,
140 WINED3D_SM4_OP_DERIV_RTX = 0x0b,
141 WINED3D_SM4_OP_DERIV_RTY = 0x0c,
142 WINED3D_SM4_OP_DISCARD = 0x0d,
143 WINED3D_SM4_OP_DIV = 0x0e,
144 WINED3D_SM4_OP_DP2 = 0x0f,
145 WINED3D_SM4_OP_DP3 = 0x10,
146 WINED3D_SM4_OP_DP4 = 0x11,
147 WINED3D_SM4_OP_ELSE = 0x12,
148 WINED3D_SM4_OP_EMIT = 0x13,
149 WINED3D_SM4_OP_ENDIF = 0x15,
150 WINED3D_SM4_OP_ENDLOOP = 0x16,
151 WINED3D_SM4_OP_ENDSWITCH = 0x17,
152 WINED3D_SM4_OP_EQ = 0x18,
153 WINED3D_SM4_OP_EXP = 0x19,
154 WINED3D_SM4_OP_FRC = 0x1a,
155 WINED3D_SM4_OP_FTOI = 0x1b,
156 WINED3D_SM4_OP_FTOU = 0x1c,
157 WINED3D_SM4_OP_GE = 0x1d,
158 WINED3D_SM4_OP_IADD = 0x1e,
159 WINED3D_SM4_OP_IF = 0x1f,
160 WINED3D_SM4_OP_IEQ = 0x20,
161 WINED3D_SM4_OP_IGE = 0x21,
162 WINED3D_SM4_OP_ILT = 0x22,
163 WINED3D_SM4_OP_IMAD = 0x23,
164 WINED3D_SM4_OP_IMAX = 0x24,
165 WINED3D_SM4_OP_IMIN = 0x25,
166 WINED3D_SM4_OP_IMUL = 0x26,
167 WINED3D_SM4_OP_INE = 0x27,
168 WINED3D_SM4_OP_INEG = 0x28,
169 WINED3D_SM4_OP_ISHL = 0x29,
170 WINED3D_SM4_OP_ISHR = 0x2a,
171 WINED3D_SM4_OP_ITOF = 0x2b,
172 WINED3D_SM4_OP_LABEL = 0x2c,
173 WINED3D_SM4_OP_LD = 0x2d,
174 WINED3D_SM4_OP_LD2DMS = 0x2e,
175 WINED3D_SM4_OP_LOG = 0x2f,
176 WINED3D_SM4_OP_LOOP = 0x30,
177 WINED3D_SM4_OP_LT = 0x31,
178 WINED3D_SM4_OP_MAD = 0x32,
179 WINED3D_SM4_OP_MIN = 0x33,
180 WINED3D_SM4_OP_MAX = 0x34,
181 WINED3D_SM4_OP_SHADER_DATA = 0x35,
182 WINED3D_SM4_OP_MOV = 0x36,
183 WINED3D_SM4_OP_MOVC = 0x37,
184 WINED3D_SM4_OP_MUL = 0x38,
185 WINED3D_SM4_OP_NE = 0x39,
186 WINED3D_SM4_OP_NOP = 0x3a,
187 WINED3D_SM4_OP_NOT = 0x3b,
188 WINED3D_SM4_OP_OR = 0x3c,
189 WINED3D_SM4_OP_RESINFO = 0x3d,
190 WINED3D_SM4_OP_RET = 0x3e,
191 WINED3D_SM4_OP_RETC = 0x3f,
192 WINED3D_SM4_OP_ROUND_NE = 0x40,
193 WINED3D_SM4_OP_ROUND_NI = 0x41,
194 WINED3D_SM4_OP_ROUND_PI = 0x42,
195 WINED3D_SM4_OP_ROUND_Z = 0x43,
196 WINED3D_SM4_OP_RSQ = 0x44,
197 WINED3D_SM4_OP_SAMPLE = 0x45,
198 WINED3D_SM4_OP_SAMPLE_C = 0x46,
199 WINED3D_SM4_OP_SAMPLE_C_LZ = 0x47,
200 WINED3D_SM4_OP_SAMPLE_LOD = 0x48,
201 WINED3D_SM4_OP_SAMPLE_GRAD = 0x49,
202 WINED3D_SM4_OP_SAMPLE_B = 0x4a,
203 WINED3D_SM4_OP_SQRT = 0x4b,
204 WINED3D_SM4_OP_SWITCH = 0x4c,
205 WINED3D_SM4_OP_SINCOS = 0x4d,
206 WINED3D_SM4_OP_UDIV = 0x4e,
207 WINED3D_SM4_OP_ULT = 0x4f,
208 WINED3D_SM4_OP_UGE = 0x50,
209 WINED3D_SM4_OP_UMUL = 0x51,
210 WINED3D_SM4_OP_UMAX = 0x53,
211 WINED3D_SM4_OP_UMIN = 0x54,
212 WINED3D_SM4_OP_USHR = 0x55,
213 WINED3D_SM4_OP_UTOF = 0x56,
214 WINED3D_SM4_OP_XOR = 0x57,
215 WINED3D_SM4_OP_DCL_RESOURCE = 0x58,
216 WINED3D_SM4_OP_DCL_CONSTANT_BUFFER = 0x59,
217 WINED3D_SM4_OP_DCL_SAMPLER = 0x5a,
218 WINED3D_SM4_OP_DCL_INDEX_RANGE = 0x5b,
219 WINED3D_SM4_OP_DCL_OUTPUT_TOPOLOGY = 0x5c,
220 WINED3D_SM4_OP_DCL_INPUT_PRIMITIVE = 0x5d,
221 WINED3D_SM4_OP_DCL_VERTICES_OUT = 0x5e,
222 WINED3D_SM4_OP_DCL_INPUT = 0x5f,
223 WINED3D_SM4_OP_DCL_INPUT_SGV = 0x60,
224 WINED3D_SM4_OP_DCL_INPUT_SIV = 0x61,
225 WINED3D_SM4_OP_DCL_INPUT_PS = 0x62,
226 WINED3D_SM4_OP_DCL_INPUT_PS_SGV = 0x63,
227 WINED3D_SM4_OP_DCL_INPUT_PS_SIV = 0x64,
228 WINED3D_SM4_OP_DCL_OUTPUT = 0x65,
229 WINED3D_SM4_OP_DCL_OUTPUT_SIV = 0x67,
230 WINED3D_SM4_OP_DCL_TEMPS = 0x68,
231 WINED3D_SM4_OP_DCL_INDEXABLE_TEMP = 0x69,
232 WINED3D_SM4_OP_DCL_GLOBAL_FLAGS = 0x6a,
233 WINED3D_SM4_OP_LOD = 0x6c,
234 WINED3D_SM4_OP_GATHER4 = 0x6d,
235 WINED3D_SM4_OP_SAMPLE_POS = 0x6e,
236 WINED3D_SM4_OP_SAMPLE_INFO = 0x6f,
237 WINED3D_SM5_OP_HS_DECLS = 0x71,
238 WINED3D_SM5_OP_HS_CONTROL_POINT_PHASE = 0x72,
239 WINED3D_SM5_OP_HS_FORK_PHASE = 0x73,
240 WINED3D_SM5_OP_HS_JOIN_PHASE = 0x74,
241 WINED3D_SM5_OP_EMIT_STREAM = 0x75,
242 WINED3D_SM5_OP_CUT_STREAM = 0x76,
243 WINED3D_SM5_OP_FCALL = 0x78,
244 WINED3D_SM5_OP_BUFINFO = 0x79,
245 WINED3D_SM5_OP_DERIV_RTX_COARSE = 0x7a,
246 WINED3D_SM5_OP_DERIV_RTX_FINE = 0x7b,
247 WINED3D_SM5_OP_DERIV_RTY_COARSE = 0x7c,
248 WINED3D_SM5_OP_DERIV_RTY_FINE = 0x7d,
249 WINED3D_SM5_OP_GATHER4_C = 0x7e,
250 WINED3D_SM5_OP_GATHER4_PO = 0x7f,
251 WINED3D_SM5_OP_GATHER4_PO_C = 0x80,
252 WINED3D_SM5_OP_RCP = 0x81,
253 WINED3D_SM5_OP_F32TOF16 = 0x82,
254 WINED3D_SM5_OP_F16TOF32 = 0x83,
255 WINED3D_SM5_OP_COUNTBITS = 0x86,
256 WINED3D_SM5_OP_FIRSTBIT_HI = 0x87,
257 WINED3D_SM5_OP_FIRSTBIT_LO = 0x88,
258 WINED3D_SM5_OP_FIRSTBIT_SHI = 0x89,
259 WINED3D_SM5_OP_UBFE = 0x8a,
260 WINED3D_SM5_OP_IBFE = 0x8b,
261 WINED3D_SM5_OP_BFI = 0x8c,
262 WINED3D_SM5_OP_BFREV = 0x8d,
263 WINED3D_SM5_OP_SWAPC = 0x8e,
264 WINED3D_SM5_OP_DCL_STREAM = 0x8f,
265 WINED3D_SM5_OP_DCL_FUNCTION_BODY = 0x90,
266 WINED3D_SM5_OP_DCL_FUNCTION_TABLE = 0x91,
267 WINED3D_SM5_OP_DCL_INTERFACE = 0x92,
268 WINED3D_SM5_OP_DCL_INPUT_CONTROL_POINT_COUNT = 0x93,
269 WINED3D_SM5_OP_DCL_OUTPUT_CONTROL_POINT_COUNT = 0x94,
270 WINED3D_SM5_OP_DCL_TESSELLATOR_DOMAIN = 0x95,
271 WINED3D_SM5_OP_DCL_TESSELLATOR_PARTITIONING = 0x96,
272 WINED3D_SM5_OP_DCL_TESSELLATOR_OUTPUT_PRIMITIVE = 0x97,
273 WINED3D_SM5_OP_DCL_HS_MAX_TESSFACTOR = 0x98,
274 WINED3D_SM5_OP_DCL_HS_FORK_PHASE_INSTANCE_COUNT = 0x99,
275 WINED3D_SM5_OP_DCL_HS_JOIN_PHASE_INSTANCE_COUNT = 0x9a,
276 WINED3D_SM5_OP_DCL_THREAD_GROUP = 0x9b,
277 WINED3D_SM5_OP_DCL_UAV_TYPED = 0x9c,
278 WINED3D_SM5_OP_DCL_UAV_RAW = 0x9d,
279 WINED3D_SM5_OP_DCL_UAV_STRUCTURED = 0x9e,
280 WINED3D_SM5_OP_DCL_TGSM_RAW = 0x9f,
281 WINED3D_SM5_OP_DCL_TGSM_STRUCTURED = 0xa0,
282 WINED3D_SM5_OP_DCL_RESOURCE_RAW = 0xa1,
283 WINED3D_SM5_OP_DCL_RESOURCE_STRUCTURED = 0xa2,
284 WINED3D_SM5_OP_LD_UAV_TYPED = 0xa3,
285 WINED3D_SM5_OP_STORE_UAV_TYPED = 0xa4,
286 WINED3D_SM5_OP_LD_RAW = 0xa5,
287 WINED3D_SM5_OP_STORE_RAW = 0xa6,
288 WINED3D_SM5_OP_LD_STRUCTURED = 0xa7,
289 WINED3D_SM5_OP_STORE_STRUCTURED = 0xa8,
290 WINED3D_SM5_OP_ATOMIC_AND = 0xa9,
291 WINED3D_SM5_OP_ATOMIC_OR = 0xaa,
292 WINED3D_SM5_OP_ATOMIC_XOR = 0xab,
293 WINED3D_SM5_OP_ATOMIC_CMP_STORE = 0xac,
294 WINED3D_SM5_OP_ATOMIC_IADD = 0xad,
295 WINED3D_SM5_OP_ATOMIC_IMAX = 0xae,
296 WINED3D_SM5_OP_ATOMIC_IMIN = 0xaf,
297 WINED3D_SM5_OP_ATOMIC_UMAX = 0xb0,
298 WINED3D_SM5_OP_ATOMIC_UMIN = 0xb1,
299 WINED3D_SM5_OP_IMM_ATOMIC_ALLOC = 0xb2,
300 WINED3D_SM5_OP_IMM_ATOMIC_CONSUME = 0xb3,
301 WINED3D_SM5_OP_IMM_ATOMIC_IADD = 0xb4,
302 WINED3D_SM5_OP_IMM_ATOMIC_AND = 0xb5,
303 WINED3D_SM5_OP_IMM_ATOMIC_OR = 0xb6,
304 WINED3D_SM5_OP_IMM_ATOMIC_XOR = 0xb7,
305 WINED3D_SM5_OP_IMM_ATOMIC_EXCH = 0xb8,
306 WINED3D_SM5_OP_IMM_ATOMIC_CMP_EXCH = 0xb9,
307 WINED3D_SM5_OP_IMM_ATOMIC_IMAX = 0xba,
308 WINED3D_SM5_OP_IMM_ATOMIC_IMIN = 0xbb,
309 WINED3D_SM5_OP_IMM_ATOMIC_UMAX = 0xbc,
310 WINED3D_SM5_OP_IMM_ATOMIC_UMIN = 0xbd,
311 WINED3D_SM5_OP_SYNC = 0xbe,
312 WINED3D_SM5_OP_EVAL_SAMPLE_INDEX = 0xcc,
313 WINED3D_SM5_OP_EVAL_CENTROID = 0xcd,
314 WINED3D_SM5_OP_DCL_GS_INSTANCES = 0xce,
317 enum wined3d_sm4_instruction_modifier
319 WINED3D_SM4_MODIFIER_AOFFIMMI = 0x1,
320 WINED3D_SM5_MODIFIER_RESOURCE_TYPE = 0x2,
321 WINED3D_SM5_MODIFIER_DATA_TYPE = 0x3,
324 enum wined3d_sm4_register_type
326 WINED3D_SM4_RT_TEMP = 0x00,
327 WINED3D_SM4_RT_INPUT = 0x01,
328 WINED3D_SM4_RT_OUTPUT = 0x02,
329 WINED3D_SM4_RT_INDEXABLE_TEMP = 0x03,
330 WINED3D_SM4_RT_IMMCONST = 0x04,
331 WINED3D_SM4_RT_SAMPLER = 0x06,
332 WINED3D_SM4_RT_RESOURCE = 0x07,
333 WINED3D_SM4_RT_CONSTBUFFER = 0x08,
334 WINED3D_SM4_RT_IMMCONSTBUFFER = 0x09,
335 WINED3D_SM4_RT_PRIMID = 0x0b,
336 WINED3D_SM4_RT_DEPTHOUT = 0x0c,
337 WINED3D_SM4_RT_NULL = 0x0d,
338 WINED3D_SM4_RT_RASTERIZER = 0x0e,
339 WINED3D_SM4_RT_OMASK = 0x0f,
340 WINED3D_SM5_RT_STREAM = 0x10,
341 WINED3D_SM5_RT_FUNCTION_BODY = 0x11,
342 WINED3D_SM5_RT_FUNCTION_POINTER = 0x13,
343 WINED3D_SM5_RT_OUTPUT_CONTROL_POINT_ID = 0x16,
344 WINED3D_SM5_RT_FORK_INSTANCE_ID = 0x17,
345 WINED3D_SM5_RT_JOIN_INSTANCE_ID = 0x18,
346 WINED3D_SM5_RT_INPUT_CONTROL_POINT = 0x19,
347 WINED3D_SM5_RT_OUTPUT_CONTROL_POINT = 0x1a,
348 WINED3D_SM5_RT_PATCH_CONSTANT_DATA = 0x1b,
349 WINED3D_SM5_RT_DOMAIN_LOCATION = 0x1c,
350 WINED3D_SM5_RT_UAV = 0x1e,
351 WINED3D_SM5_RT_SHARED_MEMORY = 0x1f,
352 WINED3D_SM5_RT_THREAD_ID = 0x20,
353 WINED3D_SM5_RT_THREAD_GROUP_ID = 0x21,
354 WINED3D_SM5_RT_LOCAL_THREAD_ID = 0x22,
355 WINED3D_SM5_RT_COVERAGE = 0x23,
356 WINED3D_SM5_RT_LOCAL_THREAD_INDEX = 0x24,
357 WINED3D_SM5_RT_GS_INSTANCE_ID = 0x25,
358 WINED3D_SM5_RT_DEPTHOUT_GREATER_EQUAL = 0x26,
359 WINED3D_SM5_RT_DEPTHOUT_LESS_EQUAL = 0x27,
362 enum wined3d_sm4_output_primitive_type
364 WINED3D_SM4_OUTPUT_PT_POINTLIST = 0x1,
365 WINED3D_SM4_OUTPUT_PT_LINESTRIP = 0x3,
366 WINED3D_SM4_OUTPUT_PT_TRIANGLESTRIP = 0x5,
369 enum wined3d_sm4_input_primitive_type
371 WINED3D_SM4_INPUT_PT_POINT = 0x01,
372 WINED3D_SM4_INPUT_PT_LINE = 0x02,
373 WINED3D_SM4_INPUT_PT_TRIANGLE = 0x03,
374 WINED3D_SM4_INPUT_PT_LINEADJ = 0x06,
375 WINED3D_SM4_INPUT_PT_TRIANGLEADJ = 0x07,
376 WINED3D_SM5_INPUT_PT_PATCH1 = 0x08,
377 WINED3D_SM5_INPUT_PT_PATCH2 = 0x09,
378 WINED3D_SM5_INPUT_PT_PATCH3 = 0x0a,
379 WINED3D_SM5_INPUT_PT_PATCH4 = 0x0b,
380 WINED3D_SM5_INPUT_PT_PATCH5 = 0x0c,
381 WINED3D_SM5_INPUT_PT_PATCH6 = 0x0d,
382 WINED3D_SM5_INPUT_PT_PATCH7 = 0x0e,
383 WINED3D_SM5_INPUT_PT_PATCH8 = 0x0f,
384 WINED3D_SM5_INPUT_PT_PATCH9 = 0x10,
385 WINED3D_SM5_INPUT_PT_PATCH10 = 0x11,
386 WINED3D_SM5_INPUT_PT_PATCH11 = 0x12,
387 WINED3D_SM5_INPUT_PT_PATCH12 = 0x13,
388 WINED3D_SM5_INPUT_PT_PATCH13 = 0x14,
389 WINED3D_SM5_INPUT_PT_PATCH14 = 0x15,
390 WINED3D_SM5_INPUT_PT_PATCH15 = 0x16,
391 WINED3D_SM5_INPUT_PT_PATCH16 = 0x17,
392 WINED3D_SM5_INPUT_PT_PATCH17 = 0x18,
393 WINED3D_SM5_INPUT_PT_PATCH18 = 0x19,
394 WINED3D_SM5_INPUT_PT_PATCH19 = 0x1a,
395 WINED3D_SM5_INPUT_PT_PATCH20 = 0x1b,
396 WINED3D_SM5_INPUT_PT_PATCH21 = 0x1c,
397 WINED3D_SM5_INPUT_PT_PATCH22 = 0x1d,
398 WINED3D_SM5_INPUT_PT_PATCH23 = 0x1e,
399 WINED3D_SM5_INPUT_PT_PATCH24 = 0x1f,
400 WINED3D_SM5_INPUT_PT_PATCH25 = 0x20,
401 WINED3D_SM5_INPUT_PT_PATCH26 = 0x21,
402 WINED3D_SM5_INPUT_PT_PATCH27 = 0x22,
403 WINED3D_SM5_INPUT_PT_PATCH28 = 0x23,
404 WINED3D_SM5_INPUT_PT_PATCH29 = 0x24,
405 WINED3D_SM5_INPUT_PT_PATCH30 = 0x25,
406 WINED3D_SM5_INPUT_PT_PATCH31 = 0x26,
407 WINED3D_SM5_INPUT_PT_PATCH32 = 0x27,
410 enum wined3d_sm4_swizzle_type
412 WINED3D_SM4_SWIZZLE_NONE = 0x0,
413 WINED3D_SM4_SWIZZLE_VEC4 = 0x1,
414 WINED3D_SM4_SWIZZLE_SCALAR = 0x2,
417 enum wined3d_sm4_dimension
419 WINED3D_SM4_DIMENSION_SCALAR = 0x1,
420 WINED3D_SM4_DIMENSION_VEC4 = 0x2,
423 enum wined3d_sm4_resource_type
425 WINED3D_SM4_RESOURCE_BUFFER = 0x1,
426 WINED3D_SM4_RESOURCE_TEXTURE_1D = 0x2,
427 WINED3D_SM4_RESOURCE_TEXTURE_2D = 0x3,
428 WINED3D_SM4_RESOURCE_TEXTURE_2DMS = 0x4,
429 WINED3D_SM4_RESOURCE_TEXTURE_3D = 0x5,
430 WINED3D_SM4_RESOURCE_TEXTURE_CUBE = 0x6,
431 WINED3D_SM4_RESOURCE_TEXTURE_1DARRAY = 0x7,
432 WINED3D_SM4_RESOURCE_TEXTURE_2DARRAY = 0x8,
433 WINED3D_SM4_RESOURCE_TEXTURE_2DMSARRAY = 0x9,
434 WINED3D_SM4_RESOURCE_TEXTURE_CUBEARRAY = 0xa,
437 enum wined3d_sm4_data_type
439 WINED3D_SM4_DATA_UNORM = 0x1,
440 WINED3D_SM4_DATA_SNORM = 0x2,
441 WINED3D_SM4_DATA_INT = 0x3,
442 WINED3D_SM4_DATA_UINT = 0x4,
443 WINED3D_SM4_DATA_FLOAT = 0x5,
446 enum wined3d_sm4_sampler_mode
448 WINED3D_SM4_SAMPLER_DEFAULT = 0x0,
449 WINED3D_SM4_SAMPLER_COMPARISON = 0x1,
452 enum wined3d_sm4_shader_data_type
454 WINED3D_SM4_SHADER_DATA_IMMEDIATE_CONSTANT_BUFFER = 0x3,
455 WINED3D_SM4_SHADER_DATA_MESSAGE = 0x4,
458 struct wined3d_shader_src_param_entry
460 struct list entry;
461 struct wined3d_shader_src_param param;
464 struct wined3d_sm4_data
466 struct wined3d_shader_version shader_version;
467 const DWORD *start, *end;
469 unsigned int output_map[MAX_REG_OUTPUT];
471 struct wined3d_shader_src_param src_param[5];
472 struct wined3d_shader_dst_param dst_param[2];
473 struct list src_free;
474 struct list src;
475 struct wined3d_shader_immediate_constant_buffer icb;
478 struct wined3d_sm4_opcode_info
480 enum wined3d_sm4_opcode opcode;
481 enum WINED3D_SHADER_INSTRUCTION_HANDLER handler_idx;
482 const char *dst_info;
483 const char *src_info;
484 void (*read_opcode_func)(struct wined3d_shader_instruction *ins,
485 DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
486 struct wined3d_sm4_data *priv);
489 static const enum wined3d_primitive_type output_primitive_type_table[] =
491 /* UNKNOWN */ WINED3D_PT_UNDEFINED,
492 /* WINED3D_SM4_OUTPUT_PT_POINTLIST */ WINED3D_PT_POINTLIST,
493 /* UNKNOWN */ WINED3D_PT_UNDEFINED,
494 /* WINED3D_SM4_OUTPUT_PT_LINESTRIP */ WINED3D_PT_LINESTRIP,
495 /* UNKNOWN */ WINED3D_PT_UNDEFINED,
496 /* WINED3D_SM4_OUTPUT_PT_TRIANGLESTRIP */ WINED3D_PT_TRIANGLESTRIP,
499 static const enum wined3d_primitive_type input_primitive_type_table[] =
501 /* UNKNOWN */ WINED3D_PT_UNDEFINED,
502 /* WINED3D_SM4_INPUT_PT_POINT */ WINED3D_PT_POINTLIST,
503 /* WINED3D_SM4_INPUT_PT_LINE */ WINED3D_PT_LINELIST,
504 /* WINED3D_SM4_INPUT_PT_TRIANGLE */ WINED3D_PT_TRIANGLELIST,
505 /* UNKNOWN */ WINED3D_PT_UNDEFINED,
506 /* UNKNOWN */ WINED3D_PT_UNDEFINED,
507 /* WINED3D_SM4_INPUT_PT_LINEADJ */ WINED3D_PT_LINELIST_ADJ,
508 /* WINED3D_SM4_INPUT_PT_TRIANGLEADJ */ WINED3D_PT_TRIANGLELIST_ADJ,
511 static const enum wined3d_shader_resource_type resource_type_table[] =
513 /* 0 */ WINED3D_SHADER_RESOURCE_NONE,
514 /* WINED3D_SM4_RESOURCE_BUFFER */ WINED3D_SHADER_RESOURCE_BUFFER,
515 /* WINED3D_SM4_RESOURCE_TEXTURE_1D */ WINED3D_SHADER_RESOURCE_TEXTURE_1D,
516 /* WINED3D_SM4_RESOURCE_TEXTURE_2D */ WINED3D_SHADER_RESOURCE_TEXTURE_2D,
517 /* WINED3D_SM4_RESOURCE_TEXTURE_2DMS */ WINED3D_SHADER_RESOURCE_TEXTURE_2DMS,
518 /* WINED3D_SM4_RESOURCE_TEXTURE_3D */ WINED3D_SHADER_RESOURCE_TEXTURE_3D,
519 /* WINED3D_SM4_RESOURCE_TEXTURE_CUBE */ WINED3D_SHADER_RESOURCE_TEXTURE_CUBE,
520 /* WINED3D_SM4_RESOURCE_TEXTURE_1DARRAY */ WINED3D_SHADER_RESOURCE_TEXTURE_1DARRAY,
521 /* WINED3D_SM4_RESOURCE_TEXTURE_2DARRAY */ WINED3D_SHADER_RESOURCE_TEXTURE_2DARRAY,
522 /* WINED3D_SM4_RESOURCE_TEXTURE_2DMSARRAY */ WINED3D_SHADER_RESOURCE_TEXTURE_2DMSARRAY,
523 /* WINED3D_SM4_RESOURCE_TEXTURE_CUBEARRAY */ WINED3D_SHADER_RESOURCE_TEXTURE_CUBEARRAY,
526 static const enum wined3d_data_type data_type_table[] =
528 /* 0 */ WINED3D_DATA_FLOAT,
529 /* WINED3D_SM4_DATA_UNORM */ WINED3D_DATA_UNORM,
530 /* WINED3D_SM4_DATA_SNORM */ WINED3D_DATA_SNORM,
531 /* WINED3D_SM4_DATA_INT */ WINED3D_DATA_INT,
532 /* WINED3D_SM4_DATA_UINT */ WINED3D_DATA_UINT,
533 /* WINED3D_SM4_DATA_FLOAT */ WINED3D_DATA_FLOAT,
536 static BOOL shader_sm4_read_src_param(struct wined3d_sm4_data *priv, const DWORD **ptr, const DWORD *end,
537 enum wined3d_data_type data_type, struct wined3d_shader_src_param *src_param);
538 static BOOL shader_sm4_read_dst_param(struct wined3d_sm4_data *priv, const DWORD **ptr, const DWORD *end,
539 enum wined3d_data_type data_type, struct wined3d_shader_dst_param *dst_param);
541 static void shader_sm4_read_conditional_op(struct wined3d_shader_instruction *ins,
542 DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
543 struct wined3d_sm4_data *priv)
545 shader_sm4_read_src_param(priv, &tokens, &tokens[token_count], WINED3D_DATA_UINT, &priv->src_param[0]);
546 ins->flags = (opcode_token & WINED3D_SM4_CONDITIONAL_NZ) ?
547 WINED3D_SHADER_CONDITIONAL_OP_NZ : WINED3D_SHADER_CONDITIONAL_OP_Z;
550 static void shader_sm4_read_shader_data(struct wined3d_shader_instruction *ins,
551 DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
552 struct wined3d_sm4_data *priv)
554 enum wined3d_sm4_shader_data_type type;
555 unsigned int icb_size;
557 type = (opcode_token & WINED3D_SM4_SHADER_DATA_TYPE_MASK) >> WINED3D_SM4_SHADER_DATA_TYPE_SHIFT;
558 if (type != WINED3D_SM4_SHADER_DATA_IMMEDIATE_CONSTANT_BUFFER)
560 FIXME("Ignoring shader data type %#x.\n", type);
561 ins->handler_idx = WINED3DSIH_NOP;
562 return;
565 ++tokens;
566 icb_size = token_count - 1;
567 if (icb_size % 4 || icb_size > MAX_IMMEDIATE_CONSTANT_BUFFER_SIZE)
569 FIXME("Unexpected immediate constant buffer size %u.\n", icb_size);
570 ins->handler_idx = WINED3DSIH_TABLE_SIZE;
571 return;
574 priv->icb.vec4_count = icb_size / 4;
575 memcpy(priv->icb.data, tokens, sizeof(*tokens) * icb_size);
576 ins->declaration.icb = &priv->icb;
579 static void shader_sm4_read_dcl_resource(struct wined3d_shader_instruction *ins,
580 DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
581 struct wined3d_sm4_data *priv)
583 enum wined3d_sm4_resource_type resource_type;
584 enum wined3d_sm4_data_type data_type;
585 enum wined3d_data_type reg_data_type;
586 uint32_t components;
588 resource_type = (opcode_token & WINED3D_SM4_RESOURCE_TYPE_MASK) >> WINED3D_SM4_RESOURCE_TYPE_SHIFT;
589 if (!resource_type || (resource_type >= ARRAY_SIZE(resource_type_table)))
591 FIXME("Unhandled resource type %#x.\n", resource_type);
592 ins->declaration.semantic.resource_type = WINED3D_SHADER_RESOURCE_NONE;
594 else
596 ins->declaration.semantic.resource_type = resource_type_table[resource_type];
599 if (ins->declaration.semantic.resource_type == WINED3D_SHADER_RESOURCE_TEXTURE_2DMS
600 || ins->declaration.semantic.resource_type == WINED3D_SHADER_RESOURCE_TEXTURE_2DMSARRAY)
602 ins->declaration.semantic.sample_count = (opcode_token & WINED3D_SM4_RESOURCE_SAMPLE_COUNT_MASK) >> WINED3D_SM4_RESOURCE_SAMPLE_COUNT_SHIFT;
605 reg_data_type = opcode == WINED3D_SM4_OP_DCL_RESOURCE ? WINED3D_DATA_RESOURCE : WINED3D_DATA_UAV;
606 shader_sm4_read_dst_param(priv, &tokens, &tokens[token_count], reg_data_type, &ins->declaration.semantic.reg);
608 components = *tokens++;
609 if ((components & 0xfff0) != (components & 0xf) * 0x1110)
610 FIXME("Components (%#x) have different data types.\n", components);
611 data_type = components & 0xf;
613 if (!data_type || (data_type >= ARRAY_SIZE(data_type_table)))
615 FIXME("Unhandled data type %#x.\n", data_type);
616 ins->declaration.semantic.resource_data_type = WINED3D_DATA_FLOAT;
618 else
620 ins->declaration.semantic.resource_data_type = data_type_table[data_type];
623 if (reg_data_type == WINED3D_DATA_UAV)
624 ins->flags = (opcode_token & WINED3D_SM5_UAV_FLAGS_MASK) >> WINED3D_SM5_UAV_FLAGS_SHIFT;
627 static void shader_sm4_read_dcl_constant_buffer(struct wined3d_shader_instruction *ins,
628 DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
629 struct wined3d_sm4_data *priv)
631 shader_sm4_read_src_param(priv, &tokens, &tokens[token_count], WINED3D_DATA_FLOAT, &ins->declaration.src);
632 if (opcode_token & WINED3D_SM4_INDEX_TYPE_MASK)
633 ins->flags |= WINED3DSI_INDEXED_DYNAMIC;
636 static void shader_sm4_read_dcl_sampler(struct wined3d_shader_instruction *ins,
637 DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
638 struct wined3d_sm4_data *priv)
640 ins->flags = (opcode_token & WINED3D_SM4_SAMPLER_MODE_MASK) >> WINED3D_SM4_SAMPLER_MODE_SHIFT;
641 if (ins->flags & ~WINED3D_SM4_SAMPLER_COMPARISON)
642 FIXME("Unhandled sampler mode %#x.\n", ins->flags);
643 shader_sm4_read_dst_param(priv, &tokens, &tokens[token_count], WINED3D_DATA_SAMPLER, &ins->declaration.dst);
646 static void shader_sm4_read_dcl_index_range(struct wined3d_shader_instruction *ins,
647 DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
648 struct wined3d_sm4_data *priv)
650 shader_sm4_read_dst_param(priv, &tokens, &tokens[token_count], WINED3D_DATA_OPAQUE,
651 &ins->declaration.index_range.first_register);
652 ins->declaration.index_range.last_register = *tokens;
655 static void shader_sm4_read_dcl_output_topology(struct wined3d_shader_instruction *ins,
656 DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
657 struct wined3d_sm4_data *priv)
659 enum wined3d_sm4_output_primitive_type primitive_type;
661 primitive_type = (opcode_token & WINED3D_SM4_PRIMITIVE_TYPE_MASK) >> WINED3D_SM4_PRIMITIVE_TYPE_SHIFT;
662 if (primitive_type >= ARRAY_SIZE(output_primitive_type_table))
663 ins->declaration.primitive_type.type = WINED3D_PT_UNDEFINED;
664 else
665 ins->declaration.primitive_type.type = output_primitive_type_table[primitive_type];
667 if (ins->declaration.primitive_type.type == WINED3D_PT_UNDEFINED)
668 FIXME("Unhandled output primitive type %#x.\n", primitive_type);
671 static void shader_sm4_read_dcl_input_primitive(struct wined3d_shader_instruction *ins,
672 DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
673 struct wined3d_sm4_data *priv)
675 enum wined3d_sm4_input_primitive_type primitive_type;
677 primitive_type = (opcode_token & WINED3D_SM4_PRIMITIVE_TYPE_MASK) >> WINED3D_SM4_PRIMITIVE_TYPE_SHIFT;
678 if (WINED3D_SM5_INPUT_PT_PATCH1 <= primitive_type && primitive_type <= WINED3D_SM5_INPUT_PT_PATCH32)
680 ins->declaration.primitive_type.type = WINED3D_PT_PATCH;
681 ins->declaration.primitive_type.patch_vertex_count = primitive_type - WINED3D_SM5_INPUT_PT_PATCH1 + 1;
683 else if (primitive_type >= ARRAY_SIZE(input_primitive_type_table))
685 ins->declaration.primitive_type.type = WINED3D_PT_UNDEFINED;
687 else
689 ins->declaration.primitive_type.type = input_primitive_type_table[primitive_type];
692 if (ins->declaration.primitive_type.type == WINED3D_PT_UNDEFINED)
693 FIXME("Unhandled input primitive type %#x.\n", primitive_type);
696 static void shader_sm4_read_declaration_count(struct wined3d_shader_instruction *ins,
697 DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
698 struct wined3d_sm4_data *priv)
700 ins->declaration.count = *tokens;
703 static void shader_sm4_read_declaration_dst(struct wined3d_shader_instruction *ins,
704 DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
705 struct wined3d_sm4_data *priv)
707 shader_sm4_read_dst_param(priv, &tokens, &tokens[token_count], WINED3D_DATA_FLOAT, &ins->declaration.dst);
710 static void shader_sm4_read_declaration_register_semantic(struct wined3d_shader_instruction *ins,
711 DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
712 struct wined3d_sm4_data *priv)
714 shader_sm4_read_dst_param(priv, &tokens, &tokens[token_count], WINED3D_DATA_FLOAT,
715 &ins->declaration.register_semantic.reg);
716 ins->declaration.register_semantic.sysval_semantic = *tokens;
719 static void shader_sm4_read_dcl_input_ps(struct wined3d_shader_instruction *ins,
720 DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
721 struct wined3d_sm4_data *priv)
723 ins->flags = (opcode_token & WINED3D_SM4_INTERPOLATION_MODE_MASK) >> WINED3D_SM4_INTERPOLATION_MODE_SHIFT;
724 shader_sm4_read_dst_param(priv, &tokens, &tokens[token_count], WINED3D_DATA_FLOAT, &ins->declaration.dst);
727 static void shader_sm4_read_dcl_input_ps_siv(struct wined3d_shader_instruction *ins,
728 DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
729 struct wined3d_sm4_data *priv)
731 ins->flags = (opcode_token & WINED3D_SM4_INTERPOLATION_MODE_MASK) >> WINED3D_SM4_INTERPOLATION_MODE_SHIFT;
732 shader_sm4_read_dst_param(priv, &tokens, &tokens[token_count], WINED3D_DATA_FLOAT,
733 &ins->declaration.register_semantic.reg);
734 ins->declaration.register_semantic.sysval_semantic = *tokens;
737 static void shader_sm4_read_dcl_indexable_temp(struct wined3d_shader_instruction *ins,
738 DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
739 struct wined3d_sm4_data *priv)
741 ins->declaration.indexable_temp.register_idx = *tokens++;
742 ins->declaration.indexable_temp.register_size = *tokens++;
743 ins->declaration.indexable_temp.component_count = *tokens;
746 static void shader_sm4_read_dcl_global_flags(struct wined3d_shader_instruction *ins,
747 DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
748 struct wined3d_sm4_data *priv)
750 ins->flags = (opcode_token & WINED3D_SM4_GLOBAL_FLAGS_MASK) >> WINED3D_SM4_GLOBAL_FLAGS_SHIFT;
753 static void shader_sm5_read_fcall(struct wined3d_shader_instruction *ins,
754 DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
755 struct wined3d_sm4_data *priv)
757 priv->src_param[0].reg.u.fp_body_idx = *tokens++;
758 shader_sm4_read_src_param(priv, &tokens, &tokens[token_count], WINED3D_DATA_OPAQUE, &priv->src_param[0]);
761 static void shader_sm5_read_dcl_function_body(struct wined3d_shader_instruction *ins,
762 DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
763 struct wined3d_sm4_data *priv)
765 ins->declaration.index = *tokens;
768 static void shader_sm5_read_dcl_function_table(struct wined3d_shader_instruction *ins,
769 DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
770 struct wined3d_sm4_data *priv)
772 ins->declaration.index = *tokens++;
773 FIXME("Ignoring set of function bodies (count %lu).\n", *tokens);
776 static void shader_sm5_read_dcl_interface(struct wined3d_shader_instruction *ins,
777 DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
778 struct wined3d_sm4_data *priv)
780 ins->declaration.fp.index = *tokens++;
781 ins->declaration.fp.body_count = *tokens++;
782 ins->declaration.fp.array_size = *tokens >> WINED3D_SM5_FP_ARRAY_SIZE_SHIFT;
783 ins->declaration.fp.table_count = *tokens++ & WINED3D_SM5_FP_TABLE_COUNT_MASK;
784 FIXME("Ignoring set of function tables (count %u).\n", ins->declaration.fp.table_count);
787 static void shader_sm5_read_control_point_count(struct wined3d_shader_instruction *ins,
788 DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
789 struct wined3d_sm4_data *priv)
791 ins->declaration.count = (opcode_token & WINED3D_SM5_CONTROL_POINT_COUNT_MASK)
792 >> WINED3D_SM5_CONTROL_POINT_COUNT_SHIFT;
795 static void shader_sm5_read_dcl_tessellator_domain(struct wined3d_shader_instruction *ins,
796 DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
797 struct wined3d_sm4_data *priv)
799 ins->declaration.tessellator_domain = (opcode_token & WINED3D_SM5_TESSELLATOR_MASK)
800 >> WINED3D_SM5_TESSELLATOR_SHIFT;
803 static void shader_sm5_read_dcl_tessellator_partitioning(struct wined3d_shader_instruction *ins,
804 DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
805 struct wined3d_sm4_data *priv)
807 ins->declaration.tessellator_partitioning = (opcode_token & WINED3D_SM5_TESSELLATOR_MASK)
808 >> WINED3D_SM5_TESSELLATOR_SHIFT;
811 static void shader_sm5_read_dcl_tessellator_output_primitive(struct wined3d_shader_instruction *ins,
812 DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
813 struct wined3d_sm4_data *priv)
815 ins->declaration.tessellator_output_primitive = (opcode_token & WINED3D_SM5_TESSELLATOR_MASK)
816 >> WINED3D_SM5_TESSELLATOR_SHIFT;
819 static void shader_sm5_read_dcl_hs_max_tessfactor(struct wined3d_shader_instruction *ins,
820 DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
821 struct wined3d_sm4_data *priv)
823 ins->declaration.max_tessellation_factor = *(float *)tokens;
826 static void shader_sm5_read_dcl_thread_group(struct wined3d_shader_instruction *ins,
827 DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
828 struct wined3d_sm4_data *priv)
830 ins->declaration.thread_group_size.x = *tokens++;
831 ins->declaration.thread_group_size.y = *tokens++;
832 ins->declaration.thread_group_size.z = *tokens++;
835 static void shader_sm5_read_dcl_uav_raw(struct wined3d_shader_instruction *ins,
836 DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
837 struct wined3d_sm4_data *priv)
839 shader_sm4_read_dst_param(priv, &tokens, &tokens[token_count], WINED3D_DATA_UAV, &ins->declaration.dst);
840 ins->flags = (opcode_token & WINED3D_SM5_UAV_FLAGS_MASK) >> WINED3D_SM5_UAV_FLAGS_SHIFT;
843 static void shader_sm5_read_dcl_uav_structured(struct wined3d_shader_instruction *ins,
844 DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
845 struct wined3d_sm4_data *priv)
847 shader_sm4_read_dst_param(priv, &tokens, &tokens[token_count], WINED3D_DATA_UAV,
848 &ins->declaration.structured_resource.reg);
849 ins->flags = (opcode_token & WINED3D_SM5_UAV_FLAGS_MASK) >> WINED3D_SM5_UAV_FLAGS_SHIFT;
850 ins->declaration.structured_resource.byte_stride = *tokens;
851 if (ins->declaration.structured_resource.byte_stride % 4)
852 FIXME("Byte stride %u is not multiple of 4.\n", ins->declaration.structured_resource.byte_stride);
855 static void shader_sm5_read_dcl_tgsm_raw(struct wined3d_shader_instruction *ins,
856 DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
857 struct wined3d_sm4_data *priv)
859 shader_sm4_read_dst_param(priv, &tokens, &tokens[token_count], WINED3D_DATA_FLOAT, &ins->declaration.tgsm_raw.reg);
860 ins->declaration.tgsm_raw.byte_count = *tokens;
861 if (ins->declaration.tgsm_raw.byte_count % 4)
862 FIXME("Byte count %u is not multiple of 4.\n", ins->declaration.tgsm_raw.byte_count);
865 static void shader_sm5_read_dcl_tgsm_structured(struct wined3d_shader_instruction *ins,
866 DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
867 struct wined3d_sm4_data *priv)
869 shader_sm4_read_dst_param(priv, &tokens, &tokens[token_count], WINED3D_DATA_FLOAT,
870 &ins->declaration.tgsm_structured.reg);
871 ins->declaration.tgsm_structured.byte_stride = *tokens++;
872 ins->declaration.tgsm_structured.structure_count = *tokens;
873 if (ins->declaration.tgsm_structured.byte_stride % 4)
874 FIXME("Byte stride %u is not multiple of 4.\n", ins->declaration.tgsm_structured.byte_stride);
877 static void shader_sm5_read_dcl_resource_structured(struct wined3d_shader_instruction *ins,
878 DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
879 struct wined3d_sm4_data *priv)
881 shader_sm4_read_dst_param(priv, &tokens, &tokens[token_count], WINED3D_DATA_RESOURCE,
882 &ins->declaration.structured_resource.reg);
883 ins->declaration.structured_resource.byte_stride = *tokens;
884 if (ins->declaration.structured_resource.byte_stride % 4)
885 FIXME("Byte stride %u is not multiple of 4.\n", ins->declaration.structured_resource.byte_stride);
888 static void shader_sm5_read_dcl_resource_raw(struct wined3d_shader_instruction *ins,
889 DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
890 struct wined3d_sm4_data *priv)
892 shader_sm4_read_dst_param(priv, &tokens, &tokens[token_count], WINED3D_DATA_RESOURCE, &ins->declaration.dst);
895 static void shader_sm5_read_sync(struct wined3d_shader_instruction *ins,
896 DWORD opcode, DWORD opcode_token, const DWORD *tokens, unsigned int token_count,
897 struct wined3d_sm4_data *priv)
899 ins->flags = (opcode_token & WINED3D_SM5_SYNC_FLAGS_MASK) >> WINED3D_SM5_SYNC_FLAGS_SHIFT;
903 * f -> WINED3D_DATA_FLOAT
904 * i -> WINED3D_DATA_INT
905 * u -> WINED3D_DATA_UINT
906 * O -> WINED3D_DATA_OPAQUE
907 * R -> WINED3D_DATA_RESOURCE
908 * S -> WINED3D_DATA_SAMPLER
909 * U -> WINED3D_DATA_UAV
911 static const struct wined3d_sm4_opcode_info opcode_table[] =
913 {WINED3D_SM4_OP_ADD, WINED3DSIH_ADD, "f", "ff"},
914 {WINED3D_SM4_OP_AND, WINED3DSIH_AND, "u", "uu"},
915 {WINED3D_SM4_OP_BREAK, WINED3DSIH_BREAK, "", ""},
916 {WINED3D_SM4_OP_BREAKC, WINED3DSIH_BREAKP, "", "u",
917 shader_sm4_read_conditional_op},
918 {WINED3D_SM4_OP_CASE, WINED3DSIH_CASE, "", "u"},
919 {WINED3D_SM4_OP_CONTINUE, WINED3DSIH_CONTINUE, "", ""},
920 {WINED3D_SM4_OP_CONTINUEC, WINED3DSIH_CONTINUEP, "", "u",
921 shader_sm4_read_conditional_op},
922 {WINED3D_SM4_OP_CUT, WINED3DSIH_CUT, "", ""},
923 {WINED3D_SM4_OP_DEFAULT, WINED3DSIH_DEFAULT, "", ""},
924 {WINED3D_SM4_OP_DERIV_RTX, WINED3DSIH_DSX, "f", "f"},
925 {WINED3D_SM4_OP_DERIV_RTY, WINED3DSIH_DSY, "f", "f"},
926 {WINED3D_SM4_OP_DISCARD, WINED3DSIH_TEXKILL, "", "u",
927 shader_sm4_read_conditional_op},
928 {WINED3D_SM4_OP_DIV, WINED3DSIH_DIV, "f", "ff"},
929 {WINED3D_SM4_OP_DP2, WINED3DSIH_DP2, "f", "ff"},
930 {WINED3D_SM4_OP_DP3, WINED3DSIH_DP3, "f", "ff"},
931 {WINED3D_SM4_OP_DP4, WINED3DSIH_DP4, "f", "ff"},
932 {WINED3D_SM4_OP_ELSE, WINED3DSIH_ELSE, "", ""},
933 {WINED3D_SM4_OP_EMIT, WINED3DSIH_EMIT, "", ""},
934 {WINED3D_SM4_OP_ENDIF, WINED3DSIH_ENDIF, "", ""},
935 {WINED3D_SM4_OP_ENDLOOP, WINED3DSIH_ENDLOOP, "", ""},
936 {WINED3D_SM4_OP_ENDSWITCH, WINED3DSIH_ENDSWITCH, "", ""},
937 {WINED3D_SM4_OP_EQ, WINED3DSIH_EQ, "u", "ff"},
938 {WINED3D_SM4_OP_EXP, WINED3DSIH_EXP, "f", "f"},
939 {WINED3D_SM4_OP_FRC, WINED3DSIH_FRC, "f", "f"},
940 {WINED3D_SM4_OP_FTOI, WINED3DSIH_FTOI, "i", "f"},
941 {WINED3D_SM4_OP_FTOU, WINED3DSIH_FTOU, "u", "f"},
942 {WINED3D_SM4_OP_GE, WINED3DSIH_GE, "u", "ff"},
943 {WINED3D_SM4_OP_IADD, WINED3DSIH_IADD, "i", "ii"},
944 {WINED3D_SM4_OP_IF, WINED3DSIH_IF, "", "u",
945 shader_sm4_read_conditional_op},
946 {WINED3D_SM4_OP_IEQ, WINED3DSIH_IEQ, "u", "ii"},
947 {WINED3D_SM4_OP_IGE, WINED3DSIH_IGE, "u", "ii"},
948 {WINED3D_SM4_OP_ILT, WINED3DSIH_ILT, "u", "ii"},
949 {WINED3D_SM4_OP_IMAD, WINED3DSIH_IMAD, "i", "iii"},
950 {WINED3D_SM4_OP_IMAX, WINED3DSIH_IMAX, "i", "ii"},
951 {WINED3D_SM4_OP_IMIN, WINED3DSIH_IMIN, "i", "ii"},
952 {WINED3D_SM4_OP_IMUL, WINED3DSIH_IMUL, "ii", "ii"},
953 {WINED3D_SM4_OP_INE, WINED3DSIH_INE, "u", "ii"},
954 {WINED3D_SM4_OP_INEG, WINED3DSIH_INEG, "i", "i"},
955 {WINED3D_SM4_OP_ISHL, WINED3DSIH_ISHL, "i", "ii"},
956 {WINED3D_SM4_OP_ISHR, WINED3DSIH_ISHR, "i", "ii"},
957 {WINED3D_SM4_OP_ITOF, WINED3DSIH_ITOF, "f", "i"},
958 {WINED3D_SM4_OP_LABEL, WINED3DSIH_LABEL, "", "O"},
959 {WINED3D_SM4_OP_LD, WINED3DSIH_LD, "u", "iR"},
960 {WINED3D_SM4_OP_LD2DMS, WINED3DSIH_LD2DMS, "u", "iRi"},
961 {WINED3D_SM4_OP_LOG, WINED3DSIH_LOG, "f", "f"},
962 {WINED3D_SM4_OP_LOOP, WINED3DSIH_LOOP, "", ""},
963 {WINED3D_SM4_OP_LT, WINED3DSIH_LT, "u", "ff"},
964 {WINED3D_SM4_OP_MAD, WINED3DSIH_MAD, "f", "fff"},
965 {WINED3D_SM4_OP_MIN, WINED3DSIH_MIN, "f", "ff"},
966 {WINED3D_SM4_OP_MAX, WINED3DSIH_MAX, "f", "ff"},
967 {WINED3D_SM4_OP_SHADER_DATA, WINED3DSIH_DCL_IMMEDIATE_CONSTANT_BUFFER, "", "",
968 shader_sm4_read_shader_data},
969 {WINED3D_SM4_OP_MOV, WINED3DSIH_MOV, "f", "f"},
970 {WINED3D_SM4_OP_MOVC, WINED3DSIH_MOVC, "f", "uff"},
971 {WINED3D_SM4_OP_MUL, WINED3DSIH_MUL, "f", "ff"},
972 {WINED3D_SM4_OP_NE, WINED3DSIH_NE, "u", "ff"},
973 {WINED3D_SM4_OP_NOP, WINED3DSIH_NOP, "", ""},
974 {WINED3D_SM4_OP_NOT, WINED3DSIH_NOT, "u", "u"},
975 {WINED3D_SM4_OP_OR, WINED3DSIH_OR, "u", "uu"},
976 {WINED3D_SM4_OP_RESINFO, WINED3DSIH_RESINFO, "f", "iR"},
977 {WINED3D_SM4_OP_RET, WINED3DSIH_RET, "", ""},
978 {WINED3D_SM4_OP_RETC, WINED3DSIH_RETP, "", "u",
979 shader_sm4_read_conditional_op},
980 {WINED3D_SM4_OP_ROUND_NE, WINED3DSIH_ROUND_NE, "f", "f"},
981 {WINED3D_SM4_OP_ROUND_NI, WINED3DSIH_ROUND_NI, "f", "f"},
982 {WINED3D_SM4_OP_ROUND_PI, WINED3DSIH_ROUND_PI, "f", "f"},
983 {WINED3D_SM4_OP_ROUND_Z, WINED3DSIH_ROUND_Z, "f", "f"},
984 {WINED3D_SM4_OP_RSQ, WINED3DSIH_RSQ, "f", "f"},
985 {WINED3D_SM4_OP_SAMPLE, WINED3DSIH_SAMPLE, "u", "fRS"},
986 {WINED3D_SM4_OP_SAMPLE_C, WINED3DSIH_SAMPLE_C, "f", "fRSf"},
987 {WINED3D_SM4_OP_SAMPLE_C_LZ, WINED3DSIH_SAMPLE_C_LZ, "f", "fRSf"},
988 {WINED3D_SM4_OP_SAMPLE_LOD, WINED3DSIH_SAMPLE_LOD, "u", "fRSf"},
989 {WINED3D_SM4_OP_SAMPLE_GRAD, WINED3DSIH_SAMPLE_GRAD, "u", "fRSff"},
990 {WINED3D_SM4_OP_SAMPLE_B, WINED3DSIH_SAMPLE_B, "u", "fRSf"},
991 {WINED3D_SM4_OP_SQRT, WINED3DSIH_SQRT, "f", "f"},
992 {WINED3D_SM4_OP_SWITCH, WINED3DSIH_SWITCH, "", "u"},
993 {WINED3D_SM4_OP_SINCOS, WINED3DSIH_SINCOS, "ff", "f"},
994 {WINED3D_SM4_OP_UDIV, WINED3DSIH_UDIV, "uu", "uu"},
995 {WINED3D_SM4_OP_ULT, WINED3DSIH_ULT, "u", "uu"},
996 {WINED3D_SM4_OP_UGE, WINED3DSIH_UGE, "u", "uu"},
997 {WINED3D_SM4_OP_UMUL, WINED3DSIH_UMUL, "uu", "uu"},
998 {WINED3D_SM4_OP_UMAX, WINED3DSIH_UMAX, "u", "uu"},
999 {WINED3D_SM4_OP_UMIN, WINED3DSIH_UMIN, "u", "uu"},
1000 {WINED3D_SM4_OP_USHR, WINED3DSIH_USHR, "u", "uu"},
1001 {WINED3D_SM4_OP_UTOF, WINED3DSIH_UTOF, "f", "u"},
1002 {WINED3D_SM4_OP_XOR, WINED3DSIH_XOR, "u", "uu"},
1003 {WINED3D_SM4_OP_DCL_RESOURCE, WINED3DSIH_DCL, "R", "",
1004 shader_sm4_read_dcl_resource},
1005 {WINED3D_SM4_OP_DCL_CONSTANT_BUFFER, WINED3DSIH_DCL_CONSTANT_BUFFER, "", "",
1006 shader_sm4_read_dcl_constant_buffer},
1007 {WINED3D_SM4_OP_DCL_SAMPLER, WINED3DSIH_DCL_SAMPLER, "", "",
1008 shader_sm4_read_dcl_sampler},
1009 {WINED3D_SM4_OP_DCL_INDEX_RANGE, WINED3DSIH_DCL_INDEX_RANGE, "", "",
1010 shader_sm4_read_dcl_index_range},
1011 {WINED3D_SM4_OP_DCL_OUTPUT_TOPOLOGY, WINED3DSIH_DCL_OUTPUT_TOPOLOGY, "", "",
1012 shader_sm4_read_dcl_output_topology},
1013 {WINED3D_SM4_OP_DCL_INPUT_PRIMITIVE, WINED3DSIH_DCL_INPUT_PRIMITIVE, "", "",
1014 shader_sm4_read_dcl_input_primitive},
1015 {WINED3D_SM4_OP_DCL_VERTICES_OUT, WINED3DSIH_DCL_VERTICES_OUT, "", "",
1016 shader_sm4_read_declaration_count},
1017 {WINED3D_SM4_OP_DCL_INPUT, WINED3DSIH_DCL_INPUT, "", "",
1018 shader_sm4_read_declaration_dst},
1019 {WINED3D_SM4_OP_DCL_INPUT_SGV, WINED3DSIH_DCL_INPUT_SGV, "", "",
1020 shader_sm4_read_declaration_register_semantic},
1021 {WINED3D_SM4_OP_DCL_INPUT_SIV, WINED3DSIH_DCL_INPUT_SIV, "", "",
1022 shader_sm4_read_declaration_register_semantic},
1023 {WINED3D_SM4_OP_DCL_INPUT_PS, WINED3DSIH_DCL_INPUT_PS, "", "",
1024 shader_sm4_read_dcl_input_ps},
1025 {WINED3D_SM4_OP_DCL_INPUT_PS_SGV, WINED3DSIH_DCL_INPUT_PS_SGV, "", "",
1026 shader_sm4_read_declaration_register_semantic},
1027 {WINED3D_SM4_OP_DCL_INPUT_PS_SIV, WINED3DSIH_DCL_INPUT_PS_SIV, "", "",
1028 shader_sm4_read_dcl_input_ps_siv},
1029 {WINED3D_SM4_OP_DCL_OUTPUT, WINED3DSIH_DCL_OUTPUT, "", "",
1030 shader_sm4_read_declaration_dst},
1031 {WINED3D_SM4_OP_DCL_OUTPUT_SIV, WINED3DSIH_DCL_OUTPUT_SIV, "", "",
1032 shader_sm4_read_declaration_register_semantic},
1033 {WINED3D_SM4_OP_DCL_TEMPS, WINED3DSIH_DCL_TEMPS, "", "",
1034 shader_sm4_read_declaration_count},
1035 {WINED3D_SM4_OP_DCL_INDEXABLE_TEMP, WINED3DSIH_DCL_INDEXABLE_TEMP, "", "",
1036 shader_sm4_read_dcl_indexable_temp},
1037 {WINED3D_SM4_OP_DCL_GLOBAL_FLAGS, WINED3DSIH_DCL_GLOBAL_FLAGS, "", "",
1038 shader_sm4_read_dcl_global_flags},
1039 {WINED3D_SM4_OP_LOD, WINED3DSIH_LOD, "f", "fRS"},
1040 {WINED3D_SM4_OP_GATHER4, WINED3DSIH_GATHER4, "u", "fRS"},
1041 {WINED3D_SM4_OP_SAMPLE_POS, WINED3DSIH_SAMPLE_POS, "f", "Ru"},
1042 {WINED3D_SM4_OP_SAMPLE_INFO, WINED3DSIH_SAMPLE_INFO, "f", "R"},
1043 {WINED3D_SM5_OP_HS_DECLS, WINED3DSIH_HS_DECLS, "", ""},
1044 {WINED3D_SM5_OP_HS_CONTROL_POINT_PHASE, WINED3DSIH_HS_CONTROL_POINT_PHASE, "", ""},
1045 {WINED3D_SM5_OP_HS_FORK_PHASE, WINED3DSIH_HS_FORK_PHASE, "", ""},
1046 {WINED3D_SM5_OP_HS_JOIN_PHASE, WINED3DSIH_HS_JOIN_PHASE, "", ""},
1047 {WINED3D_SM5_OP_EMIT_STREAM, WINED3DSIH_EMIT_STREAM, "", "f"},
1048 {WINED3D_SM5_OP_CUT_STREAM, WINED3DSIH_CUT_STREAM, "", "f"},
1049 {WINED3D_SM5_OP_FCALL, WINED3DSIH_FCALL, "", "O",
1050 shader_sm5_read_fcall},
1051 {WINED3D_SM5_OP_BUFINFO, WINED3DSIH_BUFINFO, "i", "U"},
1052 {WINED3D_SM5_OP_DERIV_RTX_COARSE, WINED3DSIH_DSX_COARSE, "f", "f"},
1053 {WINED3D_SM5_OP_DERIV_RTX_FINE, WINED3DSIH_DSX_FINE, "f", "f"},
1054 {WINED3D_SM5_OP_DERIV_RTY_COARSE, WINED3DSIH_DSY_COARSE, "f", "f"},
1055 {WINED3D_SM5_OP_DERIV_RTY_FINE, WINED3DSIH_DSY_FINE, "f", "f"},
1056 {WINED3D_SM5_OP_GATHER4_C, WINED3DSIH_GATHER4_C, "f", "fRSf"},
1057 {WINED3D_SM5_OP_GATHER4_PO, WINED3DSIH_GATHER4_PO, "f", "fiRS"},
1058 {WINED3D_SM5_OP_GATHER4_PO_C, WINED3DSIH_GATHER4_PO_C, "f", "fiRSf"},
1059 {WINED3D_SM5_OP_RCP, WINED3DSIH_RCP, "f", "f"},
1060 {WINED3D_SM5_OP_F32TOF16, WINED3DSIH_F32TOF16, "u", "f"},
1061 {WINED3D_SM5_OP_F16TOF32, WINED3DSIH_F16TOF32, "f", "u"},
1062 {WINED3D_SM5_OP_COUNTBITS, WINED3DSIH_COUNTBITS, "u", "u"},
1063 {WINED3D_SM5_OP_FIRSTBIT_HI, WINED3DSIH_FIRSTBIT_HI, "u", "u"},
1064 {WINED3D_SM5_OP_FIRSTBIT_LO, WINED3DSIH_FIRSTBIT_LO, "u", "u"},
1065 {WINED3D_SM5_OP_FIRSTBIT_SHI, WINED3DSIH_FIRSTBIT_SHI, "u", "i"},
1066 {WINED3D_SM5_OP_UBFE, WINED3DSIH_UBFE, "u", "iiu"},
1067 {WINED3D_SM5_OP_IBFE, WINED3DSIH_IBFE, "i", "iii"},
1068 {WINED3D_SM5_OP_BFI, WINED3DSIH_BFI, "u", "iiuu"},
1069 {WINED3D_SM5_OP_BFREV, WINED3DSIH_BFREV, "u", "u"},
1070 {WINED3D_SM5_OP_SWAPC, WINED3DSIH_SWAPC, "ff", "uff"},
1071 {WINED3D_SM5_OP_DCL_STREAM, WINED3DSIH_DCL_STREAM, "", "O"},
1072 {WINED3D_SM5_OP_DCL_FUNCTION_BODY, WINED3DSIH_DCL_FUNCTION_BODY, "", "",
1073 shader_sm5_read_dcl_function_body},
1074 {WINED3D_SM5_OP_DCL_FUNCTION_TABLE, WINED3DSIH_DCL_FUNCTION_TABLE, "", "",
1075 shader_sm5_read_dcl_function_table},
1076 {WINED3D_SM5_OP_DCL_INTERFACE, WINED3DSIH_DCL_INTERFACE, "", "",
1077 shader_sm5_read_dcl_interface},
1078 {WINED3D_SM5_OP_DCL_INPUT_CONTROL_POINT_COUNT, WINED3DSIH_DCL_INPUT_CONTROL_POINT_COUNT, "", "",
1079 shader_sm5_read_control_point_count},
1080 {WINED3D_SM5_OP_DCL_OUTPUT_CONTROL_POINT_COUNT, WINED3DSIH_DCL_OUTPUT_CONTROL_POINT_COUNT, "", "",
1081 shader_sm5_read_control_point_count},
1082 {WINED3D_SM5_OP_DCL_TESSELLATOR_DOMAIN, WINED3DSIH_DCL_TESSELLATOR_DOMAIN, "", "",
1083 shader_sm5_read_dcl_tessellator_domain},
1084 {WINED3D_SM5_OP_DCL_TESSELLATOR_PARTITIONING, WINED3DSIH_DCL_TESSELLATOR_PARTITIONING, "", "",
1085 shader_sm5_read_dcl_tessellator_partitioning},
1086 {WINED3D_SM5_OP_DCL_TESSELLATOR_OUTPUT_PRIMITIVE, WINED3DSIH_DCL_TESSELLATOR_OUTPUT_PRIMITIVE, "", "",
1087 shader_sm5_read_dcl_tessellator_output_primitive},
1088 {WINED3D_SM5_OP_DCL_HS_MAX_TESSFACTOR, WINED3DSIH_DCL_HS_MAX_TESSFACTOR, "", "",
1089 shader_sm5_read_dcl_hs_max_tessfactor},
1090 {WINED3D_SM5_OP_DCL_HS_FORK_PHASE_INSTANCE_COUNT, WINED3DSIH_DCL_HS_FORK_PHASE_INSTANCE_COUNT, "", "",
1091 shader_sm4_read_declaration_count},
1092 {WINED3D_SM5_OP_DCL_HS_JOIN_PHASE_INSTANCE_COUNT, WINED3DSIH_DCL_HS_JOIN_PHASE_INSTANCE_COUNT, "", "",
1093 shader_sm4_read_declaration_count},
1094 {WINED3D_SM5_OP_DCL_THREAD_GROUP, WINED3DSIH_DCL_THREAD_GROUP, "", "",
1095 shader_sm5_read_dcl_thread_group},
1096 {WINED3D_SM5_OP_DCL_UAV_TYPED, WINED3DSIH_DCL_UAV_TYPED, "", "",
1097 shader_sm4_read_dcl_resource},
1098 {WINED3D_SM5_OP_DCL_UAV_RAW, WINED3DSIH_DCL_UAV_RAW, "", "",
1099 shader_sm5_read_dcl_uav_raw},
1100 {WINED3D_SM5_OP_DCL_UAV_STRUCTURED, WINED3DSIH_DCL_UAV_STRUCTURED, "", "",
1101 shader_sm5_read_dcl_uav_structured},
1102 {WINED3D_SM5_OP_DCL_TGSM_RAW, WINED3DSIH_DCL_TGSM_RAW, "", "",
1103 shader_sm5_read_dcl_tgsm_raw},
1104 {WINED3D_SM5_OP_DCL_TGSM_STRUCTURED, WINED3DSIH_DCL_TGSM_STRUCTURED, "", "",
1105 shader_sm5_read_dcl_tgsm_structured},
1106 {WINED3D_SM5_OP_DCL_RESOURCE_RAW, WINED3DSIH_DCL_RESOURCE_RAW, "", "",
1107 shader_sm5_read_dcl_resource_raw},
1108 {WINED3D_SM5_OP_DCL_RESOURCE_STRUCTURED, WINED3DSIH_DCL_RESOURCE_STRUCTURED, "", "",
1109 shader_sm5_read_dcl_resource_structured},
1110 {WINED3D_SM5_OP_LD_UAV_TYPED, WINED3DSIH_LD_UAV_TYPED, "u", "iU"},
1111 {WINED3D_SM5_OP_STORE_UAV_TYPED, WINED3DSIH_STORE_UAV_TYPED, "U", "iu"},
1112 {WINED3D_SM5_OP_LD_RAW, WINED3DSIH_LD_RAW, "u", "iU"},
1113 {WINED3D_SM5_OP_STORE_RAW, WINED3DSIH_STORE_RAW, "U", "iu"},
1114 {WINED3D_SM5_OP_LD_STRUCTURED, WINED3DSIH_LD_STRUCTURED, "u", "iiR"},
1115 {WINED3D_SM5_OP_STORE_STRUCTURED, WINED3DSIH_STORE_STRUCTURED, "U", "iiu"},
1116 {WINED3D_SM5_OP_ATOMIC_AND, WINED3DSIH_ATOMIC_AND, "U", "iu"},
1117 {WINED3D_SM5_OP_ATOMIC_OR, WINED3DSIH_ATOMIC_OR, "U", "iu"},
1118 {WINED3D_SM5_OP_ATOMIC_XOR, WINED3DSIH_ATOMIC_XOR, "U", "iu"},
1119 {WINED3D_SM5_OP_ATOMIC_CMP_STORE, WINED3DSIH_ATOMIC_CMP_STORE, "U", "iuu"},
1120 {WINED3D_SM5_OP_ATOMIC_IADD, WINED3DSIH_ATOMIC_IADD, "U", "ii"},
1121 {WINED3D_SM5_OP_ATOMIC_IMAX, WINED3DSIH_ATOMIC_IMAX, "U", "ii"},
1122 {WINED3D_SM5_OP_ATOMIC_IMIN, WINED3DSIH_ATOMIC_IMIN, "U", "ii"},
1123 {WINED3D_SM5_OP_ATOMIC_UMAX, WINED3DSIH_ATOMIC_UMAX, "U", "iu"},
1124 {WINED3D_SM5_OP_ATOMIC_UMIN, WINED3DSIH_ATOMIC_UMIN, "U", "iu"},
1125 {WINED3D_SM5_OP_IMM_ATOMIC_ALLOC, WINED3DSIH_IMM_ATOMIC_ALLOC, "u", "U"},
1126 {WINED3D_SM5_OP_IMM_ATOMIC_CONSUME, WINED3DSIH_IMM_ATOMIC_CONSUME, "u", "U"},
1127 {WINED3D_SM5_OP_IMM_ATOMIC_IADD, WINED3DSIH_IMM_ATOMIC_IADD, "uU", "ii"},
1128 {WINED3D_SM5_OP_IMM_ATOMIC_AND, WINED3DSIH_IMM_ATOMIC_AND, "uU", "iu"},
1129 {WINED3D_SM5_OP_IMM_ATOMIC_OR, WINED3DSIH_IMM_ATOMIC_OR, "uU", "iu"},
1130 {WINED3D_SM5_OP_IMM_ATOMIC_XOR, WINED3DSIH_IMM_ATOMIC_XOR, "uU", "iu"},
1131 {WINED3D_SM5_OP_IMM_ATOMIC_EXCH, WINED3DSIH_IMM_ATOMIC_EXCH, "uU", "iu"},
1132 {WINED3D_SM5_OP_IMM_ATOMIC_CMP_EXCH, WINED3DSIH_IMM_ATOMIC_CMP_EXCH, "uU", "iuu"},
1133 {WINED3D_SM5_OP_IMM_ATOMIC_IMAX, WINED3DSIH_IMM_ATOMIC_IMAX, "iU", "ii"},
1134 {WINED3D_SM5_OP_IMM_ATOMIC_IMIN, WINED3DSIH_IMM_ATOMIC_IMIN, "iU", "ii"},
1135 {WINED3D_SM5_OP_IMM_ATOMIC_UMAX, WINED3DSIH_IMM_ATOMIC_UMAX, "uU", "iu"},
1136 {WINED3D_SM5_OP_IMM_ATOMIC_UMIN, WINED3DSIH_IMM_ATOMIC_UMIN, "uU", "iu"},
1137 {WINED3D_SM5_OP_SYNC, WINED3DSIH_SYNC, "", "",
1138 shader_sm5_read_sync},
1139 {WINED3D_SM5_OP_EVAL_SAMPLE_INDEX, WINED3DSIH_EVAL_SAMPLE_INDEX, "f", "fi"},
1140 {WINED3D_SM5_OP_EVAL_CENTROID, WINED3DSIH_EVAL_CENTROID, "f", "f"},
1141 {WINED3D_SM5_OP_DCL_GS_INSTANCES, WINED3DSIH_DCL_GS_INSTANCES, "", "",
1142 shader_sm4_read_declaration_count},
1145 static const enum wined3d_shader_register_type register_type_table[] =
1147 /* WINED3D_SM4_RT_TEMP */ WINED3DSPR_TEMP,
1148 /* WINED3D_SM4_RT_INPUT */ WINED3DSPR_INPUT,
1149 /* WINED3D_SM4_RT_OUTPUT */ WINED3DSPR_OUTPUT,
1150 /* WINED3D_SM4_RT_INDEXABLE_TEMP */ WINED3DSPR_IDXTEMP,
1151 /* WINED3D_SM4_RT_IMMCONST */ WINED3DSPR_IMMCONST,
1152 /* UNKNOWN */ ~0u,
1153 /* WINED3D_SM4_RT_SAMPLER */ WINED3DSPR_SAMPLER,
1154 /* WINED3D_SM4_RT_RESOURCE */ WINED3DSPR_RESOURCE,
1155 /* WINED3D_SM4_RT_CONSTBUFFER */ WINED3DSPR_CONSTBUFFER,
1156 /* WINED3D_SM4_RT_IMMCONSTBUFFER */ WINED3DSPR_IMMCONSTBUFFER,
1157 /* UNKNOWN */ ~0u,
1158 /* WINED3D_SM4_RT_PRIMID */ WINED3DSPR_PRIMID,
1159 /* WINED3D_SM4_RT_DEPTHOUT */ WINED3DSPR_DEPTHOUT,
1160 /* WINED3D_SM4_RT_NULL */ WINED3DSPR_NULL,
1161 /* WINED3D_SM4_RT_RASTERIZER */ WINED3DSPR_RASTERIZER,
1162 /* WINED3D_SM4_RT_OMASK */ WINED3DSPR_SAMPLEMASK,
1163 /* WINED3D_SM5_RT_STREAM */ WINED3DSPR_STREAM,
1164 /* WINED3D_SM5_RT_FUNCTION_BODY */ WINED3DSPR_FUNCTIONBODY,
1165 /* UNKNOWN */ ~0u,
1166 /* WINED3D_SM5_RT_FUNCTION_POINTER */ WINED3DSPR_FUNCTIONPOINTER,
1167 /* UNKNOWN */ ~0u,
1168 /* UNKNOWN */ ~0u,
1169 /* WINED3D_SM5_RT_OUTPUT_CONTROL_POINT_ID */ WINED3DSPR_OUTPOINTID,
1170 /* WINED3D_SM5_RT_FORK_INSTANCE_ID */ WINED3DSPR_FORKINSTID,
1171 /* WINED3D_SM5_RT_JOIN_INSTANCE_ID */ WINED3DSPR_JOININSTID,
1172 /* WINED3D_SM5_RT_INPUT_CONTROL_POINT */ WINED3DSPR_INCONTROLPOINT,
1173 /* WINED3D_SM5_RT_OUTPUT_CONTROL_POINT */ WINED3DSPR_OUTCONTROLPOINT,
1174 /* WINED3D_SM5_RT_PATCH_CONSTANT_DATA */ WINED3DSPR_PATCHCONST,
1175 /* WINED3D_SM5_RT_DOMAIN_LOCATION */ WINED3DSPR_TESSCOORD,
1176 /* UNKNOWN */ ~0u,
1177 /* WINED3D_SM5_RT_UAV */ WINED3DSPR_UAV,
1178 /* WINED3D_SM5_RT_SHARED_MEMORY */ WINED3DSPR_GROUPSHAREDMEM,
1179 /* WINED3D_SM5_RT_THREAD_ID */ WINED3DSPR_THREADID,
1180 /* WINED3D_SM5_RT_THREAD_GROUP_ID */ WINED3DSPR_THREADGROUPID,
1181 /* WINED3D_SM5_RT_LOCAL_THREAD_ID */ WINED3DSPR_LOCALTHREADID,
1182 /* WINED3D_SM5_RT_COVERAGE */ WINED3DSPR_COVERAGE,
1183 /* WINED3D_SM5_RT_LOCAL_THREAD_INDEX */ WINED3DSPR_LOCALTHREADINDEX,
1184 /* WINED3D_SM5_RT_GS_INSTANCE_ID */ WINED3DSPR_GSINSTID,
1185 /* WINED3D_SM5_RT_DEPTHOUT_GREATER_EQUAL */ WINED3DSPR_DEPTHOUTGE,
1186 /* WINED3D_SM5_RT_DEPTHOUT_LESS_EQUAL */ WINED3DSPR_DEPTHOUTLE,
1189 static const struct wined3d_sm4_opcode_info *get_opcode_info(enum wined3d_sm4_opcode opcode)
1191 unsigned int i;
1193 for (i = 0; i < ARRAY_SIZE(opcode_table); ++i)
1195 if (opcode == opcode_table[i].opcode) return &opcode_table[i];
1198 return NULL;
1201 static void map_register(const struct wined3d_sm4_data *priv, struct wined3d_shader_register *reg)
1203 switch (priv->shader_version.type)
1205 case WINED3D_SHADER_TYPE_PIXEL:
1206 if (reg->type == WINED3DSPR_OUTPUT)
1208 unsigned int reg_idx = reg->idx[0].offset;
1210 if (reg_idx >= ARRAY_SIZE(priv->output_map))
1212 ERR("Invalid output index %u.\n", reg_idx);
1213 break;
1216 reg->type = WINED3DSPR_COLOROUT;
1217 reg->idx[0].offset = priv->output_map[reg_idx];
1219 break;
1221 default:
1222 break;
1226 static enum wined3d_data_type map_data_type(char t)
1228 switch (t)
1230 case 'f':
1231 return WINED3D_DATA_FLOAT;
1232 case 'i':
1233 return WINED3D_DATA_INT;
1234 case 'u':
1235 return WINED3D_DATA_UINT;
1236 case 'O':
1237 return WINED3D_DATA_OPAQUE;
1238 case 'R':
1239 return WINED3D_DATA_RESOURCE;
1240 case 'S':
1241 return WINED3D_DATA_SAMPLER;
1242 case 'U':
1243 return WINED3D_DATA_UAV;
1244 default:
1245 ERR("Invalid data type '%c'.\n", t);
1246 return WINED3D_DATA_FLOAT;
1250 static enum wined3d_shader_type wined3d_get_sm4_shader_type(const DWORD *byte_code, size_t byte_code_size)
1252 unsigned int shader_type;
1254 if (byte_code_size / sizeof(*byte_code) < 1)
1256 WARN("Invalid byte code size %lu.\n", (long)byte_code_size);
1257 return WINED3D_SHADER_TYPE_INVALID;
1260 shader_type = byte_code[0] >> 16;
1261 switch (shader_type)
1263 case WINED3D_SM4_PS:
1264 return WINED3D_SHADER_TYPE_PIXEL;
1265 break;
1266 case WINED3D_SM4_VS:
1267 return WINED3D_SHADER_TYPE_VERTEX;
1268 break;
1269 case WINED3D_SM4_GS:
1270 return WINED3D_SHADER_TYPE_GEOMETRY;
1271 break;
1272 case WINED3D_SM5_HS:
1273 return WINED3D_SHADER_TYPE_HULL;
1274 break;
1275 case WINED3D_SM5_DS:
1276 return WINED3D_SHADER_TYPE_DOMAIN;
1277 break;
1278 case WINED3D_SM5_CS:
1279 return WINED3D_SHADER_TYPE_COMPUTE;
1280 break;
1281 default:
1282 FIXME("Unrecognised shader type %#x.\n", shader_type);
1283 return WINED3D_SHADER_TYPE_INVALID;
1287 static void *shader_sm4_init(const DWORD *byte_code, size_t byte_code_size,
1288 const struct wined3d_shader_signature *output_signature)
1290 unsigned int version_token, token_count;
1291 struct wined3d_sm4_data *priv;
1292 unsigned int i;
1294 if (byte_code_size / sizeof(*byte_code) < 2)
1296 WARN("Invalid byte code size %lu.\n", (long)byte_code_size);
1297 return NULL;
1300 version_token = byte_code[0];
1301 TRACE("Version: 0x%08x.\n", version_token);
1302 token_count = byte_code[1];
1303 TRACE("Token count: %u.\n", token_count);
1305 if (token_count < 2 || byte_code_size / sizeof(*byte_code) < token_count)
1307 WARN("Invalid token count %u.\n", token_count);
1308 return NULL;
1311 if (!(priv = heap_alloc(sizeof(*priv))))
1313 ERR("Failed to allocate private data\n");
1314 return NULL;
1317 priv->start = &byte_code[2];
1318 priv->end = &byte_code[token_count];
1320 priv->shader_version.type = wined3d_get_sm4_shader_type(byte_code, byte_code_size);
1321 if (priv->shader_version.type == WINED3D_SHADER_TYPE_INVALID)
1323 heap_free(priv);
1324 return NULL;
1327 priv->shader_version.major = WINED3D_SM4_VERSION_MAJOR(version_token);
1328 priv->shader_version.minor = WINED3D_SM4_VERSION_MINOR(version_token);
1330 memset(priv->output_map, 0xff, sizeof(priv->output_map));
1331 for (i = 0; i < output_signature->element_count; ++i)
1333 struct wined3d_shader_signature_element *e = &output_signature->elements[i];
1335 if (priv->shader_version.type == WINED3D_SHADER_TYPE_PIXEL
1336 && stricmp(e->semantic_name, "SV_TARGET"))
1337 continue;
1338 if (e->register_idx >= ARRAY_SIZE(priv->output_map))
1340 WARN("Invalid output index %u.\n", e->register_idx);
1341 continue;
1344 priv->output_map[e->register_idx] = e->semantic_idx;
1347 list_init(&priv->src_free);
1348 list_init(&priv->src);
1350 return priv;
1353 static void shader_sm4_free(void *data)
1355 struct wined3d_shader_src_param_entry *e1, *e2;
1356 struct wined3d_sm4_data *priv = data;
1358 list_move_head(&priv->src_free, &priv->src);
1359 LIST_FOR_EACH_ENTRY_SAFE(e1, e2, &priv->src_free, struct wined3d_shader_src_param_entry, entry)
1361 heap_free(e1);
1363 heap_free(priv);
1366 static struct wined3d_shader_src_param *get_src_param(struct wined3d_sm4_data *priv)
1368 struct wined3d_shader_src_param_entry *e;
1369 struct list *elem;
1371 if (!list_empty(&priv->src_free))
1373 elem = list_head(&priv->src_free);
1374 list_remove(elem);
1376 else
1378 if (!(e = heap_alloc(sizeof(*e))))
1379 return NULL;
1380 elem = &e->entry;
1383 list_add_tail(&priv->src, elem);
1384 e = LIST_ENTRY(elem, struct wined3d_shader_src_param_entry, entry);
1385 return &e->param;
1388 static void shader_sm4_read_header(void *data, const DWORD **ptr, struct wined3d_shader_version *shader_version)
1390 struct wined3d_sm4_data *priv = data;
1392 *ptr = priv->start;
1393 *shader_version = priv->shader_version;
1396 static BOOL shader_sm4_read_reg_idx(struct wined3d_sm4_data *priv, const DWORD **ptr, const DWORD *end,
1397 DWORD addressing, struct wined3d_shader_register_index *reg_idx)
1399 if (addressing & WINED3D_SM4_ADDRESSING_RELATIVE)
1401 struct wined3d_shader_src_param *rel_addr = get_src_param(priv);
1403 if (!(reg_idx->rel_addr = rel_addr))
1405 ERR("Failed to get src param for relative addressing.\n");
1406 return FALSE;
1409 if (addressing & WINED3D_SM4_ADDRESSING_OFFSET)
1410 reg_idx->offset = *(*ptr)++;
1411 else
1412 reg_idx->offset = 0;
1413 shader_sm4_read_src_param(priv, ptr, end, WINED3D_DATA_INT, rel_addr);
1415 else
1417 reg_idx->rel_addr = NULL;
1418 reg_idx->offset = *(*ptr)++;
1421 return TRUE;
1424 static BOOL shader_sm4_read_param(struct wined3d_sm4_data *priv, const DWORD **ptr, const DWORD *end,
1425 enum wined3d_data_type data_type, struct wined3d_shader_register *param,
1426 enum wined3d_shader_src_modifier *modifier)
1428 enum wined3d_sm4_register_type register_type;
1429 uint32_t token, order;
1431 if (*ptr >= end)
1433 WARN("Invalid ptr %p >= end %p.\n", *ptr, end);
1434 return FALSE;
1436 token = *(*ptr)++;
1438 register_type = (token & WINED3D_SM4_REGISTER_TYPE_MASK) >> WINED3D_SM4_REGISTER_TYPE_SHIFT;
1439 if (register_type >= ARRAY_SIZE(register_type_table)
1440 || register_type_table[register_type] == ~0u)
1442 FIXME("Unhandled register type %#x.\n", register_type);
1443 param->type = WINED3DSPR_TEMP;
1445 else
1447 param->type = register_type_table[register_type];
1449 param->data_type = data_type;
1451 if (token & WINED3D_SM4_REGISTER_MODIFIER)
1453 unsigned int m;
1455 if (*ptr >= end)
1457 WARN("Invalid ptr %p >= end %p.\n", *ptr, end);
1458 return FALSE;
1460 m = *(*ptr)++;
1462 switch (m)
1464 case 0x41:
1465 *modifier = WINED3DSPSM_NEG;
1466 break;
1468 case 0x81:
1469 *modifier = WINED3DSPSM_ABS;
1470 break;
1472 case 0xc1:
1473 *modifier = WINED3DSPSM_ABSNEG;
1474 break;
1476 default:
1477 FIXME("Skipping modifier 0x%08x.\n", m);
1478 case 0x01:
1479 *modifier = WINED3DSPSM_NONE;
1480 break;
1483 else
1485 *modifier = WINED3DSPSM_NONE;
1488 order = (token & WINED3D_SM4_REGISTER_ORDER_MASK) >> WINED3D_SM4_REGISTER_ORDER_SHIFT;
1490 if (order < 1)
1491 param->idx[0].offset = ~0U;
1492 else
1494 DWORD addressing = (token & WINED3D_SM4_ADDRESSING_MASK0) >> WINED3D_SM4_ADDRESSING_SHIFT0;
1495 if (!(shader_sm4_read_reg_idx(priv, ptr, end, addressing, &param->idx[0])))
1497 ERR("Failed to read register index.\n");
1498 return FALSE;
1502 if (order < 2)
1503 param->idx[1].offset = ~0U;
1504 else
1506 DWORD addressing = (token & WINED3D_SM4_ADDRESSING_MASK1) >> WINED3D_SM4_ADDRESSING_SHIFT1;
1507 if (!(shader_sm4_read_reg_idx(priv, ptr, end, addressing, &param->idx[1])))
1509 ERR("Failed to read register index.\n");
1510 return FALSE;
1514 if (order > 2)
1515 FIXME("Unhandled order %u.\n", order);
1517 if (register_type == WINED3D_SM4_RT_IMMCONST)
1519 enum wined3d_sm4_dimension dimension = (token & WINED3D_SM4_DIMENSION_MASK) >> WINED3D_SM4_DIMENSION_SHIFT;
1521 switch (dimension)
1523 case WINED3D_SM4_DIMENSION_SCALAR:
1524 param->immconst_type = WINED3D_IMMCONST_SCALAR;
1525 if (end - *ptr < 1)
1527 WARN("Invalid ptr %p, end %p.\n", *ptr, end);
1528 return FALSE;
1530 memcpy(param->u.immconst_data, *ptr, 1 * sizeof(DWORD));
1531 *ptr += 1;
1532 break;
1534 case WINED3D_SM4_DIMENSION_VEC4:
1535 param->immconst_type = WINED3D_IMMCONST_VEC4;
1536 if (end - *ptr < 4)
1538 WARN("Invalid ptr %p, end %p.\n", *ptr, end);
1539 return FALSE;
1541 memcpy(param->u.immconst_data, *ptr, 4 * sizeof(DWORD));
1542 *ptr += 4;
1543 break;
1545 default:
1546 FIXME("Unhandled dimension %#x.\n", dimension);
1547 break;
1551 map_register(priv, param);
1553 return TRUE;
1556 static BOOL shader_sm4_read_src_param(struct wined3d_sm4_data *priv, const DWORD **ptr, const DWORD *end,
1557 enum wined3d_data_type data_type, struct wined3d_shader_src_param *src_param)
1559 DWORD token;
1561 if (*ptr >= end)
1563 WARN("Invalid ptr %p >= end %p.\n", *ptr, end);
1564 return FALSE;
1566 token = **ptr;
1568 if (!shader_sm4_read_param(priv, ptr, end, data_type, &src_param->reg, &src_param->modifiers))
1570 ERR("Failed to read parameter.\n");
1571 return FALSE;
1574 if (src_param->reg.type == WINED3DSPR_IMMCONST)
1576 src_param->swizzle = WINED3DSP_NOSWIZZLE;
1578 else
1580 enum wined3d_sm4_swizzle_type swizzle_type =
1581 (token & WINED3D_SM4_SWIZZLE_TYPE_MASK) >> WINED3D_SM4_SWIZZLE_TYPE_SHIFT;
1583 switch (swizzle_type)
1585 case WINED3D_SM4_SWIZZLE_NONE:
1586 src_param->swizzle = WINED3DSP_NOSWIZZLE;
1587 break;
1589 case WINED3D_SM4_SWIZZLE_SCALAR:
1590 src_param->swizzle = (token & WINED3D_SM4_SWIZZLE_MASK) >> WINED3D_SM4_SWIZZLE_SHIFT;
1591 src_param->swizzle = (src_param->swizzle & 0x3) * 0x55;
1592 break;
1594 case WINED3D_SM4_SWIZZLE_VEC4:
1595 src_param->swizzle = (token & WINED3D_SM4_SWIZZLE_MASK) >> WINED3D_SM4_SWIZZLE_SHIFT;
1596 break;
1598 default:
1599 FIXME("Unhandled swizzle type %#x.\n", swizzle_type);
1600 break;
1604 return TRUE;
1607 static BOOL shader_sm4_read_dst_param(struct wined3d_sm4_data *priv, const DWORD **ptr, const DWORD *end,
1608 enum wined3d_data_type data_type, struct wined3d_shader_dst_param *dst_param)
1610 enum wined3d_shader_src_modifier modifier;
1611 DWORD token;
1613 if (*ptr >= end)
1615 WARN("Invalid ptr %p >= end %p.\n", *ptr, end);
1616 return FALSE;
1618 token = **ptr;
1620 if (!shader_sm4_read_param(priv, ptr, end, data_type, &dst_param->reg, &modifier))
1622 ERR("Failed to read parameter.\n");
1623 return FALSE;
1626 if (modifier != WINED3DSPSM_NONE)
1628 ERR("Invalid source modifier %#x on destination register.\n", modifier);
1629 return FALSE;
1632 dst_param->write_mask = (token & WINED3D_SM4_WRITEMASK_MASK) >> WINED3D_SM4_WRITEMASK_SHIFT;
1633 dst_param->modifiers = 0;
1634 dst_param->shift = 0;
1636 return TRUE;
1639 static void shader_sm4_read_instruction_modifier(uint32_t modifier, struct wined3d_shader_instruction *ins)
1641 enum wined3d_sm4_instruction_modifier modifier_type = modifier & WINED3D_SM4_MODIFIER_MASK;
1643 switch (modifier_type)
1645 case WINED3D_SM4_MODIFIER_AOFFIMMI:
1647 static const DWORD recognized_bits = WINED3D_SM4_INSTRUCTION_MODIFIER
1648 | WINED3D_SM4_MODIFIER_MASK
1649 | WINED3D_SM4_AOFFIMMI_U_MASK
1650 | WINED3D_SM4_AOFFIMMI_V_MASK
1651 | WINED3D_SM4_AOFFIMMI_W_MASK;
1653 /* Bit fields are used for sign extension. */
1654 struct
1656 int u : 4;
1657 int v : 4;
1658 int w : 4;
1659 } aoffimmi;
1661 if (modifier & ~recognized_bits)
1662 FIXME("Unhandled instruction modifier %#x.\n", modifier);
1664 aoffimmi.u = (modifier & WINED3D_SM4_AOFFIMMI_U_MASK) >> WINED3D_SM4_AOFFIMMI_U_SHIFT;
1665 aoffimmi.v = (modifier & WINED3D_SM4_AOFFIMMI_V_MASK) >> WINED3D_SM4_AOFFIMMI_V_SHIFT;
1666 aoffimmi.w = (modifier & WINED3D_SM4_AOFFIMMI_W_MASK) >> WINED3D_SM4_AOFFIMMI_W_SHIFT;
1667 ins->texel_offset.u = aoffimmi.u;
1668 ins->texel_offset.v = aoffimmi.v;
1669 ins->texel_offset.w = aoffimmi.w;
1670 break;
1673 case WINED3D_SM5_MODIFIER_DATA_TYPE:
1675 uint32_t components = (modifier & WINED3D_SM5_MODIFIER_DATA_TYPE_MASK) >> WINED3D_SM5_MODIFIER_DATA_TYPE_SHIFT;
1676 enum wined3d_sm4_data_type data_type = components & 0xf;
1678 if ((components & 0xfff0) != (components & 0xf) * 0x1110)
1679 FIXME("Components (%#x) have different data types.\n", components);
1680 ins->resource_data_type = data_type_table[data_type];
1681 break;
1684 case WINED3D_SM5_MODIFIER_RESOURCE_TYPE:
1686 enum wined3d_sm4_resource_type resource_type
1687 = (modifier & WINED3D_SM5_MODIFIER_RESOURCE_TYPE_MASK) >> WINED3D_SM5_MODIFIER_RESOURCE_TYPE_SHIFT;
1689 ins->resource_type = resource_type_table[resource_type];
1690 break;
1693 default:
1694 FIXME("Unhandled instruction modifier %#x.\n", modifier);
1698 static void shader_sm4_read_instruction(void *data, const DWORD **ptr, struct wined3d_shader_instruction *ins)
1700 const struct wined3d_sm4_opcode_info *opcode_info;
1701 uint32_t opcode_token, previous_token;
1702 struct wined3d_sm4_data *priv = data;
1703 unsigned int opcode;
1704 unsigned int i, len;
1705 SIZE_T remaining;
1706 const DWORD *p;
1707 DWORD precise;
1709 list_move_head(&priv->src_free, &priv->src);
1711 if (*ptr >= priv->end)
1713 WARN("End of byte-code, failed to read opcode.\n");
1714 goto fail;
1716 remaining = priv->end - *ptr;
1718 opcode_token = *(*ptr)++;
1719 opcode = opcode_token & WINED3D_SM4_OPCODE_MASK;
1721 len = ((opcode_token & WINED3D_SM4_INSTRUCTION_LENGTH_MASK) >> WINED3D_SM4_INSTRUCTION_LENGTH_SHIFT);
1722 if (!len)
1724 if (remaining < 2)
1726 WARN("End of byte-code, failed to read length token.\n");
1727 goto fail;
1729 len = **ptr;
1731 if (!len || remaining < len)
1733 WARN("Read invalid length %u (remaining %Iu).\n", len, remaining);
1734 goto fail;
1736 --len;
1738 if (TRACE_ON(d3d_bytecode))
1740 TRACE_(d3d_bytecode)("[ %08x ", opcode_token);
1741 for (i = 0; i < len; ++i)
1743 TRACE_(d3d_bytecode)("%08lx ", (*ptr)[i]);
1745 TRACE_(d3d_bytecode)("]\n");
1748 if (!(opcode_info = get_opcode_info(opcode)))
1750 FIXME("Unrecognized opcode %#x, opcode_token 0x%08x.\n", opcode, opcode_token);
1751 ins->handler_idx = WINED3DSIH_TABLE_SIZE;
1752 *ptr += len;
1753 return;
1756 ins->handler_idx = opcode_info->handler_idx;
1757 ins->flags = 0;
1758 ins->coissue = 0;
1759 ins->predicate = NULL;
1760 ins->dst_count = strlen(opcode_info->dst_info);
1761 ins->dst = priv->dst_param;
1762 ins->src_count = strlen(opcode_info->src_info);
1763 ins->src = priv->src_param;
1764 ins->resource_type = WINED3D_SHADER_RESOURCE_NONE;
1765 ins->resource_data_type = WINED3D_DATA_FLOAT;
1766 memset(&ins->texel_offset, 0, sizeof(ins->texel_offset));
1768 p = *ptr;
1769 *ptr += len;
1771 if (opcode_info->read_opcode_func)
1773 opcode_info->read_opcode_func(ins, opcode, opcode_token, p, len, priv);
1775 else
1777 enum wined3d_shader_dst_modifier instruction_dst_modifier = WINED3DSPDM_NONE;
1779 previous_token = opcode_token;
1780 while (previous_token & WINED3D_SM4_INSTRUCTION_MODIFIER && p != *ptr)
1781 shader_sm4_read_instruction_modifier(previous_token = *p++, ins);
1783 ins->flags = (opcode_token & WINED3D_SM4_INSTRUCTION_FLAGS_MASK) >> WINED3D_SM4_INSTRUCTION_FLAGS_SHIFT;
1784 if (ins->flags & WINED3D_SM4_INSTRUCTION_FLAG_SATURATE)
1786 ins->flags &= ~WINED3D_SM4_INSTRUCTION_FLAG_SATURATE;
1787 instruction_dst_modifier = WINED3DSPDM_SATURATE;
1789 precise = (opcode_token & WINED3D_SM5_PRECISE_MASK) >> WINED3D_SM5_PRECISE_SHIFT;
1790 ins->flags |= precise << WINED3DSI_PRECISE_SHIFT;
1792 for (i = 0; i < ins->dst_count; ++i)
1794 if (!(shader_sm4_read_dst_param(priv, &p, *ptr, map_data_type(opcode_info->dst_info[i]),
1795 &priv->dst_param[i])))
1797 ins->handler_idx = WINED3DSIH_TABLE_SIZE;
1798 return;
1800 priv->dst_param[i].modifiers |= instruction_dst_modifier;
1803 for (i = 0; i < ins->src_count; ++i)
1805 if (!(shader_sm4_read_src_param(priv, &p, *ptr, map_data_type(opcode_info->src_info[i]),
1806 &priv->src_param[i])))
1808 ins->handler_idx = WINED3DSIH_TABLE_SIZE;
1809 return;
1814 return;
1816 fail:
1817 *ptr = priv->end;
1818 ins->handler_idx = WINED3DSIH_TABLE_SIZE;
1819 return;
1822 static BOOL shader_sm4_is_end(void *data, const DWORD **ptr)
1824 struct wined3d_sm4_data *priv = data;
1825 return *ptr == priv->end;
1828 const struct wined3d_shader_frontend sm4_shader_frontend =
1830 shader_sm4_init,
1831 shader_sm4_free,
1832 shader_sm4_read_header,
1833 shader_sm4_read_instruction,
1834 shader_sm4_is_end,
1837 #define TAG_AON9 WINEMAKEFOURCC('A', 'o', 'n', '9')
1838 #define TAG_ISG1 WINEMAKEFOURCC('I', 'S', 'G', '1')
1839 #define TAG_ISGN WINEMAKEFOURCC('I', 'S', 'G', 'N')
1840 #define TAG_OSG1 WINEMAKEFOURCC('O', 'S', 'G', '1')
1841 #define TAG_OSG5 WINEMAKEFOURCC('O', 'S', 'G', '5')
1842 #define TAG_OSGN WINEMAKEFOURCC('O', 'S', 'G', 'N')
1843 #define TAG_PCSG WINEMAKEFOURCC('P', 'C', 'S', 'G')
1844 #define TAG_PSG1 WINEMAKEFOURCC('P', 'S', 'G', '1')
1845 #define TAG_SHDR WINEMAKEFOURCC('S', 'H', 'D', 'R')
1846 #define TAG_SHEX WINEMAKEFOURCC('S', 'H', 'E', 'X')
1848 struct aon9_header
1850 DWORD chunk_size;
1851 unsigned int shader_version;
1852 DWORD unknown;
1853 unsigned int byte_code_offset;
1856 static void read_dword(const char **ptr, unsigned int *d)
1858 memcpy(d, *ptr, sizeof(*d));
1859 *ptr += sizeof(*d);
1862 static BOOL require_space(size_t offset, size_t count, size_t size, size_t data_size)
1864 return !count || (data_size - offset) / count >= size;
1867 static void skip_dword_unknown(const char **ptr, unsigned int count)
1869 unsigned int i;
1870 unsigned int d;
1872 WARN("Skipping %u unknown DWORDs:\n", count);
1873 for (i = 0; i < count; ++i)
1875 read_dword(ptr, &d);
1876 WARN("\t0x%08x\n", d);
1880 static const char *shader_get_string(const char *data, size_t data_size, unsigned int offset)
1882 if (offset >= data_size)
1884 WARN("Invalid offset %#x (data size %#lx).\n", offset, (long)data_size);
1885 return NULL;
1888 if (!memchr( data + offset, 0, data_size - offset ))
1889 return NULL;
1891 return data + offset;
1894 static HRESULT shader_parse_signature(DWORD tag, const char *data, unsigned int data_size,
1895 struct wined3d_shader_signature *s)
1897 struct wined3d_shader_signature_element *e;
1898 bool has_stream_index, has_min_precision;
1899 const char *ptr = data;
1900 unsigned int i;
1901 unsigned int count;
1903 if (!require_space(0, 2, sizeof(DWORD), data_size))
1905 WARN("Invalid data size %#x.\n", data_size);
1906 return E_INVALIDARG;
1909 read_dword(&ptr, &count);
1910 TRACE("%u elements.\n", count);
1912 skip_dword_unknown(&ptr, 1); /* It seems to always be 0x00000008. */
1914 if (!require_space(ptr - data, count, 6 * sizeof(DWORD), data_size))
1916 WARN("Invalid count %#x (data size %#x).\n", count, data_size);
1917 return E_INVALIDARG;
1920 if (!(e = heap_calloc(count, sizeof(*e))))
1922 ERR("Failed to allocate input signature memory.\n");
1923 return E_OUTOFMEMORY;
1926 has_min_precision = tag == TAG_OSG1 || tag == TAG_PSG1 || tag == TAG_ISG1;
1927 has_stream_index = tag == TAG_OSG5 || has_min_precision;
1929 for (i = 0; i < count; ++i)
1931 unsigned int name_offset;
1933 if (has_stream_index)
1934 read_dword(&ptr, &e[i].stream_idx);
1935 else
1936 e[i].stream_idx = 0;
1937 read_dword(&ptr, &name_offset);
1938 if (!(e[i].semantic_name = shader_get_string(data, data_size, name_offset)))
1940 WARN("Invalid name offset %#x (data size %#x).\n", name_offset, data_size);
1941 heap_free(e);
1942 return E_INVALIDARG;
1944 read_dword(&ptr, &e[i].semantic_idx);
1945 read_dword(&ptr, &e[i].sysval_semantic);
1946 read_dword(&ptr, &e[i].component_type);
1947 read_dword(&ptr, &e[i].register_idx);
1948 read_dword(&ptr, &e[i].mask);
1950 if (has_min_precision)
1951 read_dword(&ptr, &e[i].min_precision);
1952 else
1953 e[i].min_precision = 0;
1955 TRACE("Stream: %u, semantic: %s, semantic idx: %u, sysval_semantic %#x, "
1956 "type %u, register idx: %u, use_mask %#x, input_mask %#x, min_precision %u.\n",
1957 e[i].stream_idx, debugstr_a(e[i].semantic_name), e[i].semantic_idx, e[i].sysval_semantic,
1958 e[i].component_type, e[i].register_idx, (e[i].mask >> 8) & 0xff, e[i].mask & 0xff, e[i].min_precision);
1961 s->elements = e;
1962 s->element_count = count;
1964 return S_OK;
1967 static HRESULT shader_dxbc_process_section(struct wined3d_shader *shader, unsigned int max_version,
1968 enum vkd3d_shader_source_type *source_type, const struct vkd3d_shader_dxbc_section_desc *section)
1970 unsigned int data_size = section->data.size;
1971 const void *data = section->data.code;
1972 uint32_t tag = section->tag;
1973 HRESULT hr;
1975 switch (tag)
1977 case TAG_ISGN:
1978 case TAG_ISG1:
1979 if (max_version < 4)
1981 TRACE("Skipping shader input signature.\n");
1982 break;
1984 if (shader->input_signature.elements)
1986 FIXME("Multiple input signatures.\n");
1987 break;
1989 if (FAILED(hr = shader_parse_signature(tag, data, data_size, &shader->input_signature)))
1990 return hr;
1991 break;
1993 case TAG_OSGN:
1994 case TAG_OSG1:
1995 case TAG_OSG5:
1996 if (max_version < 4)
1998 TRACE("Skipping shader output signature.\n");
1999 break;
2001 if (shader->output_signature.elements)
2003 FIXME("Multiple output signatures.\n");
2004 break;
2006 if (FAILED(hr = shader_parse_signature(tag, data, data_size, &shader->output_signature)))
2007 return hr;
2008 break;
2010 case TAG_PCSG:
2011 case TAG_PSG1:
2012 if (shader->patch_constant_signature.elements)
2014 FIXME("Multiple patch constant signatures.\n");
2015 break;
2017 if (FAILED(hr = shader_parse_signature(tag, data, data_size, &shader->patch_constant_signature)))
2018 return hr;
2019 break;
2021 case TAG_SHDR:
2022 case TAG_SHEX:
2023 if (max_version < 4)
2025 TRACE("Skipping SM4+ shader.\n");
2026 break;
2028 if (shader->function)
2029 FIXME("Multiple shader code chunks.\n");
2030 shader->function = data;
2031 shader->functionLength = data_size;
2032 *source_type = VKD3D_SHADER_SOURCE_DXBC_TPF;
2033 break;
2035 case TAG_AON9:
2036 if (max_version < 4)
2038 const struct aon9_header *header = data;
2039 unsigned int unknown_dword_count;
2040 const char *byte_code;
2042 if (data_size < sizeof(*header))
2044 WARN("Invalid Aon9 data size %#x.\n", data_size);
2045 return E_FAIL;
2047 byte_code = data;
2048 byte_code += header->byte_code_offset;
2049 unknown_dword_count = (header->byte_code_offset - sizeof(*header)) / sizeof(DWORD);
2051 if (data_size - 2 * sizeof(DWORD) < header->byte_code_offset)
2053 WARN("Invalid byte code offset %#x (size %#x).\n", header->byte_code_offset, data_size);
2054 return E_FAIL;
2056 FIXME("Skipping %u unknown DWORDs.\n", unknown_dword_count);
2058 if (shader->function)
2059 FIXME("Multiple shader code chunks.\n");
2060 shader->function = (const DWORD *)byte_code;
2061 shader->functionLength = data_size - header->byte_code_offset;
2062 *source_type = VKD3D_SHADER_SOURCE_D3D_BYTECODE;
2063 TRACE("Feature level 9 shader version 0%08x, 0%08lx.\n",
2064 header->shader_version, *shader->function);
2066 else
2068 TRACE("Skipping feature level 9 shader code.\n");
2070 break;
2072 default:
2073 TRACE("Skipping chunk %s.\n", debugstr_an((const char *)&tag, 4));
2074 break;
2077 return S_OK;
2080 HRESULT wined3d_shader_extract_from_dxbc(struct wined3d_shader *shader,
2081 unsigned int max_shader_version, enum vkd3d_shader_source_type *source_type)
2083 const struct vkd3d_shader_code dxbc = {.code = shader->byte_code, .size = shader->byte_code_size};
2084 struct vkd3d_shader_dxbc_desc dxbc_desc;
2085 HRESULT hr = WINED3D_OK;
2086 unsigned int i;
2087 int ret;
2089 if ((ret = vkd3d_shader_parse_dxbc(&dxbc, 0, &dxbc_desc, NULL)) < 0)
2091 WARN("Failed to parse DXBC, ret %d.\n", ret);
2092 return E_INVALIDARG;
2095 for (i = 0; i < dxbc_desc.section_count; ++i)
2097 if (FAILED(hr = shader_dxbc_process_section(shader, max_shader_version, source_type, &dxbc_desc.sections[i])))
2098 break;
2100 vkd3d_shader_free_dxbc(&dxbc_desc);
2102 if (!shader->function)
2103 hr = E_INVALIDARG;
2105 if (FAILED(hr))
2106 WARN("Failed to parse DXBC, hr %#lx.\n", hr);
2108 return hr;