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
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_MASK 0x3fu
31 #define WINED3D_SM5_MODIFIER_DATA_TYPE_SHIFT 6
32 #define WINED3D_SM5_MODIFIER_DATA_TYPE_MASK (0xffffu << WINED3D_SM5_MODIFIER_DATA_TYPE_SHIFT)
34 #define WINED3D_SM5_MODIFIER_RESOURCE_TYPE_SHIFT 6
35 #define WINED3D_SM5_MODIFIER_RESOURCE_TYPE_MASK (0xfu << WINED3D_SM5_MODIFIER_RESOURCE_TYPE_SHIFT)
37 #define WINED3D_SM4_AOFFIMMI_U_SHIFT 9
38 #define WINED3D_SM4_AOFFIMMI_U_MASK (0xfu << WINED3D_SM4_AOFFIMMI_U_SHIFT)
39 #define WINED3D_SM4_AOFFIMMI_V_SHIFT 13
40 #define WINED3D_SM4_AOFFIMMI_V_MASK (0xfu << WINED3D_SM4_AOFFIMMI_V_SHIFT)
41 #define WINED3D_SM4_AOFFIMMI_W_SHIFT 17
42 #define WINED3D_SM4_AOFFIMMI_W_MASK (0xfu << WINED3D_SM4_AOFFIMMI_W_SHIFT)
44 #define WINED3D_SM4_INSTRUCTION_LENGTH_SHIFT 24
45 #define WINED3D_SM4_INSTRUCTION_LENGTH_MASK (0x1fu << WINED3D_SM4_INSTRUCTION_LENGTH_SHIFT)
47 #define WINED3D_SM4_INSTRUCTION_FLAGS_SHIFT 11
48 #define WINED3D_SM4_INSTRUCTION_FLAGS_MASK (0x7u << WINED3D_SM4_INSTRUCTION_FLAGS_SHIFT)
50 #define WINED3D_SM4_RESOURCE_TYPE_SHIFT 11
51 #define WINED3D_SM4_RESOURCE_TYPE_MASK (0xfu << WINED3D_SM4_RESOURCE_TYPE_SHIFT)
53 #define WINED3D_SM4_PRIMITIVE_TYPE_SHIFT 11
54 #define WINED3D_SM4_PRIMITIVE_TYPE_MASK (0x3fu << WINED3D_SM4_PRIMITIVE_TYPE_SHIFT)
56 #define WINED3D_SM4_INDEX_TYPE_SHIFT 11
57 #define WINED3D_SM4_INDEX_TYPE_MASK (0x1u << WINED3D_SM4_INDEX_TYPE_SHIFT)
59 #define WINED3D_SM4_SAMPLER_MODE_SHIFT 11
60 #define WINED3D_SM4_SAMPLER_MODE_MASK (0xfu << WINED3D_SM4_SAMPLER_MODE_SHIFT)
62 #define WINED3D_SM4_SHADER_DATA_TYPE_SHIFT 11
63 #define WINED3D_SM4_SHADER_DATA_TYPE_MASK (0xfu << WINED3D_SM4_SHADER_DATA_TYPE_SHIFT)
65 #define WINED3D_SM4_INTERPOLATION_MODE_SHIFT 11
66 #define WINED3D_SM4_INTERPOLATION_MODE_MASK (0xfu << WINED3D_SM4_INTERPOLATION_MODE_SHIFT)
68 #define WINED3D_SM4_GLOBAL_FLAGS_SHIFT 11
69 #define WINED3D_SM4_GLOBAL_FLAGS_MASK (0xffu << WINED3D_SM4_GLOBAL_FLAGS_SHIFT)
71 #define WINED3D_SM5_PRECISE_SHIFT 19
72 #define WINED3D_SM5_PRECISE_MASK (0xfu << WINED3D_SM5_PRECISE_SHIFT)
74 #define WINED3D_SM5_CONTROL_POINT_COUNT_SHIFT 11
75 #define WINED3D_SM5_CONTROL_POINT_COUNT_MASK (0xffu << WINED3D_SM5_CONTROL_POINT_COUNT_SHIFT)
77 #define WINED3D_SM5_FP_ARRAY_SIZE_SHIFT 16
78 #define WINED3D_SM5_FP_TABLE_COUNT_MASK 0xffffu
80 #define WINED3D_SM5_UAV_FLAGS_SHIFT 15
81 #define WINED3D_SM5_UAV_FLAGS_MASK (0x1ffu << WINED3D_SM5_UAV_FLAGS_SHIFT)
83 #define WINED3D_SM5_SYNC_FLAGS_SHIFT 11
84 #define WINED3D_SM5_SYNC_FLAGS_MASK (0xffu << WINED3D_SM5_SYNC_FLAGS_SHIFT)
86 #define WINED3D_SM5_TESSELLATOR_SHIFT 11
87 #define WINED3D_SM5_TESSELLATOR_MASK (0xfu << WINED3D_SM5_TESSELLATOR_SHIFT)
89 #define WINED3D_SM4_OPCODE_MASK 0xff
91 #define WINED3D_SM4_REGISTER_MODIFIER (0x1u << 31)
93 #define WINED3D_SM4_ADDRESSING_SHIFT1 25
94 #define WINED3D_SM4_ADDRESSING_MASK1 (0x3u << WINED3D_SM4_ADDRESSING_SHIFT1)
96 #define WINED3D_SM4_ADDRESSING_SHIFT0 22
97 #define WINED3D_SM4_ADDRESSING_MASK0 (0x3u << WINED3D_SM4_ADDRESSING_SHIFT0)
99 #define WINED3D_SM4_REGISTER_ORDER_SHIFT 20
100 #define WINED3D_SM4_REGISTER_ORDER_MASK (0x3u << WINED3D_SM4_REGISTER_ORDER_SHIFT)
102 #define WINED3D_SM4_REGISTER_TYPE_SHIFT 12
103 #define WINED3D_SM4_REGISTER_TYPE_MASK (0xffu << WINED3D_SM4_REGISTER_TYPE_SHIFT)
105 #define WINED3D_SM4_SWIZZLE_TYPE_SHIFT 2
106 #define WINED3D_SM4_SWIZZLE_TYPE_MASK (0x3u << WINED3D_SM4_SWIZZLE_TYPE_SHIFT)
108 #define WINED3D_SM4_DIMENSION_SHIFT 0
109 #define WINED3D_SM4_DIMENSION_MASK (0x3u << WINED3D_SM4_DIMENSION_SHIFT)
111 #define WINED3D_SM4_WRITEMASK_SHIFT 4
112 #define WINED3D_SM4_WRITEMASK_MASK (0xfu << WINED3D_SM4_WRITEMASK_SHIFT)
114 #define WINED3D_SM4_SWIZZLE_SHIFT 4
115 #define WINED3D_SM4_SWIZZLE_MASK (0xffu << WINED3D_SM4_SWIZZLE_SHIFT)
117 #define WINED3D_SM4_VERSION_MAJOR(version) (((version) >> 4) & 0xf)
118 #define WINED3D_SM4_VERSION_MINOR(version) (((version) >> 0) & 0xf)
120 #define WINED3D_SM4_ADDRESSING_RELATIVE 0x2
121 #define WINED3D_SM4_ADDRESSING_OFFSET 0x1
123 #define WINED3D_SM4_INSTRUCTION_FLAG_SATURATE 0x4
125 #define WINED3D_SM4_CONDITIONAL_NZ (0x1u << 18)
127 enum wined3d_sm4_opcode
129 WINED3D_SM4_OP_ADD
= 0x00,
130 WINED3D_SM4_OP_AND
= 0x01,
131 WINED3D_SM4_OP_BREAK
= 0x02,
132 WINED3D_SM4_OP_BREAKC
= 0x03,
133 WINED3D_SM4_OP_CASE
= 0x06,
134 WINED3D_SM4_OP_CONTINUE
= 0x07,
135 WINED3D_SM4_OP_CONTINUEC
= 0x08,
136 WINED3D_SM4_OP_CUT
= 0x09,
137 WINED3D_SM4_OP_DEFAULT
= 0x0a,
138 WINED3D_SM4_OP_DERIV_RTX
= 0x0b,
139 WINED3D_SM4_OP_DERIV_RTY
= 0x0c,
140 WINED3D_SM4_OP_DISCARD
= 0x0d,
141 WINED3D_SM4_OP_DIV
= 0x0e,
142 WINED3D_SM4_OP_DP2
= 0x0f,
143 WINED3D_SM4_OP_DP3
= 0x10,
144 WINED3D_SM4_OP_DP4
= 0x11,
145 WINED3D_SM4_OP_ELSE
= 0x12,
146 WINED3D_SM4_OP_EMIT
= 0x13,
147 WINED3D_SM4_OP_ENDIF
= 0x15,
148 WINED3D_SM4_OP_ENDLOOP
= 0x16,
149 WINED3D_SM4_OP_ENDSWITCH
= 0x17,
150 WINED3D_SM4_OP_EQ
= 0x18,
151 WINED3D_SM4_OP_EXP
= 0x19,
152 WINED3D_SM4_OP_FRC
= 0x1a,
153 WINED3D_SM4_OP_FTOI
= 0x1b,
154 WINED3D_SM4_OP_FTOU
= 0x1c,
155 WINED3D_SM4_OP_GE
= 0x1d,
156 WINED3D_SM4_OP_IADD
= 0x1e,
157 WINED3D_SM4_OP_IF
= 0x1f,
158 WINED3D_SM4_OP_IEQ
= 0x20,
159 WINED3D_SM4_OP_IGE
= 0x21,
160 WINED3D_SM4_OP_ILT
= 0x22,
161 WINED3D_SM4_OP_IMAD
= 0x23,
162 WINED3D_SM4_OP_IMAX
= 0x24,
163 WINED3D_SM4_OP_IMIN
= 0x25,
164 WINED3D_SM4_OP_IMUL
= 0x26,
165 WINED3D_SM4_OP_INE
= 0x27,
166 WINED3D_SM4_OP_INEG
= 0x28,
167 WINED3D_SM4_OP_ISHL
= 0x29,
168 WINED3D_SM4_OP_ISHR
= 0x2a,
169 WINED3D_SM4_OP_ITOF
= 0x2b,
170 WINED3D_SM4_OP_LABEL
= 0x2c,
171 WINED3D_SM4_OP_LD
= 0x2d,
172 WINED3D_SM4_OP_LD2DMS
= 0x2e,
173 WINED3D_SM4_OP_LOG
= 0x2f,
174 WINED3D_SM4_OP_LOOP
= 0x30,
175 WINED3D_SM4_OP_LT
= 0x31,
176 WINED3D_SM4_OP_MAD
= 0x32,
177 WINED3D_SM4_OP_MIN
= 0x33,
178 WINED3D_SM4_OP_MAX
= 0x34,
179 WINED3D_SM4_OP_SHADER_DATA
= 0x35,
180 WINED3D_SM4_OP_MOV
= 0x36,
181 WINED3D_SM4_OP_MOVC
= 0x37,
182 WINED3D_SM4_OP_MUL
= 0x38,
183 WINED3D_SM4_OP_NE
= 0x39,
184 WINED3D_SM4_OP_NOP
= 0x3a,
185 WINED3D_SM4_OP_NOT
= 0x3b,
186 WINED3D_SM4_OP_OR
= 0x3c,
187 WINED3D_SM4_OP_RESINFO
= 0x3d,
188 WINED3D_SM4_OP_RET
= 0x3e,
189 WINED3D_SM4_OP_RETC
= 0x3f,
190 WINED3D_SM4_OP_ROUND_NE
= 0x40,
191 WINED3D_SM4_OP_ROUND_NI
= 0x41,
192 WINED3D_SM4_OP_ROUND_PI
= 0x42,
193 WINED3D_SM4_OP_ROUND_Z
= 0x43,
194 WINED3D_SM4_OP_RSQ
= 0x44,
195 WINED3D_SM4_OP_SAMPLE
= 0x45,
196 WINED3D_SM4_OP_SAMPLE_C
= 0x46,
197 WINED3D_SM4_OP_SAMPLE_C_LZ
= 0x47,
198 WINED3D_SM4_OP_SAMPLE_LOD
= 0x48,
199 WINED3D_SM4_OP_SAMPLE_GRAD
= 0x49,
200 WINED3D_SM4_OP_SAMPLE_B
= 0x4a,
201 WINED3D_SM4_OP_SQRT
= 0x4b,
202 WINED3D_SM4_OP_SWITCH
= 0x4c,
203 WINED3D_SM4_OP_SINCOS
= 0x4d,
204 WINED3D_SM4_OP_UDIV
= 0x4e,
205 WINED3D_SM4_OP_ULT
= 0x4f,
206 WINED3D_SM4_OP_UGE
= 0x50,
207 WINED3D_SM4_OP_UMUL
= 0x51,
208 WINED3D_SM4_OP_UMAX
= 0x53,
209 WINED3D_SM4_OP_UMIN
= 0x54,
210 WINED3D_SM4_OP_USHR
= 0x55,
211 WINED3D_SM4_OP_UTOF
= 0x56,
212 WINED3D_SM4_OP_XOR
= 0x57,
213 WINED3D_SM4_OP_DCL_RESOURCE
= 0x58,
214 WINED3D_SM4_OP_DCL_CONSTANT_BUFFER
= 0x59,
215 WINED3D_SM4_OP_DCL_SAMPLER
= 0x5a,
216 WINED3D_SM4_OP_DCL_INDEX_RANGE
= 0x5b,
217 WINED3D_SM4_OP_DCL_OUTPUT_TOPOLOGY
= 0x5c,
218 WINED3D_SM4_OP_DCL_INPUT_PRIMITIVE
= 0x5d,
219 WINED3D_SM4_OP_DCL_VERTICES_OUT
= 0x5e,
220 WINED3D_SM4_OP_DCL_INPUT
= 0x5f,
221 WINED3D_SM4_OP_DCL_INPUT_SGV
= 0x60,
222 WINED3D_SM4_OP_DCL_INPUT_SIV
= 0x61,
223 WINED3D_SM4_OP_DCL_INPUT_PS
= 0x62,
224 WINED3D_SM4_OP_DCL_INPUT_PS_SGV
= 0x63,
225 WINED3D_SM4_OP_DCL_INPUT_PS_SIV
= 0x64,
226 WINED3D_SM4_OP_DCL_OUTPUT
= 0x65,
227 WINED3D_SM4_OP_DCL_OUTPUT_SIV
= 0x67,
228 WINED3D_SM4_OP_DCL_TEMPS
= 0x68,
229 WINED3D_SM4_OP_DCL_INDEXABLE_TEMP
= 0x69,
230 WINED3D_SM4_OP_DCL_GLOBAL_FLAGS
= 0x6a,
231 WINED3D_SM4_OP_LOD
= 0x6c,
232 WINED3D_SM4_OP_GATHER4
= 0x6d,
233 WINED3D_SM4_OP_SAMPLE_POS
= 0x6e,
234 WINED3D_SM4_OP_SAMPLE_INFO
= 0x6f,
235 WINED3D_SM5_OP_HS_DECLS
= 0x71,
236 WINED3D_SM5_OP_HS_CONTROL_POINT_PHASE
= 0x72,
237 WINED3D_SM5_OP_HS_FORK_PHASE
= 0x73,
238 WINED3D_SM5_OP_HS_JOIN_PHASE
= 0x74,
239 WINED3D_SM5_OP_EMIT_STREAM
= 0x75,
240 WINED3D_SM5_OP_CUT_STREAM
= 0x76,
241 WINED3D_SM5_OP_FCALL
= 0x78,
242 WINED3D_SM5_OP_BUFINFO
= 0x79,
243 WINED3D_SM5_OP_DERIV_RTX_COARSE
= 0x7a,
244 WINED3D_SM5_OP_DERIV_RTX_FINE
= 0x7b,
245 WINED3D_SM5_OP_DERIV_RTY_COARSE
= 0x7c,
246 WINED3D_SM5_OP_DERIV_RTY_FINE
= 0x7d,
247 WINED3D_SM5_OP_GATHER4_C
= 0x7e,
248 WINED3D_SM5_OP_GATHER4_PO
= 0x7f,
249 WINED3D_SM5_OP_GATHER4_PO_C
= 0x80,
250 WINED3D_SM5_OP_RCP
= 0x81,
251 WINED3D_SM5_OP_F32TOF16
= 0x82,
252 WINED3D_SM5_OP_F16TOF32
= 0x83,
253 WINED3D_SM5_OP_COUNTBITS
= 0x86,
254 WINED3D_SM5_OP_FIRSTBIT_HI
= 0x87,
255 WINED3D_SM5_OP_FIRSTBIT_LO
= 0x88,
256 WINED3D_SM5_OP_FIRSTBIT_SHI
= 0x89,
257 WINED3D_SM5_OP_UBFE
= 0x8a,
258 WINED3D_SM5_OP_IBFE
= 0x8b,
259 WINED3D_SM5_OP_BFI
= 0x8c,
260 WINED3D_SM5_OP_BFREV
= 0x8d,
261 WINED3D_SM5_OP_SWAPC
= 0x8e,
262 WINED3D_SM5_OP_DCL_STREAM
= 0x8f,
263 WINED3D_SM5_OP_DCL_FUNCTION_BODY
= 0x90,
264 WINED3D_SM5_OP_DCL_FUNCTION_TABLE
= 0x91,
265 WINED3D_SM5_OP_DCL_INTERFACE
= 0x92,
266 WINED3D_SM5_OP_DCL_INPUT_CONTROL_POINT_COUNT
= 0x93,
267 WINED3D_SM5_OP_DCL_OUTPUT_CONTROL_POINT_COUNT
= 0x94,
268 WINED3D_SM5_OP_DCL_TESSELLATOR_DOMAIN
= 0x95,
269 WINED3D_SM5_OP_DCL_TESSELLATOR_PARTITIONING
= 0x96,
270 WINED3D_SM5_OP_DCL_TESSELLATOR_OUTPUT_PRIMITIVE
= 0x97,
271 WINED3D_SM5_OP_DCL_HS_MAX_TESSFACTOR
= 0x98,
272 WINED3D_SM5_OP_DCL_HS_FORK_PHASE_INSTANCE_COUNT
= 0x99,
273 WINED3D_SM5_OP_DCL_HS_JOIN_PHASE_INSTANCE_COUNT
= 0x9a,
274 WINED3D_SM5_OP_DCL_THREAD_GROUP
= 0x9b,
275 WINED3D_SM5_OP_DCL_UAV_TYPED
= 0x9c,
276 WINED3D_SM5_OP_DCL_UAV_RAW
= 0x9d,
277 WINED3D_SM5_OP_DCL_UAV_STRUCTURED
= 0x9e,
278 WINED3D_SM5_OP_DCL_TGSM_RAW
= 0x9f,
279 WINED3D_SM5_OP_DCL_TGSM_STRUCTURED
= 0xa0,
280 WINED3D_SM5_OP_DCL_RESOURCE_RAW
= 0xa1,
281 WINED3D_SM5_OP_DCL_RESOURCE_STRUCTURED
= 0xa2,
282 WINED3D_SM5_OP_LD_UAV_TYPED
= 0xa3,
283 WINED3D_SM5_OP_STORE_UAV_TYPED
= 0xa4,
284 WINED3D_SM5_OP_LD_RAW
= 0xa5,
285 WINED3D_SM5_OP_STORE_RAW
= 0xa6,
286 WINED3D_SM5_OP_LD_STRUCTURED
= 0xa7,
287 WINED3D_SM5_OP_STORE_STRUCTURED
= 0xa8,
288 WINED3D_SM5_OP_ATOMIC_AND
= 0xa9,
289 WINED3D_SM5_OP_ATOMIC_OR
= 0xaa,
290 WINED3D_SM5_OP_ATOMIC_XOR
= 0xab,
291 WINED3D_SM5_OP_ATOMIC_CMP_STORE
= 0xac,
292 WINED3D_SM5_OP_ATOMIC_IADD
= 0xad,
293 WINED3D_SM5_OP_ATOMIC_IMAX
= 0xae,
294 WINED3D_SM5_OP_ATOMIC_IMIN
= 0xaf,
295 WINED3D_SM5_OP_ATOMIC_UMAX
= 0xb0,
296 WINED3D_SM5_OP_ATOMIC_UMIN
= 0xb1,
297 WINED3D_SM5_OP_IMM_ATOMIC_ALLOC
= 0xb2,
298 WINED3D_SM5_OP_IMM_ATOMIC_CONSUME
= 0xb3,
299 WINED3D_SM5_OP_IMM_ATOMIC_IADD
= 0xb4,
300 WINED3D_SM5_OP_IMM_ATOMIC_AND
= 0xb5,
301 WINED3D_SM5_OP_IMM_ATOMIC_OR
= 0xb6,
302 WINED3D_SM5_OP_IMM_ATOMIC_XOR
= 0xb7,
303 WINED3D_SM5_OP_IMM_ATOMIC_EXCH
= 0xb8,
304 WINED3D_SM5_OP_IMM_ATOMIC_CMP_EXCH
= 0xb9,
305 WINED3D_SM5_OP_IMM_ATOMIC_IMAX
= 0xba,
306 WINED3D_SM5_OP_IMM_ATOMIC_IMIN
= 0xbb,
307 WINED3D_SM5_OP_IMM_ATOMIC_UMAX
= 0xbc,
308 WINED3D_SM5_OP_IMM_ATOMIC_UMIN
= 0xbd,
309 WINED3D_SM5_OP_SYNC
= 0xbe,
310 WINED3D_SM5_OP_EVAL_SAMPLE_INDEX
= 0xcc,
311 WINED3D_SM5_OP_DCL_GS_INSTANCES
= 0xce,
314 enum wined3d_sm4_instruction_modifier
316 WINED3D_SM4_MODIFIER_AOFFIMMI
= 0x1,
317 WINED3D_SM5_MODIFIER_RESOURCE_TYPE
= 0x2,
318 WINED3D_SM5_MODIFIER_DATA_TYPE
= 0x3,
321 enum wined3d_sm4_register_type
323 WINED3D_SM4_RT_TEMP
= 0x00,
324 WINED3D_SM4_RT_INPUT
= 0x01,
325 WINED3D_SM4_RT_OUTPUT
= 0x02,
326 WINED3D_SM4_RT_INDEXABLE_TEMP
= 0x03,
327 WINED3D_SM4_RT_IMMCONST
= 0x04,
328 WINED3D_SM4_RT_SAMPLER
= 0x06,
329 WINED3D_SM4_RT_RESOURCE
= 0x07,
330 WINED3D_SM4_RT_CONSTBUFFER
= 0x08,
331 WINED3D_SM4_RT_IMMCONSTBUFFER
= 0x09,
332 WINED3D_SM4_RT_PRIMID
= 0x0b,
333 WINED3D_SM4_RT_DEPTHOUT
= 0x0c,
334 WINED3D_SM4_RT_NULL
= 0x0d,
335 WINED3D_SM4_RT_RASTERIZER
= 0x0e,
336 WINED3D_SM4_RT_OMASK
= 0x0f,
337 WINED3D_SM5_RT_STREAM
= 0x10,
338 WINED3D_SM5_RT_FUNCTION_BODY
= 0x11,
339 WINED3D_SM5_RT_FUNCTION_POINTER
= 0x13,
340 WINED3D_SM5_RT_OUTPUT_CONTROL_POINT_ID
= 0x16,
341 WINED3D_SM5_RT_FORK_INSTANCE_ID
= 0x17,
342 WINED3D_SM5_RT_JOIN_INSTANCE_ID
= 0x18,
343 WINED3D_SM5_RT_INPUT_CONTROL_POINT
= 0x19,
344 WINED3D_SM5_RT_OUTPUT_CONTROL_POINT
= 0x1a,
345 WINED3D_SM5_RT_PATCH_CONSTANT_DATA
= 0x1b,
346 WINED3D_SM5_RT_DOMAIN_LOCATION
= 0x1c,
347 WINED3D_SM5_RT_UAV
= 0x1e,
348 WINED3D_SM5_RT_SHARED_MEMORY
= 0x1f,
349 WINED3D_SM5_RT_THREAD_ID
= 0x20,
350 WINED3D_SM5_RT_THREAD_GROUP_ID
= 0x21,
351 WINED3D_SM5_RT_LOCAL_THREAD_ID
= 0x22,
352 WINED3D_SM5_RT_COVERAGE
= 0x23,
353 WINED3D_SM5_RT_LOCAL_THREAD_INDEX
= 0x24,
354 WINED3D_SM5_RT_GS_INSTANCE_ID
= 0x25,
355 WINED3D_SM5_RT_DEPTHOUT_GREATER_EQUAL
= 0x26,
356 WINED3D_SM5_RT_DEPTHOUT_LESS_EQUAL
= 0x27,
359 enum wined3d_sm4_output_primitive_type
361 WINED3D_SM4_OUTPUT_PT_POINTLIST
= 0x1,
362 WINED3D_SM4_OUTPUT_PT_LINESTRIP
= 0x3,
363 WINED3D_SM4_OUTPUT_PT_TRIANGLESTRIP
= 0x5,
366 enum wined3d_sm4_input_primitive_type
368 WINED3D_SM4_INPUT_PT_POINT
= 0x01,
369 WINED3D_SM4_INPUT_PT_LINE
= 0x02,
370 WINED3D_SM4_INPUT_PT_TRIANGLE
= 0x03,
371 WINED3D_SM4_INPUT_PT_LINEADJ
= 0x06,
372 WINED3D_SM4_INPUT_PT_TRIANGLEADJ
= 0x07,
373 WINED3D_SM5_INPUT_PT_PATCH1
= 0x08,
374 WINED3D_SM5_INPUT_PT_PATCH2
= 0x09,
375 WINED3D_SM5_INPUT_PT_PATCH3
= 0x0a,
376 WINED3D_SM5_INPUT_PT_PATCH4
= 0x0b,
377 WINED3D_SM5_INPUT_PT_PATCH5
= 0x0c,
378 WINED3D_SM5_INPUT_PT_PATCH6
= 0x0d,
379 WINED3D_SM5_INPUT_PT_PATCH7
= 0x0e,
380 WINED3D_SM5_INPUT_PT_PATCH8
= 0x0f,
381 WINED3D_SM5_INPUT_PT_PATCH9
= 0x10,
382 WINED3D_SM5_INPUT_PT_PATCH10
= 0x11,
383 WINED3D_SM5_INPUT_PT_PATCH11
= 0x12,
384 WINED3D_SM5_INPUT_PT_PATCH12
= 0x13,
385 WINED3D_SM5_INPUT_PT_PATCH13
= 0x14,
386 WINED3D_SM5_INPUT_PT_PATCH14
= 0x15,
387 WINED3D_SM5_INPUT_PT_PATCH15
= 0x16,
388 WINED3D_SM5_INPUT_PT_PATCH16
= 0x17,
389 WINED3D_SM5_INPUT_PT_PATCH17
= 0x18,
390 WINED3D_SM5_INPUT_PT_PATCH18
= 0x19,
391 WINED3D_SM5_INPUT_PT_PATCH19
= 0x1a,
392 WINED3D_SM5_INPUT_PT_PATCH20
= 0x1b,
393 WINED3D_SM5_INPUT_PT_PATCH21
= 0x1c,
394 WINED3D_SM5_INPUT_PT_PATCH22
= 0x1d,
395 WINED3D_SM5_INPUT_PT_PATCH23
= 0x1e,
396 WINED3D_SM5_INPUT_PT_PATCH24
= 0x1f,
397 WINED3D_SM5_INPUT_PT_PATCH25
= 0x20,
398 WINED3D_SM5_INPUT_PT_PATCH26
= 0x21,
399 WINED3D_SM5_INPUT_PT_PATCH27
= 0x22,
400 WINED3D_SM5_INPUT_PT_PATCH28
= 0x23,
401 WINED3D_SM5_INPUT_PT_PATCH29
= 0x24,
402 WINED3D_SM5_INPUT_PT_PATCH30
= 0x25,
403 WINED3D_SM5_INPUT_PT_PATCH31
= 0x26,
404 WINED3D_SM5_INPUT_PT_PATCH32
= 0x27,
407 enum wined3d_sm4_swizzle_type
409 WINED3D_SM4_SWIZZLE_NONE
= 0x0,
410 WINED3D_SM4_SWIZZLE_VEC4
= 0x1,
411 WINED3D_SM4_SWIZZLE_SCALAR
= 0x2,
414 enum wined3d_sm4_dimension
416 WINED3D_SM4_DIMENSION_SCALAR
= 0x1,
417 WINED3D_SM4_DIMENSION_VEC4
= 0x2,
420 enum wined3d_sm4_resource_type
422 WINED3D_SM4_RESOURCE_BUFFER
= 0x1,
423 WINED3D_SM4_RESOURCE_TEXTURE_1D
= 0x2,
424 WINED3D_SM4_RESOURCE_TEXTURE_2D
= 0x3,
425 WINED3D_SM4_RESOURCE_TEXTURE_2DMS
= 0x4,
426 WINED3D_SM4_RESOURCE_TEXTURE_3D
= 0x5,
427 WINED3D_SM4_RESOURCE_TEXTURE_CUBE
= 0x6,
428 WINED3D_SM4_RESOURCE_TEXTURE_1DARRAY
= 0x7,
429 WINED3D_SM4_RESOURCE_TEXTURE_2DARRAY
= 0x8,
430 WINED3D_SM4_RESOURCE_TEXTURE_2DMSARRAY
= 0x9,
431 WINED3D_SM4_RESOURCE_TEXTURE_CUBEARRAY
= 0xa,
434 enum wined3d_sm4_data_type
436 WINED3D_SM4_DATA_UNORM
= 0x1,
437 WINED3D_SM4_DATA_SNORM
= 0x2,
438 WINED3D_SM4_DATA_INT
= 0x3,
439 WINED3D_SM4_DATA_UINT
= 0x4,
440 WINED3D_SM4_DATA_FLOAT
= 0x5,
443 enum wined3d_sm4_sampler_mode
445 WINED3D_SM4_SAMPLER_DEFAULT
= 0x0,
446 WINED3D_SM4_SAMPLER_COMPARISON
= 0x1,
449 enum wined3d_sm4_shader_data_type
451 WINED3D_SM4_SHADER_DATA_IMMEDIATE_CONSTANT_BUFFER
= 0x3,
452 WINED3D_SM4_SHADER_DATA_MESSAGE
= 0x4,
455 struct wined3d_shader_src_param_entry
458 struct wined3d_shader_src_param param
;
461 struct wined3d_sm4_data
463 struct wined3d_shader_version shader_version
;
464 const DWORD
*start
, *end
;
466 unsigned int output_map
[MAX_REG_OUTPUT
];
468 struct wined3d_shader_src_param src_param
[5];
469 struct wined3d_shader_dst_param dst_param
[2];
470 struct list src_free
;
472 struct wined3d_shader_immediate_constant_buffer icb
;
475 struct wined3d_sm4_opcode_info
477 enum wined3d_sm4_opcode opcode
;
478 enum WINED3D_SHADER_INSTRUCTION_HANDLER handler_idx
;
479 const char *dst_info
;
480 const char *src_info
;
481 void (*read_opcode_func
)(struct wined3d_shader_instruction
*ins
,
482 DWORD opcode
, DWORD opcode_token
, const DWORD
*tokens
, unsigned int token_count
,
483 struct wined3d_sm4_data
*priv
);
486 static const enum wined3d_primitive_type output_primitive_type_table
[] =
488 /* UNKNOWN */ WINED3D_PT_UNDEFINED
,
489 /* WINED3D_SM4_OUTPUT_PT_POINTLIST */ WINED3D_PT_POINTLIST
,
490 /* UNKNOWN */ WINED3D_PT_UNDEFINED
,
491 /* WINED3D_SM4_OUTPUT_PT_LINESTRIP */ WINED3D_PT_LINESTRIP
,
492 /* UNKNOWN */ WINED3D_PT_UNDEFINED
,
493 /* WINED3D_SM4_OUTPUT_PT_TRIANGLESTRIP */ WINED3D_PT_TRIANGLESTRIP
,
496 static const enum wined3d_primitive_type input_primitive_type_table
[] =
498 /* UNKNOWN */ WINED3D_PT_UNDEFINED
,
499 /* WINED3D_SM4_INPUT_PT_POINT */ WINED3D_PT_POINTLIST
,
500 /* WINED3D_SM4_INPUT_PT_LINE */ WINED3D_PT_LINELIST
,
501 /* WINED3D_SM4_INPUT_PT_TRIANGLE */ WINED3D_PT_TRIANGLELIST
,
502 /* UNKNOWN */ WINED3D_PT_UNDEFINED
,
503 /* UNKNOWN */ WINED3D_PT_UNDEFINED
,
504 /* WINED3D_SM4_INPUT_PT_LINEADJ */ WINED3D_PT_LINELIST_ADJ
,
505 /* WINED3D_SM4_INPUT_PT_TRIANGLEADJ */ WINED3D_PT_TRIANGLELIST_ADJ
,
508 static const enum wined3d_shader_resource_type resource_type_table
[] =
510 /* 0 */ WINED3D_SHADER_RESOURCE_NONE
,
511 /* WINED3D_SM4_RESOURCE_BUFFER */ WINED3D_SHADER_RESOURCE_BUFFER
,
512 /* WINED3D_SM4_RESOURCE_TEXTURE_1D */ WINED3D_SHADER_RESOURCE_TEXTURE_1D
,
513 /* WINED3D_SM4_RESOURCE_TEXTURE_2D */ WINED3D_SHADER_RESOURCE_TEXTURE_2D
,
514 /* WINED3D_SM4_RESOURCE_TEXTURE_2DMS */ WINED3D_SHADER_RESOURCE_TEXTURE_2DMS
,
515 /* WINED3D_SM4_RESOURCE_TEXTURE_3D */ WINED3D_SHADER_RESOURCE_TEXTURE_3D
,
516 /* WINED3D_SM4_RESOURCE_TEXTURE_CUBE */ WINED3D_SHADER_RESOURCE_TEXTURE_CUBE
,
517 /* WINED3D_SM4_RESOURCE_TEXTURE_1DARRAY */ WINED3D_SHADER_RESOURCE_TEXTURE_1DARRAY
,
518 /* WINED3D_SM4_RESOURCE_TEXTURE_2DARRAY */ WINED3D_SHADER_RESOURCE_TEXTURE_2DARRAY
,
519 /* WINED3D_SM4_RESOURCE_TEXTURE_2DMSARRAY */ WINED3D_SHADER_RESOURCE_TEXTURE_2DMSARRAY
,
520 /* WINED3D_SM4_RESOURCE_TEXTURE_CUBEARRAY */ WINED3D_SHADER_RESOURCE_TEXTURE_CUBEARRAY
,
523 static const enum wined3d_data_type data_type_table
[] =
525 /* 0 */ WINED3D_DATA_FLOAT
,
526 /* WINED3D_SM4_DATA_UNORM */ WINED3D_DATA_UNORM
,
527 /* WINED3D_SM4_DATA_SNORM */ WINED3D_DATA_SNORM
,
528 /* WINED3D_SM4_DATA_INT */ WINED3D_DATA_INT
,
529 /* WINED3D_SM4_DATA_UINT */ WINED3D_DATA_UINT
,
530 /* WINED3D_SM4_DATA_FLOAT */ WINED3D_DATA_FLOAT
,
533 static BOOL
shader_sm4_read_src_param(struct wined3d_sm4_data
*priv
, const DWORD
**ptr
, const DWORD
*end
,
534 enum wined3d_data_type data_type
, struct wined3d_shader_src_param
*src_param
);
535 static BOOL
shader_sm4_read_dst_param(struct wined3d_sm4_data
*priv
, const DWORD
**ptr
, const DWORD
*end
,
536 enum wined3d_data_type data_type
, struct wined3d_shader_dst_param
*dst_param
);
538 static void shader_sm4_read_conditional_op(struct wined3d_shader_instruction
*ins
,
539 DWORD opcode
, DWORD opcode_token
, const DWORD
*tokens
, unsigned int token_count
,
540 struct wined3d_sm4_data
*priv
)
542 shader_sm4_read_src_param(priv
, &tokens
, &tokens
[token_count
], WINED3D_DATA_UINT
, &priv
->src_param
[0]);
543 ins
->flags
= (opcode_token
& WINED3D_SM4_CONDITIONAL_NZ
) ?
544 WINED3D_SHADER_CONDITIONAL_OP_NZ
: WINED3D_SHADER_CONDITIONAL_OP_Z
;
547 static void shader_sm4_read_shader_data(struct wined3d_shader_instruction
*ins
,
548 DWORD opcode
, DWORD opcode_token
, const DWORD
*tokens
, unsigned int token_count
,
549 struct wined3d_sm4_data
*priv
)
551 enum wined3d_sm4_shader_data_type type
;
552 unsigned int icb_size
;
554 type
= (opcode_token
& WINED3D_SM4_SHADER_DATA_TYPE_MASK
) >> WINED3D_SM4_SHADER_DATA_TYPE_SHIFT
;
555 if (type
!= WINED3D_SM4_SHADER_DATA_IMMEDIATE_CONSTANT_BUFFER
)
557 FIXME("Ignoring shader data type %#x.\n", type
);
558 ins
->handler_idx
= WINED3DSIH_NOP
;
563 icb_size
= token_count
- 1;
564 if (icb_size
% 4 || icb_size
> MAX_IMMEDIATE_CONSTANT_BUFFER_SIZE
)
566 FIXME("Unexpected immediate constant buffer size %u.\n", icb_size
);
567 ins
->handler_idx
= WINED3DSIH_TABLE_SIZE
;
571 priv
->icb
.vec4_count
= icb_size
/ 4;
572 memcpy(priv
->icb
.data
, tokens
, sizeof(*tokens
) * icb_size
);
573 ins
->declaration
.icb
= &priv
->icb
;
576 static void shader_sm4_read_dcl_resource(struct wined3d_shader_instruction
*ins
,
577 DWORD opcode
, DWORD opcode_token
, const DWORD
*tokens
, unsigned int token_count
,
578 struct wined3d_sm4_data
*priv
)
580 enum wined3d_sm4_resource_type resource_type
;
581 enum wined3d_sm4_data_type data_type
;
582 enum wined3d_data_type reg_data_type
;
585 resource_type
= (opcode_token
& WINED3D_SM4_RESOURCE_TYPE_MASK
) >> WINED3D_SM4_RESOURCE_TYPE_SHIFT
;
586 if (!resource_type
|| (resource_type
>= ARRAY_SIZE(resource_type_table
)))
588 FIXME("Unhandled resource type %#x.\n", resource_type
);
589 ins
->declaration
.semantic
.resource_type
= WINED3D_SHADER_RESOURCE_NONE
;
593 ins
->declaration
.semantic
.resource_type
= resource_type_table
[resource_type
];
595 reg_data_type
= opcode
== WINED3D_SM4_OP_DCL_RESOURCE
? WINED3D_DATA_RESOURCE
: WINED3D_DATA_UAV
;
596 shader_sm4_read_dst_param(priv
, &tokens
, &tokens
[token_count
], reg_data_type
, &ins
->declaration
.semantic
.reg
);
598 components
= *tokens
++;
599 if ((components
& 0xfff0) != (components
& 0xf) * 0x1110)
600 FIXME("Components (%#x) have different data types.\n", components
);
601 data_type
= components
& 0xf;
603 if (!data_type
|| (data_type
>= ARRAY_SIZE(data_type_table
)))
605 FIXME("Unhandled data type %#x.\n", data_type
);
606 ins
->declaration
.semantic
.resource_data_type
= WINED3D_DATA_FLOAT
;
610 ins
->declaration
.semantic
.resource_data_type
= data_type_table
[data_type
];
613 if (reg_data_type
== WINED3D_DATA_UAV
)
614 ins
->flags
= (opcode_token
& WINED3D_SM5_UAV_FLAGS_MASK
) >> WINED3D_SM5_UAV_FLAGS_SHIFT
;
617 static void shader_sm4_read_dcl_constant_buffer(struct wined3d_shader_instruction
*ins
,
618 DWORD opcode
, DWORD opcode_token
, const DWORD
*tokens
, unsigned int token_count
,
619 struct wined3d_sm4_data
*priv
)
621 shader_sm4_read_src_param(priv
, &tokens
, &tokens
[token_count
], WINED3D_DATA_FLOAT
, &ins
->declaration
.src
);
622 if (opcode_token
& WINED3D_SM4_INDEX_TYPE_MASK
)
623 ins
->flags
|= WINED3DSI_INDEXED_DYNAMIC
;
626 static void shader_sm4_read_dcl_sampler(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 ins
->flags
= (opcode_token
& WINED3D_SM4_SAMPLER_MODE_MASK
) >> WINED3D_SM4_SAMPLER_MODE_SHIFT
;
631 if (ins
->flags
& ~WINED3D_SM4_SAMPLER_COMPARISON
)
632 FIXME("Unhandled sampler mode %#x.\n", ins
->flags
);
633 shader_sm4_read_dst_param(priv
, &tokens
, &tokens
[token_count
], WINED3D_DATA_SAMPLER
, &ins
->declaration
.dst
);
636 static void shader_sm4_read_dcl_index_range(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 shader_sm4_read_dst_param(priv
, &tokens
, &tokens
[token_count
], WINED3D_DATA_OPAQUE
,
641 &ins
->declaration
.index_range
.first_register
);
642 ins
->declaration
.index_range
.last_register
= *tokens
;
645 static void shader_sm4_read_dcl_output_topology(struct wined3d_shader_instruction
*ins
,
646 DWORD opcode
, DWORD opcode_token
, const DWORD
*tokens
, unsigned int token_count
,
647 struct wined3d_sm4_data
*priv
)
649 enum wined3d_sm4_output_primitive_type primitive_type
;
651 primitive_type
= (opcode_token
& WINED3D_SM4_PRIMITIVE_TYPE_MASK
) >> WINED3D_SM4_PRIMITIVE_TYPE_SHIFT
;
652 if (primitive_type
>= ARRAY_SIZE(output_primitive_type_table
))
653 ins
->declaration
.primitive_type
.type
= WINED3D_PT_UNDEFINED
;
655 ins
->declaration
.primitive_type
.type
= output_primitive_type_table
[primitive_type
];
657 if (ins
->declaration
.primitive_type
.type
== WINED3D_PT_UNDEFINED
)
658 FIXME("Unhandled output primitive type %#x.\n", primitive_type
);
661 static void shader_sm4_read_dcl_input_primitive(struct wined3d_shader_instruction
*ins
,
662 DWORD opcode
, DWORD opcode_token
, const DWORD
*tokens
, unsigned int token_count
,
663 struct wined3d_sm4_data
*priv
)
665 enum wined3d_sm4_input_primitive_type primitive_type
;
667 primitive_type
= (opcode_token
& WINED3D_SM4_PRIMITIVE_TYPE_MASK
) >> WINED3D_SM4_PRIMITIVE_TYPE_SHIFT
;
668 if (WINED3D_SM5_INPUT_PT_PATCH1
<= primitive_type
&& primitive_type
<= WINED3D_SM5_INPUT_PT_PATCH32
)
670 ins
->declaration
.primitive_type
.type
= WINED3D_PT_PATCH
;
671 ins
->declaration
.primitive_type
.patch_vertex_count
= primitive_type
- WINED3D_SM5_INPUT_PT_PATCH1
+ 1;
673 else if (primitive_type
>= ARRAY_SIZE(input_primitive_type_table
))
675 ins
->declaration
.primitive_type
.type
= WINED3D_PT_UNDEFINED
;
679 ins
->declaration
.primitive_type
.type
= input_primitive_type_table
[primitive_type
];
682 if (ins
->declaration
.primitive_type
.type
== WINED3D_PT_UNDEFINED
)
683 FIXME("Unhandled input primitive type %#x.\n", primitive_type
);
686 static void shader_sm4_read_declaration_count(struct wined3d_shader_instruction
*ins
,
687 DWORD opcode
, DWORD opcode_token
, const DWORD
*tokens
, unsigned int token_count
,
688 struct wined3d_sm4_data
*priv
)
690 ins
->declaration
.count
= *tokens
;
693 static void shader_sm4_read_declaration_dst(struct wined3d_shader_instruction
*ins
,
694 DWORD opcode
, DWORD opcode_token
, const DWORD
*tokens
, unsigned int token_count
,
695 struct wined3d_sm4_data
*priv
)
697 shader_sm4_read_dst_param(priv
, &tokens
, &tokens
[token_count
], WINED3D_DATA_FLOAT
, &ins
->declaration
.dst
);
700 static void shader_sm4_read_declaration_register_semantic(struct wined3d_shader_instruction
*ins
,
701 DWORD opcode
, DWORD opcode_token
, const DWORD
*tokens
, unsigned int token_count
,
702 struct wined3d_sm4_data
*priv
)
704 shader_sm4_read_dst_param(priv
, &tokens
, &tokens
[token_count
], WINED3D_DATA_FLOAT
,
705 &ins
->declaration
.register_semantic
.reg
);
706 ins
->declaration
.register_semantic
.sysval_semantic
= *tokens
;
709 static void shader_sm4_read_dcl_input_ps(struct wined3d_shader_instruction
*ins
,
710 DWORD opcode
, DWORD opcode_token
, const DWORD
*tokens
, unsigned int token_count
,
711 struct wined3d_sm4_data
*priv
)
713 ins
->flags
= (opcode_token
& WINED3D_SM4_INTERPOLATION_MODE_MASK
) >> WINED3D_SM4_INTERPOLATION_MODE_SHIFT
;
714 shader_sm4_read_dst_param(priv
, &tokens
, &tokens
[token_count
], WINED3D_DATA_FLOAT
, &ins
->declaration
.dst
);
717 static void shader_sm4_read_dcl_input_ps_siv(struct wined3d_shader_instruction
*ins
,
718 DWORD opcode
, DWORD opcode_token
, const DWORD
*tokens
, unsigned int token_count
,
719 struct wined3d_sm4_data
*priv
)
721 ins
->flags
= (opcode_token
& WINED3D_SM4_INTERPOLATION_MODE_MASK
) >> WINED3D_SM4_INTERPOLATION_MODE_SHIFT
;
722 shader_sm4_read_dst_param(priv
, &tokens
, &tokens
[token_count
], WINED3D_DATA_FLOAT
,
723 &ins
->declaration
.register_semantic
.reg
);
724 ins
->declaration
.register_semantic
.sysval_semantic
= *tokens
;
727 static void shader_sm4_read_dcl_indexable_temp(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
->declaration
.indexable_temp
.register_idx
= *tokens
++;
732 ins
->declaration
.indexable_temp
.register_size
= *tokens
++;
733 ins
->declaration
.indexable_temp
.component_count
= *tokens
;
736 static void shader_sm4_read_dcl_global_flags(struct wined3d_shader_instruction
*ins
,
737 DWORD opcode
, DWORD opcode_token
, const DWORD
*tokens
, unsigned int token_count
,
738 struct wined3d_sm4_data
*priv
)
740 ins
->flags
= (opcode_token
& WINED3D_SM4_GLOBAL_FLAGS_MASK
) >> WINED3D_SM4_GLOBAL_FLAGS_SHIFT
;
743 static void shader_sm5_read_fcall(struct wined3d_shader_instruction
*ins
,
744 DWORD opcode
, DWORD opcode_token
, const DWORD
*tokens
, unsigned int token_count
,
745 struct wined3d_sm4_data
*priv
)
747 priv
->src_param
[0].reg
.u
.fp_body_idx
= *tokens
++;
748 shader_sm4_read_src_param(priv
, &tokens
, &tokens
[token_count
], WINED3D_DATA_OPAQUE
, &priv
->src_param
[0]);
751 static void shader_sm5_read_dcl_function_body(struct wined3d_shader_instruction
*ins
,
752 DWORD opcode
, DWORD opcode_token
, const DWORD
*tokens
, unsigned int token_count
,
753 struct wined3d_sm4_data
*priv
)
755 ins
->declaration
.index
= *tokens
;
758 static void shader_sm5_read_dcl_function_table(struct wined3d_shader_instruction
*ins
,
759 DWORD opcode
, DWORD opcode_token
, const DWORD
*tokens
, unsigned int token_count
,
760 struct wined3d_sm4_data
*priv
)
762 ins
->declaration
.index
= *tokens
++;
763 FIXME("Ignoring set of function bodies (count %u).\n", *tokens
);
766 static void shader_sm5_read_dcl_interface(struct wined3d_shader_instruction
*ins
,
767 DWORD opcode
, DWORD opcode_token
, const DWORD
*tokens
, unsigned int token_count
,
768 struct wined3d_sm4_data
*priv
)
770 ins
->declaration
.fp
.index
= *tokens
++;
771 ins
->declaration
.fp
.body_count
= *tokens
++;
772 ins
->declaration
.fp
.array_size
= *tokens
>> WINED3D_SM5_FP_ARRAY_SIZE_SHIFT
;
773 ins
->declaration
.fp
.table_count
= *tokens
++ & WINED3D_SM5_FP_TABLE_COUNT_MASK
;
774 FIXME("Ignoring set of function tables (count %u).\n", ins
->declaration
.fp
.table_count
);
777 static void shader_sm5_read_control_point_count(struct wined3d_shader_instruction
*ins
,
778 DWORD opcode
, DWORD opcode_token
, const DWORD
*tokens
, unsigned int token_count
,
779 struct wined3d_sm4_data
*priv
)
781 ins
->declaration
.count
= (opcode_token
& WINED3D_SM5_CONTROL_POINT_COUNT_MASK
)
782 >> WINED3D_SM5_CONTROL_POINT_COUNT_SHIFT
;
785 static void shader_sm5_read_dcl_tessellator_domain(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 ins
->declaration
.tessellator_domain
= (opcode_token
& WINED3D_SM5_TESSELLATOR_MASK
)
790 >> WINED3D_SM5_TESSELLATOR_SHIFT
;
793 static void shader_sm5_read_dcl_tessellator_partitioning(struct wined3d_shader_instruction
*ins
,
794 DWORD opcode
, DWORD opcode_token
, const DWORD
*tokens
, unsigned int token_count
,
795 struct wined3d_sm4_data
*priv
)
797 ins
->declaration
.tessellator_partitioning
= (opcode_token
& WINED3D_SM5_TESSELLATOR_MASK
)
798 >> WINED3D_SM5_TESSELLATOR_SHIFT
;
801 static void shader_sm5_read_dcl_tessellator_output_primitive(struct wined3d_shader_instruction
*ins
,
802 DWORD opcode
, DWORD opcode_token
, const DWORD
*tokens
, unsigned int token_count
,
803 struct wined3d_sm4_data
*priv
)
805 ins
->declaration
.tessellator_output_primitive
= (opcode_token
& WINED3D_SM5_TESSELLATOR_MASK
)
806 >> WINED3D_SM5_TESSELLATOR_SHIFT
;
809 static void shader_sm5_read_dcl_hs_max_tessfactor(struct wined3d_shader_instruction
*ins
,
810 DWORD opcode
, DWORD opcode_token
, const DWORD
*tokens
, unsigned int token_count
,
811 struct wined3d_sm4_data
*priv
)
813 ins
->declaration
.max_tessellation_factor
= *(float *)tokens
;
816 static void shader_sm5_read_dcl_thread_group(struct wined3d_shader_instruction
*ins
,
817 DWORD opcode
, DWORD opcode_token
, const DWORD
*tokens
, unsigned int token_count
,
818 struct wined3d_sm4_data
*priv
)
820 ins
->declaration
.thread_group_size
.x
= *tokens
++;
821 ins
->declaration
.thread_group_size
.y
= *tokens
++;
822 ins
->declaration
.thread_group_size
.z
= *tokens
++;
825 static void shader_sm5_read_dcl_uav_raw(struct wined3d_shader_instruction
*ins
,
826 DWORD opcode
, DWORD opcode_token
, const DWORD
*tokens
, unsigned int token_count
,
827 struct wined3d_sm4_data
*priv
)
829 shader_sm4_read_dst_param(priv
, &tokens
, &tokens
[token_count
], WINED3D_DATA_UAV
, &ins
->declaration
.dst
);
830 ins
->flags
= (opcode_token
& WINED3D_SM5_UAV_FLAGS_MASK
) >> WINED3D_SM5_UAV_FLAGS_SHIFT
;
833 static void shader_sm5_read_dcl_uav_structured(struct wined3d_shader_instruction
*ins
,
834 DWORD opcode
, DWORD opcode_token
, const DWORD
*tokens
, unsigned int token_count
,
835 struct wined3d_sm4_data
*priv
)
837 shader_sm4_read_dst_param(priv
, &tokens
, &tokens
[token_count
], WINED3D_DATA_UAV
,
838 &ins
->declaration
.structured_resource
.reg
);
839 ins
->flags
= (opcode_token
& WINED3D_SM5_UAV_FLAGS_MASK
) >> WINED3D_SM5_UAV_FLAGS_SHIFT
;
840 ins
->declaration
.structured_resource
.byte_stride
= *tokens
;
841 if (ins
->declaration
.structured_resource
.byte_stride
% 4)
842 FIXME("Byte stride %u is not multiple of 4.\n", ins
->declaration
.structured_resource
.byte_stride
);
845 static void shader_sm5_read_dcl_tgsm_raw(struct wined3d_shader_instruction
*ins
,
846 DWORD opcode
, DWORD opcode_token
, const DWORD
*tokens
, unsigned int token_count
,
847 struct wined3d_sm4_data
*priv
)
849 shader_sm4_read_dst_param(priv
, &tokens
, &tokens
[token_count
], WINED3D_DATA_FLOAT
, &ins
->declaration
.tgsm_raw
.reg
);
850 ins
->declaration
.tgsm_raw
.byte_count
= *tokens
;
851 if (ins
->declaration
.tgsm_raw
.byte_count
% 4)
852 FIXME("Byte count %u is not multiple of 4.\n", ins
->declaration
.tgsm_raw
.byte_count
);
855 static void shader_sm5_read_dcl_tgsm_structured(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
,
860 &ins
->declaration
.tgsm_structured
.reg
);
861 ins
->declaration
.tgsm_structured
.byte_stride
= *tokens
++;
862 ins
->declaration
.tgsm_structured
.structure_count
= *tokens
;
863 if (ins
->declaration
.tgsm_structured
.byte_stride
% 4)
864 FIXME("Byte stride %u is not multiple of 4.\n", ins
->declaration
.tgsm_structured
.byte_stride
);
867 static void shader_sm5_read_dcl_resource_structured(struct wined3d_shader_instruction
*ins
,
868 DWORD opcode
, DWORD opcode_token
, const DWORD
*tokens
, unsigned int token_count
,
869 struct wined3d_sm4_data
*priv
)
871 shader_sm4_read_dst_param(priv
, &tokens
, &tokens
[token_count
], WINED3D_DATA_RESOURCE
,
872 &ins
->declaration
.structured_resource
.reg
);
873 ins
->declaration
.structured_resource
.byte_stride
= *tokens
;
874 if (ins
->declaration
.structured_resource
.byte_stride
% 4)
875 FIXME("Byte stride %u is not multiple of 4.\n", ins
->declaration
.structured_resource
.byte_stride
);
878 static void shader_sm5_read_dcl_resource_raw(struct wined3d_shader_instruction
*ins
,
879 DWORD opcode
, DWORD opcode_token
, const DWORD
*tokens
, unsigned int token_count
,
880 struct wined3d_sm4_data
*priv
)
882 shader_sm4_read_dst_param(priv
, &tokens
, &tokens
[token_count
], WINED3D_DATA_RESOURCE
, &ins
->declaration
.dst
);
885 static void shader_sm5_read_sync(struct wined3d_shader_instruction
*ins
,
886 DWORD opcode
, DWORD opcode_token
, const DWORD
*tokens
, unsigned int token_count
,
887 struct wined3d_sm4_data
*priv
)
889 ins
->flags
= (opcode_token
& WINED3D_SM5_SYNC_FLAGS_MASK
) >> WINED3D_SM5_SYNC_FLAGS_SHIFT
;
893 * f -> WINED3D_DATA_FLOAT
894 * i -> WINED3D_DATA_INT
895 * u -> WINED3D_DATA_UINT
896 * O -> WINED3D_DATA_OPAQUE
897 * R -> WINED3D_DATA_RESOURCE
898 * S -> WINED3D_DATA_SAMPLER
899 * U -> WINED3D_DATA_UAV
901 static const struct wined3d_sm4_opcode_info opcode_table
[] =
903 {WINED3D_SM4_OP_ADD
, WINED3DSIH_ADD
, "f", "ff"},
904 {WINED3D_SM4_OP_AND
, WINED3DSIH_AND
, "u", "uu"},
905 {WINED3D_SM4_OP_BREAK
, WINED3DSIH_BREAK
, "", ""},
906 {WINED3D_SM4_OP_BREAKC
, WINED3DSIH_BREAKP
, "", "u",
907 shader_sm4_read_conditional_op
},
908 {WINED3D_SM4_OP_CASE
, WINED3DSIH_CASE
, "", "u"},
909 {WINED3D_SM4_OP_CONTINUE
, WINED3DSIH_CONTINUE
, "", ""},
910 {WINED3D_SM4_OP_CONTINUEC
, WINED3DSIH_CONTINUEP
, "", "u",
911 shader_sm4_read_conditional_op
},
912 {WINED3D_SM4_OP_CUT
, WINED3DSIH_CUT
, "", ""},
913 {WINED3D_SM4_OP_DEFAULT
, WINED3DSIH_DEFAULT
, "", ""},
914 {WINED3D_SM4_OP_DERIV_RTX
, WINED3DSIH_DSX
, "f", "f"},
915 {WINED3D_SM4_OP_DERIV_RTY
, WINED3DSIH_DSY
, "f", "f"},
916 {WINED3D_SM4_OP_DISCARD
, WINED3DSIH_TEXKILL
, "", "u",
917 shader_sm4_read_conditional_op
},
918 {WINED3D_SM4_OP_DIV
, WINED3DSIH_DIV
, "f", "ff"},
919 {WINED3D_SM4_OP_DP2
, WINED3DSIH_DP2
, "f", "ff"},
920 {WINED3D_SM4_OP_DP3
, WINED3DSIH_DP3
, "f", "ff"},
921 {WINED3D_SM4_OP_DP4
, WINED3DSIH_DP4
, "f", "ff"},
922 {WINED3D_SM4_OP_ELSE
, WINED3DSIH_ELSE
, "", ""},
923 {WINED3D_SM4_OP_EMIT
, WINED3DSIH_EMIT
, "", ""},
924 {WINED3D_SM4_OP_ENDIF
, WINED3DSIH_ENDIF
, "", ""},
925 {WINED3D_SM4_OP_ENDLOOP
, WINED3DSIH_ENDLOOP
, "", ""},
926 {WINED3D_SM4_OP_ENDSWITCH
, WINED3DSIH_ENDSWITCH
, "", ""},
927 {WINED3D_SM4_OP_EQ
, WINED3DSIH_EQ
, "u", "ff"},
928 {WINED3D_SM4_OP_EXP
, WINED3DSIH_EXP
, "f", "f"},
929 {WINED3D_SM4_OP_FRC
, WINED3DSIH_FRC
, "f", "f"},
930 {WINED3D_SM4_OP_FTOI
, WINED3DSIH_FTOI
, "i", "f"},
931 {WINED3D_SM4_OP_FTOU
, WINED3DSIH_FTOU
, "u", "f"},
932 {WINED3D_SM4_OP_GE
, WINED3DSIH_GE
, "u", "ff"},
933 {WINED3D_SM4_OP_IADD
, WINED3DSIH_IADD
, "i", "ii"},
934 {WINED3D_SM4_OP_IF
, WINED3DSIH_IF
, "", "u",
935 shader_sm4_read_conditional_op
},
936 {WINED3D_SM4_OP_IEQ
, WINED3DSIH_IEQ
, "u", "ii"},
937 {WINED3D_SM4_OP_IGE
, WINED3DSIH_IGE
, "u", "ii"},
938 {WINED3D_SM4_OP_ILT
, WINED3DSIH_ILT
, "u", "ii"},
939 {WINED3D_SM4_OP_IMAD
, WINED3DSIH_IMAD
, "i", "iii"},
940 {WINED3D_SM4_OP_IMAX
, WINED3DSIH_IMAX
, "i", "ii"},
941 {WINED3D_SM4_OP_IMIN
, WINED3DSIH_IMIN
, "i", "ii"},
942 {WINED3D_SM4_OP_IMUL
, WINED3DSIH_IMUL
, "ii", "ii"},
943 {WINED3D_SM4_OP_INE
, WINED3DSIH_INE
, "u", "ii"},
944 {WINED3D_SM4_OP_INEG
, WINED3DSIH_INEG
, "i", "i"},
945 {WINED3D_SM4_OP_ISHL
, WINED3DSIH_ISHL
, "i", "ii"},
946 {WINED3D_SM4_OP_ISHR
, WINED3DSIH_ISHR
, "i", "ii"},
947 {WINED3D_SM4_OP_ITOF
, WINED3DSIH_ITOF
, "f", "i"},
948 {WINED3D_SM4_OP_LABEL
, WINED3DSIH_LABEL
, "", "O"},
949 {WINED3D_SM4_OP_LD
, WINED3DSIH_LD
, "u", "iR"},
950 {WINED3D_SM4_OP_LD2DMS
, WINED3DSIH_LD2DMS
, "u", "iRi"},
951 {WINED3D_SM4_OP_LOG
, WINED3DSIH_LOG
, "f", "f"},
952 {WINED3D_SM4_OP_LOOP
, WINED3DSIH_LOOP
, "", ""},
953 {WINED3D_SM4_OP_LT
, WINED3DSIH_LT
, "u", "ff"},
954 {WINED3D_SM4_OP_MAD
, WINED3DSIH_MAD
, "f", "fff"},
955 {WINED3D_SM4_OP_MIN
, WINED3DSIH_MIN
, "f", "ff"},
956 {WINED3D_SM4_OP_MAX
, WINED3DSIH_MAX
, "f", "ff"},
957 {WINED3D_SM4_OP_SHADER_DATA
, WINED3DSIH_DCL_IMMEDIATE_CONSTANT_BUFFER
, "", "",
958 shader_sm4_read_shader_data
},
959 {WINED3D_SM4_OP_MOV
, WINED3DSIH_MOV
, "f", "f"},
960 {WINED3D_SM4_OP_MOVC
, WINED3DSIH_MOVC
, "f", "uff"},
961 {WINED3D_SM4_OP_MUL
, WINED3DSIH_MUL
, "f", "ff"},
962 {WINED3D_SM4_OP_NE
, WINED3DSIH_NE
, "u", "ff"},
963 {WINED3D_SM4_OP_NOP
, WINED3DSIH_NOP
, "", ""},
964 {WINED3D_SM4_OP_NOT
, WINED3DSIH_NOT
, "u", "u"},
965 {WINED3D_SM4_OP_OR
, WINED3DSIH_OR
, "u", "uu"},
966 {WINED3D_SM4_OP_RESINFO
, WINED3DSIH_RESINFO
, "f", "iR"},
967 {WINED3D_SM4_OP_RET
, WINED3DSIH_RET
, "", ""},
968 {WINED3D_SM4_OP_RETC
, WINED3DSIH_RETP
, "", "u",
969 shader_sm4_read_conditional_op
},
970 {WINED3D_SM4_OP_ROUND_NE
, WINED3DSIH_ROUND_NE
, "f", "f"},
971 {WINED3D_SM4_OP_ROUND_NI
, WINED3DSIH_ROUND_NI
, "f", "f"},
972 {WINED3D_SM4_OP_ROUND_PI
, WINED3DSIH_ROUND_PI
, "f", "f"},
973 {WINED3D_SM4_OP_ROUND_Z
, WINED3DSIH_ROUND_Z
, "f", "f"},
974 {WINED3D_SM4_OP_RSQ
, WINED3DSIH_RSQ
, "f", "f"},
975 {WINED3D_SM4_OP_SAMPLE
, WINED3DSIH_SAMPLE
, "u", "fRS"},
976 {WINED3D_SM4_OP_SAMPLE_C
, WINED3DSIH_SAMPLE_C
, "f", "fRSf"},
977 {WINED3D_SM4_OP_SAMPLE_C_LZ
, WINED3DSIH_SAMPLE_C_LZ
, "f", "fRSf"},
978 {WINED3D_SM4_OP_SAMPLE_LOD
, WINED3DSIH_SAMPLE_LOD
, "u", "fRSf"},
979 {WINED3D_SM4_OP_SAMPLE_GRAD
, WINED3DSIH_SAMPLE_GRAD
, "u", "fRSff"},
980 {WINED3D_SM4_OP_SAMPLE_B
, WINED3DSIH_SAMPLE_B
, "u", "fRSf"},
981 {WINED3D_SM4_OP_SQRT
, WINED3DSIH_SQRT
, "f", "f"},
982 {WINED3D_SM4_OP_SWITCH
, WINED3DSIH_SWITCH
, "", "u"},
983 {WINED3D_SM4_OP_SINCOS
, WINED3DSIH_SINCOS
, "ff", "f"},
984 {WINED3D_SM4_OP_UDIV
, WINED3DSIH_UDIV
, "uu", "uu"},
985 {WINED3D_SM4_OP_ULT
, WINED3DSIH_ULT
, "u", "uu"},
986 {WINED3D_SM4_OP_UGE
, WINED3DSIH_UGE
, "u", "uu"},
987 {WINED3D_SM4_OP_UMUL
, WINED3DSIH_UMUL
, "uu", "uu"},
988 {WINED3D_SM4_OP_UMAX
, WINED3DSIH_UMAX
, "u", "uu"},
989 {WINED3D_SM4_OP_UMIN
, WINED3DSIH_UMIN
, "u", "uu"},
990 {WINED3D_SM4_OP_USHR
, WINED3DSIH_USHR
, "u", "uu"},
991 {WINED3D_SM4_OP_UTOF
, WINED3DSIH_UTOF
, "f", "u"},
992 {WINED3D_SM4_OP_XOR
, WINED3DSIH_XOR
, "u", "uu"},
993 {WINED3D_SM4_OP_DCL_RESOURCE
, WINED3DSIH_DCL
, "R", "",
994 shader_sm4_read_dcl_resource
},
995 {WINED3D_SM4_OP_DCL_CONSTANT_BUFFER
, WINED3DSIH_DCL_CONSTANT_BUFFER
, "", "",
996 shader_sm4_read_dcl_constant_buffer
},
997 {WINED3D_SM4_OP_DCL_SAMPLER
, WINED3DSIH_DCL_SAMPLER
, "", "",
998 shader_sm4_read_dcl_sampler
},
999 {WINED3D_SM4_OP_DCL_INDEX_RANGE
, WINED3DSIH_DCL_INDEX_RANGE
, "", "",
1000 shader_sm4_read_dcl_index_range
},
1001 {WINED3D_SM4_OP_DCL_OUTPUT_TOPOLOGY
, WINED3DSIH_DCL_OUTPUT_TOPOLOGY
, "", "",
1002 shader_sm4_read_dcl_output_topology
},
1003 {WINED3D_SM4_OP_DCL_INPUT_PRIMITIVE
, WINED3DSIH_DCL_INPUT_PRIMITIVE
, "", "",
1004 shader_sm4_read_dcl_input_primitive
},
1005 {WINED3D_SM4_OP_DCL_VERTICES_OUT
, WINED3DSIH_DCL_VERTICES_OUT
, "", "",
1006 shader_sm4_read_declaration_count
},
1007 {WINED3D_SM4_OP_DCL_INPUT
, WINED3DSIH_DCL_INPUT
, "", "",
1008 shader_sm4_read_declaration_dst
},
1009 {WINED3D_SM4_OP_DCL_INPUT_SGV
, WINED3DSIH_DCL_INPUT_SGV
, "", "",
1010 shader_sm4_read_declaration_register_semantic
},
1011 {WINED3D_SM4_OP_DCL_INPUT_SIV
, WINED3DSIH_DCL_INPUT_SIV
, "", "",
1012 shader_sm4_read_declaration_register_semantic
},
1013 {WINED3D_SM4_OP_DCL_INPUT_PS
, WINED3DSIH_DCL_INPUT_PS
, "", "",
1014 shader_sm4_read_dcl_input_ps
},
1015 {WINED3D_SM4_OP_DCL_INPUT_PS_SGV
, WINED3DSIH_DCL_INPUT_PS_SGV
, "", "",
1016 shader_sm4_read_declaration_register_semantic
},
1017 {WINED3D_SM4_OP_DCL_INPUT_PS_SIV
, WINED3DSIH_DCL_INPUT_PS_SIV
, "", "",
1018 shader_sm4_read_dcl_input_ps_siv
},
1019 {WINED3D_SM4_OP_DCL_OUTPUT
, WINED3DSIH_DCL_OUTPUT
, "", "",
1020 shader_sm4_read_declaration_dst
},
1021 {WINED3D_SM4_OP_DCL_OUTPUT_SIV
, WINED3DSIH_DCL_OUTPUT_SIV
, "", "",
1022 shader_sm4_read_declaration_register_semantic
},
1023 {WINED3D_SM4_OP_DCL_TEMPS
, WINED3DSIH_DCL_TEMPS
, "", "",
1024 shader_sm4_read_declaration_count
},
1025 {WINED3D_SM4_OP_DCL_INDEXABLE_TEMP
, WINED3DSIH_DCL_INDEXABLE_TEMP
, "", "",
1026 shader_sm4_read_dcl_indexable_temp
},
1027 {WINED3D_SM4_OP_DCL_GLOBAL_FLAGS
, WINED3DSIH_DCL_GLOBAL_FLAGS
, "", "",
1028 shader_sm4_read_dcl_global_flags
},
1029 {WINED3D_SM4_OP_LOD
, WINED3DSIH_LOD
, "f", "fRS"},
1030 {WINED3D_SM4_OP_GATHER4
, WINED3DSIH_GATHER4
, "u", "fRS"},
1031 {WINED3D_SM4_OP_SAMPLE_POS
, WINED3DSIH_SAMPLE_POS
, "f", "Ru"},
1032 {WINED3D_SM4_OP_SAMPLE_INFO
, WINED3DSIH_SAMPLE_INFO
, "f", "R"},
1033 {WINED3D_SM5_OP_HS_DECLS
, WINED3DSIH_HS_DECLS
, "", ""},
1034 {WINED3D_SM5_OP_HS_CONTROL_POINT_PHASE
, WINED3DSIH_HS_CONTROL_POINT_PHASE
, "", ""},
1035 {WINED3D_SM5_OP_HS_FORK_PHASE
, WINED3DSIH_HS_FORK_PHASE
, "", ""},
1036 {WINED3D_SM5_OP_HS_JOIN_PHASE
, WINED3DSIH_HS_JOIN_PHASE
, "", ""},
1037 {WINED3D_SM5_OP_EMIT_STREAM
, WINED3DSIH_EMIT_STREAM
, "", "f"},
1038 {WINED3D_SM5_OP_CUT_STREAM
, WINED3DSIH_CUT_STREAM
, "", "f"},
1039 {WINED3D_SM5_OP_FCALL
, WINED3DSIH_FCALL
, "", "O",
1040 shader_sm5_read_fcall
},
1041 {WINED3D_SM5_OP_BUFINFO
, WINED3DSIH_BUFINFO
, "i", "U"},
1042 {WINED3D_SM5_OP_DERIV_RTX_COARSE
, WINED3DSIH_DSX_COARSE
, "f", "f"},
1043 {WINED3D_SM5_OP_DERIV_RTX_FINE
, WINED3DSIH_DSX_FINE
, "f", "f"},
1044 {WINED3D_SM5_OP_DERIV_RTY_COARSE
, WINED3DSIH_DSY_COARSE
, "f", "f"},
1045 {WINED3D_SM5_OP_DERIV_RTY_FINE
, WINED3DSIH_DSY_FINE
, "f", "f"},
1046 {WINED3D_SM5_OP_GATHER4_C
, WINED3DSIH_GATHER4_C
, "f", "fRSf"},
1047 {WINED3D_SM5_OP_GATHER4_PO
, WINED3DSIH_GATHER4_PO
, "f", "fiRS"},
1048 {WINED3D_SM5_OP_GATHER4_PO_C
, WINED3DSIH_GATHER4_PO_C
, "f", "fiRSf"},
1049 {WINED3D_SM5_OP_RCP
, WINED3DSIH_RCP
, "f", "f"},
1050 {WINED3D_SM5_OP_F32TOF16
, WINED3DSIH_F32TOF16
, "u", "f"},
1051 {WINED3D_SM5_OP_F16TOF32
, WINED3DSIH_F16TOF32
, "f", "u"},
1052 {WINED3D_SM5_OP_COUNTBITS
, WINED3DSIH_COUNTBITS
, "u", "u"},
1053 {WINED3D_SM5_OP_FIRSTBIT_HI
, WINED3DSIH_FIRSTBIT_HI
, "u", "u"},
1054 {WINED3D_SM5_OP_FIRSTBIT_LO
, WINED3DSIH_FIRSTBIT_LO
, "u", "u"},
1055 {WINED3D_SM5_OP_FIRSTBIT_SHI
, WINED3DSIH_FIRSTBIT_SHI
, "u", "i"},
1056 {WINED3D_SM5_OP_UBFE
, WINED3DSIH_UBFE
, "u", "iiu"},
1057 {WINED3D_SM5_OP_IBFE
, WINED3DSIH_IBFE
, "i", "iii"},
1058 {WINED3D_SM5_OP_BFI
, WINED3DSIH_BFI
, "u", "iiuu"},
1059 {WINED3D_SM5_OP_BFREV
, WINED3DSIH_BFREV
, "u", "u"},
1060 {WINED3D_SM5_OP_SWAPC
, WINED3DSIH_SWAPC
, "ff", "uff"},
1061 {WINED3D_SM5_OP_DCL_STREAM
, WINED3DSIH_DCL_STREAM
, "", "O"},
1062 {WINED3D_SM5_OP_DCL_FUNCTION_BODY
, WINED3DSIH_DCL_FUNCTION_BODY
, "", "",
1063 shader_sm5_read_dcl_function_body
},
1064 {WINED3D_SM5_OP_DCL_FUNCTION_TABLE
, WINED3DSIH_DCL_FUNCTION_TABLE
, "", "",
1065 shader_sm5_read_dcl_function_table
},
1066 {WINED3D_SM5_OP_DCL_INTERFACE
, WINED3DSIH_DCL_INTERFACE
, "", "",
1067 shader_sm5_read_dcl_interface
},
1068 {WINED3D_SM5_OP_DCL_INPUT_CONTROL_POINT_COUNT
, WINED3DSIH_DCL_INPUT_CONTROL_POINT_COUNT
, "", "",
1069 shader_sm5_read_control_point_count
},
1070 {WINED3D_SM5_OP_DCL_OUTPUT_CONTROL_POINT_COUNT
, WINED3DSIH_DCL_OUTPUT_CONTROL_POINT_COUNT
, "", "",
1071 shader_sm5_read_control_point_count
},
1072 {WINED3D_SM5_OP_DCL_TESSELLATOR_DOMAIN
, WINED3DSIH_DCL_TESSELLATOR_DOMAIN
, "", "",
1073 shader_sm5_read_dcl_tessellator_domain
},
1074 {WINED3D_SM5_OP_DCL_TESSELLATOR_PARTITIONING
, WINED3DSIH_DCL_TESSELLATOR_PARTITIONING
, "", "",
1075 shader_sm5_read_dcl_tessellator_partitioning
},
1076 {WINED3D_SM5_OP_DCL_TESSELLATOR_OUTPUT_PRIMITIVE
, WINED3DSIH_DCL_TESSELLATOR_OUTPUT_PRIMITIVE
, "", "",
1077 shader_sm5_read_dcl_tessellator_output_primitive
},
1078 {WINED3D_SM5_OP_DCL_HS_MAX_TESSFACTOR
, WINED3DSIH_DCL_HS_MAX_TESSFACTOR
, "", "",
1079 shader_sm5_read_dcl_hs_max_tessfactor
},
1080 {WINED3D_SM5_OP_DCL_HS_FORK_PHASE_INSTANCE_COUNT
, WINED3DSIH_DCL_HS_FORK_PHASE_INSTANCE_COUNT
, "", "",
1081 shader_sm4_read_declaration_count
},
1082 {WINED3D_SM5_OP_DCL_HS_JOIN_PHASE_INSTANCE_COUNT
, WINED3DSIH_DCL_HS_JOIN_PHASE_INSTANCE_COUNT
, "", "",
1083 shader_sm4_read_declaration_count
},
1084 {WINED3D_SM5_OP_DCL_THREAD_GROUP
, WINED3DSIH_DCL_THREAD_GROUP
, "", "",
1085 shader_sm5_read_dcl_thread_group
},
1086 {WINED3D_SM5_OP_DCL_UAV_TYPED
, WINED3DSIH_DCL_UAV_TYPED
, "", "",
1087 shader_sm4_read_dcl_resource
},
1088 {WINED3D_SM5_OP_DCL_UAV_RAW
, WINED3DSIH_DCL_UAV_RAW
, "", "",
1089 shader_sm5_read_dcl_uav_raw
},
1090 {WINED3D_SM5_OP_DCL_UAV_STRUCTURED
, WINED3DSIH_DCL_UAV_STRUCTURED
, "", "",
1091 shader_sm5_read_dcl_uav_structured
},
1092 {WINED3D_SM5_OP_DCL_TGSM_RAW
, WINED3DSIH_DCL_TGSM_RAW
, "", "",
1093 shader_sm5_read_dcl_tgsm_raw
},
1094 {WINED3D_SM5_OP_DCL_TGSM_STRUCTURED
, WINED3DSIH_DCL_TGSM_STRUCTURED
, "", "",
1095 shader_sm5_read_dcl_tgsm_structured
},
1096 {WINED3D_SM5_OP_DCL_RESOURCE_RAW
, WINED3DSIH_DCL_RESOURCE_RAW
, "", "",
1097 shader_sm5_read_dcl_resource_raw
},
1098 {WINED3D_SM5_OP_DCL_RESOURCE_STRUCTURED
, WINED3DSIH_DCL_RESOURCE_STRUCTURED
, "", "",
1099 shader_sm5_read_dcl_resource_structured
},
1100 {WINED3D_SM5_OP_LD_UAV_TYPED
, WINED3DSIH_LD_UAV_TYPED
, "u", "iU"},
1101 {WINED3D_SM5_OP_STORE_UAV_TYPED
, WINED3DSIH_STORE_UAV_TYPED
, "U", "iu"},
1102 {WINED3D_SM5_OP_LD_RAW
, WINED3DSIH_LD_RAW
, "u", "iU"},
1103 {WINED3D_SM5_OP_STORE_RAW
, WINED3DSIH_STORE_RAW
, "U", "iu"},
1104 {WINED3D_SM5_OP_LD_STRUCTURED
, WINED3DSIH_LD_STRUCTURED
, "u", "iiR"},
1105 {WINED3D_SM5_OP_STORE_STRUCTURED
, WINED3DSIH_STORE_STRUCTURED
, "U", "iiu"},
1106 {WINED3D_SM5_OP_ATOMIC_AND
, WINED3DSIH_ATOMIC_AND
, "U", "iu"},
1107 {WINED3D_SM5_OP_ATOMIC_OR
, WINED3DSIH_ATOMIC_OR
, "U", "iu"},
1108 {WINED3D_SM5_OP_ATOMIC_XOR
, WINED3DSIH_ATOMIC_XOR
, "U", "iu"},
1109 {WINED3D_SM5_OP_ATOMIC_CMP_STORE
, WINED3DSIH_ATOMIC_CMP_STORE
, "U", "iuu"},
1110 {WINED3D_SM5_OP_ATOMIC_IADD
, WINED3DSIH_ATOMIC_IADD
, "U", "ii"},
1111 {WINED3D_SM5_OP_ATOMIC_IMAX
, WINED3DSIH_ATOMIC_IMAX
, "U", "ii"},
1112 {WINED3D_SM5_OP_ATOMIC_IMIN
, WINED3DSIH_ATOMIC_IMIN
, "U", "ii"},
1113 {WINED3D_SM5_OP_ATOMIC_UMAX
, WINED3DSIH_ATOMIC_UMAX
, "U", "iu"},
1114 {WINED3D_SM5_OP_ATOMIC_UMIN
, WINED3DSIH_ATOMIC_UMIN
, "U", "iu"},
1115 {WINED3D_SM5_OP_IMM_ATOMIC_ALLOC
, WINED3DSIH_IMM_ATOMIC_ALLOC
, "u", "U"},
1116 {WINED3D_SM5_OP_IMM_ATOMIC_CONSUME
, WINED3DSIH_IMM_ATOMIC_CONSUME
, "u", "U"},
1117 {WINED3D_SM5_OP_IMM_ATOMIC_IADD
, WINED3DSIH_IMM_ATOMIC_IADD
, "uU", "ii"},
1118 {WINED3D_SM5_OP_IMM_ATOMIC_AND
, WINED3DSIH_IMM_ATOMIC_AND
, "uU", "iu"},
1119 {WINED3D_SM5_OP_IMM_ATOMIC_OR
, WINED3DSIH_IMM_ATOMIC_OR
, "uU", "iu"},
1120 {WINED3D_SM5_OP_IMM_ATOMIC_XOR
, WINED3DSIH_IMM_ATOMIC_XOR
, "uU", "iu"},
1121 {WINED3D_SM5_OP_IMM_ATOMIC_EXCH
, WINED3DSIH_IMM_ATOMIC_EXCH
, "uU", "iu"},
1122 {WINED3D_SM5_OP_IMM_ATOMIC_CMP_EXCH
, WINED3DSIH_IMM_ATOMIC_CMP_EXCH
, "uU", "iuu"},
1123 {WINED3D_SM5_OP_IMM_ATOMIC_IMAX
, WINED3DSIH_IMM_ATOMIC_IMAX
, "iU", "ii"},
1124 {WINED3D_SM5_OP_IMM_ATOMIC_IMIN
, WINED3DSIH_IMM_ATOMIC_IMIN
, "iU", "ii"},
1125 {WINED3D_SM5_OP_IMM_ATOMIC_UMAX
, WINED3DSIH_IMM_ATOMIC_UMAX
, "uU", "iu"},
1126 {WINED3D_SM5_OP_IMM_ATOMIC_UMIN
, WINED3DSIH_IMM_ATOMIC_UMIN
, "uU", "iu"},
1127 {WINED3D_SM5_OP_SYNC
, WINED3DSIH_SYNC
, "", "",
1128 shader_sm5_read_sync
},
1129 {WINED3D_SM5_OP_EVAL_SAMPLE_INDEX
, WINED3DSIH_EVAL_SAMPLE_INDEX
, "f", "fi"},
1130 {WINED3D_SM5_OP_DCL_GS_INSTANCES
, WINED3DSIH_DCL_GS_INSTANCES
, "", "",
1131 shader_sm4_read_declaration_count
},
1134 static const enum wined3d_shader_register_type register_type_table
[] =
1136 /* WINED3D_SM4_RT_TEMP */ WINED3DSPR_TEMP
,
1137 /* WINED3D_SM4_RT_INPUT */ WINED3DSPR_INPUT
,
1138 /* WINED3D_SM4_RT_OUTPUT */ WINED3DSPR_OUTPUT
,
1139 /* WINED3D_SM4_RT_INDEXABLE_TEMP */ WINED3DSPR_IDXTEMP
,
1140 /* WINED3D_SM4_RT_IMMCONST */ WINED3DSPR_IMMCONST
,
1142 /* WINED3D_SM4_RT_SAMPLER */ WINED3DSPR_SAMPLER
,
1143 /* WINED3D_SM4_RT_RESOURCE */ WINED3DSPR_RESOURCE
,
1144 /* WINED3D_SM4_RT_CONSTBUFFER */ WINED3DSPR_CONSTBUFFER
,
1145 /* WINED3D_SM4_RT_IMMCONSTBUFFER */ WINED3DSPR_IMMCONSTBUFFER
,
1147 /* WINED3D_SM4_RT_PRIMID */ WINED3DSPR_PRIMID
,
1148 /* WINED3D_SM4_RT_DEPTHOUT */ WINED3DSPR_DEPTHOUT
,
1149 /* WINED3D_SM4_RT_NULL */ WINED3DSPR_NULL
,
1150 /* WINED3D_SM4_RT_RASTERIZER */ WINED3DSPR_RASTERIZER
,
1151 /* WINED3D_SM4_RT_OMASK */ WINED3DSPR_SAMPLEMASK
,
1152 /* WINED3D_SM5_RT_STREAM */ WINED3DSPR_STREAM
,
1153 /* WINED3D_SM5_RT_FUNCTION_BODY */ WINED3DSPR_FUNCTIONBODY
,
1155 /* WINED3D_SM5_RT_FUNCTION_POINTER */ WINED3DSPR_FUNCTIONPOINTER
,
1158 /* WINED3D_SM5_RT_OUTPUT_CONTROL_POINT_ID */ WINED3DSPR_OUTPOINTID
,
1159 /* WINED3D_SM5_RT_FORK_INSTANCE_ID */ WINED3DSPR_FORKINSTID
,
1160 /* WINED3D_SM5_RT_JOIN_INSTANCE_ID */ WINED3DSPR_JOININSTID
,
1161 /* WINED3D_SM5_RT_INPUT_CONTROL_POINT */ WINED3DSPR_INCONTROLPOINT
,
1162 /* WINED3D_SM5_RT_OUTPUT_CONTROL_POINT */ WINED3DSPR_OUTCONTROLPOINT
,
1163 /* WINED3D_SM5_RT_PATCH_CONSTANT_DATA */ WINED3DSPR_PATCHCONST
,
1164 /* WINED3D_SM5_RT_DOMAIN_LOCATION */ WINED3DSPR_TESSCOORD
,
1166 /* WINED3D_SM5_RT_UAV */ WINED3DSPR_UAV
,
1167 /* WINED3D_SM5_RT_SHARED_MEMORY */ WINED3DSPR_GROUPSHAREDMEM
,
1168 /* WINED3D_SM5_RT_THREAD_ID */ WINED3DSPR_THREADID
,
1169 /* WINED3D_SM5_RT_THREAD_GROUP_ID */ WINED3DSPR_THREADGROUPID
,
1170 /* WINED3D_SM5_RT_LOCAL_THREAD_ID */ WINED3DSPR_LOCALTHREADID
,
1171 /* WINED3D_SM5_RT_COVERAGE */ WINED3DSPR_COVERAGE
,
1172 /* WINED3D_SM5_RT_LOCAL_THREAD_INDEX */ WINED3DSPR_LOCALTHREADINDEX
,
1173 /* WINED3D_SM5_RT_GS_INSTANCE_ID */ WINED3DSPR_GSINSTID
,
1174 /* WINED3D_SM5_RT_DEPTHOUT_GREATER_EQUAL */ WINED3DSPR_DEPTHOUTGE
,
1175 /* WINED3D_SM5_RT_DEPTHOUT_LESS_EQUAL */ WINED3DSPR_DEPTHOUTLE
,
1178 static const struct wined3d_sm4_opcode_info
*get_opcode_info(enum wined3d_sm4_opcode opcode
)
1182 for (i
= 0; i
< ARRAY_SIZE(opcode_table
); ++i
)
1184 if (opcode
== opcode_table
[i
].opcode
) return &opcode_table
[i
];
1190 static void map_register(const struct wined3d_sm4_data
*priv
, struct wined3d_shader_register
*reg
)
1192 switch (priv
->shader_version
.type
)
1194 case WINED3D_SHADER_TYPE_PIXEL
:
1195 if (reg
->type
== WINED3DSPR_OUTPUT
)
1197 unsigned int reg_idx
= reg
->idx
[0].offset
;
1199 if (reg_idx
>= ARRAY_SIZE(priv
->output_map
))
1201 ERR("Invalid output index %u.\n", reg_idx
);
1205 reg
->type
= WINED3DSPR_COLOROUT
;
1206 reg
->idx
[0].offset
= priv
->output_map
[reg_idx
];
1215 static enum wined3d_data_type
map_data_type(char t
)
1220 return WINED3D_DATA_FLOAT
;
1222 return WINED3D_DATA_INT
;
1224 return WINED3D_DATA_UINT
;
1226 return WINED3D_DATA_OPAQUE
;
1228 return WINED3D_DATA_RESOURCE
;
1230 return WINED3D_DATA_SAMPLER
;
1232 return WINED3D_DATA_UAV
;
1234 ERR("Invalid data type '%c'.\n", t
);
1235 return WINED3D_DATA_FLOAT
;
1239 static enum wined3d_shader_type
wined3d_get_sm4_shader_type(const DWORD
*byte_code
, size_t byte_code_size
)
1243 if (byte_code_size
/ sizeof(*byte_code
) < 1)
1245 WARN("Invalid byte code size %lu.\n", (long)byte_code_size
);
1246 return WINED3D_SHADER_TYPE_INVALID
;
1249 shader_type
= byte_code
[0] >> 16;
1250 switch (shader_type
)
1252 case WINED3D_SM4_PS
:
1253 return WINED3D_SHADER_TYPE_PIXEL
;
1255 case WINED3D_SM4_VS
:
1256 return WINED3D_SHADER_TYPE_VERTEX
;
1258 case WINED3D_SM4_GS
:
1259 return WINED3D_SHADER_TYPE_GEOMETRY
;
1261 case WINED3D_SM5_HS
:
1262 return WINED3D_SHADER_TYPE_HULL
;
1264 case WINED3D_SM5_DS
:
1265 return WINED3D_SHADER_TYPE_DOMAIN
;
1267 case WINED3D_SM5_CS
:
1268 return WINED3D_SHADER_TYPE_COMPUTE
;
1271 FIXME("Unrecognised shader type %#x.\n", shader_type
);
1272 return WINED3D_SHADER_TYPE_INVALID
;
1276 static void *shader_sm4_init(const DWORD
*byte_code
, size_t byte_code_size
,
1277 const struct wined3d_shader_signature
*output_signature
)
1279 DWORD version_token
, token_count
;
1280 struct wined3d_sm4_data
*priv
;
1283 if (byte_code_size
/ sizeof(*byte_code
) < 2)
1285 WARN("Invalid byte code size %lu.\n", (long)byte_code_size
);
1289 version_token
= byte_code
[0];
1290 TRACE("Version: 0x%08x.\n", version_token
);
1291 token_count
= byte_code
[1];
1292 TRACE("Token count: %u.\n", token_count
);
1294 if (token_count
< 2 || byte_code_size
/ sizeof(*byte_code
) < token_count
)
1296 WARN("Invalid token count %u.\n", token_count
);
1300 if (!(priv
= heap_alloc(sizeof(*priv
))))
1302 ERR("Failed to allocate private data\n");
1306 priv
->start
= &byte_code
[2];
1307 priv
->end
= &byte_code
[token_count
];
1309 priv
->shader_version
.type
= wined3d_get_sm4_shader_type(byte_code
, byte_code_size
);
1310 if (priv
->shader_version
.type
== WINED3D_SHADER_TYPE_INVALID
)
1316 priv
->shader_version
.major
= WINED3D_SM4_VERSION_MAJOR(version_token
);
1317 priv
->shader_version
.minor
= WINED3D_SM4_VERSION_MINOR(version_token
);
1319 memset(priv
->output_map
, 0xff, sizeof(priv
->output_map
));
1320 for (i
= 0; i
< output_signature
->element_count
; ++i
)
1322 struct wined3d_shader_signature_element
*e
= &output_signature
->elements
[i
];
1324 if (e
->register_idx
>= ARRAY_SIZE(priv
->output_map
))
1326 WARN("Invalid output index %u.\n", e
->register_idx
);
1330 priv
->output_map
[e
->register_idx
] = e
->semantic_idx
;
1333 list_init(&priv
->src_free
);
1334 list_init(&priv
->src
);
1339 static void shader_sm4_free(void *data
)
1341 struct wined3d_shader_src_param_entry
*e1
, *e2
;
1342 struct wined3d_sm4_data
*priv
= data
;
1344 list_move_head(&priv
->src_free
, &priv
->src
);
1345 LIST_FOR_EACH_ENTRY_SAFE(e1
, e2
, &priv
->src_free
, struct wined3d_shader_src_param_entry
, entry
)
1352 static struct wined3d_shader_src_param
*get_src_param(struct wined3d_sm4_data
*priv
)
1354 struct wined3d_shader_src_param_entry
*e
;
1357 if (!list_empty(&priv
->src_free
))
1359 elem
= list_head(&priv
->src_free
);
1364 if (!(e
= heap_alloc(sizeof(*e
))))
1369 list_add_tail(&priv
->src
, elem
);
1370 e
= LIST_ENTRY(elem
, struct wined3d_shader_src_param_entry
, entry
);
1374 static void shader_sm4_read_header(void *data
, const DWORD
**ptr
, struct wined3d_shader_version
*shader_version
)
1376 struct wined3d_sm4_data
*priv
= data
;
1379 *shader_version
= priv
->shader_version
;
1382 static BOOL
shader_sm4_read_reg_idx(struct wined3d_sm4_data
*priv
, const DWORD
**ptr
, const DWORD
*end
,
1383 DWORD addressing
, struct wined3d_shader_register_index
*reg_idx
)
1385 if (addressing
& WINED3D_SM4_ADDRESSING_RELATIVE
)
1387 struct wined3d_shader_src_param
*rel_addr
= get_src_param(priv
);
1389 if (!(reg_idx
->rel_addr
= rel_addr
))
1391 ERR("Failed to get src param for relative addressing.\n");
1395 if (addressing
& WINED3D_SM4_ADDRESSING_OFFSET
)
1396 reg_idx
->offset
= *(*ptr
)++;
1398 reg_idx
->offset
= 0;
1399 shader_sm4_read_src_param(priv
, ptr
, end
, WINED3D_DATA_INT
, rel_addr
);
1403 reg_idx
->rel_addr
= NULL
;
1404 reg_idx
->offset
= *(*ptr
)++;
1410 static BOOL
shader_sm4_read_param(struct wined3d_sm4_data
*priv
, const DWORD
**ptr
, const DWORD
*end
,
1411 enum wined3d_data_type data_type
, struct wined3d_shader_register
*param
,
1412 enum wined3d_shader_src_modifier
*modifier
)
1414 enum wined3d_sm4_register_type register_type
;
1419 WARN("Invalid ptr %p >= end %p.\n", *ptr
, end
);
1424 register_type
= (token
& WINED3D_SM4_REGISTER_TYPE_MASK
) >> WINED3D_SM4_REGISTER_TYPE_SHIFT
;
1425 if (register_type
>= ARRAY_SIZE(register_type_table
)
1426 || register_type_table
[register_type
] == ~0u)
1428 FIXME("Unhandled register type %#x.\n", register_type
);
1429 param
->type
= WINED3DSPR_TEMP
;
1433 param
->type
= register_type_table
[register_type
];
1435 param
->data_type
= data_type
;
1437 if (token
& WINED3D_SM4_REGISTER_MODIFIER
)
1443 WARN("Invalid ptr %p >= end %p.\n", *ptr
, end
);
1451 *modifier
= WINED3DSPSM_NEG
;
1455 *modifier
= WINED3DSPSM_ABS
;
1459 *modifier
= WINED3DSPSM_ABSNEG
;
1463 FIXME("Skipping modifier 0x%08x.\n", m
);
1464 *modifier
= WINED3DSPSM_NONE
;
1470 *modifier
= WINED3DSPSM_NONE
;
1473 order
= (token
& WINED3D_SM4_REGISTER_ORDER_MASK
) >> WINED3D_SM4_REGISTER_ORDER_SHIFT
;
1476 param
->idx
[0].offset
= ~0U;
1479 DWORD addressing
= (token
& WINED3D_SM4_ADDRESSING_MASK0
) >> WINED3D_SM4_ADDRESSING_SHIFT0
;
1480 if (!(shader_sm4_read_reg_idx(priv
, ptr
, end
, addressing
, ¶m
->idx
[0])))
1482 ERR("Failed to read register index.\n");
1488 param
->idx
[1].offset
= ~0U;
1491 DWORD addressing
= (token
& WINED3D_SM4_ADDRESSING_MASK1
) >> WINED3D_SM4_ADDRESSING_SHIFT1
;
1492 if (!(shader_sm4_read_reg_idx(priv
, ptr
, end
, addressing
, ¶m
->idx
[1])))
1494 ERR("Failed to read register index.\n");
1500 FIXME("Unhandled order %u.\n", order
);
1502 if (register_type
== WINED3D_SM4_RT_IMMCONST
)
1504 enum wined3d_sm4_dimension dimension
= (token
& WINED3D_SM4_DIMENSION_MASK
) >> WINED3D_SM4_DIMENSION_SHIFT
;
1508 case WINED3D_SM4_DIMENSION_SCALAR
:
1509 param
->immconst_type
= WINED3D_IMMCONST_SCALAR
;
1512 WARN("Invalid ptr %p, end %p.\n", *ptr
, end
);
1515 memcpy(param
->u
.immconst_data
, *ptr
, 1 * sizeof(DWORD
));
1519 case WINED3D_SM4_DIMENSION_VEC4
:
1520 param
->immconst_type
= WINED3D_IMMCONST_VEC4
;
1523 WARN("Invalid ptr %p, end %p.\n", *ptr
, end
);
1526 memcpy(param
->u
.immconst_data
, *ptr
, 4 * sizeof(DWORD
));
1531 FIXME("Unhandled dimension %#x.\n", dimension
);
1536 map_register(priv
, param
);
1541 static BOOL
shader_sm4_read_src_param(struct wined3d_sm4_data
*priv
, const DWORD
**ptr
, const DWORD
*end
,
1542 enum wined3d_data_type data_type
, struct wined3d_shader_src_param
*src_param
)
1548 WARN("Invalid ptr %p >= end %p.\n", *ptr
, end
);
1553 if (!shader_sm4_read_param(priv
, ptr
, end
, data_type
, &src_param
->reg
, &src_param
->modifiers
))
1555 ERR("Failed to read parameter.\n");
1559 if (src_param
->reg
.type
== WINED3DSPR_IMMCONST
)
1561 src_param
->swizzle
= WINED3DSP_NOSWIZZLE
;
1565 enum wined3d_sm4_swizzle_type swizzle_type
=
1566 (token
& WINED3D_SM4_SWIZZLE_TYPE_MASK
) >> WINED3D_SM4_SWIZZLE_TYPE_SHIFT
;
1568 switch (swizzle_type
)
1570 case WINED3D_SM4_SWIZZLE_NONE
:
1571 src_param
->swizzle
= WINED3DSP_NOSWIZZLE
;
1574 case WINED3D_SM4_SWIZZLE_SCALAR
:
1575 src_param
->swizzle
= (token
& WINED3D_SM4_SWIZZLE_MASK
) >> WINED3D_SM4_SWIZZLE_SHIFT
;
1576 src_param
->swizzle
= (src_param
->swizzle
& 0x3) * 0x55;
1579 case WINED3D_SM4_SWIZZLE_VEC4
:
1580 src_param
->swizzle
= (token
& WINED3D_SM4_SWIZZLE_MASK
) >> WINED3D_SM4_SWIZZLE_SHIFT
;
1584 FIXME("Unhandled swizzle type %#x.\n", swizzle_type
);
1592 static BOOL
shader_sm4_read_dst_param(struct wined3d_sm4_data
*priv
, const DWORD
**ptr
, const DWORD
*end
,
1593 enum wined3d_data_type data_type
, struct wined3d_shader_dst_param
*dst_param
)
1595 enum wined3d_shader_src_modifier modifier
;
1600 WARN("Invalid ptr %p >= end %p.\n", *ptr
, end
);
1605 if (!shader_sm4_read_param(priv
, ptr
, end
, data_type
, &dst_param
->reg
, &modifier
))
1607 ERR("Failed to read parameter.\n");
1611 if (modifier
!= WINED3DSPSM_NONE
)
1613 ERR("Invalid source modifier %#x on destination register.\n", modifier
);
1617 dst_param
->write_mask
= (token
& WINED3D_SM4_WRITEMASK_MASK
) >> WINED3D_SM4_WRITEMASK_SHIFT
;
1618 dst_param
->modifiers
= 0;
1619 dst_param
->shift
= 0;
1624 static void shader_sm4_read_instruction_modifier(DWORD modifier
, struct wined3d_shader_instruction
*ins
)
1626 enum wined3d_sm4_instruction_modifier modifier_type
= modifier
& WINED3D_SM4_MODIFIER_MASK
;
1628 switch (modifier_type
)
1630 case WINED3D_SM4_MODIFIER_AOFFIMMI
:
1632 static const DWORD recognized_bits
= WINED3D_SM4_INSTRUCTION_MODIFIER
1633 | WINED3D_SM4_MODIFIER_MASK
1634 | WINED3D_SM4_AOFFIMMI_U_MASK
1635 | WINED3D_SM4_AOFFIMMI_V_MASK
1636 | WINED3D_SM4_AOFFIMMI_W_MASK
;
1638 /* Bit fields are used for sign extension. */
1646 if (modifier
& ~recognized_bits
)
1647 FIXME("Unhandled instruction modifier %#x.\n", modifier
);
1649 aoffimmi
.u
= (modifier
& WINED3D_SM4_AOFFIMMI_U_MASK
) >> WINED3D_SM4_AOFFIMMI_U_SHIFT
;
1650 aoffimmi
.v
= (modifier
& WINED3D_SM4_AOFFIMMI_V_MASK
) >> WINED3D_SM4_AOFFIMMI_V_SHIFT
;
1651 aoffimmi
.w
= (modifier
& WINED3D_SM4_AOFFIMMI_W_MASK
) >> WINED3D_SM4_AOFFIMMI_W_SHIFT
;
1652 ins
->texel_offset
.u
= aoffimmi
.u
;
1653 ins
->texel_offset
.v
= aoffimmi
.v
;
1654 ins
->texel_offset
.w
= aoffimmi
.w
;
1658 case WINED3D_SM5_MODIFIER_DATA_TYPE
:
1660 DWORD components
= (modifier
& WINED3D_SM5_MODIFIER_DATA_TYPE_MASK
) >> WINED3D_SM5_MODIFIER_DATA_TYPE_SHIFT
;
1661 enum wined3d_sm4_data_type data_type
= components
& 0xf;
1663 if ((components
& 0xfff0) != (components
& 0xf) * 0x1110)
1664 FIXME("Components (%#x) have different data types.\n", components
);
1665 ins
->resource_data_type
= data_type_table
[data_type
];
1669 case WINED3D_SM5_MODIFIER_RESOURCE_TYPE
:
1671 enum wined3d_sm4_resource_type resource_type
1672 = (modifier
& WINED3D_SM5_MODIFIER_RESOURCE_TYPE_MASK
) >> WINED3D_SM5_MODIFIER_RESOURCE_TYPE_SHIFT
;
1674 ins
->resource_type
= resource_type_table
[resource_type
];
1679 FIXME("Unhandled instruction modifier %#x.\n", modifier
);
1683 static void shader_sm4_read_instruction(void *data
, const DWORD
**ptr
, struct wined3d_shader_instruction
*ins
)
1685 const struct wined3d_sm4_opcode_info
*opcode_info
;
1686 DWORD opcode_token
, opcode
, previous_token
;
1687 struct wined3d_sm4_data
*priv
= data
;
1688 unsigned int i
, len
;
1693 list_move_head(&priv
->src_free
, &priv
->src
);
1695 if (*ptr
>= priv
->end
)
1697 WARN("End of byte-code, failed to read opcode.\n");
1700 remaining
= priv
->end
- *ptr
;
1702 opcode_token
= *(*ptr
)++;
1703 opcode
= opcode_token
& WINED3D_SM4_OPCODE_MASK
;
1705 len
= ((opcode_token
& WINED3D_SM4_INSTRUCTION_LENGTH_MASK
) >> WINED3D_SM4_INSTRUCTION_LENGTH_SHIFT
);
1710 WARN("End of byte-code, failed to read length token.\n");
1715 if (!len
|| remaining
< len
)
1717 WARN("Read invalid length %u (remaining %lu).\n", len
, remaining
);
1722 if (TRACE_ON(d3d_bytecode
))
1724 TRACE_(d3d_bytecode
)("[ %08x ", opcode_token
);
1725 for (i
= 0; i
< len
; ++i
)
1727 TRACE_(d3d_bytecode
)("%08x ", (*ptr
)[i
]);
1729 TRACE_(d3d_bytecode
)("]\n");
1732 if (!(opcode_info
= get_opcode_info(opcode
)))
1734 FIXME("Unrecognized opcode %#x, opcode_token 0x%08x.\n", opcode
, opcode_token
);
1735 ins
->handler_idx
= WINED3DSIH_TABLE_SIZE
;
1740 ins
->handler_idx
= opcode_info
->handler_idx
;
1743 ins
->predicate
= NULL
;
1744 ins
->dst_count
= strlen(opcode_info
->dst_info
);
1745 ins
->dst
= priv
->dst_param
;
1746 ins
->src_count
= strlen(opcode_info
->src_info
);
1747 ins
->src
= priv
->src_param
;
1748 ins
->resource_type
= WINED3D_SHADER_RESOURCE_NONE
;
1749 ins
->resource_data_type
= WINED3D_DATA_FLOAT
;
1750 memset(&ins
->texel_offset
, 0, sizeof(ins
->texel_offset
));
1755 if (opcode_info
->read_opcode_func
)
1757 opcode_info
->read_opcode_func(ins
, opcode
, opcode_token
, p
, len
, priv
);
1761 enum wined3d_shader_dst_modifier instruction_dst_modifier
= WINED3DSPDM_NONE
;
1763 previous_token
= opcode_token
;
1764 while (previous_token
& WINED3D_SM4_INSTRUCTION_MODIFIER
&& p
!= *ptr
)
1765 shader_sm4_read_instruction_modifier(previous_token
= *p
++, ins
);
1767 ins
->flags
= (opcode_token
& WINED3D_SM4_INSTRUCTION_FLAGS_MASK
) >> WINED3D_SM4_INSTRUCTION_FLAGS_SHIFT
;
1768 if (ins
->flags
& WINED3D_SM4_INSTRUCTION_FLAG_SATURATE
)
1770 ins
->flags
&= ~WINED3D_SM4_INSTRUCTION_FLAG_SATURATE
;
1771 instruction_dst_modifier
= WINED3DSPDM_SATURATE
;
1773 precise
= (opcode_token
& WINED3D_SM5_PRECISE_MASK
) >> WINED3D_SM5_PRECISE_SHIFT
;
1774 ins
->flags
|= precise
<< WINED3DSI_PRECISE_SHIFT
;
1776 for (i
= 0; i
< ins
->dst_count
; ++i
)
1778 if (!(shader_sm4_read_dst_param(priv
, &p
, *ptr
, map_data_type(opcode_info
->dst_info
[i
]),
1779 &priv
->dst_param
[i
])))
1781 ins
->handler_idx
= WINED3DSIH_TABLE_SIZE
;
1784 priv
->dst_param
[i
].modifiers
|= instruction_dst_modifier
;
1787 for (i
= 0; i
< ins
->src_count
; ++i
)
1789 if (!(shader_sm4_read_src_param(priv
, &p
, *ptr
, map_data_type(opcode_info
->src_info
[i
]),
1790 &priv
->src_param
[i
])))
1792 ins
->handler_idx
= WINED3DSIH_TABLE_SIZE
;
1802 ins
->handler_idx
= WINED3DSIH_TABLE_SIZE
;
1806 static BOOL
shader_sm4_is_end(void *data
, const DWORD
**ptr
)
1808 struct wined3d_sm4_data
*priv
= data
;
1809 return *ptr
== priv
->end
;
1812 const struct wined3d_shader_frontend sm4_shader_frontend
=
1816 shader_sm4_read_header
,
1817 shader_sm4_read_instruction
,
1821 #define TAG_AON9 WINEMAKEFOURCC('A', 'o', 'n', '9')
1822 #define TAG_DXBC WINEMAKEFOURCC('D', 'X', 'B', 'C')
1823 #define TAG_ISGN WINEMAKEFOURCC('I', 'S', 'G', 'N')
1824 #define TAG_OSG5 WINEMAKEFOURCC('O', 'S', 'G', '5')
1825 #define TAG_OSGN WINEMAKEFOURCC('O', 'S', 'G', 'N')
1826 #define TAG_PCSG WINEMAKEFOURCC('P', 'C', 'S', 'G')
1827 #define TAG_SHDR WINEMAKEFOURCC('S', 'H', 'D', 'R')
1828 #define TAG_SHEX WINEMAKEFOURCC('S', 'H', 'E', 'X')
1833 DWORD shader_version
;
1835 DWORD byte_code_offset
;
1838 struct shader_handler_context
1840 struct wined3d_shader
*shader
;
1841 enum wined3d_shader_byte_code_format
*format
;
1842 unsigned int max_version
;
1845 static void read_dword(const char **ptr
, DWORD
*d
)
1847 memcpy(d
, *ptr
, sizeof(*d
));
1851 static BOOL
require_space(size_t offset
, size_t count
, size_t size
, size_t data_size
)
1853 return !count
|| (data_size
- offset
) / count
>= size
;
1856 static void skip_dword_unknown(const char **ptr
, unsigned int count
)
1861 WARN("Skipping %u unknown DWORDs:\n", count
);
1862 for (i
= 0; i
< count
; ++i
)
1864 read_dword(ptr
, &d
);
1865 WARN("\t0x%08x\n", d
);
1869 static HRESULT
parse_dxbc(const char *data
, SIZE_T data_size
,
1870 HRESULT (*chunk_handler
)(const char *data
, DWORD data_size
, DWORD tag
, void *ctx
), void *ctx
)
1872 const char *ptr
= data
;
1880 read_dword(&ptr
, &tag
);
1881 TRACE("tag: %s.\n", debugstr_an((const char *)&tag
, 4));
1883 if (tag
!= TAG_DXBC
)
1885 WARN("Wrong tag.\n");
1886 return E_INVALIDARG
;
1889 WARN("Ignoring DXBC checksum.\n");
1890 skip_dword_unknown(&ptr
, 4);
1892 read_dword(&ptr
, &version
);
1893 TRACE("version: %#x.\n", version
);
1894 if (version
!= 0x00000001)
1896 WARN("Got unexpected DXBC version %#x.\n", version
);
1897 return E_INVALIDARG
;
1900 read_dword(&ptr
, &total_size
);
1901 TRACE("total size: %#x\n", total_size
);
1903 read_dword(&ptr
, &chunk_count
);
1904 TRACE("chunk count: %#x\n", chunk_count
);
1906 for (i
= 0; i
< chunk_count
; ++i
)
1908 DWORD chunk_tag
, chunk_size
;
1909 const char *chunk_ptr
;
1912 read_dword(&ptr
, &chunk_offset
);
1913 TRACE("chunk %u at offset %#x\n", i
, chunk_offset
);
1915 if (chunk_offset
>= data_size
|| !require_space(chunk_offset
, 2, sizeof(DWORD
), data_size
))
1917 WARN("Invalid chunk offset %#x (data size %#lx).\n", chunk_offset
, data_size
);
1921 chunk_ptr
= data
+ chunk_offset
;
1923 read_dword(&chunk_ptr
, &chunk_tag
);
1924 read_dword(&chunk_ptr
, &chunk_size
);
1926 if (!require_space(chunk_ptr
- data
, 1, chunk_size
, data_size
))
1928 WARN("Invalid chunk size %#x (data size %#lx, chunk offset %#x).\n",
1929 chunk_size
, data_size
, chunk_offset
);
1933 if (FAILED(hr
= chunk_handler(chunk_ptr
, chunk_size
, chunk_tag
, ctx
)))
1940 static const char *shader_get_string(const char *data
, size_t data_size
, DWORD offset
)
1942 if (offset
>= data_size
)
1944 WARN("Invalid offset %#x (data size %#lx).\n", offset
, (long)data_size
);
1948 if (!memchr( data
+ offset
, 0, data_size
- offset
))
1951 return data
+ offset
;
1954 static HRESULT
shader_parse_signature(DWORD tag
, const char *data
, DWORD data_size
,
1955 struct wined3d_shader_signature
*s
)
1957 struct wined3d_shader_signature_element
*e
;
1958 const char *ptr
= data
;
1962 if (!require_space(0, 2, sizeof(DWORD
), data_size
))
1964 WARN("Invalid data size %#x.\n", data_size
);
1965 return E_INVALIDARG
;
1968 read_dword(&ptr
, &count
);
1969 TRACE("%u elements.\n", count
);
1971 skip_dword_unknown(&ptr
, 1); /* It seems to always be 0x00000008. */
1973 if (!require_space(ptr
- data
, count
, 6 * sizeof(DWORD
), data_size
))
1975 WARN("Invalid count %#x (data size %#x).\n", count
, data_size
);
1976 return E_INVALIDARG
;
1979 if (!(e
= heap_calloc(count
, sizeof(*e
))))
1981 ERR("Failed to allocate input signature memory.\n");
1982 return E_OUTOFMEMORY
;
1985 for (i
= 0; i
< count
; ++i
)
1989 if (tag
== TAG_OSG5
)
1990 read_dword(&ptr
, &e
[i
].stream_idx
);
1992 e
[i
].stream_idx
= 0;
1993 read_dword(&ptr
, &name_offset
);
1994 if (!(e
[i
].semantic_name
= shader_get_string(data
, data_size
, name_offset
)))
1996 WARN("Invalid name offset %#x (data size %#x).\n", name_offset
, data_size
);
1998 return E_INVALIDARG
;
2000 read_dword(&ptr
, &e
[i
].semantic_idx
);
2001 read_dword(&ptr
, &e
[i
].sysval_semantic
);
2002 read_dword(&ptr
, &e
[i
].component_type
);
2003 read_dword(&ptr
, &e
[i
].register_idx
);
2004 read_dword(&ptr
, &e
[i
].mask
);
2006 TRACE("Stream: %u, semantic: %s, semantic idx: %u, sysval_semantic %#x, "
2007 "type %u, register idx: %u, use_mask %#x, input_mask %#x.\n",
2008 e
[i
].stream_idx
, debugstr_a(e
[i
].semantic_name
), e
[i
].semantic_idx
, e
[i
].sysval_semantic
,
2009 e
[i
].component_type
, e
[i
].register_idx
, (e
[i
].mask
>> 8) & 0xff, e
[i
].mask
& 0xff);
2013 s
->element_count
= count
;
2018 static HRESULT
shader_dxbc_chunk_handler(const char *data
, DWORD data_size
, DWORD tag
, void *context
)
2020 struct shader_handler_context
*ctx
= context
;
2021 struct wined3d_shader
*shader
= ctx
->shader
;
2027 if (ctx
->max_version
< 4)
2029 TRACE("Skipping shader input signature.\n");
2032 if (shader
->input_signature
.elements
)
2034 FIXME("Multiple input signatures.\n");
2037 if (FAILED(hr
= shader_parse_signature(tag
, data
, data_size
, &shader
->input_signature
)))
2043 if (ctx
->max_version
< 4)
2045 TRACE("Skipping shader output signature.\n");
2048 if (shader
->output_signature
.elements
)
2050 FIXME("Multiple output signatures.\n");
2053 if (FAILED(hr
= shader_parse_signature(tag
, data
, data_size
, &shader
->output_signature
)))
2058 if (shader
->patch_constant_signature
.elements
)
2060 FIXME("Multiple patch constant signatures.\n");
2063 if (FAILED(hr
= shader_parse_signature(tag
, data
, data_size
, &shader
->patch_constant_signature
)))
2069 if (ctx
->max_version
< 4)
2071 TRACE("Skipping SM4+ shader.\n");
2074 if (shader
->function
)
2075 FIXME("Multiple shader code chunks.\n");
2076 shader
->function
= (const DWORD
*)data
;
2077 shader
->functionLength
= data_size
;
2078 *ctx
->format
= WINED3D_SHADER_BYTE_CODE_FORMAT_SM4
;
2082 if (ctx
->max_version
< 4)
2084 const struct aon9_header
*header
= (const struct aon9_header
*)data
;
2085 unsigned int unknown_dword_count
;
2086 const char *byte_code
;
2088 if (data_size
< sizeof(*header
))
2090 WARN("Invalid Aon9 data size %#x.\n", data_size
);
2093 byte_code
= data
+ header
->byte_code_offset
;
2094 unknown_dword_count
= (header
->byte_code_offset
- sizeof(*header
)) / sizeof(DWORD
);
2096 if (data_size
- 2 * sizeof(DWORD
) < header
->byte_code_offset
)
2098 WARN("Invalid byte code offset %#x (size %#x).\n", header
->byte_code_offset
, data_size
);
2101 FIXME("Skipping %u unknown DWORDs.\n", unknown_dword_count
);
2103 if (shader
->function
)
2104 FIXME("Multiple shader code chunks.\n");
2105 shader
->function
= (const DWORD
*)byte_code
;
2106 shader
->functionLength
= data_size
- header
->byte_code_offset
;
2107 *ctx
->format
= WINED3D_SHADER_BYTE_CODE_FORMAT_SM1
;
2108 TRACE("Feature level 9 shader version 0%08x, 0%08x.\n",
2109 header
->shader_version
, *shader
->function
);
2113 TRACE("Skipping feature level 9 shader code.\n");
2118 TRACE("Skipping chunk %s.\n", debugstr_an((const char *)&tag
, 4));
2125 HRESULT
shader_extract_from_dxbc(struct wined3d_shader
*shader
,
2126 unsigned int max_shader_version
, enum wined3d_shader_byte_code_format
*format
)
2128 struct shader_handler_context ctx
;
2131 ctx
.shader
= shader
;
2132 ctx
.format
= format
;
2133 ctx
.max_version
= max_shader_version
;
2135 hr
= parse_dxbc(shader
->byte_code
, shader
->byte_code_size
, shader_dxbc_chunk_handler
, &ctx
);
2136 if (!shader
->function
)
2140 WARN("Failed to parse DXBC, hr %#x.\n", hr
);
2145 static HRESULT
shader_isgn_chunk_handler(const char *data
, DWORD data_size
, DWORD tag
, void *ctx
)
2147 struct wined3d_shader_signature
*is
= ctx
;
2149 if (tag
!= TAG_ISGN
)
2154 FIXME("Multiple shader signatures.\n");
2158 return shader_parse_signature(tag
, data
, data_size
, is
);
2161 HRESULT CDECL
wined3d_extract_shader_input_signature_from_dxbc(struct wined3d_shader_signature
*signature
,
2162 const void *code
, SIZE_T code_size
)
2164 memset(signature
, 0, sizeof(*signature
));
2165 return parse_dxbc(code
, code_size
, shader_isgn_chunk_handler
, signature
);